コード例 #1
0
def irmc_setnextboot(module):
    result = dict(changed=False, status=0)

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

    # Get iRMC system data
    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)

    # Evaluate function params against iRMC
    bootsourceallowed = get_irmc_json(
        sysdata.json(),
        ["Boot", "*****@*****.**"])
    if module.params['bootsource'] not in bootsourceallowed:
        result['msg'] = "Invalid parameter '" + module.params['bootsource'] + "' for function. Allowed: " + \
                        json.dumps(bootsourceallowed)
        result['status'] = 10
        module.fail_json(**result)

    # evaluate parameters
    bootoverrideallowed = get_irmc_json(
        sysdata.json(),
        ["Boot", "*****@*****.**"])
    if module.params['bootoverride'] not in bootoverrideallowed:
        result['msg'] = "Invalid parameter '" + module.params['bootoverride'] + "' for function. Allowed: " + \
                        json.dumps(bootoverrideallowed)
        result['status'] = 11
        module.fail_json(**result)

    # Set iRMC system data
    body = {
        "Boot": {
            "BootSourceOverrideTarget": module.params['bootsource'],
            "BootSourceOverrideEnabled": module.params['bootoverride']
        }
    }
    if module.params['bootmode'] is not None:
        body['Boot']['BootSourceOverrideMode'] = module.params['bootmode']
    etag = get_irmc_json(sysdata.json(), "@odata.etag")
    status, patch, msg = irmc_redfish_patch(module, "redfish/v1/Systems/0/",
                                            json.dumps(body), etag)
    if status < 100:
        module.fail_json(msg=msg, status=status, exception=patch)
    elif status != 200:
        module.fail_json(msg=msg, status=status)

    result['changed'] = True
    module.exit_json(**result)
コード例 #2
0
def irmc_idled(module):
    result = dict(changed=False, status=0)

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

    # preliminary parameter check
    if module.params['command'] == "set" and module.params['state'] is None:
        result['msg'] = "Command 'set' requires 'state' parameter to be set!"
        result['status'] = 10
        module.fail_json(**result)

    # get iRMC system data
    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)

    idledstate = get_irmc_json(sysdata.json(), "IndicatorLED")
    if module.params['command'] == "get":
        result['idled_state'] = idledstate
        module.exit_json(**result)

    # evaluate function params against iRMC
    if idledstate == module.params['state']:
        result['skipped'] = True
        result['msg'] = "iRMC ID LED is already in state '{0}'".format(
            module.params['state'])
        module.exit_json(**result)

    allowedparams = get_irmc_json(sysdata.json(),
                                  "*****@*****.**")
    if module.params['state'] not in allowedparams:
        result['msg'] = "Invalid parameter '{0}'. Allowed: {1}".format(
            module.params['state'], json.dumps(allowedparams))
        result['status'] = 11
        module.fail_json(**result)

    # set iRMC system data
    body = {'IndicatorLED': module.params['state']}
    etag = get_irmc_json(sysdata.json(), "@odata.etag")
    status, patch, msg = irmc_redfish_patch(module, "redfish/v1/Systems/0/",
                                            json.dumps(body), etag)
    if status < 100:
        module.fail_json(msg=msg, status=status, exception=patch)
    elif status != 200:
        module.fail_json(msg=msg, status=status)

    result['changed'] = True
    module.exit_json(**result)
コード例 #3
0
def irmc_setvirtualmedia(module):
    result = dict(changed=False, status=0)

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

    vmparams, status = setup_datadict(module)

    # Get iRMC Virtual Media data
    status, vmdata, msg = irmc_redfish_get(
        module, "redfish/v1/Systems/0/Oem/ts_fujitsu/VirtualMedia/")
    if status < 100:
        module.fail_json(msg=msg, status=status, exception=vmdata)
    elif status != 200:
        module.fail_json(msg=msg, status=status)

    # Evaluate configured Virtual Media Data
    maxdevno = get_irmc_json(
        vmdata.json(), [module.params['vm_type'], "MaximumNumberOfDevices"])
    if maxdevno == 0:
        if not module.params['force_mediatype_active']:
            result['warnings'] = "No Virtual Media of Type '" + module.params[
                'vm_type'] + "' is configured!"
            result['status'] = 20
            module.fail_json(**result)
        else:
            new_maxdevno = 1
    else:
        new_maxdevno = maxdevno

    remotemountenabled = get_irmc_json(vmdata.json(), "RemoteMountEnabled")
    if not remotemountenabled and not module.params[
            'force_remotemount_enabled']:
        result['msg'] = "Remote Mount of Virtual Media is not enabled!"
        result['status'] = 30
        module.fail_json(**result)

    # Set iRMC system data
    body = setup_vmdata(vmparams, maxdevno, new_maxdevno)
    etag = get_irmc_json(vmdata.json(), "@odata.etag")
    status, patch, msg = irmc_redfish_patch(
        module, "redfish/v1/Systems/0/Oem/ts_fujitsu/VirtualMedia/",
        json.dumps(body), etag)
    if status < 100:
        module.fail_json(msg=msg, status=status, exception=patch)
    elif status != 200:
        module.fail_json(msg=msg, status=status)

    result['changed'] = True
    module.exit_json(**result)
