From b5fbfe730d712bc001a92dfb75dba4debd12cc88 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Wed, 11 May 2016 17:03:05 -0400 Subject: [PATCH] Add nodeinventory command Provide a native confluent client alternative to 'rinv'. Also add missing flags to nodesetboot. --- confluent_client/bin/nodeeventlog | 2 +- confluent_client/bin/nodeinventory | 85 ++++++++++++++++++++++++++++ confluent_client/bin/nodesetboot | 21 ++++++- confluent_client/confluent/client.py | 7 ++- 4 files changed, 109 insertions(+), 6 deletions(-) create mode 100644 confluent_client/bin/nodeinventory diff --git a/confluent_client/bin/nodeeventlog b/confluent_client/bin/nodeeventlog index 9c026931..13997ae9 100644 --- a/confluent_client/bin/nodeeventlog +++ b/confluent_client/bin/nodeeventlog @@ -1,7 +1,7 @@ #!/usr/bin/python # vim: tabstop=4 shiftwidth=4 softtabstop=4 -# Copyright 2015 Lenovo +# Copyright 2015-2016 Lenovo # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/confluent_client/bin/nodeinventory b/confluent_client/bin/nodeinventory new file mode 100644 index 00000000..cd8cce71 --- /dev/null +++ b/confluent_client/bin/nodeinventory @@ -0,0 +1,85 @@ +#!/usr/bin/python +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright 2016 Lenovo +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys +path = os.path.dirname(os.path.realpath(__file__)) +path = os.path.realpath(os.path.join(path, '..', 'lib', 'python')) +if path.startswith('/opt'): + sys.path.append(path) + +import confluent.client as client + + +def print_mem_info(node, prefix, meminfo): + capacity = meminfo['capacity_mb'] / 1024 + memdescfmt = '{0}GB PC' + if meminfo['memory_type'] == 'DDR3 SDRAM': + memdescfmt += '3-{1} ' + elif meminfo['memory_type'] == 'DDR4 SDRAM': + memdescfmt += '4-{1} ' + if meminfo['ecc']: + memdescfmt += 'ECC ' + memdescfmt += meminfo['module_type'] + memdesc = memdescfmt.format(capacity, meminfo['speed']) + print('{0}: {1} description: {2}'.format(node, prefix, memdesc)) + print('{0}: {1} manufacturer: {2}'.format( + node, prefix, meminfo['manufacturer'])) + print('{0}: {1} model: {2}'.format(node, prefix, meminfo['model'])) + print('{0}: {1} serial number: {2}'.format(node, prefix, + meminfo['serial'])) + print('{0}: {1} manufacture date: {2}'.format(node, prefix, + meminfo['manufacture_date'])) + print('{0}: {1} manufacture location: {2}'.format( + node, prefix, meminfo['manufacture_location'])) + + +try: + noderange = sys.argv[1] +except IndexError: + sys.stderr.write( + 'Usage: {0} \n'.format( + sys.argv[0])) + sys.exit(1) +try: + session = client.Command() + for res in session.read('/noderange/{0}/inventory/hardware/all/all'.format( + noderange)): + for node in res['databynode']: + for inv in res['databynode'][node]['inventory']: + prefix = inv['name'] + if not inv['present']: + print '{0}: {1}: Not Present'.format(node, prefix) + continue + info = inv['information'] + info.pop('board_extra', None) + info.pop('oem_parser', None) + info.pop('chassis_extra', None) + info.pop('product_extra', None) + if 'memory_type' in info: + print_mem_info(node, prefix, info) + continue + for datum in info: + if info[datum] is None: + continue + print('{0}: {1} {2}: {3}'.format(node, prefix, datum, + info[datum])) + exitcode = 0 + sys.exit( + session.simple_noderange_command(noderange, '/inventory/hardware/all/all')) +except KeyboardInterrupt: + print('') diff --git a/confluent_client/bin/nodesetboot b/confluent_client/bin/nodesetboot index 48252047..35091cf4 100755 --- a/confluent_client/bin/nodesetboot +++ b/confluent_client/bin/nodesetboot @@ -15,6 +15,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import optparse import os import sys @@ -25,9 +26,19 @@ if path.startswith('/opt'): import confluent.client as client +argparser = optparse.OptionParser() +argparser.add_option('-b', '--bios', dest='biosmode', + action='store_true', default=False, + help='Request BIOS style boot (rather than UEFI)') +argparser.add_option('-p', '--persist', dest='persist', action='store_true', + default=False, + help='Request the boot device be persistent rather than ' + 'one time') + +(options, args) = argparser.parse_args() try: - noderange = sys.argv[1] + noderange = args[0] except IndexError: sys.stderr.write( 'Usage: {0} [default|cd|network|setup|hd]\n'.format( @@ -40,5 +51,11 @@ if len(sys.argv) > 2: bootdev = 'network' session = client.Command() exitcode = 0 +if options.biosmode: + bootmode = 'bios' +else: + bootmode = 'uefi' sys.exit( - session.simple_noderange_command(noderange, '/boot/nextdevice', bootdev)) \ No newline at end of file + session.simple_noderange_command(noderange, '/boot/nextdevice', bootdev, + bootmode=bootmode, + persistent=options.persist)) \ No newline at end of file diff --git a/confluent_client/confluent/client.py b/confluent_client/confluent/client.py index bbe584be..38ff2bbf 100644 --- a/confluent_client/confluent/client.py +++ b/confluent_client/confluent/client.py @@ -1,7 +1,7 @@ # vim: tabstop=4 shiftwidth=4 softtabstop=4 # Copyright 2014 IBM Corporation -# Copyright 2015 Lenovo +# Copyright 2015-2016 Lenovo # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -97,7 +97,7 @@ class Command(object): return rc def simple_noderange_command(self, noderange, resource, input=None, - key=None): + key=None, **kwargs): try: rc = 0 if resource[0] == '/': @@ -112,8 +112,9 @@ class Command(object): noderange, resource)): rc = self.handle_results(ikey, rc, res) else: + kwargs[ikey] = input for res in self.update('/noderange/{0}/{1}'.format( - noderange, resource), {ikey: input}): + noderange, resource), kwargs): rc = self.handle_results(ikey, rc, res) return rc except KeyboardInterrupt: