summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Hobbs <jason.hobbs@calxeda.com>2012-11-20 12:28:44 -0600
committerJason Hobbs <jason.hobbs@calxeda.com>2012-11-20 12:33:14 -0600
commit904c85e7215ae4f37d59b6d85460979239354582 (patch)
tree0fc920b1c2c01bea1086ad7de625da52f10dd84b
parent09078278441841b54f99e3f401a791dddc006d1d (diff)
downloadcxmanage-904c85e7215ae4f37d59b6d85460979239354582.tar.gz
CXMAN-146: Fabric: lazy node discovery
Don't perform node discovery until fabric.nodes is accessed for the first time. This allows us to create a fabric object at a time that the system may not be ready, and then use it later when the system is ready.
-rw-r--r--cxmanage_api/fabric.py22
-rw-r--r--cxmanage_test/fabric_test.py4
2 files changed, 19 insertions, 7 deletions
diff --git a/cxmanage_api/fabric.py b/cxmanage_api/fabric.py
index 4949a36..c6de412 100644
--- a/cxmanage_api/fabric.py
+++ b/cxmanage_api/fabric.py
@@ -59,12 +59,16 @@ class Fabric(object):
tftp=None, max_threads=1, command_delay=0, verbose=False,
node=None):
"""Default constructor for the Fabric class."""
- self.nodes = {}
self._tftp = tftp
self.max_threads = max_threads
self.command_delay = command_delay
self.verbose = verbose
self.node = node
+ self.ip_address = ip_address
+ self.username = username
+ self.password = password
+
+ self._nodes = {}
if (not self.node):
self.node = NODE
@@ -72,9 +76,6 @@ class Fabric(object):
if (not self.tftp):
self.tftp = InternalTftp()
- self._discover_nodes(ip_address=ip_address, username=username,
- password=password)
-
def __eq__(self, other):
return isinstance(other, Fabric) and self.nodes == other.nodes
@@ -98,6 +99,10 @@ class Fabric(object):
@tftp.setter
def tftp(self, value):
self._tftp = value
+
+ if not self._nodes:
+ return
+
for node in self.nodes.values():
node.tftp = value
@@ -176,6 +181,13 @@ class Fabric(object):
""" Run an arbitrary IPMItool command on all nodes """
return self._run_command(asynchronous, "ipmitool_command",
ipmitool_args)
+ @property
+ def nodes(self):
+ """List of nodes in the fabric - lazily initialized"""
+ if not self._nodes:
+ self._discover_nodes(self.ip_address)
+
+ return self._nodes
############################### Private methods ###############################
@@ -186,7 +198,7 @@ class Fabric(object):
verbose=self.verbose)
ipinfo = node.get_fabric_ipinfo()
for node_id, node_address in ipinfo.iteritems():
- self.nodes[node_id] = self.node(ip_address=node_address,
+ self._nodes[node_id] = self.node(ip_address=node_address,
username=username,
password=password,
tftp=self.tftp,
diff --git a/cxmanage_test/fabric_test.py b/cxmanage_test/fabric_test.py
index cb1fc34..787bdb7 100644
--- a/cxmanage_test/fabric_test.py
+++ b/cxmanage_test/fabric_test.py
@@ -48,7 +48,7 @@ class FabricTest(unittest.TestCase):
self.fabric = Fabric("192.168.100.1", max_threads=32,
node=DummyNode)
self.nodes = [DummyNode(x) for x in ADDRESSES]
- self.fabric.nodes = dict((i, self.nodes[i])
+ self.fabric._nodes = dict((i, self.nodes[i])
for i in xrange(NUM_NODES))
def test_tftp(self):
@@ -69,7 +69,7 @@ class FabricTest(unittest.TestCase):
"""Test that we delay for at least command_delay"""
delay = random.randint(1, 5)
self.fabric.command_delay = delay
- self.fabric.nodes = {0: self.fabric.nodes[0]}
+ self.fabric._nodes = {0: self.fabric.nodes[0]}
start = time.time()
self.fabric.info_basic()
finish = time.time()