From 0d967a2a781748fc9105af14ceacd183fc2d36e7 Mon Sep 17 00:00:00 2001 From: Michal Date: Tue, 15 Oct 2019 14:14:33 +0200 Subject: [PATCH] Add IP address to the list column --- ChangeLog | 1 + devnest/lib/cli.py | 6 ++++-- devnest/lib/node.py | 20 ++++++++++++++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 64841db..4877fad 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,7 @@ CHANGES ======= +* Add dump config options * Add directory options to update multiply slaves at once * Ensure force reservation is only for not reserved nodes * Add force reserve without specific node diff --git a/devnest/lib/cli.py b/devnest/lib/cli.py index 10d80cf..b36a0ff 100755 --- a/devnest/lib/cli.py +++ b/devnest/lib/cli.py @@ -51,9 +51,9 @@ class Action(object): class Columns(object): """Enumeration for the columns.""" (HOST, STATE, RAM, CPU, RESERVED, UNTIL, GROUPS, - CAPABILITIES) = range(8) + CAPABILITIES, IP_ADDRESS) = range(9) - DEFAULT = 'host,state,ram,cpu,reserved,until' + DEFAULT = 'host,state,ram,cpu,reserved,until,ip_address' DEFAULT_JSON = 'state,host' @staticmethod @@ -78,6 +78,7 @@ def to_str(column): Columns.UNTIL: 'Reserved until', Columns.GROUPS: 'Groups', Columns.CAPABILITIES: 'Capabilities', + Columns.IP_ADDRESS: 'IP Address', }[column] @staticmethod @@ -92,6 +93,7 @@ def to_data(node, column): Columns.GROUPS: ",".join(sorted( node.node_details.get_node_labels())), Columns.CAPABILITIES: node.node_details.get_capabilities(), + Columns.IP_ADDRESS: node.get_node_ip_address(), }[column] diff --git a/devnest/lib/node.py b/devnest/lib/node.py index 365c964..c42d59d 100755 --- a/devnest/lib/node.py +++ b/devnest/lib/node.py @@ -25,6 +25,7 @@ import json import re +import socket import time LOG = logger.LOG @@ -507,6 +508,25 @@ def get_node_status_str(self): return "Unknown" + def get_node_ip_address(self): + """Return IP address of the node. + + Returns: + (:obj:`str`): node IP address or empty string + """ + ip_address = None + description = self.node_data.get('description') + ip_address = re.findall(r'[0-9]+(?:\.[0-9]+){3}', description) + + if ip_address and len(ip_address) == 1: + try: + socket.inet_aton(ip_address[0]) + ip_address = ip_address[0] + except socket.error: + ip_address = "" + + return ip_address + def get_name(self): """Return name of the node.