def check_all_tasks_are_finished(module):
    status, taskdata, msg = irmc_redfish_get(module,
                                             "redfish/v1/TaskService/Tasks")
    if status < 100:
        module.fail_json(msg=msg, status=status, exception=taskdata)
    elif status not in (200, 202, 204):
        module.fail_json(msg=msg, status=status)
    tasks = get_irmc_json(taskdata.json(), ["Members"])
    for task in tasks:
        url = get_irmc_json(task, "@odata.id")
        status, sdata, msg = irmc_redfish_get(module, "{0}".format(url[1:]))
        if status < 100:
            module.fail_json(msg=msg, status=status, exception=sdata)
        elif status not in (200, 202, 204):
            module.fail_json(msg=msg, status=status)

        task_state = get_irmc_json(sdata.json(),
                                   ["Oem", "ts_fujitsu", "StatusOEM"])
        if task_state in ("Pending", "FlashImageDownloadedSuccessfully"):
            msg = "Firmware update has already been started, system reboot is required. Cannot continue new update."
            module.fail_json(msg=msg, status=30)
        task_progress = get_irmc_json(
            sdata.json(), ["Oem", "ts_fujitsu", "TotalProgressPercent"])
        if str(task_progress) != "100":
            msg = "Task '{0}' is still in progress. Cannot continue new update.". \
                  format(get_irmc_json(sdata.json(), "Name"))
            module.fail_json(msg=msg, status=31)
def get_adapter(module, adapter):
    ctrl = {}
    ctrl['id'] = get_irmc_json(adapter, ["@AdapterId"])
    ctrl['name'] = ctrl['id']
    ctrl['level'] = get_irmc_json(adapter, ["Features", "RaidLevel"])
    ctrl['logical_drives'] = []
    ctrl['unused_disks'] = []
    status, hwdata, msg = irmc_redfish_get(
        module, "redfish/v1/Systems/0/Storage?$expand=Members")
    if status < 100:
        module.fail_json(msg=msg, status=status, exception=hwdata)
    elif status != 200:
        module.fail_json(msg=msg, status=status)
    for member in get_irmc_json(hwdata.json(), "Members"):
        # iRMC has each StroageController with its own Storage
        for sc in get_irmc_json(member, "StorageControllers"):
            if get_irmc_json(adapter, ["@AdapterId"]).replace(
                    "RAIDAdapter", "") == get_irmc_json(sc, ["MemberId"]):
                ctrl['name'] = get_irmc_json(sc, ["Model"])
                ctrl['firmware'] = get_irmc_json(sc, ["FirmwareVersion"])
                ctrl['drives'] = get_irmc_json(
                    sc, ["Oem", "ts_fujitsu", "DriveCount"])
                ctrl['volumes'] = get_irmc_json(
                    sc, ["Oem", "ts_fujitsu", "VolumeCount"])
                break
    return (ctrl)
def get_raid_configuration(module, irmc_profile):
    raid_configuration = []
    for adapter in get_irmc_json(
            irmc_profile,
        ["Server", "HWConfigurationIrmc", "Adapters", "RAIDAdapter"]):
        adapter_list = get_adapter(module, adapter)
        disk_data = get_irmc_json(adapter, ["PhysicalDisks", "PhysicalDisk"])
        ld_data = get_irmc_json(adapter, ["LogicalDrives", "LogicalDrive"])
        for pd in disk_data:
            disk_list = get_disk(pd)
            adapter_list['unused_disks'].append(disk_list)
        if "Key" not in ld_data:
            for ld in ld_data:
                array_list = get_logicaldrive(ld)
                for ref in get_irmc_json(ld, ["ArrayRefs", "ArrayRef"]):
                    for array in get_irmc_json(adapter, ["Arrays", "Array"]):
                        if get_irmc_json(ref, ["@Number"]) == get_irmc_json(
                                array, ["@Number"]):
                            for disk in get_irmc_json(
                                    array,
                                ["PhysicalDiskRefs", "PhysicalDiskRef"]):
                                for pd in disk_data:
                                    if get_irmc_json(
                                            disk,
                                        ["@Number"]) == get_irmc_json(
                                            pd, ["@Number"]):
                                        break
                                disk_list = get_disk(pd)
                                array_list['disks'].append(disk_list)
                                adapter_list['unused_disks'].remove(disk_list)
                adapter_list['logical_drives'].append(array_list)
        raid_configuration.append(adapter_list)
    return raid_configuration
