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
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ class ModuleDocFragment(object):
CONFIG_ACTION_CHOICES = ['set', 'merge', 'update',
'replace', 'override', 'overwrite', 'patch']
# Supported configuration modes
CONFIG_MODE_CHOICES = ['exclusive', 'private']
CONFIG_MODE_CHOICES = ['exclusive', 'private', 'dynamic', 'batch', 'ephemeral']
# Supported configuration models
CONFIG_MODEL_CHOICES = ['openconfig', 'custom', 'ietf', 'True']

Expand Down Expand Up @@ -513,7 +513,7 @@ class JuniperJunosModule(AnsibleModule):
open: Open self.dev.
close: Close self.dev.
add_sw: Add an instance of jnp.junos.utils.sw.SW() to self.
open_configuration: Open cand. conf. db in exclusive or private mode.
open_configuration: Open cand. conf. db in exclusive/private/dynamic/batch/ephemeral mode.
close_configuration: Close candidate configuration database.
get_configuration: Return the device config. in the specified format.
rollback_configuration: Rollback device config. to the specified id.
Expand Down Expand Up @@ -1137,7 +1137,7 @@ def add_sw(self):
"""
self.sw = SW(self.dev)

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

Failures:
Expand All @@ -1164,6 +1164,8 @@ def open_configuration(self, mode, ignore_warning=None):
if self.config is 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')
if self.dev is None:
self.open()
config = jnpr.junos.utils.config.Config(self.dev, mode=mode)
Expand All @@ -1174,6 +1176,23 @@ def open_configuration(self, mode, ignore_warning=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:
self.fail_json(msg='Unable to open the configuration in %s '
Expand Down Expand Up @@ -1202,7 +1221,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.logger.debug("Configuration closed.")
except (pyez_exception.ConnectError,
Expand Down
34 changes: 33 additions & 1 deletion ansible_collections/juniper/device/plugins/modules/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,20 @@
* If the I(config_mode) option has a value of C(private), open a private
candidate configuration database. If opening the private configuration
database fails the module fails and reports an error.
* If the I(config_mode) option has a value of C(dynamic), open a dynamic
candidate configuration database. If opening the dynamic configuration
database fails the module fails and reports an error.
* If the I(config_mode) option has a value of C(batch), open a batch
candidate configuration database. If opening the batch configuration
database fails the module fails and reports an error.
* If the I(config_mode) option has a value of C(ephemeral), open a default
ephemeral candidate configuration database. If opening the ephemeral
configuration database fails the module fails and reports an error.
* If the I(ephemeral_instance) option has a value of C(ephemeral instance
name) along with I(config_mode) option has a value of C(ephemeral), open
a user defined ephemeral instance candidate configuration database. If
opening the ephemeral onfiguration database fails the module fails
and reports an error.
#. Load configuration data into the candidate configuration database.

* Configuration data may be loaded using the I(load) or I(rollback)
Expand Down Expand Up @@ -208,10 +222,19 @@
choices:
- exclusive
- private
- dynamic
- batch
- ephemeral
aliases:
- config_access
- edit_mode
- edit_access
ephemeral_instance:
description:
- To open a user-defined instance of the ephemeral database
required: false
default: None
type: str
confirmed:
description:
- Provide a confirmed timeout, in minutes, to be used with the commit
Expand Down Expand Up @@ -826,6 +849,9 @@ def main():
aliases=['config_access', 'edit_mode',
'edit_access'],
default='exclusive'),
ephemeral_instance=dict(type='str',
required=False,
default=None),
rollback=dict(type='str',
required=False,
default=None),
Expand Down Expand Up @@ -943,6 +969,7 @@ def main():

# Straight from params
config_mode = junos_module.params.get('config_mode')
ephemeral_instance = junos_module.params.get('ephemeral_instance')

# Parse rollback value
rollback = junos_module.parse_rollback_option()
Expand Down Expand Up @@ -976,6 +1003,10 @@ def main():
remove_ns = junos_module.params.get('remove_ns')
namespace = junos_module.params.get('namespace')

# Ephemeral database doesn't support "show | compare",
# so setting diff to False.
if config_mode == 'ephemeral':
diff = False

# If retrieve is set and load and rollback are not set, then
# check, diff, and commit default to False.
Expand Down Expand Up @@ -1092,7 +1123,8 @@ def main():

junos_module.logger.debug("Step 1 - Open a candidate configuration "
"database.")
junos_module.open_configuration(mode=config_mode, ignore_warning=ignore_warning)
junos_module.open_configuration(mode=config_mode, ignore_warning=ignore_warning,
ephemeral_instance=ephemeral_instance)
results['msg'] += 'opened'

junos_module.logger.debug("Step 2 - Load configuration data into the "
Expand Down