diff options
author | Tyler Mock <tyler.mock@calxeda.com> | 2013-04-26 11:05:33 -0500 |
---|---|---|
committer | Tyler Mock <tyler.mock@calxeda.com> | 2013-04-26 11:05:33 -0500 |
commit | 0f0a8736c50a1d40ee0f4f667ac750ad42c10249 (patch) | |
tree | 559051db9b843264fa47a3f9a15e38a865d61f54 | |
parent | 0acc5d6be09bb5c7b3e1493ac2004f732ea28665 (diff) | |
download | cxmanage-0f0a8736c50a1d40ee0f4f667ac750ad42c10249.tar.gz |
Added support for get_fabric_depth_chart()
-rw-r--r-- | cxmanage_api/fabric.py | 18 | ||||
-rw-r--r-- | cxmanage_api/node.py | 63 |
2 files changed, 80 insertions, 1 deletions
diff --git a/cxmanage_api/fabric.py b/cxmanage_api/fabric.py index fe338e4..84e5a51 100644 --- a/cxmanage_api/fabric.py +++ b/cxmanage_api/fabric.py @@ -871,7 +871,23 @@ class Fabric(object): :rtype: dictionary """ - return self.primary_node.get_fabric_routing_table() + rt_tables = {} + for nn, node in self.nodes.items(): + rt_tables[nn] = node.get_fabric_routing_table() + return rt_tables + + def get_depth_chart(self): + """Get the depth_chart for the fabric. + + :returns: The depth_chart for the fabric. + :rtype: dictionary + + """ + dpthcharts = {} + for nn, node in self.nodes.items(): + dpthcharts[nn] = node.get_fabric_depth_chart() + + return dpthcharts def _run_command(self, async, name, *args): """Start a command on the given nodes.""" diff --git a/cxmanage_api/node.py b/cxmanage_api/node.py index 012aa40..6a4e3c0 100644 --- a/cxmanage_api/node.py +++ b/cxmanage_api/node.py @@ -1177,6 +1177,69 @@ class Node(object): return results + def get_fabric_depth_chart(self): + """Gets a table indicating the distance from a given node to all other + nodes on each fabric link. + + :return: Returns a map of target->(neighbor, hops), + [other (neighbors,hops)] + :rtype: dictionary + + :raises IpmiError: If the IPMI command fails. + :raises TftpException: If the TFTP transfer fails. + + """ + filename = temp_file() + basename = os.path.basename(filename) + + try: + result = self.bmc.fabric_get_depthchart(basename) + if hasattr(result, "error"): + raise IpmiError(result.error) + self.ecme_tftp.get_file(basename, filename) + except (IpmiError, TftpException): + # Fall back and use our tftp server + try: + result = self.bmc.fabric_get_depthchart(basename, + self.tftp_address) + except IpmiError as e: + raise IpmiError(self._parse_ipmierror(e)) + if hasattr(result, "error"): + raise IpmiError(result.error) + + deadline = time.time() + 10 + while time.time() < deadline: + try: + time.sleep(1) + self.tftp.get_file(src=basename, dest=filename) + if (os.path.getsize(filename) > 0): + break + except (TftpException, IOError): + pass + + results = {} + for line in open(filename): + if (line.startswith("Node")): + elements = line.strip().split() + target = int(elements[1].rstrip(':')) + neighbor = int(elements[8].rstrip(':')) + hops = int(elements[4].strip()) + dchrt_entries = [] + try: + other_hops_neighbors = elements[12].strip().split('[,\s]+') + for entry in other_hops_neighbors: + pair = entry.strip().split('/') + dchrt_entries.append((int(pair[1]), int(pair[0]))) + results[target] = (neighbor, hops), dchrt_entries + except: + results[target] = (neighbor, hops) + + # Make sure we found something + if (not results): + raise TftpException("Node failed to reach TFTP server") + + return results + def get_server_ip(self, interface=None, ipv6=False, user="user1", password="1Password", aggressive=False): """Get the IP address of the Linux server. The server must be powered |