Commit 69883b4b authored by Alain Takoudjou's avatar Alain Takoudjou Committed by Thomas Gambier

format: dump partition resources information if not exists yet

If there is not changes in slapformat.xml, current slapformat will not dump computer
resources (as well as partition resources).

For compatibility with olders version of slapformat, dump partition resources
if it's not created yet event if the file slapformat.xml didn't change.

/reviewed-on nexedi/slapos.core!88
parent 72ddfb33
......@@ -354,6 +354,10 @@ class Computer(object):
path_to_json: String, path to the JSON version to save.
"""
# dump partition resources information
for partition in self.partition_list:
partition.dump()
computer_dict = _getDict(self)
if path_to_json:
......@@ -388,9 +392,6 @@ class Computer(object):
with open(path_to_xml, 'wb') as fout:
fout.write(new_pretty_xml)
for partition in self.partition_list:
partition.dump()
def backup_xml(self, path_to_archive, path_to_xml):
"""
Stores a copy of the current xml file to an historical archive.
......@@ -752,13 +753,20 @@ class Partition(object):
def dump(self):
"""Dump available resources into ~partition_home/.slapos-resource."""
file_path = os.path.join(self.path, self.resource_file)
logger.info("Partition resources saved to {}".format(
self.reference, file_path))
data = _getDict(self)
content = json.dumps(data, sort_keys=True, indent=4)
if os.path.exists(file_path):
with open(file_path, "r") as f:
if f.read() == content:
# dumped resources didn't change
return
with open(file_path, "wb") as fo:
json.dump(data, fo, sort_keys=True, indent=4)
fo.write(content)
owner_pw = pwd.getpwnam(self.user.name)
os.chmod(file_path, 0o644)
logger.info("Partition resources saved to {}".format(
self.reference, file_path))
class User(object):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment