summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Kraft <george.kraft@calxeda.com>2013-12-12 16:26:50 -0600
committerGreg Lutostanski <greg.lutostanski@calxeda.com>2013-12-13 14:09:58 -0600
commit1a68dce1ecccf5fd583b8ae4aacab4629608193a (patch)
tree372ba4b56927a21366f5490b7c3fdd1e9613ee36
parent33298ed02abc5cc5baf87dfd900397d2545a9043 (diff)
downloadcxmanage-1a68dce1ecccf5fd583b8ae4aacab4629608193a.tar.gz
CXMAN-277: Remove guid from node.__hash__ and node.__eq__
Since we need an IPMI command to get the guid. Having it in __hash__ can cause weird behavior -- for example, as soon as we add the Node object to a set, we may fire off an IPMI command. Which could raise an exception. We can still make use of GUIDs in fabric.refresh though.
-rw-r--r--cxmanage_api/fabric.py39
-rw-r--r--cxmanage_api/node.py4
2 files changed, 17 insertions, 26 deletions
diff --git a/cxmanage_api/fabric.py b/cxmanage_api/fabric.py
index 5b03fb5..bd05a10 100644
--- a/cxmanage_api/fabric.py
+++ b/cxmanage_api/fabric.py
@@ -217,36 +217,31 @@ class Fabric(object):
def get_nodes():
"""Returns a dictionary of nodes reported by the primary node IP"""
new_nodes = {}
- node = self.node(
+ root_node = self.node(
ip_address=self.ip_address, username=self.username,
password=self.password, tftp=self.tftp,
ecme_tftp_port=self.ecme_tftp_port, verbose=self.verbose
)
- ipinfo = node.get_fabric_ipinfo()
- for node_id, node_address in ipinfo.iteritems():
- new_nodes[node_id] = self.node(
+ ipinfo = root_node.get_fabric_ipinfo()
+ for node_id, node_address in ipinfo.items():
+ node = self.node(
ip_address=node_address, username=self.username,
password=self.password, tftp=self.tftp,
ecme_tftp_port=self.ecme_tftp_port,
verbose=self.verbose
)
- new_nodes[node_id].node_id = node_id
+ node.node_id = node_id
+ new_nodes[node.guid] = node
return new_nodes
initial_node_count = len(self._nodes)
+ old_nodes = {node.guid: node for node in self._nodes.values()}
- if initial_node_count == 0:
- self._nodes = get_nodes()
- self.get_power()
- return
-
- new_nodes = {node.guid: node for node in get_nodes().values()}
if wait:
deadline = time.time() + timeout
while time.time() < deadline:
try:
- new_nodes = {node.guid: node
- for node in get_nodes().values()}
+ new_nodes = get_nodes()
if len(new_nodes) >= initial_node_count:
break
except (IpmiError, TftpException, ParseError):
@@ -256,19 +251,15 @@ class Fabric(object):
"Fabric refresh timed out. Rediscovered %i of %i nodes"
% (len(new_nodes), initial_node_count)
)
+ else:
+ new_nodes = get_nodes()
- old_nodes = self._nodes
- for old_node_key, old_node in old_nodes.items():
- if old_node.guid in new_nodes:
- old_node.refresh(new_nodes[old_node.guid])
- del new_nodes[old_node.guid]
- else:
- del self._nodes[old_node_key]
-
- for new_node in new_nodes.values():
- self._nodes[new_node.node_id] = new_node
+ for guid, node in new_nodes.items():
+ if guid in old_nodes:
+ old_nodes[guid].refresh(node)
+ new_nodes[guid] = old_nodes[guid]
- self.get_power()
+ self._nodes = {node.node_id: node for node in new_nodes.values()}
def get_mac_addresses(self):
"""Gets MAC addresses from all nodes.
diff --git a/cxmanage_api/node.py b/cxmanage_api/node.py
index 329c301..784f7f5 100644
--- a/cxmanage_api/node.py
+++ b/cxmanage_api/node.py
@@ -119,10 +119,10 @@ class Node(object):
self._guid = None
def __eq__(self, other):
- return isinstance(other, Node) and self.guid == other.guid
+ return isinstance(other, Node) and self.ip_address == other.ip_address
def __hash__(self):
- return hash(self.guid)
+ return hash(self.ip_address)
def __str__(self):
return 'Node %s (%s)' % (self.node_id, self.ip_address)