Example #1
1
def test_imc_context_manager_no_timeout():
    try:
        import ConfigParser
    except:
        import configparser as ConfigParser

    from imcsdk.imchandle import ImcHandle
    from ..connection import info

    host = 'imc'
    config = ConfigParser.RawConfigParser()
    config.read(info.CONNECTION_CFG_FILEPATH)
    hostname = config.get(host, "hostname")
    username = config.get(host, "username")
    password = config.get(host, "password")

    handle = ImcHandle(hostname, username, password)
    with handle:
        server_dn = get_server_dn(handle)
        mo = handle.query_dn(server_dn, timeout=600)
        usr_lbl = "test-lbl2"
        mo.usr_lbl = usr_lbl
        handle.set_mo(mo, timeout=600)
        mo = handle.query_dn(server_dn)

    assert_equal(mo.usr_lbl, usr_lbl)
Example #2
0
def server_power_down(handle, timeout=60, interval=5, server_id=1, **kwargs):
    """
    This method will power down the rack server, even if tasks are still
    running on it.  Then polls the server every $interval until either $timeout
    or it comes online.

    Args:
        handle(ImcHandle)
        timeout(int)
        interval(int)
        server_id (int): Server Id to be specified for C3260 platforms
        kwargs: key=value paired arguments

    Returns:
        ComputeRackUnit object for non-C3260 platform
        ComputeServerNode object for C3260 platform

    Example:
        server_power_down(handle)
        server_power_down(handle, timeout=120, interval=10)
        server_power_down(handle, server_id=2, timeout=60)
    """

    server_dn = get_server_dn(handle, server_id)
    # Turn power off only if not already powered down
    if server_power_state_get(handle, server_id) != "off":
        _set_power_state(handle, server_dn, "down")

    # Poll until the server is powered up
    _wait_for_power_state(handle, "off", timeout=timeout,
                          interval=interval, server_id=server_id)

    return handle.query_dn(server_dn)
Example #3
0
def server_power_cycle(handle, timeout=120, interval=5, server_id=1, **kwargs):
    """
    This method will power cycle the rack server immediately.

    Args:
        handle(ImcHandle)
        server_id (int): Server Id to be specified for C3260 platforms
        kwargs: key=value paired arguments


    Returns:
        ComputeRackUnit object for non-C3260 platform
        ComputeServerNode object for C3260 platform

    Example:
        server_power_cycle(handle) for non-C3260 platforms
        server_power_cycle(handle, timeout=120, interval=10) \
                for non-C3260 platforms
        server_power_cycle(handle, server_id=2, timeout=60) for C3260 platforms
    """

    server_dn = get_server_dn(handle, server_id)
    _set_power_state(handle, server_dn, "cycle")

    # Poll until the server is powered up
    _wait_for_power_state(handle, "on", timeout=timeout,
                          interval=interval, server_id=server_id)

    return handle.query_dn(server_dn)
Example #4
0
def test_vd_create_delete():
    # Guarding check to execute only on servers that have a CONTROLLER_SLOT controller
    # and have drive 1-6 present
    server_dn = get_server_dn(handle, server_id=1)
    slot_dn = server_dn + "/board/storage-SAS-SLOT-MEZZ"
    mo = handle.query_dn(slot_dn)
    if mo is None:
        return
    for i in range(1, 7):
        mo = handle.query_dn(slot_dn + "/pd-" + str(i))
        if mo is None:
            return

    tests = [{
        "dg": [[1]],
        "ct": CONTROLLER_TYPE,
        "cs": CONTROLLER_SLOT,
        "r": 0
    }, {
        "dg": [[1, 2, 3, 4]],
        "ct": CONTROLLER_TYPE,
        "cs": CONTROLLER_SLOT,
        "r": 1
    }, {
        "dg": [[1, 2, 3]],
        "ct": CONTROLLER_TYPE,
        "cs": CONTROLLER_SLOT,
        "r": 5
    }, {
        "dg": [[1, 2, 3]],
        "ct": CONTROLLER_TYPE,
        "cs": CONTROLLER_SLOT,
        "r": 6
    }, {
        "dg": [[1, 2], [3, 4], [5, 6]],
        "ct": CONTROLLER_TYPE,
        "cs": CONTROLLER_SLOT,
        "r": 10
    }, {
        "dg": [[1, 2, 3], [4, 5, 6]],
        "ct": CONTROLLER_TYPE,
        "cs": CONTROLLER_SLOT,
        "r": 50
    }, {
        "dg": [[1, 2, 3], [4, 5, 6]],
        "ct": CONTROLLER_TYPE,
        "cs": CONTROLLER_SLOT,
        "r": 60
    }]

    for t in tests:
        vd = virtual_drive_create(handle=handle,
                                  drive_group=t["dg"],
                                  controller_type=t["ct"],
                                  controller_slot=t["cs"],
                                  raid_level=t["r"],
                                  self_encrypt=True)
        virtual_drive_delete(handle=handle,
                             controller_slot=t["cs"],
                             name=vd.virtual_drive_name)
Example #5
0
def server_power_state_get(handle, server_id=1):
    """
    This method will return the oper power status of the rack server

    Args:
        handle (ImcHandle)
        server_id (int): Server Id to be specified for C3260 platforms

    Examples:
        For classic or non-C3260 series servers:-
        server_power_state_get(handle)

        For modular or C3260 series servers, server_id should also be passed
        in the params:-
        server_power_state_get(handle, server_id=1)
        If server_id is not specified, this will assume server_id="1"

    Returns:
        oper power state(string)
    """

    server_dn = get_server_dn(handle, server_id)
    server_mo = handle.query_dn(server_dn)
    if server_mo:
        return server_mo.oper_power

    raise ImcOperationError("Get Server Power State",
                            "Managed Object not found for dn:%s" % server_dn)
