def run_export_server_config_profile(idrac, module):
    """Export Server Configuration Profile to a network share."""
    export_format = ExportFormatEnum[module.params['export_format']]
    scp_file = module.params['scp_file']
    if scp_file:
        scp_file_name_format = scp_file
        if not str(scp_file.lower()).endswith(('.xml', '.json')):
            scp_file_name_format = "{0}.{1}".format(
                scp_file, module.params['export_format'].lower())
    else:
        scp_file_name_format = "%ip_%Y%m%d_%H%M%S_scp.{0}".format(
            module.params['export_format'].lower())
    target = SCPTargetEnum[module.params['scp_components']]
    export_use = ExportUseEnum[module.params['export_use']]
    idrac.use_redfish = True

    try:
        myshare = file_share_manager.create_share_obj(
            share_path=module.params['share_name'],
            creds=UserCredentials(module.params['share_user'],
                                  module.params['share_password']),
            isFolder=True)
        scp_file_name = myshare.new_file(scp_file_name_format)
        export_status = idrac.config_mgr.scp_export(
            scp_file_name,
            target=target,
            export_format=export_format,
            export_use=export_use,
            job_wait=module.params['job_wait'])
        if not export_status or export_status.get('Status') != "Success":
            module.fail_json(msg='Failed to export scp.',
                             scp_status=export_status)
    except RuntimeError as e:
        module.fail_json(msg=str(e))
    return export_status
示例#2
0
def run_setup_idrac_syslog(idrac, module):
    idrac.use_redfish = True
    upd_share = file_share_manager.create_share_obj(
        share_path=module.params['share_name'],
        mount_point=module.params['share_mnt'],
        isFolder=True,
        creds=UserCredentials(module.params['share_user'],
                              module.params['share_password']))
    if not upd_share.IsValid:
        module.fail_json(
            msg="Unable to access the share. Ensure that the share name, "
            "share mount, and share credentials provided are correct.")
    idrac.config_mgr.set_liason_share(upd_share)
    if module.check_mode:
        if module.params['syslog'] == 'Enabled':
            idrac.config_mgr.enable_syslog(apply_changes=False)
        elif module.params['syslog'] == 'Disabled':
            idrac.config_mgr.disable_syslog(apply_changes=False)
        msg = idrac.config_mgr.is_change_applicable()
    else:
        if module.params['syslog'] == 'Enabled':
            msg = idrac.config_mgr.enable_syslog()
        elif module.params['syslog'] == 'Disabled':
            msg = idrac.config_mgr.disable_syslog()
    return msg
def run_export_lc_logs(idrac, module):
    """
    Export Lifecycle Controller Log to the given file share

    Keyword arguments:
    idrac  -- iDRAC handle
    module -- Ansible module
    """
    msg = {}
    msg['changed'] = False
    msg['failed'] = False
    err = False

    try:
        lclog_file_name_format = "%ip_%Y%m%d_%H%M%S_LC_Log.log"

        myshare = file_share_manager.create_share_obj(
            share_path=module.params['share_name'],
            creds=get_user_credentials(module),
            isFolder=True)

        lc_log_file = myshare.new_file(lclog_file_name_format)

        job_wait = module.params['job_wait']
        msg['msg'] = idrac.log_mgr.lclog_export(lc_log_file, job_wait)
        if "Status" in msg['msg'] and msg['msg']['Status'] != "Success":
            msg['failed'] = True

    except Exception as e:
        err = True
        msg['msg'] = "Error: %s" % str(e)
        msg['failed'] = True

    return msg, err
def run_import_server_config_profile(idrac, module):
    """Import Server Configuration Profile from a network share."""
    target = SCPTargetEnum[module.params['scp_components']]
    job_wait = module.params['job_wait']
    end_host_power_state = EndHostPowerStateEnum[
        module.params['end_host_power_state']]
    shutdown_type = ShutdownTypeEnum[module.params['shutdown_type']]
    idrac.use_redfish = True

    try:
        myshare = file_share_manager.create_share_obj(
            share_path="{0}{1}{2}".format(module.params['share_name'], os.sep,
                                          module.params['scp_file']),
            creds=UserCredentials(module.params['share_user'],
                                  module.params['share_password']),
            isFolder=False)
        import_status = idrac.config_mgr.scp_import(
            myshare,
            target=target,
            shutdown_type=shutdown_type,
            end_host_power_state=end_host_power_state,
            job_wait=job_wait)
        if not import_status or import_status.get('Status') != "Success":
            module.fail_json(msg='Failed to import scp.',
                             scp_status=import_status)
    except RuntimeError as e:
        module.fail_json(msg=str(e))
    return import_status
def set_liason_share(idrac, module):
    idrac.use_redfish = True
    share_name = tempfile.gettempdir() + os.sep
    storage_share = file_share_manager.create_share_obj(share_path=share_name,
                                                        isFolder=True)
    set_liason = idrac.config_mgr.set_liason_share(storage_share)
    if set_liason['Status'] == "Failed":
        liason_data = set_liason.get('Data', set_liason)
        module.fail_json(msg=liason_data.get('Message', "Failed to set Liason share"))
def run_system_lockdown_mode(idrac, module):
    """
    Get Lifecycle Controller status

    Keyword arguments:
    idrac  -- iDRAC handle
    module -- Ansible module
    """
    msg = {}
    msg['changed'] = False
    msg['failed'] = False
    msg['msg'] = {}
    err = False

    try:

        idrac.use_redfish = True
        upd_share = file_share_manager.create_share_obj(share_path=module.params['share_name'],
                                                        mount_point=module.params['share_mnt'],
                                                        isFolder=True,
                                                        creds=UserCredentials(
                                                            module.params['share_user'],
                                                            module.params['share_pwd'])
                                                        )

        set_liason = idrac.config_mgr.set_liason_share(upd_share)
        if set_liason['Status'] == "Failed":
            try:
                message = set_liason['Data']['Message']
            except (IndexError, KeyError):
                message = set_liason['Message']
            err = True
            msg['msg'] = "{}".format(message)
            msg['failed'] = True
            return msg, err

        if module.params['lockdown_mode'] == 'Enabled':
            msg['msg'] = idrac.config_mgr.enable_system_lockdown()
        elif module.params['lockdown_mode'] == 'Disabled':
            msg['msg'] = idrac.config_mgr.disable_system_lockdown()

        if "Status" in msg['msg']:
            if msg['msg']['Status'] == "Success":
                msg['changed'] = True
            else:
                msg['failed'] = True
    except Exception as e:
        err = True
        msg['msg'] = "Error: %s" % str(e)
        msg['failed'] = True
    return msg, err
def get_user_credentials(module):
    share_username = module.params['share_user']
    share_password = module.params['share_password']
    work_group = None
    if share_username is not None and "@" in share_username:
        username_domain = share_username.split("@")
        share_username = username_domain[0]
        work_group = username_domain[1]
    elif share_username is not None and "\\" in share_username:
        username_domain = share_username.split("\\")
        work_group = username_domain[0]
        share_username = username_domain[1]
    share = file_share_manager.create_share_obj(share_path=module.params['share_name'],
                                                creds=UserCredentials(share_username, share_password,
                                                                      work_group=work_group), isFolder=True)
    return share
def run_system_lockdown_mode(idrac, module):
    """
    Get Lifecycle Controller status

    Keyword arguments:
    idrac  -- iDRAC handle
    module -- Ansible module
    """
    msg = {
        'changed': False,
        'failed': False,
        'msg': "Successfully completed the lockdown mode operations."
    }
    idrac.use_redfish = True
    upd_share = file_share_manager.create_share_obj(
        share_path=module.params['share_name'],
        mount_point=module.params['share_mnt'],
        isFolder=True,
        creds=UserCredentials(module.params['share_user'],
                              module.params['share_password']))
    if not upd_share.IsValid:
        module.fail_json(
            msg="Unable to access the share. Ensure that the share name, "
            "share mount, and share credentials provided are correct.")
    set_liason = idrac.config_mgr.set_liason_share(upd_share)
    if set_liason['Status'] == "Failed":
        try:
            message = set_liason['Data']['Message']
        except (IndexError, KeyError):
            message = set_liason['Message']
        module.fail_json(msg=message)
    if module.params['lockdown_mode'] == 'Enabled':
        msg["system_lockdown_status"] = idrac.config_mgr.enable_system_lockdown(
        )
    elif module.params['lockdown_mode'] == 'Disabled':
        msg["system_lockdown_status"] = idrac.config_mgr.disable_system_lockdown(
        )

    if msg.get("system_lockdown_status"
               ) and "Status" in msg['system_lockdown_status']:
        if msg['system_lockdown_status']['Status'] == "Success":
            msg['changed'] = True
        else:
            module.fail_json(
                msg="Failed to complete the lockdown mode operations.")
    return msg
