Skip to content
Merged
Show file tree
Hide file tree
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
38 changes: 32 additions & 6 deletions ansible_collections/juniper/device/plugins/connection/pyez.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@
)

# Supported configuration modes
CONFIG_MODE_CHOICES = ['exclusive', 'private']
CONFIG_MODE_CHOICES = ['exclusive', 'private', 'dynamic', 'batch', 'ephemeral']


class Connection(NetworkConnectionBase):
Expand Down Expand Up @@ -590,7 +590,7 @@ def invoke_jsnapy(self, data, action):
(type(responses), str(responses)))
return results

def open_configuration(self, mode, ignore_warn=None):
def open_configuration(self, mode, ignore_warn=None, ephemeral_instance=None):
"""Open candidate configuration database in exclusive or private mode.

Failures:
Expand All @@ -601,6 +601,10 @@ def open_configuration(self, mode, ignore_warn=None):
if self.config is None:
if mode not in CONFIG_MODE_CHOICES:
raise AnsibleError("Invalid configuration mode: %s" % mode)
if mode != 'ephemeral' and ephemeral_instance is not None:
self.fail_json(msg='Ephemeral instance is specified while the mode '
'is not ephemeral. Specify the mode as ephemeral '
'or do not specify the instance.')
if self.dev is None:
self.open()
config = jnpr.junos.utils.config.Config(self.dev, mode=mode)
Expand All @@ -611,6 +615,23 @@ def open_configuration(self, mode, ignore_warn=None):
self.dev.rpc.open_configuration(
private=True,
ignore_warning=ignore_warn)
elif config.mode == 'dynamic':
self.dev.rpc.open_configuration(
dynamic=True,
ignore_warning=ignore_warn)
elif config.mode == 'batch':
self.dev.rpc.open_configuration(
batch=True,
ignore_warning=ignore_warn)
elif config.mode == 'ephemeral':
if ephemeral_instance is None:
self.dev.rpc.open_configuration(
ephemeral=True,
ignore_warning=ignore_warn)
else:
self.dev.rpc.open_configuration(
ephemeral_instance = ephemeral_instance,
ignore_warning=ignore_warn)
except (pyez_exception.ConnectError,
pyez_exception.RpcError) as ex:
raise AnsibleError('Unable to open the configuration in %s '
Expand All @@ -631,7 +652,7 @@ def close_configuration(self):
try:
if config.mode == 'exclusive':
config.unlock()
elif config.mode == 'private':
elif config.mode in ['batch', 'dynamic', 'private', 'ephemeral']:
self.dev.rpc.close_configuration()
self.queue_message("log", "Configuration closed.")
except (pyez_exception.ConnectError,
Expand Down Expand Up @@ -723,7 +744,7 @@ def load_configuration(self, config, load_args):
if config is not None:
self.config.load(config, **load_args)
else:
self.queue_message("log", "Load args %s.", str(load_args))
self.queue_message("log", "Load args %s." %str(load_args))
self.config.load(**load_args)
self.queue_message("log", "Configuration loaded.")
except (self.pyez_exception.RpcError,
Expand All @@ -732,7 +753,8 @@ def load_configuration(self, config, load_args):
(str(ex)))

def commit_configuration(self, ignore_warning=None, comment=None,
confirmed=None):
confirmed=None, timeout=30, full=False,
force_sync=False, sync=False):
"""Commit the candidate configuration.
Assumes the configuration is already opened.

Expand All @@ -747,7 +769,11 @@ def commit_configuration(self, ignore_warning=None, comment=None,
try:
self.config.commit(ignore_warning=ignore_warning,
comment=comment,
confirm=confirmed)
confirm=confirmed,
timeout=timeout,
full=full,
force_sync=force_sync,
sync=sync)
self.queue_message("log", "Configuration committed.")
except (self.pyez_exception.RpcError,
self.pyez_exception.ConnectError) as ex:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1165,7 +1165,9 @@ def open_configuration(self, mode, ignore_warning=None, ephemeral_instance=None)
if mode not in CONFIG_MODE_CHOICES:
self.fail_json(msg='Invalid configuration mode: %s' % (mode))
if mode != 'ephemeral' and ephemeral_instance is not None:
self.fail_json(msg='configuration mode ephemeral is required')
self.fail_json(msg='Ephemeral instance is specified while the mode '
'is not ephemeral.Specify the mode as ephemeral or '
'do not specify the instance.')
if self.dev is None:
self.open()
config = jnpr.junos.utils.config.Config(self.dev, mode=mode)
Expand Down Expand Up @@ -1542,7 +1544,7 @@ def commit_configuration(self, ignore_warning=None, comment=None,
- An error returned from committing the configuration.
"""
if self.conn_type != "local":
self._pyez_conn.commit_configuration(ignore_warning, comment, timeout, confirmed)
self._pyez_conn.commit_configuration(ignore_warning, comment, timeout, confirmed, full, sync, force_sync)
return

if self.dev is None or self.config is None:
Expand Down