Esempio n. 1
0
File: bios.py Progetto: vvb/imcsdk
def _get_device(parent_dn, device_type, device_name):
    from imcsdk.imccoreutils import load_class

    if _is_boot_order_precision(parent_dn):
        if device_type not in precision_device_dict:
            return None
        class_struct = load_class(precision_device_dict[device_type]["class_id"])
        class_obj = class_struct(parent_mo_or_dn=parent_dn, name=device_name)
        if "type" in precision_device_dict[device_type]:
            class_obj.type = precision_device_dict[device_type]["type"]
        if "subtype" in precision_device_dict[device_type]:
            class_obj.subtype = precision_device_dict[device_type]["subtype"]
    elif _is_boot_order_policy(parent_dn):
        if device_type not in policy_device_dict:
            return None
        class_struct = load_class(policy_device_dict[device_type]["class_id"])
        access = policy_device_dict[device_type]["access"]
        '''
        cdrom and fdd are of type LsbootVirtualMedia and have "access" as the
        naming property. Other objects under LsbootDef do not need this.
        Hence cdrom and fdd need special handling below.
        '''
        if device_type in ["cdrom", "fdd"]:
            class_obj = class_struct(parent_mo_or_dn=parent_dn, access=access)
        else:
            class_obj = class_struct(parent_mo_or_dn=parent_dn)
            class_obj.access = access
    else:
        return None

    return class_obj
Esempio n. 2
0
def _get_device(parent_dn, device_type, device_name):
    from imcsdk.imccoreutils import load_class

    if _is_boot_order_precision(parent_dn):
        if device_type not in precision_device_dict:
            return None
        class_struct = load_class(
            precision_device_dict[device_type]["class_id"])
        class_obj = class_struct(parent_mo_or_dn=parent_dn, name=device_name)
        if "type" in precision_device_dict[device_type]:
            class_obj.type = precision_device_dict[device_type]["type"]
        if "subtype" in precision_device_dict[device_type]:
            class_obj.subtype = precision_device_dict[device_type]["subtype"]
    elif _is_boot_order_policy(parent_dn):
        if device_type not in policy_device_dict:
            return None
        class_struct = load_class(policy_device_dict[device_type]["class_id"])
        access = policy_device_dict[device_type]["access"]
        '''
        cdrom and fdd are of type LsbootVirtualMedia and have "access" as the
        naming property. Other objects under LsbootDef do not need this.
        Hence cdrom and fdd need special handling below.
        '''
        if device_type in ["cdrom", "fdd"]:
            class_obj = class_struct(parent_mo_or_dn=parent_dn, access=access)
        else:
            class_obj = class_struct(parent_mo_or_dn=parent_dn)
            class_obj.access = access
    else:
        return None

    return class_obj
Esempio n. 3
0
def bios_tokens_set(handle, tokens={}, server_id=1):
    """
    Args:
        handle (ImcHandle)
        tokens (dictionary) : (key, value) pair of bios tokens with key being the name of the token
        server_id (int): Id of the server to perform
                         this operation on C3260 platforms.

    Returns:
        None

    Examples:
        bios_tokens_set(handle,
                        tokens = {
                            "BaudRate": "19200",
                            "IntelVTDATSSupport": "enabled",
                            "ConsoleRedirection": "com-1",
                            "FlowControl": "rts-cts"},
                        server_id=2)
    """

    from imcsdk.imccoreutils import load_class

    parent_dn = _get_bios_dn(handle, server_id) + "/bios-settings"
    mo_table = _get_bios_mo_table(handle, tokens, server_id)

    for mo_name, props in mo_table.items():
        mo_class = load_class(mo_name)
        mo_obj = mo_class(parent_mo_or_dn=parent_dn, **props)
        handle.set_mo(mo_obj)
