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
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)
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)
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
def ldap_settings_exist(handle, **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_settings_exist( 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) params = _get_ldap_params(kwargs) if not mo.check_prop_match(**params): return False, None if _is_valid_arg('ldap_servers', kwargs): if not _check_ldap_server_match(mo, kwargs.pop('ldap_servers')): return False, None if not mo.check_prop_match(**kwargs): return False, None return True, mo
def ldap_role_group_exists(handle, **kwargs): """ Checks if the ldap group exists with the specified settings Args: handle (ImcHandle) kwargs: Key-Value paired arguments for future use Returns: (True, AaaLdapRoleGroup) if match found, else (False, None) Examples: ldap_role_group_exists(handle, domain='abcd.pqrs.com', name='abcd', role='user') """ domain = kwargs.get('domain') name = kwargs.get('name') mo = ldap_role_group_get(handle, domain=domain, name=name) if not mo: return False, None if _is_valid_arg('role', kwargs): if mo.role != kwargs.get('role'): return False, None return True, mo
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, None return True, mo
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
def ldap_role_group_exists(handle, **kwargs): """ Checks if the ldap group exists with the specified settings Args: handle (ImcHandle) kwargs: Key-Value paired arguments for future use Returns: (True, AaaLdapRoleGroup) if match found, else (False, None) Examples: ldap_role_group_exists(handle, domain='abcd.pqrs.com', name='abcd', role='user') """ domain = kwargs.get('domain') name = kwargs.get('name') mo = ldap_role_group_get(handle, domain=domain, name=name) if not mo: return False, None if _is_valid_arg('role', kwargs): if mo.role != kwargs.get('role'): return False, None return True, mo
def ldap_settings_exist(handle, **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_settings_exist( 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) params = _get_ldap_params(kwargs) if not mo.check_prop_match(**params): return False, None if _is_valid_arg('ldap_servers', kwargs): if not _check_ldap_server_match(mo, kwargs.pop('ldap_servers')): return False, None if not mo.check_prop_match(**kwargs): return False, None return True, mo
def boot_order_precision_exists(handle, **kwargs): from imcsdk.imccoreutils import _set_server_dn from imcsdk.apis.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): in_boot_order = sorted(kwargs["boot_devices"], key=lambda x: 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
def _get_ldap_params(kwargs): params = {} if _is_valid_arg('enabled', kwargs): params['admin_state'] = ('disabled', 'enabled')[kwargs.pop('enabled')] if _is_valid_arg('encryption', kwargs): params['encryption'] = ('disabled', 'enabled')[kwargs.pop('encryption')] if _is_valid_arg('group_auth', kwargs): params['group_auth'] = ('disabled', 'enabled')[kwargs.pop('group_auth')] if _is_valid_arg('locate_directory_using_dns', kwargs): params['locate_directory_using_dns'] = ( 'no', 'yes')[kwargs.pop('locate_directory_using_dns')] if _is_valid_arg('timeout', kwargs): params['timeout'] = str(kwargs.pop('timeout')) if _is_valid_arg('group_nested_search', kwargs): params['group_nested_search'] = str(kwargs.pop('group_nested_search')) # pop the password property if it exists if _is_valid_arg('password', kwargs): kwargs.pop('password') return params
def _get_ldap_params(kwargs): params = {} if _is_valid_arg('enabled', kwargs): params['admin_state'] = ('disabled', 'enabled')[kwargs.pop('enabled')] if _is_valid_arg('encryption', kwargs): params['encryption'] = ('disabled', 'enabled')[kwargs.pop('encryption')] if _is_valid_arg('group_auth', kwargs): params['group_auth'] = ('disabled', 'enabled')[kwargs.pop('group_auth')] if _is_valid_arg('locate_directory_using_dns', kwargs): params['locate_directory_using_dns'] = ('no', 'yes')[kwargs.pop('locate_directory_using_dns')] if _is_valid_arg('timeout', kwargs): params['timeout'] = str(kwargs.pop('timeout')) if _is_valid_arg('group_nested_search', kwargs): params['group_nested_search'] = str(kwargs.pop('group_nested_search')) # pop the password property if it exists if _is_valid_arg('password', kwargs): kwargs.pop('password') return params
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 """ ntp_mo = _get_mo(handle, dn=NTP_DN) if _is_valid_arg("ntp_enable", kwargs): if ntp_mo.ntp_enable != kwargs.get("ntp_enable"): return False, None if _is_valid_arg("ntp_servers", kwargs): mo = CommNtpProvider(parent_mo_or_dn=COMM_EXT_DN) _set_ntp_servers(mo, kwargs.get("ntp_servers")) if not _check_ntp_server_match(ntp_mo, mo): return False, None return True, ntp_mo
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 """ ntp_mo = _get_mo(handle, dn=NTP_DN) if _is_valid_arg("ntp_enable", kwargs): if ntp_mo.ntp_enable != kwargs.get("ntp_enable"): return False, None if _is_valid_arg("ntp_servers", kwargs): mo = CommNtpProvider(parent_mo_or_dn=COMM_EXT_DN) _set_ntp_servers(mo, kwargs.get("ntp_servers")) if not _check_ntp_server_match(ntp_mo, mo): return False, None return True, ntp_mo
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
def boot_order_precision_exists(handle, **kwargs): from imcsdk.imccoreutils import _set_server_dn from imcsdk.apis.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(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
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
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
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
def boot_order_precision_exists(handle, **kwargs): from imcsdk.imccoreutils import _set_server_dn from imcsdk.apis.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] reboot_on_update = kwargs.get("reboot_on_update") if isinstance(reboot_on_update, bool): reboot_on_update = ("no", "yes")[reboot_on_update] args = {"reboot_on_update": reboot_on_update, "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): in_boot_order = sorted( kwargs["boot_devices"], key=lambda x: 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)): if not (in_boot_order[i]["order"] == configured_boot_order[i]["order"] and in_boot_order[i]["device-type"] == configured_boot_order[i]["device-type"] and in_boot_order[i]["name"] == configured_boot_order[i]["name"]): return False, "dictionaries do not match" return True, None
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