示例#1
0
def boot_order_policy_get(handle, dump=False, server_id=1):
    """
    Gets the boot order. This is the legacy boot order

    Args:
        handle (ImcHandle)
        dump (bool): True or False
        server_id (int): Id of the server to perform
                         this operation on C3260 platforms

    Returns:
        List of dict in the format
            [{"order": '1', "device-type": "pxe", "name": "pxe"}]

    Example:
        boot_order_policy_get(handle, dump=False)
    """

    from imcsdk.mometa.lsboot.LsbootBootSecurity import LsbootBootSecurity

    server_dn = imccoreutils.get_server_dn(handle, server_id)
    parent_dn = server_dn + "/boot-policy"

    boot_order_list = []
    child_mo_list = handle.query_children(
        in_dn=parent_dn)
    boot_security_policy = LsbootBootSecurity(
        parent_mo_or_dn=parent_dn)

    for device in child_mo_list:
        if device.dn == boot_security_policy.dn:
            continue

        device_name = "NA"
        if hasattr(device, "name"):
            device_name = device.name

        device_type = _get_device_type("boot-order-policy", device)
        boot_order_list.append({"order": device.order,
                                "device-type": device_type,
                                "name": device_name})

    sorted_boot_order_list = sorted(
        boot_order_list, key=lambda x: x["order"])

    if dump:
        log.info("Boot Order according to Policy is [Order, Type, Name]:")
        log.info("------------------------------------------------------")

        for device_tuple in sorted_boot_order_list:
            log.info(
                " %s %s %s" %
                (device_tuple["order"].ljust(5),
                 device_tuple["device-type"].center(10),
                 device_tuple["name"].center(20)))

    return sorted_boot_order_list
示例#2
0
def boot_order_policy_set(handle,
                          reboot_on_update="no",
                          secure_boot="disabled",
                          boot_devices=[],
                          server_id=1):
    """
    This method will set the boot order policy passed from the user
    This is the deprecated way of setting the boot order
        and is applicable releases older than EP

    Args:
        handle (ImcHandle)
        reboot_on_update (string): "yes", "no"
        secure_boot (string): "enabled", "disabled"
        boot_devices (list of dict): format
            [{"order":'1', "device-type":"cdrom", "name":"cdrom0"},
             {"order":'2', "device-type":"lan", "name":"lan"}]

            boot-order(string): Order
            boot-device-type(string): "efi", "lan", "storage", "cdrom", "fdd"
            boot-device-name(string): Unique label for the boot device
        server_id (int): Id of the server to perform
                         this operation on C3260 platforms
    Returns:
        LsBootDef object

    Examples:
        boot_order_policy_set(
            handle,
            reboot_on_update="yes",
            secure_boot="enabled",
            boot_devices = [{"order":'1', "device-type":"cdrom",
                            "name":"cdrom0"},
                            {"order":'2', "device-type":"lan", "name":"lan"}]


    """

    # IMC expects the devices to be configured in sorted order
    boot_devices = sorted(boot_devices, key=lambda x: x["order"])

    from imcsdk.mometa.lsboot.LsbootDef import LsbootDef
    from imcsdk.mometa.lsboot.LsbootBootSecurity import LsbootBootSecurity

    server_dn = imccoreutils.get_server_dn(handle, server_id)

    boot_policy = LsbootDef(parent_mo_or_dn=server_dn)
    boot_policy.reboot_on_update = reboot_on_update
    handle.set_mo(boot_policy)

    secure_boot_policy = LsbootBootSecurity(parent_mo_or_dn=boot_policy.dn)
    # Secure boot policy is supported only from ImcVersion 2.0(1a)
    if handle.version >= secure_boot_policy.get_version(handle.platform):
        secure_boot_policy.secure_boot = secure_boot
        handle.set_mo(secure_boot_policy)

    boot_policy_child_mos = handle.query_children(in_dn=boot_policy.dn)
    for mo in boot_policy_child_mos:
        if mo.dn == secure_boot_policy.dn:
            continue
        # handle.remove_mo(mo)

    for device in boot_devices:
        _add_boot_device(handle, boot_policy.dn, device)

    boot_policy = handle.query_classid("LsbootDef")
    return boot_policy
