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

bug fixes in vyos shared module #16588

Merged
merged 1 commit into from
Jul 6, 2016
Merged
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
28 changes: 18 additions & 10 deletions lib/ansible/module_utils/vyos.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from ansible.module_utils.network import NetworkError, get_module, get_exception
from ansible.module_utils.network import register_transport, to_list
from ansible.module_utils.network import Command, NetCli
from ansible.module_utils.netcfg import NetworkConfig
from ansible.module_utils.shell import Shell, ShellError, HAS_PARAMIKO

DEFAULT_COMMENT = 'configured by vyos_config'
Expand All @@ -36,17 +37,18 @@ def argument_spec():
vyos_argument_spec = argument_spec()

def get_config(module):
if module.params['config']:
return module.params['config']
config = module.config.get_config()
module.params['config'] = config
return config
contents = module.params['config']
if not contents:
contents = str(module.config.get_config()).split('\n')
module.params['config'] = contents
contents = '\n'.join(contents)
return NetworkConfig(contents=contents, device_os='junos')

def diff_config(candidate, config):
updates = set()
config = [str(c).replace("'", '') for c in config]
config = [str(c).replace("'", '') for c in str(config).split('\n')]

for line in candidate:
for line in str(candidate).split('\n'):
item = str(line).replace("'", '')

if not item.startswith('set') and not item.startswith('delete'):
Expand All @@ -66,8 +68,9 @@ def diff_config(candidate, config):

return list(updates)

def load_config(module, candidate):
config = get_config(module).split('\n')
def load_candidate(module, candidate):
config = get_config(module)

updates = diff_config(candidate, config)

comment = module.params['comment']
Expand All @@ -81,7 +84,6 @@ def load_config(module, candidate):
result['diff'] = dict(prepared=diff)

result['changed'] = True
result['updates'] = updates

if not module.check_mode:
module.config.commit_config(comment=comment)
Expand All @@ -93,8 +95,14 @@ def load_config(module, candidate):
# exit from config mode
module.cli('exit')

result['updates'] = updates
return result

def load_config(module, commands):
contents = '\n'.join(commands)
candidate = NetworkConfig(contents=contents, device_os='junos')
return load_candidate(module, candidate)


class Cli(NetCli):

Expand Down