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
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 update_firmware(idrac, module):
    """Update firmware from a network share and return the job details."""
    msg = {}
    msg['changed'] = False
    msg['update_status'] = {}

    try:
        upd_share = FileOnShare(remote=module.params['share_name'] + "/" +
                                module.params['catalog_file_name'],
                                mount_point=module.params['share_mnt'],
                                isFolder=False,
                                creds=UserCredentials(
                                    module.params['share_user'],
                                    module.params['share_password']))

        idrac.use_redfish = True
        if '12' in idrac.ServerGeneration or '13' in idrac.ServerGeneration:
            idrac.use_redfish = False

        apply_update = True
        msg['update_status'] = idrac.update_mgr.update_from_repo(
            upd_share, apply_update, module.params['reboot'],
            module.params['job_wait'])
    except RuntimeError as e:
        module.fail_json(msg=str(e))

    if "Status" in msg['update_status']:
        if msg['update_status']['Status'] == "Success":
            if module.params['job_wait']:
                msg['changed'] = True
        else:
            module.fail_json(msg='Failed to update firmware.',
                             update_status=msg['update_status'])
    return msg
コード例 #4
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
    """
    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=UserCredentials(module.params['share_user'],
                                                                            module.params['share_pwd']),
                                                      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 export_tech_support_report(idrac, module):
    """
    Export Tech Support Report (TSR)

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

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

    try:
        tsr_file_name_format = "%ip_%Y%m%d_%H%M%S_tsr.zip"

        myshare = FileOnShare(remote=module.params['share_name'],
                              isFolder=True)
        myshare.addcreds(
            UserCredentials(module.params['share_user'],
                            module.params['share_pwd']))
        tsr_file_name = myshare.new_file(tsr_file_name_format)

        msg['msg'] = idrac.config_mgr.export_tsr(tsr_file_name)

        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
コード例 #6
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
コード例 #7
0
def 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:
        if module.check_mode:
            msg['changed'] = True
        else:
            myshare = FileOnShare(remote=module.params['share_name'],
                                  mount_point=module.params['share_mnt'],
                                  isFolder=True)
            myshare.addcreds(
                UserCredentials(module.params['share_user'],
                                module.params['share_pwd']))
            scp_file_path = 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

            msg['msg'] = idrac.config_mgr.scp_import(
                scp_share_path=scp_file_path,
                components=scp_components,
                format_file=ExportFormatEnum.XML,
                reboot=module.params['reboot'],
                job_wait=module.params['job_wait'])

            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 run_update_fw_from_nw_share(idrac, module):
    """
    Update firmware from a network share
    Keyword arguments:
    idrac  -- iDRAC handle
    module -- Ansible module
    """

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

    try:
        invalid, message = _validate_catalog_file(module.params)
        if invalid:
            err = True
            msg['msg'] = message
            msg['failed'] = True
            return msg, err

        share_name = module.params['share_name']
        if share_name is None:
            share_name = ''
        upd_share = FileOnShare(
            remote="{}{}{}".format(share_name, os.sep,
                                   module.params['catalog_file_name']),
            mount_point=module.params['share_mnt'],
            isFolder=False,
            creds=UserCredentials(module.params['share_user'],
                                  module.params['share_pwd']))

        idrac.use_redfish = True
        if '12' in idrac.ServerGeneration or '13' in idrac.ServerGeneration:
            idrac.use_redfish = False

        # upd_share_file_path = upd_share.new_file("Catalog.xml")

        apply_update = True
        msg['msg'] = idrac.update_mgr.update_from_repo(
            upd_share, apply_update, module.params['reboot'],
            module.params['job_wait'])

        if "Status" in msg['msg']:
            if msg['msg']['Status'] == "Success":
                if module.params['job_wait'] is True:
                    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
コード例 #9
0
ファイル: CollectInventory.py プロジェクト: hunter007VN/omsdk
def CollectInventory(arglist):
    parser = ArgumentParser(description='Inventory Collector')
    parser.add_argument('-u', '--user', 
        action="store", dest="user", type=str, nargs='?',
        default='root', help="Username to use for iDRAC")
    parser.add_argument('-p', '--password', 
        action="store", dest="password", type=str,
        default='calvin', help="Password to use for iDRAC")
    parser.add_argument('-i', '--ipaddress',
        action="store", dest="idrac_ip", nargs='+',
        help="ipaddress of iDRAC")
    parser.add_argument('-f', '--folder', 
        action="store", dest="folder", type=str,
        help="folder from where inventory is serialized")

    options = parser.parse_args(arglist)

    if options.password is None:
        print("password must be provided")
        return -1
    if options.user is None:
        print("user must be provided")
        return -1
    if options.folder is None:
        print("Folder must be provided")
        return -1
    if options.idrac_ip is None or len(options.idrac_ip) <= 0:
        print("iDRAC ip addresses must be provided")
        return -1


    updshare = LocalFile(local = options.folder, isFolder=True)
    if not updshare.IsValid:
        print("Folder is not writable!")
        return -2

    print("Configuring Update Share...")
    UpdateManager.configure(updshare)

    sd = sdkinfra()
    sd.importPath()
    creds = UserCredentials(options.user, options.password)
    for ipaddr in options.idrac_ip:
        try:
            print("Connecting to " + ipaddr + " ... ")
            idrac = sd.get_driver(sd.driver_enum.iDRAC, ipaddr, creds)
            if idrac:
                print("    ... saving firmware!")
                UpdateHelper.save_firmware_inventory(idrac)
                idrac.disconnect()
            else:
                print("    failed to connect to iDRAC")
        except Exception as ex:
            print(str(ex))
def run_boot_to_network_iso(idrac, module):
    """
    Boot to a network ISO image
    Keyword arguments:
    idrac  -- iDRAC handle
    module -- Ansible module
    """

    logger.info(module.params['idrac_ip'] +
                ': STARTING: Boot To Network iso 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: File on share OMSDK API')
            myshare = FileOnShare(remote=module.params['share_name'] + "/" +
                                  module.params['iso_image'],
                                  isFolder=False,
                                  creds=UserCredentials(
                                      module.params['share_user'],
                                      module.params['share_pwd']))

            logger.info(module.params['idrac_ip'] +
                        ': FINISHED: File on share OMSDK API')

            msg['msg'] = idrac.config_mgr.boot_to_network_iso(myshare, "")
            logger.info(module.params['idrac_ip'] +
                        ': FINISHED: Boot To Network iso Method:'
                        ' Invoking OMSDK Operating System Deployment API')

            if "Status" in msg['msg']:
                if msg['msg']['Status'] == "Success":
                    msg['changed'] = True
                else:
                    msg['failed'] = True

    except Exception as e:
        logger.error(module.params['idrac_ip'] +
                     ': EXCEPTION: Boot To Network iso Method: ' + str(e))
        err = True
        msg['msg'] = "Error: %s" % str(e)
        msg['failed'] = True

    logger.info(module.params['idrac_ip'] +
                ': FINISHED: Boot To Network iso Method')
    return msg, err
def export_server_config_profile(idrac, module):
    """
    Export Server Configuration Profile to a network share

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

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

    try:
        scp_file_name_format = "%ip_%Y%m%d_%H%M%S_" + \
            module.params['scp_components'] + "_SCP.xml"

        myshare = FileOnShare(remote=module.params['share_name'],
                              isFolder=True)
        myshare.addcreds(
            UserCredentials(module.params['share_user'],
                            module.params['share_pwd']))
        scp_file_name = myshare.new_file(scp_file_name_format)

        scp_components = TypeHelper.convert_to_enum(
            module.params['scp_components'], SCPTargetEnum)

        export_format = ExportFormatEnum.XML
        if module.params['export_format'] == 'JSON':
            export_format = ExportFormatEnum.JSON

        export_method = ExportMethodEnum.Default
        if module.params['export_method'] == 'Clone':
            export_method = ExportMethodEnum.Clone

        msg['msg'] = idrac.config_mgr.scp_export(
            scp_share_path=scp_file_name,
            components=scp_components,
            format_file=export_format,
            method=export_method,
            job_wait=module.params['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_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
コード例 #13
0
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]
    creds = UserCredentials(share_username, share_password, work_group=work_group)
    return creds
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
コード例 #15
0
ファイル: dellemc_idrac.py プロジェクト: zship/ansible
 def __init__(self, module_params):
     if not HAS_OMSDK:
         raise ImportError(
             "Dell EMC OMSDK library is required for this module")
     self.idrac_ip = module_params['idrac_ip']
     self.idrac_user = module_params['idrac_user']
     self.idrac_pwd = module_params['idrac_pwd']
     self.idrac_port = module_params['idrac_port']
     if not all((self.idrac_ip, self.idrac_user, self.idrac_pwd)):
         raise ValueError("hostname, username and password required")
     self.handle = None
     self.creds = UserCredentials(self.idrac_user, self.idrac_pwd)
     self.pOp = WsManOptions(port=self.idrac_port)
     self.sdk = sdkinfra()
     if self.sdk is None:
         msg = "Could not initialize iDRAC drivers."
         raise RuntimeError(msg)
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
コード例 #17
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
コード例 #18
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
コード例 #19
0
    def connect(self):
        results = {}

        ansible_module_params = self.module.params

        idrac = ansible_module_params.get('idrac')
        idrac_ip = ansible_module_params.get('idrac_ip')
        idrac_user = ansible_module_params.get('idrac_user')
        idrac_pwd = ansible_module_params.get('idrac_pwd')
        idrac_port = ansible_module_params.get('idrac_port')

        if idrac:
            return idrac

        try:
            sd = sdkinfra()
            sd.importPath()
        except Exception as e:
            results['msg'] = "Could not initialize drivers"
            results['exception'] = str(e)
            self.module.fail_json(**results)

        # Connect to iDRAC
        if idrac_ip == '' or idrac_user == '' or idrac_pwd == '':
            results['msg'] = "hostname, username and password required"
            self.module.fail_json(**results)
        else:
            creds = UserCredentials(idrac_user, idrac_pwd)
            pOp = WsManOptions(port=idrac_port)

            idrac = sd.get_driver(sd.driver_enum.iDRAC,
                                  idrac_ip,
                                  creds,
                                  pOptions=pOp)

            if idrac is None:
                results[
                    'msg'] = "Could not find device driver for iDRAC with IP Address: " + idrac_ip
                self.module.fail_json(**results)

        self.handle = idrac
        return idrac
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)
コード例 #21
0
def boot_to_network_iso(idrac, module):
    """
    Boot to a network ISO image

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

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

    try:
        if module.check_mode:
            msg['changed'] = True
        else:
            myshare = FileOnShare(remote=module.params['share_name'],
                                  mount_point=module.params['share_mnt'],
                                  isFolder=True,
                                  creds=UserCredentials(module.params['share_user'],
                                                        module.params['share_pwd']))
            iso_image = myshare.new_file(module.params['iso_image'])

            msg['msg'] = idrac.config_mgr.boot_to_network_iso(iso_image,
                                                              module.params['job_wait'])

            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
コード例 #22
0
    def setup_nw_share_mount(self):
        results = {}
        try:
            share_name = self.module.params.get('share_name')
            share_user = self.module.params.get('share_user')
            share_pwd  = self.module.params.get('share_pwd')
            share_mnt  = self.module.params.get('share_mnt')

            if share_name and share_user and share_pwd and share_mnt:
                nw_share = FileOnShare(remote=share_name,
                                       mount_point=share_mnt,
                                       isFolder=True,
                                       creds=UserCredentials(share_user, share_pwd))

                if nw_share:
                    return self.handle.config_mgr.set_liason_share(nw_share)
        except Exception as e:
            results['msg'] = "Error: %s" % str(e)
            self.module.fail_json(**results)

        return False
コード例 #23
0
def run_boot_to_network_iso(idrac, module):
    """Boot to a network ISO image"""
    try:
        share_name = module.params['share_name']
        if share_name is None:
            share_name = ''
        share_obj = FileOnShare(
            remote="{0}{1}{2}".format(share_name, os.sep,
                                      module.params['iso_image']),
            isFolder=False,
            creds=UserCredentials(module.params['share_user'],
                                  module.params['share_password']))
        cim_exp_duration = minutes_to_cim_format(
            module, module.params['expose_duration'])
        boot_status = idrac.config_mgr.boot_to_network_iso(
            share_obj, "", expose_duration=cim_exp_duration)
        if not boot_status.get("Status", False) == "Success":
            module.fail_json(msg=boot_status)
    except Exception as e:
        module.fail_json(msg=str(e))
    return boot_status
コード例 #24
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_boot_to_network_iso(idrac, module):
    """
    Boot to a network ISO image
    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:
            share_name = ''
        myshare = FileOnShare(remote="{}{}{}".format(share_name, os.sep, module.params['iso_image']),
                              isFolder=False,
                              creds=UserCredentials(
                                  module.params['share_user'],
                                  module.params['share_pwd'])
                              )
        msg['msg'] = idrac.config_mgr.boot_to_network_iso(myshare, "")

        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 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
コード例 #27
0
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)
コード例 #28
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_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
コード例 #30
0
from omdrivers.types.iDRAC.NIC import *
from omdrivers.types.iDRAC.FCHBA import *
from omdrivers.types.iDRAC.SystemConfiguration import *
from omdrivers.lifecycle.iDRAC.SCPParsers import XMLParser
from omsdk.sdkinfra import sdkinfra
from omsdk.simulator.devicesim import Simulator
logging.basicConfig(level=logging.ERROR)
from omsdk.sdkfile import FileOnShare
from omsdk.sdkprint import PrettyPrint
import logging
from omdrivers.lifecycle.iDRAC.RAIDHelper import *

myshare = FileOnShare(remote="\\\\<share>\\Share",
                      mount_point='Z:\\',
                      isFolder=True,
                      creds=UserCredentials("user@domain", "password"))

ipaddr = '192.168.0.1'
logging.basicConfig(level=logging.DEBUG)
myshare.valid = True

Simulator.start_simulating()
sd = sdkinfra()
sd.importPath()
idrac = sd.get_driver('iDRAC', ipaddr, UserCredentials('user', 'pass'))
idrac.config_mgr.set_liason_share(myshare)


def emailtest(idrac, address, expected, action=1):
    print(expected)
    idrac.config_mgr._sysconfig.iDRAC.EmailAlert._index_helper.printx()