示例#9
0
def run_idrac_timezone_config(idrac, module):
    """
    Get Lifecycle Controller status

    Keyword arguments:
    idrac  -- iDRAC handle
    module -- Ansible module
    """
    idrac.use_redfish = True
    upd_share = file_share_manager.create_share_obj(
        share_path=module.params['share_name'],
        mount_point=module.params['share_mnt'],
        isFolder=True,
        creds=UserCredentials(module.params['share_user'],
                              module.params['share_password']))
    if not upd_share.IsValid:
        module.fail_json(
            msg="Unable to access the share. Ensure that the share name, "
            "share mount, and share credentials provided are correct.")
    idrac.config_mgr.set_liason_share(upd_share)

    if module.params['setup_idrac_timezone'] is not None:
        idrac.config_mgr.configure_timezone(
            module.params['setup_idrac_timezone'])

    if module.params['enable_ntp'] is not None:
        idrac.config_mgr.configure_ntp(
            enable_ntp=NTPEnable_NTPConfigGroupTypes[
                module.params['enable_ntp']])
    if module.params['ntp_server_1'] is not None:
        idrac.config_mgr.configure_ntp(
            ntp_server_1=module.params['ntp_server_1'])
    if module.params['ntp_server_2'] is not None:
        idrac.config_mgr.configure_ntp(
            ntp_server_2=module.params['ntp_server_2'])
    if module.params['ntp_server_3'] is not None:
        idrac.config_mgr.configure_ntp(
            ntp_server_3=module.params['ntp_server_3'])

    if module.check_mode:
        msg = idrac.config_mgr.is_change_applicable()
    else:
        msg = idrac.config_mgr.apply_changes(reboot=False)
    return msg
示例#10
0
def run_export_lc_logs(idrac, module):
    """
    Export Lifecycle Controller Log to the given file share

    Keyword arguments:
    idrac  -- iDRAC handle
    module -- Ansible module
    """

    lclog_file_name_format = "%ip_%Y%m%d_%H%M%S_LC_Log.log"

    myshare = file_share_manager.create_share_obj(share_path=module.params['share_name'],
                                                  creds=UserCredentials(module.params['share_user'],
                                                                        module.params['share_password']),
                                                  isFolder=True)
    lc_log_file = myshare.new_file(lclog_file_name_format)
    job_wait = module.params['job_wait']
    msg = idrac.log_mgr.lclog_export(lc_log_file, job_wait)
    return msg
def run_setup_idrac_csior(idrac, module):
    """
    Get Lifecycle Controller status

    Keyword arguments:
    idrac  -- iDRAC handle
    module -- Ansible module
    """
    idrac.use_redfish = True
    upd_share = file_share_manager.create_share_obj(share_path=module.params['share_name'],
                                                    mount_point=module.params['share_mnt'],
                                                    isFolder=True,
                                                    creds=UserCredentials(
                                                        module.params['share_user'],
                                                        module.params['share_password'])
                                                    )
    if not upd_share.IsValid:
        module.fail_json(msg="Unable to access the share. Ensure that the share name, "
                             "share mount, and share credentials provided are correct.")
    set_liason = idrac.config_mgr.set_liason_share(upd_share)
    if set_liason['Status'] == "Failed":
        try:
            message = set_liason['Data']['Message']
        except (IndexError, KeyError):
            message = set_liason['Message']
        module.fail_json(msg=message)
    if module.params['csior'] == 'Enabled':
        # Enable csior
        idrac.config_mgr.enable_csior()
    elif module.params['csior'] == 'Disabled':
        # Disable csior
        idrac.config_mgr.disable_csior()

    if module.check_mode:
        status = idrac.config_mgr.is_change_applicable()
        if status.get("changes_applicable"):
            module.exit_json(msg="Changes found to commit!", changed=True)
        else:
            module.exit_json(msg="No changes found to commit!")
    else:
        return idrac.config_mgr.apply_changes(reboot=False)
示例#12
0
def run_setup_idrac_syslog(idrac, module):
    idrac.use_redfish = True
    upd_share = file_share_manager.create_share_obj(share_path=module.params['share_name'],
                                                    mount_point=module.params['share_mnt'],
                                                    isFolder=True,
                                                    creds=UserCredentials(
                                                        module.params['share_user'],
                                                        module.params['share_password']))
    idrac.config_mgr.set_liason_share(upd_share)
    if module.check_mode:
        if module.params['syslog'] == 'Enabled':
            idrac.config_mgr.enable_syslog(apply_changes=False)
        elif module.params['syslog'] == 'Disabled':
            idrac.config_mgr.disable_syslog(apply_changes=False)
        msg = idrac.config_mgr.is_change_applicable()
    else:
        if module.params['syslog'] == 'Enabled':
            msg = idrac.config_mgr.enable_syslog()
        elif module.params['syslog'] == 'Disabled':
            msg = idrac.config_mgr.disable_syslog()
    return msg
def run_server_bios_config(idrac, module):
    msg = {}
    temp_dir = tempfile.gettempdir() + os.sep
    share_name = module.params.get('share_name')
    share_path = share_name if share_name is not None else temp_dir

    idrac.use_redfish = True
    upd_share = file_share_manager.create_share_obj(
        share_path=share_path,
        mount_point=module.params['share_mnt'],
        isFolder=True,
        creds=UserCredentials(module.params['share_user'],
                              module.params['share_password']))
    if not upd_share.IsValid:
        module.fail_json(
            msg="Unable to access the share. Ensure that the share name, "
            "share mount, and share credentials provided are correct.")
    if module.params['boot_sources']:
        _validate_params(module.params['boot_sources'])
        if module.check_mode:
            idrac.config_mgr.is_change_applicable()
        msg = idrac.config_mgr.configure_boot_sources(
            input_boot_devices=module.params['boot_sources'])
        return msg

    idrac.config_mgr.set_liason_share(upd_share)

    if module.params['boot_mode'] and not (module.params['attributes']
                                           and 'BootMode'
                                           in module.params['attributes']):
        idrac.config_mgr.configure_boot_mode(
            boot_mode=BootModeTypes[module.params['boot_mode']])

    if module.params['nvme_mode'] and not (module.params['attributes']
                                           and 'NvmeMode'
                                           in module.params['attributes']):
        idrac.config_mgr.configure_nvme_mode(
            nvme_mode=NvmeModeTypes[module.params['nvme_mode']])

    if module.params['secure_boot_mode'] and not (
            module.params['attributes']
            and 'SecureBootMode' in module.params['attributes']):
        idrac.config_mgr.configure_secure_boot_mode(
            secure_boot_mode=SecureBootModeTypes[
                module.params['secure_boot_mode']])

    if module.params['onetime_boot_mode'] and not (
            module.params['attributes']
            and 'OneTimeBootMode' in module.params['attributes']):
        idrac.config_mgr.configure_onetime_boot_mode(
            onetime_boot_mode=OneTimeBootModeTypes[
                module.params['onetime_boot_mode']])

    if module.params["boot_mode"] is not None and module.params[
            "boot_sequence"] is not None:
        idrac.config_mgr.configure_boot_sequence(
            boot_mode=BootModeEnum[module.params['boot_mode']],
            boot_sequence=module.params['boot_sequence'])

    if module.params['attributes']:
        msg['msg'] = idrac.config_mgr.configure_bios(
            bios_attr_val=module.params['attributes'])

    if module.check_mode:
        msg = idrac.config_mgr.is_change_applicable()
    else:
        msg = idrac.config_mgr.apply_changes(reboot=True)
    return msg