Esempio n. 4
0
def bios_tokens_set(handle, tokens={}, server_id=1):
    """
    Args:
        handle (ImcHandle)
        tokens (dictionary) : (key, value) pair of bios tokens with key being the name of the token
        server_id (int): Id of the server to perform
                         this operation on C3260 platforms.

    Returns:
        None

    Examples:
        bios_tokens_set(handle,
                        tokens = {
                            "BaudRate": "19200",
                            "IntelVTDATSSupport": "enabled",
                            "ConsoleRedirection": "com-1",
                            "FlowControl": "rts-cts"},
                        server_id=2)
    """

    from imcsdk.imccoreutils import load_class

    parent_dn = _get_bios_dn(handle, server_id) + "/bios-settings"
    mo_table = _get_bios_mo_table(handle, tokens, server_id)

    for mo_name, props in mo_table.items():
        mo_class = load_class(mo_name)
        mo_obj = mo_class(parent_mo_or_dn=parent_dn, **props)
        handle.set_mo(mo_obj)
Esempio n. 5
0
def _get_device(parent_mo_or_dn, device_type, device_name):
    from imcsdk.imccoreutils import load_class

    # precision boot order supports hierarchy in configConfMO
    # legacy boot order does not
    # so passing parent Mo to class_struct in case of precision boot order
    # in case of legacy boot order, only dn is passed
    if type(parent_mo_or_dn) is str:
        parent = parent_mo_or_dn
        parent_dn = parent_mo_or_dn
    else:
        parent = parent_mo_or_dn
        parent_dn = parent_mo_or_dn.dn

    if _is_boot_order_precision(parent_dn):
        if device_type not in precision_device_dict:
            return None
        class_struct = load_class(
            precision_device_dict[device_type]["class_id"])
        class_obj = class_struct(parent_mo_or_dn=parent, name=device_name)
        if "type" in precision_device_dict[device_type]:
            class_obj.type = precision_device_dict[device_type]["type"]
        if "subtype" in precision_device_dict[device_type]:
            class_obj.subtype = precision_device_dict[device_type]["subtype"]
    elif _is_boot_order_policy(parent_dn):
        if device_type not in policy_device_dict:
            return None
        class_struct = load_class(policy_device_dict[device_type]["class_id"])
        access = policy_device_dict[device_type]["access"]
        '''
        cdrom and fdd are of type LsbootVirtualMedia and have "access" as the
        naming property. Other objects under LsbootDef do not need this.
        Hence cdrom and fdd need special handling below.
        '''
        if device_type in ["cdrom", "fdd"]:
            class_obj = class_struct(parent_mo_or_dn=parent_dn, access=access)
        else:
            class_obj = class_struct(parent_mo_or_dn=parent_dn)
            class_obj.access = access
    else:
        return None

    return class_obj
Esempio n. 6
0
def _get_device(parent_mo_or_dn, device_type, device_name):
    from imcsdk.imccoreutils import load_class

    # precision boot order supports hierarchy in configConfMO
    # legacy boot order does not
    # so passing parent Mo to class_struct in case of precision boot order
    # in case of legacy boot order, only dn is passed
    if type(parent_mo_or_dn) is str:
        parent = parent_mo_or_dn
        parent_dn = parent_mo_or_dn
    else:
        parent = parent_mo_or_dn
        parent_dn = parent_mo_or_dn.dn

    if _is_boot_order_precision(parent_dn):
        if device_type not in precision_device_dict:
            return None
        class_struct = load_class(
            precision_device_dict[device_type]["class_id"])
        class_obj = class_struct(parent_mo_or_dn=parent, name=device_name)
        if "type" in precision_device_dict[device_type]:
            class_obj.type = precision_device_dict[device_type]["type"]
        if "subtype" in precision_device_dict[device_type]:
            class_obj.subtype = precision_device_dict[device_type]["subtype"]
    elif _is_boot_order_policy(parent_dn):
        if device_type not in policy_device_dict:
            return None
        class_struct = load_class(policy_device_dict[device_type]["class_id"])
        access = policy_device_dict[device_type]["access"]
        '''
        cdrom and fdd are of type LsbootVirtualMedia and have "access" as the
        naming property. Other objects under LsbootDef do not need this.
        Hence cdrom and fdd need special handling below.
        '''
        if device_type in ["cdrom", "fdd"]:
            class_obj = class_struct(parent_mo_or_dn=parent_dn, access=access)
        else:
            class_obj = class_struct(parent_mo_or_dn=parent_dn)
            class_obj.access = access
    else:
        return None

    return class_obj
Esempio n. 7
0
def _create_vic_object(adaptor_mo, vic_name, vic_type, api_error_msg,
                       **kwargs):
    from imcsdk.imccoreutils import load_class
    from imcsdk.imccoreutils import find_class_id_in_mo_meta_ignore_case

    vic_mo_name = vic_map[vic_type]
    vic_mo_class = load_class(vic_mo_name)
    vic_mo = vic_mo_class(parent_mo_or_dn=adaptor_mo, name=vic_name)

    # process vnic/vhba children
    vic_children = {}
    for key, value in kwargs.items():
        mo_name, prop_name = _process_mo_prop_str(key, api_error_msg)
        if not mo_name:
            raise ImcOperationError(api_error_msg, "MO name is missing.")
        if not prop_name:
            raise ImcOperationError(api_error_msg, "Property name is missing.")
        prop_value = None if value is None else str(value)

        # VIC 1385 adapter is a multi-pci link adapter and hence just use the pci-link what we have received
        # For all other adapters, hard-code it to 0
        if adaptor_mo.model != "UCSC-PCIE-C40Q-03":
            if mo_name == "AdaptorEthGenProfile" or mo_name == "AdaptorFcGenProfile":
                if prop_name == "pci_link":
                    prop_value = "0"

        # Allow vHBA Type Configuration for Generation4+ adaptor only. Else, set the vhbaType to None as they are not supported.
        adaptorModel = adaptor_mo.model.split("-")
        genVersion = adaptorModel[len(adaptorModel) - 1]
        if genVersion < "04" and mo_name == "AdaptorFcGenProfile" and prop_name == "vhba_type":
            prop_value = None

        nmo_name = find_class_id_in_mo_meta_ignore_case(mo_name)
        if nmo_name is None:
            log.debug("Ignoring '%s'. MO '%s' does not exist in meta." %
                      (key, mo_name))
            continue
        else:
            mo_name = nmo_name

        if mo_name == vic_mo_name:
            mo = vic_mo
        elif mo_name not in vic_children:
            mo = _create_child_mo(vic_mo, mo_name)
            vic_children[mo_name] = mo
        else:
            mo = vic_children[mo_name]

        setattr(mo, prop_name, prop_value)

    return vic_mo
Esempio n. 8
0
def _vic_get(handle, adaptor_slot, name, vic_type, server_id=1):
    """
    Internal method to get vnic and vhba
    """
    from imcsdk.imccoreutils import load_class

    parent_mo = adaptor_unit_get(handle, adaptor_slot, server_id)
    if parent_mo is None:
        raise ImcOperationError("Cannot create %s." % vic_type,
                                "Adaptor unit %s is missing" % adaptor_slot)

    vic_mo_name = vic_map[vic_type]
    vic_mo_class = load_class(vic_mo_name)
    vic_mo = vic_mo_class(parent_mo_or_dn=parent_mo, name=name)
    return handle.query_dn(vic_mo.dn)
Esempio n. 9
0
def _create_child_mo(parent_mo_or_dn, mo_name):
    '''
    creates child object of vnic and vhba
    '''
    from imcsdk.imccoreutils import load_class
    from imcsdk.imccoreutils import find_class_id_in_mo_meta_ignore_case

    class_id = find_class_id_in_mo_meta_ignore_case(mo_name)
    if class_id is None:
        return None

    class_struct = load_class(class_id)
    class_obj = class_struct(parent_mo_or_dn)

    return class_obj
Esempio n. 10
0
def SetBios(handle):
    tokens = {
        "BaudRate": "115200",
        "ConsoleRedirection": "com-0",
        "FlowControl": "none",
        "TerminalType": "vt100"}
    server_id=1

    from imcsdk.imccoreutils import load_class

    parent_dn = _get_bios_dn(handle, server_id) + "/bios-settings"
    mo_table = _get_bios_mo_table(handle, tokens, server_id)

    for mo_name, props in mo_table.items():
        mo_class = load_class(mo_name)
        mo_obj = mo_class(parent_mo_or_dn=parent_dn, **props)
        handle.set_mo(mo_obj)
Esempio n. 11
0
def bios_tokens_set(handle, tokens={}, server_id=1):
    """
    Args:
        handle (ImcHandle)
        tokens (dictionary) : (key, value) pair of bios tokens with key being the name of the token
        server_id (int): Id of the server to perform
                         this operation on C3260 platforms.

    Returns:
        Dictionary with a failure message, if any.

    Examples:
        bios_tokens_set(handle,
                        tokens = {
                            "baudRate": "19200",
                            "intelVtdatsSupport": "enabled",
                            "consoleRedirection": "com-1",
                            "flowControl": "rts-cts",
                            "sataModeSelect": "platform-default",
                            "txtSupport": "platform-default",
                            "packageCstateLimit": "C0 C1 State"},
                        server_id=2)
    """

    from imcsdk.imccoreutils import load_class, sanitize_xml_parsing_error
    from imcsdk.mometa.bios.BiosSettings import BiosSettings

    messages = []
    ret = {}

    bios_mo = BiosSettings(parent_mo_or_dn=_get_bios_dn(handle, server_id))
    mo_table = _get_bios_mo_table(handle, tokens, server_id)
    server_mos = _get_server_bios_mo_table(handle, dn=bios_mo.dn)

    # Prepare the filtered table i.e. send only those MOs that exist on the server
    table = {k: v for k, v in iteritems(mo_table) if k in server_mos}

    # Separate the MOs which have only platform-default
    for mo_name, props in table.items():
        non_default_props = {k: v for k, v in iteritems(props) if v != "platform-default"}
        # if there are no non-default props, it can be batched
        if len(non_default_props) == 0:
            # filter properties to only those applicable to the server
            server_mo_props = server_mos[mo_name]
            filtered_props = {k: v for k, v in iteritems(props) if k in server_mo_props and server_mo_props[k]}
            # load an instance of the class
            mo_class = load_class(mo_name)
            filtered_props["_handle"] = handle
            mo_obj = mo_class(parent_mo_or_dn=bios_mo, **filtered_props)
            # pop the object from the table dictionary
            table.pop(mo_name)

    # Send all the MOs with default properties in one shot
    handle.set_mo(bios_mo)

    # Send the rest of the MOs
    for mo_name, props in table.items():
        d = {}
        server_mo_props = server_mos[mo_name]
        filtered_props = {k: v for k, v in iteritems(props)
                          if k in server_mo_props and server_mo_props[k]}

        if len(filtered_props) != 0:
            mo_class = load_class(mo_name)
            filtered_props["_handle"] = handle
            try:
                mo_obj = mo_class(parent_mo_or_dn=bios_mo.dn, **filtered_props)
                handle.set_mo(mo_obj)
            except ImcException as e:
                d["Object"] = mo_name
                error = e.error_descr
                if e.error_code == "ERR-xml-parse-error":
                    error = sanitize_xml_parsing_error(e.error_descr)
                d["Error"] = error
                messages.append(d)
                continue
            except Exception as e:
                d["Object"] = mo_name
                d["Error"] = str(e)
                messages.append(d)
                continue

    message = ""

    if len(messages) != 0:
        message = "Following issues were seen during application of BIOS " \
                "tokens: \n"
        for m in messages:
            message += m["Object"] + ": " + m["Error"] + "\n"

    ret["msg"] = message
    ret["msg_params"] = messages
    ret["changed"] = True
    return ret
