Skip to content
Open
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
46 changes: 40 additions & 6 deletions imcsdk/imchandle.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ class ImcHandle(ImcSession):
port (int or None): The port number to be used during connection
secure (bool or None): True for secure connection, otherwise False
proxy (str): The proxy object to be used to connect
auto_refresh (bool): if set to True, it'll refresh the cookie continuously
auto_refresh (bool): if set to True, it'll refresh the cookie
continuously
force (bool): if set to True it'll reconnect even if cookie exists
and is valid for the respective connection.
timeout (int): timeout value in secs
Expand All @@ -59,6 +60,26 @@ def __init__(self, ip, username, password, port=None, secure=None,
auto_refresh=auto_refresh, force=force,
timeout=timeout)
self.__to_commit = {}
self.__response_timeout = 120

def __set_internal_timeout(self, timeout):
if timeout:
return timeout
return self.__response_timeout

def set_response_timeout(self, timeout):
"""
Modifes the response timeout
"""

self.__response_timeout = timeout

def reset_response_timeout(self):
"""
Resets response timeout
"""

self.__response_timeout = 120

def __enter__(self):
"""
Expand Down Expand Up @@ -116,7 +137,9 @@ def login(self, auto_refresh=None, force=None, timeout=None):
where handle is ImcHandle()
"""

return self._login(auto_refresh=auto_refresh, force=force, timeout=timeout)
timeout = self.__set_internal_timeout(timeout)
return self._login(auto_refresh=auto_refresh, force=force,
timeout=timeout)

def logout(self, timeout=None):
"""
Expand All @@ -135,6 +158,7 @@ def logout(self, timeout=None):
where handle is ImcHandle()
"""

timeout = self.__set_internal_timeout(timeout)
return self._logout(timeout=timeout)

def process_xml_elem(self, elem, timeout=None):
Expand All @@ -156,6 +180,7 @@ def process_xml_elem(self, elem, timeout=None):
objs = handle.process_xml_elem(elem)
"""

timeout = self.__set_internal_timeout(timeout)
response = self.post_elem(elem, timeout=timeout)
if response.error_code != 0:
raise ImcException(response.error_code, response.error_descr)
Expand Down Expand Up @@ -183,6 +208,7 @@ def get_auth_token(self, timeout=None):

from .imcmethodfactory import aaa_get_compute_auth_tokens

timeout = self.__set_internal_timeout(timeout)
auth_token = None
mo = self.query_classid(class_id=NamingId.COMPUTE_BOARD)
if not mo:
Expand Down Expand Up @@ -231,6 +257,7 @@ def query_dn(self, dn, hierarchy=False, need_response=False, timeout=None):
if not dn:
raise ValueError("Provide dn.")

timeout = self.__set_internal_timeout(timeout)
elem = config_resolve_dn(cookie=self.cookie, dn=dn,
in_hierarchical=hierarchy)
response = self.post_elem(elem, timeout=timeout)
Expand Down Expand Up @@ -287,6 +314,7 @@ def query_classid(self, class_id=None, hierarchy=False,
if not class_id:
raise ValueError("Provide Parameter class_id")

timeout = self.__set_internal_timeout(timeout)
meta_class_id = imccoreutils.find_class_id_in_mo_meta_ignore_case(
class_id)
if not meta_class_id:
Expand Down Expand Up @@ -339,6 +367,7 @@ def query_children(self, in_mo=None, in_dn=None, class_id=None,

from .imcmethodfactory import config_resolve_children

timeout = self.__set_internal_timeout(timeout)
if not in_mo and not in_dn:
raise ValueError('[Error]: GetChild: Provide in_mo or in_dn.')

Expand All @@ -352,7 +381,8 @@ def query_children(self, in_mo=None, in_dn=None, class_id=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
# 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)
Expand All @@ -368,9 +398,8 @@ def query_children(self, in_mo=None, in_dn=None, class_id=None,
if response.error_code != 0:
raise ImcException(response.error_code, response.error_descr)

out_mo_list = imccoreutils.extract_molist_from_method_response(response,
hierarchy
)
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,
Expand All @@ -396,6 +425,7 @@ def add_mo(self, mo, modify_present=True, timeout=None):

from .imccoreutils import validate_mo_version

timeout = self.__set_internal_timeout(timeout)
validate_mo_version(self, mo)

if modify_present in imcgenutils.AFFIRMATIVE_LIST:
Expand Down Expand Up @@ -427,6 +457,7 @@ def set_mo(self, mo, timeout=None):

from .imccoreutils import validate_mo_version

timeout = self.__set_internal_timeout(timeout)
validate_mo_version(self, mo)

mo.status = "modified"
Expand All @@ -450,6 +481,7 @@ def remove_mo(self, mo, timeout=None):

from .imccoreutils import validate_mo_version

timeout = self.__set_internal_timeout(timeout)
validate_mo_version(self, mo)

mo.status = "deleted"
Expand Down Expand Up @@ -478,6 +510,8 @@ def _commit(self, timeout=None):

from .imcbasetype import ConfigMap
from .imcmethodfactory import config_conf_mo

timeout = self.__set_internal_timeout(timeout)
mo_dict = self.__to_commit
if not mo_dict:
log.debug("Commit Buffer is Empty")
Expand Down