示例#3
0
文件: boot.py 项目: CiscoUcs/imcsdk
def boot_order_policy_set(handle, reboot_on_update="no",
                          secure_boot="no",
                          boot_devices=[],
                          server_id=1):
    """
    This method will set the boot order policy passed from the user
    This is the deprecated way of setting the boot order
        and is applicable releases older than EP

    Args:
        handle (ImcHandle)
        reboot_on_update (string): "yes", "no"
        secure_boot (string): "enabled", "disabled"
        boot_devices (list of dict): format
            [{"order":'1', "device-type":"cdrom", "name":"cdrom0"},
             {"order":'2', "device-type":"lan", "name":"lan"}]

            boot-order(string): Order
            boot-device-type(string): "efi", "lan", "storage", "cdrom", "fdd"
            boot-device-name(string): Unique label for the boot device
        server_id (int): Id of the server to perform
                         this operation on C3260 platforms
    Returns:
        LsBootDef object

    Examples:
        boot_order_policy_set(
            handle,
            reboot_on_update="yes",
            secure_boot="no",
            boot_devices = [{"order":'1', "device-type":"cdrom",
                            "name":"cdrom0"},
                            {"order":'2', "device-type":"lan", "name":"lan"}]


    """

    # IMC expects the devices to be configured in sorted order
    boot_devices = sorted(boot_devices, key=lambda x: int(x["order"]))

    from imcsdk.mometa.lsboot.LsbootDef import LsbootDef
    from imcsdk.mometa.lsboot.LsbootBootSecurity import LsbootBootSecurity

    server_dn = imccoreutils.get_server_dn(handle, server_id)

    boot_policy = LsbootDef(parent_mo_or_dn=server_dn)
    boot_policy.reboot_on_update = reboot_on_update
    handle.set_mo(boot_policy)

    secure_boot_policy = LsbootBootSecurity(parent_mo_or_dn=boot_policy.dn)
    # Secure boot policy is supported only from ImcVersion 2.0(1a)
    if handle.version >= secure_boot_policy.get_version(handle.platform):
        if secure_boot == "yes":
            secure_boot_policy.secure_boot = "enabled"
        else:
            secure_boot_policy.secure_boot = "disabled"
        handle.set_mo(secure_boot_policy)

    boot_policy_child_mos = handle.query_children(in_dn=boot_policy.dn)
    for mo in boot_policy_child_mos:
        if mo.dn == secure_boot_policy.dn:
            continue
        handle.remove_mo(mo)

    for device in boot_devices:
        _add_boot_device(handle, boot_policy.dn, device)

    boot_policy = handle.query_classid("LsbootDef")
    return boot_policy
示例#4
0
文件: boot.py 项目: CiscoUcs/imcsdk
def boot_order_precision_set(
        handle,
        reboot_on_update="no",
        reapply="no",
        configured_boot_mode="Legacy",
        secure_boot="no",
        boot_devices=[],
        server_id=1):
    """
    This method will replace the existing boot order precision with the new one
        and also set the boot mode
    This functionality is available only in release EP and above

    Args:
        handle (ImcHandle)
        reboot_on_update (string): "yes", "no"
        reapply(string): "yes", "no"
        configured_boot_mode(string): "Legacy", "Uefi", "None"
        boot_devices (list of dict): format
            [{"order":'1', "device-type":"vmedia", "name":"vmedia"},
             {"order":'2', "device-type":"hdd", "name":"hdd"}]

            boot-order(string): Order
            boot-device-type(string): "hdd", "iscsi", "pchstorage", "pxe",
                                      "san", "sdcard", "uefishell", "usb",
                                      "vmedia"
            boot-device-name(string): Unique label for the boot device
        server_id (int): Id of the server to perform
                         this operation on C3260 platforms

    Returns:
        LsBootDevPrecision object

    Examples:
        boot_order_precision_set(
            handle,
            reboot_on_update="no",
            reapply="no",
            configured_boot_mode="Uefi",
            boot_devices = [{"order":'1', "device-type":"vmedia",
                            "name":"vmedia"},
                            {"order":'2', "device-type":"hdd", "name":"hdd"}]
    """
    from imcsdk.mometa.lsboot.LsbootDef import LsbootDef
    from imcsdk.mometa.lsboot.LsbootBootSecurity import LsbootBootSecurity

    boot_devices = sanitize_input_from_intersight(boot_devices)

    # Insert version check here to gracefully handle older versions of CIMC

    # IMC expects the devices to be configured in sorted order
    boot_devices = sorted(boot_devices, key=lambda x: int(x["order"]))

    server_dn = imccoreutils.get_server_dn(handle, server_id)

    # secure boot is a part of LsBootDef
    boot_policy = LsbootDef(parent_mo_or_dn=server_dn)
    secure_boot_mo = LsbootBootSecurity(parent_mo_or_dn=boot_policy.dn)
    if secure_boot == "yes":
        secure_boot_mo.secure_boot = "enabled"
    else:
        secure_boot_mo.secure_boot = "disabled"
    handle.set_mo(secure_boot_mo)

    lsbootdev = LsbootDevPrecision(parent_mo_or_dn=server_dn)

    # clean existing configuration
    # Need to check if doing this everytime will have any adverse impact
    boot_order_child_mos = handle.query_children(in_dn=lsbootdev.dn)
    for mo in boot_order_child_mos:
        if mo.get_class_id() == "LsbootCdd":
            # Deletion of LsbootCdd is not yet supported using XML API
            # Remove this check when CSCvh47929 is fixed
            # Existing Cdd device will automatically move down the
            # order when configuring other devices with CDD device's order
            continue
        handle.remove_mo(mo)

    # set the boot order precision related properties and devices
    lsbootdev.reboot_on_update = reboot_on_update
    lsbootdev.reapply = reapply
    if secure_boot == "no":
        lsbootdev.configured_boot_mode = configured_boot_mode

    for device in boot_devices:
        _add_boot_device(handle, lsbootdev, device)

    handle.set_mo(lsbootdev)
    return lsbootdev
