Example #1
0
def ip_filtering_exists(handle, **kwargs):
    """
    Checks if IP filtering settings match according to the parameters specified.

    Args:
        Args:
        handle (ImcHandle)
        kwargs: Key-Value paired arguments relevant to IpFiltering object

    Returns:
        (True, IpFiltering object) if exists, else (False, None)

    Examples:
        ip_filtering_exists(handle, enable='yes',
                            filters=[{"id": 1, "filter": "1.1.1.0-255.255.255.255"},
                                     {"id": 2, "filter": "2.2.2.2"}])
    """
    ip_mo = IpFiltering(parent_mo_or_dn=_get_mgmt_if_dn(handle))
    ip_mo = handle.query_dn(ip_mo.dn)

    if _is_valid_arg('enable', kwargs):
        if ip_mo.enable.lower() != kwargs.get('enable').lower():
            return False, None

    if _is_valid_arg('filters', kwargs):
        mo = IpFiltering(parent_mo_or_dn=_get_mgmt_if_dn(handle))
        _set_ip_filters(mo, kwargs.get('filters'))
        if not _check_ip_filter_match(ip_mo, mo):
            return False, None

    return True, ip_mo
Example #2
0
def locator_led_off(handle, **kwargs):
    """
    This method will turn off the locator led on the server or on the chassis

    Args:
        handle(ImcHandle)
        kwargs: key=value paired arguments

    Returns:
        None

    Example:
        locator_led_off(handle) for non-C3260 platforms.
            Turns off locator led on the server.
        locator_led_off(handle, server_id=1) for C3260 platforms.
            Turns off locator led on the specified server.
        locator_led_off(handle, chassis_id=1) for C3260 platforms.
            Turns off locator led on the chassis.
    """

    if _is_valid_arg("chassis_id", kwargs):
        _set_chassis_locator_led_state(handle, False, kwargs)

    if _is_valid_arg("server_id", kwargs) or \
            handle.platform == IMC_PLATFORM.TYPE_CLASSIC:
        _set_server_locator_led_state(handle, False, kwargs)
Example #3
0
def boot_order_precision_exists(handle, **kwargs):
    from imcsdk.imccoreutils import _set_server_dn
    from imcsdk.apis.v2.utils import _is_valid_arg

    server_dn = _set_server_dn(handle, kwargs)
    mos = handle.query_children(in_dn=server_dn, class_id="LsbootDevPrecision")
    if len(mos) == 0:
        return False, "no Mos found"

    mo = mos[0]

    args = {"configured_boot_mode": kwargs.get("configured_boot_mode")}
    if not mo.check_prop_match(**args):
        return False, "parent MO property values do not match"

    if _is_valid_arg("boot_devices", kwargs):
        boot_devices = kwargs["boot_devices"]
        boot_devices = sanitize_input_from_intersight(handle, boot_devices)

        in_boot_order = sorted(boot_devices, key=lambda x: int(x["order"]))
        configured_boot_order = boot_precision_configured_get(
            handle, kwargs.get("server_id"))

        if len(in_boot_order) != len(configured_boot_order):
            return False, "length mismatch"
        for i in range(0, len(in_boot_order)):
            bt_ord = in_boot_order[i]
            cfg_bt_ord = configured_boot_order[i]
            if not (bt_ord["order"] == cfg_bt_ord["order"]
                    and bt_ord["device-type"] == cfg_bt_ord["device-type"]
                    and bt_ord["name"] == cfg_bt_ord["name"]):
                return False, "dictionaries do not match"
    return True, None
Example #4
0
def ntp_setting_exists(handle, **kwargs):
    """
    Check if the specified NTP settings are already applied
    Args:
        handle (ImcHandle)
        kwargs: key-value paired arguments

    Returns:
        (True, CommNtpProvider) if settings match, (False, None) otherwise
    """

    mo = _get_mo(handle, dn=NTP_DN)
    if mo is None:
        return False, None

    kwargs['ntp_enable'] = "yes"

    if _is_valid_arg("ntp_servers", kwargs):
        args = _get_ntp_servers(kwargs['ntp_servers'])
        del kwargs['ntp_servers']
        kwargs.update(args)

    if not mo.check_prop_match(**kwargs):
        return False, mo

    return True, mo
Example #5
0
def ldap_exists(handle, change_password=False, **kwargs):
    """
    Checks if the specified LDAP settings are already applied

    Args:
        handle (ImcHandle)
        kwargs: Key-Value paired arguments

    Returns:
        (True, AaaLdap) if settings match, else (False, None)

    Examples:
        match, mo = ldap_exists(
                    handle, enabled=True,
                    basedn='DC=LAB,DC=cisco,DC=com',
                    domain='LAB.cisco.com',
                    timeout=20, group_auth=True,
                    bind_dn='CN=administrator,CN=Users,DC=LAB,DC=cisco,DC=com',
                    password='******', ldap_servers=ldap_servers)
    """

    mo = _get_mo(handle, dn=LDAP_DN)
    if mo is None:
        return False, None

    if _is_valid_arg('ldap_servers', kwargs):
        if not _check_ldap_server_match(mo, kwargs.pop('ldap_servers')):
            return False, mo

    if 'password' in kwargs and not change_password:
        kwargs.pop('password', None)

    if 'dns_search_domain' in kwargs and kwargs['dns_search_domain'] == "":
        kwargs.pop('dns_search_domain', None)

    if 'dns_search_forest' in kwargs and kwargs['dns_search_forest'] == "":
        kwargs.pop('dns_search_forest', None)

    kwargs['admin_state'] = 'enabled'
    if not mo.check_prop_match(**kwargs):
        return False, mo

    return True, mo
Example #6
0
def ip_filtering_exists(handle, **kwargs):
    """
    Checks if the ip filtering already exists.
    Args:
        handle (ImcHandle)
        kwargs: key-value paired arguments

    Returns:
        True/False, MO/None
    """
    dn = _get_mgmtif_mo_dn(handle) + "/ip-filter"
    mo = handle.query_dn(dn)
    if mo is None:
        return False, None

    kwargs['enable'] = 'yes'

    if _is_valid_arg("ip_filters", kwargs):
        args = _get_ip_filters(kwargs['ip_filters'])
        del kwargs['ip_filters']
        kwargs.update(args)

    return mo.check_prop_match(**kwargs), mo
Example #7
0
def bios_profile_exists(handle, name, server_id=1, **kwargs):
    """
    Checks if the bios profile with the specified params exists

    Args:
        handle (ImcHandle)
        name (str): Name of the bios profile.
                    Corresponds to the name field in the json file.
        server_id (int): Id of the server to perform
                         this operation on C3260 platforms.
        kwargs: Key-Value paired arguments relevant to BiosProfile object

    Returns:
        (True, BiosProfile) if the settings match, else (False, None)

    Examples:
        match, mo = bios_profile_exists(handle, name='simple',
                                        enabled=True)
    """

    mo = _get_bios_profile_mo(handle, name=name, server_id=server_id)
    if mo is None:
        return False, None

    params = {}

    if _is_valid_arg('enabled', kwargs):
        params['enabled'] = ('No', 'Yes')[kwargs.pop('enabled')]

    if not mo.check_prop_match(**params):
        return False, None

    if not mo.check_prop_match(**kwargs):
        return False, None

    return True, mo