def elcm_online_update(module): if module.params['command'] == "check": uri = "rest/v1/Oem/eLCM/OnlineUpdate" if module.params['skip_hcl_verify'] is True: uri = uri + "?skipHCLVerification=yes" status, elcmdata, msg = irmc_redfish_post(module, uri, "") else: status, elcmdata, msg = irmc_redfish_put( module, "rest/v1/Oem/eLCM/OnlineUpdate/updateCollection", "") if status < 100: module.fail_json(msg=msg, status=status, exception=elcmdata) elif status == 409: result[ 'msg'] = "Cannot {0} eLCM update, another session is in progress.".format( module.params['command']) result['status'] = status module.fail_json(**result) elif status not in (200, 202, 204): module.fail_json(msg=msg, status=status) if module.params['wait_for_finish'] is True: # check that current session is terminated status, data, msg = waitForSessionToFinish( module, get_irmc_json(elcmdata.json(), ["Session", "Id"])) if status > 30 and status < 100: module.fail_json(msg=msg, status=status, exception=data) elif status not in (200, 202, 204): module.fail_json(msg=msg, log=data, status=status) result['changed'] = True
def create_profile(module): url = "rest/v1/Oem/eLCM/ProfileManagement/get?PARAM_PATH=Server/{0}".format( module.params['profile']) status, sysdata, msg = irmc_redfish_post(module, url, "") if status < 100: module.fail_json(msg=msg, status=status, exception=sysdata) elif status == 404: result['msg'] = "Requested profile '{0}' cannot be created.".format( module.params['profile']) module.fail_json(msg=msg, status=status) elif status == 409: result['msg'] = "Requested profile '{0}' already exists.".format( module.params['profile']) result['skipped'] = True module.exit_json(**result) elif status not in (200, 202, 204): module.fail_json(msg=msg, status=status) if module.params['wait_for_finish'] is True: # check that current session is terminated status, data, msg = waitForSessionToFinish( module, get_irmc_json(sysdata.json(), ["Session", "Id"])) if status > 30 and status < 100: module.fail_json(msg=msg, status=status, exception=data) elif status not in (200, 202, 204): module.fail_json(msg=msg, log=data, status=status) result['changed'] = True
def set_default_bootorder(module): new_profile = { "Server": { "@Version": "1.01", "SystemConfig": { "BiosConfig": { "@Processing": "execute", "BiosBootOrder": { "BootOrderApply": True, "BootOrderReset": True }, "@Version": "1.03" } } } } if module.params['next_boot_device'] is not None: new_profile['Server']['SystemConfig']['BiosConfig']['BiosBootOrder']['NextBootDevice'] = \ module.params['next_boot_device'] # Set new boot profile status, data, msg = irmc_redfish_post(module, "rest/v1/Oem/eLCM/ProfileManagement/set", json.dumps(new_profile)) if status < 100: module.fail_json(msg=msg, status=status, exception=data) elif status not in (200, 202, 204): module.fail_json(msg=msg, status=status) # check that current session is terminated status, data, msg = waitForSessionToFinish(module, get_irmc_json(data.json(), ["Session", "Id"])) if status > 30 and status < 100: module.fail_json(msg=msg, status=status, exception=data) elif status not in (200, 202, 204): module.fail_json(msg=msg, log=data, status=status)
def force_new_boot_profile(module): # check whether 'Automatic BiosParameter Backup' is set scci_map = [ # Param, SCCI Name, SCCI Code, value [ "bios_backup_enabled", "ConfPermanentBiosConfigStorageEnabled", 0x1CC0, None ], ["bios_config_active", "ConfPermanentBiosConfigActive", 0x2721, None], ] datadict = dict() datadict['bios_backup_enabled'] = None datadict['bios_config_active'] = None body = scci_body_start for elem in scci_map: body += add_scci_command("GET", scci_map, elem[1], 0, '') body += scci_body_end # send command list to scripting interface status, data, msg = irmc_scci_post(module, body) if status < 100: module.fail_json(msg=msg, status=status, exception=data) elif status not in (200, 202, 204, 404): module.fail_json(msg=msg, status=status) # evaluate results list datadict, scciresult, sccicontext = get_scciresultlist( data.content, datadict, scci_map) if scciresult != 0: module.fail_json(msg=sccicontext, status=status) # we only need to generate a new profile if 'Automatic BiosParameter Backup' is not set and active if datadict['bios_backup_enabled'] == "0" or datadict[ 'bios_config_active'] == "0": # Delete current Boot Profile Data (if it exists) status, sysdata, msg = irmc_redfish_delete( module, "rest/v1/Oem/eLCM/ProfileManagement/BiosBootOrder") if status < 100: module.fail_json(msg=msg, status=status, exception=sysdata) elif status not in (200, 202, 204, 404): module.fail_json(msg=msg, status=status) # Generate new Boot Profile Data url = "/rest/v1/Oem/eLCM/ProfileManagement/get?PARAM_PATH=Server/SystemConfig/BiosConfig/BiosBootOrder" status, sysdata, msg = irmc_redfish_post(module, url, "") if status < 100: module.fail_json(msg=msg, status=status, exception=sysdata) elif status not in (200, 202, 204): module.fail_json(msg=msg, status=status) # check that current session is terminated status, data, msg = waitForSessionToFinish( module, get_irmc_json(sysdata.json(), ["Session", "Id"])) if status > 30 and status < 100: module.fail_json(msg=msg, status=status, exception=data) elif status not in (200, 202, 204): module.fail_json(msg=msg, log=data, status=status)
def waitForIrmcSessionsInactive(module): # Get iRMC Profile processing state status, sessiondata, msg = irmc_redfish_get(module, "sessionInformation") if status < 100: module.fail_json(msg=msg, status=status, exception=sessiondata) elif status not in (200, 202, 204): module.fail_json(msg=msg, status=status) sessions = get_irmc_json(sessiondata.json(), ["SessionList"]) for status, session in sessions.items(): for item in session: for ikey, value in item.items(): if ikey == "#text" and "Profile" in value: status, sessiondata, msg = waitForSessionToFinish(module, item['@Id']) continue
def get_raid_data(module): # make sure RAIDAdapter profile is up-to-date status, sysdata, msg = irmc_redfish_delete( module, "/rest/v1/Oem/eLCM/ProfileManagement/RAIDAdapter") if status < 100: module.fail_json(msg=msg, status=status, exception=sysdata) elif status not in (200, 202, 204, 404): module.fail_json(msg=msg, status=status) url = "rest/v1/Oem/eLCM/ProfileManagement/get?PARAM_PATH=Server/HWConfigurationIrmc/Adapters/RAIDAdapter" status, sysdata, msg = irmc_redfish_post(module, url, "") if status < 100: module.fail_json(msg=msg, status=status, exception=sysdata) elif status == 404: result[ 'msg'] = "Requested profile 'HWConfigurationIrmc/Adapters/RAIDAdapter' cannot be created." module.fail_json(msg=msg, status=status) elif status == 409: result[ 'msg'] = "Requested profile 'HWConfigurationIrmc/Adapters/RAIDAdapter' already exists." module.fail_json(msg=msg, status=status) elif status not in (200, 202, 204): module.fail_json(msg=msg, status=status) if module.params['wait_for_finish'] is True: # check that current session is terminated status, data, msg = waitForSessionToFinish( module, get_irmc_json(sysdata.json(), ["Session", "Id"])) if status > 30 and status < 100: module.fail_json(msg=msg, status=status, exception=data) elif status not in (200, 202, 204): module.fail_json(msg=msg, log=data, status=status) status, sysdata, msg = irmc_redfish_get( module, "/rest/v1/Oem/eLCM/ProfileManagement/RAIDAdapter") if status < 100: module.fail_json(msg=msg, status=status, exception=sysdata) elif status == 404: module.fail_json( msg= "Requested profile 'HWConfigurationIrmc/Adapters/RAIDAdapter' does not exist.", status=status) elif status != 200: module.fail_json(msg=msg, status=status) return sysdata.json()
def import_profile(module): if module.params['profile_json'] is None: try: with open(module.params['profile_path']) as infile: irmc_profile = json.load(infile) except Exception: result[ 'msg'] = "Could not read JSON profile data from file '{0}'".format( module.params['profile_path']) result['status'] = 20 module.fail_json(**result) else: try: irmc_profile = json.loads(module.params['profile_json']) except Exception: result['msg'] = "Profile data are not proper JSON '{0}'.".format( module.params['profile_json']) result['status'] = 21 module.fail_json(**result) irmc_profile = checkandupdate_irmc_profile(module, irmc_profile) # Set new profile status, sysdata, msg = irmc_redfish_post( module, "rest/v1/Oem/eLCM/ProfileManagement/set", json.dumps(irmc_profile)) if status < 100: module.fail_json(msg=msg, status=status, exception=sysdata) elif status == 404: result['msg'] = "Requested profile '{0}' cannot be imported.".format( module.params['profile']) module.fail_json(msg=msg, status=status) elif status not in (200, 202, 204): module.fail_json(msg=msg, status=status) if module.params['wait_for_finish'] is True: # check that current session is terminated status, data, msg = waitForSessionToFinish( module, get_irmc_json(sysdata.json(), ["Session", "Id"])) if status > 30 and status < 100: module.fail_json(msg=msg, status=status, exception=data) elif status not in (200, 202, 204): module.fail_json(msg=msg, log=data, status=status) result['changed'] = True
def apply_raid_configuration(module, body): status, sysdata, msg = irmc_redfish_post(module, "rest/v1/Oem/eLCM/ProfileManagement/set", json.dumps(body)) if status < 100: module.fail_json(msg=msg, status=status, exception=sysdata) elif status == 406: result['msg'] = "Raid Configuration cannot be {0}d.".format(module.params['command']) module.fail_json(msg=msg, status=status) elif status not in (200, 202, 204): module.fail_json(msg=msg, status=status) if module.params['wait_for_finish'] is True: # check that current session is terminated status, data, msg = waitForSessionToFinish(module, get_irmc_json(sysdata.json(), ["Session", "Id"])) if status > 30 and status < 100: module.fail_json(msg=msg, status=status, exception=data) elif status not in (200, 202, 204): module.fail_json(msg=msg, log=data, status=status) result['changed'] = True
def set_elcm_data(module): body = {'Repository': {}} if module.params['server'] is not None or module.params['catalog'] is not None or \ module.params['use_proxy'] is not None: body['Repository']['Server'] = {} if module.params['server'] is not None: body['Repository']['Server']['URL'] = module.params['server'] if module.params['catalog'] is not None: body['Repository']['Server']['Catalog'] = module.params['catalog'] if module.params['use_proxy'] is not None: body['Repository']['Server']['UseProxy'] = true_false.get( module.params['use_proxy']) if module.params['proxy_url'] is not None or module.params['proxy_port'] is not None or \ module.params['proxy_user'] is not None or module.params['proxy_password'] is not None: body['Repository']['Proxy'] = {} if module.params['proxy_url'] is not None: body['Repository']['Proxy']['URL'] = module.params['proxy_url'] if module.params['proxy_port'] is not None: body['Repository']['Proxy']['Port'] = module.params['proxy_port'] if module.params['proxy_user'] is not None: body['Repository']['Proxy']['User'] = module.params['proxy_user'] if module.params['proxy_password'] is not None and module.params[ 'proxy_password'] != "": body['Repository']['Proxy']['Password'] = module.params[ 'proxy_password'] status, elcmdata, msg = irmc_redfish_put( module, "rest/v1/Oem/eLCM/Repository/Update", json.dumps(body)) if status < 100: module.fail_json(msg=msg, status=status, exception=elcmdata) elif status not in (200, 202, 204): module.fail_json(msg=msg, status=status) if module.params['wait_for_finish'] is True: # check that current session is terminated status, data, msg = waitForSessionToFinish( module, get_irmc_json(elcmdata.json(), ["Session", "Id"])) if status > 30 and status < 100: module.fail_json(msg=msg, status=status, exception=data) elif status not in (200, 202, 204): module.fail_json(msg=msg, log=data, status=status)
def irmc_biosbootorder(module): # initialize result result['changed'] = False result['status'] = 0 if module.check_mode: result['msg'] = "module was not run" module.exit_json(**result) # preliminary parameter check preliminary_parameter_check(module) # check that all iRMC Profile processing states are terminated waitForIrmcSessionsInactive(module) if module.params['command'] == "default": set_default_bootorder(module) result['changed'] = True module.exit_json(**result) if module.params['force_new'] is True: force_new_boot_profile(module) # Get Boot Profile Data boot_profile_data = get_boot_profile_data(module) devices = get_irmc_json(boot_profile_data, ["Server", "SystemConfig", "BiosConfig", "BiosBootOrder", "Devices"]) if module.params['command'] == "get": for status, devicelist in devices.items(): result['boot_order'] = [] for device in devicelist: bo = {} bo['DeviceIdx'] = device['@DeviceIdx'] bo['DeviceName'] = device['DeviceName'] bo['StructuredBootString'] = device['StructuredBootString'] result['boot_order'].append(bo) module.exit_json(**result) # setup new boot order new_profile = setup_new_boot_profile(module, boot_profile_data) comparison_list = [] comparison_result, comparison_list = compare_irmc_profile(boot_profile_data, new_profile, "", "", comparison_list) if comparison_result is True: result['skipped'] = True result['msg'] = "Bios boot order is already as requested." module.exit_json(**result) # activate the new profile new_profile['Server']['SystemConfig']['BiosConfig']['BiosBootOrder']['BootOrderApply'] = True new_profile['Server']['SystemConfig']['BiosConfig']['@Processing'] = "execute" # Set new boot profile status, sysdata, msg = irmc_redfish_post(module, "rest/v1/Oem/eLCM/ProfileManagement/set", json.dumps(new_profile)) if status < 100: module.fail_json(msg=msg, status=status, exception=sysdata) elif status not in (200, 202, 204): module.fail_json(msg=msg, status=status) # check that current session is terminated status, data, msg = waitForSessionToFinish(module, get_irmc_json(sysdata.json(), ["Session", "Id"])) if status > 30 and status < 100: module.fail_json(msg=msg, status=status, exception=data) elif status not in (200, 202, 204): module.fail_json(msg=msg, log=data, status=status) result['changed'] = True module.exit_json(**result)
def irmc_elcm_offline_update(module): # initialize result result['changed'] = False result['status'] = 0 if module.check_mode: result['msg'] = "module was not run" module.exit_json(**result) # check eLCM status status, data, msg = elcm_check_status(module) if status > 30 and status < 100: module.fail_json(msg=msg, status=status, exception=data) elif status < 30 or status not in (200, 202, 204): module.fail_json(msg=msg, status=status) if module.params['command'] == "execute" and module.params[ 'ignore_power_on'] is False: # Get server power state status, sysdata, msg = irmc_redfish_get(module, "redfish/v1/Systems/0/") if status < 100: module.fail_json(msg=msg, status=status, exception=sysdata) elif status != 200: module.fail_json(msg=msg, status=status) if get_irmc_json(sysdata.json(), "PowerState") == "On": result['msg'] = "Server is powered on. Cannot continue." result['status'] = 10 module.fail_json(**result) if module.params['command'] == "prepare": uri = "rest/v1/Oem/eLCM/OfflineUpdate" if module.params['skip_hcl_verify'] is True: uri = uri + "?skipHCLVerification=yes" status, elcmdata, msg = irmc_redfish_post(module, uri, "") else: status, elcmdata, msg = irmc_redfish_put( module, "rest/v1/Oem/eLCM/OfflineUpdate", "") if status < 100: module.fail_json(msg=msg, status=status, exception=elcmdata) elif status == 409: result[ 'msg'] = "Cannot {0} eLCM update, another session is in progress.".format( module.params['command']) result['status'] = status module.fail_json(**result) elif status not in (200, 202, 204): module.fail_json(msg=msg, status=status) if module.params['wait_for_finish'] is True: # check that current session is terminated status, data, msg = waitForSessionToFinish( module, get_irmc_json(elcmdata.json(), ["Session", "Id"])) if status > 30 and status < 100: module.fail_json(msg=msg, status=status, exception=data) elif status not in (200, 202, 204): module.fail_json(msg=msg, log=data, status=status) result['changed'] = True module.exit_json(**result)