Beispiel #1
0
def ipmi_enable(handle, priv=None, key=None, server_id=1):
    """
    Enable IPMI over LAN.

    Args:
        handle (ImcHandle)
        priv (string): Optional privilege level: 'admin', 'user', 'read-only'
        key (string): Optional encryption key as hexadecimal string
        server_id (int): Server Id to be specified for C3260 platforms

    Returns:
        CommIpmiLan object

    Raises:
        ValueError if privilege or key are invalid

    Example:
        if ipmi_enable(handle):
            print("IPMI Enabled")
    """

    from imcsdk.imcexception import ImcOperationError
    # Enable policy if only user mode is ipmi
    mos = handle.query_classid(class_id="AaaUserPolicy")
    userPolicy = mos[0]

    if userPolicy.user_mode != None and userPolicy.user_mode == 'non-ipmi':
        raise ImcOperationError("Enable IPMI over LAN",
                                "IPMI user mode is disabled on the endpoint.")

    # Verify key is a hex number
    try:
        if key:
            hex(int(key, 16))[2:]
    except ValueError:
        raise ValueError('{0}: ERROR: Encryption key is not hex number: ' +
                         '"{1}"'.format(handle.ip, key))

    # Create enabled IPMI object
    mo = CommIpmiLan(parent_mo_or_dn=_get_comm_mo_dn(handle, server_id))
    mo.admin_state = "enabled"
    mo.priv = priv
    mo.key = key

    # Configure IPMI object on CIMC
    handle.set_mo(mo)
    return mo
Beispiel #2
0
def ipmi_disable(handle, server_id=1):
    """
    Disable IPMI over LAN.
    Args:
        handle (ImcHandle)
        server_id (int): Server Id to be specified for C3260 platforms

    Returns:
        CommIpmiLan object
    """

    # Create disabled IPMI object
    mo = CommIpmiLan(parent_mo_or_dn=_get_comm_mo_dn(handle, server_id))
    mo.admin_state = "disabled"

    # Configure IPMI object on CIMC
    handle.set_mo(mo)
    return mo
Beispiel #3
0
def ipmi_disable(handle, server_id=1):
    """
    Disable IPMI over LAN.
    Args:
        handle (ImcHandle)
        server_id (int): Server Id to be specified for C3260 platforms

    Returns:
        CommIpmiLan object
    """

    # Create disabled IPMI object
    ipmi_mo = CommIpmiLan(parent_mo_or_dn=_get_comm_mo_dn(handle, server_id))
    ipmi_mo.admin_state = "disabled"

    # Configure IPMI object on CIMC
    handle.set_mo(ipmi_mo)
    return handle.query_dn(ipmi_mo.dn)
Beispiel #4
0
def ipmi_enable(handle,
                priv=CommIpmiLanConsts.PRIV_ADMIN,
                key='0' * 40,
                server_id=1):
    """
    Enable IPMI over LAN.

    Args:
        handle (ImcHandle)
        priv (string): Optional privilege level: 'admin', 'user', 'read-only'
        key (string): Optional encryption key as hexadecimal string
        server_id (int): Server Id to be specified for C3260 platforms

    Returns:
        CommIpmiLan object

    Raises:
        ValueError if privilege or key are invalid

    Example:
        if ipmi_enable(handle):
            print("IPMI Enabled")
    """

    # Verify key is a hex number
    try:
        hex(int(key, 16))[2:]
    except ValueError:
        raise ValueError('{0}: ERROR: Encryption key is not hex number: ' +
                         '"{1}"'.format(handle.ip, key))

    # Create enabled IPMI object
    ipmi_mo = CommIpmiLan(parent_mo_or_dn=_get_comm_mo_dn(handle, server_id))
    ipmi_mo.admin_state = "enabled"
    ipmi_mo.priv = priv
    ipmi_mo.key = key

    # Configure IPMI object on CIMC
    handle.set_mo(ipmi_mo)
    return handle.query_dn(ipmi_mo.dn)
Beispiel #5
0
def ipmi_enable(handle, priv=None, key=None, server_id=1):
    """
    Enable IPMI over LAN.

    Args:
        handle (ImcHandle)
        priv (string): Optional privilege level: 'admin', 'user', 'read-only'
        key (string): Optional encryption key as hexadecimal string
        server_id (int): Server Id to be specified for C3260 platforms

    Returns:
        CommIpmiLan object

    Raises:
        ValueError if privilege or key are invalid

    Example:
        if ipmi_enable(handle):
            print "IPMI Enabled"
    """

    # Verify key is a hex number
    try:
        if key:
            hex(int(key, 16))[2:]
    except ValueError:
        raise ValueError('{0}: ERROR: Encryption key is not hex number: ' +
                         '"{1}"'.format(handle.ip, key))

    # Create enabled IPMI object
    mo = CommIpmiLan(parent_mo_or_dn=_get_comm_mo_dn(handle, server_id))
    mo.admin_state = "enabled"
    mo.priv = priv
    mo.key = key

    # Configure IPMI object on CIMC
    handle.set_mo(mo)
    return mo