コード例 #4
0
def elcm_change_component(module):
    uri = "rest/v1/Oem/eLCM/OnlineUpdate/updateCollection/{0}/{1}?Execution={2}". \
          format(module.params['component'], module.params['subcomponent'],
                 true_false.get(module.params['select']))
    status, elcmdata, msg = irmc_redfish_patch(module, uri, "", 0)
    if status < 100:
        module.fail_json(msg=msg, status=status, exception=elcmdata)
    elif status == 400:
        result['msg'] = "Component '{0}/{1}' does not exist in updateCollection". \
                        format(module.params['component'], module.params['subcomponent'])
        result['status'] = status
        module.fail_json(**result)
    elif status not in (200, 202, 204):
        module.fail_json(msg=msg, status=status)

    result['changed'] = True
コード例 #5
0
def patch_update_data(module, update_url, etag):
    body = {}
    if module.params['update_source'] == "tftp":
        body['ServerName'] = module.params['server_name']
        if module.params['update_type'] == "irmc":
            body['iRMCFileName'] = module.params['file_name']
        else:
            body['BiosFileName'] = module.params['file_name']
    if module.params['irmc_flash_selector'] is not None:
        body['iRMCFlashSelector'] = module.params['irmc_flash_selector']
    if module.params['irmc_boot_selector'] is not None:
        body['iRMCBootSelector'] = module.params['irmc_boot_selector']

    if body != {}:
        status, patch, msg = irmc_redfish_patch(module, update_url,
                                                json.dumps(body), etag)
        if status < 100:
            module.fail_json(msg=msg, status=status, exception=patch)
        elif status != 200:
            module.fail_json(msg=msg, status=status)
コード例 #6
0
def irmc_facts(module):
    result = dict(changed=False, status=0)

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

    # parameter check
    if module.params['command'] == "set":
        if module.params['asset_tag'] is None and module.params['description'] is None and \
           module.params['helpdesk_message'] is None and module.params['location'] is None and \
           module.params['contact'] is None:
            result[
                'msg'] = "Command 'set' requires at least one parameter to be set!"
            result['status'] = 10
            module.fail_json(**result)

    # Get iRMC OEM system data
    status, oemdata, msg = irmc_redfish_get(
        module, "redfish/v1/Systems/0/Oem/ts_fujitsu/System")
    if status < 100:
        module.fail_json(msg=msg, status=status, exception=oemdata)
    elif status != 200:
        module.fail_json(msg=msg, status=status)

    if module.params['command'] == "get":
        # Get iRMC system data
        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)
        power_state = get_irmc_json(sysdata.json(), "PowerState")

        # Get iRMC FW data
        status, fwdata, msg = irmc_redfish_get(
            module, "redfish/v1/Systems/0/Oem/ts_fujitsu/FirmwareInventory")
        if status < 100:
            module.fail_json(msg=msg, status=status, exception=fwdata)
        elif status != 200:
            module.fail_json(msg=msg, status=status)

        result['facts'] = setup_resultdata(sysdata, oemdata, fwdata)
        result = add_system_hw_info(power_state, module, result)
        result = add_chassis_hw_info(module, result)
        result = add_irmc_hw_info(module, result)
        module.exit_json(**result)

    # Set iRMC OEM system data
    body = setup_facts(module.params)
    etag = get_irmc_json(oemdata.json(), "@odata.etag")
    status, patch, msg = irmc_redfish_patch(
        module, "redfish/v1/Systems/0/Oem/ts_fujitsu/System/",
        json.dumps(body), etag)
    if status < 100:
        module.fail_json(msg=msg, status=status, exception=patch)
    elif status != 200:
        module.fail_json(msg=msg, status=status)

    result['changed'] = True
    module.exit_json(**result)