Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for query_children with hierarchy and class_id as filter #100

Merged
merged 2 commits into from
Feb 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions imcsdk/imccoreutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,14 @@ def extract_molist_from_method_response(method_response,
return mo_list


def filter_molist_on_class_id(mo_list, class_id=None):
if not class_id:
return mo_list

out_list = [mo for mo in mo_list if mo._class_id.lower() == class_id.lower()]
return out_list


def write_mo_tree(mo, level=0, depth=None, show_level=[],
print_tree=True, tree_dict={}, dn=None):
"""
Expand Down
15 changes: 11 additions & 4 deletions imcsdk/imchandle.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,13 +322,17 @@ def query_children(self, in_mo=None, in_dn=None, class_id=None,
elif in_dn:
parent_dn = in_dn

if class_id:
meta_class_id = None
# Setting the default class-id to None
# When hierarchy and class-id are passed together to Cisco IMC,
# an empty response is received.
# Hence, passing the class-id only when hierarchy is not set
# When both hierarchy and class-id are set, do local filtering for class-id
if class_id and not hierarchy:
meta_class_id = imccoreutils.find_class_id_in_mo_meta_ignore_case(
class_id)
if not meta_class_id:
meta_class_id = class_id
else:
meta_class_id = class_id

elem = config_resolve_children(cookie=self.cookie,
class_id=meta_class_id,
Expand All @@ -342,7 +346,10 @@ def query_children(self, in_mo=None, in_dn=None, class_id=None,
out_mo_list = imccoreutils.extract_molist_from_method_response(response,
hierarchy
)

if class_id and hierarchy:
out_mo_list = imccoreutils.filter_molist_on_class_id(
out_mo_list,
class_id=class_id)
return out_mo_list

def add_mo(self, mo, modify_present=True, timeout=None):
Expand Down
18 changes: 18 additions & 0 deletions tests/common/test_query_children.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

from nose.tools import assert_equal
from ..connection.info import custom_setup, custom_teardown
from imcsdk.imccoreutils import IMC_PLATFORM

handle = None

Expand All @@ -30,3 +31,20 @@ def test_default():
mos = handle.query_children(in_dn="sys/user-ext", class_id="aaaUser")
for mo in mos:
assert_equal(mo._class_id, "AaaUser")


def test_hierarchy():
mos = handle.query_children(in_dn="sys/svc-ext", hierarchy=True)
assert_equal(len(mos) > 30, True)


def test_hierarchy_with_empty_class_id():
mos = handle.query_children(in_dn="sys/svc-ext", hierarchy=True, class_id="")
assert_equal(len(mos) > 30, True)


def test_hierarchy_with_class_id():
mos = handle.query_children(in_dn="sys/svc-ext", class_id="commSnmpUser",
hierarchy=True)
for mo in mos:
assert_equal(mo._class_id, "CommSnmpUser")