def run_idrac_services_config(idrac, module):
    """
    Get Lifecycle Controller status

    Keyword arguments:
    idrac  -- iDRAC handle
    module -- Ansible module
    """
    idrac.use_redfish = True
    upd_share = file_share_manager.create_share_obj(
        share_path=module.params['share_name'],
        mount_point=module.params['share_mnt'],
        isFolder=True,
        creds=UserCredentials(module.params['share_user'],
                              module.params['share_password']))

    set_liason = idrac.config_mgr.set_liason_share(upd_share)
    if set_liason['Status'] == "Failed":
        try:
            message = set_liason['Data']['Message']
        except (IndexError, KeyError):
            message = set_liason['Message']
        module.fail_json(msg=message)

    if module.params['enable_web_server'] is not None:
        idrac.config_mgr.configure_web_server(
            enable_web_server=Enable_WebServerTypes[
                module.params['enable_web_server']])
    if module.params['http_port'] is not None:
        idrac.config_mgr.configure_web_server(
            http_port=module.params['http_port'])
    if module.params['https_port'] is not None:
        idrac.config_mgr.configure_web_server(
            https_port=module.params['https_port'])
    if module.params['timeout'] is not None:
        idrac.config_mgr.configure_web_server(timeout=module.params['timeout'])
    if module.params['ssl_encryption'] is not None:
        idrac.config_mgr.configure_web_server(
            ssl_encryption=SSLEncryptionBitLength_WebServerTypes[
                module.params['ssl_encryption']])
    if module.params['tls_protocol'] is not None:
        idrac.config_mgr.configure_web_server(
            tls_protocol=TLSProtocol_WebServerTypes[
                module.params['tls_protocol']])

    if module.params['snmp_enable'] is not None:
        idrac.config_mgr.configure_snmp(
            snmp_enable=AgentEnable_SNMPTypes[module.params['snmp_enable']])
    if module.params['community_name'] is not None:
        idrac.config_mgr.configure_snmp(
            community_name=module.params['community_name'])
    if module.params['snmp_protocol'] is not None:
        idrac.config_mgr.configure_snmp(snmp_protocol=SNMPProtocol_SNMPTypes[
            module.params['snmp_protocol']])
    if module.params['alert_port'] is not None:
        idrac.config_mgr.configure_snmp(alert_port=module.params['alert_port'])
    if module.params['discovery_port'] is not None:
        idrac.config_mgr.configure_snmp(
            discovery_port=module.params['discovery_port'])
    if module.params['trap_format'] is not None:
        idrac.config_mgr.configure_snmp(
            trap_format=module.params['trap_format'])
    if module.params['ipmi_lan'] is not None:
        ipmi_option = module.params.get('ipmi_lan')
        community_name = ipmi_option.get('community_name')
        if community_name is not None:
            idrac.config_mgr.configure_snmp(ipmi_community=community_name)

    if module.check_mode:
        status = idrac.config_mgr.is_change_applicable()
        if status.get('changes_applicable'):
            module.exit_json(msg="Changes found to commit!", changed=True)
        else:
            module.exit_json(msg="No changes found to commit!")
    else:
        return idrac.config_mgr.apply_changes(reboot=False)
示例#15
0
def run_import_server_config_profile(idrac, module):
    """
    Import Server Configuration Profile from a network share

    Keyword arguments:
    idrac  -- iDRAC handle
    module -- Ansible module
    """
    logger.info(module.params['idrac_ip'] +
                ': STARTING: Importing Server Configuration Profile Method')
    msg = {}
    msg['changed'] = False
    msg['failed'] = False
    msg['msg'] = {}
    err = False

    try:
        if module.check_mode:
            msg['changed'] = True

        else:

            logger.info(module.params['idrac_ip'] +
                        ': CALLING: Create File share object OMSDK API')
            myshare = file_share_manager.create_share_obj(
                share_path=module.params['share_name'] + "/" +
                module.params['scp_file'],
                creds=UserCredentials(module.params['share_user'],
                                      module.params['share_pwd']),
                isFolder=False,
            )
            logger.info(module.params['idrac_ip'] +
                        ': FINISHED: Create File share object OMSDK API')
            # myshare.new_file(module.params['scp_file'])

            scp_components = SCPTargetEnum.ALL

            if module.params['scp_components'] == 'IDRAC':
                scp_components = SCPTargetEnum.IDRAC
            elif module.params['scp_components'] == 'BIOS':
                scp_components = SCPTargetEnum.BIOS
            elif module.params['scp_components'] == 'NIC':
                scp_components = SCPTargetEnum.NIC
            elif module.params['scp_components'] == 'RAID':
                scp_components = SCPTargetEnum.RAID
            job_wait = module.params['job_wait']

            end_host_power_state = EndHostPowerStateEnum.On
            if module.params['end_host_power_state'] == 'Off':
                end_host_power_state = EndHostPowerStateEnum.Off

            shutdown_type = ShutdownTypeEnum.Graceful
            if module.params['shutdown_type'] == 'Forced':
                shutdown_type = ShutdownTypeEnum.Forced
            elif module.params['shutdown_type'] == 'NoReboot':
                shutdown_type = ShutdownTypeEnum.NoReboot

            logger.info(
                module.params['idrac_ip'] +
                ': STARTING: Importing Server Configuration Profile Method:'
                ' Invoking OMSDK Import SCP API')
            idrac.use_redfish = True
            msg['msg'] = idrac.config_mgr.scp_import(
                myshare,
                target=scp_components,
                shutdown_type=shutdown_type,
                end_host_power_state=end_host_power_state,
                job_wait=job_wait)
            logger.info(
                module.params['idrac_ip'] +
                ': FINISHED: Importing Server Configuration Profile Method:'
                ' Invoked OMSDK Import SCP API')
            if "Status" in msg['msg']:
                if msg['msg']['Status'] == "Success":
                    if module.params['job_wait'] == True:
                        msg['changed'] = True
                        if "Message" in msg['msg']:
                            if "No changes were applied" in msg['msg'][
                                    'Message']:
                                msg['changed'] = False
                else:
                    msg['failed'] = True

    except Exception as e:
        logger.error(
            module.params['idrac_ip'] +
            ': EXCEPTION: Importing Server Configuration Profile Method: ' +
            str(e))
        err = True
        msg['msg'] = "Error: %s" % str(e)
        msg['failed'] = True
    logger.info(module.params['idrac_ip'] +
                ': FINISHED: Imported Server Configuration Profile Method')
    return msg, err
def run_server_bios_config(idrac, module):
    """
    Get Lifecycle Controller status

    Keyword arguments:
    idrac  -- iDRAC handle
    module -- Ansible module
    """
    msg = {}
    msg['changed'] = False
    msg['failed'] = False
    err = False
    temp_dir = tempfile.gettempdir() + os.sep
    share_name = module.params.get('share_name')
    share_path = share_name if share_name is not None else temp_dir
    deprecation_warning_message = 'boot_mode, nvme_mode, secure_boot_mode, onetime_boot_mode and boot_sequence options ' \
                                  'have been deprecated, and will be removed. ' \
                                  'Please use the attributes option for Bios attributes configuration instead.'
    try:
        idrac.use_redfish = True
        upd_share = file_share_manager.create_share_obj(
            share_path=share_path,
            mount_point=module.params['share_mnt'],
            isFolder=True,
            creds=UserCredentials(module.params['share_user'],
                                  module.params['share_pwd']))
        if module.params['boot_sources']:
            err, message = _validate_params(module.params['boot_sources'])
            if err:
                msg['changed'] = False
                msg['failed'] = True
                msg['msg'] = {}
                msg['msg']['Message'] = message
                msg['msg']['Status'] = "Failed"
                return msg, err
            if module.check_mode:
                msg['msg'] = idrac.config_mgr.is_change_applicable()
                if 'changes_applicable' in msg['msg']:
                    msg['changed'] = msg['msg']['changes_applicable']
                    return msg, err
            msg['msg'] = idrac.config_mgr.configure_boot_sources(
                input_boot_devices=module.params['boot_sources'])

            if "Status" in msg['msg']:
                if msg['msg']['Status'] == "Success":
                    msg['changed'] = True
                    if "Message" in msg['msg']:
                        if msg['msg'][
                                'Message'] == "No changes found to commit!":
                            msg['changed'] = False
                        elif msg['msg'][
                                'Message'] == "No changes found to apply.":
                            msg['changed'] = False
                else:
                    msg['failed'] = True
                    err = True
                    msg['changed'] = False
            return msg, err

        set_liason = idrac.config_mgr.set_liason_share(upd_share)
        if set_liason['Status'] == "Failed":
            try:
                message = set_liason['Data']['Message']
            except (IndexError, KeyError):
                message = set_liason['Message']
            err = True
            msg['msg'] = "Error: {}".format(message)
            msg['failed'] = True
            return msg, err
        if (module.params['boot_mode'] or module.params['nvme_mode']
                or ['secure_boot_mode'] or module.params['onetime_boot_mode']
                or module.params["boot_mode"]):
            module.deprecate(deprecation_warning_message, version='2.9')

        if module.params['boot_mode'] and not (module.params['attributes']
                                               and 'BootMode'
                                               in module.params['attributes']):
            idrac.config_mgr.configure_boot_mode(
                boot_mode=BootModeTypes[module.params['boot_mode']])

        if module.params['nvme_mode'] and not (module.params['attributes']
                                               and 'NvmeMode'
                                               in module.params['attributes']):
            idrac.config_mgr.configure_nvme_mode(
                nvme_mode=NvmeModeTypes[module.params['nvme_mode']])

        if module.params['secure_boot_mode'] and not (
                module.params['attributes']
                and 'SecureBootMode' in module.params['attributes']):
            idrac.config_mgr.configure_secure_boot_mode(
                secure_boot_mode=SecureBootModeTypes[
                    module.params['secure_boot_mode']])

        if module.params['onetime_boot_mode'] and not (
                module.params['attributes']
                and 'OneTimeBootMode' in module.params['attributes']):
            idrac.config_mgr.configure_onetime_boot_mode(
                onetime_boot_mode=OneTimeBootModeTypes[
                    module.params['onetime_boot_mode']])

        if module.params["boot_mode"] is not None and module.params[
                "boot_sequence"] is not None:
            idrac.config_mgr.configure_boot_sequence(
                boot_mode=BootModeEnum[module.params['boot_mode']],
                boot_sequence=module.params['boot_sequence'])

        if module.params['attributes']:
            msg['msg'] = idrac.config_mgr.configure_bios(
                bios_attr_val=module.params['attributes'])
            if msg['msg']['Status'] != 'Success':
                err = True
                msg['failed'] = True
                return msg, err

        if module.check_mode:
            msg['msg'] = idrac.config_mgr.is_change_applicable()
            if 'changes_applicable' in msg['msg']:
                msg['changed'] = msg['msg']['changes_applicable']
        else:
            msg['msg'] = idrac.config_mgr.apply_changes(reboot=True)

            if "Status" in msg['msg']:
                if msg['msg']['Status'] == "Success":
                    msg['changed'] = True
                    if "Message" in msg['msg']:
                        if msg['msg'][
                                'Message'] == "No changes found to commit!":
                            msg['changed'] = False
                        elif msg['msg'][
                                'Message'] == "No changes found to apply.":
                            msg['changed'] = False
                else:
                    msg['failed'] = True
    except Exception as e:
        err = True
        msg['msg'] = "Error: %s" % str(e)
        msg['failed'] = True
    return msg, err
