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)
示例#2
0
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)
示例#3
0
def irmc_certificate(module):
    # initialize result
    result['changed'] = False
    result['status'] = 0

    if module.check_mode:
        result['msg'] = "module was not run"
        module.exit_json(**result)

    certdata, setparam_count = setup_datadict(module, False)

    # parameter check
    if module.params['command'] == "set":
        check_parameters(module, certdata, setparam_count)

        certdata, status, msg = read_keyfile(certdata, 'private_key_path')
        if status != 0:
            module.fail_json(msg=msg, status=status)
        certdata, status, msg = read_keyfile(certdata, 'ssl_cert_path')
        if status != 0:
            module.fail_json(msg=msg, status=status)
        certdata, status, msg = read_keyfile(certdata, 'ssl_ca_cert_path')
        if status != 0:
            module.fail_json(msg=msg, status=status)

    if module.params['command'] == "set":
        body = setup_commandlist(certdata, "SET", param_scci_map)
    else:
        body = setup_commandlist(certdata, "GET", param_scci_map)

    # 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 results list
    certdata, scciresult, sccicontext = get_scciresultlist(
        data.content, certdata, param_scci_map)
    if scciresult != 0:
        module.fail_json(msg=sccicontext, status=scciresult)

    if module.params['command'] == "get":
        result['certificates'] = setup_resultdata(certdata)
    else:
        result['changed'] = True

    module.exit_json(**result)
示例#4
0
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
def irmc_ntp(module):
    result = dict(changed=False, status=0)

    if module.check_mode:
        result['msg'] = "module was not run"
        module.exit_json(**result)

    module.params['time_zone'] = None
    module.params['mmb_time_sync'] = None
    ntpdata, setparam_count = setup_datadict(module)

    # preliminary parameter checks
    if module.params['command'] == "set":
        if setparam_count < 0:
            result[
                'msg'] = "Command 'set' requires at least one parameter to be changed!"
            result['status'] = 10
            module.fail_json(**result)

    # set up command list
    if module.params['command'] == "get":
        body = setup_commandlist(ntpdata, "GET", param_scci_map)
    else:
        body = setup_commandlist(ntpdata, "SET", param_scci_map)

    # 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)

    # evalaute result list
    ntpdata, scciresult, sccicontext = get_scciresultlist(
        data.content, ntpdata, param_scci_map)
    if scciresult != 0:
        module.fail_json(msg=sccicontext, status=scciresult)

    if module.params['command'] == "get":
        result['time_settings'] = setup_resultdata(ntpdata)
    else:
        result['changed'] = True

    module.exit_json(**result)
def irmc_ldap(module):
    result = dict(
        changed=False,
        status=0
    )

    if module.check_mode:
        result['msg'] = "module was not run"
        module.exit_json(**result)

    ldapdata, setparam_count = setup_datadict(module)

    # preliminary parameter check
    if module.params['command'] == "set" and setparam_count == 0:
        result['msg'] = "Command 'set' requires at least one parameter to be set!"
        result['status'] = 10
        module.fail_json(**result)

    if module.params['command'] == "set":
        body = setup_commandlist(ldapdata, "SET", param_scci_map)
    else:
        body = setup_commandlist(ldapdata, "GET", param_scci_map)

    # 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 results list
    ldapdata, scciresult, sccicontext = get_scciresultlist(data.content, ldapdata, param_scci_map)
    if scciresult != 0:
        module.fail_json(msg=sccicontext, status=scciresult)

    if module.params['command'] == "get":
        result['ldap'] = setup_resultdata(ldapdata)
    else:
        result['changed'] = True

    module.exit_json(**result)
示例#7
0
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 irmc_scci(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_cs" and module.params['data'] is None:
        result['msg'] = "SCCI SET command requires 'data' parameter!"
        result['status'] = 10
        module.fail_json(**result)

    body = setup_sccirequest(module, scci_code_map)

    # send command 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 command result
    sccidata, result['status'], sccicontext = get_scciresult(
        data.content, module.params['opcodeext'])
    if result['status'] != 0:
        result['msg'] = "SCCI '{0}' command was not successful. Return code {1}: {2}". \
                        format(module.params['command'], result['status'], sccicontext)
        if result['status'] == 95:
            result['exception'] = sccidata
        module.fail_json(**result)

    if module.params['command'] != "get_cs":
        result['changed'] = True
    else:
        result['data'] = sccidata

    module.exit_json(**result)