mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-04-18 18:01:31 +00:00
Initial commit
This commit is contained in:
commit
aebc1b03fd
4861 changed files with 812621 additions and 0 deletions
220
plugins/modules/network/exos/exos_command.py
Normal file
220
plugins/modules/network/exos/exos_command.py
Normal file
|
|
@ -0,0 +1,220 @@
|
|||
#!/usr/bin/python
|
||||
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
from __future__ import absolute_import, division, print_function
|
||||
__metaclass__ = type
|
||||
|
||||
|
||||
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
||||
'status': ['preview'],
|
||||
'supported_by': 'community'}
|
||||
|
||||
|
||||
DOCUMENTATION = '''
|
||||
---
|
||||
module: exos_command
|
||||
author: "Rafael D. Vencioneck (@rdvencioneck)"
|
||||
short_description: Run commands on remote devices running Extreme EXOS
|
||||
description:
|
||||
- Sends arbitrary commands to an Extreme EXOS device and returns the results
|
||||
read from the device. This module includes an argument that will cause the
|
||||
module to wait for a specific condition before returning or timing out if
|
||||
the condition is not met.
|
||||
- This module does not support running configuration commands.
|
||||
Please use M(exos_config) to configure EXOS devices.
|
||||
notes:
|
||||
- If a command sent to the device requires answering a prompt, it is possible
|
||||
to pass a dict containing I(command), I(answer) and I(prompt). See examples.
|
||||
options:
|
||||
commands:
|
||||
description:
|
||||
- List of commands to send to the remote EXOS device over the
|
||||
configured provider. The resulting output from the command
|
||||
is returned. If the I(wait_for) argument is provided, the
|
||||
module is not returned until the condition is satisfied or
|
||||
the number of retries has expired.
|
||||
required: true
|
||||
wait_for:
|
||||
description:
|
||||
- List of conditions to evaluate against the output of the
|
||||
command. The task will wait for each condition to be true
|
||||
before moving forward. If the conditional is not true
|
||||
within the configured number of retries, the task fails.
|
||||
See examples.
|
||||
match:
|
||||
description:
|
||||
- The I(match) argument is used in conjunction with the
|
||||
I(wait_for) argument to specify the match policy. Valid
|
||||
values are C(all) or C(any). If the value is set to C(all)
|
||||
then all conditionals in the wait_for must be satisfied. If
|
||||
the value is set to C(any) then only one of the values must be
|
||||
satisfied.
|
||||
default: all
|
||||
choices: ['any', 'all']
|
||||
retries:
|
||||
description:
|
||||
- Specifies the number of retries a command should by tried
|
||||
before it is considered failed. The command is run on the
|
||||
target device every retry and evaluated against the
|
||||
I(wait_for) conditions.
|
||||
default: 10
|
||||
interval:
|
||||
description:
|
||||
- Configures the interval in seconds to wait between retries
|
||||
of the command. If the command does not pass the specified
|
||||
conditions, the interval indicates how long to wait before
|
||||
trying the command again.
|
||||
default: 1
|
||||
'''
|
||||
|
||||
EXAMPLES = """
|
||||
tasks:
|
||||
- name: run show version on remote devices
|
||||
exos_command:
|
||||
commands: show version
|
||||
- name: run show version and check to see if output contains ExtremeXOS
|
||||
exos_command:
|
||||
commands: show version
|
||||
wait_for: result[0] contains ExtremeXOS
|
||||
- name: run multiple commands on remote nodes
|
||||
exos_command:
|
||||
commands:
|
||||
- show version
|
||||
- show ports no-refresh
|
||||
- name: run multiple commands and evaluate the output
|
||||
exos_command:
|
||||
commands:
|
||||
- show version
|
||||
- show ports no-refresh
|
||||
wait_for:
|
||||
- result[0] contains ExtremeXOS
|
||||
- result[1] contains 20
|
||||
- name: run command that requires answering a prompt
|
||||
exos_command:
|
||||
commands:
|
||||
- command: 'clear license-info'
|
||||
prompt: 'Are you sure.*'
|
||||
answer: 'Yes'
|
||||
"""
|
||||
|
||||
RETURN = """
|
||||
stdout:
|
||||
description: The set of responses from the commands
|
||||
returned: always apart from low level errors (such as action plugin)
|
||||
type: list
|
||||
sample: ['...', '...']
|
||||
stdout_lines:
|
||||
description: The value of stdout split into a list
|
||||
returned: always apart from low level errors (such as action plugin)
|
||||
type: list
|
||||
sample: [['...', '...'], ['...'], ['...']]
|
||||
failed_conditions:
|
||||
description: The list of conditionals that have failed
|
||||
returned: failed
|
||||
type: list
|
||||
sample: ['...', '...']
|
||||
"""
|
||||
import re
|
||||
import time
|
||||
|
||||
from ansible_collections.community.general.plugins.module_utils.network.exos.exos import run_commands
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ComplexList
|
||||
from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.parsing import Conditional
|
||||
from ansible.module_utils.six import string_types
|
||||
|
||||
|
||||
def to_lines(stdout):
|
||||
for item in stdout:
|
||||
if isinstance(item, string_types):
|
||||
item = str(item).split('\n')
|
||||
yield item
|
||||
|
||||
|
||||
def parse_commands(module, warnings):
|
||||
command = ComplexList(dict(
|
||||
command=dict(key=True),
|
||||
prompt=dict(),
|
||||
answer=dict()
|
||||
), module)
|
||||
commands = command(module.params['commands'])
|
||||
for item in list(commands):
|
||||
command_split = re.match(r'^(\w*)(.*)$', item['command'])
|
||||
if module.check_mode and not item['command'].startswith('show'):
|
||||
warnings.append(
|
||||
'only show commands are supported when using check mode, not '
|
||||
'executing `%s`' % item['command']
|
||||
)
|
||||
commands.remove(item)
|
||||
elif command_split and command_split.group(1) not in ('check', 'clear', 'debug', 'history',
|
||||
'ls', 'mrinfo', 'mtrace', 'nslookup',
|
||||
'ping', 'rtlookup', 'show', 'traceroute'):
|
||||
module.fail_json(
|
||||
msg='some commands were not recognized. exos_command can only run read-only'
|
||||
'commands. For configuration commands, please use exos_config instead'
|
||||
)
|
||||
return commands
|
||||
|
||||
|
||||
def main():
|
||||
"""main entry point for module execution
|
||||
"""
|
||||
argument_spec = dict(
|
||||
commands=dict(type='list', required=True),
|
||||
|
||||
wait_for=dict(type='list'),
|
||||
match=dict(default='all', choices=['all', 'any']),
|
||||
|
||||
retries=dict(default=10, type='int'),
|
||||
interval=dict(default=1, type='int')
|
||||
)
|
||||
|
||||
module = AnsibleModule(argument_spec=argument_spec,
|
||||
supports_check_mode=True)
|
||||
|
||||
result = {'changed': False}
|
||||
|
||||
warnings = list()
|
||||
commands = parse_commands(module, warnings)
|
||||
result['warnings'] = warnings
|
||||
|
||||
wait_for = module.params['wait_for'] or list()
|
||||
conditionals = [Conditional(c) for c in wait_for]
|
||||
|
||||
retries = module.params['retries']
|
||||
interval = module.params['interval']
|
||||
match = module.params['match']
|
||||
|
||||
while retries > 0:
|
||||
responses = run_commands(module, commands)
|
||||
|
||||
for item in list(conditionals):
|
||||
if item(responses):
|
||||
if match == 'any':
|
||||
conditionals = list()
|
||||
break
|
||||
conditionals.remove(item)
|
||||
|
||||
if not conditionals:
|
||||
break
|
||||
|
||||
time.sleep(interval)
|
||||
retries -= 1
|
||||
|
||||
if conditionals:
|
||||
failed_conditions = [item.raw for item in conditionals]
|
||||
msg = 'One or more conditional statements have not be satisfied'
|
||||
module.fail_json(msg=msg, failed_conditions=failed_conditions)
|
||||
|
||||
result.update({
|
||||
'changed': False,
|
||||
'stdout': responses,
|
||||
'stdout_lines': list(to_lines(responses))
|
||||
})
|
||||
|
||||
module.exit_json(**result)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
436
plugins/modules/network/exos/exos_config.py
Normal file
436
plugins/modules/network/exos/exos_config.py
Normal file
|
|
@ -0,0 +1,436 @@
|
|||
#!/usr/bin/python
|
||||
|
||||
# Copyright: (c) 2018, Extreme Networks Inc.
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
||||
'status': ['preview'],
|
||||
'supported_by': 'community'}
|
||||
|
||||
|
||||
DOCUMENTATION = '''
|
||||
---
|
||||
module: exos_config
|
||||
author: "Lance Richardson (@hlrichardson)"
|
||||
short_description: Manage Extreme Networks EXOS configuration sections
|
||||
description:
|
||||
- Extreme EXOS configurations use a simple flat text file syntax.
|
||||
This module provides an implementation for working with EXOS
|
||||
configuration lines in a deterministic way.
|
||||
notes:
|
||||
- Tested against EXOS version 22.6.0b19
|
||||
options:
|
||||
lines:
|
||||
description:
|
||||
- The ordered set of commands that should be configured in the
|
||||
section. The commands must be the exact same commands as found
|
||||
in the device running-config. Be sure to note the configuration
|
||||
command syntax as some commands are automatically modified by the
|
||||
device config parser.
|
||||
aliases: ['commands']
|
||||
src:
|
||||
description:
|
||||
- Specifies the source path to the file that contains the configuration
|
||||
or configuration template to load. The path to the source file can
|
||||
either be the full path on the Ansible control host or a relative
|
||||
path from the playbook or role root directory. This argument is mutually
|
||||
exclusive with I(lines).
|
||||
before:
|
||||
description:
|
||||
- The ordered set of commands to push on to the command stack if
|
||||
a change needs to be made. This allows the playbook designer
|
||||
the opportunity to perform configuration commands prior to pushing
|
||||
any changes without affecting how the set of commands are matched
|
||||
against the system.
|
||||
after:
|
||||
description:
|
||||
- The ordered set of commands to append to the end of the command
|
||||
stack if a change needs to be made. Just like with I(before) this
|
||||
allows the playbook designer to append a set of commands to be
|
||||
executed after the command set.
|
||||
match:
|
||||
description:
|
||||
- Instructs the module on the way to perform the matching of
|
||||
the set of commands against the current device config. If
|
||||
match is set to I(line), commands are matched line by line. If
|
||||
match is set to I(strict), command lines are matched with respect
|
||||
to position. If match is set to I(exact), command lines
|
||||
must be an equal match. Finally, if match is set to I(none), the
|
||||
module will not attempt to compare the source configuration with
|
||||
the running configuration on the remote device.
|
||||
default: line
|
||||
choices: ['line', 'strict', 'exact', 'none']
|
||||
replace:
|
||||
description:
|
||||
- Instructs the module on the way to perform the configuration
|
||||
on the device. If the replace argument is set to I(line) then
|
||||
the modified lines are pushed to the device in configuration
|
||||
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
|
||||
line is not correct.
|
||||
default: line
|
||||
choices: ['line', 'block']
|
||||
backup:
|
||||
description:
|
||||
- This argument will cause the module to create a full backup of
|
||||
the current C(running-config) from the remote device before any
|
||||
changes are made. If the C(backup_options) value is not given,
|
||||
the backup file is written to the C(backup) folder in the playbook
|
||||
root directory. If the directory does not exist, it is created.
|
||||
type: bool
|
||||
default: 'no'
|
||||
running_config:
|
||||
description:
|
||||
- The module, by default, will connect to the remote device and
|
||||
retrieve the current running-config to use as a base for comparing
|
||||
against the contents of source. There are times when it is not
|
||||
desirable to have the task get the current running-config for
|
||||
every task in a playbook. The I(running_config) argument allows the
|
||||
implementer to pass in the configuration to use as the base
|
||||
config for comparison.
|
||||
aliases: ['config']
|
||||
defaults:
|
||||
description:
|
||||
- This argument specifies whether or not to collect all defaults
|
||||
when getting the remote device running config. When enabled,
|
||||
the module will get the current config by issuing the command
|
||||
C(show running-config all).
|
||||
type: bool
|
||||
default: 'no'
|
||||
save_when:
|
||||
description:
|
||||
- When changes are made to the device running-configuration, the
|
||||
changes are not copied to non-volatile storage by default. Using
|
||||
this argument will change that behavior. If the argument is set to
|
||||
I(always), then the running-config will always be copied to the
|
||||
startup-config and the I(modified) flag will always be set to
|
||||
True. If the argument is set to I(modified), then the running-config
|
||||
will only be copied to the startup-config if it has changed since
|
||||
the last save to startup-config. If the argument is set to
|
||||
I(never), the running-config will never be copied to the
|
||||
startup-config. If the argument is set to I(changed), then the running-config
|
||||
will only be copied to the startup-config if the task has made a change.
|
||||
default: never
|
||||
choices: ['always', 'never', 'modified', 'changed']
|
||||
diff_against:
|
||||
description:
|
||||
- When using the C(ansible-playbook --diff) command line argument
|
||||
the module can generate diffs against different sources.
|
||||
- When this option is configure as I(startup), the module will return
|
||||
the diff of the running-config against the startup-config.
|
||||
- When this option is configured as I(intended), the module will
|
||||
return the diff of the running-config against the configuration
|
||||
provided in the C(intended_config) argument.
|
||||
- When this option is configured as I(running), the module will
|
||||
return the before and after diff of the running-config with respect
|
||||
to any changes made to the device configuration.
|
||||
default: running
|
||||
choices: ['running', 'startup', 'intended']
|
||||
diff_ignore_lines:
|
||||
description:
|
||||
- Use this argument to specify one or more lines that should be
|
||||
ignored during the diff. This is used for lines in the configuration
|
||||
that are automatically updated by the system. This argument takes
|
||||
a list of regular expressions or exact line matches.
|
||||
intended_config:
|
||||
description:
|
||||
- The C(intended_config) provides the master configuration that
|
||||
the node should conform to and is used to check the final
|
||||
running-config against. This argument will not modify any settings
|
||||
on the remote device and is strictly used to check the compliance
|
||||
of the current device's configuration against. When specifying this
|
||||
argument, the task should also modify the C(diff_against) value and
|
||||
set it to I(intended).
|
||||
backup_options:
|
||||
description:
|
||||
- This is a dict object containing configurable options related to backup file path.
|
||||
The value of this option is read only when C(backup) is set to I(yes), if C(backup) is set
|
||||
to I(no) this option will be silently ignored.
|
||||
suboptions:
|
||||
filename:
|
||||
description:
|
||||
- The filename to be used to store the backup configuration. If the filename
|
||||
is not given it will be generated based on the hostname, current time and date
|
||||
in format defined by <hostname>_config.<current-date>@<current-time>
|
||||
dir_path:
|
||||
description:
|
||||
- This option provides the path ending with directory name in which the backup
|
||||
configuration file will be stored. If the directory does not exist it will be first
|
||||
created and the filename is either the value of C(filename) or default filename
|
||||
as described in C(filename) options description. If the path value is not given
|
||||
in that case a I(backup) directory will be created in the current working directory
|
||||
and backup configuration will be copied in C(filename) within I(backup) directory.
|
||||
type: path
|
||||
type: dict
|
||||
'''
|
||||
|
||||
EXAMPLES = """
|
||||
- name: configure SNMP system name
|
||||
exos_config:
|
||||
lines: configure snmp sysName "{{ inventory_hostname }}"
|
||||
|
||||
- name: configure interface settings
|
||||
exos_config:
|
||||
lines:
|
||||
- configure ports 2 description-string "Master Uplink"
|
||||
backup: yes
|
||||
|
||||
- name: check the running-config against master config
|
||||
exos_config:
|
||||
diff_against: intended
|
||||
intended_config: "{{ lookup('file', 'master.cfg') }}"
|
||||
|
||||
- name: check the startup-config against the running-config
|
||||
exos_config:
|
||||
diff_against: startup
|
||||
diff_ignore_lines:
|
||||
- ntp clock .*
|
||||
|
||||
- name: save running to startup when modified
|
||||
exos_config:
|
||||
save_when: modified
|
||||
|
||||
- name: configurable backup path
|
||||
exos_config:
|
||||
lines:
|
||||
- configure ports 2 description-string "Master Uplink"
|
||||
backup: yes
|
||||
backup_options:
|
||||
filename: backup.cfg
|
||||
dir_path: /home/user
|
||||
"""
|
||||
|
||||
RETURN = """
|
||||
updates:
|
||||
description: The set of commands that will be pushed to the remote device
|
||||
returned: always
|
||||
type: list
|
||||
sample: ['switch-attributes hostname foo', 'router ospf', 'area 0']
|
||||
commands:
|
||||
description: The set of commands that will be pushed to the remote device
|
||||
returned: always
|
||||
type: list
|
||||
sample: ['create vlan "foo"', 'configure snmp sysName "x620-red"']
|
||||
backup_path:
|
||||
description: The full path to the backup file
|
||||
returned: when backup is yes
|
||||
type: str
|
||||
sample: /playbooks/ansible/backup/x870_config.2018-08-08@15:00:21
|
||||
|
||||
"""
|
||||
import re
|
||||
|
||||
from ansible_collections.community.general.plugins.module_utils.network.exos.exos import run_commands, get_config, load_config, get_diff
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.config import NetworkConfig, dumps
|
||||
from ansible.module_utils._text import to_text
|
||||
from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import to_list
|
||||
|
||||
__metaclass__ = type
|
||||
|
||||
|
||||
def get_running_config(module, current_config=None, flags=None):
|
||||
contents = module.params['running_config']
|
||||
if not contents:
|
||||
if current_config:
|
||||
contents = current_config.config_text
|
||||
else:
|
||||
contents = get_config(module, flags=flags)
|
||||
return contents
|
||||
|
||||
|
||||
def get_startup_config(module, flags=None):
|
||||
reply = run_commands(module, {'command': 'show switch', 'output': 'text'})
|
||||
match = re.search(r'Config Selected: +(\S+)\.cfg', to_text(reply, errors='surrogate_or_strict').strip(), re.MULTILINE)
|
||||
if match:
|
||||
cfgname = match.group(1).strip()
|
||||
command = ' '.join(['debug cfgmgr show configuration file', cfgname])
|
||||
if flags:
|
||||
command += ' '.join(to_list(flags)).strip()
|
||||
reply = run_commands(module, {'command': command, 'output': 'text'})
|
||||
data = reply[0]
|
||||
else:
|
||||
data = ''
|
||||
return data
|
||||
|
||||
|
||||
def get_candidate(module):
|
||||
candidate = NetworkConfig(indent=1)
|
||||
|
||||
if module.params['src']:
|
||||
candidate.load(module.params['src'])
|
||||
elif module.params['lines']:
|
||||
candidate.add(module.params['lines'])
|
||||
candidate = dumps(candidate, 'raw')
|
||||
return candidate
|
||||
|
||||
|
||||
def save_config(module, result):
|
||||
result['changed'] = True
|
||||
if not module.check_mode:
|
||||
command = {"command": "save configuration",
|
||||
"prompt": "Do you want to save configuration", "answer": "y"}
|
||||
run_commands(module, command)
|
||||
else:
|
||||
module.warn('Skipping command `save configuration` '
|
||||
'due to check_mode. Configuration not copied to '
|
||||
'non-volatile storage')
|
||||
|
||||
|
||||
def main():
|
||||
""" main entry point for module execution
|
||||
"""
|
||||
backup_spec = dict(
|
||||
filename=dict(),
|
||||
dir_path=dict(type='path')
|
||||
)
|
||||
argument_spec = dict(
|
||||
src=dict(type='path'),
|
||||
|
||||
lines=dict(aliases=['commands'], type='list'),
|
||||
|
||||
before=dict(type='list'),
|
||||
after=dict(type='list'),
|
||||
|
||||
match=dict(default='line', choices=['line', 'strict', 'exact', 'none']),
|
||||
replace=dict(default='line', choices=['line', 'block']),
|
||||
|
||||
running_config=dict(aliases=['config']),
|
||||
intended_config=dict(),
|
||||
|
||||
defaults=dict(type='bool', default=False),
|
||||
backup=dict(type='bool', default=False),
|
||||
backup_options=dict(type='dict', options=backup_spec),
|
||||
|
||||
save_when=dict(choices=['always', 'never', 'modified', 'changed'], default='never'),
|
||||
|
||||
diff_against=dict(choices=['startup', 'intended', 'running'], default='running'),
|
||||
diff_ignore_lines=dict(type='list'),
|
||||
)
|
||||
|
||||
mutually_exclusive = [('lines', 'src')]
|
||||
|
||||
required_if = [('match', 'strict', ['lines']),
|
||||
('match', 'exact', ['lines']),
|
||||
('replace', 'block', ['lines']),
|
||||
('diff_against', 'intended', ['intended_config'])]
|
||||
|
||||
module = AnsibleModule(argument_spec=argument_spec,
|
||||
mutually_exclusive=mutually_exclusive,
|
||||
required_if=required_if,
|
||||
supports_check_mode=True)
|
||||
|
||||
result = {'changed': False}
|
||||
|
||||
warnings = list()
|
||||
if warnings:
|
||||
result['warnings'] = warnings
|
||||
|
||||
config = None
|
||||
flags = ['detail'] if module.params['defaults'] else []
|
||||
diff_ignore_lines = module.params['diff_ignore_lines']
|
||||
|
||||
if module.params['backup'] or (module._diff and module.params['diff_against'] == 'running'):
|
||||
contents = get_config(module, flags=flags)
|
||||
config = NetworkConfig(indent=1, contents=contents)
|
||||
if module.params['backup']:
|
||||
result['__backup__'] = contents
|
||||
|
||||
if any((module.params['lines'], module.params['src'])):
|
||||
match = module.params['match']
|
||||
replace = module.params['replace']
|
||||
|
||||
candidate = get_candidate(module)
|
||||
running = get_running_config(module, config)
|
||||
|
||||
try:
|
||||
response = get_diff(module, candidate=candidate, running=running, diff_match=match, diff_ignore_lines=diff_ignore_lines, diff_replace=replace)
|
||||
except ConnectionError as exc:
|
||||
module.fail_json(msg=to_text(exc, errors='surrogate_then_replace'))
|
||||
|
||||
config_diff = response.get('config_diff')
|
||||
|
||||
if config_diff:
|
||||
commands = config_diff.split('\n')
|
||||
|
||||
if module.params['before']:
|
||||
commands[:0] = module.params['before']
|
||||
|
||||
if module.params['after']:
|
||||
commands.extend(module.params['after'])
|
||||
|
||||
result['commands'] = commands
|
||||
result['updates'] = commands
|
||||
|
||||
# send the configuration commands to the device and merge
|
||||
# them with the current running config
|
||||
if not module.check_mode:
|
||||
if commands:
|
||||
load_config(module, commands)
|
||||
|
||||
result['changed'] = True
|
||||
|
||||
running_config = None
|
||||
startup_config = None
|
||||
|
||||
if module.params['save_when'] == 'always':
|
||||
save_config(module, result)
|
||||
elif module.params['save_when'] == 'modified':
|
||||
running = get_running_config(module)
|
||||
startup = get_startup_config(module)
|
||||
|
||||
running_config = NetworkConfig(indent=1, contents=running, ignore_lines=diff_ignore_lines)
|
||||
startup_config = NetworkConfig(indent=1, contents=startup, ignore_lines=diff_ignore_lines)
|
||||
|
||||
if running_config.sha1 != startup_config.sha1:
|
||||
save_config(module, result)
|
||||
elif module.params['save_when'] == 'changed' and result['changed']:
|
||||
save_config(module, result)
|
||||
|
||||
if module._diff:
|
||||
if not running_config:
|
||||
contents = get_running_config(module)
|
||||
else:
|
||||
contents = running_config.config_text
|
||||
|
||||
# recreate the object in order to process diff_ignore_lines
|
||||
running_config = NetworkConfig(indent=1, contents=contents, ignore_lines=diff_ignore_lines)
|
||||
|
||||
if module.params['diff_against'] == 'running':
|
||||
if module.check_mode:
|
||||
module.warn("unable to perform diff against running-config due to check mode")
|
||||
contents = None
|
||||
else:
|
||||
contents = config.config_text
|
||||
|
||||
elif module.params['diff_against'] == 'startup':
|
||||
if not startup_config:
|
||||
contents = get_startup_config(module)
|
||||
else:
|
||||
contents = startup_config.config_text
|
||||
|
||||
elif module.params['diff_against'] == 'intended':
|
||||
contents = module.params['intended_config']
|
||||
|
||||
if contents is not None:
|
||||
base_config = NetworkConfig(indent=1, contents=contents, ignore_lines=diff_ignore_lines)
|
||||
|
||||
if running_config.sha1 != base_config.sha1:
|
||||
if module.params['diff_against'] == 'intended':
|
||||
before = running_config
|
||||
after = base_config
|
||||
elif module.params['diff_against'] in ('startup', 'running'):
|
||||
before = base_config
|
||||
after = running_config
|
||||
|
||||
result.update({
|
||||
'changed': True,
|
||||
'diff': {'before': str(before), 'after': str(after)}
|
||||
})
|
||||
|
||||
module.exit_json(**result)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
189
plugins/modules/network/exos/exos_facts.py
Normal file
189
plugins/modules/network/exos/exos_facts.py
Normal file
|
|
@ -0,0 +1,189 @@
|
|||
#!/usr/bin/python
|
||||
#
|
||||
# (c) 2018 Extreme Networks Inc.
|
||||
#
|
||||
# This file is part of Ansible
|
||||
#
|
||||
# Ansible is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Ansible is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
from __future__ import absolute_import, division, print_function
|
||||
__metaclass__ = type
|
||||
|
||||
|
||||
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
||||
'status': ['preview'],
|
||||
'supported_by': 'community'}
|
||||
|
||||
|
||||
DOCUMENTATION = '''
|
||||
---
|
||||
module: exos_facts
|
||||
author:
|
||||
- "Lance Richardson (@hlrichardson)"
|
||||
- "Ujwal Koamrla (@ujwalkomarla)"
|
||||
short_description: Collect facts from devices running Extreme EXOS
|
||||
description:
|
||||
- Collects a base set of device facts from a remote device that
|
||||
is running EXOS. This module prepends all of the base network
|
||||
fact keys with C(ansible_net_<fact>). The facts module will
|
||||
always collect a base set of facts from the device and can
|
||||
enable or disable collection of additional facts.
|
||||
notes:
|
||||
- Tested against EXOS 22.5.1.7
|
||||
options:
|
||||
gather_subset:
|
||||
description:
|
||||
- When supplied, this argument will restrict the facts collected
|
||||
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 C(M(!)) to specify that a specific subset should
|
||||
not be collected.
|
||||
required: false
|
||||
type: list
|
||||
default: ['!config']
|
||||
gather_network_resources:
|
||||
description:
|
||||
- When supplied, this argument will restrict the facts collected
|
||||
to a given subset. Possible values for this argument include
|
||||
all and the resources like interfaces, vlans etc.
|
||||
Can specify a list of values to include a larger subset.
|
||||
Values can also be used with an initial C(M(!)) to specify that
|
||||
a specific subset should not be collected.
|
||||
Valid subsets are 'all', 'lldp_global'.
|
||||
type: list
|
||||
'''
|
||||
|
||||
EXAMPLES = """
|
||||
- name: Gather all legacy facts
|
||||
exos_facts:
|
||||
gather_subset: all
|
||||
|
||||
- name: Gather only the config and default facts
|
||||
exos_facts:
|
||||
gather_subset: config
|
||||
|
||||
- name: do not gather hardware facts
|
||||
exos_facts:
|
||||
gather_subset: "!hardware"
|
||||
|
||||
- name: Gather legacy and resource facts
|
||||
exos_facts:
|
||||
gather_subset: all
|
||||
gather_network_resources: all
|
||||
|
||||
- name: Gather only the lldp global resource facts and no legacy facts
|
||||
exos_facts:
|
||||
gather_subset:
|
||||
- '!all'
|
||||
- '!min'
|
||||
gather_network_resource:
|
||||
- lldp_global
|
||||
|
||||
- name: Gather lldp global resource and minimal legacy facts
|
||||
exos_facts:
|
||||
gather_subset: min
|
||||
gather_network_resource: lldp_global
|
||||
"""
|
||||
|
||||
RETURN = """
|
||||
ansible_net_gather_subset:
|
||||
description: The list of fact subsets collected from the device
|
||||
returned: always
|
||||
type: list
|
||||
|
||||
ansible_net_gather_network_resources:
|
||||
description: The list of fact for network resource subsets collected from the device
|
||||
returned: when the resource is configured
|
||||
type: list
|
||||
|
||||
# default
|
||||
ansible_net_model:
|
||||
description: The model name returned from the device
|
||||
returned: always
|
||||
type: str
|
||||
ansible_net_serialnum:
|
||||
description: The serial number of the remote device
|
||||
returned: always
|
||||
type: str
|
||||
ansible_net_version:
|
||||
description: The operating system version running on the remote device
|
||||
returned: always
|
||||
type: str
|
||||
ansible_net_hostname:
|
||||
description: The configured hostname of the device
|
||||
returned: always
|
||||
type: str
|
||||
|
||||
# hardware
|
||||
ansible_net_memfree_mb:
|
||||
description: The available free memory on the remote device in Mb
|
||||
returned: when hardware is configured
|
||||
type: int
|
||||
ansible_net_memtotal_mb:
|
||||
description: The total memory on the remote device in Mb
|
||||
returned: when hardware is configured
|
||||
type: int
|
||||
|
||||
# config
|
||||
ansible_net_config:
|
||||
description: The current active config from the device
|
||||
returned: when config is configured
|
||||
type: str
|
||||
|
||||
# interfaces
|
||||
ansible_net_all_ipv4_addresses:
|
||||
description: All IPv4 addresses configured on the device
|
||||
returned: when interfaces is configured
|
||||
type: list
|
||||
ansible_net_all_ipv6_addresses:
|
||||
description: All Primary IPv6 addresses configured on the device
|
||||
returned: when interfaces is configured
|
||||
type: list
|
||||
ansible_net_interfaces:
|
||||
description: A hash of all interfaces running on the system
|
||||
returned: when interfaces is configured
|
||||
type: dict
|
||||
ansible_net_neighbors:
|
||||
description: The list of LLDP neighbors from the remote device
|
||||
returned: when interfaces is configured
|
||||
type: dict
|
||||
"""
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible_collections.community.general.plugins.module_utils.network.exos.argspec.facts.facts import FactsArgs
|
||||
from ansible_collections.community.general.plugins.module_utils.network.exos.facts.facts import Facts
|
||||
|
||||
|
||||
def main():
|
||||
"""Main entry point for AnsibleModule
|
||||
"""
|
||||
argument_spec = FactsArgs.argument_spec
|
||||
|
||||
module = AnsibleModule(argument_spec=argument_spec,
|
||||
supports_check_mode=True)
|
||||
|
||||
warnings = ['default value for `gather_subset` '
|
||||
'will be changed to `min` from `!config` v2.11 onwards']
|
||||
|
||||
result = Facts(module).get_facts()
|
||||
|
||||
ansible_facts, additional_warnings = result
|
||||
warnings.extend(additional_warnings)
|
||||
|
||||
module.exit_json(ansible_facts=ansible_facts, warnings=warnings)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
1136
plugins/modules/network/exos/exos_l2_interfaces.py
Normal file
1136
plugins/modules/network/exos/exos_l2_interfaces.py
Normal file
File diff suppressed because it is too large
Load diff
429
plugins/modules/network/exos/exos_lldp_global.py
Normal file
429
plugins/modules/network/exos/exos_lldp_global.py
Normal file
|
|
@ -0,0 +1,429 @@
|
|||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2019 Red Hat
|
||||
# GNU General Public License v3.0+
|
||||
# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
#############################################
|
||||
# WARNING #
|
||||
#############################################
|
||||
#
|
||||
# This file is auto generated by the resource
|
||||
# module builder playbook.
|
||||
#
|
||||
# Do not edit this file manually.
|
||||
#
|
||||
# Changes to this file will be over written
|
||||
# by the resource module builder.
|
||||
#
|
||||
# Changes should be made in the model used to
|
||||
# generate this file or in the resource module
|
||||
# builder template.
|
||||
#
|
||||
#############################################
|
||||
|
||||
"""
|
||||
The module file for exos_lldp_global
|
||||
"""
|
||||
|
||||
from __future__ import absolute_import, division, print_function
|
||||
__metaclass__ = type
|
||||
|
||||
ANSIBLE_METADATA = {
|
||||
'metadata_version': '1.1',
|
||||
'status': ['preview'],
|
||||
'supported_by': 'community'
|
||||
}
|
||||
|
||||
DOCUMENTATION = '''
|
||||
---
|
||||
module: exos_lldp_global
|
||||
short_description: Configure and manage Link Layer Discovery Protocol(LLDP) attributes on EXOS platforms.
|
||||
description: This module configures and manages the Link Layer Discovery Protocol(LLDP) attributes on Extreme Networks EXOS platforms.
|
||||
author: Ujwal Komarla (@ujwalkomarla)
|
||||
notes:
|
||||
- Tested against Extreme Networks EXOS version 30.2.1.8 on x460g2.
|
||||
- This module works with connection C(httpapi).
|
||||
See L(EXOS Platform Options,../network/user_guide/platform_exos.html)
|
||||
options:
|
||||
config:
|
||||
description: A dictionary of LLDP options
|
||||
type: dict
|
||||
suboptions:
|
||||
interval:
|
||||
description:
|
||||
- Frequency at which LLDP advertisements are sent (in seconds). By default - 30 seconds.
|
||||
type: int
|
||||
default: 30
|
||||
tlv_select:
|
||||
description:
|
||||
- This attribute can be used to specify the TLVs that need to be sent in the LLDP packets. By default, only system name and system description is sent
|
||||
type: dict
|
||||
suboptions:
|
||||
management_address:
|
||||
description:
|
||||
- Used to specify the management address in TLV messages
|
||||
type: bool
|
||||
port_description:
|
||||
description:
|
||||
- Used to specify the port description TLV
|
||||
type: bool
|
||||
system_capabilities:
|
||||
description:
|
||||
- Used to specify the system capabilities TLV
|
||||
type: bool
|
||||
system_description:
|
||||
description:
|
||||
- Used to specify the system description TLV
|
||||
type: bool
|
||||
default: true
|
||||
system_name:
|
||||
description:
|
||||
- Used to specify the system name TLV
|
||||
type: bool
|
||||
default: true
|
||||
|
||||
state:
|
||||
description:
|
||||
- The state of the configuration after module completion.
|
||||
type: str
|
||||
choices:
|
||||
- merged
|
||||
- replaced
|
||||
- deleted
|
||||
default: merged
|
||||
'''
|
||||
EXAMPLES = """
|
||||
# Using merged
|
||||
|
||||
|
||||
# Before state:
|
||||
# -------------
|
||||
# path: /rest/restconf/data/openconfig_lldp:lldp/config
|
||||
# method: GET
|
||||
# data:
|
||||
# {
|
||||
# "openconfig_lldp:config": {
|
||||
# "enabled": true,
|
||||
# "hello-timer": 30,
|
||||
# "suppress-tlv-advertisement": [
|
||||
# "PORT_DESCRIPTION",
|
||||
# "SYSTEM_CAPABILITIES",
|
||||
# "MANAGEMENT_ADDRESS"
|
||||
# ],
|
||||
# "system-description": "ExtremeXOS (X460G2-24t-10G4) version 30.2.1.8"
|
||||
# "system-name": "X460G2-24t-10G4"
|
||||
# }
|
||||
# }
|
||||
|
||||
- name: Merge provided LLDP configuration with device configuration
|
||||
exos_lldp_global:
|
||||
config:
|
||||
interval: 10000
|
||||
tlv_select:
|
||||
system_capabilities: true
|
||||
state: merged
|
||||
|
||||
# Module Execution Results:
|
||||
# -------------------------
|
||||
#
|
||||
# "before": [
|
||||
# {
|
||||
# "interval": 30,
|
||||
# "tlv_select": {
|
||||
# "system_name": true,
|
||||
# "system_description": true
|
||||
# "port_description": false,
|
||||
# "management_address": false,
|
||||
# "system_capabilities": false
|
||||
# }
|
||||
# }
|
||||
# ]
|
||||
#
|
||||
# "requests": [
|
||||
# {
|
||||
# "data": {
|
||||
# "openconfig_lldp:config": {
|
||||
# "hello-timer": 10000,
|
||||
# "suppress-tlv-advertisement": [
|
||||
# "PORT_DESCRIPTION",
|
||||
# "MANAGEMENT_ADDRESS"
|
||||
# ]
|
||||
# }
|
||||
# },
|
||||
# "method": "PATCH",
|
||||
# "path": "/rest/restconf/data/openconfig_lldp:lldp/config"
|
||||
# }
|
||||
# ]
|
||||
#
|
||||
# "after": [
|
||||
# {
|
||||
# "interval": 10000,
|
||||
# "tlv_select": {
|
||||
# "system_name": true,
|
||||
# "system_description": true,
|
||||
# "port_description": false,
|
||||
# "management_address": false,
|
||||
# "system_capabilities": true
|
||||
# }
|
||||
# }
|
||||
# ]
|
||||
|
||||
|
||||
# After state:
|
||||
# -------------
|
||||
# path: /rest/restconf/data/openconfig_lldp:lldp/config
|
||||
# method: GET
|
||||
# data:
|
||||
# {
|
||||
# "openconfig_lldp:config": {
|
||||
# "enabled": true,
|
||||
# "hello-timer": 10000,
|
||||
# "suppress-tlv-advertisement": [
|
||||
# "PORT_DESCRIPTION",
|
||||
# "MANAGEMENT_ADDRESS"
|
||||
# ],
|
||||
# "system-description": "ExtremeXOS (X460G2-24t-10G4) version 30.2.1.8"
|
||||
# "system-name": "X460G2-24t-10G4"
|
||||
# }
|
||||
# }
|
||||
|
||||
|
||||
# Using replaced
|
||||
|
||||
|
||||
# Before state:
|
||||
# -------------
|
||||
# path: /rest/restconf/data/openconfig_lldp:lldp/config
|
||||
# method: GET
|
||||
# data:
|
||||
# {
|
||||
# "openconfig_lldp:config": {
|
||||
# "enabled": true,
|
||||
# "hello-timer": 30,
|
||||
# "suppress-tlv-advertisement": [
|
||||
# "PORT_DESCRIPTION",
|
||||
# "SYSTEM_CAPABILITIES",
|
||||
# "MANAGEMENT_ADDRESS"
|
||||
# ],
|
||||
# "system-description": "ExtremeXOS (X460G2-24t-10G4) version 30.2.1.8"
|
||||
# "system-name": "X460G2-24t-10G4"
|
||||
# }
|
||||
# }
|
||||
|
||||
- name: Replace device configuration with provided LLDP configuration
|
||||
exos_lldp_global:
|
||||
config:
|
||||
interval: 10000
|
||||
tlv_select:
|
||||
system_capabilities: true
|
||||
state: replaced
|
||||
|
||||
# Module Execution Results:
|
||||
# -------------------------
|
||||
#
|
||||
# "before": [
|
||||
# {
|
||||
# "interval": 30,
|
||||
# "tlv_select": {
|
||||
# "system_name": true,
|
||||
# "system_description": true
|
||||
# "port_description": false,
|
||||
# "management_address": false,
|
||||
# "system_capabilities": false
|
||||
# }
|
||||
# }
|
||||
# ]
|
||||
#
|
||||
# "requests": [
|
||||
# {
|
||||
# "data": {
|
||||
# "openconfig_lldp:config": {
|
||||
# "hello-timer": 10000,
|
||||
# "suppress-tlv-advertisement": [
|
||||
# "SYSTEM_NAME",
|
||||
# "SYSTEM_DESCRIPTION",
|
||||
# "PORT_DESCRIPTION",
|
||||
# "MANAGEMENT_ADDRESS"
|
||||
# ]
|
||||
# }
|
||||
# },
|
||||
# "method": "PATCH",
|
||||
# "path": "/rest/restconf/data/openconfig_lldp:lldp/config"
|
||||
# }
|
||||
# ]
|
||||
#
|
||||
# "after": [
|
||||
# {
|
||||
# "interval": 10000,
|
||||
# "tlv_select": {
|
||||
# "system_name": false,
|
||||
# "system_description": false,
|
||||
# "port_description": false,
|
||||
# "management_address": false,
|
||||
# "system_capabilities": true
|
||||
# }
|
||||
# }
|
||||
# ]
|
||||
|
||||
|
||||
# After state:
|
||||
# -------------
|
||||
# path: /rest/restconf/data/openconfig_lldp:lldp/config
|
||||
# method: GET
|
||||
# data:
|
||||
# {
|
||||
# "openconfig_lldp:config": {
|
||||
# "enabled": true,
|
||||
# "hello-timer": 10000,
|
||||
# "suppress-tlv-advertisement": [
|
||||
# "SYSTEM_NAME",
|
||||
# "SYSTEM_DESCRIPTION",
|
||||
# "PORT_DESCRIPTION",
|
||||
# "MANAGEMENT_ADDRESS"
|
||||
# ],
|
||||
# "system-description": "ExtremeXOS (X460G2-24t-10G4) version 30.2.1.8"
|
||||
# "system-name": "X460G2-24t-10G4"
|
||||
# }
|
||||
# }
|
||||
|
||||
|
||||
# Using deleted
|
||||
|
||||
|
||||
# Before state:
|
||||
# -------------
|
||||
# path: /rest/restconf/data/openconfig_lldp:lldp/config
|
||||
# method: GET
|
||||
# data:
|
||||
# {
|
||||
# "openconfig_lldp:config": {
|
||||
# "enabled": true,
|
||||
# "hello-timer": 10000,
|
||||
# "suppress-tlv-advertisement": [
|
||||
# "SYSTEM_CAPABILITIES",
|
||||
# "MANAGEMENT_ADDRESS"
|
||||
# ],
|
||||
# "system-description": "ExtremeXOS (X460G2-24t-10G4) version 30.2.1.8"
|
||||
# "system-name": "X460G2-24t-10G4"
|
||||
# }
|
||||
# }
|
||||
|
||||
- name: Delete attributes of given LLDP service (This won't delete the LLDP service itself)
|
||||
exos_lldp_global:
|
||||
config:
|
||||
state: deleted
|
||||
|
||||
# Module Execution Results:
|
||||
# -------------------------
|
||||
#
|
||||
# "before": [
|
||||
# {
|
||||
# "interval": 10000,
|
||||
# "tlv_select": {
|
||||
# "system_name": true,
|
||||
# "system_description": true,
|
||||
# "port_description": true,
|
||||
# "management_address": false,
|
||||
# "system_capabilities": false
|
||||
# }
|
||||
# }
|
||||
# ]
|
||||
#
|
||||
# "requests": [
|
||||
# {
|
||||
# "data": {
|
||||
# "openconfig_lldp:config": {
|
||||
# "hello-timer": 30,
|
||||
# "suppress-tlv-advertisement": [
|
||||
# "SYSTEM_CAPABILITIES",
|
||||
# "PORT_DESCRIPTION",
|
||||
# "MANAGEMENT_ADDRESS"
|
||||
# ]
|
||||
# }
|
||||
# },
|
||||
# "method": "PATCH",
|
||||
# "path": "/rest/restconf/data/openconfig_lldp:lldp/config"
|
||||
# }
|
||||
# ]
|
||||
#
|
||||
# "after": [
|
||||
# {
|
||||
# "interval": 30,
|
||||
# "tlv_select": {
|
||||
# "system_name": true,
|
||||
# "system_description": true,
|
||||
# "port_description": false,
|
||||
# "management_address": false,
|
||||
# "system_capabilities": false
|
||||
# }
|
||||
# }
|
||||
# ]
|
||||
|
||||
|
||||
# After state:
|
||||
# -------------
|
||||
# path: /rest/restconf/data/openconfig_lldp:lldp/config
|
||||
# method: GET
|
||||
# data:
|
||||
# {
|
||||
# "openconfig_lldp:config": {
|
||||
# "enabled": true,
|
||||
# "hello-timer": 30,
|
||||
# "suppress-tlv-advertisement": [
|
||||
# "SYSTEM_CAPABILITIES",
|
||||
# "PORT_DESCRIPTION",
|
||||
# "MANAGEMENT_ADDRESS"
|
||||
# ],
|
||||
# "system-description": "ExtremeXOS (X460G2-24t-10G4) version 30.2.1.8"
|
||||
# "system-name": "X460G2-24t-10G4"
|
||||
# }
|
||||
# }
|
||||
|
||||
|
||||
"""
|
||||
RETURN = """
|
||||
before:
|
||||
description: The configuration as structured data prior to module invocation.
|
||||
returned: always
|
||||
sample: >
|
||||
The configuration returned will always be in the same format
|
||||
of the parameters above.
|
||||
type: list
|
||||
after:
|
||||
description: The configuration as structured data after module completion.
|
||||
returned: when changed
|
||||
sample: >
|
||||
The configuration returned will always be in the same format
|
||||
of the parameters above.
|
||||
type: list
|
||||
requests:
|
||||
description: The set of requests pushed to the remote device.
|
||||
returned: always
|
||||
type: list
|
||||
sample: [{"data": "...", "method": "...", "path": "..."}, {"data": "...", "method": "...", "path": "..."}, {"data": "...", "method": "...", "path": "..."}]
|
||||
"""
|
||||
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible_collections.community.general.plugins.module_utils.network.exos.argspec.lldp_global.lldp_global import Lldp_globalArgs
|
||||
from ansible_collections.community.general.plugins.module_utils.network.exos.config.lldp_global.lldp_global import Lldp_global
|
||||
|
||||
|
||||
def main():
|
||||
"""
|
||||
Main entry point for module execution
|
||||
|
||||
:returns: the result form module invocation
|
||||
"""
|
||||
required_if = [('state', 'merged', ('config',)),
|
||||
('state', 'replaced', ('config',))]
|
||||
module = AnsibleModule(argument_spec=Lldp_globalArgs.argument_spec, required_if=required_if,
|
||||
supports_check_mode=True)
|
||||
|
||||
result = Lldp_global(module).execute_module()
|
||||
module.exit_json(**result)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
679
plugins/modules/network/exos/exos_lldp_interfaces.py
Normal file
679
plugins/modules/network/exos/exos_lldp_interfaces.py
Normal file
|
|
@ -0,0 +1,679 @@
|
|||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2019 Red Hat
|
||||
# GNU General Public License v3.0+
|
||||
# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
#############################################
|
||||
# WARNING #
|
||||
#############################################
|
||||
#
|
||||
# This file is auto generated by the resource
|
||||
# module builder playbook.
|
||||
#
|
||||
# Do not edit this file manually.
|
||||
#
|
||||
# Changes to this file will be over written
|
||||
# by the resource module builder.
|
||||
#
|
||||
# Changes should be made in the model used to
|
||||
# generate this file or in the resource module
|
||||
# builder template.
|
||||
#
|
||||
#############################################
|
||||
"""
|
||||
The module file for exos_lldp_interfaces
|
||||
"""
|
||||
|
||||
from __future__ import absolute_import, division, print_function
|
||||
__metaclass__ = type
|
||||
|
||||
ANSIBLE_METADATA = {
|
||||
'metadata_version': '1.1',
|
||||
'status': ['preview'],
|
||||
'supported_by': 'community'
|
||||
}
|
||||
|
||||
DOCUMENTATION = '''
|
||||
---
|
||||
module: exos_lldp_interfaces
|
||||
short_description: Manage link layer discovery protocol (LLDP) attributes of interfaces on EXOS platforms.
|
||||
description:
|
||||
- This module manages link layer discovery protocol (LLDP) attributes of interfaces on Extreme Networks EXOS platforms.
|
||||
author: Jayalakshmi Viswanathan (@JayalakshmiV)
|
||||
options:
|
||||
config:
|
||||
description: The list of link layer discovery protocol interface attribute configurations
|
||||
type: list
|
||||
elements: dict
|
||||
suboptions:
|
||||
name:
|
||||
description:
|
||||
- Name of the interface LLDP needs to be configured on.
|
||||
type: str
|
||||
required: True
|
||||
enabled:
|
||||
description:
|
||||
- This is a boolean value to control disabling of LLDP on the interface C(name)
|
||||
type: bool
|
||||
state:
|
||||
description:
|
||||
- The state the configuration should be left in.
|
||||
type: str
|
||||
choices:
|
||||
- merged
|
||||
- replaced
|
||||
- overridden
|
||||
- deleted
|
||||
default: merged
|
||||
'''
|
||||
EXAMPLES = """
|
||||
# Using merged
|
||||
|
||||
# Before state:
|
||||
# -------------
|
||||
#
|
||||
# path: /rest/restconf/data/openconfig-lldp:lldp/interfaces?depth=4
|
||||
# method: GET
|
||||
# data:
|
||||
# {
|
||||
# "openconfig-lldp:interfaces": {
|
||||
# "interface": [
|
||||
# {
|
||||
# "config": {
|
||||
# "enabled": true,
|
||||
# "name": "1"
|
||||
# }
|
||||
# },
|
||||
# {
|
||||
# "config": {
|
||||
# "enabled": true,
|
||||
# "name": "2"
|
||||
# }
|
||||
# },
|
||||
# {
|
||||
# "config": {
|
||||
# "enabled": false,
|
||||
# "name": "3"
|
||||
# }
|
||||
# },
|
||||
# {
|
||||
# "config": {
|
||||
# "enabled": true,
|
||||
# "name": "4"
|
||||
# }
|
||||
# },
|
||||
# {
|
||||
# "config": {
|
||||
# "enabled": false,
|
||||
# "name": "5"
|
||||
# }
|
||||
# }
|
||||
# ]
|
||||
# }
|
||||
# }
|
||||
|
||||
- name: Merge provided configuration with device configuration
|
||||
exos_lldp_interfaces:
|
||||
config:
|
||||
- name: '2'
|
||||
enabled: false
|
||||
- name: '5'
|
||||
enabled: true
|
||||
state: merged
|
||||
|
||||
# Module Execution Results:
|
||||
# -------------------------
|
||||
#
|
||||
# "before":
|
||||
# - name: '1'
|
||||
# enabled: True
|
||||
# - name: '2'
|
||||
# enabled: True
|
||||
# - name: '3'
|
||||
# enabled: False
|
||||
# - name: '4'
|
||||
# enabled: True
|
||||
# - name: '5'
|
||||
# enabled: False
|
||||
#
|
||||
# "requests": [
|
||||
# {
|
||||
# "data": |
|
||||
# {
|
||||
# "openconfig-lldp:config": {
|
||||
# "enabled": false,
|
||||
# "name": "2"
|
||||
# }
|
||||
# }
|
||||
# "method": "PATCH",
|
||||
# "path": "/rest/restconf/data/openconfig-lldp:lldp/interfaces/interface=2/config"
|
||||
# },
|
||||
# {
|
||||
# "data": |
|
||||
# {
|
||||
# "openconfig-lldp:config": {
|
||||
# "enabled": true,
|
||||
# "name": "5"
|
||||
# }
|
||||
# }
|
||||
# "method": "PATCH",
|
||||
# "path": "/rest/restconf/data/openconfig-lldp:lldp/interfaces/interface=5/config"
|
||||
# }
|
||||
# ]
|
||||
#
|
||||
# "after":
|
||||
# - name: '1'
|
||||
# enabled: True
|
||||
# - name: '2'
|
||||
# enabled: False
|
||||
# - name: '3'
|
||||
# enabled: False
|
||||
# - name: '4'
|
||||
# enabled: True
|
||||
# - name: '5'
|
||||
# enabled: True
|
||||
|
||||
# After state:
|
||||
# -------------
|
||||
#
|
||||
# path: /rest/restconf/data/openconfig-lldp:lldp/interfaces?depth=4
|
||||
# method: GET
|
||||
# data:
|
||||
# {
|
||||
# "openconfig-lldp:interfaces": {
|
||||
# "interface": [
|
||||
# {
|
||||
# "config": {
|
||||
# "enabled": true,
|
||||
# "name": "1"
|
||||
# }
|
||||
# },
|
||||
# {
|
||||
# "config": {
|
||||
# "enabled": false,
|
||||
# "name": "2"
|
||||
# }
|
||||
# },
|
||||
# {
|
||||
# "config": {
|
||||
# "enabled": false,
|
||||
# "name": "3"
|
||||
# }
|
||||
# },
|
||||
# {
|
||||
# "config": {
|
||||
# "enabled": true,
|
||||
# "name": "4"
|
||||
# }
|
||||
# },
|
||||
# {
|
||||
# "config": {
|
||||
# "enabled": true,
|
||||
# "name": "5"
|
||||
# }
|
||||
# }
|
||||
# ]
|
||||
# }
|
||||
# }
|
||||
|
||||
|
||||
# Using replaced
|
||||
|
||||
# Before state:
|
||||
# -------------
|
||||
#
|
||||
# path: /rest/restconf/data/openconfig-lldp:lldp/interfaces?depth=4
|
||||
# method: GET
|
||||
# data:
|
||||
# {
|
||||
# "openconfig-lldp:interfaces": {
|
||||
# "interface": [
|
||||
# {
|
||||
# "config": {
|
||||
# "enabled": true,
|
||||
# "name": "1"
|
||||
# }
|
||||
# },
|
||||
# {
|
||||
# "config": {
|
||||
# "enabled": true,
|
||||
# "name": "2"
|
||||
# }
|
||||
# },
|
||||
# {
|
||||
# "config": {
|
||||
# "enabled": false,
|
||||
# "name": "3"
|
||||
# }
|
||||
# },
|
||||
# {
|
||||
# "config": {
|
||||
# "enabled": true,
|
||||
# "name": "4"
|
||||
# }
|
||||
# },
|
||||
# {
|
||||
# "config": {
|
||||
# "enabled": false,
|
||||
# "name": "5"
|
||||
# }
|
||||
# }
|
||||
# ]
|
||||
# }
|
||||
# }
|
||||
|
||||
- name: Replaces device configuration of listed lldp_interfaces with provided configuration
|
||||
exos_lldp_interfaces:
|
||||
config:
|
||||
- name: '1'
|
||||
enabled: false
|
||||
- name: '3'
|
||||
enabled: true
|
||||
state: merged
|
||||
|
||||
# Module Execution Results:
|
||||
# -------------------------
|
||||
#
|
||||
# "before":
|
||||
# - name: '1'
|
||||
# enabled: True
|
||||
# - name: '2'
|
||||
# enabled: True
|
||||
# - name: '3'
|
||||
# enabled: False
|
||||
# - name: '4'
|
||||
# enabled: True
|
||||
# - name: '5'
|
||||
# enabled: False
|
||||
#
|
||||
# "requests": [
|
||||
# {
|
||||
# "data": |
|
||||
# {
|
||||
# "openconfig-lldp:config": {
|
||||
# "enabled": false,
|
||||
# "name": "1"
|
||||
# }
|
||||
# }
|
||||
# "method": "PATCH",
|
||||
# "path": "/rest/restconf/data/openconfig-lldp:lldp/interfaces/interface=1/config"
|
||||
# },
|
||||
# {
|
||||
# "data": |
|
||||
# {
|
||||
# "openconfig-lldp:config": {
|
||||
# "enabled": true,
|
||||
# "name": "3"
|
||||
# }
|
||||
# }
|
||||
# "method": "PATCH",
|
||||
# "path": "/rest/restconf/data/openconfig-lldp:lldp/interfaces/interface=3/config"
|
||||
# }
|
||||
# ]
|
||||
#
|
||||
# "after":
|
||||
# - name: '1'
|
||||
# enabled: False
|
||||
# - name: '2'
|
||||
# enabled: True
|
||||
# - name: '3'
|
||||
# enabled: True
|
||||
# - name: '4'
|
||||
# enabled: True
|
||||
# - name: '5'
|
||||
# enabled: False
|
||||
|
||||
# After state:
|
||||
# -------------
|
||||
#
|
||||
# path: /rest/restconf/data/openconfig-lldp:lldp/interfaces?depth=4
|
||||
# method: GET
|
||||
# data:
|
||||
# {
|
||||
# "openconfig-lldp:interfaces": {
|
||||
# "interface": [
|
||||
# {
|
||||
# "config": {
|
||||
# "enabled": false,
|
||||
# "name": "1"
|
||||
# }
|
||||
# },
|
||||
# {
|
||||
# "config": {
|
||||
# "enabled": true,
|
||||
# "name": "2"
|
||||
# }
|
||||
# },
|
||||
# {
|
||||
# "config": {
|
||||
# "enabled": true,
|
||||
# "name": "3"
|
||||
# }
|
||||
# },
|
||||
# {
|
||||
# "config": {
|
||||
# "enabled": true,
|
||||
# "name": "4"
|
||||
# }
|
||||
# },
|
||||
# {
|
||||
# "config": {
|
||||
# "enabled": false,
|
||||
# "name": "5"
|
||||
# }
|
||||
# }
|
||||
# ]
|
||||
# }
|
||||
# }
|
||||
|
||||
|
||||
# Using deleted
|
||||
|
||||
# Before state:
|
||||
# -------------
|
||||
#
|
||||
# path: /rest/restconf/data/openconfig-lldp:lldp/interfaces?depth=4
|
||||
# method: GET
|
||||
# data:
|
||||
# {
|
||||
# "openconfig-lldp:interfaces": {
|
||||
# "interface": [
|
||||
# {
|
||||
# "config": {
|
||||
# "enabled": false,
|
||||
# "name": "1"
|
||||
# },
|
||||
# },
|
||||
# {
|
||||
# "config": {
|
||||
# "enabled": false,
|
||||
# "name": "2"
|
||||
# },
|
||||
# },
|
||||
# {
|
||||
# "config": {
|
||||
# "enabled": false,
|
||||
# "name": "3"
|
||||
# },
|
||||
# }
|
||||
# ]
|
||||
# }
|
||||
# }
|
||||
|
||||
- name: Delete lldp interface configuration (this will not delete other lldp configuration)
|
||||
exos_lldp_interfaces:
|
||||
config:
|
||||
- name: '1'
|
||||
- name: '3'
|
||||
state: deleted
|
||||
|
||||
# Module Execution Results:
|
||||
# -------------------------
|
||||
#
|
||||
# "before":
|
||||
# - name: '1'
|
||||
# enabled: False
|
||||
# - name: '2'
|
||||
# enabled: False
|
||||
# - name: '3'
|
||||
# enabled: False
|
||||
#
|
||||
# "requests": [
|
||||
# {
|
||||
# "data": |
|
||||
# {
|
||||
# "openconfig-lldp:config": {
|
||||
# "enabled": true,
|
||||
# "name": "1"
|
||||
# }
|
||||
# }
|
||||
# "method": "PATCH",
|
||||
# "path": "/rest/restconf/data/openconfig-lldp:lldp/interfaces/interface=1/config"
|
||||
# },
|
||||
# {
|
||||
# "data": |
|
||||
# {
|
||||
# "openconfig-lldp:config": {
|
||||
# "enabled": true,
|
||||
# "name": "3"
|
||||
# }
|
||||
# }
|
||||
# "method": "PATCH",
|
||||
# "path": "/rest/restconf/data/openconfig-lldp:lldp/interfaces/interface=3/config"
|
||||
# }
|
||||
# ]
|
||||
#
|
||||
# "after":
|
||||
# - name: '1'
|
||||
# enabled: True
|
||||
# - name: '2'
|
||||
# enabled: False
|
||||
# - name: '3'
|
||||
# enabled: True
|
||||
#
|
||||
# After state:
|
||||
# -------------
|
||||
# path: /rest/restconf/data/openconfig-lldp:lldp/interfaces?depth=4
|
||||
# method: GET
|
||||
# data:
|
||||
# {
|
||||
# "openconfig-lldp:interfaces": {
|
||||
# "interface": [
|
||||
# {
|
||||
# "config": {
|
||||
# "enabled": true,
|
||||
# "name": "1"
|
||||
# },
|
||||
# },
|
||||
# {
|
||||
# "config": {
|
||||
# "enabled": false,
|
||||
# "name": "2"
|
||||
# },
|
||||
# },
|
||||
# {
|
||||
# "config": {
|
||||
# "enabled": true,
|
||||
# "name": "3"
|
||||
# },
|
||||
# }
|
||||
# ]
|
||||
# }
|
||||
# }
|
||||
|
||||
|
||||
# Using overridden
|
||||
|
||||
# Before state:
|
||||
# -------------
|
||||
#
|
||||
# path: /rest/restconf/data/openconfig-lldp:lldp/interfaces?depth=4
|
||||
# method: GET
|
||||
# data:
|
||||
# {
|
||||
# "openconfig-lldp:interfaces": {
|
||||
# "interface": [
|
||||
# {
|
||||
# "config": {
|
||||
# "enabled": true,
|
||||
# "name": "1"
|
||||
# }
|
||||
# },
|
||||
# {
|
||||
# "config": {
|
||||
# "enabled": true,
|
||||
# "name": "2"
|
||||
# }
|
||||
# },
|
||||
# {
|
||||
# "config": {
|
||||
# "enabled": false,
|
||||
# "name": "3"
|
||||
# }
|
||||
# },
|
||||
# {
|
||||
# "config": {
|
||||
# "enabled": true,
|
||||
# "name": "4"
|
||||
# }
|
||||
# },
|
||||
# {
|
||||
# "config": {
|
||||
# "enabled": false,
|
||||
# "name": "5"
|
||||
# }
|
||||
# }
|
||||
# ]
|
||||
# }
|
||||
# }
|
||||
|
||||
- name: Override device configuration of all lldp_interfaces with provided configuration
|
||||
exos_lldp_interfaces:
|
||||
config:
|
||||
- name: '3'
|
||||
enabled: true
|
||||
state: overridden
|
||||
|
||||
# Module Execution Results:
|
||||
# -------------------------
|
||||
#
|
||||
# "before":
|
||||
# - name: '1'
|
||||
# enabled: True
|
||||
# - name: '2'
|
||||
# enabled: True
|
||||
# - name: '3'
|
||||
# enabled: False
|
||||
# - name: '4'
|
||||
# enabled: True
|
||||
# - name: '5'
|
||||
# enabled: False
|
||||
#
|
||||
# "requests": [
|
||||
# {
|
||||
# "data": |
|
||||
# {
|
||||
# "openconfig-lldp:config": {
|
||||
# "enabled": true,
|
||||
# "name": "5"
|
||||
# }
|
||||
# }
|
||||
# "method": "PATCH",
|
||||
# "path": "/rest/restconf/data/openconfig-lldp:lldp/interfaces/interface=5/config"
|
||||
# },
|
||||
# {
|
||||
# "data": |
|
||||
# {
|
||||
# "openconfig-lldp:config": {
|
||||
# "enabled": true,
|
||||
# "name": "3"
|
||||
# }
|
||||
# }
|
||||
# "method": "PATCH",
|
||||
# "path": "/rest/restconf/data/openconfig-lldp:lldp/interfaces/interface=3/config"
|
||||
# }
|
||||
# ]
|
||||
#
|
||||
# "after":
|
||||
# - name: '1'
|
||||
# enabled: True
|
||||
# - name: '2'
|
||||
# enabled: True
|
||||
# - name: '3'
|
||||
# enabled: True
|
||||
# - name: '4'
|
||||
# enabled: True
|
||||
# - name: '5'
|
||||
# enabled: True
|
||||
|
||||
# After state:
|
||||
# -------------
|
||||
#
|
||||
# path: /rest/restconf/data/openconfig-lldp:lldp/interfaces?depth=4
|
||||
# method: GET
|
||||
# data:
|
||||
# {
|
||||
# "openconfig-lldp:interfaces": {
|
||||
# "interface": [
|
||||
# {
|
||||
# "config": {
|
||||
# "enabled": true,
|
||||
# "name": "1"
|
||||
# }
|
||||
# },
|
||||
# {
|
||||
# "config": {
|
||||
# "enabled": true,
|
||||
# "name": "2"
|
||||
# }
|
||||
# },
|
||||
# {
|
||||
# "config": {
|
||||
# "enabled": true,
|
||||
# "name": "3"
|
||||
# }
|
||||
# },
|
||||
# {
|
||||
# "config": {
|
||||
# "enabled": true,
|
||||
# "name": "4"
|
||||
# }
|
||||
# },
|
||||
# {
|
||||
# "config": {
|
||||
# "enabled": true,
|
||||
# "name": "5"
|
||||
# }
|
||||
# }
|
||||
# ]
|
||||
# }
|
||||
# }
|
||||
|
||||
|
||||
"""
|
||||
RETURN = """
|
||||
before:
|
||||
description: The configuration prior to the model invocation.
|
||||
returned: always
|
||||
sample: >
|
||||
The configuration returned will always be in the same format
|
||||
of the parameters above.
|
||||
type: list
|
||||
after:
|
||||
description: The resulting configuration model invocation.
|
||||
returned: when changed
|
||||
sample: >
|
||||
The configuration returned will always be in the same format
|
||||
of the parameters above.
|
||||
type: list
|
||||
requests:
|
||||
description: The set of requests pushed to the remote device.
|
||||
returned: always
|
||||
type: list
|
||||
sample: [{"data": "...", "method": "...", "path": "..."}, {"data": "...", "method": "...", "path": "..."}, {"data": "...", "method": "...", "path": "..."}]
|
||||
"""
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible_collections.community.general.plugins.module_utils.network.exos.argspec.lldp_interfaces.lldp_interfaces import Lldp_interfacesArgs
|
||||
from ansible_collections.community.general.plugins.module_utils.network.exos.config.lldp_interfaces.lldp_interfaces import Lldp_interfaces
|
||||
|
||||
|
||||
def main():
|
||||
"""
|
||||
Main entry point for module execution
|
||||
|
||||
:returns: the result form module invocation
|
||||
"""
|
||||
required_if = [('state', 'merged', ('config', )),
|
||||
('state', 'replaced', ('config', ))]
|
||||
module = AnsibleModule(argument_spec=Lldp_interfacesArgs.argument_spec,
|
||||
required_if=required_if,
|
||||
supports_check_mode=True)
|
||||
|
||||
result = Lldp_interfaces(module).execute_module()
|
||||
module.exit_json(**result)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
758
plugins/modules/network/exos/exos_vlans.py
Normal file
758
plugins/modules/network/exos/exos_vlans.py
Normal file
|
|
@ -0,0 +1,758 @@
|
|||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2019 Red Hat
|
||||
# GNU General Public License v3.0+
|
||||
# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
#############################################
|
||||
# WARNING #
|
||||
#############################################
|
||||
#
|
||||
# This file is auto generated by the resource
|
||||
# module builder playbook.
|
||||
#
|
||||
# Do not edit this file manually.
|
||||
#
|
||||
# Changes to this file will be over written
|
||||
# by the resource module builder.
|
||||
#
|
||||
# Changes should be made in the model used to
|
||||
# generate this file or in the resource module
|
||||
# builder template.
|
||||
#
|
||||
#############################################
|
||||
|
||||
"""
|
||||
The module file for exos_vlans
|
||||
"""
|
||||
|
||||
from __future__ import absolute_import, division, print_function
|
||||
__metaclass__ = type
|
||||
|
||||
ANSIBLE_METADATA = {
|
||||
'metadata_version': '1.1',
|
||||
'status': ['preview'],
|
||||
'supported_by': 'community'
|
||||
}
|
||||
|
||||
DOCUMENTATION = '''
|
||||
---
|
||||
module: exos_vlans
|
||||
short_description: Manage VLANs on Extreme Networks EXOS devices.
|
||||
description: This module provides declarative management of VLANs on Extreme Networks EXOS network devices.
|
||||
author: Jayalakshmi Viswanathan (@jayalakshmiV)
|
||||
notes:
|
||||
- Tested against EXOS 30.2.1.8
|
||||
- This module works with connection C(httpapi).
|
||||
See L(EXOS Platform Options,../network/user_guide/platform_exos.html)
|
||||
options:
|
||||
config:
|
||||
description: A dictionary of VLANs options
|
||||
type: list
|
||||
elements: dict
|
||||
suboptions:
|
||||
name:
|
||||
description:
|
||||
- Ascii name of the VLAN.
|
||||
type: str
|
||||
vlan_id:
|
||||
description:
|
||||
- ID of the VLAN. Range 1-4094
|
||||
type: int
|
||||
required: True
|
||||
state:
|
||||
description:
|
||||
- Operational state of the VLAN
|
||||
type: str
|
||||
choices:
|
||||
- active
|
||||
- suspend
|
||||
default: active
|
||||
state:
|
||||
description:
|
||||
- The state the configuration should be left in
|
||||
type: str
|
||||
choices:
|
||||
- merged
|
||||
- replaced
|
||||
- overridden
|
||||
- deleted
|
||||
default: merged
|
||||
'''
|
||||
EXAMPLES = """
|
||||
# Using deleted
|
||||
|
||||
# Before state:
|
||||
# -------------
|
||||
#
|
||||
# path: /rest/restconf/data/openconfig-vlan:vlans/
|
||||
# method: GET
|
||||
# data:
|
||||
# {
|
||||
# "openconfig-vlan:vlans": {
|
||||
# "vlan": [
|
||||
# {
|
||||
# "config": {
|
||||
# "name": "Default",
|
||||
# "status": "ACTIVE",
|
||||
# "tpid": "oc-vlan-types:TPID_0x8100",
|
||||
# "vlan-id": 1
|
||||
# },
|
||||
# },
|
||||
# {
|
||||
# "config": {
|
||||
# "name": "vlan_10",
|
||||
# "status": "ACTIVE",
|
||||
# "tpid": "oc-vlan-types:TPID_0x8100",
|
||||
# "vlan-id": 10
|
||||
# },
|
||||
# },
|
||||
# {
|
||||
# "config": {
|
||||
# "name": "vlan_20",
|
||||
# "status": "ACTIVE",
|
||||
# "tpid": "oc-vlan-types:TPID_0x8100",
|
||||
# "vlan-id": 20
|
||||
# },
|
||||
# },
|
||||
# {
|
||||
# "config": {
|
||||
# "name": "vlan_30",
|
||||
# "status": "ACTIVE",
|
||||
# "tpid": "oc-vlan-types:TPID_0x8100",
|
||||
# "vlan-id": 30
|
||||
# },
|
||||
# }
|
||||
# ]
|
||||
# }
|
||||
# }
|
||||
|
||||
- name: Delete attributes of given VLANs
|
||||
exos_vlans:
|
||||
config:
|
||||
- vlan_id: 10
|
||||
- vlan_id: 20
|
||||
- vlan_id: 30
|
||||
state: deleted
|
||||
|
||||
# Module Execution Results:
|
||||
# -------------------------
|
||||
#
|
||||
# "after": [
|
||||
# {
|
||||
# "name": "Default",
|
||||
# "state": "active",
|
||||
# "vlan_id": 1
|
||||
# }
|
||||
# ],
|
||||
#
|
||||
# "before": [
|
||||
# {
|
||||
# "name": "Default",
|
||||
# "state": "active",
|
||||
# "vlan_id": 1
|
||||
# },
|
||||
# {
|
||||
# "name": "vlan_10",
|
||||
# "state": "active",
|
||||
# "vlan_id": 10
|
||||
# },
|
||||
# {
|
||||
# "name": "vlan_20",
|
||||
# "state": "active",
|
||||
# "vlan_id": 20
|
||||
# }
|
||||
# {
|
||||
# "name": "vlan_30",
|
||||
# "state": "active",
|
||||
# "vlan_id": 30
|
||||
# }
|
||||
# ],
|
||||
#
|
||||
# "requests": [
|
||||
# {
|
||||
# "data": null,
|
||||
# "method": "DELETE",
|
||||
# "path": "/rest/restconf/data/openconfig-vlan:vlans/vlan=10"
|
||||
# },
|
||||
# {
|
||||
# "data": null,
|
||||
# "method": "DELETE",
|
||||
# "path": "/rest/restconf/data/openconfig-vlan:vlans/vlan=20"
|
||||
# },
|
||||
# {
|
||||
# "data": null,
|
||||
# "method": "DELETE",
|
||||
# "path": "/rest/restconf/data/openconfig-vlan:vlans/vlan=30"
|
||||
# }
|
||||
# ]
|
||||
#
|
||||
#
|
||||
# After state:
|
||||
# -------------
|
||||
#
|
||||
# path: /rest/restconf/data/openconfig-vlan:vlans/
|
||||
# method: GET
|
||||
# data:
|
||||
# {
|
||||
# "openconfig-vlan:vlans": {
|
||||
# "vlan": [
|
||||
# {
|
||||
# "config": {
|
||||
# "name": "Default",
|
||||
# "status": "ACTIVE",
|
||||
# "tpid": "oc-vlan-types:TPID_0x8100",
|
||||
# "vlan-id": 1
|
||||
# },
|
||||
# }
|
||||
# ]
|
||||
# }
|
||||
# }
|
||||
|
||||
|
||||
# Using merged
|
||||
|
||||
# Before state:
|
||||
# -------------
|
||||
# path: /rest/restconf/data/openconfig-vlan:vlans/
|
||||
# method: GET
|
||||
# data:
|
||||
# {
|
||||
# "openconfig-vlan:vlans": {
|
||||
# "vlan": [
|
||||
# {
|
||||
# "config": {
|
||||
# "name": "Default",
|
||||
# "status": "ACTIVE",
|
||||
# "tpid": "oc-vlan-types:TPID_0x8100",
|
||||
# "vlan-id": 1
|
||||
# },
|
||||
# }
|
||||
# ]
|
||||
# }
|
||||
# }
|
||||
|
||||
- name: Merge provided configuration with device configuration
|
||||
exos_vlans:
|
||||
config:
|
||||
- name: vlan_10
|
||||
vlan_id: 10
|
||||
state: active
|
||||
- name: vlan_20
|
||||
vlan_id: 20
|
||||
state: active
|
||||
- name: vlan_30
|
||||
vlan_id: 30
|
||||
state: active
|
||||
state: merged
|
||||
|
||||
# Module Execution Results:
|
||||
# -------------------------
|
||||
#
|
||||
# "after": [
|
||||
# {
|
||||
# "name": "Default",
|
||||
# "state": "active",
|
||||
# "vlan_id": 1
|
||||
# },
|
||||
# {
|
||||
# "name": "vlan_10",
|
||||
# "state": "active",
|
||||
# "vlan_id": 10
|
||||
# },
|
||||
# {
|
||||
# "name": "vlan_20",
|
||||
# "state": "active",
|
||||
# "vlan_id": 20
|
||||
# },
|
||||
# {
|
||||
# "name": "vlan_30",
|
||||
# "state": "active",
|
||||
# "vlan_id": 30
|
||||
# }
|
||||
# ],
|
||||
#
|
||||
# "before": [
|
||||
# {
|
||||
# "name": "Default",
|
||||
# "state": "active",
|
||||
# "vlan_id": 1
|
||||
# }
|
||||
# ],
|
||||
#
|
||||
# "requests": [
|
||||
# {
|
||||
# "data": {
|
||||
# "openconfig-vlan:vlan": [
|
||||
# {
|
||||
# "config": {
|
||||
# "name": "vlan_10",
|
||||
# "status": "ACTIVE",
|
||||
# "tpid": "oc-vlan-types:TPID_0x8100",
|
||||
# "vlan-id": 10
|
||||
# }
|
||||
# }
|
||||
# ]
|
||||
# },
|
||||
# "method": "POST",
|
||||
# "path": "/rest/restconf/data/openconfig-vlan:vlans/"
|
||||
# },
|
||||
# {
|
||||
# "data": {
|
||||
# "openconfig-vlan:vlan": [
|
||||
# {
|
||||
# "config": {
|
||||
# "name": "vlan_20",
|
||||
# "status": "ACTIVE",
|
||||
# "tpid": "oc-vlan-types:TPID_0x8100",
|
||||
# "vlan-id": 20
|
||||
# }
|
||||
# }
|
||||
# ]
|
||||
# },
|
||||
# "method": "POST",
|
||||
# "path": "/rest/restconf/data/openconfig-vlan:vlans/"
|
||||
# },
|
||||
# "data": {
|
||||
# "openconfig-vlan:vlan": [
|
||||
# {
|
||||
# "config": {
|
||||
# "name": "vlan_30",
|
||||
# "status": "ACTIVE",
|
||||
# "tpid": "oc-vlan-types:TPID_0x8100",
|
||||
# "vlan-id": 30
|
||||
# }
|
||||
# }
|
||||
# ]
|
||||
# },
|
||||
# "method": "POST",
|
||||
# "path": "/rest/restconf/data/openconfig-vlan:vlans/"
|
||||
# }
|
||||
# ]
|
||||
#
|
||||
#
|
||||
# After state:
|
||||
# -------------
|
||||
#
|
||||
# path: /rest/restconf/data/openconfig-vlan:vlans/
|
||||
# method: GET
|
||||
# data:
|
||||
# {
|
||||
# "openconfig-vlan:vlans": {
|
||||
# "vlan": [
|
||||
# {
|
||||
# "config": {
|
||||
# "name": "Default",
|
||||
# "status": "ACTIVE",
|
||||
# "tpid": "oc-vlan-types:TPID_0x8100",
|
||||
# "vlan-id": 1
|
||||
# },
|
||||
# },
|
||||
# {
|
||||
# "config": {
|
||||
# "name": "vlan_10",
|
||||
# "status": "ACTIVE",
|
||||
# "tpid": "oc-vlan-types:TPID_0x8100",
|
||||
# "vlan-id": 10
|
||||
# },
|
||||
# },
|
||||
# {
|
||||
# "config": {
|
||||
# "name": "vlan_20",
|
||||
# "status": "ACTIVE",
|
||||
# "tpid": "oc-vlan-types:TPID_0x8100",
|
||||
# "vlan-id": 20
|
||||
# },
|
||||
# },
|
||||
# {
|
||||
# "config": {
|
||||
# "name": "vlan_30",
|
||||
# "status": "ACTIVE",
|
||||
# "tpid": "oc-vlan-types:TPID_0x8100",
|
||||
# "vlan-id": 30
|
||||
# },
|
||||
# }
|
||||
# ]
|
||||
# }
|
||||
# }
|
||||
|
||||
|
||||
# Using overridden
|
||||
|
||||
# Before state:
|
||||
# -------------
|
||||
#
|
||||
# path: /rest/restconf/data/openconfig-vlan:vlans/
|
||||
# method: GET
|
||||
# data:
|
||||
# {
|
||||
# "openconfig-vlan:vlans": {
|
||||
# "vlan": [
|
||||
# {
|
||||
# "config": {
|
||||
# "name": "Default",
|
||||
# "status": "ACTIVE",
|
||||
# "tpid": "oc-vlan-types:TPID_0x8100",
|
||||
# "vlan-id": 1
|
||||
# },
|
||||
# },
|
||||
# {
|
||||
# "config": {
|
||||
# "name": "vlan_10",
|
||||
# "status": "ACTIVE",
|
||||
# "tpid": "oc-vlan-types:TPID_0x8100",
|
||||
# "vlan-id": 10
|
||||
# },
|
||||
# },
|
||||
# {
|
||||
# "config": {
|
||||
# "name": "vlan_20",
|
||||
# "status": "ACTIVE",
|
||||
# "tpid": "oc-vlan-types:TPID_0x8100",
|
||||
# "vlan-id": 20
|
||||
# },
|
||||
# },
|
||||
# {
|
||||
# "config": {
|
||||
# "name": "vlan_30",
|
||||
# "status": "ACTIVE",
|
||||
# "tpid": "oc-vlan-types:TPID_0x8100",
|
||||
# "vlan-id": 30
|
||||
# },
|
||||
# }
|
||||
# ]
|
||||
# }
|
||||
# }
|
||||
|
||||
- name: Override device configuration of all VLANs with provided configuration
|
||||
exos_vlans:
|
||||
config:
|
||||
- name: TEST_VLAN10
|
||||
vlan_id: 10
|
||||
state: overridden
|
||||
|
||||
# Module Execution Results:
|
||||
# -------------------------
|
||||
#
|
||||
# "after": [
|
||||
# {
|
||||
# "name": "Default",
|
||||
# "state": "active",
|
||||
# "vlan_id": 1
|
||||
# },
|
||||
# {
|
||||
# "name": "TEST_VLAN10",
|
||||
# "state": "active",
|
||||
# "vlan_id": 10
|
||||
# },
|
||||
# ],
|
||||
#
|
||||
# "before": [
|
||||
# {
|
||||
# "name": "Default",
|
||||
# "state": "active",
|
||||
# "vlan_id": 1
|
||||
# },
|
||||
# {
|
||||
# "name": "vlan_10",
|
||||
# "state": "active",
|
||||
# "vlan_id": 10
|
||||
# },
|
||||
# {
|
||||
# "name": "vlan_20",
|
||||
# "state": "active",
|
||||
# "vlan_id": 20
|
||||
# },
|
||||
# {
|
||||
# "name": "vlan_30",
|
||||
# "state": "active",
|
||||
# "vlan_id": 30
|
||||
# }
|
||||
# ],
|
||||
#
|
||||
# "requests": [
|
||||
# {
|
||||
# "data": {
|
||||
# "openconfig-vlan:vlan": {
|
||||
# "vlan": [
|
||||
# {
|
||||
# "config": {
|
||||
# "name": "TEST_VLAN10",
|
||||
# "status": "ACTIVE",
|
||||
# "tpid": "oc-vlan-types:TPID_0x8100",
|
||||
# "vlan-id": 10
|
||||
# }
|
||||
# }
|
||||
# ]
|
||||
# }
|
||||
# }
|
||||
# },
|
||||
# "method": "PATCH",
|
||||
# "path": "/rest/restconf/data/openconfig-vlan:vlans/"
|
||||
# },
|
||||
# {
|
||||
# "data": null,
|
||||
# "method": "DELETE",
|
||||
# "path": "/rest/restconf/data/openconfig-vlan:vlans/vlan=20"
|
||||
# },
|
||||
# {
|
||||
# "data": null,
|
||||
# "method": "DELETE",
|
||||
# "path": "/rest/restconf/data/openconfig-vlan:vlans/vlan=30"
|
||||
# }
|
||||
# ]
|
||||
#
|
||||
#
|
||||
# After state:
|
||||
# -------------
|
||||
#
|
||||
# path: /rest/restconf/data/openconfig-vlan:vlans/
|
||||
# method: GET
|
||||
# data:
|
||||
# {
|
||||
# "openconfig-vlan:vlans": {
|
||||
# "vlan": [
|
||||
# {
|
||||
# "config": {
|
||||
# "name": "Default",
|
||||
# "status": "ACTIVE",
|
||||
# "tpid": "oc-vlan-types:TPID_0x8100",
|
||||
# "vlan-id": 1
|
||||
# },
|
||||
# },
|
||||
# {
|
||||
# "config": {
|
||||
# "name": "TEST_VLAN10",
|
||||
# "status": "ACTIVE",
|
||||
# "tpid": "oc-vlan-types:TPID_0x8100",
|
||||
# "vlan-id": 10
|
||||
# },
|
||||
# }
|
||||
# ]
|
||||
# }
|
||||
# }
|
||||
|
||||
|
||||
# Using replaced
|
||||
|
||||
# Before state:
|
||||
# -------------
|
||||
#
|
||||
# path: /rest/restconf/data/openconfig-vlan:vlans/
|
||||
# method: GET
|
||||
# data:
|
||||
# {
|
||||
# "openconfig-vlan:vlans": {
|
||||
# "vlan": [
|
||||
# {
|
||||
# "config": {
|
||||
# "name": "Default",
|
||||
# "status": "ACTIVE",
|
||||
# "tpid": "oc-vlan-types:TPID_0x8100",
|
||||
# "vlan-id": 1
|
||||
# },
|
||||
# },
|
||||
# {
|
||||
# "config": {
|
||||
# "name": "vlan_10",
|
||||
# "status": "ACTIVE",
|
||||
# "tpid": "oc-vlan-types:TPID_0x8100",
|
||||
# "vlan-id": 10
|
||||
# },
|
||||
# },
|
||||
# {
|
||||
# "config": {
|
||||
# "name": "vlan_20",
|
||||
# "status": "ACTIVE",
|
||||
# "tpid": "oc-vlan-types:TPID_0x8100",
|
||||
# "vlan-id": 20
|
||||
# },
|
||||
# },
|
||||
# {
|
||||
# "config": {
|
||||
# "name": "vlan_30",
|
||||
# "status": "ACTIVE",
|
||||
# "tpid": "oc-vlan-types:TPID_0x8100",
|
||||
# "vlan-id": 30
|
||||
# },
|
||||
# }
|
||||
# ]
|
||||
# }
|
||||
# }
|
||||
|
||||
- name: Replaces device configuration of listed VLANs with provided configuration
|
||||
exos_vlans:
|
||||
config:
|
||||
- name: Test_VLAN20
|
||||
vlan_id: 20
|
||||
- name: Test_VLAN30
|
||||
vlan_id: 30
|
||||
state: replaced
|
||||
|
||||
# Module Execution Results:
|
||||
# -------------------------
|
||||
#
|
||||
# "after": [
|
||||
# {
|
||||
# "name": "Default",
|
||||
# "state": "active",
|
||||
# "vlan_id": 1
|
||||
# },
|
||||
# {
|
||||
# "name": "vlan_10",
|
||||
# "state": "active",
|
||||
# "vlan_id": 10
|
||||
# },
|
||||
# {
|
||||
# "name": "TEST_VLAN20",
|
||||
# "state": "active",
|
||||
# "vlan_id": 20
|
||||
# },
|
||||
# {
|
||||
# "name": "TEST_VLAN30",
|
||||
# "state": "active",
|
||||
# "vlan_id": 30
|
||||
# }
|
||||
# ],
|
||||
#
|
||||
# "before": [
|
||||
# {
|
||||
# "name": "Default",
|
||||
# "state": "active",
|
||||
# "vlan_id": 1
|
||||
# },
|
||||
# {
|
||||
# "name": "vlan_10",
|
||||
# "state": "active",
|
||||
# "vlan_id": 10
|
||||
# },
|
||||
# {
|
||||
# "name": "vlan_20",
|
||||
# "state": "active",
|
||||
# "vlan_id": 20
|
||||
# },
|
||||
# {
|
||||
# "name": "vlan_30",
|
||||
# "state": "active",
|
||||
# "vlan_id": 30
|
||||
# }
|
||||
# ],
|
||||
#
|
||||
# "requests": [
|
||||
# {
|
||||
# "data": {
|
||||
# "openconfig-vlan:vlan": {
|
||||
# "vlan": [
|
||||
# {
|
||||
# "config": {
|
||||
# "name": "TEST_VLAN20",
|
||||
# "status": "ACTIVE",
|
||||
# "tpid": "oc-vlan-types:TPID_0x8100",
|
||||
# "vlan-id": 20
|
||||
# }
|
||||
# "config": {
|
||||
# "name": "TEST_VLAN30",
|
||||
# "status": "ACTIVE",
|
||||
# "tpid": "oc-vlan-types:TPID_0x8100",
|
||||
# "vlan-id": 30
|
||||
# }
|
||||
# }
|
||||
# ]
|
||||
# },
|
||||
# "method": "PATCH",
|
||||
# "path": "/rest/restconf/data/openconfig-vlan:vlans/"
|
||||
# }
|
||||
# ]
|
||||
#
|
||||
# After state:
|
||||
# -------------
|
||||
#
|
||||
# path: /rest/restconf/data/openconfig-vlan:vlans/
|
||||
# method: GET
|
||||
# data:
|
||||
# {
|
||||
# "openconfig-vlan:vlans": {
|
||||
# "vlan": [
|
||||
# {
|
||||
# "config": {
|
||||
# "name": "Default",
|
||||
# "status": "ACTIVE",
|
||||
# "tpid": "oc-vlan-types:TPID_0x8100",
|
||||
# "vlan-id": 1
|
||||
# },
|
||||
# },
|
||||
# {
|
||||
# "config": {
|
||||
# "name": "vlan_10",
|
||||
# "status": "ACTIVE",
|
||||
# "tpid": "oc-vlan-types:TPID_0x8100",
|
||||
# "vlan-id": 10
|
||||
# },
|
||||
# },
|
||||
# {
|
||||
# "config": {
|
||||
# "name": "TEST_VLAN20",
|
||||
# "status": "ACTIVE",
|
||||
# "tpid": "oc-vlan-types:TPID_0x8100",
|
||||
# "vlan-id": 20
|
||||
# },
|
||||
# },
|
||||
# {
|
||||
# "config": {
|
||||
# "name": "TEST_VLAN30",
|
||||
# "status": "ACTIVE",
|
||||
# "tpid": "oc-vlan-types:TPID_0x8100",
|
||||
# "vlan-id": 30
|
||||
# },
|
||||
# }
|
||||
# ]
|
||||
# }
|
||||
# }
|
||||
|
||||
|
||||
"""
|
||||
RETURN = """
|
||||
before:
|
||||
description: The configuration prior to the model invocation.
|
||||
returned: always
|
||||
sample: >
|
||||
The configuration returned will always be in the same format
|
||||
of the parameters above.
|
||||
type: list
|
||||
after:
|
||||
description: The resulting configuration model invocation.
|
||||
returned: when changed
|
||||
sample: >
|
||||
The configuration returned will always be in the same format
|
||||
of the parameters above.
|
||||
type: list
|
||||
requests:
|
||||
description: The set of requests pushed to the remote device.
|
||||
returned: always
|
||||
type: list
|
||||
sample: [{"data": "...", "method": "...", "path": "..."}, {"data": "...", "method": "...", "path": "..."}, {"data": "...", "method": "...", "path": "..."}]
|
||||
"""
|
||||
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible_collections.community.general.plugins.module_utils.network.exos.argspec.vlans.vlans import VlansArgs
|
||||
from ansible_collections.community.general.plugins.module_utils.network.exos.config.vlans.vlans import Vlans
|
||||
|
||||
|
||||
def main():
|
||||
"""
|
||||
Main entry point for module execution
|
||||
|
||||
:returns: the result form module invocation
|
||||
"""
|
||||
required_if = [('state', 'merged', ('config',)),
|
||||
('state', 'replaced', ('config',))]
|
||||
module = AnsibleModule(argument_spec=VlansArgs.argument_spec, required_if=required_if,
|
||||
supports_check_mode=True)
|
||||
|
||||
result = Vlans(module).execute_module()
|
||||
module.exit_json(**result)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Loading…
Add table
Add a link
Reference in a new issue