def run_idrac_services_config(idrac, module):
    """
    Get Lifecycle Controller status

    Keyword arguments:
    idrac  -- iDRAC handle
    module -- Ansible module
    """
    msg = {}
    msg['changed'] = False
    msg['failed'] = False
    msg['msg'] = {}
    err = False

    try:

        idrac.use_redfish = True
        upd_share = file_share_manager.create_share_obj(share_path=module.params['share_name'],
                                                        mount_point=module.params['share_mnt'],
                                                        isFolder=True,
                                                        creds=UserCredentials(
                                                            module.params['share_user'],
                                                            module.params['share_pwd'])
                                                        )

        set_liason = idrac.config_mgr.set_liason_share(upd_share)
        if set_liason['Status'] == "Failed":
            try:
                message = set_liason['Data']['Message']
            except (IndexError, KeyError):
                message = set_liason['Message']
            err = True
            msg['msg'] = "{}".format(message)
            msg['failed'] = True
            return msg, err

        if module.params['enable_web_server'] is not None:
            idrac.config_mgr.configure_web_server(
                enable_web_server=Enable_WebServerTypes[module.params['enable_web_server']]
            )
        if module.params['http_port'] is not None:
            idrac.config_mgr.configure_web_server(
                http_port=module.params['http_port']
            )
        if module.params['https_port'] is not None:
            idrac.config_mgr.configure_web_server(
                https_port=module.params['https_port']
            )
        if module.params['timeout'] is not None:
            idrac.config_mgr.configure_web_server(
                timeout=module.params['timeout']
            )
        if module.params['ssl_encryption'] is not None:
            idrac.config_mgr.configure_web_server(
                ssl_encryption=SSLEncryptionBitLength_WebServerTypes[module.params['ssl_encryption']]
            )
        if module.params['tls_protocol'] is not None:
            idrac.config_mgr.configure_web_server(
                tls_protocol=TLSProtocol_WebServerTypes[module.params['tls_protocol']]
            )

        if module.params['snmp_enable'] is not None:
            idrac.config_mgr.configure_snmp(
                snmp_enable=AgentEnable_SNMPTypes[module.params['snmp_enable']]
            )
        if module.params['community_name'] is not None:
            idrac.config_mgr.configure_snmp(
                community_name=module.params['community_name']
            )
        if module.params['snmp_protocol'] is not None:
            idrac.config_mgr.configure_snmp(
                snmp_protocol=SNMPProtocol_SNMPTypes[module.params['snmp_protocol']]
            )
        if module.params['alert_port'] is not None:
            idrac.config_mgr.configure_snmp(
                alert_port=module.params['alert_port']
            )
        if module.params['discovery_port'] is not None:
            idrac.config_mgr.configure_snmp(
                discovery_port=module.params['discovery_port']
            )
        if module.params['trap_format'] is not None:
            idrac.config_mgr.configure_snmp(
                trap_format=module.params['trap_format']
            )

        if module.check_mode:
            msg['msg'] = idrac.config_mgr.is_change_applicable()
            if 'changes_applicable' in msg['msg']:
                msg['changed'] = msg['msg']['changes_applicable']
        else:
            msg['msg'] = idrac.config_mgr.apply_changes(reboot=False)
            if "Status" in msg['msg']:
                if msg['msg']['Status'] == "Success":
                    msg['changed'] = True
                    if "Message" in msg['msg']:
                        if msg['msg']['Message'] == "No changes found to commit!":
                            msg['changed'] = False
                else:
                    msg['failed'] = True
    except Exception as e:
        err = True
        msg['msg'] = "Error: %s" % str(e)
        msg['failed'] = True
    return msg, err
def run_setup_idrac_csior(idrac, module):
    """
    Get Lifecycle Controller status

    Keyword arguments:
    idrac  -- iDRAC handle
    module -- Ansible module
    """
    msg = {}
    msg['changed'] = False
    msg['failed'] = False
    # msg['msg'] = {}
    err = False

    try:

        idrac.use_redfish = True
        upd_share = file_share_manager.create_share_obj(
            share_path=module.params['share_name'],
            mount_point=module.params['share_mnt'],
            isFolder=True,
            creds=UserCredentials(module.params['share_user'],
                                  module.params['share_password']))

        set_liason = idrac.config_mgr.set_liason_share(upd_share)
        if set_liason['Status'] == "Failed":
            try:
                message = set_liason['Data']['Message']
            except (IndexError, KeyError):
                message = set_liason['Message']
            err = True
            msg['msg'] = "{}".format(message)
            msg['failed'] = True
            return msg, err

        if module.params['csior'] == 'Enabled':
            # Enable csior
            idrac.config_mgr.enable_csior()
        elif module.params['csior'] == 'Disabled':
            # Disable csior
            idrac.config_mgr.disable_csior()
        if module.check_mode:
            msg['msg'] = idrac.config_mgr.is_change_applicable()
            if 'changes_applicable' in msg['msg']:
                msg['changed'] = msg['msg']['changes_applicable']
        else:
            msg['msg'] = idrac.config_mgr.apply_changes(reboot=True)
            if "Status" in msg['msg']:
                if msg['msg']['Status'] == "Success":
                    msg['changed'] = True
                    if "Message" in msg['msg']:
                        if msg['msg'][
                                'Message'] == "No changes found to commit!":
                            msg['changed'] = False
                else:
                    msg['failed'] = True
    except Exception as e:
        err = True
        msg['msg'] = "Error: %s" % str(e)
        msg['failed'] = True
    return msg, err
示例#19
0
def run_import_server_config_profile(idrac, module):
    """
    Import Server Configuration Profile from a network share

    Keyword arguments:
    idrac  -- iDRAC handle
    module -- Ansible module
    """
    msg = {}
    msg['changed'] = False
    msg['failed'] = False
    msg['msg'] = {}
    err = False

    try:
        share_name = module.params['share_name']
        if share_name is None:
            message = "Share path is not valid : {}{}".format(
                os.sep, module.params['scp_file'])
            err = True
            msg['msg'] = "Error: {}".format(message)
            msg['failed'] = True
            return msg, err
        myshare = file_share_manager.create_share_obj(
            share_path="{}{}{}".format(share_name, os.sep,
                                       module.params['scp_file']),
            creds=UserCredentials(module.params['share_user'],
                                  module.params['share_pwd']),
            isFolder=False,
        )
        # myshare.new_file(module.params['scp_file'])

        scp_components = SCPTargetEnum.ALL

        if module.params['scp_components'] == 'IDRAC':
            scp_components = SCPTargetEnum.IDRAC
        elif module.params['scp_components'] == 'BIOS':
            scp_components = SCPTargetEnum.BIOS
        elif module.params['scp_components'] == 'NIC':
            scp_components = SCPTargetEnum.NIC
        elif module.params['scp_components'] == 'RAID':
            scp_components = SCPTargetEnum.RAID
        job_wait = module.params['job_wait']

        end_host_power_state = EndHostPowerStateEnum.On
        if module.params['end_host_power_state'] == 'Off':
            end_host_power_state = EndHostPowerStateEnum.Off

        shutdown_type = ShutdownTypeEnum.Graceful
        if module.params['shutdown_type'] == 'Forced':
            shutdown_type = ShutdownTypeEnum.Forced
        elif module.params['shutdown_type'] == 'NoReboot':
            shutdown_type = ShutdownTypeEnum.NoReboot

        idrac.use_redfish = True
        msg['msg'] = idrac.config_mgr.scp_import(
            myshare,
            target=scp_components,
            shutdown_type=shutdown_type,
            end_host_power_state=end_host_power_state,
            job_wait=job_wait)
        if "Status" in msg['msg']:
            if msg['msg']['Status'] == "Success":
                if module.params['job_wait'] is True:
                    msg['changed'] = True
                    if "Message" in msg['msg']:
                        if "No changes were applied" in msg['msg']['Message']:
                            msg['changed'] = False
            else:
                msg['failed'] = True

    except Exception as e:
        err = True
        msg['msg'] = "Error: %s" % str(e)
        msg['failed'] = True
    return msg, err
