def ibmc_set_ip_module(module):
    """
    Function:
        Set iBMC ethernet interface configuration
    Args:
              module       (class):

    Returns:
        {"result": False, "msg": 'not run set ibmc ip yet'}
    Raises:
        None
    Examples:

    Author:
    Date: 2019/11/4 17:33
    """
    # Modifying the IP address will result in the inability to delete the original session
    # Cannot create an object with the 'with as' method
    ibmc = IbmcBaseConnect(module.params, log, report)
    ret = is_support_server(ibmc, SERVERTYPE)
    if ret['result']:
        ret = set_ibmc_ip(ibmc, module.params)
        try:
            ibmc.delete_session()
            ibmc.session.close()
        except Exception as e:
            log.info(
                MSG_FORMAT %
                (str(ibmc.ip),
                 "Failed to close session, The error info is: %s" % str(e)))
    return ret
def ibmc_profile_export_module(module):
    """
    Function:
        Export or import BIOS, BMC, and RAID Controller Configurations
    Args:
        module  : information from yml
    Returns:
        ret : Task result
            "result": True or False
            "msg": description for success or failure
    Raises:
        None
    Date: 2019/10/9 20:30
    """
    with IbmcBaseConnect(module.params, log, report) as ibmc:
        ret = is_support_server(ibmc, SERVERTYPE)
        if ret['result']:
            all_file_path = (module.params.get("local_export"),
                             module.params.get("remote_export"))
            if all(all_file_path) or not any(all_file_path):
                log_error = "Profile export failed! Please select a profile " \
                            "export mode from local_export or remote_export."
                set_result(ibmc.log_error, log_error, False, ret)
                return ret

            try:
                local, profile = get_profile_name(ibmc, module)
            except Exception as e:
                log_error = "Profile export failed! %s" % str(e)
                set_result(ibmc.log_error, log_error, False, ret)
                return ret
            command = "export"
            ret = server_profile(ibmc, profile, command, local)
    return ret
def ibmc_outband_fw_update_module(module):
    """
    Function: Outband firmware upgrade
    Args:
        module : information from yml
    Returns:
        ret : Task result
            "result": True or False
            "msg": description for success or failure
    Raises:
        None
    Date: 2019/10/9 20:30
    """
    with IbmcBaseConnect(module.params, log, report) as ibmc:
        ret = is_support_server(ibmc, SERVERTYPE)
        if ret['result']:
            all_file = (module.params.get("local_file"),
                        module.params.get("remote_file"))
            if all(all_file) or not any(all_file):
                log_error = "Please select an out-of-band firmware upgrade " \
                            "mode from local_file and remote_file."
                set_result(ibmc.log_error, log_error, False, ret)
                return ret
        try:
            local, file, protocol = get_file_name(module)
        except Exception as e:
            log_error = "Update failed! %s" % str(e)
            set_result(ibmc.log_error, log_error, False, ret)
            return ret

        ret = update_fw(ibmc, file, protocol, local)
    return ret
def ibmc_inband_fw_update_module(module):
    """
    Function:

    Args:
              ansible_module       (class):

    Returns:
        "result": False
        "msg": 'not run update inband firmware yet'
    Raises:
        Exception
    Examples:

    Author: xwh
    Date: 2019/10/9 20:30
    """
    with IbmcBaseConnect(module.params, log, report) as ibmc:
        ret = is_support_server(ibmc, SERVERTYPE)
        if ret['result']:
            file_path_list = []
            for each_item in module.params["image_url"]:
                if 'nfs' in each_item.lower() or ("file_server_user" not in module.params) or (
                            module.params["file_server_user"] is ''):
                    file_path_list.append(each_item)
                else:
                    file_url = each_item.replace("://", "://%s:%s@" % (
                        module.params["file_server_user"], module.params["file_server_pswd"]))
                    file_path_list.append(file_url)
            ret = sp_upgrade_fw_process(ibmc, file_path_list)
    return ret
def ibmc_collect_log_module(module):
    """
    Function:
        Collect iBMC logs
    Args:
        module : information from yml
    Returns:
        ret : Task result
            "result": True or False
            "msg": description for success or failure
    Raises:
        None
    Date: 2021/2/22
    """
    with IbmcBaseConnect(module.params, log, report) as ibmc:
        ret = is_support_server(ibmc, SERVERTYPE)
        if ret['result']:
            save_location = {
                "save_mode": module.params.get("save_mode"),
                "file_server_ip": module.params.get("file_server_ip"),
                "file_server_user": module.params.get("file_server_user"),
                "file_server_pswd": module.params.get("file_server_pswd")
            }
            ret = collect_log(ibmc,
                              save_location,
                              module.params.get("file_name"),
                              log_type="SEL")
    return ret
def ibmc_modify_account_module(module):
    """
    Function:

    Args:
              ansible_module       (class):

    Returns:
        ret = {"result": False, "msg": 'not run modify account yet'}
    Raises:
        Exception
    Examples:

    Author: xwh
    Date: 2019/10/9 20:30
    """
    ret = {"result": False, "msg": 'not run modify account yet'}
    with IbmcBaseConnect(module.params, log, report) as ibmc:
        oem_info = ibmc.oem_info
        config_dic = {}
        body_para = {}
        oem_dic = {oem_info: {}}
        if module.params.get("new_account_user"):
            body_para["UserName"] = module.params.get("new_account_user")
        if module.params.get("new_account_pswd"):
            body_para["Password"] = module.params.get("new_account_pswd")
        if module.params.get("roleid"):
            body_para["RoleId"] = module.params.get("roleid")
        if module.params.get("locked") is not None:
            if module.params["locked"] is not False:
                error_msg = "The locked param can not be set to true"
                set_result(ibmc.log_error, error_msg, False, ret)
                return ret
            body_para["Locked"] = module.params["locked"]
        if module.params.get("enable") is not None:
            body_para["Enabled"] = module.params["enable"]
        if module.params.get("account_insecure_prompt_enabled") is not None:
            oem_dic[oem_info]["AccountInsecurePromptEnabled"] = module.params["account_insecure_prompt_enabled"]

        try:
            new_information(ibmc, module, oem_dic)
        except Exception as e:
            set_result(ibmc.log_error, str(e), False, ret)
            return ret
        if oem_dic[oem_info] != {}:
            body_para['Oem'] = oem_dic
        config_dic[module.params["old_account_user"]] = body_para
        ret = modify_account(ibmc, config_dic)
    return ret
def ibmc_download_file_module(module):
    """
    Function:
        Download files from /tmp/web/
    Args:
        module : information from yml
    Returns:
        ret : Task result
            "result": True or False
            "msg": description for success or failure
    Raises:
        None
    Date: 2021/2/22
    """
    with IbmcBaseConnect(module.params, log, report) as ibmc:
        ret = is_support_server(ibmc, SERVERTYPE)
        if ret['result']:
            ret = download_file(ibmc, module.params.get("file_name"), module.params.get("local_path"))
    return ret
Beispiel #8
0
def ibmc_get_basic_info(module):
    """
    Function:
        Get Server basic info
    Args:
        module       (class):
    Returns:
        {"result": False, "msg": ''}
    Raises:
        None
    Examples:

    Author:
    Date: 2019/11/23 15:11
    """
    ret = {"result": False, "msg": 'not run get basic info yet'}
    with IbmcBaseConnect(module.params, log, report) as ibmc:
        ret = get_basic_info(ibmc, module.params.get("csv_format"))
    return ret
def ibmc_clear_sel_log_module(module):
    """
    Function:
        Clear SEL logs
    Args:
        module : information from yml
    Returns:
        ret : Task result
            "result": True or False
            "msg": description for success or failure
    Raises:
         None
    Date: 2021/2/22
    """
    with IbmcBaseConnect(module.params, log, report) as ibmc:
        ret = is_support_server(ibmc, SERVERTYPE)
        if ret['result']:
            ret = clear_sel_log(ibmc)
    return ret
def ibmc_upload_file_module(module):
    """
    Function:
        Upload files
    Args:
        module : information from yml
    Returns:
        ret : Task result
            "result": True or False
            "msg": description for success or failure
    Raises:
        None
    Date: 2021/2/22
    """
    with IbmcBaseConnect(module.params, log, report) as ibmc:
        ret = is_support_server(ibmc, SERVERTYPE)
        if ret['result']:
            ret = upload_file(ibmc, module.params["imgfile"])
    return ret
def ibmc_get_bios_module(module):
    """
    Function:
        Get BIOS information
    Args:
        module : information from yml
    Returns:
        ret : Task result
            "result": True or False
            "msg": description for success or failure
    Raises:
        None
    Date: 2021/2/22
    """
    with IbmcBaseConnect(module.params, log, report) as ibmc:
        ret = is_support_server(ibmc, SERVERTYPE)
        if ret['result']:
            ret = get_bios_info(ibmc, module.params["bios_attribute"])
    return ret
Beispiel #12
0
def ibmc_delete_account_module(module):
    """
    Function:

    Args:
              ansible_module       (class):

    Returns:
        ret = {"result": False, "msg": 'not run delete account yet'}
    Raises:
        Exception
    Examples:

    Author: xwh
    Date: 2019/10/9 20:30
    """
    ret = {"result": False, "msg": 'not run delete account yet'}
    with IbmcBaseConnect(module.params, log, report) as ibmc:
        ret = delete_account(ibmc, module.params["delete_account"])
    return ret
Beispiel #13
0
def ibmc_modify_raid_module(module):
    """
    Function:
        Modify RAID configuration
    Args:
        module       (class):
    Returns:
        {"result": False, "msg": 'not run modify raid yet'}
    Raises:
        None
    Examples:

    Author:
    Date: 2019/11/9 17:33
    """
    with IbmcBaseConnect(module.params, log, report) as ibmc:
        ret = is_support_server(ibmc, SERVERTYPE)
        if ret['result']:
            ret = modify_raid(ibmc, module.params)
    return ret