示例#5
0
def boot_order_precision_set(handle,
                             reboot_on_update="no",
                             reapply="no",
                             configured_boot_mode="Legacy",
                             secure_boot="no",
                             boot_devices=[],
                             server_id=1):
    """
    This method will replace the existing boot order precision with the new one
        and also set the boot mode
    This functionality is available only in release EP and above

    Args:
        handle (ImcHandle)
        reboot_on_update (string): "yes", "no"
        reapply(string): "yes", "no"
        configured_boot_mode(string): "Legacy", "Uefi", "None"
        boot_devices (list of dict): format
            [{"order":'1', "device-type":"vmedia", "name":"vmedia"},
             {"order":'2', "device-type":"hdd", "name":"hdd"}]

            boot-order(string): Order
            boot-device-type(string): "hdd", "iscsi", "pchstorage", "pxe",
                                      "san", "sdcard", "uefishell", "usb",
                                      "vmedia"
            boot-device-name(string): Unique label for the boot device
        server_id (int): Id of the server to perform
                         this operation on C3260 platforms

    Returns:
        LsBootDevPrecision object

    Examples:
        boot_order_precision_set(
            handle,
            reboot_on_update="no",
            reapply="no",
            configured_boot_mode="Uefi",
            boot_devices = [{"order":'1', "device-type":"vmedia",
                            "name":"vmedia"},
                            {"order":'2', "device-type":"hdd", "name":"hdd"}]
    """
    from imcsdk.mometa.lsboot.LsbootDef import LsbootDef
    from imcsdk.mometa.lsboot.LsbootBootSecurity import LsbootBootSecurity

    boot_devices = sanitize_input_from_intersight(boot_devices)

    # Insert version check here to gracefully handle older versions of CIMC

    # IMC expects the devices to be configured in sorted order
    boot_devices = sorted(boot_devices, key=lambda x: int(x["order"]))

    server_dn = imccoreutils.get_server_dn(handle, server_id)

    # secure boot is a part of LsBootDef
    boot_policy = LsbootDef(parent_mo_or_dn=server_dn)
    secure_boot_mo = LsbootBootSecurity(parent_mo_or_dn=boot_policy.dn)
    if secure_boot == "yes":
        secure_boot_mo.secure_boot = "enabled"
    else:
        secure_boot_mo.secure_boot = "disabled"
    handle.set_mo(secure_boot_mo)

    lsbootdev = LsbootDevPrecision(parent_mo_or_dn=server_dn)

    # clean existing configuration
    # Need to check if doing this everytime will have any adverse impact
    boot_order_child_mos = handle.query_children(in_dn=lsbootdev.dn)
    for mo in boot_order_child_mos:
        if mo.get_class_id() == "LsbootCdd":
            # Deletion of LsbootCdd is not yet supported using XML API
            # Remove this check when CSCvh47929 is fixed
            # Existing Cdd device will automatically move down the
            # order when configuring other devices with CDD device's order
            continue
        handle.remove_mo(mo)

    # set the boot order precision related properties and devices
    lsbootdev.reboot_on_update = reboot_on_update
    lsbootdev.reapply = reapply
    if secure_boot == "no":
        lsbootdev.configured_boot_mode = configured_boot_mode

    for device in boot_devices:
        _add_boot_device(handle, lsbootdev, device)

    handle.set_mo(lsbootdev)
    return lsbootdev