def run_idrac_eventing_config(idrac, module):
    """
    Get Lifecycle Controller status

    Keyword arguments:
    idrac  -- iDRAC handle
    module -- Ansible module
    """
    msg = {}
    msg['changed'] = False
    msg['failed'] = False
    msg['msg'] = {}
    err = False

    try:

        idrac.use_redfish = True
        upd_share = file_share_manager.create_share_obj(
            share_path=module.params['share_name'],
            mount_point=module.params['share_mnt'],
            isFolder=True,
            creds=UserCredentials(module.params['share_user'],
                                  module.params['share_pwd']))

        set_liason = idrac.config_mgr.set_liason_share(upd_share)
        if set_liason['Status'] == "Failed":
            try:
                message = set_liason['Data']['Message']
            except (IndexError, KeyError):
                message = set_liason['Message']
            err = True
            msg['msg'] = "{}".format(message)
            msg['failed'] = True
            return msg, err

        if module.params["destination_number"] is not None:
            if module.params["destination"] is not None:
                idrac.config_mgr.configure_snmp_trap_destination(
                    destination=module.params["destination"],
                    destination_number=module.params["destination_number"])
            if module.params["snmp_v3_username"] is not None:
                idrac.config_mgr.configure_snmp_trap_destination(
                    snmp_v3_username=module.params["snmp_v3_username"],
                    destination_number=module.params["destination_number"])
            if module.params["snmp_trap_state"] is not None:
                idrac.config_mgr.configure_snmp_trap_destination(
                    state=State_SNMPAlertTypes[
                        module.params["snmp_trap_state"]],
                    destination_number=module.params["destination_number"])

        if module.params["alert_number"] is not None:
            if module.params["email_alert_state"] is not None:
                idrac.config_mgr.configure_email_alerts(
                    state=Enable_EmailAlertTypes[
                        module.params["email_alert_state"]],
                    alert_number=module.params["alert_number"])
            if module.params["address"] is not None:
                idrac.config_mgr.configure_email_alerts(
                    address=module.params["address"],
                    alert_number=module.params["alert_number"])
            if module.params["custom_message"] is not None:
                idrac.config_mgr.configure_email_alerts(
                    custom_message=module.params["custom_message"],
                    alert_number=module.params["alert_number"])

        if module.params["enable_alerts"] is not None:
            idrac.config_mgr.configure_idrac_alerts(
                enable_alerts=AlertEnable_IPMILanTypes[
                    module.params["enable_alerts"]], )

        if module.params['authentication'] is not None:
            idrac.config_mgr.configure_smtp_server_settings(
                authentication=SMTPAuthentication_RemoteHostsTypes[
                    module.params['authentication']])
        if module.params['smtp_ip_address'] is not None:
            idrac.config_mgr.configure_smtp_server_settings(
                smtp_ip_address=module.params['smtp_ip_address'])
        if module.params['smtp_port'] is not None:
            idrac.config_mgr.configure_smtp_server_settings(
                smtp_port=module.params['smtp_port'])
        if module.params['username'] is not None:
            idrac.config_mgr.configure_smtp_server_settings(
                username=module.params['username'])
        if module.params['password'] is not None:
            idrac.config_mgr.configure_smtp_server_settings(
                password=module.params['password'])

        if module.check_mode:
            msg['msg'] = idrac.config_mgr.is_change_applicable()
            if 'changes_applicable' in msg['msg']:
                msg['changed'] = msg['msg']['changes_applicable']
        else:
            msg['msg'] = idrac.config_mgr.apply_changes(reboot=False)
            if "Status" in msg['msg']:
                if msg['msg']['Status'] == "Success":
                    msg['changed'] = True
                    if "Message" in msg['msg']:
                        if msg['msg'][
                                'Message'] == "No changes found to commit!":
                            msg['changed'] = False
                        if "No changes were applied" in msg['msg']['Message']:
                            msg['changed'] = False
                else:
                    msg['failed'] = True
    except Exception as e:
        err = True
        msg['msg'] = "Error: %s" % str(e)
        msg['failed'] = True
    return msg, err
def run_server_raid_config(idrac, module):
    """
    Get Lifecycle Controller status

    Keyword arguments:
    idrac  -- iDRAC handle
    module -- Ansible module
    """
    msg = {}
    msg['changed'] = False
    msg['failed'] = False
    err = False
    try:

        idrac.use_redfish = True
        upd_share = file_share_manager.create_share_obj(
            share_path=module.params['share_name'],
            mount_point=module.params['share_mnt'],
            isFolder=True,
            creds=UserCredentials(module.params['share_user'],
                                  module.params['share_pwd']))

        set_liason = idrac.config_mgr.set_liason_share(upd_share)
        if set_liason['Status'] == "Failed":
            try:
                message = set_liason['Data']['Message']
            except (IndexError, KeyError):
                message = set_liason['Message']
            err = True
            msg['msg'] = "{}".format(message)
            msg['failed'] = True
            return msg, err

        if module.params['state'] == "present":
            # Create VD

            # Physical Disk filter
            pd_filter = '((disk.parent.parent is Controller and disk.parent.parent.FQDD._value == "{0}")'.format(
                module.params['controller_fqdd'])
            pd_filter += ' or (disk.parent is Controller and disk.parent.FQDD._value == "{0}"))'.format(
                module.params['controller_fqdd'])
            pd_filter += ' and disk.MediaType == "{0}"'.format(
                module.params['media_type'])
            pd_filter += ' and disk.BusProtocol == "{0}"'.format(
                module.params['bus_protocol'])

            msg['msg'] = idrac.config_mgr.RaidHelper.new_virtual_disk(
                # VirtualDisk parameters
                Name=module.params['vd_name'],
                SpanDepth=module.params['span_depth'],
                SpanLength=module.params['span_length'],
                NumberDedicatedHotSpare=module.
                params['number_dedicated_hot_spare'],
                NumberGlobalHotSpare=module.params['number_global_hot_spare'],
                RAIDTypes=module.params['raid_level'],
                DiskCachePolicy=module.params['disk_cache_policy'],
                RAIDdefaultWritePolicy=module.params['write_cache_policy'],
                RAIDdefaultReadPolicy=module.params['read_cache_policy'],
                StripeSize=module.params['stripe_size'],
                RAIDforeignConfig="Clear",
                RAIDaction=RAIDactionTypes.Create,
                PhysicalDiskFilter=pd_filter)

        if module.params['state'] == "absent":
            # Remove VD
            if module.params['vd_name'] is None:
                message = 'Virtual disk name is a required parameter for remove virtual disk operations.'
                err = True
                msg['msg'] = "{}".format(message)
                msg['failed'] = True
                return msg, err
            msg['msg'] = idrac.config_mgr.RaidHelper.delete_virtual_disk(
                Name=module.params['vd_name'])
        if "Status" in msg['msg']:
            if msg['msg']['Status'] == "Success":
                msg['changed'] = True
                if "Message" in msg['msg']:
                    if msg['msg']['Message'] == "No changes found to commit!":
                        msg['changed'] = False
            else:
                msg['failed'] = True
    except Exception as e:
        err = True
        msg['msg'] = "Error: %s" % str(e)
        msg['failed'] = True
    return msg, err
