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

refactors junos modules to support persistent socket connections #21365

Merged
merged 1 commit into from
Feb 16, 2017
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
467 changes: 178 additions & 289 deletions lib/ansible/module_utils/junos.py

Large diffs are not rendered by default.

30 changes: 9 additions & 21 deletions lib/ansible/modules/network/junos/_junos_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,42 +127,30 @@ def main():
transport=dict(default='netconf', choices=['netconf'])
)

module = NetworkModule(argument_spec=argument_spec,
module = AnsibleModule(argument_spec=argument_spec,
supports_check_mode=True)

comment = module.params['comment']
confirm = module.params['confirm']
commit = not module.check_mode

replace = False
overwrite = False

action = module.params['action']
if action == 'overwrite':
overwrite = True
elif action == 'replace':
replace = True

src = module.params['src']
fmt = module.params['config_format']

if action == 'overwrite' and fmt == 'set':
module.fail_json(msg="overwrite cannot be used when format is "
"set per junos-pyez documentation")

results = dict(changed=False)
results['_backup'] = unicode(module.config.get_config()).strip()
results = {'changed': False}

try:
diff = module.config.load_config(src, commit=commit, replace=replace,
confirm=confirm, comment=comment, config_format=fmt)
if module.praams['backup']:
results['__backup__'] = unicode(get_configuration(module))

if diff:
results['changed'] = True
results['diff'] = dict(prepared=diff)
except NetworkError:
exc = get_exception()
module.fail_json(msg=str(exc), **exc.kwargs)
diff = load(module, src, **kwargs)
if diff:
results['changed'] = True
if module._diff:
results['diff'] = {'prepared': diff}

module.exit_json(**results)

Expand Down