summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Kraft <george.kraft@calxeda.com>2013-12-09 15:04:57 -0600
committerGeorge Kraft <george.kraft@calxeda.com>2013-12-09 15:04:57 -0600
commitc63a907329c5b59a5f7821ae0f3146a6001d8983 (patch)
treef633b68ebdc140812e76dd1c96b89d491b0fd5c8
parentc0da16130c98f54aaf1c556420761e86be876c66 (diff)
downloadcxmanage-c63a907329c5b59a5f7821ae0f3146a6001d8983.tar.gz
CXMAN-265: Raise an error if we get 0.0.0.0 in IP info
This generally indicates something's wrong. There's some node that we're not getting access to. For the cxmanage command line tool, the --force option can be used to ignore it and keep going.
-rw-r--r--cxmanage_api/cli/__init__.py4
-rw-r--r--cxmanage_api/node.py17
2 files changed, 18 insertions, 3 deletions
diff --git a/cxmanage_api/cli/__init__.py b/cxmanage_api/cli/__init__.py
index f57a394..6eb94f2 100644
--- a/cxmanage_api/cli/__init__.py
+++ b/cxmanage_api/cli/__init__.py
@@ -108,7 +108,9 @@ def get_nodes(args, tftp, verify_prompt=False):
if not args.quiet:
print("Getting IP addresses...")
- results, errors = run_command(args, nodes, "get_fabric_ipinfo")
+ results, errors = run_command(
+ args, nodes, "get_fabric_ipinfo", args.force
+ )
all_nodes = []
for node in nodes:
diff --git a/cxmanage_api/node.py b/cxmanage_api/node.py
index f71a380..373e398 100644
--- a/cxmanage_api/node.py
+++ b/cxmanage_api/node.py
@@ -1188,12 +1188,15 @@ communication.
image = self._download_image(partition)
return self.ubootenv(open(image.filename).read())
- def get_fabric_ipinfo(self):
+ def get_fabric_ipinfo(self, allow_errors=False):
"""Gets what ip information THIS node knows about the Fabric.
>>> node.get_fabric_ipinfo()
{0: '10.20.1.9', 1: '10.20.2.131', 2: '10.20.0.220', 3: '10.20.2.5'}
+ :param allow_errors: Skip IP parsing errors
+ :type allow_errors: boolean
+
:return: Returns a map of node_ids->ip_addresses.
:rtype: dictionary
@@ -1214,7 +1217,17 @@ communication.
elements = line.split()
node_id = int(elements[1].rstrip(":"))
ip_address = elements[2]
- socket.inet_aton(ip_address) # IP validity check
+
+ # IP validity check
+ try:
+ socket.inet_aton(ip_address)
+ if ip_address == "0.0.0.0":
+ raise ValueError("Invalid IP address 0.0.0.0")
+ except (socket.error, ValueError):
+ if allow_errors:
+ continue
+ raise
+
results[node_id] = ip_address
return results
except (IndexError, ValueError, socket.error):