示例#22
0
def run_idrac_network_config(idrac, module):
    idrac.use_redfish = True
    upd_share = file_share_manager.create_share_obj(
        share_path=module.params['share_name'],
        mount_point=module.params['share_mnt'],
        isFolder=True,
        creds=UserCredentials(module.params['share_user'],
                              module.params['share_password']))
    if not upd_share.IsValid:
        module.fail_json(
            msg="Unable to access the share. Ensure that the share name, "
            "share mount, and share credentials provided are correct.")
    idrac.config_mgr.set_liason_share(upd_share)
    if module.params['register_idrac_on_dns'] is not None:
        idrac.config_mgr.configure_dns(
            register_idrac_on_dns=DNSRegister_NICTypes[
                module.params['register_idrac_on_dns']])
    if module.params['dns_idrac_name'] is not None:
        idrac.config_mgr.configure_dns(
            dns_idrac_name=module.params['dns_idrac_name'])
    if module.params['auto_config'] is not None:
        idrac.config_mgr.configure_dns(
            auto_config=DNSDomainFromDHCP_NICStaticTypes[
                module.params['auto_config']])
    if module.params['static_dns'] is not None:
        idrac.config_mgr.configure_dns(static_dns=module.params['static_dns'])

    if module.params['setup_idrac_nic_vlan'] is not None:
        idrac.config_mgr.configure_nic_vlan(vlan_enable=VLanEnable_NICTypes[
            module.params['setup_idrac_nic_vlan']])
    if module.params['vlan_id'] is not None:
        idrac.config_mgr.configure_nic_vlan(vlan_id=module.params['vlan_id'])
    if module.params['vlan_priority'] is not None:
        idrac.config_mgr.configure_nic_vlan(
            vlan_priority=module.params['vlan_priority'])

    if module.params['enable_nic'] is not None:
        idrac.config_mgr.configure_network_settings(
            enable_nic=Enable_NICTypes[module.params['enable_nic']])
    if module.params['nic_selection'] is not None:
        idrac.config_mgr.configure_network_settings(
            nic_selection=Selection_NICTypes[module.params['nic_selection']])
    if module.params['failover_network'] is not None:
        idrac.config_mgr.configure_network_settings(
            failover_network=Failover_NICTypes[
                module.params['failover_network']])
    if module.params['auto_detect'] is not None:
        idrac.config_mgr.configure_network_settings(
            auto_detect=AutoDetect_NICTypes[module.params['auto_detect']])
    if module.params['auto_negotiation'] is not None:
        idrac.config_mgr.configure_network_settings(
            auto_negotiation=Autoneg_NICTypes[
                module.params['auto_negotiation']])
    if module.params['network_speed'] is not None:
        idrac.config_mgr.configure_network_settings(
            network_speed=Speed_NICTypes[module.params['network_speed']])
    if module.params['duplex_mode'] is not None:
        idrac.config_mgr.configure_network_settings(
            duplex_mode=Duplex_NICTypes[module.params['duplex_mode']])
    if module.params['nic_mtu'] is not None:
        idrac.config_mgr.configure_network_settings(
            nic_mtu=module.params['nic_mtu'])

    if module.params['enable_dhcp'] is not None:
        idrac.config_mgr.configure_ipv4(
            enable_dhcp=DHCPEnable_IPv4Types[module.params["enable_dhcp"]])
    if module.params['ip_address'] is not None:
        idrac.config_mgr.configure_ipv4(ip_address=module.params["ip_address"])
    if module.params['enable_ipv4'] is not None:
        idrac.config_mgr.configure_ipv4(
            enable_ipv4=Enable_IPv4Types[module.params["enable_ipv4"]])
    if module.params['dns_from_dhcp'] is not None:
        idrac.config_mgr.configure_static_ipv4(
            dns_from_dhcp=DNSFromDHCP_IPv4StaticTypes[
                module.params["dns_from_dhcp"]])
    if module.params['static_dns_1'] is not None:
        idrac.config_mgr.configure_static_ipv4(
            dns_1=module.params["static_dns_1"])
    if module.params['static_dns_2'] is not None:
        idrac.config_mgr.configure_static_ipv4(
            dns_2=module.params["static_dns_2"])
    if module.params['static_gateway'] is not None:
        idrac.config_mgr.configure_static_ipv4(
            gateway=module.params["static_gateway"])
    if module.params['static_net_mask'] is not None:
        idrac.config_mgr.configure_static_ipv4(
            net_mask=module.params["static_net_mask"])

    if module.check_mode:
        msg = idrac.config_mgr.is_change_applicable()
    else:
        msg = idrac.config_mgr.apply_changes(reboot=False)
    return msg
def run_export_server_config_profile(idrac, module):
    """
    Export Server Configuration Profile to a network share

    Keyword arguments:
    idrac  -- iDRAC handle
    module -- Ansible module
    """
    from omdrivers.enums.iDRAC.iDRACEnums import SCPTargetEnum, ExportFormatEnum, ExportUseEnum

    msg = {}
    msg['changed'] = False
    msg['failed'] = False
    err = False

    try:
        if module.params['export_format'].lower() == 'JSON'.lower():
            export_format = ExportFormatEnum.JSON
            scp_file_name_format = "%ip_%Y%m%d_%H%M%S_scp.json"
        elif module.params['export_format'].lower() == 'XML'.lower():
            export_format = ExportFormatEnum.XML
            scp_file_name_format = "%ip_%Y%m%d_%H%M%S_scp.xml"

        myshare = file_share_manager.create_share_obj(share_path=module.params['share_name'],
                                                      creds=UserCredentials(module.params['share_user'],
                                                                            module.params['share_pwd']),
                                                      isFolder=True, )

        scp_file_name = myshare.new_file(scp_file_name_format)

        target = SCPTargetEnum.ALL

        if module.params['scp_components'] == 'IDRAC':
            target = SCPTargetEnum.IDRAC
        elif module.params['scp_components'] == 'BIOS':
            target = SCPTargetEnum.BIOS
        elif module.params['scp_components'] == 'NIC':
            target = SCPTargetEnum.NIC
        elif module.params['scp_components'] == 'RAID':
            target = SCPTargetEnum.RAID
        job_wait = module.params['job_wait']

        if module.params['export_use'].lower() == 'Default'.lower():
            export_use = ExportUseEnum.Default
        elif module.params['export_use'].lower() == 'Clone'.lower():
            export_use = ExportUseEnum.Clone
        elif module.params['export_use'].lower() == 'Replace'.lower():
            export_use = ExportUseEnum.Replace

        idrac.use_redfish = True
        msg['msg'] = idrac.config_mgr.scp_export(scp_file_name,
                                                 target=target,
                                                 export_format=export_format,
                                                 export_use=export_use,
                                                 job_wait=job_wait)
        if 'Status' in msg['msg'] and msg['msg']['Status'] != "Success":
            msg['failed'] = True

    except Exception as e:
        err = True
        msg['msg'] = "Error: %s" % str(e)
        msg['failed'] = True
    return msg, err
示例#24
0
def run_idrac_eventing_config(idrac, module):
    """
    Get Lifecycle Controller status

    Keyword arguments:
    idrac  -- iDRAC handle
    module -- Ansible module
    """
    idrac.use_redfish = True
    upd_share = file_share_manager.create_share_obj(
        share_path=module.params['share_name'],
        mount_point=module.params['share_mnt'],
        isFolder=True,
        creds=UserCredentials(module.params['share_user'],
                              module.params['share_password']))
    if not upd_share.IsValid:
        module.fail_json(
            msg="Unable to access the share. Ensure that the share name, "
            "share mount, and share credentials provided are correct.")
    set_liason = idrac.config_mgr.set_liason_share(upd_share)
    if set_liason['Status'] == "Failed":
        try:
            message = set_liason['Data']['Message']
        except (IndexError, KeyError):
            message = set_liason['Message']
        module.fail_json(msg=message)

    if module.params["destination_number"] is not None:
        if module.params["destination"] is not None:
            idrac.config_mgr.configure_snmp_trap_destination(
                destination=module.params["destination"],
                destination_number=module.params["destination_number"])
        if module.params["snmp_v3_username"] is not None:
            idrac.config_mgr.configure_snmp_trap_destination(
                snmp_v3_username=module.params["snmp_v3_username"],
                destination_number=module.params["destination_number"])
        if module.params["snmp_trap_state"] is not None:
            idrac.config_mgr.configure_snmp_trap_destination(
                state=State_SNMPAlertTypes[module.params["snmp_trap_state"]],
                destination_number=module.params["destination_number"])

    if module.params["alert_number"] is not None:
        if module.params["email_alert_state"] is not None:
            idrac.config_mgr.configure_email_alerts(
                state=Enable_EmailAlertTypes[
                    module.params["email_alert_state"]],
                alert_number=module.params["alert_number"])
        if module.params["address"] is not None:
            idrac.config_mgr.configure_email_alerts(
                address=module.params["address"],
                alert_number=module.params["alert_number"])
        if module.params["custom_message"] is not None:
            idrac.config_mgr.configure_email_alerts(
                custom_message=module.params["custom_message"],
                alert_number=module.params["alert_number"])

    if module.params["enable_alerts"] is not None:
        idrac.config_mgr.configure_idrac_alerts(
            enable_alerts=AlertEnable_IPMILanTypes[
                module.params["enable_alerts"]], )

    if module.params['authentication'] is not None:
        idrac.config_mgr.configure_smtp_server_settings(
            authentication=SMTPAuthentication_RemoteHostsTypes[
                module.params['authentication']])
    if module.params['smtp_ip_address'] is not None:
        idrac.config_mgr.configure_smtp_server_settings(
            smtp_ip_address=module.params['smtp_ip_address'])
    if module.params['smtp_port'] is not None:
        idrac.config_mgr.configure_smtp_server_settings(
            smtp_port=module.params['smtp_port'])
    if module.params['username'] is not None:
        idrac.config_mgr.configure_smtp_server_settings(
            username=module.params['username'])
    if module.params['password'] is not None:
        idrac.config_mgr.configure_smtp_server_settings(
            password=module.params['password'])

    if module.check_mode:
        status = idrac.config_mgr.is_change_applicable()
        if status.get("changes_applicable"):
            module.exit_json(msg="Changes found to commit!", changed=True)
        else:
            module.exit_json(msg="No changes found to commit!")
    else:
        status = idrac.config_mgr.apply_changes(reboot=False)

    return status
