Skip to content

Commit

Permalink
Add IP address to the list column
Browse files Browse the repository at this point in the history
  • Loading branch information
mpryc committed Oct 15, 2019
1 parent 0b73863 commit 0d967a2
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 4 additions & 2 deletions devnest/lib/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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]


Expand Down
20 changes: 20 additions & 0 deletions devnest/lib/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import json
import re
import socket
import time

LOG = logger.LOG
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 0d967a2

Please sign in to comment.