Example #6
0
def server_power_cycle(handle, timeout=120, interval=5, server_id=1, **kwargs):
    """
    This method will power cycle the rack server immediately.

    Args:
        handle(ImcHandle)
        server_id (int): Server Id to be specified for C3260 platforms
        kwargs: key=value paired arguments


    Returns:
        ComputeRackUnit object for non-C3260 platform
        ComputeServerNode object for C3260 platform

    Example:
        server_power_cycle(handle) for non-C3260 platforms
        server_power_cycle(handle, timeout=120, interval=10) \
                for non-C3260 platforms
        server_power_cycle(handle, server_id=2, timeout=60) for C3260 platforms
    """

    server_dn = get_server_dn(handle, server_id)
    _set_power_state(handle, server_dn, "cycle")

    # Poll until the server is powered up
    _wait_for_power_state(handle,
                          "on",
                          timeout=timeout,
                          interval=interval,
                          server_id=server_id)

    return handle.query_dn(server_dn)
Example #7
0
def test_imc_context_manager_no_timeout():
    try:
        import ConfigParser
    except:
        import configparser as ConfigParser

    from imcsdk.imchandle import ImcHandle
    from ..connection import info

    host = 'imc'
    config = ConfigParser.RawConfigParser()
    config.read(info.CONNECTION_CFG_FILEPATH)
    hostname = config.get(host, "hostname")
    username = config.get(host, "username")
    password = config.get(host, "password")

    handle = ImcHandle(hostname, username, password)
    with handle:
        server_dn = get_server_dn(handle)
        mo = handle.query_dn(server_dn, timeout=600)
        usr_lbl = "test-lbl2"
        mo.usr_lbl = usr_lbl
        handle.set_mo(mo, timeout=600)
        mo = handle.query_dn(server_dn)

    assert_equal(mo.usr_lbl, usr_lbl)
Example #8
0
def test_vd_create_delete():
    # Guarding check to execute only on servers that have a CONTROLLER_SLOT controller
    # and have drive 1-6 present
    server_dn = get_server_dn(handle, server_id=1)
    slot_dn = server_dn + "/board/storage-SAS-SLOT-MEZZ"
    mo = handle.query_dn(slot_dn)
    if mo is None:
        return
    for i in range(1, 7):
        mo = handle.query_dn(slot_dn + "/pd-" + str(i))
        if mo is None:
            return

    tests = [{"dg": [[1]], "ct": CONTROLLER_TYPE, "cs": CONTROLLER_SLOT, "r": 0},
             {"dg": [[1, 2, 3, 4]], "ct": CONTROLLER_TYPE, "cs": CONTROLLER_SLOT, "r": 1},
             {"dg": [[1, 2, 3]], "ct": CONTROLLER_TYPE, "cs": CONTROLLER_SLOT, "r": 5},
             {"dg": [[1, 2, 3]], "ct": CONTROLLER_TYPE, "cs": CONTROLLER_SLOT, "r": 6},
             {"dg": [[1, 2], [3, 4], [5, 6]], "ct": CONTROLLER_TYPE, "cs": CONTROLLER_SLOT, "r": 10},
             {"dg": [[1, 2, 3], [4, 5, 6]], "ct": CONTROLLER_TYPE, "cs": CONTROLLER_SLOT, "r": 50},
             {"dg": [[1, 2, 3], [4, 5, 6]], "ct": CONTROLLER_TYPE, "cs": CONTROLLER_SLOT, "r": 60}]

    for t in tests:
        vd = virtual_drive_create(handle=handle,
                                  drive_group=t["dg"],
                                  controller_type=t["ct"],
                                  controller_slot=t["cs"],
                                  raid_level=t["r"],
                                  self_encrypt=True)
        virtual_drive_delete(handle=handle,
                             controller_slot=t["cs"],
                             name=vd.virtual_drive_name)
Example #9
0
def server_power_state_get(handle, server_id=1):
    """
    This method will return the oper power status of the rack server

    Args:
        handle (ImcHandle)
        server_id (int): Server Id to be specified for C3260 platforms

    Examples:
        For classic or non-C3260 series servers:-
        server_power_state_get(handle)

        For modular or C3260 series servers, server_id should also be passed
        in the params:-
        server_power_state_get(handle, server_id=1)
        If server_id is not specified, this will assume server_id="1"

    Returns:
        oper power state(string)
    """

    server_dn = get_server_dn(handle, server_id)
    server_mo = handle.query_dn(server_dn)
    if server_mo:
        return server_mo.oper_power

    raise ImcOperationError("Get Server Power State",
                            "Managed Object not found for dn:%s" % server_dn)
Example #10
0
def sol_setup(handle, speed, comport, ssh_port, server_id=1):
    """
    This method will setup serial over lan connection

    Args:
        handle (ImcHandle)
        speed (string): "9600", "19200", "38400", "57600", "115200"
        comport (string): "com0", "com1"
        ssh_port (int): port for ssh
        server_id (int): Server Id to be specified for C3260 platforms

    Returns:
        SolIf object
    """

    solif_mo = SolIf(parent_mo_or_dn=get_server_dn(handle, server_id))
    params = {
        "admin_state": SolIfConsts.ADMIN_STATE_ENABLE,
        "speed": str(speed),
        "comport": comport,
        "ssh_port": str(ssh_port),
    }

    solif_mo.set_prop_multiple(**params)
    handle.set_mo(solif_mo)
    return handle.query_dn(solif_mo.dn)