示例#25
0
def run_idrac_timezone_config(idrac, module):
    """
    Get Lifecycle Controller status

    Keyword arguments:
    idrac  -- iDRAC handle
    module -- Ansible module
    """
    msg = {}
    msg['changed'] = False
    msg['failed'] = False
    msg['msg'] = {}
    err = False

    try:

        idrac.use_redfish = True
        upd_share = file_share_manager.create_share_obj(
            share_path=module.params['share_name'],
            mount_point=module.params['share_mnt'],
            isFolder=True,
            creds=UserCredentials(module.params['share_user'],
                                  module.params['share_pwd']))

        set_liason = idrac.config_mgr.set_liason_share(upd_share)
        if set_liason['Status'] == "Failed":
            try:
                message = set_liason['Data']['Message']
            except (IndexError, KeyError):
                message = set_liason['Message']
            err = True
            msg['msg'] = "{}".format(message)
            msg['failed'] = True
            return msg, err

        if module.params['setup_idrac_timezone'] is not None:
            idrac.config_mgr.configure_timezone(
                module.params['setup_idrac_timezone'])

        if module.params['enable_ntp'] is not None:
            idrac.config_mgr.configure_ntp(
                enable_ntp=NTPEnable_NTPConfigGroupTypes[
                    module.params['enable_ntp']])
        if module.params['ntp_server_1'] is not None:
            idrac.config_mgr.configure_ntp(
                ntp_server_1=module.params['ntp_server_1'])
        if module.params['ntp_server_2'] is not None:
            idrac.config_mgr.configure_ntp(
                ntp_server_2=module.params['ntp_server_2'])
        if module.params['ntp_server_3'] is not None:
            idrac.config_mgr.configure_ntp(
                ntp_server_3=module.params['ntp_server_3'])

        if module.check_mode:
            msg['msg'] = idrac.config_mgr.is_change_applicable()
            if 'changes_applicable' in msg['msg']:
                msg['changed'] = msg['msg']['changes_applicable']
        else:
            msg['msg'] = idrac.config_mgr.apply_changes(reboot=False)
            if "Status" in msg['msg']:
                if msg['msg']['Status'] == "Success":
                    msg['changed'] = True
                    if "Message" in msg['msg']:
                        if msg['msg'][
                                'Message'] == "No changes found to commit!":
                            msg['changed'] = False
                else:
                    msg['failed'] = True
    except Exception as e:
        err = True
        msg['msg'] = "Error: %s" % str(e)
        msg['failed'] = True
    return msg, err
示例#26
0
def run_server_raid_config(idrac, module):
    """
    Get Lifecycle Controller status

    Keyword arguments:
    idrac  -- iDRAC handle
    module -- Ansible module
    """
    msg = {}
    msg['changed'] = False
    msg['failed'] = False
    err = False
    share_name = Constants.share_name
    try:
        if module.params['state'] == "view":
            msg = view_storage(idrac, module)
            if msg['msg']['Status'] == 'Failed':
                msg['msg']['failed'] = True
                err = True
            return msg, err

        idrac.use_redfish = True
        upd_share = file_share_manager.create_share_obj(share_path=share_name,
                                                        isFolder=True)
        set_liason = idrac.config_mgr.set_liason_share(upd_share)
        if set_liason['Status'] == "Failed":
            try:
                message = set_liason['Data']['Message']
            except (IndexError, KeyError):
                message = set_liason['Message']
            err = True
            msg['msg'] = "{}".format(message)
            msg['failed'] = True
            return msg, err

        if module.params['state'] == "create":
            # Create VD
            # Physical Disk filter

            if module.params["controller_id"] is None or module.params[
                    "controller_id"] is "":
                err = True
                msg['msg'] = 'Controller ID is required.'
                msg['failed'] = True
                return msg, err

            pd_filter = '((disk.parent.parent is Controller and ' \
                        'disk.parent.parent.FQDD._value == "{0}")'\
                .format(module.params["controller_id"])
            pd_filter += ' or (disk.parent is Controller and ' \
                         'disk.parent.FQDD._value == "{0}"))'\
                .format(module.params["controller_id"])

            vd_values = []
            if module.params['vd_values'] is not None:
                for each in module.params['vd_values']:
                    mod_args = copy.deepcopy(module.params)
                    msg, err, each_vd = multiple_vd_config(mod_args=mod_args,
                                                           each_vd=each,
                                                           pd_filter=pd_filter)
                    if err:
                        return msg, err
                    vd_values.append(each_vd)
            else:
                msg, err, each_vd = multiple_vd_config(mod_args=module.params,
                                                       pd_filter=pd_filter)
                if err:
                    return msg, err
                vd_values.append(each_vd)
            msg['msg'] = idrac.config_mgr.RaidHelper.new_virtual_disk(
                multiple_vd=vd_values, apply_changes=not module.check_mode)
        if module.params['state'] == "delete":
            # Remove VD
            message = 'Virtual disk name is a required parameter for remove virtual disk operations.'
            if module.params['vd_values'] is None or None in module.params[
                    'vd_values']:
                message = message
                err = True
                msg['msg'] = "{}".format(message)
                msg['failed'] = True
                return msg, err
            elif module.params['vd_values']:
                if not all("name" in each
                           for each in module.params['vd_values']):
                    err = True
                    msg['msg'] = message
                    msg['failed'] = True
                    return msg, err
                names = [key.get("name") for key in module.params['vd_values']]
            msg['msg'] = idrac.config_mgr.RaidHelper.delete_virtual_disk(
                vd_names=names, apply_changes=not module.check_mode)
        if 'changes_applicable' in msg['msg']:
            msg['changed'] = msg['msg']['changes_applicable']
        else:
            if "Status" in msg["msg"]:
                if msg["msg"]["Status"] == "Success":
                    msg["changed"] = True
                    if "Message" in msg["msg"]:
                        if msg["msg"]["Message"] == "No changes found to commit!" \
                                or msg["msg"]["Message"] == "Unable to find the virtual disk":
                            msg["changed"] = False
                else:
                    msg["failed"] = True
    except Exception as e:
        err = True
        msg["msg"] = "Error: %s" % str(e)
        msg["failed"] = True
    finally:
        module.params["volumes"] = module.params.pop("vd_values")
        module.params["volume_id"] = module.params.pop("vd_fqdd")
    return msg, err
