MCPcopy Create free account
hub / github.com/apache/cloudstack / DataBag

Class DataBag

systemvm/debian/opt/cloud/bin/merge.py:43–82  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

41
42
43class DataBag:
44
45 DPATH = "/etc/cloudstack"
46
47 def __init__(self):
48 self.bdata = {}
49
50 def load(self):
51 data = self.bdata
52 if not os.path.exists(self.DPATH):
53 os.makedirs(self.DPATH)
54 self.fpath = os.path.join(self.DPATH, self.key + '.json')
55
56 try:
57 with open(self.fpath, 'r') as _fh:
58 logging.debug("Loading data bag type %s", self.key)
59 data = json.load(_fh)
60 except (IOError, ValueError):
61 logging.debug("Caught load error, creating empty data bag type %s", self.key)
62 data.update({"id": self.key})
63 finally:
64 self.dbag = data
65
66 def save(self, dbag):
67 try:
68 with open(self.fpath, 'w') as _fh:
69 logging.debug("Writing data bag type %s", self.key)
70 json.dump(
71 dbag, _fh,
72 sort_keys=True,
73 indent=2
74 )
75 except IOError:
76 logging.error("Could not write data bag %s", self.key)
77
78 def getDataBag(self):
79 return self.dbag
80
81 def setKey(self, key):
82 self.key = key
83
84
85class updateDataBag:

Callers 3

__init__Method · 0.90
__init__Method · 0.90
processMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected