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
Exemplo n.º 2
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 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