Esempio n. 12
0
def bios_tokens_set(handle, tokens={}, server_id=1):
    """
    Args:
        handle (ImcHandle)
        tokens (dictionary) : (key, value) pair of bios tokens with key being the name of the token
        server_id (int): Id of the server to perform
                         this operation on C3260 platforms.

    Returns:
        Dictionary with a failure message, if any.

    Examples:
        bios_tokens_set(handle,
                        tokens = {
                            "baudRate": "19200",
                            "intelVtdatsSupport": "enabled",
                            "consoleRedirection": "com-1",
                            "flowControl": "rts-cts",
                            "sataModeSelect": "platform-default",
                            "txtSupport": "platform-default",
                            "packageCstateLimit": "C0 C1 State"},
                        server_id=2)
    """

    from imcsdk.imccoreutils import load_class, sanitize_xml_parsing_error
    from imcsdk.mometa.bios.BiosSettings import BiosSettings
    from imcsdk.imccoremeta import ImcVersion

    messages = []
    ret = {}

    bios_mo = BiosSettings(parent_mo_or_dn=_get_bios_dn(handle, server_id))
    mo_table = _get_bios_mo_table(handle, tokens, server_id)
    server_mos = _get_server_bios_mo_table(handle, dn=bios_mo.dn)

    # Prepare the filtered table i.e. send only those MOs that exist on the server
    table = {k: v for k, v in mo_table.items() if k in server_mos}

    log.debug("Mo Table       Count: %s Values: %s" %
              (len(mo_table), mo_table))
    log.debug("Server Table   Count: %s Values: %s" %
              (len(server_mos), server_mos))
    log.debug("Filtered Table Count: %s Values: %s" % (len(table), table))

    processed_tokens = []
    # Separate the MOs which have only platform-default
    for mo_name, props in table.items():
        non_default_props = {
            k: v
            for k, v in props.items() if v != "platform-default"
        }
        # if there are no non-default props, it can be batched
        if len(non_default_props) == 0:
            # filter properties to only those applicable to the server
            server_mo_props = server_mos[mo_name]
            filtered_props = {
                k: v
                for k, v in props.items()
                if k in server_mo_props and server_mo_props[k]
            }

            if len(filtered_props) == 0:
                log.debug("skipping token %s props: %s server_mo_props %s " %
                          (mo_name, props, server_mo_props))
                processed_tokens.append(mo_name)
                continue

            # load an instance of the class
            mo_class = load_class(mo_name)
            filtered_props["_handle"] = handle
            mo_obj = mo_class(parent_mo_or_dn=bios_mo, **filtered_props)

            # HACK for CIMC ISSUE. 'rn' is different for M4 and M5
            # rn for M5 for this token has been corrected in GP-MR2
            if mo_name == "BiosVfSataModeSelect" and \
                    is_platform_m5(handle) and \
                    handle.version < ImcVersion("3.1(3a)"):
                mo_obj.rn = "SataModeSelect"
                mo_obj.dn = bios_mo.dn + "/" + mo_obj.rn

            # In HP release, for Janus platform, vp_cbs_cmn_cpu_gen_downcore_ctrl token
            # does not have a platform default value supported on the endpoint
            if mo_name == "BiosVfCbsCmnCpuGenDowncoreCtrl" and \
                    mo_obj.vp_cbs_cmn_cpu_gen_downcore_ctrl == "platform-default" and \
                    handle.version == ImcVersion("4.0(1a)"):
                mo_obj.vp_cbs_cmn_cpu_gen_downcore_ctrl = "Auto"

            # pop the object from the table dictionary
            processed_tokens.append(mo_name)

    for each in processed_tokens:
        table.pop(each)

    log.debug("Modified Tokens Count: %s Values: %s" % (len(table), table))

    # Send all the MOs with default properties in one shot
    handle.set_mo(bios_mo)

    # Send the rest of the MOs
    for mo_name, props in table.items():
        d = {}
        server_mo_props = server_mos[mo_name]
        filtered_props = {
            k: v
            for k, v in props.items()
            if k in server_mo_props and server_mo_props[k]
        }

        # REALLY DIRTY HACK!!
        # C6 Non Retention - Works on M5, fails on M4
        # C6 non Retention - Works on M4, fails on M5
        if mo_name == "BiosVfPackageCStateLimit" and is_platform_m4(
                handle) and "vp_package_c_state_limit" in filtered_props:
            if filtered_props[
                    "vp_package_c_state_limit"] == "C6 Non Retention":
                filtered_props["vp_package_c_state_limit"] = "C6 non Retention"

        if len(filtered_props) != 0:
            mo_class = load_class(mo_name)
            filtered_props["_handle"] = handle
            try:
                mo_obj = mo_class(parent_mo_or_dn=bios_mo.dn, **filtered_props)

                # HACK for CIMC ISSUE. 'rn' is different for M4 and M5
                # rn for M5 for this token has been corrected in GP-MR2
                if mo_name == "BiosVfSataModeSelect" and \
                        is_platform_m5(handle) and \
                        handle.version < ImcVersion("3.1(3a)"):
                    mo_obj.rn = "SataModeSelect"
                    mo_obj.dn = bios_mo.dn + "/" + mo_obj.rn

                # HP and below only "Disabled" was supported for this token
                # In HP, "disabled" was also supported and hence need to send the older
                # version of this value for an older server
                if mo_name == "BiosVfCDNSupport" and \
                        mo_obj.vp_cdn_support == "disabled" and \
                        handle.version < ImcVersion("4.0(1a)"):
                    mo_obj.vp_cdn_support = "Disabled"

                handle.set_mo(mo_obj)
            except ImcException as e:
                d["Object"] = mo_name
                error = e.error_descr
                if e.error_code == "ERR-xml-parse-error":
                    error = sanitize_xml_parsing_error(e.error_descr)
                d["Error"] = error
                messages.append(d)
                continue
            except Exception as e:
                d["Object"] = mo_name
                d["Error"] = str(e)
                messages.append(d)
                continue

    message = ""

    if len(messages) != 0:
        message = "Following issues were seen during application of BIOS " \
                "tokens: \n"
        for m in messages:
            message += m["Object"] + ": " + m["Error"] + "\n"

    ret["msg"] = message
    ret["msg_params"] = messages
    ret["changed"] = True
    return ret
