File tree Expand file tree Collapse file tree
systemvm/patches/debian/config/opt/cloud/bin Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -26,7 +26,7 @@ class CsConfig(object):
2626 A class to cache all the stuff that the other classes need
2727 """
2828 __LOG_FILE = "/var/log/cloud.log"
29- __LOG_LEVEL = "DEBUG "
29+ __LOG_LEVEL = "INFO "
3030 __LOG_FORMAT = "%(asctime)s %(levelname)-8s %(message)s"
3131 cl = None
3232
Original file line number Diff line number Diff line change @@ -47,28 +47,29 @@ def load(self):
4747 data = self .bdata
4848 if not os .path .exists (self .DPATH ):
4949 os .makedirs (self .DPATH )
50- self .fpath = self .DPATH + '/' + self .key + '.json'
50+ self .fpath = os .path .join (self .DPATH , self .key + '.json' )
51+
5152 try :
52- handle = open (self .fpath )
53+ with open (self .fpath , 'r' ) as _fh :
54+ logging .debug ("Loading data bag type %s" , self .key )
55+ data = json .load (_fh )
5356 except IOError :
5457 logging .debug ("Creating data bag type %s" , self .key )
5558 data .update ({"id" : self .key })
56- else :
57- logging .debug ("Loading data bag type %s" , self .key )
58- data = json .load (handle )
59- handle .close ()
60- self .dbag = data
59+ finally :
60+ self .dbag = data
6161
6262 def save (self , dbag ):
6363 try :
64- handle = open (self .fpath , 'w' )
64+ with open (self .fpath , 'w' ) as _fh :
65+ logging .debug ("Writing data bag type %s" , self .key )
66+ json .dump (
67+ dbag , _fh ,
68+ sort_keys = True ,
69+ indent = 2
70+ )
6571 except IOError :
6672 logging .error ("Could not write data bag %s" , self .key )
67- else :
68- logging .debug ("Writing data bag type %s" , self .key )
69- logging .debug (dbag )
70- jsono = json .dumps (dbag , indent = 4 , sort_keys = True )
71- handle .write (jsono )
7273
7374 def getDataBag (self ):
7475 return self .dbag
Original file line number Diff line number Diff line change 2727import json
2828from cs .CsVmPassword import *
2929
30- logging .basicConfig (filename = '/var/log/cloud.log' , level = logging .DEBUG , format = '%(asctime)s %(filename)s %(funcName)s:%(lineno)d %(message)s' )
30+ logging .basicConfig (filename = '/var/log/cloud.log' , level = logging .INFO , format = '%(asctime)s %(filename)s %(funcName)s:%(lineno)d %(message)s' )
3131
3232# first commandline argument should be the file to process
3333if (len (sys .argv ) != 2 ):
You can’t perform that action at this time.
0 commit comments