Skip to content

Commit

Permalink
cloud.openstack: Split out node-finding
Browse files Browse the repository at this point in the history
... into its own method.

Signed-off-by: Zack Cerza <[email protected]>
  • Loading branch information
zmc committed Mar 22, 2017
1 parent dbf6fd9 commit eb14ec9
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions teuthology/provision/cloud/openstack.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,22 +370,25 @@ def userdata(self):

@property
def node(self):
if not hasattr(self, '_node'):
nodes = retry(self.provider.driver.list_nodes)
for node in nodes:
matches = [node for node in nodes if node.name == self.name]
msg = "Unknown error locating %s"
if not matches:
msg = "No nodes found with name '%s'" % self.name
log.warn(msg)
return
elif len(matches) > 1:
msg = "More than one node found with name '%s'"
elif len(matches) == 1:
self._node = matches[0]
break
raise RuntimeError(msg % self.name)
return self._node
if hasattr(self, '_node'):
return self._node
matches = self._find_nodes()
msg = "Unknown error locating %s"
if not matches:
msg = "No nodes found with name '%s'" % self.name
log.warn(msg)
return
elif len(matches) > 1:
msg = "More than one node found with name '%s'"
elif len(matches) == 1:
self._node = matches[0]
return self._node
raise RuntimeError(msg % self.name)

def _find_nodes(self):
nodes = retry(self.provider.driver.list_nodes)
matches = [node for node in nodes if node.name == self.name]
return matches

def _destroy(self):
if not self.node:
Expand Down

0 comments on commit eb14ec9

Please sign in to comment.