Add get_node_by_name

We want to set the value of uuid field of Watcher ComputeNode
to hypversion id(as uuid). We need a method to get compute
node by name.

Change-Id: I0975500f359de92b6d6fdea2e01614cf0ba73f05
Related-Bug: #1835192
This commit is contained in:
licanwei
2019-07-08 11:48:13 +08:00
parent 46cc09f00e
commit a3c49cf8a4
2 changed files with 39 additions and 0 deletions

View File

@@ -149,6 +149,19 @@ class ModelRoot(nx.DiGraph, base.Model):
except exception.ComputeResourceNotFound:
raise exception.ComputeNodeNotFound(name=uuid)
@lockutils.synchronized("model_root")
def get_node_by_name(self, name):
try:
node_list = [cn['attr'] for uuid, cn in self.nodes(data=True)
if (isinstance(cn['attr'], element.ComputeNode) and
cn['attr']['hostname'] == name)]
if node_list:
return node_list[0]
else:
raise exception.ComputeResourceNotFound
except exception.ComputeResourceNotFound:
raise exception.ComputeNodeNotFound(name=name)
@lockutils.synchronized("model_root")
def get_instance_by_uuid(self, uuid):
try: