Merge "Make NodeSet fully serializable"
This commit is contained in:
commit
f846956c59
|
@ -348,6 +348,7 @@ class TestWeb(BaseTestWeb):
|
|||
'name': '',
|
||||
'nodes': [{'comment': None,
|
||||
'hold_job': None,
|
||||
'id': None,
|
||||
'label': 'label1',
|
||||
'name': 'controller',
|
||||
'aliases': [],
|
||||
|
@ -394,6 +395,7 @@ class TestWeb(BaseTestWeb):
|
|||
'name': '',
|
||||
'nodes': [{'comment': None,
|
||||
'hold_job': None,
|
||||
'id': None,
|
||||
'label': 'label2',
|
||||
'name': 'controller',
|
||||
'aliases': [],
|
||||
|
@ -1017,6 +1019,7 @@ class TestWeb(BaseTestWeb):
|
|||
'nodes': [{
|
||||
'comment': None,
|
||||
'hold_job': None,
|
||||
'id': None,
|
||||
'label': 'label1',
|
||||
'name': ['controller'],
|
||||
'state': 'unknown'
|
||||
|
|
|
@ -636,6 +636,7 @@ class Node(ConfigObject):
|
|||
|
||||
def toDict(self, internal_attributes=False):
|
||||
d = {}
|
||||
d["id"] = self.id
|
||||
d['state'] = self.state
|
||||
d['hold_job'] = self.hold_job
|
||||
d['comment'] = self.comment
|
||||
|
@ -658,6 +659,12 @@ class Node(ConfigObject):
|
|||
setattr(self, k, v)
|
||||
self._keys = keys
|
||||
|
||||
@classmethod
|
||||
def fromDict(cls, data):
|
||||
node = cls(data["name"], data["label"])
|
||||
node.updateFromDict(data)
|
||||
return node
|
||||
|
||||
|
||||
class Group(ConfigObject):
|
||||
"""A logical group of nodes for use by a job.
|
||||
|
@ -690,6 +697,10 @@ class Group(ConfigObject):
|
|||
'nodes': self.nodes
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def fromDict(cls, data):
|
||||
return cls(data["name"], data["nodes"])
|
||||
|
||||
|
||||
class NodeSet(ConfigObject):
|
||||
"""A set of nodes.
|
||||
|
@ -727,6 +738,15 @@ class NodeSet(ConfigObject):
|
|||
d['groups'].append(group.toDict())
|
||||
return d
|
||||
|
||||
@classmethod
|
||||
def fromDict(cls, data):
|
||||
nodeset = cls(data["name"])
|
||||
for node in data["nodes"]:
|
||||
nodeset.addNode(Node.fromDict(node))
|
||||
for group in data["groups"]:
|
||||
nodeset.addGroup(Group.fromDict(group))
|
||||
return nodeset
|
||||
|
||||
def copy(self):
|
||||
n = NodeSet(self.name)
|
||||
for name, node in self.nodes.items():
|
||||
|
|
Loading…
Reference in New Issue