def get_logicaldrive(ld):
    logicaldrive = {}
    logicaldrive['id'] = get_irmc_json(ld, ["@Number"])
    logicaldrive['level'] = get_irmc_json(ld, ["RaidLevel"])
    logicaldrive['name'] = get_irmc_json(ld, ["Name"])
    logicaldrive['disks'] = []
    return (logicaldrive)
Exemple #5
0
def get_disk(pd):
    disk = {}
    disk['id'] = get_irmc_json(pd, ["@Number"])
    disk['slot'] = get_irmc_json(pd, ["Slot"])
    disk['name'] = get_irmc_json(pd, ["Product"])
    disk['size'] = "{0} {1}".format(get_irmc_json(pd, ["Size", "#text"]), get_irmc_json(pd, ["Size", "@Unit"]))
    return(disk)
def irmc_fwbios_update(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 tasks are finished properly
    check_all_tasks_are_finished(module)

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

    # Get iRMC FW Update data
    update_url = "redfish/v1/Managers/iRMC/Oem/ts_fujitsu/iRMCConfiguration/FWUpdate/"
    status, fwdata, msg = irmc_redfish_get(module, update_url)
    if status < 100:
        module.fail_json(msg=msg, status=status, exception=fwdata)
    elif status != 200:
        module.fail_json(msg=msg, status=status)

    if module.params['command'] == "get":
        result['fw_update_configuration'] = setup_resultdata(fwdata, sysdata)
        module.exit_json(**result)
    elif module.params['update_type'] == "irmc":
        patch_update_data(module, update_url,
                          get_irmc_json(fwdata.json(), "@odata.etag"))

    if module.params['update_source'] == "file":
        status, udata, msg = irmc_redfish_post_file(module,
                                                    get_update_url(module),
                                                    module.params['file_name'])
    else:
        status, udata, msg = irmc_redfish_post(module, get_update_url(module),
                                               module.params['file_name'])
    if status < 100:
        module.fail_json(msg=msg, status=status, exception=udata)
    elif status not in (200, 202, 204):
        if status == 104 and module.params['update_type'] == "irmc":
            msg = "{0} This message might indicate that iRMC needs to reboot before FW update.".format(
                msg)
        if status == 400:
            msg = "{0} This message might be due to the binary file being invalid for the server.".format(
                msg)
        module.fail_json(msg=msg, status=status)

    wait_for_update_to_finish(module, udata.headers['Location'],
                              get_irmc_json(sysdata.json(), "PowerState"))
    module.exit_json(**result)
def wait_for_update_to_finish(module, location, power_state):
    rebootDone = None
    start_time = time.time()
    while True:
        time.sleep(5)
        elapsed_time = time.time() - start_time
        # make sure the module does not get stuck if anything goes wrong
        now = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
        if elapsed_time > module.params['timeout'] * 60:
            msg = "Timeout of {0} minutes exceeded. Abort.".format(
                module.params['timeout'])
            module.fail_json(msg=msg, status=20)

        status, sdata, msg = irmc_redfish_get(module,
                                              "{0}".format(location[1:]))
        if status == 99:
            time.sleep(55)
            continue
        elif status == 404:
            if rebootDone is True:
                result['changed'] = True
                break
            continue
        elif status == 503:
            if rebootDone is None:
                rebootDone = False  # just in case we miss the 'complete' message
            else:
                rebootDone = True
            time.sleep(25)
            continue
        elif status < 100 or (status not in (200, 202, 204)):
            time.sleep(5)
            continue

        if "Key" in get_irmc_json(sdata.json(), "error"):
            rebootDone = False
            oemstate = get_irmc_json(sdata.json(),
                                     ["Oem", "ts_fujitsu", "StatusOEM"])
            state = get_irmc_json(sdata.json(), "TaskState")
            # make sure the process ran through
            if power_state == "On" and oemstate == "Pending":
                msg = "A BIOS firmware update has been started and a system reboot is required to continue the update."
                result['warnings'] = msg
                break
            if power_state == "On" and oemstate == "FlashImageDownloadedSuccessfully":
                msg = "A BIOS firmware update has been started. A system reboot is required to continue the update."
                result['warnings'] = msg
                break
            if state == "Exception":
                msg = "{0}: Update failed.".format(now)
                module.fail_json(msg=msg, status=21)
            # for BIOS we are done here, for iRMC we need to wait for iRMC shutdown and reboot
            if module.params['update_type'] == "bios" and state == "Completed":
                result['changed'] = True
                break
        else:
            break
def irmc_powerstate(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)

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

    # Evaluate function params against iRMC
    if "Power" + power_state == module.params['state'].replace("Graceful", ""):
        result['skipped'] = True
        result['msg'] = "PRIMERGY server is already in state '{0}'".format(
            power_state)
        module.exit_json(**result)

    allowedparams = \
        get_irmc_json(sysdata.json(),
                      ["Actions", "Oem",
                       "http://ts.fujitsu.com/redfish-schemas/v1/FTSSchema.v1_0_0#FTSComputerSystem.Reset",
                       "*****@*****.**"])
    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 = {'FTSResetType': module.params['state']}
    status, sysdata, msg = irmc_redfish_post(
        module, "redfish/v1/Systems/0/Actions/Oem/FTSComputerSystem.Reset",
        json.dumps(body))
    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)

    result['changed'] = True
    module.exit_json(**result)
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)
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)
Exemple #11
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)
def add_irmc_hw_info(module, result):
    # get iRMC info
    status, hwdata, msg = irmc_redfish_get(
        module, "redfish/v1/Managers/iRMC/EthernetInterfaces?$expand=Members")
    if status < 100:
        module.fail_json(msg=msg, status=status, exception=hwdata)
    elif status != 200:
        module.fail_json(msg=msg, status=status)
    for member in get_irmc_json(hwdata.json(), "Members"):
        result['facts']['irmc']['macaddress'] = "{0}".format(
            get_irmc_json(member, ["MACAddress"]))
        result['facts']['irmc']['hostname'] = "{0}".format(
            get_irmc_json(member, ["HostName"]))
    return result
