summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Kraft <george.kraft@calxeda.com>2013-03-12 11:58:28 -0500
committerGeorge Kraft <george.kraft@calxeda.com>2013-03-12 11:58:28 -0500
commit81f434f8381551701736d7277311cb3997ccd586 (patch)
treee379ba10215372c0a16b8e360c3ad58531e99100
parentba491b5d339a6a319b024561fe4cfbc75c299070 (diff)
downloadcxmanage-81f434f8381551701736d7277311cb3997ccd586.tar.gz
CXMAN-159: Add a -i/--ids command line option to display node IDs
For commands that normally don't display node IDs (power status, sensor, etc), this option will display node IDs alongside their IP addresses in the output. We'll stick to the old behavior by default though.
-rw-r--r--cxmanage/__init__.py28
-rw-r--r--cxmanage/commands/config.py6
-rw-r--r--cxmanage/commands/fw.py7
-rw-r--r--cxmanage/commands/info.py11
-rw-r--r--cxmanage/commands/ipdiscover.py5
-rw-r--r--cxmanage/commands/ipmitool.py5
-rw-r--r--cxmanage/commands/power.py13
-rw-r--r--cxmanage/commands/sensor.py12
-rwxr-xr-xscripts/cxmanage4
9 files changed, 59 insertions, 32 deletions
diff --git a/cxmanage/__init__.py b/cxmanage/__init__.py
index d205b56..c6f31b3 100644
--- a/cxmanage/__init__.py
+++ b/cxmanage/__init__.py
@@ -96,13 +96,15 @@ def get_nodes(args, tftp, verify_prompt=False):
new_node = Node(ip_address=ip_address, username=args.user,
password=args.password, tftp=tftp,
verbose=args.verbose)
+ new_node.node_id = node_id
if not new_node in all_nodes:
all_nodes.append(new_node)
+ node_strings = get_node_strings(args, all_nodes, justify=False)
if not args.quiet and all_nodes:
print "Discovered the following IP addresses:"
for node in all_nodes:
- print node.ip_address
+ print node_strings[node]
print
if errors:
@@ -124,6 +126,22 @@ def get_nodes(args, tftp, verify_prompt=False):
return nodes
+def get_node_strings(args, nodes, justify=False):
+ """ Get string representations for the nodes. """
+ # Use the private _node_id instead of node_id. Strange choice,
+ # but we want to avoid accidentally polling the BMC.
+ if args.ids and all(x._node_id != None for x in nodes):
+ strings = ["Node %i (%s)" % (x._node_id, x.ip_address) for x in nodes]
+ else:
+ strings = [x.ip_address for x in nodes]
+
+ if justify:
+ just_size = max(16, max(len(x) for x in strings) + 1)
+ strings = [x.ljust(just_size) for x in strings]
+
+ return dict(zip(nodes, strings))
+
+
def run_command(args, nodes, name, *method_args):
if args.threads != None:
task_queue = TaskQueue(threads=args.threads, delay=args.command_delay)
@@ -168,7 +186,7 @@ def run_command(args, nodes, name, *method_args):
# Handle errors
should_retry = False
if errors:
- _print_errors(nodes, errors)
+ _print_errors(args, nodes, errors)
if args.retry == None:
sys.stdout.write("Retry command on failed hosts? (y/n): ")
sys.stdout.flush()
@@ -273,14 +291,14 @@ def parse_ip_range_entry(entry):
return addresses
-def _print_errors(nodes, errors):
+def _print_errors(args, nodes, errors):
""" Print errors if they occured """
if errors:
+ node_strings = get_node_strings(args, nodes, justify=True)
print "Command failed on these hosts"
for node in nodes:
if node in errors:
- print "%s: %s" % (node.ip_address.ljust(16),
- errors[node])
+ print "%s: %s" % (node_strings[node], errors[node])
print
# Print a special message for TFTP errors
diff --git a/cxmanage/commands/config.py b/cxmanage/commands/config.py
index 9fa4426..c92c078 100644
--- a/cxmanage/commands/config.py
+++ b/cxmanage/commands/config.py
@@ -28,7 +28,7 @@
# THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
# DAMAGE.
-from cxmanage import get_tftp, get_nodes, run_command
+from cxmanage import get_tftp, get_nodes, get_node_strings, run_command
from cxmanage_api.ubootenv import UbootEnv
@@ -86,11 +86,11 @@ def config_boot_status_command(args):
# Print results
if results:
+ node_strings = get_node_strings(args, results, justify=True)
print "Boot order"
for node in nodes:
if node in results:
- print "%s: %s" % (node.ip_address.ljust(16),
- ",".join(results[node]))
+ print "%s: %s" % (node_strings[node], ",".join(results[node]))
print
if not args.quiet and errors:
diff --git a/cxmanage/commands/fw.py b/cxmanage/commands/fw.py
index 8c97ad0..3af1fd2 100644
--- a/cxmanage/commands/fw.py
+++ b/cxmanage/commands/fw.py
@@ -28,7 +28,8 @@
# THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
# DAMAGE.
-from cxmanage import get_tftp, get_nodes, run_command, prompt_yes
+from cxmanage import get_tftp, get_nodes, get_node_strings, run_command, \
+ prompt_yes
from cxmanage_api.image import Image
from cxmanage_api.firmware_package import FirmwarePackage
@@ -64,7 +65,6 @@ def fwupdate_command(args):
'WARNING: Updating firmware without --all-nodes is dangerous. Continue?'):
return 1
-
tftp = get_tftp(args)
nodes = get_nodes(args, tftp, verify_prompt=True)
@@ -100,9 +100,10 @@ def fwinfo_command(args):
results, errors = run_command(args, nodes, "get_firmware_info")
+ node_strings = get_node_strings(args, results, justify=False)
for node in nodes:
if node in results:
- print "[ Firmware info for %s ]" % node.ip_address
+ print "[ Firmware info for %s ]" % node_strings[node]
for partition in results[node]:
print "Partition : %s" % partition.partition
diff --git a/cxmanage/commands/info.py b/cxmanage/commands/info.py
index 97d1e47..95f63d9 100644
--- a/cxmanage/commands/info.py
+++ b/cxmanage/commands/info.py
@@ -28,7 +28,7 @@
# THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
# DAMAGE.
-from cxmanage import get_tftp, get_nodes, run_command
+from cxmanage import get_tftp, get_nodes, get_node_strings, run_command
def info_command(args):
@@ -62,10 +62,11 @@ def info_basic_command(args):
results, errors = run_command(args, nodes, "get_versions")
# Print results
+ node_strings = get_node_strings(args, results, justify=False)
for node in nodes:
if node in results:
result = results[node]
- print "[ Info from %s ]" % node.ip_address
+ print "[ Info from %s ]" % node_strings[node]
print "Hardware version : %s" % result.hardware_version
print "Firmware version : %s" % result.firmware_version
for var, string in components:
@@ -89,10 +90,11 @@ def info_ubootenv_command(args):
results, errors = run_command(args, nodes, "get_ubootenv")
# Print results
+ node_strings = get_node_strings(args, results, justify=False)
for node in nodes:
if node in results:
ubootenv = results[node]
- print "[ U-Boot Environment from %s ]" % node.ip_address
+ print "[ U-Boot Environment from %s ]" % node_strings[node]
for variable in ubootenv.variables:
print "%s=%s" % (variable, ubootenv.variables[variable])
print
@@ -112,9 +114,10 @@ def info_dump_command(args):
results, errors = run_command(args, nodes, "info_dump")
# Print results
+ node_strings = get_node_strings(args, results, justify=False)
for node in nodes:
if node in results:
- print "[ Info dump from %s ]" % node.ip_address
+ print "[ Info dump from %s ]" % node_strings[node]
print results[node]
print
diff --git a/cxmanage/commands/ipdiscover.py b/cxmanage/commands/ipdiscover.py
index 279b62b..f619d16 100644
--- a/cxmanage/commands/ipdiscover.py
+++ b/cxmanage/commands/ipdiscover.py
@@ -28,7 +28,7 @@
# THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
# DAMAGE.
-from cxmanage import get_tftp, get_nodes, run_command
+from cxmanage import get_tftp, get_nodes, get_node_strings, run_command
def ipdiscover_command(args):
@@ -43,10 +43,11 @@ def ipdiscover_command(args):
args.ipv6, args.server_user, args.server_password, args.aggressive)
if results:
+ node_strings = get_node_strings(args, results, justify=True)
print 'IP addresses (ECME, Server)'
for node in nodes:
if node in results:
- print '%s: %s' % (node.ip_address.ljust(16), results[node])
+ print '%s: %s' % (node_strings[node], results[node])
print
if not args.quiet and errors:
diff --git a/cxmanage/commands/ipmitool.py b/cxmanage/commands/ipmitool.py
index 0c03bf1..f8baf80 100644
--- a/cxmanage/commands/ipmitool.py
+++ b/cxmanage/commands/ipmitool.py
@@ -28,7 +28,7 @@
# THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
# DAMAGE.
-from cxmanage import get_tftp, get_nodes, run_command
+from cxmanage import get_tftp, get_nodes, get_node_strings, run_command
def ipmitool_command(args):
@@ -47,9 +47,10 @@ def ipmitool_command(args):
ipmitool_args)
# Print results
+ node_strings = get_node_strings(args, results, justify=False)
for node in nodes:
if node in results and results[node] != "":
- print "[ IPMItool output from %s ]" % node.ip_address
+ print "[ IPMItool output from %s ]" % node_strings[node]
print results[node]
print
diff --git a/cxmanage/commands/power.py b/cxmanage/commands/power.py
index 44736c4..b5b6015 100644
--- a/cxmanage/commands/power.py
+++ b/cxmanage/commands/power.py
@@ -28,7 +28,7 @@
# THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
# DAMAGE.
-from cxmanage import get_tftp, get_nodes, run_command
+from cxmanage import get_tftp, get_nodes, get_node_strings, run_command
def power_command(args):
@@ -57,14 +57,12 @@ def power_status_command(args):
# Print results
if results:
+ node_strings = get_node_strings(args, results, justify=True)
print 'Power status'
for node in nodes:
if node in results:
- if results[node]:
- result = 'on'
- else:
- result = 'off'
- print '%s: %s' % (node.ip_address.ljust(16), result)
+ result = 'on' if results[node] else 'off'
+ print '%s: %s' % (node_strings[node], result)
print
if not args.quiet and errors:
@@ -99,10 +97,11 @@ def power_policy_status_command(args):
# Print results
if results:
+ node_strings = get_node_strings(args, results, justify=True)
print 'Power policy status'
for node in nodes:
if node in results:
- print '%s: %s' % (node.ip_address.ljust(16), results[node])
+ print '%s: %s' % (node_strings[node], results[node])
print
if not args.quiet and errors:
diff --git a/cxmanage/commands/sensor.py b/cxmanage/commands/sensor.py
index 0c9ecbb..c3fed32 100644
--- a/cxmanage/commands/sensor.py
+++ b/cxmanage/commands/sensor.py
@@ -28,7 +28,7 @@
# THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
# DAMAGE.
-from cxmanage import get_tftp, get_nodes, run_command
+from cxmanage import get_tftp, get_nodes, get_node_strings, run_command
def sensor_command(args):
@@ -56,20 +56,22 @@ def sensor_command(args):
except ValueError:
sensors[sensor_name].append((node, reading, ""))
+ node_strings = get_node_strings(args, results, justify=True)
+ jsize = len(node_strings.itervalues().next())
for sensor_name, readings in sensors.iteritems():
print sensor_name
for node, reading, suffix in readings:
- print "%s: %.2f %s" % (node.ip_address.ljust(16), reading, suffix)
+ print "%s: %.2f %s" % (node_strings[node], reading, suffix)
try:
if all(suffix == x[2] for x in readings):
minimum = min(x[1] for x in readings)
maximum = max(x[1] for x in readings)
average = sum(x[1] for x in readings) / len(readings)
- print "Minimum : %.2f %s" % (minimum, suffix)
- print "Maximum : %.2f %s" % (maximum, suffix)
- print "Average : %.2f %s" % (average, suffix)
+ print "%s: %.2f %s" % ("Minimum".ljust(jsize), minimum, suffix)
+ print "%s: %.2f %s" % ("Maximum".ljust(jsize), maximum, suffix)
+ print "%s: %.2f %s" % ("Average".ljust(jsize), average, suffix)
except ValueError:
pass
diff --git a/scripts/cxmanage b/scripts/cxmanage
index 469bf32..2a09272 100755
--- a/scripts/cxmanage
+++ b/scripts/cxmanage
@@ -79,6 +79,8 @@ def build_parser():
default=None)
parser.add_argument('-n', '--nodes', metavar='COUNT', type=int,
help='Expected number of nodes')
+ parser.add_argument('-i', '--ids', action='store_true',
+ help='Display node IDs in addition to IP addresses')
verbosity = parser.add_mutually_exclusive_group()
verbosity.add_argument('-v', '--verbose', action='store_true',
help='Verbose output')
@@ -258,7 +260,7 @@ def build_parser():
help='Server-side Linux password')
ipdiscover.add_argument('-6', '--ipv6', action='store_true',
help='Discover IPv6 addresses')
- ipdiscover.add_argument('-i', '--interface', type=str, default=None,
+ ipdiscover.add_argument('-I', '--interface', type=str, default=None,
help='Network interface to check')
ipdiscover.set_defaults(func=ipdiscover_command)