def run_idrac_network_config(idrac, module):
    """
    Get Lifecycle Controller status

    Keyword arguments:
    idrac  -- iDRAC handle
    module -- Ansible module
    """
    msg = {}
    msg['changed'] = False
    msg['failed'] = False
    msg['msg'] = {}
    err = False

    try:

        idrac.use_redfish = True
        upd_share = file_share_manager.create_share_obj(
            share_path=module.params['share_name'],
            mount_point=module.params['share_mnt'],
            isFolder=True,
            creds=UserCredentials(module.params['share_user'],
                                  module.params['share_pwd']))

        set_liason = idrac.config_mgr.set_liason_share(upd_share)
        if set_liason['Status'] == "Failed":
            try:
                message = set_liason['Data']['Message']
            except (IndexError, KeyError):
                message = set_liason['Message']
            err = True
            msg['msg'] = "{}".format(message)
            msg['failed'] = True
            return msg, err

        if module.params['register_idrac_on_dns'] is not None:
            idrac.config_mgr.configure_dns(
                register_idrac_on_dns=DNSRegister_NICTypes[
                    module.params['register_idrac_on_dns']])
        if module.params['dns_idrac_name'] is not None:
            idrac.config_mgr.configure_dns(
                dns_idrac_name=module.params['dns_idrac_name'])
        if module.params['auto_config'] is not None:
            idrac.config_mgr.configure_dns(
                auto_config=DNSDomainFromDHCP_NICStaticTypes[
                    module.params['auto_config']])
        if module.params['static_dns'] is not None:
            idrac.config_mgr.configure_dns(
                static_dns=module.params['static_dns'])

        if module.params['setup_idrac_nic_vlan'] is not None:
            idrac.config_mgr.configure_nic_vlan(
                vlan_enable=VLanEnable_NICTypes[
                    module.params['setup_idrac_nic_vlan']])
        if module.params['vlan_id'] is not None:
            idrac.config_mgr.configure_nic_vlan(
                vlan_id=module.params['vlan_id'])
        if module.params['vlan_priority'] is not None:
            idrac.config_mgr.configure_nic_vlan(
                vlan_priority=module.params['vlan_priority'])

        if module.params['enable_nic'] is not None:
            idrac.config_mgr.configure_network_settings(
                enable_nic=Enable_NICTypes[module.params['enable_nic']])
        if module.params['nic_selection'] is not None:
            idrac.config_mgr.configure_network_settings(
                nic_selection=Selection_NICTypes[
                    module.params['nic_selection']])
        if module.params['failover_network'] is not None:
            idrac.config_mgr.configure_network_settings(
                failover_network=Failover_NICTypes[
                    module.params['failover_network']])
        if module.params['auto_detect'] is not None:
            idrac.config_mgr.configure_network_settings(
                auto_detect=AutoDetect_NICTypes[module.params['auto_detect']])
        if module.params['auto_negotiation'] is not None:
            idrac.config_mgr.configure_network_settings(
                auto_negotiation=Autoneg_NICTypes[
                    module.params['auto_negotiation']])
        if module.params['network_speed'] is not None:
            idrac.config_mgr.configure_network_settings(
                network_speed=Speed_NICTypes[module.params['network_speed']])
        if module.params['duplex_mode'] is not None:
            idrac.config_mgr.configure_network_settings(
                duplex_mode=Duplex_NICTypes[module.params['duplex_mode']])
        if module.params['nic_mtu'] is not None:
            idrac.config_mgr.configure_network_settings(
                nic_mtu=module.params['nic_mtu'])

        if module.params['enable_dhcp'] is not None:
            idrac.config_mgr.configure_ipv4(
                enable_dhcp=DHCPEnable_IPv4Types[module.params["enable_dhcp"]])
        if module.params['ip_address'] is not None:
            idrac.config_mgr.configure_ipv4(
                ip_address=module.params["ip_address"])
        if module.params['enable_ipv4'] is not None:
            idrac.config_mgr.configure_ipv4(
                enable_ipv4=Enable_IPv4Types[module.params["enable_ipv4"]])
        if module.params['dns_from_dhcp'] is not None:
            idrac.config_mgr.configure_static_ipv4(
                dns_from_dhcp=DNSFromDHCP_IPv4StaticTypes[
                    module.params["dns_from_dhcp"]])
        if module.params['static_dns_1'] is not None:
            idrac.config_mgr.configure_static_ipv4(
                dns_1=module.params["static_dns_1"])
        if module.params['static_dns_2'] is not None:
            idrac.config_mgr.configure_static_ipv4(
                dns_2=module.params["static_dns_2"])
        if module.params['static_gateway'] is not None:
            idrac.config_mgr.configure_static_ipv4(
                gateway=module.params["static_gateway"])
        if module.params['static_net_mask'] is not None:
            idrac.config_mgr.configure_static_ipv4(
                net_mask=module.params["static_net_mask"])

        if module.check_mode:
            msg['msg'] = idrac.config_mgr.is_change_applicable()
            if 'changes_applicable' in msg['msg']:
                msg['changed'] = msg['msg']['changes_applicable']
        else:
            msg['msg'] = idrac.config_mgr.apply_changes(reboot=False)
            if "Status" in msg['msg']:
                if msg['msg']['Status'] == "Success":
                    msg['changed'] = True
                    if "Message" in msg['msg']:
                        if msg['msg'][
                                'Message'] == "No changes found to commit!":
                            msg['changed'] = False
                        if "No changes were applied" in msg['msg']['Message']:
                            msg['changed'] = False
                else:
                    msg['failed'] = True
    except Exception as e:
        err = True
        msg['msg'] = "Error: %s" % str(e)
        msg['failed'] = True
    return msg, err
def run_idrac_users_config(idrac, module):
    """
    Get Lifecycle Controller status
    Keyword arguments:
    idrac  -- iDRAC handle
    module -- Ansible module
    """
    msg = {}
    msg['changed'] = False
    msg['failed'] = False
    msg['msg'] = {}
    err = False

    try:

        idrac.use_redfish = True
        upd_share = file_share_manager.create_share_obj(
            share_path=module.params['share_name'],
            mount_point=module.params['share_mnt'],
            isFolder=True,
            creds=UserCredentials(module.params['share_user'],
                                  module.params['share_pwd']))

        set_liason = idrac.config_mgr.set_liason_share(upd_share)
        if set_liason['Status'] == "Failed":
            try:
                message = set_liason['Data']['Message']
            except (IndexError, KeyError):
                message = set_liason['Message']
            err = True
            msg['msg'] = "{}".format(message)
            msg['failed'] = True
            return msg, err

        enable_users = solenable_users = protocolenable_users = None
        privilege_users = ipmilanprivilege_users = ipmiserialprivilege_users = None
        if module.params['enable_users'] is not None:
            enable_users = Enable_UsersTypes[module.params['enable_users']]
        if module.params['solenable_users'] is not None:
            solenable_users = SolEnable_UsersTypes[
                module.params['solenable_users']]
        if module.params['protocolenable_users'] is not None:
            protocolenable_users = ProtocolEnable_UsersTypes[
                module.params['protocolenable_users']]

        if module.params['privilege_users'] is not None:
            privilege_users = Privilege_UsersTypes[
                module.params['privilege_users']]
        if module.params['ipmilanprivilege_users'] is not None:
            ipmilanprivilege_users = IpmiLanPrivilege_UsersTypes[
                module.params['ipmilanprivilege_users']]
        if module.params['ipmiserialprivilege_users'] is not None:
            ipmiserialprivilege_users = IpmiSerialPrivilege_UsersTypes[
                module.params['ipmiserialprivilege_users']]

        authenticationprotocol_users = privacyprotocol_users = None
        if module.params['authenticationprotocol_users'] is not None:
            authenticationprotocol_users = AuthenticationProtocol_UsersTypes[
                module.params['authenticationprotocol_users']]
        if module.params['privacyprotocol_users'] is not None:
            privacyprotocol_users = PrivacyProtocol_UsersTypes[
                module.params['privacyprotocol_users']]

        if module.params['action'] == 'create':
            if module.check_mode:
                user = idrac.config_mgr._sysconfig.iDRAC.Users.find_first(
                    UserName_Users=module.params['user_name'])
                if user:
                    msg['msg'] = {
                        'Status': 'Success',
                        'Message': 'No changes found to commit',
                        'changes_applicable': False
                    }
                    msg['changed'] = msg['msg']['changes_applicable']
                    return msg, err

            idrac.user_mgr.Users.new(
                UserName_Users=module.params['user_name'],
                Password_Users=module.params['user_password'],
                Privilege_Users=privilege_users,
                IpmiLanPrivilege_Users=ipmilanprivilege_users,
                IpmiSerialPrivilege_Users=ipmiserialprivilege_users,
                Enable_Users=enable_users,
                SolEnable_Users=solenable_users,
                ProtocolEnable_Users=protocolenable_users,
                AuthenticationProtocol_Users=authenticationprotocol_users,
                PrivacyProtocol_Users=privacyprotocol_users)

        if module.params['action'] == 'modify':
            user = idrac.config_mgr._sysconfig.iDRAC.Users.find_first(
                UserName_Users=module.params['user_name'])
            if user:
                if module.params['user_password'] is not None:
                    user.Password_Users.set_value(
                        module.params['user_password'])
                if privilege_users is not None:
                    user.Privilege_Users.set_value(privilege_users)
                if ipmilanprivilege_users is not None:
                    user.IpmiLanPrivilege_Users.set_value(
                        ipmilanprivilege_users)
                if ipmiserialprivilege_users is not None:
                    user.IpmiSerialPrivilege_Users.set_value(
                        ipmiserialprivilege_users)
                if enable_users is not None:
                    user.Enable_Users.set_value(enable_users)
                if solenable_users is not None:
                    user.SolEnable_Users.set_value(solenable_users)
                if protocolenable_users is not None:
                    user.ProtocolEnable_Users.set_value(protocolenable_users)
                if authenticationprotocol_users is not None:
                    user.AuthenticationProtocol_Users.set_value(
                        authenticationprotocol_users)
                if privacyprotocol_users is not None:
                    user.PrivacyProtocol_Users.set_value(privacyprotocol_users)
            else:
                message = "User: {} does not exist".format(
                    module.params['user_name'])
                err = True
                msg['msg'] = "{}".format(message)
                msg['failed'] = True
                return msg, err

        if module.params['action'] == 'delete':
            idrac.user_mgr.Users.remove(
                UserName_Users=module.params['user_name'])

        if module.check_mode:
            msg['msg'] = idrac.config_mgr.is_change_applicable()
            if 'changes_applicable' in msg['msg']:
                msg['changed'] = msg['msg']['changes_applicable']
        else:
            msg['msg'] = idrac.config_mgr.apply_changes()

            if "Status" in msg['msg']:
                if msg['msg']['Status'] == "Success":
                    msg['changed'] = True
                    if "Message" in msg['msg']:
                        if msg['msg'][
                                'Message'] == "No changes found to commit!":
                            msg['changed'] = False
                else:
                    msg['failed'] = True
    except Exception as e:
        err = True
        msg['msg'] = "Error: %s" % str(e)
        msg['failed'] = True
    return msg, err