summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Kraft <george.kraft@calxeda.com>2013-10-21 12:11:28 -0500
committerGeorge Kraft <george.kraft@calxeda.com>2013-10-21 12:11:28 -0500
commit4a116cac1b2d6319604f957fd34d42a4bba29b21 (patch)
treede9a805d60ac462b354ebe7c5272ff023fcded07
parente62b7e2960ccca5a062712a1ea3bfb87bbf86ec0 (diff)
downloadcxmanage-4a116cac1b2d6319604f957fd34d42a4bba29b21.tar.gz
CXMAN-243: Add a wait=True flag to fabric.refresh()
-rw-r--r--cxmanage_api/fabric.py57
1 files changed, 42 insertions, 15 deletions
diff --git a/cxmanage_api/fabric.py b/cxmanage_api/fabric.py
index ab17677..e143c32 100644
--- a/cxmanage_api/fabric.py
+++ b/cxmanage_api/fabric.py
@@ -32,10 +32,13 @@
# THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
# DAMAGE.
+import time
+
from cxmanage_api.tasks import DEFAULT_TASK_QUEUE
from cxmanage_api.tftp import InternalTftp
from cxmanage_api.node import Node as NODE
-from cxmanage_api.cx_exceptions import CommandFailedError
+from cxmanage_api.cx_exceptions import CommandFailedError, TimeoutError, \
+ IpmiError, TftpException
# pylint: disable=R0902,R0903, R0904
@@ -209,22 +212,46 @@ class Fabric(object):
"""
return self.nodes[0]
- def refresh(self):
+ def refresh(self, wait=False, timeout=600):
"""Gets the nodes of this fabric by pulling IP info from a BMC."""
+ def get_nodes():
+ """Returns a dictionary of nodes reported by the primary node IP"""
+ new_nodes = {}
+ 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(
+ 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
+ return new_nodes
+
+ initial_node_count = len(self._nodes)
self._nodes = {}
- 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():
- self._nodes[node_id] = 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)
- self._nodes[node_id].node_id = node_id
+
+ if wait:
+ deadline = time.time() + timeout
+ while time.time() < deadline:
+ try:
+ self._nodes = get_nodes()
+ if len(self._nodes) >= initial_node_count:
+ break
+ except (IpmiError, TftpException):
+ pass
+ else:
+ raise TimeoutError(
+ "Fabric refresh timed out. Rediscovered %i of %i nodes"
+ % (len(self._nodes), initial_node_count)
+ )
+ else:
+ self._nodes = get_nodes()
def get_mac_addresses(self):
"""Gets MAC addresses from all nodes.