Exemple #13
0
def elcm_online_collection(module):
    if module.params['command'] == "get":
        status, elcmdata, msg = irmc_redfish_get(
            module, "rest/v1/Oem/eLCM/OnlineUpdate/updateCollection")
    else:
        status, elcmdata, msg = irmc_redfish_delete(
            module, "rest/v1/Oem/eLCM/OnlineUpdate/updateCollection")
    if status < 100:
        module.fail_json(msg=msg, status=status, exception=elcmdata)
    elif status == 404:
        result['msg'] = "updateCollection does not exist."
        if module.params['command'] == "get":
            result['status'] = status
            module.fail_json(**result)
        else:
            result['skipped'] = True
            module.exit_json(**result)
    elif status not in (200, 202, 204):
        module.fail_json(msg=msg, status=status)

    if module.params['command'] == "get":
        result['update_collection'] = []
        for item in get_irmc_json(elcmdata.json(), ["Links", "Contains"]):
            sw = {}
            #            sw['link'] = get_irmc_json(item, ["@odata.id"])
            #            sw['name'] = sw['link'].replace("rest/v1/Oem/eLCM/OnlineUpdate/updateCollection/PrimSupportPack-Win/", "")

            status, swdata, msg = irmc_redfish_get(
                module, get_irmc_json(item, ["@odata.id"]))
            if status < 100:
                module.fail_json(msg=msg, status=status, exception=swdata)
            elif status not in (200, 202, 204):
                module.fail_json(msg=msg, status=status)
            sw['component'] = get_irmc_json(swdata.json(),
                                            ["Update", "Component"])
            sw['subcomponent'] = get_irmc_json(swdata.json(),
                                               ["Update", "SubComponent"])
            sw['current'] = get_irmc_json(swdata.json(), ["Update", "Current"])
            sw['new'] = get_irmc_json(swdata.json(), ["Update", "New"])
            sw['severity'] = get_irmc_json(swdata.json(),
                                           ["Update", "Severity"])
            sw['status'] = get_irmc_json(swdata.json(), ["Update", "Status"])
            sw['reboot'] = get_irmc_json(swdata.json(), ["Update", "Reboot"])
            sw['selected'] = get_irmc_json(swdata.json(),
                                           ["Update", "Execution"])
            result['update_collection'].append(sw)
    else:
        result['changed'] = True
def preliminary_parameter_check(module):
    if module.params['command'] == "update":
        if module.params['update_source'] is None or module.params['update_type'] is None or \
           module.params['file_name'] is None:
            result[
                'msg'] = "Command 'update' requires 'update_source, update_type, file_name' parameters to be set!"
            result['status'] = 10
            module.fail_json(**result)
        if module.params['update_source'] == "tftp" and module.params[
                'server_name'] is None:
            result[
                'msg'] = "TFTP update requires 'server_name' parameter to be set!"
            result['status'] = 11
            module.fail_json(**result)

        if 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['skipped'] = True
                result['warnings'] = "Server is powered on. Cannot continue."
                module.exit_json(**result)
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 get_irmc_sessions(module):
    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)
    return get_irmc_json(sessiondata.json(), ["SessionList"])
