def irmc_user(module): # initialize result result['changed'] = False result['status'] = 0 if module.check_mode: result['msg'] = "module was not run" module.exit_json(**result) userdata, setparam_count = setup_datadict(module) preliminary_parameter_check(module, setparam_count) # determine user ID (free or otherwise) userdata['id'] = determine_userid(module) # set up command list if module.params['command'] == "get": body = setup_user_commandlist(userdata, "GET", param_scci_map, userdata['id']) elif module.params['command'] == "change": body = setup_user_commandlist(userdata, "SET", param_scci_map, userdata['id']) elif module.params['command'] == "create": userdata = set_default(userdata) body = setup_user_commandlist(userdata, "CREATE", param_scci_map, userdata['id']) elif module.params['command'] == "delete": body = scci_body_start body += add_scci_command("DELETE", param_scci_map, "ConfBMCAcctUserName", userdata['id'], "") body += add_scci_command("DELETE", param_scci_map, "ConfBMCAcctUserDescription", userdata['id'], "") 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): module.fail_json(msg=msg, status=status) # evaluate result list userdata, scciresult, sccicontext = get_scciresultlist( data.content, userdata, param_scci_map) if scciresult != 0: module.fail_json(msg=sccicontext, status=scciresult) userdata['name'] = module.params['name'] if module.params['command'] == "get": result['user'] = setup_resultdata(userdata) else: result['changed'] = True module.exit_json(**result)
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 setup_user_commandlist(cmdlist, ctype, scci_map, user_id): body = scci_body_start data = "" for elem in scci_map: if elem[3] is not None and cmdlist[elem[0]] is not None: data = get_key_for_value(cmdlist[elem[0]], elem[3]) else: data = cmdlist[elem[0]] body += add_scci_command(ctype, scci_map, elem[1], user_id, data) body += scci_body_end return body
def irmc_license(module): result = dict(changed=False, status=0) if module.check_mode: result['msg'] = "module was not run" module.exit_json(**result) if module.params[ 'command'] == "set" and module.params['license_key'] is None: result['msg'] = "Command 'set' requires 'license_key' to be set!" result['status'] = 10 module.fail_json(**result) body = scci_body_start if module.params['command'] == "set": body += add_scci_command("SET", param_scci_map, "ConfBMCLicenseKey", 0, module.params['license_key']) else: body += add_scci_command("GET", param_scci_map, "ConfBMCLicenseKey", 0, "") body += scci_body_end 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): module.fail_json(msg=msg, status=status) licensekey, scciresult, sccicontext = get_scciresult(data.content, 0x1980) if scciresult != 0: module.fail_json(msg=sccicontext, status=scciresult) if module.params['command'] == "get": result['license_key'] = licensekey else: result['changed'] = True module.exit_json(**result)
def determine_userid(module): usernumber = newuser = 0 userid = None while True: body = scci_body_start + add_scci_command("GET", param_scci_map, "ConfBMCAcctUserName", usernumber, "") + \ scci_body_end 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): module.fail_json(msg=msg, status=status) username, sccistatus, msg = get_scciresult(data.content, 0x1451) if (sccistatus != 0 or username == "" or username is None) and newuser == 0: newuser = usernumber if username == module.params['name']: userid = usernumber break usernumber += 1 if usernumber >= 15: break if module.params['command'] == "create": if userid is not None: result['skipped'] = True result['msg'] = "User '{0}' already exists.".format( module.params['name']) module.exit_json(**result) else: userid = newuser else: if userid is None: if module.params['command'] == "delete": result['skipped'] = True result['msg'] = "User '{0}' does not exist.".format( module.params['name']) module.exit_json(**result) else: result[ 'msg'] = "Requested user '{0}' could not be found.".format( module.params['name']) result['status'] = 20 module.fail_json(**result) return userid