Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add exclusive configuration mode support in IOS-XR #59289

Merged
merged 1 commit into from
Jul 19, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/ansible/module_utils/network/iosxr/iosxr.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ def check_existing_commit_labels(conn, label):


def load_config(module, command_filter, commit=False, replace=False,
comment=None, admin=False, running=None, nc_get_filter=None,
comment=None, admin=False, exclusive=False, running=None, nc_get_filter=None,
label=None):

conn = get_connection(module)
Expand Down Expand Up @@ -472,7 +472,8 @@ def load_config(module, command_filter, commit=False, replace=False,
' and rerun task' % label
)

response = conn.edit_config(candidate=command_filter, commit=commit, admin=admin, replace=replace, comment=comment, label=label)
response = conn.edit_config(candidate=command_filter, commit=commit, admin=admin,
exclusive=exclusive, replace=replace, comment=comment, label=label)
if module._diff:
diff = response.get('diff')

Expand Down
11 changes: 10 additions & 1 deletion lib/ansible/modules/network/iosxr/iosxr_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,13 @@
type: path
type: dict
version_added: "2.8"
exclusive:
description:
- Enters into exclusive configuration mode that locks out all users from committing
configuration changes until the exclusive session ends.
type: bool
default: false
version_added: "2.9"
"""

EXAMPLES = """
Expand Down Expand Up @@ -308,6 +315,7 @@ def run(module, result):
path = module.params['parents']
comment = module.params['comment']
admin = module.params['admin']
exclusive = module.params['exclusive']
check_mode = module.check_mode
label = module.params['label']

Expand Down Expand Up @@ -350,7 +358,7 @@ def run(module, result):
commit = not check_mode
diff = load_config(
module, commands, commit=commit,
replace=replace_file_path, comment=comment, admin=admin,
replace=replace_file_path, comment=comment, admin=admin, exclusive=exclusive,
label=label
)
if diff:
Expand Down Expand Up @@ -387,6 +395,7 @@ def main():
backup_options=dict(type='dict', options=backup_spec),
comment=dict(default=DEFAULT_COMMIT_COMMENT),
admin=dict(type='bool', default=False),
exclusive=dict(type='bool', default=False),
label=dict()
)

Expand Down
9 changes: 6 additions & 3 deletions lib/ansible/plugins/cliconf/iosxr.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,14 @@ def get_device_info(self):

return device_info

def configure(self, admin=False):
def configure(self, admin=False, exclusive=False):
prompt = to_text(self._connection.get_prompt(), errors='surrogate_or_strict').strip()
if not prompt.endswith(')#'):
if admin and 'admin-' not in prompt:
self.send_command('admin')
if exclusive:
self.send_command('configure exclusive')
return
self.send_command('configure terminal')

def abort(self, admin=False):
Expand All @@ -99,15 +102,15 @@ def get_config(self, source='running', format='text', flags=None):

return self.send_command(cmd)

def edit_config(self, candidate=None, commit=True, admin=False, replace=None, comment=None, label=None):
def edit_config(self, candidate=None, commit=True, admin=False, exclusive=False, replace=None, comment=None, label=None):
operations = self.get_device_operations()
self.check_edit_config_capability(operations, candidate, commit, replace, comment)

resp = {}
results = []
requests = []

self.configure(admin=admin)
self.configure(admin=admin, exclusive=exclusive)

if replace:
candidate = 'load {0}'.format(replace)
Expand Down
2 changes: 2 additions & 0 deletions test/integration/targets/iosxr_config/tests/cli/comment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
iosxr_config:
src: basic/config.j2
comment: "this is sensible commit message"
exclusive: true
register: result

- assert:
Expand All @@ -24,6 +25,7 @@
- name: check device with config
iosxr_config:
src: basic/config.j2
exclusive: true
register: result

- assert:
Expand Down