def irmc_elcm_online_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) # 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") == "Off": result['msg'] = "Server is powered off. Cannot continue." result['status'] = 12 module.fail_json(**result) # preliminary parameter check if module.params['command'] == "set": if module.params['component'] is None and module.params[ 'subcomponent'] is None: result[ 'msg'] = "Command 'set' requires 'component' and 'subcomponent' parameters to be set!" result['status'] = 10 module.fail_json(**result) if module.params['select'] is None: result[ 'msg'] = "Command 'set' requires 'select' parameter to be set!" result['status'] = 11 module.fail_json(**result) # start doing the actual work if module.params['command'] == 'set': elcm_change_component(module) if module.params['command'] in ("get", "delete"): elcm_online_collection(module) if module.params['command'] in ("check", "execute"): elcm_online_update(module) module.exit_json(**result)
def irmc_elcm_repository(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) # preliminary parameter check if module.params['command'] == "set": none_count = 0 plist = ("server", "catalog", "use_proxy", "proxy_url", "proxy_port", "proxy_user", "proxy_password") for param in plist: if module.params[param] is None: none_count += 1 if none_count == len(plist): result[ 'msg'] = "Command 'set' requires at least one parameter to be set!" result['status'] = 10 module.fail_json(**result) if (module.params['proxy_url'] is None and module.params['proxy_port'] is not None) or \ (module.params['proxy_url'] is not None and module.params['proxy_port'] is None): result[ 'msg'] = "'proxy_url' and 'proxy_port' need to be set together!" result['status'] = 11 module.fail_json(**result) # start doing the actual work if module.params['command'] == "get": get_elcm_data(module) if module.params['command'] == "set": set_elcm_data(module) 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)