openswitch: Docs fixes

This commit is contained in:
John Barker 2016-08-05 14:40:52 +01:00
parent b8c1edc04d
commit d45a75bc01
4 changed files with 33 additions and 20 deletions

View file

@ -24,7 +24,7 @@ author: "Peter sprygada (@privateip)"
short_description: Run arbitrary commands on OpenSwitch devices. short_description: Run arbitrary commands on OpenSwitch devices.
description: description:
- Sends arbitrary commands to an OpenSwitch node and returns the results - Sends arbitrary commands to an OpenSwitch node and returns the results
read from the device. The M(ops_command) module includes an read from the device. This module includes an
argument that will cause the module to wait for a specific condition argument that will cause the module to wait for a specific condition
before returning or timing out if the condition is not met. before returning or timing out if the condition is not met.
extends_documentation_fragment: openswitch extends_documentation_fragment: openswitch
@ -42,7 +42,7 @@ options:
- List of conditions to evaluate against the output of the - List of conditions to evaluate against the output of the
command. The task will wait for a each condition to be true command. The task will wait for a each condition to be true
before moving forward. If the conditional is not true before moving forward. If the conditional is not true
within the configured number of retries, the task fails. within the configured number of I(retries), the task fails.
See examples. See examples.
required: false required: false
default: null default: null
@ -51,12 +51,12 @@ options:
- Specifies the number of retries a command should by tried - Specifies the number of retries a command should by tried
before it is considered failed. The command is run on the before it is considered failed. The command is run on the
target device every retry and evaluated against the target device every retry and evaluated against the
waitfor conditions. I(waitfor) conditions.
required: false required: false
default: 10 default: 10
interval: interval:
description: 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 of the command. If the command does not pass the specified
conditions, the interval indicates how long to wait before conditions, the interval indicates how long to wait before
trying the command again. trying the command again.
@ -104,12 +104,14 @@ failed_conditions:
import time import time
def to_lines(stdout): def to_lines(stdout):
for item in stdout: for item in stdout:
if isinstance(item, basestring): if isinstance(item, basestring):
item = str(item).split('\n') item = str(item).split('\n')
yield item yield item
def main(): def main():
spec = dict( spec = dict(
commands=dict(type='list'), commands=dict(type='list'),
@ -163,4 +165,3 @@ from ansible.module_utils.netcfg import *
from ansible.module_utils.openswitch import * from ansible.module_utils.openswitch import *
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View file

@ -23,8 +23,8 @@ version_added: "2.1"
author: "Peter sprygada (@privateip)" author: "Peter sprygada (@privateip)"
short_description: Manage OpenSwitch configuration using CLI short_description: Manage OpenSwitch configuration using CLI
description: description:
- OpenSwitch configurations use a simple block indent file sytanx - OpenSwitch configurations use a simple block indent file syntax
for segementing configuration into sections. This module provides for segmenting configuration into sections. This module provides
an implementation for working with ops configuration sections in an implementation for working with ops configuration sections in
a deterministic way. a deterministic way.
extends_documentation_fragment: openswitch extends_documentation_fragment: openswitch
@ -51,7 +51,7 @@ options:
a change needs to be made. This allows the playbook designer a change needs to be made. This allows the playbook designer
the opportunity to perform configuration commands prior to pushing the opportunity to perform configuration commands prior to pushing
any changes without affecting how the set of commands are matched any changes without affecting how the set of commands are matched
against the system against the system.
required: false required: false
default: null default: null
after: after:
@ -80,7 +80,7 @@ options:
the modified lines are pushed to the device in configuration the modified lines are pushed to the device in configuration
mode. If the replace argument is set to I(block) then the entire mode. If the replace argument is set to I(block) then the entire
command block is pushed to the device in configuration mode if any command block is pushed to the device in configuration mode if any
line is not correct line is not correct.
required: false required: false
default: line default: line
choices: ['line', 'block'] choices: ['line', 'block']
@ -100,8 +100,8 @@ options:
against the contents of source. There are times when it is not against the contents of source. There are times when it is not
desirable to have the task get the current running-config for desirable to have the task get the current running-config for
every task in a playbook. The I(config) argument allows the every task in a playbook. The I(config) argument allows the
implementer to pass in the configuruation to use as the base implementer to pass in the configuration to use as the base
config for comparision. config for comparison.
required: false required: false
default: null default: null
""" """
@ -142,6 +142,7 @@ def get_config(module):
config = module.config config = module.config
return config return config
def build_candidate(lines, parents, config, strategy): def build_candidate(lines, parents, config, strategy):
candidate = list() candidate = list()
@ -244,4 +245,3 @@ from ansible.module_utils.netcfg import *
from ansible.module_utils.openswitch import * from ansible.module_utils.openswitch import *
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View file

@ -32,21 +32,24 @@ options:
description: description:
- When enabled, this argument will collect the current - When enabled, this argument will collect the current
running configuration from the remote device. If the running configuration from the remote device. If the
transport is C(rest) then the collected configuration will C(transport=rest) then the collected configuration will
be the full system configuration. be the full system configuration.
required: false required: false
choices:
- true
- false
default: false default: false
endpoints: endpoints:
description: description:
- Accepts a list of endpoints to retrieve from the remote - Accepts a list of endpoints to retrieve from the remote
device using the REST API. The endpoints should be valid device using the REST API. The endpoints should be valid
endpoints availble on the device. This argument is only endpoints available on the device. This argument is only
valid when the transport is C(rest). valid when the C(transport=rest).
required: false required: false
default: null default: null
notes: notes:
- The use of the REST transport is still experimental until it is - The use of the REST transport is still experimental until it is
fully implemented fully implemented.
""" """
EXAMPLES = """ EXAMPLES = """
@ -91,12 +94,14 @@ endpoints:
""" """
import re import re
def get(module, url, expected_status=200): def get(module, url, expected_status=200):
response = module.connection.get(url) response = module.connection.get(url)
if response.headers['status'] != expected_status: if response.headers['status'] != expected_status:
module.fail_json(**response.headers) module.fail_json(**response.headers)
return response return response
def get_config(module): def get_config(module):
if module.params['transport'] == 'ssh': if module.params['transport'] == 'ssh':
rc, out, err = module.run_command('vtysh -c "show running-config"') rc, out, err = module.run_command('vtysh -c "show running-config"')
@ -108,6 +113,7 @@ def get_config(module):
response = module.connection.send('show running-config') response = module.connection.send('show running-config')
return response[0] return response[0]
def get_facts(module): def get_facts(module):
if module.params['transport'] == 'rest': if module.params['transport'] == 'rest':
response = get(module, '/system') response = get(module, '/system')
@ -167,4 +173,3 @@ from ansible.module_utils.openswitch import *
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View file

@ -62,8 +62,8 @@ options:
against the contents of source. There are times when it is not against the contents of source. There are times when it is not
desirable to have the task get the current running-config for desirable to have the task get the current running-config for
every task in a playbook. The I(config) argument allows the every task in a playbook. The I(config) argument allows the
implementer to pass in the configuruation to use as the base implementer to pass in the configuration to use as the base
config for comparision. config for comparison.
required: false required: false
default: null default: null
""" """
@ -97,6 +97,7 @@ responses:
""" """
import copy import copy
def compare(this, other): def compare(this, other):
parents = [item.text for item in this.parents] parents = [item.text for item in this.parents]
for entry in other: for entry in other:
@ -104,6 +105,7 @@ def compare(this, other):
return None return None
return this return this
def expand(obj, queue): def expand(obj, queue):
block = [item.raw for item in obj.parents] block = [item.raw for item in obj.parents]
block.append(obj.raw) block.append(obj.raw)
@ -117,23 +119,27 @@ def expand(obj, queue):
if c.raw not in current_level: if c.raw not in current_level:
current_level[c.raw] = collections.OrderedDict() current_level[c.raw] = collections.OrderedDict()
def flatten(data, obj): def flatten(data, obj):
for k, v in data.items(): for k, v in data.items():
obj.append(k) obj.append(k)
flatten(v, obj) flatten(v, obj)
return obj return obj
def get_config(module): def get_config(module):
config = module.params['config'] or dict() config = module.params['config'] or dict()
if not config and not module.params['force']: if not config and not module.params['force']:
config = module.config config = module.config
return config return config
def sort(val): def sort(val):
if isinstance(val, (list, set)): if isinstance(val, (list, set)):
return sorted(val) return sorted(val)
return val return val
def diff(this, other, path=None): def diff(this, other, path=None):
updates = list() updates = list()
path = path or list() path = path or list()
@ -152,6 +158,7 @@ def diff(this, other, path=None):
updates.append((list(path), key, value, other_value)) updates.append((list(path), key, value, other_value))
return updates return updates
def merge(changeset, config=None): def merge(changeset, config=None):
config = config or dict() config = config or dict()
for path, key, value, _ in changeset: for path, key, value, _ in changeset:
@ -163,6 +170,7 @@ def merge(changeset, config=None):
current_level[key] = value current_level[key] = value
return config return config
def main(): def main():
""" main entry point for module execution """ main entry point for module execution
""" """
@ -242,4 +250,3 @@ from ansible.module_utils.openswitch import *
if __name__ == '__main__': if __name__ == '__main__':
main() main()