Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def commit(self, confirmed=False, timeout=None, persist=None, remove_ns=False):
try:
resp = self.m.commit(confirmed=confirmed, timeout=timeout, persist=persist)
if remove_ns:
response = remove_namespaces(resp)
else:
response = resp.data_xml if hasattr(resp, 'data_xml') else resp.xml
return response
except RPCError as exc:
raise Exception(to_xml(exc.xml))
def get(self, filter=None, remove_ns=False):
if isinstance(filter, list):
filter = tuple(filter)
try:
resp = self.m.get(filter=filter)
if remove_ns:
response = remove_namespaces(resp)
else:
response = resp.data_xml if hasattr(resp, 'data_xml') else resp.xml
return response
except RPCError as exc:
raise Exception(to_xml(exc.xml))
def rpc(self, name):
"""
RPC to be execute on remote device
:param name: Name of rpc in string format
:return: Received rpc response from remote host
"""
try:
obj = to_ele(name)
resp = self.m.rpc(obj)
return resp.data_xml if hasattr(resp, 'data_xml') else resp.xml
except RPCError as exc:
msg = exc.xml
raise Exception(to_xml(msg))
def set_nc_config(module, xml_str):
""" set_config """
conn = get_nc_connection(module)
try:
out = conn.edit_config(target='running', config=xml_str, default_operation='merge',
error_option='rollback-on-error')
finally:
# conn.unlock(target = 'candidate')
pass
return to_string(to_xml(out))
def _find_capable_switch_xml(self, tree):
return ncclient.xml_.to_xml(self._find_capable_switch(tree))
def _find_capable_switch_xml(self, tree):
return ncclient.xml_.to_xml(self._find_capable_switch(tree))
def execute_nc_action(module, xml_str):
""" huawei execute-action """
conn = get_nc_connection(module)
response = conn.execute_action(xml_str)
return to_string(to_xml(response))
def get(self, *args, **kwargs):
try:
if_rpc_reply = kwargs.pop('if_rpc_reply', False)
if if_rpc_reply:
return self.m.get(*args, **kwargs).xml
return self.m.get(*args, **kwargs).data_xml
except RPCError as exc:
raise Exception(to_xml(exc.xml))