def get_irmc_session_info(module, item):
    status, sdata, msg = irmc_redfish_get(
        module, "sessionInformation/{0}/status".format(item['@Id']))
    if status < 100:
        module.fail_json(msg=msg, status=status, exception=sdata)
    elif status not in (200, 202, 204):
        module.fail_json(msg=msg, status=status)

    session = {}
    session['Id'] = item['@Id']
    session['Text'] = item['#text']
    session['Tag'] = item['@Tag']
    session['Status'] = get_irmc_json(sdata.json(), ["Session", "Status"])
    session['Start'] = get_irmc_json(sdata.json(), ["Session", "Start"])
    session['Duration'] = get_irmc_json(sdata.json(), ["Session", "Duration"])
    return session
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)
Exemple #19
0
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 preliminary_parameter_check(module):
    if module.params['command'] != "get":
        # 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'] == "create" and \
       module.params['adapter'] is None and module.params['level'] is None:
        result[
            'msg'] = "Command 'create' requires 'adapter' and 'level' to be set."
        result['status'] = 10
        module.fail_json(**result)
    if module.params['command'] == "delete" and module.params[
            'adapter'] is None and module.params['array'] is None:
        result[
            'msg'] = "Command 'delete' requires 'adapter' and 'array' to be set."
        result['status'] = 11
        module.fail_json(**result)
def setup_resultdata(data, sysdata):
    configuration = {
        'tftp_server_name': get_irmc_json(data.json(), "ServerName"),
        'irmc_file_name': get_irmc_json(data.json(), "iRMCFileName"),
        'irmc_flash_selector': get_irmc_json(data.json(), "iRMCFlashSelector"),
        'irmc_boot_selector': get_irmc_json(data.json(), "iRMCBootSelector"),
        'irmc_fw_low': get_irmc_json(data.json(), "iRMCFwImageLow"),
        'irmc_fw_high': get_irmc_json(data.json(), "iRMCFwImageHigh"),
        'bios_file_name': get_irmc_json(data.json(), "BiosFileName"),
        'bios_version': get_irmc_json(sysdata.json(), "BiosVersion"),
        'power_state': get_irmc_json(sysdata.json(), "PowerState"),
    }
    return configuration
