Skip to content

Commit

Permalink
Merge pull request CiscoUcs#100 from waghswapnil/query_children
Browse files Browse the repository at this point in the history
add support for query_children with hierarchy and class_id as filter
  • Loading branch information
waghswapnil authored Feb 1, 2017
2 parents 34639df + 386a159 commit e4a9abd
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
8 changes: 8 additions & 0 deletions imcsdk/imccoreutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,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")

0 comments on commit e4a9abd

Please sign in to comment.