Example #11
0
def sol_get(handle, server_id=1, caller="sol_get"):
    parent_dn = get_server_dn(handle, server_id)
    dn = parent_dn + "/sol-if"
    mo = handle.query_dn(dn)
    if mo is None:
        raise ImcOperationError(caller, "SOL '%s' doesn't exist." % dn)
    return mo
Example #12
0
def sol_setup(handle, speed, comport, ssh_port, server_id=1):
    """
    This method will setup serial over lan connection

    Args:
        handle (ImcHandle)
        speed (string): "9600", "19200", "38400", "57600", "115200"
        comport (string): "com0", "com1"
        ssh_port (int): port for ssh
        server_id (int): Server Id to be specified for C3260 platforms

    Returns:
        SolIf object
    """

    solif_mo = SolIf(parent_mo_or_dn=get_server_dn(handle, server_id))
    params = {
        "admin_state": SolIfConsts.ADMIN_STATE_ENABLE,
        "speed": str(speed),
        "comport": comport,
        "ssh_port": str(ssh_port),
    }

    solif_mo.set_prop_multiple(**params)
    handle.set_mo(solif_mo)
    return handle.query_dn(solif_mo.dn)
Example #13
0
def server_power_down_gracefully(handle, timeout=120, interval=5,
                                 server_id=1, **kwargs):
    """
    This method will power down the rack server gracefully

    Args:
        handle(ImcHandle)
        server_id (int): Server Id to be specified for C3260 platforms
        kwargs: key=value paired arguments

    Returns:
        ComputeRackUnit object for non-C3260 platform
        ComputeServerNode object for C3260 platform

    Example:
        server_power_down_gracefully(handle)
        server_power_down_gracefully(handle, timeout=120, interval=10)
        server_power_down_gracefully(handle, server_id=2, timeout=60)
    """

    server_dn = get_server_dn(handle, server_id)
    # Gracefully power off only if not already powered down
    if server_power_state_get(handle, server_id) != "off":
        _set_power_state(handle, server_dn, "graceful-down")

    # Poll until the server is powered up
    _wait_for_power_state(handle, "off", timeout=timeout,
                          interval=interval, server_id=server_id)

    return handle.query_dn(server_dn)
Example #14
0
def server_power_up(handle, timeout=60, interval=5, server_id=1, **kwargs):
    """
    This method will send the server the power up signal, and then polls
    the server every $interval until either $timeout or it comes online.

    Args:
        handle(ImcHandle)
        timeout (int)
        interval (int)
        server_id (int): Server Id to be specified for C3260 platforms
        kwargs: key=value paired arguments

    Returns:
        ComputeRackUnit object for non-C3260 platform
        ComputeServerNode object for C3260 platform

    Example:
        server_power_up(handle)
        server_power_up(handle, timeout=120, interval=10)
        server_power_up(handle, server_id=2, timeout=60)
    """

    server_dn = get_server_dn(handle, server_id)
    # Turn power on only if not already powered up
    if server_power_state_get(handle, server_id) != "on":
        _set_power_state(handle, server_dn, "up")

    # Poll until the server is powered up
    _wait_for_power_state(handle, "on", timeout=timeout,
                          interval=interval, server_id=server_id)

    # Return object with current state
    return handle.query_dn(server_dn)
Example #15
0
def sol_get(handle, server_id=1, caller="sol_get"):
    parent_dn = get_server_dn(handle, server_id)
    dn = parent_dn + "/sol-if"
    mo = handle.query_dn(dn)
    if mo is None:
        raise ImcOperationError(caller,
                                "SOL '%s' doesn't exist." % dn)
    return mo
