mirror of
https://github.com/xcat2/confluent.git
synced 2026-09-02 07:26:04 +00:00
Report an inventory filter that matched nothing
Asking for the mac addresses of a node whose inventory does not describe any, which is every node reached over ipmi, printed absolutely nothing and exited successfully, leaving no way to tell an empty answer from a broken command. Name what was asked for instead. The exit code stays successful, since an inventory that does not mention something is a valid answer rather than a failure.
This commit is contained in:
@@ -38,6 +38,8 @@ if sys.version_info[0] < 3:
|
||||
sys.stdout = codecs.getwriter('utf8')(sys.stdout)
|
||||
|
||||
filters = []
|
||||
wanted = []
|
||||
matched = False
|
||||
|
||||
|
||||
def pretty(text):
|
||||
@@ -123,6 +125,8 @@ if len(args) > 1:
|
||||
url = '/noderange/{0}/inventory/hardware/all/system'
|
||||
for rawarg in args:
|
||||
for arg in rawarg.split(','):
|
||||
if arg in ('serial', 'model', 'uuid', 'mac'):
|
||||
wanted.append(arg)
|
||||
if arg == 'serial':
|
||||
filters.append(re.compile('serial number'))
|
||||
elif arg == 'model':
|
||||
@@ -203,6 +207,7 @@ try:
|
||||
continue
|
||||
if info[datum] is None:
|
||||
continue
|
||||
matched = True
|
||||
if options.json:
|
||||
if node not in databynode:
|
||||
databynode[node] = {}
|
||||
@@ -212,6 +217,11 @@ try:
|
||||
print(u'{0}: {1} {2}: {3}'.format(node, prefix,
|
||||
pretty(datum),
|
||||
info[datum]))
|
||||
if filters and not matched and not options.store:
|
||||
# An inventory that does not describe what was asked for is a valid
|
||||
# answer, but saying nothing at all leaves the caller guessing
|
||||
sys.stderr.write('No {0} reported for "{1}"\n'.format(
|
||||
'/'.join(wanted) if wanted else 'matching inventory', noderange))
|
||||
if options.json:
|
||||
print(json.dumps(databynode, sort_keys=True, indent=4,
|
||||
separators=(',', ': ')))
|
||||
|
||||
Reference in New Issue
Block a user