diff --git a/confluent_client/bin/nodeinventory b/confluent_client/bin/nodeinventory index eeaba71e..68d999b3 100755 --- a/confluent_client/bin/nodeinventory +++ b/confluent_client/bin/nodeinventory @@ -17,6 +17,7 @@ import optparse import os +import re import signal import sys @@ -31,6 +32,8 @@ if path.startswith('/opt'): import confluent.client as client +filters = [] + def pretty(text): if text == 'pcislot': @@ -76,6 +79,8 @@ def printerror(res, node=None): exitcode = 1 +url = '/noderange/{0}/inventory/hardware/all/all' + argparser = optparse.OptionParser(usage="Usage: %prog ") (options, args) = argparser.parse_args() try: @@ -83,12 +88,26 @@ try: except IndexError: argparser.print_help() sys.exit(1) -if len(args) > 1 and args[1] == 'firm': - os.execlp('nodefirmware', 'nodefirmware', noderange) +if len(args) > 1: + if args[1] == 'firm': + os.execlp('nodefirmware', 'nodefirmware', noderange) + else: + url = '/noderange/{0}/inventory/hardware/all/system' + for arg in args: + for arg in arg.split(','): + if arg == 'serial': + filters.append(re.compile('serial number')) + elif arg == 'model': + filters.append(re.compile('^model')) + filters.append(re.compile('product name')) + elif arg == 'uuid': + filters.append(re.compile('uuid')) + elif arg == 'mac': + filters.append(re.compile('mac address')) + url = '/noderange/{0}/inventory/hardware/all/all' try: session = client.Command() - for res in session.read('/noderange/{0}/inventory/hardware/all/all'.format( - noderange)): + for res in session.read(url.format(noderange)): printerror(res) if 'databynode' not in res: continue @@ -99,7 +118,8 @@ try: for inv in res['databynode'][node]['inventory']: prefix = inv['name'] if not inv['present']: - print '{0}: {1}: Not Present'.format(node, prefix) + if not filters: + print '{0}: {1}: Not Present'.format(node, prefix) continue info = inv['information'] info.pop('board_extra', None) @@ -107,9 +127,16 @@ try: info.pop('chassis_extra', None) info.pop('product_extra', None) if 'memory_type' in info: - print_mem_info(node, prefix, info) + if not filters: + print_mem_info(node, prefix, info) continue for datum in info: + if filters: + for filter in filters: + if filter.match(datum.lower()): + break + else: + continue if info[datum] is None: continue print(u'{0}: {1} {2}: {3}'.format(node, prefix,