示例#6
0
def boot_order_precision_set(handle,
                             reboot_on_update="no",
                             reapply="no",
                             configured_boot_mode="Legacy",
                             secure_boot="no",
                             boot_devices=[],
                             server_id=1):
    """
    This method will replace the existing boot order precision with the new one
        and also set the boot mode
    This functionality is available only in release EP and above

    Args:
        handle (ImcHandle)
        reboot_on_update (string): "yes", "no"
        reapply(string): "yes", "no"
        configured_boot_mode(string): "Legacy", "Uefi", "None"
        boot_devices (list of dict): format
            [{"order":'1', "device-type":"vmedia", "name":"vmedia"},
             {"order":'2', "device-type":"hdd", "name":"hdd"}]

            boot-order(string): Order
            boot-device-type(string): "hdd", "iscsi", "pchstorage", "pxe",
                                      "san", "sdcard", "uefishell", "usb",
                                      "vmedia"
            boot-device-name(string): Unique label for the boot device
        server_id (int): Id of the server to perform
                         this operation on C3260 platforms

    Returns:
        LsBootDevPrecision object

    Examples:
        boot_order_precision_set(
            handle,
            reboot_on_update="no",
            reapply="no",
            configured_boot_mode="Uefi",
            boot_devices = [{"order":'1', "device-type":"vmedia",
                            "name":"vmedia"},
                            {"order":'2', "device-type":"hdd", "name":"hdd"}]
    """
    from imcsdk.mometa.lsboot.LsbootDef import LsbootDef
    from imcsdk.mometa.lsboot.LsbootBootSecurity import LsbootBootSecurity
    from imcsdk.imccoreutils import is_platform_m4

    boot_devices = sanitize_input_from_intersight(handle, boot_devices)

    # Insert version check here to gracefully handle older versions of CIMC

    # IMC expects the devices to be configured in sorted order
    boot_devices = sorted(boot_devices, key=lambda x: int(x["order"]))

    # filter pxe device
    # enable pxe boot on respective interface
    # derive logical port
    pxe.disable_pxeboot_vnics_all(handle)
    pxe.prepare_pxe_devices(handle, boot_devices)

    server_dn = imccoreutils.get_server_dn(handle, server_id)

    # secure boot is a part of LsBootDef
    boot_policy = LsbootDef(parent_mo_or_dn=server_dn)
    secure_boot_mo = LsbootBootSecurity(parent_mo_or_dn=boot_policy.dn)
    if secure_boot == "yes":
        secure_boot_mo.secure_boot = "enabled"
    else:
        secure_boot_mo.secure_boot = "disabled"
    handle.set_mo(secure_boot_mo)

    lsbootdev = LsbootDevPrecision(parent_mo_or_dn=server_dn)

    # clean existing configuration
    # Need to check if doing this everytime will have any adverse impact
    boot_order_child_mos = handle.query_children(in_dn=lsbootdev.dn)

    #check the version as CSCvh47929 fix is applied to later versions
    for mo in boot_order_child_mos:
        if str(handle.version) < "3.1(3a)" and mo.get_class_id(
        ) == "LsbootCdd":
            # Deletion of LsbootCdd is not supported using XML API for older versions
            # although CSCvh47929 is fixed
            # Existing Cdd device will automatically move down the
            # order when configuring other devices with CDD device's order
            continue
        handle.remove_mo(mo)

    # set the boot order precision related properties and devices
    lsbootdev.reboot_on_update = reboot_on_update
    lsbootdev.reapply = reapply
    if secure_boot == "no":
        lsbootdev.configured_boot_mode = configured_boot_mode

    i = 0
    #check the version and skip if the device is of type localcdd
    for device in boot_devices:
        if device["device-type"] == "cdd" and (
                is_platform_m4(handle) or str(handle.version) < "3.1(3a)"):
            i = i + 1
            continue
        if device['device-type'] == 'pxe' and is_platform_m4(
                handle) and device['interface_source'] == 'mac':
            i = i + 1
            continue

        #if the list has cdd, reorder the policy types that are after cdd  as cdd will be skipped
        #and CIMC expects the devices in sorted order.
        if i != 0:
            device["order"] = str(int(device["order"]) - i)
        _add_boot_device(handle, lsbootdev, device)
    handle.set_mo(lsbootdev)
    return lsbootdev