Ejemplo n.º 1
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)
Ejemplo n.º 2
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)
Ejemplo n.º 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)
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)