|
|
@ -42,15 +42,6 @@ except ImportError:
|
|
|
|
from xml.etree.ElementTree import Element, SubElement, tostring, fromstring
|
|
|
|
from xml.etree.ElementTree import Element, SubElement, tostring, fromstring
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def ensure_connected(func):
|
|
|
|
|
|
|
|
@wraps(func)
|
|
|
|
|
|
|
|
def wrapped(self, *args, **kwargs):
|
|
|
|
|
|
|
|
if not self._connection._connected:
|
|
|
|
|
|
|
|
self._connection._connect()
|
|
|
|
|
|
|
|
return func(self, *args, **kwargs)
|
|
|
|
|
|
|
|
return wrapped
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def ensure_ncclient(func):
|
|
|
|
def ensure_ncclient(func):
|
|
|
|
@wraps(func)
|
|
|
|
@wraps(func)
|
|
|
|
def wrapped(self, *args, **kwargs):
|
|
|
|
def wrapped(self, *args, **kwargs):
|
|
|
@ -118,10 +109,8 @@ class NetconfBase(AnsiblePlugin):
|
|
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
@property
|
|
|
|
def m(self):
|
|
|
|
def m(self):
|
|
|
|
return self._connection._manager
|
|
|
|
return self._connection.manager
|
|
|
|
|
|
|
|
|
|
|
|
@ensure_ncclient
|
|
|
|
|
|
|
|
@ensure_connected
|
|
|
|
|
|
|
|
def rpc(self, name):
|
|
|
|
def rpc(self, name):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
RPC to be execute on remote device
|
|
|
|
RPC to be execute on remote device
|
|
|
@ -136,7 +125,6 @@ class NetconfBase(AnsiblePlugin):
|
|
|
|
msg = exc.xml
|
|
|
|
msg = exc.xml
|
|
|
|
raise Exception(to_xml(msg))
|
|
|
|
raise Exception(to_xml(msg))
|
|
|
|
|
|
|
|
|
|
|
|
@ensure_connected
|
|
|
|
|
|
|
|
def get_config(self, source=None, filter=None):
|
|
|
|
def get_config(self, source=None, filter=None):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
Retrieve all or part of a specified configuration
|
|
|
|
Retrieve all or part of a specified configuration
|
|
|
@ -153,7 +141,6 @@ class NetconfBase(AnsiblePlugin):
|
|
|
|
resp = self.m.get_config(source=source, filter=filter)
|
|
|
|
resp = self.m.get_config(source=source, filter=filter)
|
|
|
|
return resp.data_xml if hasattr(resp, 'data_xml') else resp.xml
|
|
|
|
return resp.data_xml if hasattr(resp, 'data_xml') else resp.xml
|
|
|
|
|
|
|
|
|
|
|
|
@ensure_connected
|
|
|
|
|
|
|
|
def get(self, filter=None, with_defaults=None):
|
|
|
|
def get(self, filter=None, with_defaults=None):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
Retrieve device configuration and state information.
|
|
|
|
Retrieve device configuration and state information.
|
|
|
@ -169,7 +156,6 @@ class NetconfBase(AnsiblePlugin):
|
|
|
|
response = resp.data_xml if hasattr(resp, 'data_xml') else resp.xml
|
|
|
|
response = resp.data_xml if hasattr(resp, 'data_xml') else resp.xml
|
|
|
|
return response
|
|
|
|
return response
|
|
|
|
|
|
|
|
|
|
|
|
@ensure_connected
|
|
|
|
|
|
|
|
def edit_config(self, config=None, format='xml', target='candidate', default_operation=None, test_option=None, error_option=None):
|
|
|
|
def edit_config(self, config=None, format='xml', target='candidate', default_operation=None, test_option=None, error_option=None):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
Loads all or part of the specified *config* to the *target* configuration datastore.
|
|
|
|
Loads all or part of the specified *config* to the *target* configuration datastore.
|
|
|
@ -189,7 +175,6 @@ class NetconfBase(AnsiblePlugin):
|
|
|
|
error_option=error_option)
|
|
|
|
error_option=error_option)
|
|
|
|
return resp.data_xml if hasattr(resp, 'data_xml') else resp.xml
|
|
|
|
return resp.data_xml if hasattr(resp, 'data_xml') else resp.xml
|
|
|
|
|
|
|
|
|
|
|
|
@ensure_connected
|
|
|
|
|
|
|
|
def validate(self, source='candidate'):
|
|
|
|
def validate(self, source='candidate'):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
Validate the contents of the specified configuration.
|
|
|
|
Validate the contents of the specified configuration.
|
|
|
@ -200,7 +185,6 @@ class NetconfBase(AnsiblePlugin):
|
|
|
|
resp = self.m.validate(source=source)
|
|
|
|
resp = self.m.validate(source=source)
|
|
|
|
return resp.data_xml if hasattr(resp, 'data_xml') else resp.xml
|
|
|
|
return resp.data_xml if hasattr(resp, 'data_xml') else resp.xml
|
|
|
|
|
|
|
|
|
|
|
|
@ensure_connected
|
|
|
|
|
|
|
|
def copy_config(self, source, target):
|
|
|
|
def copy_config(self, source, target):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
Create or replace an entire configuration datastore with the contents of another complete configuration datastore.
|
|
|
|
Create or replace an entire configuration datastore with the contents of another complete configuration datastore.
|
|
|
@ -212,7 +196,6 @@ class NetconfBase(AnsiblePlugin):
|
|
|
|
resp = self.m.copy_config(source, target)
|
|
|
|
resp = self.m.copy_config(source, target)
|
|
|
|
return resp.data_xml if hasattr(resp, 'data_xml') else resp.xml
|
|
|
|
return resp.data_xml if hasattr(resp, 'data_xml') else resp.xml
|
|
|
|
|
|
|
|
|
|
|
|
@ensure_connected
|
|
|
|
|
|
|
|
def dispatch(self, rpc_command=None, source=None, filter=None):
|
|
|
|
def dispatch(self, rpc_command=None, source=None, filter=None):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
Execute rpc on the remote device eg. dispatch('clear-arp-table')
|
|
|
|
Execute rpc on the remote device eg. dispatch('clear-arp-table')
|
|
|
@ -240,7 +223,6 @@ class NetconfBase(AnsiblePlugin):
|
|
|
|
|
|
|
|
|
|
|
|
return result
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
|
|
@ensure_connected
|
|
|
|
|
|
|
|
def lock(self, target="candidate"):
|
|
|
|
def lock(self, target="candidate"):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
Allows the client to lock the configuration system of a device.
|
|
|
|
Allows the client to lock the configuration system of a device.
|
|
|
@ -251,7 +233,6 @@ class NetconfBase(AnsiblePlugin):
|
|
|
|
resp = self.m.lock(target=target)
|
|
|
|
resp = self.m.lock(target=target)
|
|
|
|
return resp.data_xml if hasattr(resp, 'data_xml') else resp.xml
|
|
|
|
return resp.data_xml if hasattr(resp, 'data_xml') else resp.xml
|
|
|
|
|
|
|
|
|
|
|
|
@ensure_connected
|
|
|
|
|
|
|
|
def unlock(self, target="candidate"):
|
|
|
|
def unlock(self, target="candidate"):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
Release a configuration lock, previously obtained with the lock operation.
|
|
|
|
Release a configuration lock, previously obtained with the lock operation.
|
|
|
@ -262,7 +243,6 @@ class NetconfBase(AnsiblePlugin):
|
|
|
|
resp = self.m.unlock(target=target)
|
|
|
|
resp = self.m.unlock(target=target)
|
|
|
|
return resp.data_xml if hasattr(resp, 'data_xml') else resp.xml
|
|
|
|
return resp.data_xml if hasattr(resp, 'data_xml') else resp.xml
|
|
|
|
|
|
|
|
|
|
|
|
@ensure_connected
|
|
|
|
|
|
|
|
def discard_changes(self):
|
|
|
|
def discard_changes(self):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
Revert the candidate configuration to the currently running configuration.
|
|
|
|
Revert the candidate configuration to the currently running configuration.
|
|
|
@ -272,7 +252,6 @@ class NetconfBase(AnsiblePlugin):
|
|
|
|
resp = self.m.discard_changes()
|
|
|
|
resp = self.m.discard_changes()
|
|
|
|
return resp.data_xml if hasattr(resp, 'data_xml') else resp.xml
|
|
|
|
return resp.data_xml if hasattr(resp, 'data_xml') else resp.xml
|
|
|
|
|
|
|
|
|
|
|
|
@ensure_connected
|
|
|
|
|
|
|
|
def commit(self, confirmed=False, timeout=None, persist=None):
|
|
|
|
def commit(self, confirmed=False, timeout=None, persist=None):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
Commit the candidate configuration as the device's new current configuration.
|
|
|
|
Commit the candidate configuration as the device's new current configuration.
|
|
|
@ -291,7 +270,6 @@ class NetconfBase(AnsiblePlugin):
|
|
|
|
resp = self.m.commit(confirmed=confirmed, timeout=timeout, persist=persist)
|
|
|
|
resp = self.m.commit(confirmed=confirmed, timeout=timeout, persist=persist)
|
|
|
|
return resp.data_xml if hasattr(resp, 'data_xml') else resp.xml
|
|
|
|
return resp.data_xml if hasattr(resp, 'data_xml') else resp.xml
|
|
|
|
|
|
|
|
|
|
|
|
@ensure_connected
|
|
|
|
|
|
|
|
def get_schema(self, identifier=None, version=None, format=None):
|
|
|
|
def get_schema(self, identifier=None, version=None, format=None):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
Retrieve a named schema, with optional revision and type.
|
|
|
|
Retrieve a named schema, with optional revision and type.
|
|
|
@ -303,7 +281,6 @@ class NetconfBase(AnsiblePlugin):
|
|
|
|
resp = self.m.get_schema(identifier, version=version, format=format)
|
|
|
|
resp = self.m.get_schema(identifier, version=version, format=format)
|
|
|
|
return resp.data_xml if hasattr(resp, 'data_xml') else resp.xml
|
|
|
|
return resp.data_xml if hasattr(resp, 'data_xml') else resp.xml
|
|
|
|
|
|
|
|
|
|
|
|
@ensure_connected
|
|
|
|
|
|
|
|
def delete_config(self, target):
|
|
|
|
def delete_config(self, target):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
delete a configuration datastore
|
|
|
|
delete a configuration datastore
|
|
|
@ -313,7 +290,6 @@ class NetconfBase(AnsiblePlugin):
|
|
|
|
resp = self.m.delete_config(target)
|
|
|
|
resp = self.m.delete_config(target)
|
|
|
|
return resp.data_xml if hasattr(resp, 'data_xml') else resp.xml
|
|
|
|
return resp.data_xml if hasattr(resp, 'data_xml') else resp.xml
|
|
|
|
|
|
|
|
|
|
|
|
@ensure_connected
|
|
|
|
|
|
|
|
def locked(self, target):
|
|
|
|
def locked(self, target):
|
|
|
|
return self.m.locked(target)
|
|
|
|
return self.m.locked(target)
|
|
|
|
|
|
|
|
|
|
|
@ -387,7 +363,7 @@ class NetconfBase(AnsiblePlugin):
|
|
|
|
if operations['supports_startup']:
|
|
|
|
if operations['supports_startup']:
|
|
|
|
operations['lock_datastore'].append('startup')
|
|
|
|
operations['lock_datastore'].append('startup')
|
|
|
|
|
|
|
|
|
|
|
|
operations['supports_lock'] = True if len(operations['lock_datastore']) else False
|
|
|
|
operations['supports_lock'] = bool(operations['lock_datastore'])
|
|
|
|
|
|
|
|
|
|
|
|
return operations
|
|
|
|
return operations
|
|
|
|
|
|
|
|
|
|
|
|