Beispiel #14
0
def ibmc_get_account_module(module):
    """
    Function:

    Args:
              module       (class):

    Returns:
        ret = {"result": False, "msg": 'not run get account yet'}
    Raises:
        Exception
    Examples:

    Author: xwh
    Date: 2019/10/9 20:30
    """
    ret = {"result": False, "msg": 'not run get account yet'}
    with IbmcBaseConnect(module.params, log, report) as ibmc:
        ret = get_accounts(ibmc)
    return ret
Beispiel #15
0
def ibmc_get_ntp_module(module):
    """
    Function:
        Get NTP configuration resource information
    Args:
              module       (class):

    Returns:
        {"result": False, "msg": 'not run get ntp yet'}
    Raises:
        None
    Examples:

    Author:
    Date: 2019/11/4 17:33
    """
    with IbmcBaseConnect(module.params, log, report) as ibmc:
        ret = is_support_server(ibmc, SERVERTYPE)
        if ret['result']:
            ret = get_ntp(ibmc)
    return ret
def ibmc_common_api_module(module):
    """
    Function:
        Common api
    Args:
        module : information from yml
    Returns:
        ret : Task result
            "result": True or False
            "msg": description for success or failure
    Raises:
         None
    Date: 2021/2/22
    """
    with IbmcBaseConnect(module.params, log, report) as ibmc:
        ret = is_support_server(ibmc, SERVERTYPE)
        if ret['result']:
            ret = common_api(ibmc, module.params.get('url'),
                             module.params.get('request_method'),
                             module.params.get('request_body'))
    return ret
def ibmc_get_power_status_module(module):
    """
    Function:

    Args:
              ansible_module       (class):

    Returns:
        ret = {"result": False, "msg": 'not run get power status yet'}
    Raises:
        Exception
    Examples:

    Author: xwh
    Date: 2019/10/9 20:30
    """
    with IbmcBaseConnect(module.params, log, report) as ibmc:
        ret = is_support_server(ibmc, SERVERTYPE)
        if ret['result']:
            ret = get_power_status(ibmc)
    return ret
def ibmc_set_boot_device_module(module):
    """
    Function:
        Set boot device
    Args:
              module       (class):

    Returns:
        {"result": False, "msg": 'not run set boot device yet'}
    Raises:
        None
    Examples:

    Author:
    Date: 2019/11/4 17:33
    """
    with IbmcBaseConnect(module.params, log, report) as ibmc:
        ret = is_support_server(ibmc, SERVERTYPE)
        if ret['result']:
            ret = set_boot_device(ibmc, module.params)
    return ret
Beispiel #19
0
def ibmc_delete_raid_module(module):
    """
    Function:
        Delete RAID configuration
    Args:
        module       (class):
    Returns:
        "result": False
        "msg": 'not run delete raid yet'
    Raises:
        None
    Examples:

    Author:
    Date: 2019/11/12 15:11
    """
    with IbmcBaseConnect(module.params, log, report) as ibmc:
        ret = is_support_server(ibmc, SERVERTYPE)
        if ret['result']:
            ret = delete_raid(ibmc, module.params)
    return ret
Beispiel #20
0
def ibmc_deploy_os_by_service_cd_process(module):
    """
    Function:

    Args:
              ansible_module       (class):

    Returns:
        ret = {"result": False, "msg": 'not run deploy os by ServiceCD yet'}
    Raises:
        Exception
    Examples:

    Author: xwh
    Date: 2019/10/9 20:30
    """
    with IbmcBaseConnect(module.params, log, report) as ibmc:
        ret = is_support_server(ibmc, SERVERTYPE)
        if ret['result']:
            ret = deploy_os_process(ibmc, module.params)
    return ret
Beispiel #21
0
def ibmc_set_snmp_trap_module(module):
    """
    Function:
        Set SNMP trap resource properties
    Args:
              module       (class):

    Returns:
        {"result": False, "msg": 'not run set snmp trap yet'}
    Raises:
        None
    Examples:

    Author:
    Date: 2019/11/4 17:33
    """
    with IbmcBaseConnect(module.params, log, report) as ibmc:
        ret = is_support_server(ibmc, SERVERTYPE)
        if ret['result']:
            ret = set_snmp_trap(ibmc, module.params)
    return ret
Beispiel #22
0
def ibmc_power_mannager_module(module):
    """
    Function:

    Args:
              ansible_module       (class):

    Returns:
        "result": False
        "msg": 'not run set power yet'
    Raises:
        Exception
    Examples:

    Author: xwh
    Date: 2019/10/9 20:30
    """
    with IbmcBaseConnect(module.params, log, report) as ibmc:
        ret = is_support_server(ibmc, SERVERTYPE)
        if ret['result']:
            ret = manage_power(ibmc, module.params["power_cmd"])
    return ret
def ibmc_create_account_module(module):
    """
    Function:

    Args:
              ansible_module       (class):

    Returns:
        "result": False
        "msg": 'not run create account yet'
    Raises:
        Exception
    Examples:

    Author: xwh
    Date: 2019/10/9 20:30
    """
    ret = {"result": False, "msg": 'not run create account yet'}

    with IbmcBaseConnect(module.params, log, report) as ibmc:
        ret = create_account(ibmc, module.params["new_account_user"],
                             module.params["new_account_pswd"],
                             module.params["roleid"])
    return ret