def CollectInventory(arglist): parser = ArgumentParser(description='Inventory Collector') parser.add_argument('-u', '--user', action="store", dest="user", type=str, nargs='?', default='root', help="Username to use for iDRAC") parser.add_argument('-p', '--password', action="store", dest="password", type=str, default='calvin', help="Password to use for iDRAC") parser.add_argument('-i', '--ipaddress', action="store", dest="idrac_ip", nargs='+', help="ipaddress of iDRAC") parser.add_argument('-f', '--folder', action="store", dest="folder", type=str, help="folder from where inventory is serialized") options = parser.parse_args(arglist) if options.password is None: print("password must be provided") return -1 if options.user is None: print("user must be provided") return -1 if options.folder is None: print("Folder must be provided") return -1 if options.idrac_ip is None or len(options.idrac_ip) <= 0: print("iDRAC ip addresses must be provided") return -1 updshare = LocalFile(local = options.folder, isFolder=True) if not updshare.IsValid: print("Folder is not writable!") return -2 print("Configuring Update Share...") UpdateManager.configure(updshare) sd = sdkinfra() sd.importPath() creds = UserCredentials(options.user, options.password) for ipaddr in options.idrac_ip: try: print("Connecting to " + ipaddr + " ... ") idrac = sd.get_driver(sd.driver_enum.iDRAC, ipaddr, creds) if idrac: print(" ... saving firmware!") UpdateHelper.save_firmware_inventory(idrac) idrac.disconnect() else: print(" failed to connect to iDRAC") except Exception as ex: print(str(ex))
def sw_inventory(idrac, module): """ Get Firmware Inventory Keyword arguments: idrac -- iDRAC handle module -- Ansible module """ msg = {} msg['changed'] = False msg['failed'] = False msg['msg'] = {} error = False try: if module.params['choice'] == "all": msg['msg'] = idrac.update_mgr.get_swidentity() elif module.params['choice'] == "installed": msg['msg'] = idrac.update_mgr.InstalledFirmware if module.params['serialize']: fw_inv_path = LocalFile(local=module.params['share_mnt'], isFolder=True) if fw_inv_path.IsValid: UpdateManager.configure(fw_inv_path) msg['msg'] = UpdateHelper.save_firmware_inventory(idrac) if "Status" in msg['msg'] and msg['msg']['Status'] != "Success": msg['failed'] = True else: msg['msg'] = "Error: Network share is not valid" msg['failed'] = True except Exception as err: error = True msg['msg'] = "Error: %s" % str(err) msg['exception'] = traceback.format_exc() msg['failed'] = True return msg, error