From ecc7e445b5344e003672ddf3f31201a2f3e5b000 Mon Sep 17 00:00:00 2001 From: John Barker Date: Fri, 5 Aug 2016 15:14:04 +0100 Subject: [PATCH] vyos: Docs fixes --- .../modules/network/vyos/vyos_command.py | 17 +++++++------- .../modules/network/vyos/vyos_config.py | 22 ++++++++++--------- .../modules/network/vyos/vyos_facts.py | 8 ++++--- 3 files changed, 26 insertions(+), 21 deletions(-) diff --git a/lib/ansible/modules/network/vyos/vyos_command.py b/lib/ansible/modules/network/vyos/vyos_command.py index 8771613c06b..8a94f2cad28 100644 --- a/lib/ansible/modules/network/vyos/vyos_command.py +++ b/lib/ansible/modules/network/vyos/vyos_command.py @@ -24,7 +24,7 @@ author: "Peter Sprygada (@privateip)" short_description: Run one or more commands on VyOS devices description: - The command module allows running one or more commands on remote - devices running VyOS. The mdoule commands can also be introspected + devices running VyOS. This module can also be introspected to validate key parameters before returning successfully. If the conditional statements are not met in the wait period, the task fails. @@ -36,7 +36,7 @@ options: running VyOS. The output from the command execution is returned to the playbook. If the I(wait_for) argument is provided, the module is not returned until the condition is - satistifed or the number of retries has been exceeded. + satisfied or the number of retries has been exceeded. required: true wait_for: description: @@ -44,7 +44,7 @@ options: and what conditionals to apply. This argument will cause the task to wait for a particular conditional to be true before moving forward. If the conditional is not true - by the configured retries, the task fails. See examples. + by the configured I(retries), the task fails. See examples. required: false default: null aliases: ['waitfor'] @@ -52,13 +52,13 @@ options: description: - Specifies the number of retries a command should be tried before it is considered failed. The command is run on the - target device every retry and evaluated against the waitfor - conditionals + target device every retry and evaluated against the I(wait_for) + conditionals. required: false default: 10 interval: description: - - Configures the interval in seconds to wait between retries + - Configures the interval in seconds to wait between I(retries) of the command. If the command does not pass the specified conditional, the interval indicates how to long to wait before trying the command again. @@ -115,16 +115,19 @@ warnings: type: list sample: ['...', '...'] """ + from ansible.module_utils.netcmd import CommandRunner, FailedConditionsError from ansible.module_utils.vyos import NetworkModule, NetworkError from ansible.module_utils.vyos import vyos_argument_spec, get_exception + def to_lines(stdout): for item in stdout: if isinstance(item, basestring): item = str(item).split('\n') yield item + def main(): """Main entry point for Ansible module execution """ @@ -140,7 +143,6 @@ def main(): connect_on_load=False, supports_check_mode=True) - commands = module.params['commands'] conditionals = module.params['wait_for'] or list() @@ -192,4 +194,3 @@ def main(): if __name__ == '__main__': main() - diff --git a/lib/ansible/modules/network/vyos/vyos_config.py b/lib/ansible/modules/network/vyos/vyos_config.py index 7bf5b38ece9..b3b240e8454 100644 --- a/lib/ansible/modules/network/vyos/vyos_config.py +++ b/lib/ansible/modules/network/vyos/vyos_config.py @@ -39,31 +39,28 @@ options: default: null src: description: - - The C(src) argument provides the path to the configuration - file to load. + - Path to the configuration file to load. required: no default: null rollback: description: - - This argument will rollback the device configuration to the + - Rollback the device configuration to the revision specified. If the specified rollback revision does not exist, then the module will produce an error and fail. - - NOTE THIS WILL CAUSE THE DEVICE TO REBOOT AUTOMATICALLY + - NOTE THIS WILL CAUSE THE DEVICE TO REBOOT AUTOMATICALLY. required: false default: null update_config: description: - - This argument will control whether or not the configuration - on the remote device is udpated with the calculated changes. - When set to true, the configuration will be updated and - when set to false, the configuration will not be updated. + - Should the configuration on the remote device be updated with the + calculated changes. When set to true, the configuration will be updated + and when set to false, the configuration will not be updated. required: false default: true choices: ['yes', 'no'] backup_config: description: - - The C(backup_config) argument will instruct the module to - create a local backup copy of the current running configuration + - Create a local backup copy of the current running configuration prior to making any changes. The configuration file will be stored in the backups folder in the root of the playbook or role. required: false @@ -119,6 +116,7 @@ def invoke(name, *args, **kwargs): if func: return func(*args, **kwargs) + def config_to_commands(config): set_format = config.startswith('set') or config.startswith('delete') candidate = NetworkConfig(indent=4, contents=config, device_os='junos') @@ -135,15 +133,18 @@ def config_to_commands(config): commands = str(candidate).split('\n') return commands + def do_lines(module, result): commands = module.params['lines'] result.update(load_config(module, commands)) + def do_src(module, result): contents = module.params['src'] commands = config_to_commands(contents) result.update(load_config(module, commands)) + def do_rollback(module, result): rollback = 'rollback %s' % module.params['rollback'] prompt = re.compile('\[confirm\]') @@ -156,6 +157,7 @@ def do_rollback(module, result): cmds = [str(c) for c in exc.kwargs.get('commands', list())] module.fail_json(msg=str(exc), commands=cmds) + def main(): argument_spec = dict( diff --git a/lib/ansible/modules/network/vyos/vyos_facts.py b/lib/ansible/modules/network/vyos/vyos_facts.py index f34e2f00597..3c09f36505a 100644 --- a/lib/ansible/modules/network/vyos/vyos_facts.py +++ b/lib/ansible/modules/network/vyos/vyos_facts.py @@ -23,7 +23,7 @@ author: "Peter Sprygada (@privateip)" short_description: Collect facts from remote devices running OS description: - Collects a base set of device facts from a remote device that - is running VyOS. The M(vyos_facts) module prepends all of the + is running VyOS. This module prepends all of the base network fact keys with U(ansible_net_). The facts module will always collect a base set of facts from the device and can enable or disable collection of additional facts. @@ -32,7 +32,7 @@ options: gather_subset: description: - When supplied, this argument will restrict the facts collected - to a given subset. Possible values for this argument inlcude + to a given subset. Possible values for this argument include all, hardware, config, and interfaces. Can specify a list of values to include a larger subset. Values can also be used with an initial M(!) to specify that a specific subset should @@ -103,6 +103,7 @@ import re from ansible.module_utils.netcmd import CommandRunner from ansible.module_utils.vyos import NetworkModule + class FactsBase(object): def __init__(self, runner): @@ -111,6 +112,7 @@ class FactsBase(object): self.commands() + class Default(FactsBase): def commands(self): @@ -236,6 +238,7 @@ FACT_SUBSETS = dict( VALID_SUBSETS = frozenset(FACT_SUBSETS.keys()) + def main(): spec = dict( gather_subset=dict(default=['!config'], type='list') @@ -305,4 +308,3 @@ def main(): if __name__ == '__main__': main() -