Esempio n. 13
0
def bios_tokens_set(handle, tokens={}, server_id=1):
    """
    Args:
        handle (ImcHandle)
        tokens (dictionary) : (key, value) pair of bios tokens with key being the name of the token
        server_id (int): Id of the server to perform
                         this operation on C3260 platforms.

    Returns:
        Dictionary with a failure message, if any.

    Examples:
        bios_tokens_set(handle,
                        tokens = {
                            "baudRate": "19200",
                            "intelVtdatsSupport": "enabled",
                            "consoleRedirection": "com-1",
                            "flowControl": "rts-cts",
                            "sataModeSelect": "platform-default",
                            "txtSupport": "platform-default",
                            "packageCstateLimit": "C0 C1 State"},
                        server_id=2)
    """

    from imcsdk.imccoreutils import load_class, sanitize_xml_parsing_error
    from imcsdk.mometa.bios.BiosSettings import BiosSettings

    messages = []
    ret = {}

    bios_mo = BiosSettings(parent_mo_or_dn=_get_bios_dn(handle, server_id))
    mo_table = _get_bios_mo_table(handle, tokens, server_id)
    server_mos = _get_server_bios_mo_table(handle, dn=bios_mo.dn)

    # Prepare the filtered table i.e. send only those MOs that exist on the server
    table = {k: v for k, v in iteritems(mo_table) if k in server_mos}

    # Separate the MOs which have only platform-default
    for mo_name, props in table.items():
        non_default_props = {
            k: v
            for k, v in iteritems(props) if v != "platform-default"
        }
        # if there are no non-default props, it can be batched
        if len(non_default_props) == 0:
            # filter properties to only those applicable to the server
            server_mo_props = server_mos[mo_name]
            filtered_props = {
                k: v
                for k, v in iteritems(props)
                if k in server_mo_props and server_mo_props[k]
            }
            # load an instance of the class
            mo_class = load_class(mo_name)
            filtered_props["_handle"] = handle
            mo_obj = mo_class(parent_mo_or_dn=bios_mo, **filtered_props)
            # pop the object from the table dictionary
            table.pop(mo_name)

    # Send all the MOs with default properties in one shot
    handle.set_mo(bios_mo)

    # Send the rest of the MOs
    for mo_name, props in table.items():
        d = {}
        server_mo_props = server_mos[mo_name]
        filtered_props = {
            k: v
            for k, v in iteritems(props)
            if k in server_mo_props and server_mo_props[k]
        }

        if len(filtered_props) != 0:
            mo_class = load_class(mo_name)
            filtered_props["_handle"] = handle
            try:
                mo_obj = mo_class(parent_mo_or_dn=bios_mo.dn, **filtered_props)
                handle.set_mo(mo_obj)
            except ImcException as e:
                d["Object"] = mo_name
                error = e.error_descr
                if e.error_code == "ERR-xml-parse-error":
                    error = sanitize_xml_parsing_error(e.error_descr)
                d["Error"] = error
                messages.append(d)
                continue
            except Exception as e:
                d["Object"] = mo_name
                d["Error"] = str(e)
                messages.append(d)
                continue

    message = ""

    if len(messages) != 0:
        message = "Following issues were seen during application of BIOS " \
                "tokens: \n"
        for m in messages:
            message += m["Object"] + ": " + m["Error"] + "\n"

    ret["msg"] = message
    ret["msg_params"] = messages
    ret["changed"] = True
    return ret