Check if data_xml object in present in NCElement object (#35604)
If ncclient return NCElement object call data_xml() on response else call xml()
This commit is contained in:
parent
7dbcf752c8
commit
9ea5e8b37c
1 changed files with 28 additions and 14 deletions
|
@ -103,9 +103,11 @@ class NetconfBase(with_metaclass(ABCMeta, object)):
|
||||||
:name: Name of rpc in string format"""
|
:name: Name of rpc in string format"""
|
||||||
try:
|
try:
|
||||||
obj = to_ele(to_bytes(name, errors='surrogate_or_strict'))
|
obj = to_ele(to_bytes(name, errors='surrogate_or_strict'))
|
||||||
return self.m.rpc(obj).data_xml
|
resp = self.m.rpc(obj)
|
||||||
|
return resp.data_xml if hasattr(resp, 'data_xml') else resp.xml
|
||||||
except RPCError as exc:
|
except RPCError as exc:
|
||||||
raise Exception(to_xml(exc.xml))
|
msg = exc.data_xml if hasattr(exc, 'data_xml') else exc.xml
|
||||||
|
raise Exception(to_xml(msg))
|
||||||
|
|
||||||
@ensure_connected
|
@ensure_connected
|
||||||
def get_config(self, *args, **kwargs):
|
def get_config(self, *args, **kwargs):
|
||||||
|
@ -113,7 +115,8 @@ class NetconfBase(with_metaclass(ABCMeta, object)):
|
||||||
:source: name of the configuration datastore being queried
|
:source: name of the configuration datastore being queried
|
||||||
:filter: specifies the portion of the configuration to retrieve
|
:filter: specifies the portion of the configuration to retrieve
|
||||||
(by default entire configuration is retrieved)"""
|
(by default entire configuration is retrieved)"""
|
||||||
return self.m.get_config(*args, **kwargs).data_xml
|
resp = self.m.get_config(*args, **kwargs)
|
||||||
|
return resp.data_xml if hasattr(resp, 'data_xml') else resp.xml
|
||||||
|
|
||||||
@ensure_connected
|
@ensure_connected
|
||||||
def get(self, *args, **kwargs):
|
def get(self, *args, **kwargs):
|
||||||
|
@ -121,7 +124,8 @@ class NetconfBase(with_metaclass(ABCMeta, object)):
|
||||||
*filter* specifies the portion of the configuration to retrieve
|
*filter* specifies the portion of the configuration to retrieve
|
||||||
(by default entire configuration is retrieved)
|
(by default entire configuration is retrieved)
|
||||||
"""
|
"""
|
||||||
return self.m.get(*args, **kwargs).data_xml
|
resp = self.m.get(*args, **kwargs)
|
||||||
|
return resp.data_xml if hasattr(resp, 'data_xml') else resp.xml
|
||||||
|
|
||||||
@ensure_connected
|
@ensure_connected
|
||||||
def edit_config(self, *args, **kwargs):
|
def edit_config(self, *args, **kwargs):
|
||||||
|
@ -135,7 +139,8 @@ class NetconfBase(with_metaclass(ABCMeta, object)):
|
||||||
:error_option: if specified must be one of { `"stop-on-error"`, `"continue-on-error"`, `"rollback-on-error"` }
|
:error_option: if specified must be one of { `"stop-on-error"`, `"continue-on-error"`, `"rollback-on-error"` }
|
||||||
The `"rollback-on-error"` *error_option* depends on the `:rollback-on-error` capability.
|
The `"rollback-on-error"` *error_option* depends on the `:rollback-on-error` capability.
|
||||||
"""
|
"""
|
||||||
return self.m.edit_config(*args, **kwargs).xml
|
resp = self.m.edit_config(*args, **kwargs)
|
||||||
|
return resp.data_xml if hasattr(resp, 'data_xml') else resp.xml
|
||||||
|
|
||||||
@ensure_connected
|
@ensure_connected
|
||||||
def validate(self, *args, **kwargs):
|
def validate(self, *args, **kwargs):
|
||||||
|
@ -143,7 +148,8 @@ class NetconfBase(with_metaclass(ABCMeta, object)):
|
||||||
:source: is the name of the configuration datastore being validated or `config`
|
:source: is the name of the configuration datastore being validated or `config`
|
||||||
element containing the configuration subtree to be validated
|
element containing the configuration subtree to be validated
|
||||||
"""
|
"""
|
||||||
return self.m.validate(*args, **kwargs).xml
|
resp = self.m.validate(*args, **kwargs)
|
||||||
|
return resp.data_xml if hasattr(resp, 'data_xml') else resp.xml
|
||||||
|
|
||||||
@ensure_connected
|
@ensure_connected
|
||||||
def copy_config(self, *args, **kwargs):
|
def copy_config(self, *args, **kwargs):
|
||||||
|
@ -152,27 +158,31 @@ class NetconfBase(with_metaclass(ABCMeta, object)):
|
||||||
:source: is the name of the configuration datastore to use as the source of the
|
:source: is the name of the configuration datastore to use as the source of the
|
||||||
copy operation or `config` element containing the configuration subtree to copy
|
copy operation or `config` element containing the configuration subtree to copy
|
||||||
:target: is the name of the configuration datastore to use as the destination of the copy operation"""
|
:target: is the name of the configuration datastore to use as the destination of the copy operation"""
|
||||||
return self.m.copy_config(*args, **kwargs).xml
|
resp = self.m.copy_config(*args, **kwargs)
|
||||||
|
return resp.data_xml if hasattr(resp, 'data_xml') else resp.xml
|
||||||
|
|
||||||
@ensure_connected
|
@ensure_connected
|
||||||
def lock(self, *args, **kwargs):
|
def lock(self, *args, **kwargs):
|
||||||
"""Allows the client to lock the configuration system of a device.
|
"""Allows the client to lock the configuration system of a device.
|
||||||
*target* is the name of the configuration datastore to lock
|
*target* is the name of the configuration datastore to lock
|
||||||
"""
|
"""
|
||||||
return self.m.lock(*args, **kwargs).xml
|
resp = self.m.lock(*args, **kwargs)
|
||||||
|
return resp.data_xml if hasattr(resp, 'data_xml') else resp.xml
|
||||||
|
|
||||||
@ensure_connected
|
@ensure_connected
|
||||||
def unlock(self, *args, **kwargs):
|
def unlock(self, *args, **kwargs):
|
||||||
"""Release a configuration lock, previously obtained with the lock operation.
|
"""Release a configuration lock, previously obtained with the lock operation.
|
||||||
:target: is the name of the configuration datastore to unlock
|
:target: is the name of the configuration datastore to unlock
|
||||||
"""
|
"""
|
||||||
return self.m.unlock(*args, **kwargs).xml
|
resp = self.m.unlock(*args, **kwargs)
|
||||||
|
return resp.data_xml if hasattr(resp, 'data_xml') else resp.xml
|
||||||
|
|
||||||
@ensure_connected
|
@ensure_connected
|
||||||
def discard_changes(self, *args, **kwargs):
|
def discard_changes(self, *args, **kwargs):
|
||||||
"""Revert the candidate configuration to the currently running configuration.
|
"""Revert the candidate configuration to the currently running configuration.
|
||||||
Any uncommitted changes are discarded."""
|
Any uncommitted changes are discarded."""
|
||||||
return self.m.discard_changes(*args, **kwargs).xml
|
resp = self.m.discard_changes(*args, **kwargs)
|
||||||
|
return resp.data_xml if hasattr(resp, 'data_xml') else resp.xml
|
||||||
|
|
||||||
@ensure_connected
|
@ensure_connected
|
||||||
def commit(self, *args, **kwargs):
|
def commit(self, *args, **kwargs):
|
||||||
|
@ -186,23 +196,27 @@ class NetconfBase(with_metaclass(ABCMeta, object)):
|
||||||
:confirmed: whether this is a confirmed commit
|
:confirmed: whether this is a confirmed commit
|
||||||
:timeout: specifies the confirm timeout in seconds
|
:timeout: specifies the confirm timeout in seconds
|
||||||
"""
|
"""
|
||||||
return self.m.commit(*args, **kwargs).xml
|
resp = self.m.commit(*args, **kwargs)
|
||||||
|
return resp.data_xml if hasattr(resp, 'data_xml') else resp.xml
|
||||||
|
|
||||||
@ensure_connected
|
@ensure_connected
|
||||||
def validate(self, *args, **kwargs):
|
def validate(self, *args, **kwargs):
|
||||||
"""Validate the contents of the specified configuration.
|
"""Validate the contents of the specified configuration.
|
||||||
:source: name of configuration data store"""
|
:source: name of configuration data store"""
|
||||||
return self.m.validate(*args, **kwargs).xml
|
resp = self.m.validate(*args, **kwargs)
|
||||||
|
return resp.data_xml if hasattr(resp, 'data_xml') else resp.xml
|
||||||
|
|
||||||
@ensure_connected
|
@ensure_connected
|
||||||
def get_schema(self, *args, **kwargs):
|
def get_schema(self, *args, **kwargs):
|
||||||
"""Retrieves the required schema from the device
|
"""Retrieves the required schema from the device
|
||||||
"""
|
"""
|
||||||
return self.m.get_schema(*args, **kwargs).xml
|
resp = self.m.get_schema(*args, **kwargs)
|
||||||
|
return resp.data_xml if hasattr(resp, 'data_xml') else resp.xml
|
||||||
|
|
||||||
@ensure_connected
|
@ensure_connected
|
||||||
def locked(self, *args, **kwargs):
|
def locked(self, *args, **kwargs):
|
||||||
return self.m.locked(*args, **kwargs)
|
resp = self.m.locked(*args, **kwargs)
|
||||||
|
return resp.data_xml if hasattr(resp, 'data_xml') else resp.xml
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def get_capabilities(self):
|
def get_capabilities(self):
|
||||||
|
|
Loading…
Reference in a new issue