diff --git a/confluent_client/bin/nodeconfig b/confluent_client/bin/nodeconfig index 78f46680..170fe335 100755 --- a/confluent_client/bin/nodeconfig +++ b/confluent_client/bin/nodeconfig @@ -187,8 +187,10 @@ if setmode: for path in updatebypath: for fr in session.update('/noderange/{0}/{1}'.format(noderange, path), updatebypath[path]): - for node in fr['databynode']: + rcode |= client.printerror(fr) + for node in fr.get('databynode', []): r = fr['databynode'][node] + exitcode |= client.printerror(r, node) if 'error' in r: sys.stderr.write(node + ': ' + r['error'] + '\n') if 'errorcode' in r: diff --git a/confluent_client/bin/nodefirmware b/confluent_client/bin/nodefirmware index 5ac9eba9..fa033961 100755 --- a/confluent_client/bin/nodefirmware +++ b/confluent_client/bin/nodefirmware @@ -35,18 +35,6 @@ import confluent.screensqueeze as sq exitcode = 0 -def printerror(res, node=None): - global exitcode - if 'errorcode' in res: - exitcode = res['errorcode'] - if 'error' in res: - if node: - sys.stderr.write('{0}: {1}\n'.format(node, res['error'])) - else: - sys.stderr.write('{0}\n'.format(res['error'])) - if 'errorcode' not in res: - exitcode = 1 - def printfirm(node, prefix, data): if 'model' in data: @@ -144,11 +132,11 @@ def show_firmware(session): for res in session.read( '/noderange/{0}/inventory/firmware/all/{1}'.format( noderange, component)): - printerror(res) + exitcode |= client.printerror(res) if 'databynode' not in res: continue for node in res['databynode']: - printerror(res['databynode'][node], node) + exitcode |= client.printerror(res['databynode'][node], node) if 'firmware' not in res['databynode'][node]: continue for inv in res['databynode'][node]['firmware']: diff --git a/confluent_client/confluent/client.py b/confluent_client/confluent/client.py index 42face02..7706da63 100644 --- a/confluent_client/confluent/client.py +++ b/confluent_client/confluent/client.py @@ -33,6 +33,20 @@ _attraliases = { 'bmcpass': 'secret.hardwaremanagementpassword', } + +def printerror(res, node=None): + if 'errorcode' in res: + exitcode = res['errorcode'] + if 'error' in res: + if node: + sys.stderr.write('{0}: {1}\n'.format(node, res['error'])) + else: + sys.stderr.write('{0}\n'.format(res['error'])) + if 'errorcode' not in res: + exitcode = 1 + return exitcode + + def cprint(txt): print(txt) sys.stdout.flush()