Exemple #22
0
def get_irmc_eventlog_info(module, item):
    eventlog = {}
    eventlog['Id'] = item['Id']
    eventlog['Severity'] = item['Severity']
    eventlog['Created'] = item['Created']
    eventlog['Type'] = item['EntryType']
    eventlog['AlertGroup'] = get_irmc_json(item,
                                           ["Oem", "ts_fujitsu", "AlertGroup"])
    if module.params['eventlog_type'] == "SystemEventLog":
        eventlog['EventSource'] = get_irmc_json(
            item, ["Oem", "ts_fujitsu", "EventSource"])
        eventlog['Message'] = get_irmc_json(
            item, ["Oem", "ts_fujitsu", "MessageOEM", "en"])[0]
        if get_irmc_json(item, ["Oem", "ts_fujitsu", "Cause"]) is not None:
            eventlog['Cause'] = get_irmc_json(
                item, ["Oem", "ts_fujitsu", "Cause", "en"])[0]
        else:
            eventlog['Cause'] = None
        if get_irmc_json(item,
                         ["Oem", "ts_fujitsu", "Resolutions"]) is not None:
            eventlog['Resolutions'] = get_irmc_json(
                item, ["Oem", "ts_fujitsu", "Resolutions", "en"])[0]
        else:
            eventlog['Resolutions'] = None
    else:
        eventlog['MessageId'] = item['MessageId']
        eventlog['Message'] = item['Message']
    return eventlog
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)
Exemple #24
0
def irmc_task(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
    if (module.params['command']
            in ("get", "remove", "terminate")) and module.params['id'] is None:
        result[
            'msg'] = "Command '{0}' requires 'id' parameter to be set!".format(
                module.params['command'])
        result['status'] = 10
        module.fail_json(**result)

    id_found = 0
    if module.params['command'] == "get":
        id_found = 1
        result['task'] = get_irmc_task_info(
            module,
            "/redfish/v1/TaskService/Tasks/{0}".format(module.params['id']),
            module.params['id'])

    if module.params['command'] == "list":
        status, taskdata, msg = irmc_redfish_get(
            module, "redfish/v1/TaskService/Tasks")
        if status < 100:
            module.fail_json(msg=msg, status=status, exception=taskdata)
        elif status not in (200, 202, 204):
            module.fail_json(msg=msg, status=status)
        tasks = get_irmc_json(taskdata.json(), ["Members"])

        result['tasks'] = []
        for task in tasks:
            id_found += 1
            task_url = get_irmc_json(task, "@odata.id")
            myID = task_url.replace("/redfish/v1/TaskService/Tasks/", "")
            task_info = get_irmc_task_info(module, task_url, myID)
            result['tasks'].append(task_info)

    module.exit_json(**result)
def setup_new_boot_profile(module, profile):
    index = 0
    boot_devices = ""
    new_profile = copy.deepcopy(profile)
    devices = get_irmc_json(
        new_profile,
        ["Server", "SystemConfig", "BiosConfig", "BiosBootOrder", "Devices"])

    new_bootorder = []
    for msg, devicelist in devices.items():
        for item in devicelist:
            for ikey, value in item.items():
                if ikey == module.params[
                        'boot_key'] and value == module.params['boot_device']:
                    index += 1
                    item['@DeviceIdx'] = index
                    if boot_devices != "":
                        boot_devices += ", "
                    boot_devices += item[module.params['boot_key']]
                    new_bootorder.append(item)
        for item in devicelist:
            for ikey, value in item.items():
                if ikey == module.params[
                        'boot_key'] and value != module.params['boot_device']:
                    index += 1
                    item['@DeviceIdx'] = index
                    if boot_devices != "":
                        boot_devices += ", "
                    boot_devices += str(item[module.params['boot_key']])
                    new_bootorder.append(item)

    if module.params['boot_device'] not in boot_devices:
        msg = "'boot_device' '{0}' cannot be found in existing boot devices: '{1}'". \
              format(module.params['boot_device'], boot_devices)
        module.fail_json(msg=msg, status=20)

    if module.params['next_boot_device'] is not None and module.params[
            'next_boot_device'] not in boot_devices:
        msg = "'next_boot_device' '{0}' cannot be found in existing boot devices: '{1}'". \
              format(module.params['next_boot_device'], boot_devices)
        module.fail_json(msg=msg, status=21)

    # add new boot order to profile
    del new_profile['Server']['SystemConfig']['BiosConfig']['BiosBootOrder'][
        'Devices']['Device']
    new_profile['Server']['SystemConfig']['BiosConfig']['BiosBootOrder'][
        'Devices']['Device'] = new_bootorder
    if module.params['next_boot_device'] is not None:
        new_profile['Server']['SystemConfig']['BiosConfig']['BiosBootOrder']['NextBootDevice'] = \
            module.params['next_boot_device']

    return new_profile
Exemple #26
0
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)
Exemple #27
0
def irmc_eventlog(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
    if module.params['command'] == "get" and module.params['id'] is None:
        result['msg'] = "Command 'get' requires 'id' parameter to be set!"
        result['status'] = 10
        module.fail_json(**result)

    if module.params['command'] == "list":
        status, data, msg = irmc_redfish_get(
            module, "redfish/v1/Managers/iRMC/LogServices/{0}/Entries".format(
                module.params['eventlog_type']))
        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)

        eventlogs = get_irmc_json(data.json(), ["Members"])
        result['eventlog'] = []
        for item in eventlogs:
            result['eventlog'].append(get_irmc_eventlog_info(module, item))
    elif module.params['command'] == "clear":
        url = "redfish/v1/Managers/iRMC/LogServices/{0}/Actions/LogService.ClearLog". \
              format(module.params['eventlog_type'])
        status, data, msg = irmc_redfish_post(module, url, "")
        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)
        result['changed'] = True
    else:
        status, data, msg = irmc_redfish_get(
            module,
            "redfish/v1/Managers/iRMC/LogServices/{0}/Entries/{1}".format(
                module.params['eventlog_type'], module.params['id']))
        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)

        result['eventlog_entry'] = get_irmc_eventlog_info(module, data.json())

    module.exit_json(**result)
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 list_profiles(module):
    status, sysdata, msg = irmc_redfish_get(
        module, "/rest/v1/Oem/eLCM/ProfileManagement")
    if status < 100:
        module.fail_json(msg=msg, status=status, exception=sysdata)
    elif status != 200:
        module.fail_json(msg=msg, status=status)

    result['profiles'] = {}
    for profile in get_irmc_json(sysdata.json(), ["Links", "profileStore"]):
        for status, value in profile.items():
            profile = {}
            profile['Name'] = value.replace(
                "rest/v1/Oem/eLCM/ProfileManagement/", "")
            profile['Location'] = value
            result['profiles'][value.replace(
                "rest/v1/Oem/eLCM/ProfileManagement/", "")] = profile