Example #16
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
Example #17
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: int(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
Example #18
0
def _get_mgmt_if_dn(handle, id=1):
    from imcsdk.mometa.mgmt.MgmtIf import MgmtIf

    if handle.platform == IMC_PLATFORM.TYPE_CLASSIC:
        parent_dn = get_server_dn(handle) + '/mgmt'
    elif handle.platform == IMC_PLATFORM.TYPE_MODULAR:
        parent_dn = 'sys/chassis-1'

    mo = MgmtIf(parent_mo_or_dn=parent_dn)
    return mo.dn
Example #19
0
def _get_mgmt_if_dn(handle, id=1):
    from imcsdk.mometa.mgmt.MgmtIf import MgmtIf

    if handle.platform == IMC_PLATFORM.TYPE_CLASSIC:
        parent_dn = get_server_dn(handle) + '/mgmt'
    elif handle.platform == IMC_PLATFORM.TYPE_MODULAR:
        parent_dn = 'sys/chassis-1'

    mo = MgmtIf(parent_mo_or_dn=parent_dn)
    return mo.dn
Example #20
0
def test_imc_no_timeout():

    global handle
    server_dn = get_server_dn(handle)
    mo = handle.query_dn(server_dn, timeout=600)
    usr_lbl = "test-lbl1"
    mo.usr_lbl = usr_lbl
    handle.set_mo(mo, timeout=600)

    mo = handle.query_dn(server_dn)
    assert_equal(mo.usr_lbl, usr_lbl)
Example #21
0
def firmware_huu_update_monitor(handle, timeout=60, interval=10, server_id=1):
    """
    This method monitors status of a firmware upgrade.

    Args:
        handle(ImcHandle)
        timeout(int): Timeout in minutes for monitor API.
        interval(int): frequency of monitoring in seconds
        server_id(int): Server id for monitoring firmware upgrade

    Returns:
        None

    Examples:
        firmware_huu_update_monitor(handle, 60, 10)
    """
    current_status = []
    start = datetime.datetime.now()

    top_system = TopSystem()
    if handle.platform == IMC_PLATFORM.TYPE_CLASSIC:
        parent_dn = top_system.dn
    elif handle.platform == IMC_PLATFORM.TYPE_MODULAR:
        parent_dn = get_server_dn(handle, str(server_id))

    huu = HuuController(parent_mo_or_dn=parent_dn)
    huu_firmware_updater = HuuFirmwareUpdater(parent_mo_or_dn=huu.dn)
    update_obj = HuuFirmwareUpdateStatus(
        parent_mo_or_dn=huu_firmware_updater.dn)

    while True:
        try:
            update_obj = handle.query_dn(update_obj.dn)
            if _has_upgrade_started(update_obj):
                log_progress("Firmware upgrade is yet to start")

            if _has_upgrade_finished(update_obj):
                log_progress("Firmware upgrade has finished",
                             update_obj.overall_status)
                _print_component_upgrade_summary(handle)
                break
            elif update_obj.overall_status not in current_status:
                log_progress("Firmware Upgrade is still running",
                             update_obj.overall_status)
                current_status.append(update_obj.overall_status)

            time.sleep(interval)
            secs = (datetime.datetime.now() - start).total_seconds()
            if int(secs / 60) > timeout:
                log_progress("Monitor API timeout",
                             "rerun firmware_huu_update_monitor")
                break
        except:
            _validate_connection(handle)
Example #22
0
def firmware_huu_update_monitor(handle, timeout=60, interval=10, server_id=1):
    """
    This method monitors status of a firmware upgrade.

    Args:
        handle(ImcHandle)
        timeout(int): Timeout in minutes for monitor API.
        interval(int): frequency of monitoring in seconds
        server_id(int): Server id for monitoring firmware upgrade

    Returns:
        None

    Examples:
        firmware_huu_update_monitor(handle, 60, 10)
    """
    current_status = []
    start = datetime.datetime.now()

    top_system = TopSystem()
    if handle.platform == IMC_PLATFORM.TYPE_CLASSIC:
        parent_dn = top_system.dn
    elif handle.platform == IMC_PLATFORM.TYPE_MODULAR:
        parent_dn = get_server_dn(handle, str(server_id))

    huu = HuuController(parent_mo_or_dn=parent_dn)
    huu_firmware_updater = HuuFirmwareUpdater(parent_mo_or_dn=huu.dn)
    update_obj = HuuFirmwareUpdateStatus(
            parent_mo_or_dn=huu_firmware_updater.dn)

    while True:
        try:
            update_obj = handle.query_dn(update_obj.dn)
            if _has_upgrade_started(update_obj):
                log_progress("Firmware upgrade is yet to start")

            if _has_upgrade_finished(update_obj):
                log_progress("Firmware upgrade has finished",
                             update_obj.overall_status)
                _print_component_upgrade_summary(handle)
                break
            elif update_obj.overall_status not in current_status:
                log_progress("Firmware Upgrade is still running",
                             update_obj.overall_status)
                current_status.append(update_obj.overall_status)

            time.sleep(interval)
            secs = (datetime.datetime.now() - start).total_seconds()
            if int(secs / 60) > timeout:
                log_progress("Monitor API timeout",
                             "rerun firmware_huu_update_monitor")
                break
        except:
            _validate_connection(handle)
Example #23
0
def test_imc_no_timeout():

    global handle
    server_dn = get_server_dn(handle)
    mo = handle.query_dn(server_dn, timeout=600)
    usr_lbl = "test-lbl1"
    mo.usr_lbl = usr_lbl
    handle.set_mo(mo, timeout=600)

    mo = handle.query_dn(server_dn)
    assert_equal(mo.usr_lbl, usr_lbl)
Example #24
0
def server_standard_power_cap_set(handle,
                                  power_limit,
                                  throttle=False,
                                  correction_time=3,
                                  corrective_action="alert",
                                  hard_cap=False,
                                  server_id=1):
    """
    This method sets up the standard power cap configuration profile

    Args:
        handle (ImcHandle)
        throttle (bool)
        power_limit (int): Power limit in Watts.
                           Range can be retrieved from min_power and max_power
                           fields of PowerBudget object
        correction_time (int): Time in seconds before power_limit is enforced
            and corrective action is taken. Range (1-600)s
        corrective_action (string): "none","alert","shutdown","alert,shutdown"
        hard_cap (bool): Enable hard power cap
        server_id (int): Server Id to be specified for C3260 platforms

    Returns:
        StandardPowerProfile object

    Examples:
        server_standard_power_cap_set(handle,
                                      correction_time=5,
                                      corrective_action="alert")
        server_standard_power_cap_set(handle, throttle=True,
                               power_limit=200, correction_time=5,
                               corrective_action="alert, shutdown")
    """

    if not is_supported_model(handle):
        return

    power_budget_dn = get_server_dn(handle, server_id) + "/budget"
    stdpowerprof_mo = StandardPowerProfile(parent_mo_or_dn=power_budget_dn)

    params = {
        "allow_throttle": ("no", "yes")[throttle],
        "power_limit": str(power_limit),
        "corr_time": str(correction_time),
        "corr_action": corrective_action,
        "profile_enabled": "yes",
        "hard_cap": ("no", "yes")[hard_cap]
    }

    stdpowerprof_mo.set_prop_multiple(**params)
    handle.set_mo(stdpowerprof_mo)
    return stdpowerprof_mo
Example #25
0
def test_imc_timeout():

    import urllib2

    global handle
    server_dn = get_server_dn(handle)
    mo = handle.query_dn(server_dn, timeout=600)
    usr_lbl = "test-lbl2"
    mo.usr_lbl = usr_lbl
    try:
        handle.set_mo(mo, timeout=1)
    except urllib2.URLError as e:
        print("Hit expected error")
        raise Exception
Example #26
0
def _get_comm_mo_dn(handle, server_id=1):
    """
    Internal method to get the IPMI mo's parent_dn based \
            on the type of platform
    """
    from imcsdk.imcexception import ImcValidationException

    if handle.platform == IMC_PLATFORM.TYPE_CLASSIC:
        return("sys/svc-ext")
    elif handle.platform == IMC_PLATFORM.TYPE_MODULAR:
        return(get_server_dn(handle, server_id) + "/svc-ext")
    else:
        raise ImcValidationException("Invalid platform detected:%s" %
                                     handle.platform)
Example #27
0
def test_imc_timeout():

    from six.moves import urllib

    global handle
    server_dn = get_server_dn(handle)
    mo = handle.query_dn(server_dn, timeout=600)
    usr_lbl = "test-lbl2"
    mo.usr_lbl = usr_lbl
    try:
        handle.set_mo(mo, timeout=1)
    except urllib.error.URLError:
        print("Hit expected error")
        raise Exception
Example #28
0
def _get_comm_mo_dn(handle, server_id=1):
    """
    Internal method to get the IPMI mo's parent_dn based \
            on the type of platform
    """
    from imcsdk.imcexception import ImcValidationException

    if handle.platform == IMC_PLATFORM.TYPE_CLASSIC:
        return ("sys/svc-ext")
    elif handle.platform == IMC_PLATFORM.TYPE_MODULAR:
        return (get_server_dn(handle, server_id) + "/svc-ext")
    else:
        raise ImcValidationException("Invalid platform detected:%s" %
                                     handle.platform)
Example #29
0
def server_standard_power_cap_set(handle, power_limit, throttle=False,
                                  correction_time=3, corrective_action="alert",
                                  hard_cap=False, server_id=1):
    """
    This method sets up the standard power cap configuration profile

    Args:
        handle (ImcHandle)
        throttle (bool)
        power_limit (int): Power limit in Watts.
                           Range can be retrieved from min_power and max_power
                           fields of PowerBudget object
        correction_time (int): Time in seconds before power_limit is enforced
            and corrective action is taken. Range (1-600)s
        corrective_action (string): "none","alert","shutdown","alert,shutdown"
        hard_cap (bool): Enable hard power cap
        server_id (int): Server Id to be specified for C3260 platforms

    Returns:
        StandardPowerProfile object

    Examples:
        server_standard_power_cap_set(handle,
                                      correction_time=5,
                                      corrective_action="alert")
        server_standard_power_cap_set(handle, throttle=True,
                               power_limit=200, correction_time=5,
                               corrective_action="alert, shutdown")
    """

    if not is_supported_model(handle):
        return

    power_budget_dn = get_server_dn(handle, server_id) + "/budget"
    stdpowerprof_mo = StandardPowerProfile(
        parent_mo_or_dn=power_budget_dn)

    params = {
        "allow_throttle": ("no", "yes")[throttle],
        "power_limit": str(power_limit),
        "corr_time": str(correction_time),
        "corr_action": corrective_action,
        "profile_enabled": "yes",
        "hard_cap": ("no", "yes")[hard_cap]
    }

    stdpowerprof_mo.set_prop_multiple(**params)
    handle.set_mo(stdpowerprof_mo)
    return stdpowerprof_mo
Example #30
0
def is_sol_enabled(handle, server_id=1):
    """
    This method will check if Serial over Lan connection is enabled

    Args:
        handle (ImcHandle)
        server_id (int): Server Id to be specified for C3260 platforms

    Returns:
        None
    """

    solif_mo = SolIf(parent_mo_or_dn=get_server_dn(handle, server_id))
    solif_mo = handle.query_dn(solif_mo.dn)
    return solif_mo.admin_state.lower() in ["enable", "enabled"]
Example #31
0
def is_sol_enabled(handle, server_id=1):
    """
    This method will check if Serial over Lan connection is enabled

    Args:
        handle (ImcHandle)
        server_id (int): Server Id to be specified for C3260 platforms

    Returns:
        None
    """

    solif_mo = SolIf(parent_mo_or_dn=get_server_dn(handle, server_id))
    solif_mo = handle.query_dn(solif_mo.dn)
    return solif_mo.admin_state.lower() in ["enable", "enabled"]
Example #32
0
def sol_disable(handle, server_id=1):
    """
    This method will disable Serial over Lan connection

    Args:
        handle (ImcHandle)
        server_id (int): Server Id to be specified for C3260 platforms

    Returns:
        None
    """

    solif_mo = SolIf(parent_mo_or_dn=get_server_dn(handle, server_id))
    solif_mo.admin_state = SolIfConsts.ADMIN_STATE_DISABLE
    handle.set_mo(solif_mo)
Example #33
0
def sol_disable(handle, server_id=1):
    """
    This method will disable Serial over Lan connection

    Args:
        handle (ImcHandle)
        server_id (int): Server Id to be specified for C3260 platforms

    Returns:
        None
    """

    solif_mo = SolIf(parent_mo_or_dn=get_server_dn(handle, server_id))
    solif_mo.admin_state = SolIfConsts.ADMIN_STATE_DISABLE
    handle.set_mo(solif_mo)
Example #34
0
def boot_order_precision_get(handle, dump=False, server_id=1):
    """
    Gets the precision boot order.
    This is supported from EP release onwards only

    Args:
        handle (ImcHandle)
        dump (bool): True or False
        server_id (int): Id of the server in case of C3260 platforms

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

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

    server_dn = imccoreutils.get_server_dn(handle, server_id)
    parent_dn = server_dn + "/bios/bdgep"

    boot_order_list = []
    boot_device_list = handle.query_children(in_dn=parent_dn,
                                             class_id="BiosBootDevPrecision")

    for device in boot_device_list:
        device_type = device.type if device.type else str(device.type)
        boot_order_list.append({
            "order": device.order,
            "device-type": device_type,
            "name": device.name
        })

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

    log.debug("sorted_boot_order_list:\n%s" % sorted_boot_order_list)

    if dump:
        log.info("Precision Boot Order is [Order, Type, Name]:")
        log.info("--------------------------------------------")
        for device in sorted_boot_order_list:
            log.info(
                " %s %s %s" %
                (device["order"].ljust(5), device["device-type"].ljust(10),
                 device["name"].ljust(20)))

    return sorted_boot_order_list
Example #35
0
def boot_order_precision_get(handle, dump=False, server_id=1):
    """
    Gets the precision boot order.
    This is supported from EP release onwards only

    Args:
        handle (ImcHandle)
        dump (bool): True or False
        server_id (int): Id of the server in case of C3260 platforms

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

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

    server_dn = imccoreutils.get_server_dn(handle, server_id)
    parent_dn = server_dn + "/bios/bdgep"

    boot_order_list = []
    boot_device_list = handle.query_children(
        in_dn=parent_dn, class_id="BiosBootDevPrecision")

    for device in boot_device_list:
        device_type = device.type if device.type else str(device.type)
        boot_order_list.append({"order": device.order,
                                "device-type": device_type,
                                "name": device.name})

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

    log.debug("sorted_boot_order_list:\n%s" % sorted_boot_order_list)

    if dump:
        log.info("Precision Boot Order is [Order, Type, Name]:")
        log.info("--------------------------------------------")
        for device in sorted_boot_order_list:
            log.info(" %s %s %s" % (device["order"].ljust(5),
                                    device["device-type"].ljust(10),
                                    device["name"].ljust(20)))

    return sorted_boot_order_list
Example #36
0
File: bios.py Project: vvb/imcsdk
def boot_precision_configured_get(handle, server_id=1):
    from imcsdk.imccoreutils import get_server_dn

    configured_boot_order = []

    class_to_name_dict = {
        value["class_id"]: key for key,
        value in imcgenutils.iteritems(precision_device_dict)}

    server_dn = get_server_dn(handle, server_id)
    pmo = LsbootDevPrecision(parent_mo_or_dn=server_dn)
    mos = handle.query_children(in_dn=pmo.dn)
    for mo in mos:
        device = {"order": mo.order,
                  "device-type": class_to_name_dict[mo._class_id],
                  "name": mo.name}
        configured_boot_order.append(device)
    return sorted(configured_boot_order, key=lambda x: x["order"])
Example #37
0
def server_power_characterization_enable(handle, server_id=1):
    """
    Enables power characterization.

    Args:
        handle (ImcHandle)
        server_id (int): Server Id to be specified for C3260 platforms

    Returns:
        PowerBudget object
    """
    if not is_supported_model(handle):
        return
    power_budget_mo = PowerBudget(
        parent_mo_or_dn=get_server_dn(handle, server_id))
    power_budget_mo.pow_char_enable = "enabled"
    handle.set_mo(power_budget_mo)
    return power_budget_mo
Example #38
0
def boot_precision_configured_get(handle, server_id=1):
    from imcsdk.imccoreutils import get_server_dn

    configured_boot_order = []

    class_to_name_dict = {
        value["class_id"]: key for key,
        value in precision_device_dict.items()}

    server_dn = get_server_dn(handle, server_id)
    pmo = LsbootDevPrecision(parent_mo_or_dn=server_dn)
    mos = handle.query_children(in_dn=pmo.dn)
    for mo in mos:
        device = {"order": mo.order,
                  "device-type": class_to_name_dict[mo._class_id],
                  "name": mo.name}
        configured_boot_order.append(device)
    return sorted(configured_boot_order, key=lambda x: x["order"])
Example #39
0
def server_power_capping_enable(handle, server_id=1):
    """
    Enables power capping feature on the server.

    Args:
        handle (ImcHandle)
        server_id (int): Server Id to be specified for C3260 platforms

    Returns:
        PowerBudget object
    """

    if not is_supported_model(handle):
        return
    power_budget_mo = PowerBudget(parent_mo_or_dn=get_server_dn(handle, server_id))
    power_budget_mo.admin_state = "enabled"
    handle.set_mo(power_budget_mo)
    return power_budget_mo
Example #40
0
def server_power_characterization_enable(handle, server_id=1):
    """
    Enables power characterization.

    Args:
        handle (ImcHandle)
        server_id (int): Server Id to be specified for C3260 platforms

    Returns:
        PowerBudget object
    """
    if not is_supported_model(handle):
        return
    power_budget_mo = PowerBudget(
        parent_mo_or_dn=get_server_dn(handle, server_id))
    power_budget_mo.pow_char_enable = "enabled"
    handle.set_mo(power_budget_mo)
    return power_budget_mo
Example #41
0
def server_power_capping_enable(handle, server_id=1):
    """
    Enables power capping feature on the server.

    Args:
        handle (ImcHandle)
        server_id (int): Server Id to be specified for C3260 platforms

    Returns:
        PowerBudget object
    """

    if not is_supported_model(handle):
        return
    power_budget_mo = PowerBudget(
        parent_mo_or_dn=get_server_dn(handle, server_id))
    power_budget_mo.admin_state = "enabled"
    handle.set_mo(power_budget_mo)
    return power_budget_mo
Example #42
0
def server_standard_power_cap_disable(handle, server_id=1):
    """
    This method disables the standard power profile

    Args:
        handle (ImcHandle)
        server_id (int): Server Id to be specified for C3260 platforms

    Returns:
        None
    """

    if not is_supported_model(handle):
        return
    server_dn = get_server_dn(handle, server_id)
    power_budget_dn = server_dn + "/budget"
    stdpowerprof_mo = StandardPowerProfile(parent_mo_or_dn=power_budget_dn)

    stdpowerprof_mo.profile_enabled = "no"
    handle.set_mo(stdpowerprof_mo)
Example #43
0
def server_power_characterization_start(handle, server_id=1):
    """
    Starts a power characterization run.
    From 3.0(1c) onwards, server_power_characterization_enable needs to be
    explicitly done, before invoking this api.

    Args:
        handle (ImcHandle)
        server_id (int): Server Id to be specified for C3260 platforms

    Returns:
        PowerBudget object
    """
    if not is_supported_model(handle):
        return
    power_budget_mo = PowerBudget(parent_mo_or_dn=get_server_dn(handle, server_id))

    power_budget_mo.admin_action = \
        PowerBudgetConsts.ADMIN_ACTION_START_POWER_CHAR
    handle.set_mo(power_budget_mo)
    return power_budget_mo
Example #44
0
def server_standard_power_cap_disable(handle, server_id=1):
    """
    This method disables the standard power profile

    Args:
        handle (ImcHandle)
        server_id (int): Server Id to be specified for C3260 platforms

    Returns:
        None
    """

    if not is_supported_model(handle):
        return
    server_dn = get_server_dn(handle, server_id)
    power_budget_dn = server_dn + "/budget"
    stdpowerprof_mo = StandardPowerProfile(
        parent_mo_or_dn=power_budget_dn)

    stdpowerprof_mo.profile_enabled = "no"
    handle.set_mo(stdpowerprof_mo)
Example #45
0
def server_power_characterization_start(handle, server_id=1):
    """
    Starts a power characterization run.
    From 3.0(1c) onwards, server_power_characterization_enable needs to be
    explicitly done, before invoking this api.

    Args:
        handle (ImcHandle)
        server_id (int): Server Id to be specified for C3260 platforms

    Returns:
        PowerBudget object
    """
    if not is_supported_model(handle):
        return
    power_budget_mo = PowerBudget(
        parent_mo_or_dn=get_server_dn(handle, server_id))

    power_budget_mo.admin_action = \
        PowerBudgetConsts.ADMIN_ACTION_START_POWER_CHAR
    handle.set_mo(power_budget_mo)
    return power_budget_mo
Example #46
0
def firmware_exists(handle,
                    version,
                    server_id=1,
                    force=False,
                    backup_fw=False):
    if force:
        return False, None

    server_dn = get_server_dn(handle, server_id)
    dn = server_dn + "/mgmt/fw-system"
    if backup_fw:
        dn = server_dn + "/mgmt/fw-updatable"
    mo = handle.query_dn(dn)
    if mo is None:
        return False, None

    mo_ver = mo.version.strip().lower()
    ver = version.strip().lower()
    if mo.version.strip().lower() != version.strip().lower():
        log.debug("%s | %s " % (mo_ver, ver))
        return False, None
    return True, mo
Example #47
0
def server_power_budget_get(handle, server_id=1):
    """
    This api gets the min and max power limits for the platform, cpu and memory
        for this specific server

    Args:
        handle (ImcHandle)
        server_id (int): Server Id to be specified for C3260 platforms

    Returns:
        PowerBudget object
    """

    if not is_supported_model(handle):
        return

    power_budget_mo = handle.query_children(in_dn=get_server_dn(handle, server_id),
                                            class_id="PowerBudget")
    if not power_budget_mo:
        raise ImcOperationError("Get Power Budget",
                                "Invalid Server Id configured")

    return power_budget_mo[0]
Example #48
0
def server_power_down_gracefully(handle,
                                 timeout=120,
                                 interval=5,
                                 server_id=1,
                                 **kwargs):
    """
    This method will power down the rack server gracefully

    Args:
        handle(ImcHandle)
        server_id (int): Server Id to be specified for C3260 platforms
        kwargs: key=value paired arguments

    Returns:
        ComputeRackUnit object for non-C3260 platform
        ComputeServerNode object for C3260 platform

    Example:
        server_power_down_gracefully(handle)
        server_power_down_gracefully(handle, timeout=120, interval=10)
        server_power_down_gracefully(handle, server_id=2, timeout=60)
    """

    server_dn = get_server_dn(handle, server_id)
    # Gracefully power off only if not already powered down
    if server_power_state_get(handle, server_id) != "off":
        _set_power_state(handle, server_dn, "graceful-down")

    # Poll until the server is powered up
    _wait_for_power_state(handle,
                          "off",
                          timeout=timeout,
                          interval=interval,
                          server_id=server_id)

    return handle.query_dn(server_dn)
Example #49
0
def server_power_down(handle, timeout=60, interval=5, server_id=1, **kwargs):
    """
    This method will power down the rack server, even if tasks are still
    running on it.  Then polls the server every $interval until either $timeout
    or it comes online.

    Args:
        handle(ImcHandle)
        timeout(int)
        interval(int)
        server_id (int): Server Id to be specified for C3260 platforms
        kwargs: key=value paired arguments

    Returns:
        ComputeRackUnit object for non-C3260 platform
        ComputeServerNode object for C3260 platform

    Example:
        server_power_down(handle)
        server_power_down(handle, timeout=120, interval=10)
        server_power_down(handle, server_id=2, timeout=60)
    """

    server_dn = get_server_dn(handle, server_id)
    # Turn power off only if not already powered down
    if server_power_state_get(handle, server_id) != "off":
        _set_power_state(handle, server_dn, "down")

    # Poll until the server is powered up
    _wait_for_power_state(handle,
                          "off",
                          timeout=timeout,
                          interval=interval,
                          server_id=server_id)

    return handle.query_dn(server_dn)
Example #50
0
def server_power_up(handle, timeout=60, interval=5, server_id=1, **kwargs):
    """
    This method will send the server the power up signal, and then polls
    the server every $interval until either $timeout or it comes online.

    Args:
        handle(ImcHandle)
        timeout (int)
        interval (int)
        server_id (int): Server Id to be specified for C3260 platforms
        kwargs: key=value paired arguments

    Returns:
        ComputeRackUnit object for non-C3260 platform
        ComputeServerNode object for C3260 platform

    Example:
        server_power_up(handle)
        server_power_up(handle, timeout=120, interval=10)
        server_power_up(handle, server_id=2, timeout=60)
    """

    server_dn = get_server_dn(handle, server_id)
    # Turn power on only if not already powered up
    if server_power_state_get(handle, server_id) != "on":
        _set_power_state(handle, server_dn, "up")

    # Poll until the server is powered up
    _wait_for_power_state(handle,
                          "on",
                          timeout=timeout,
                          interval=interval,
                          server_id=server_id)

    # Return object with current state
    return handle.query_dn(server_dn)
Example #51
0
def server_power_budget_get(handle, server_id=1):
    """
    This api gets the min and max power limits for the platform, cpu and memory
        for this specific server

    Args:
        handle (ImcHandle)
        server_id (int): Server Id to be specified for C3260 platforms

    Returns:
        PowerBudget object
    """

    if not is_supported_model(handle):
        return

    power_budget_mo = handle.query_children(in_dn=get_server_dn(
        handle, server_id),
                                            class_id="PowerBudget")
    if not power_budget_mo:
        raise ImcOperationError("Get Power Budget",
                                "Invalid Server Id configured")

    return power_budget_mo[0]
Example #52
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
Example #53
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
Example #54
0
File: bios.py Project: vvb/imcsdk
def _get_bios_dn(handle, server_id=1):
    server_dn = imccoreutils.get_server_dn(handle, server_id)
    return (server_dn + '/bios')
Example #55
0
def boot_order_precision_set(handle,
                             reboot_on_update="no",
                             reapply="no",
                             configured_boot_mode="Legacy",
                             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"}]
    """

    # 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: x["order"])

    server_dn = imccoreutils.get_server_dn(handle, server_id)

    lsbootdevprecision_mo = LsbootDevPrecision(parent_mo_or_dn=server_dn)
    lsbootdevprecision_mo.reboot_on_update = reboot_on_update
    lsbootdevprecision_mo.reapply = reapply
    lsbootdevprecision_mo.configured_boot_mode = configured_boot_mode

    handle.set_mo(lsbootdevprecision_mo)

    boot_order_child_mos = handle.query_children(
        in_dn=lsbootdevprecision_mo.dn)
    for mo in boot_order_child_mos:
        handle.remove_mo(mo)

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

    lsbootdevprecision_mo = handle.query_classid("LsbootDevPrecision")
    return lsbootdevprecision_mo
Example #56
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
Example #57
0
def _get_bios_dn(handle, server_id=1):
    server_dn = imccoreutils.get_server_dn(handle, server_id)
    return (server_dn + '/bios')
Example #58
0
File: bios.py Project: vvb/imcsdk
def boot_order_precision_set(
        handle,
        reboot_on_update=False,
        reapply=False,
        configured_boot_mode="Legacy",
        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 (bool): True, False
        reapply(bool): True, False
        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=False,
            reapply=False,
            configured_boot_mode="Uefi",
            boot_devices = [{"order":'1', "device-type":"vmedia", "name":"vmedia"},
                            {"order":'2', "device-type":"hdd", "name":"hdd"}]
    """

    # 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: x["order"])

    server_dn = imccoreutils.get_server_dn(handle, server_id)
    lsbootdevprecision_mo = LsbootDevPrecision(parent_mo_or_dn=server_dn)

    lsbootdevprecision_mo.reboot_on_update = "no"
    if reboot_on_update:
        lsbootdevprecision_mo.reboot_on_update = "yes"

    lsbootdevprecision_mo.reapply = "no"
    if reapply:
        lsbootdevprecision_mo.reapply = "yes"

    lsbootdevprecision_mo.configured_boot_mode = configured_boot_mode

    handle.set_mo(lsbootdevprecision_mo)

    boot_order_child_mos = handle.query_children(
        in_dn=lsbootdevprecision_mo.dn)
    for mo in boot_order_child_mos:
        handle.remove_mo(mo)

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

    lsbootdevprecision_mo = handle.query_classid("LsbootDevPrecision")
    return lsbootdevprecision_mo
Example #59
0
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
Example #60
0
def _get_controller_dn(handle, controller_type, controller_slot, server_id=1):
    server_dn = imccoreutils.get_server_dn(handle, server_id)
    return (server_dn + "/board/storage-" + controller_type + "-" + controller_slot)