diff options
author | ansible-zuul[bot] <48994755+ansible-zuul[bot]@users.noreply.github.com> | 2019-08-16 18:55:56 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-08-16 18:55:56 +0000 |
commit | 3fabcd898a415a724048f445dfc35e29f895fe2e (patch) | |
tree | 391360212f87a5d815f91e05205f38f7c733a10a /plugins/modules | |
parent | 83a80f9f9df748b10eaa36dd3aab4592aaf40b28 (diff) | |
parent | 6a2aa3b8adaf9dd220916e42ec65904820d64092 (diff) | |
download | vyos-ansible-collection-3fabcd898a415a724048f445dfc35e29f895fe2e.tar.gz vyos-ansible-collection-3fabcd898a415a724048f445dfc35e29f895fe2e.zip |
Merge pull request #19 from ansible-network/ansible_sha_e7a8e4805349aec2d8a9538f544ad9e29b2e6318
based on ansible/ansible e7a8e4805349aec2d8a9538f544ad9e29b2e6318
Reviewed-by: https://github.com/apps/ansible-zuul
Diffstat (limited to 'plugins/modules')
-rw-r--r-- | plugins/modules/_vyos_interface.py | 1 | ||||
-rw-r--r-- | plugins/modules/_vyos_l3_interface.py | 1 | ||||
-rw-r--r-- | plugins/modules/_vyos_linkagg.py | 317 | ||||
-rw-r--r-- | plugins/modules/vyos_banner.py | 1 | ||||
-rw-r--r-- | plugins/modules/vyos_command.py | 1 | ||||
-rw-r--r-- | plugins/modules/vyos_config.py | 1 | ||||
-rw-r--r-- | plugins/modules/vyos_facts.py | 5 | ||||
-rw-r--r-- | plugins/modules/vyos_interfaces.py | 1 | ||||
-rw-r--r-- | plugins/modules/vyos_l3_interfaces.py | 1 | ||||
-rw-r--r-- | plugins/modules/vyos_lag_interfaces.py | 570 | ||||
l---------[-rw-r--r--] | plugins/modules/vyos_linkagg.py | 310 | ||||
-rw-r--r-- | plugins/modules/vyos_lldp.py | 1 | ||||
-rw-r--r-- | plugins/modules/vyos_lldp_interface.py | 1 | ||||
-rw-r--r-- | plugins/modules/vyos_logging.py | 1 | ||||
-rw-r--r-- | plugins/modules/vyos_ping.py | 2 | ||||
-rw-r--r-- | plugins/modules/vyos_static_route.py | 1 | ||||
-rw-r--r-- | plugins/modules/vyos_system.py | 1 | ||||
-rw-r--r-- | plugins/modules/vyos_user.py | 1 | ||||
-rw-r--r-- | plugins/modules/vyos_vlan.py | 1 |
19 files changed, 890 insertions, 328 deletions
diff --git a/plugins/modules/_vyos_interface.py b/plugins/modules/_vyos_interface.py index 5128574..71a98c5 100644 --- a/plugins/modules/_vyos_interface.py +++ b/plugins/modules/_vyos_interface.py @@ -183,7 +183,6 @@ from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import load_config, get_config, ) - from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import ( vyos_argument_spec, ) diff --git a/plugins/modules/_vyos_l3_interface.py b/plugins/modules/_vyos_l3_interface.py index a504e7c..054d810 100644 --- a/plugins/modules/_vyos_l3_interface.py +++ b/plugins/modules/_vyos_l3_interface.py @@ -110,7 +110,6 @@ from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import load_config, run_commands, ) - from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import ( vyos_argument_spec, ) diff --git a/plugins/modules/_vyos_linkagg.py b/plugins/modules/_vyos_linkagg.py new file mode 100644 index 0000000..95fbae9 --- /dev/null +++ b/plugins/modules/_vyos_linkagg.py @@ -0,0 +1,317 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +# (c) 2017, Ansible by Red Hat, inc +# +# This file is part of Ansible by Red Hat +# +# 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/>. +# + +ANSIBLE_METADATA = { + "metadata_version": "1.1", + "status": ["deprecated"], + "supported_by": "network", +} + + +DOCUMENTATION = """ +--- +module: vyos_linkagg +version_added: "2.4" +author: "Ricardo Carrillo Cruz (@rcarrillocruz)" +short_description: Manage link aggregation groups on VyOS network devices +description: + - This module provides declarative management of link aggregation groups + on VyOS network devices. +deprecated: + removed_in: '2.13' + alternative: vyos_lag_interfaces + why: Updated modules released with more functionality. +notes: + - Tested against VYOS 1.1.7 +options: + name: + description: + - Name of the link aggregation group. + required: true + type: str + mode: + description: + - Mode of the link aggregation group. + choices: ['802.3ad', 'active-backup', 'broadcast', + 'round-robin', 'transmit-load-balance', + 'adaptive-load-balance', 'xor-hash', 'on'] + type: str + members: + description: + - List of members of the link aggregation group. + type: list + aggregate: + description: List of link aggregation definitions. + type: list + state: + description: + - State of the link aggregation group. + default: present + choices: ['present', 'absent', 'up', 'down'] + type: str +extends_documentation_fragment: vyos +""" + +EXAMPLES = """ +- name: configure link aggregation group + vyos_linkagg: + name: bond0 + members: + - eth0 + - eth1 + +- name: remove configuration + vyos_linkagg: + name: bond0 + state: absent + +- name: Create aggregate of linkagg definitions + vyos_linkagg: + aggregate: + - { name: bond0, members: [eth1] } + - { name: bond1, members: [eth2] } + +- name: Remove aggregate of linkagg definitions + vyos_linkagg: + aggregate: + - name: bond0 + - name: bond1 + state: absent +""" + +RETURN = """ +commands: + description: The list of configuration mode commands to send to the device + returned: always, except for the platforms that use Netconf transport to manage the device. + type: list + sample: + - set interfaces bonding bond0 + - set interfaces ethernet eth0 bond-group 'bond0' + - set interfaces ethernet eth1 bond-group 'bond0' +""" +from copy import deepcopy + +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.network.common.utils import remove_default_spec +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import ( + load_config, + run_commands, +) +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import ( + vyos_argument_spec, +) + + +def search_obj_in_list(name, lst): + for o in lst: + if o["name"] == name: + return o + + return None + + +def map_obj_to_commands(updates, module): + commands = list() + want, have = updates + + for w in want: + name = w["name"] + members = w.get("members") or [] + mode = w["mode"] + + if mode == "on": + mode = "802.3ad" + + state = w["state"] + + obj_in_have = search_obj_in_list(name, have) + + if state == "absent": + if obj_in_have: + for m in obj_in_have["members"]: + commands.append( + "delete interfaces ethernet " + m + " bond-group" + ) + + commands.append("delete interfaces bonding " + name) + else: + if not obj_in_have: + commands.append( + "set interfaces bonding " + name + " mode " + mode + ) + + for m in members: + commands.append( + "set interfaces ethernet " + m + " bond-group " + name + ) + + if state == "down": + commands.append( + "set interfaces bonding " + name + " disable" + ) + else: + if mode != obj_in_have["mode"]: + commands.append( + "set interfaces bonding " + name + " mode " + mode + ) + + missing_members = list( + set(members) - set(obj_in_have["members"]) + ) + for m in missing_members: + commands.append( + "set interfaces ethernet " + m + " bond-group " + name + ) + + if state == "down" and obj_in_have["state"] == "up": + commands.append( + "set interfaces bonding " + name + " disable" + ) + elif state == "up" and obj_in_have["state"] == "down": + commands.append( + "delete interfaces bonding " + name + " disable" + ) + + return commands + + +def map_config_to_obj(module): + obj = [] + output = run_commands(module, ["show interfaces bonding slaves"]) + lines = output[0].splitlines() + + if len(lines) > 1: + for line in lines[1:]: + splitted_line = line.split() + + name = splitted_line[0] + mode = splitted_line[1] + state = splitted_line[2] + + if len(splitted_line) > 4: + members = splitted_line[4:] + else: + members = [] + + obj.append( + { + "name": name, + "mode": mode, + "members": members, + "state": state, + } + ) + + return obj + + +def map_params_to_obj(module): + obj = [] + aggregate = module.params.get("aggregate") + if aggregate: + for item in aggregate: + for key in item: + if item.get(key) is None: + item[key] = module.params[key] + + obj.append(item.copy()) + else: + obj.append( + { + "name": module.params["name"], + "mode": module.params["mode"], + "members": module.params["members"], + "state": module.params["state"], + } + ) + + return obj + + +def main(): + """ main entry point for module execution + """ + element_spec = dict( + name=dict(), + mode=dict( + choices=[ + "802.3ad", + "active-backup", + "broadcast", + "round-robin", + "transmit-load-balance", + "adaptive-load-balance", + "xor-hash", + "on", + ], + default="802.3ad", + ), + members=dict(type="list"), + state=dict( + default="present", choices=["present", "absent", "up", "down"] + ), + ) + + aggregate_spec = deepcopy(element_spec) + aggregate_spec["name"] = dict(required=True) + + # remove default in aggregate spec, to handle common arguments + remove_default_spec(aggregate_spec) + + argument_spec = dict( + aggregate=dict(type="list", elements="dict", options=aggregate_spec) + ) + + argument_spec.update(element_spec) + argument_spec.update(vyos_argument_spec) + + required_one_of = [["name", "aggregate"]] + mutually_exclusive = [["name", "aggregate"]] + module = AnsibleModule( + argument_spec=argument_spec, + required_one_of=required_one_of, + mutually_exclusive=mutually_exclusive, + supports_check_mode=True, + ) + + warnings = list() + + result = {"changed": False} + + if warnings: + result["warnings"] = warnings + + want = map_params_to_obj(module) + have = map_config_to_obj(module) + + commands = map_obj_to_commands((want, have), module) + result["commands"] = commands + + if commands: + commit = not module.check_mode + load_config(module, commands, commit=commit) + result["changed"] = True + + module.exit_json(**result) + + +if __name__ == "__main__": + main() diff --git a/plugins/modules/vyos_banner.py b/plugins/modules/vyos_banner.py index 447c174..39801b5 100644 --- a/plugins/modules/vyos_banner.py +++ b/plugins/modules/vyos_banner.py @@ -92,7 +92,6 @@ from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import get_config, load_config, ) - from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import ( vyos_argument_spec, ) diff --git a/plugins/modules/vyos_command.py b/plugins/modules/vyos_command.py index b812fae..892e853 100644 --- a/plugins/modules/vyos_command.py +++ b/plugins/modules/vyos_command.py @@ -150,7 +150,6 @@ from ansible.module_utils.network.common.utils import ( from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import ( run_commands, ) - from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import ( vyos_argument_spec, ) diff --git a/plugins/modules/vyos_config.py b/plugins/modules/vyos_config.py index 2956063..9ffc654 100644 --- a/plugins/modules/vyos_config.py +++ b/plugins/modules/vyos_config.py @@ -194,7 +194,6 @@ from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import get_config, run_commands, ) - from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import ( vyos_argument_spec, get_connection, diff --git a/plugins/modules/vyos_facts.py b/plugins/modules/vyos_facts.py index 1fa5214..6ceb234 100644 --- a/plugins/modules/vyos_facts.py +++ b/plugins/modules/vyos_facts.py @@ -29,6 +29,7 @@ description: author: - Nathaniel Case (@qalthos) - Nilashish Chakraborty (@Nilashishc) + - Rohit Thakur (@rohitthakur2590) extends_documentation_fragment: vyos notes: - Tested against VyOS 1.1.8 @@ -53,7 +54,7 @@ options: specific subset should not be collected. required: false version_added: "2.9" - choices: ['all', 'interfaces', '!interfaces', 'l3_interfaces', '!l3_interfaces'] + choices: ['all', 'interfaces', '!interfaces', 'l3_interfaces', '!l3_interfaces', 'lag_interfaces', '!lag_interfaces'] """ EXAMPLES = """ @@ -140,11 +141,9 @@ from ansible.module_utils.basic import AnsibleModule from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.facts.facts import ( FactsArgs, ) - from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.facts import ( Facts, ) - from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import ( vyos_argument_spec, ) diff --git a/plugins/modules/vyos_interfaces.py b/plugins/modules/vyos_interfaces.py index ca61f4d..bc179ed 100644 --- a/plugins/modules/vyos_interfaces.py +++ b/plugins/modules/vyos_interfaces.py @@ -859,7 +859,6 @@ from ansible.module_utils.basic import AnsibleModule from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.interfaces.interfaces import ( InterfacesArgs, ) - from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.config.interfaces.interfaces import ( Interfaces, ) diff --git a/plugins/modules/vyos_l3_interfaces.py b/plugins/modules/vyos_l3_interfaces.py index 1a2e453..25a57d3 100644 --- a/plugins/modules/vyos_l3_interfaces.py +++ b/plugins/modules/vyos_l3_interfaces.py @@ -355,7 +355,6 @@ from ansible.module_utils.basic import AnsibleModule from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.l3_interfaces.l3_interfaces import ( L3_interfacesArgs, ) - from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.config.l3_interfaces.l3_interfaces import ( L3_interfaces, ) diff --git a/plugins/modules/vyos_lag_interfaces.py b/plugins/modules/vyos_lag_interfaces.py new file mode 100644 index 0000000..9707f2e --- /dev/null +++ b/plugins/modules/vyos_lag_interfaces.py @@ -0,0 +1,570 @@ +#!/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 vyos_lag_interfaces +""" + +from __future__ import absolute_import, division, print_function + +__metaclass__ = type + +ANSIBLE_METADATA = { + "metadata_version": "1.1", + "status": ["preview"], + "supported_by": "network", +} + +DOCUMENTATION = """ +--- +module: vyos_lag_interfaces +version_added: 2.9 +short_description: Manages attributes of link aggregation groups on VyOS network devices. +description: This module manages attributes of link aggregation groups on VyOS network devices. +notes: + - Tested against VyOS 1.1.8 (helium). + - This module works with connection C(network_cli). +author: Rohit Thakur (@rohitthakur2590) +options: + config: + description: A list of link aggregation group configurations. + type: list + suboptions: + name: + description: + - Name of the link aggregation group (LAG) or bond. + type: str + required: True + mode: + description: + - LAG or bond mode. + type: str + choices: + - 802.3ad + - active-backup + - broadcast + - round-robin + - transmit-load-balance + - adaptive-load-balance + - xor-hash + members: + description: + - List of member interfaces for the LAG (bond). + type: list + suboptions: + member: + description: + - Name of the member interface. + type: str + primary: + description: + - Primary device interfaces for the LAG (bond). + type: str + hash_policy: + description: + - LAG or bonding transmit hash policy. + type: str + choices: + - layer2 + - layer2+3 + - layer3+4 + arp_monitor: + description: + - ARP Link monitoring parameters. + type: dict + suboptions: + interval: + description: + - ARP link monitoring frequency in milliseconds. + type: int + target: + description: + - IP address to use for ARP monitoring. + type: list + state: + description: + - The state the configuration should be left in. + type: str + choices: + - merged + - replaced + - overridden + - deleted + default: merged + +""" +EXAMPLES = """ +# Using merged +# +# Before state: +# ------------- +# +# vyos@vyos:~$ show configuration commands | grep bond +# set interfaces bonding bond2 +# set interfaces bonding bond3 +# +- name: Merge provided configuration with device configuration + vyos_lag_interfaces: + config: + - name: bond2 + mode: active-backup + members: + - member: eth2 + - member: eth1 + hash_policy: layer2 + primary: eth2 + + - name: 'bond3' + mode: 'active-backup' + hash_policy: 'layer2+3' + members: + - member: eth3 + primary: 'eth3' + state: merged +# +# +# ------------------------- +# Module Execution Result +# ------------------------- +# +# "before": [ +# { +# "name": "bond2" +# }, +# { +# "name": "bond3" +# } +# ], +# +# "commands": [ +# "set interfaces bonding bond2 hash-policy 'layer2'", +# "set interfaces bonding bond2 mode 'active-backup'", +# "set interfaces ethernet eth2 bond-group bond2", +# "set interfaces ethernet eth1 bond-group bond2", +# "set interfaces bonding bond2 primary 'eth2'", +# "set interfaces bonding bond3 hash-policy 'layer2+3'", +# "set interfaces bonding bond3 mode 'active-backup'", +# "set interfaces ethernet eth3 bond-group bond3", +# "set interfaces bonding bond3 primary 'eth3'" +# ] +# +# "after": [ +# { +# "hash_policy": "layer2", +# "members": [ +# { +# "member": "eth1" +# }, +# { +# "member": "eth2" +# } +# ], +# "mode": "active-backup", +# "name": "bond2", +# "primary": "eth2" +# }, +# { +# "hash_policy": "layer2+3", +# "members": [ +# { +# "member": "eth3" +# } +# ], +# "mode": "active-backup", +# "name": "bond3", +# "primary": "eth3" +# } +# ] +# +# After state: +# ------------- +# +# vyos@vyos:~$ show configuration commands | grep bond +# set interfaces bonding bond2 hash-policy 'layer2' +# set interfaces bonding bond2 mode 'active-backup' +# set interfaces bonding bond2 primary 'eth2' +# set interfaces bonding bond3 hash-policy 'layer2+3' +# set interfaces bonding bond3 mode 'active-backup' +# set interfaces bonding bond3 primary 'eth3' +# set interfaces ethernet eth1 bond-group 'bond2' +# set interfaces ethernet eth2 bond-group 'bond2' +# set interfaces ethernet eth3 bond-group 'bond3' + + +# Using replaced +# +# Before state: +# ------------- +# +# vyos@vyos:~$ show configuration commands | grep bond +# set interfaces bonding bond2 hash-policy 'layer2' +# set interfaces bonding bond2 mode 'active-backup' +# set interfaces bonding bond2 primary 'eth2' +# set interfaces bonding bond3 hash-policy 'layer2+3' +# set interfaces bonding bond3 mode 'active-backup' +# set interfaces bonding bond3 primary 'eth3' +# set interfaces ethernet eth1 bond-group 'bond2' +# set interfaces ethernet eth2 bond-group 'bond2' +# set interfaces ethernet eth3 bond-group 'bond3' +# +- name: Replace device configurations of listed LAGs with provided configurations + vyos_lag_interfaces: + config: + - name: bond3 + mode: '802.3ad' + hash_policy: 'layer2' + members: + - member: eth3 + state: replaced +# +# +# ------------------------- +# Module Execution Result +# ------------------------- +# +# "before": [ +# { +# "hash_policy": "layer2", +# "members": [ +# { +# "member": "eth1" +# }, +# { +# "member": "eth2" +# } +# ], +# "mode": "active-backup", +# "name": "bond2", +# "primary": "eth2" +# }, +# { +# "hash_policy": "layer2+3", +# "members": [ +# { +# "member": "eth3" +# } +# ], +# "mode": "active-backup", +# "name": "bond3", +# "primary": "eth3" +# } +# ], +# +# "commands": [ +# "delete interfaces bonding bond3 primary", +# "set interfaces bonding bond3 hash-policy 'layer2'", +# "set interfaces bonding bond3 mode '802.3ad'" +# ], +# +# "after": [ +# { +# "hash_policy": "layer2", +# "members": [ +# { +# "member": "eth1" +# }, +# { +# "member": "eth2" +# } +# ], +# "mode": "active-backup", +# "name": "bond2", +# "primary": "eth2" +# }, +# { +# "hash_policy": "layer2", +# "members": [ +# { +# "member": "eth3" +# } +# ], +# "mode": "802.3ad", +# "name": "bond3" +# } +# ], +# +# After state: +# ------------- +# +# vyos@vyos:~$ show configuration commands | grep bond +# set interfaces bonding bond2 hash-policy 'layer2' +# set interfaces bonding bond2 mode 'active-backup' +# set interfaces bonding bond2 primary 'eth2' +# set interfaces bonding bond3 hash-policy 'layer2' +# set interfaces bonding bond3 mode '802.3ad' +# set interfaces ethernet eth1 bond-group 'bond2' +# set interfaces ethernet eth2 bond-group 'bond2' +# set interfaces ethernet eth3 bond-group 'bond3' + + +# Using overridden +# +# Before state +# -------------- +# +# vyos@vyos:~$ show configuration commands | grep bond +# set interfaces bonding bond2 hash-policy 'layer2' +# set interfaces bonding bond2 mode 'active-backup' +# set interfaces bonding bond2 primary 'eth2' +# set interfaces bonding bond3 hash-policy 'layer2' +# set interfaces bonding bond3 mode '802.3ad' +# set interfaces ethernet eth1 bond-group 'bond2' +# set interfaces ethernet eth2 bond-group 'bond2' +# set interfaces ethernet eth3 bond-group 'bond3' +# +- name: Overrides all device configuration with provided configuration + vyos_lag_interfaces: + config: + - name: bond3 + mode: active-backup + members: + - member: eth1 + - member: eth2 + - member: eth3 + primary: eth3 + hash_policy: layer2 + state: overridden +# +# +# ------------------------- +# Module Execution Result +# ------------------------- +# +# "before": [ +# { +# "hash_policy": "layer2", +# "members": [ +# { +# "member": "eth1" +# }, +# { +# "member": "eth2" +# } +# ], +# "mode": "active-backup", +# "name": "bond2", +# "primary": "eth2" +# }, +# { +# "hash_policy": "layer2", +# "members": [ +# { +# "member": "eth3" +# } +# ], +# "mode": "802.3ad", +# "name": "bond3" +# } +# ], +# +# "commands": [ +# "delete interfaces bonding bond2 hash-policy", +# "delete interfaces ethernet eth1 bond-group bond2", +# "delete interfaces ethernet eth2 bond-group bond2", +# "delete interfaces bonding bond2 mode", +# "delete interfaces bonding bond2 primary", +# "set interfaces bonding bond3 mode 'active-backup'", +# "set interfaces ethernet eth1 bond-group bond3", +# "set interfaces ethernet eth2 bond-group bond3", +# "set interfaces bonding bond3 primary 'eth3'" +# ], +# +# "after": [ +# { +# "name": "bond2" +# }, +# { +# "hash_policy": "layer2", +# "members": [ +# { +# "member": "eth1" +# }, +# { +# "member": "eth2" +# }, +# { +# "member": "eth3" +# } +# ], +# "mode": "active-backup", +# "name": "bond3", +# "primary": "eth3" +# } +# ], +# +# +# After state +# ------------ +# +# vyos@vyos:~$ show configuration commands | grep bond +# set interfaces bonding bond2 +# set interfaces bonding bond3 hash-policy 'layer2' +# set interfaces bonding bond3 mode 'active-backup' +# set interfaces bonding bond3 primary 'eth3' +# set interfaces ethernet eth1 bond-group 'bond3' +# set interfaces ethernet eth2 bond-group 'bond3' +# set interfaces ethernet eth3 bond-group 'bond3' + + +# Using deleted +# +# Before state +# ------------- +# +# vyos@vyos:~$ show configuration commands | grep bond +# set interfaces bonding bond2 hash-policy 'layer2' +# set interfaces bonding bond2 mode 'active-backup' +# set interfaces bonding bond2 primary 'eth2' +# set interfaces bonding bond3 hash-policy 'layer2+3' +# set interfaces bonding bond3 mode 'active-backup' +# set interfaces bonding bond3 primary 'eth3' +# set interfaces ethernet eth1 bond-group 'bond2' +# set interfaces ethernet eth2 bond-group 'bond2' +# set interfaces ethernet eth3 bond-group 'bond3' +# +- name: Delete LAG attributes of given interfaces (Note This won't delete the interface itself) + vyos_lag_interfaces: + config: + - name: bond2 + - name: bond3 + state: deleted +# +# +# ------------------------ +# Module Execution Results +# ------------------------ +# +# "before": [ +# { +# "hash_policy": "layer2", +# "members": [ +# { +# "member": "eth1" +# }, +# { +# "member": "eth2" +# } +# ], +# "mode": "active-backup", +# "name": "bond2", +# "primary": "eth2" +# }, +# { +# "hash_policy": "layer2+3", +# "members": [ +# { +# "member": "eth3" +# } +# ], +# "mode": "active-backup", +# "name": "bond3", +# "primary": "eth3" +# } +# ], +# "commands": [ +# "delete interfaces bonding bond2 hash-policy", +# "delete interfaces ethernet eth1 bond-group bond2", +# "delete interfaces ethernet eth2 bond-group bond2", +# "delete interfaces bonding bond2 mode", +# "delete interfaces bonding bond2 primary", +# "delete interfaces bonding bond3 hash-policy", +# "delete interfaces ethernet eth3 bond-group bond3", +# "delete interfaces bonding bond3 mode", +# "delete interfaces bonding bond3 primary" +# ], +# +# "after": [ +# { +# "name": "bond2" +# }, +# { +# "name": "bond3" +# } +# ], +# +# After state +# ------------ +# vyos@vyos:~$ show configuration commands | grep bond +# set interfaces bonding bond2 +# set interfaces bonding bond3 + + +""" +RETURN = """ +before: + description: The configuration prior to the model invocation. + returned: always + type: list + sample: > + The configuration returned will always be in the same format + of the parameters above. +after: + description: The resulting configuration model invocation. + returned: when changed + type: list + sample: > + The configuration returned will always be in the same format + of the parameters above. +commands: + description: The set of commands pushed to the remote device. + returned: always + type: list + sample: + - 'set interfaces bonding bond2' + - 'set interfaces bonding bond2 hash-policy layer2' +""" + + +from ansible.module_utils.basic import AnsibleModule +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.lag_interfaces.lag_interfaces import ( + Lag_interfacesArgs, +) +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.config.lag_interfaces.lag_interfaces import ( + Lag_interfaces, +) + + +def main(): + """ + Main entry point for module execution + + :returns: the result form module invocation + """ + required_if = [ + ("state", "merged", ("config",)), + ("state", "replaced", ("config",)), + ("state", "overridden", ("config",)), + ] + module = AnsibleModule( + argument_spec=Lag_interfacesArgs.argument_spec, + required_if=required_if, + supports_check_mode=True, + ) + + result = Lag_interfaces(module).execute_module() + module.exit_json(**result) + + +if __name__ == "__main__": + main() diff --git a/plugins/modules/vyos_linkagg.py b/plugins/modules/vyos_linkagg.py index 2fc8d66..294bec1 100644..120000 --- a/plugins/modules/vyos_linkagg.py +++ b/plugins/modules/vyos_linkagg.py @@ -1,309 +1 @@ -#!/usr/bin/python -# -*- coding: utf-8 -*- - -# (c) 2017, Ansible by Red Hat, inc -# -# This file is part of Ansible by Red Hat -# -# 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/>. -# - -ANSIBLE_METADATA = { - "metadata_version": "1.1", - "status": ["preview"], - "supported_by": "network", -} - - -DOCUMENTATION = """ ---- -module: vyos_linkagg -version_added: "2.4" -author: "Ricardo Carrillo Cruz (@rcarrillocruz)" -short_description: Manage link aggregation groups on VyOS network devices -description: - - This module provides declarative management of link aggregation groups - on VyOS network devices. -notes: - - Tested against VYOS 1.1.7 -options: - name: - description: - - Name of the link aggregation group. - required: true - mode: - description: - - Mode of the link aggregation group. - choices: ['802.3ad', 'active-backup', 'broadcast', - 'round-robin', 'transmit-load-balance', - 'adaptive-load-balance', 'xor-hash', 'on'] - members: - description: - - List of members of the link aggregation group. - aggregate: - description: List of link aggregation definitions. - state: - description: - - State of the link aggregation group. - default: present - choices: ['present', 'absent', 'up', 'down'] -extends_documentation_fragment: vyos -""" - -EXAMPLES = """ -- name: configure link aggregation group - vyos_linkagg: - name: bond0 - members: - - eth0 - - eth1 - -- name: remove configuration - vyos_linkagg: - name: bond0 - state: absent - -- name: Create aggregate of linkagg definitions - vyos_linkagg: - aggregate: - - { name: bond0, members: [eth1] } - - { name: bond1, members: [eth2] } - -- name: Remove aggregate of linkagg definitions - vyos_linkagg: - aggregate: - - name: bond0 - - name: bond1 - state: absent -""" - -RETURN = """ -commands: - description: The list of configuration mode commands to send to the device - returned: always, except for the platforms that use Netconf transport to manage the device. - type: list - sample: - - set interfaces bonding bond0 - - set interfaces ethernet eth0 bond-group 'bond0' - - set interfaces ethernet eth1 bond-group 'bond0' -""" -from copy import deepcopy - -from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.network.common.utils import remove_default_spec -from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import ( - load_config, - run_commands, -) - -from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import ( - vyos_argument_spec, -) - - -def search_obj_in_list(name, lst): - for o in lst: - if o["name"] == name: - return o - - return None - - -def map_obj_to_commands(updates, module): - commands = list() - want, have = updates - - for w in want: - name = w["name"] - members = w.get("members") or [] - mode = w["mode"] - - if mode == "on": - mode = "802.3ad" - - state = w["state"] - - obj_in_have = search_obj_in_list(name, have) - - if state == "absent": - if obj_in_have: - for m in obj_in_have["members"]: - commands.append( - "delete interfaces ethernet " + m + " bond-group" - ) - - commands.append("delete interfaces bonding " + name) - else: - if not obj_in_have: - commands.append( - "set interfaces bonding " + name + " mode " + mode - ) - - for m in members: - commands.append( - "set interfaces ethernet " + m + " bond-group " + name - ) - - if state == "down": - commands.append( - "set interfaces bonding " + name + " disable" - ) - else: - if mode != obj_in_have["mode"]: - commands.append( - "set interfaces bonding " + name + " mode " + mode - ) - - missing_members = list( - set(members) - set(obj_in_have["members"]) - ) - for m in missing_members: - commands.append( - "set interfaces ethernet " + m + " bond-group " + name - ) - - if state == "down" and obj_in_have["state"] == "up": - commands.append( - "set interfaces bonding " + name + " disable" - ) - elif state == "up" and obj_in_have["state"] == "down": - commands.append( - "delete interfaces bonding " + name + " disable" - ) - - return commands - - -def map_config_to_obj(module): - obj = [] - output = run_commands(module, ["show interfaces bonding slaves"]) - lines = output[0].splitlines() - - if len(lines) > 1: - for line in lines[1:]: - splitted_line = line.split() - - name = splitted_line[0] - mode = splitted_line[1] - state = splitted_line[2] - - if len(splitted_line) > 4: - members = splitted_line[4:] - else: - members = [] - - obj.append( - { - "name": name, - "mode": mode, - "members": members, - "state": state, - } - ) - - return obj - - -def map_params_to_obj(module): - obj = [] - aggregate = module.params.get("aggregate") - if aggregate: - for item in aggregate: - for key in item: - if item.get(key) is None: - item[key] = module.params[key] - - obj.append(item.copy()) - else: - obj.append( - { - "name": module.params["name"], - "mode": module.params["mode"], - "members": module.params["members"], - "state": module.params["state"], - } - ) - - return obj - - -def main(): - """ main entry point for module execution - """ - element_spec = dict( - name=dict(), - mode=dict( - choices=[ - "802.3ad", - "active-backup", - "broadcast", - "round-robin", - "transmit-load-balance", - "adaptive-load-balance", - "xor-hash", - "on", - ], - default="802.3ad", - ), - members=dict(type="list"), - state=dict( - default="present", choices=["present", "absent", "up", "down"] - ), - ) - - aggregate_spec = deepcopy(element_spec) - aggregate_spec["name"] = dict(required=True) - - # remove default in aggregate spec, to handle common arguments - remove_default_spec(aggregate_spec) - - argument_spec = dict( - aggregate=dict(type="list", elements="dict", options=aggregate_spec) - ) - - argument_spec.update(element_spec) - argument_spec.update(vyos_argument_spec) - - required_one_of = [["name", "aggregate"]] - mutually_exclusive = [["name", "aggregate"]] - module = AnsibleModule( - argument_spec=argument_spec, - required_one_of=required_one_of, - mutually_exclusive=mutually_exclusive, - supports_check_mode=True, - ) - - warnings = list() - - result = {"changed": False} - - if warnings: - result["warnings"] = warnings - - want = map_params_to_obj(module) - have = map_config_to_obj(module) - - commands = map_obj_to_commands((want, have), module) - result["commands"] = commands - - if commands: - commit = not module.check_mode - load_config(module, commands, commit=commit) - result["changed"] = True - - module.exit_json(**result) - - -if __name__ == "__main__": - main() +_vyos_linkagg.py
\ No newline at end of file diff --git a/plugins/modules/vyos_lldp.py b/plugins/modules/vyos_lldp.py index 18a013f..fdec814 100644 --- a/plugins/modules/vyos_lldp.py +++ b/plugins/modules/vyos_lldp.py @@ -69,7 +69,6 @@ from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import get_config, load_config, ) - from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import ( vyos_argument_spec, ) diff --git a/plugins/modules/vyos_lldp_interface.py b/plugins/modules/vyos_lldp_interface.py index 5d25ea3..494fac4 100644 --- a/plugins/modules/vyos_lldp_interface.py +++ b/plugins/modules/vyos_lldp_interface.py @@ -99,7 +99,6 @@ from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import get_config, load_config, ) - from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import ( vyos_argument_spec, ) diff --git a/plugins/modules/vyos_logging.py b/plugins/modules/vyos_logging.py index fa0d1cf..8eb5777 100644 --- a/plugins/modules/vyos_logging.py +++ b/plugins/modules/vyos_logging.py @@ -116,7 +116,6 @@ from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import get_config, load_config, ) - from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import ( vyos_argument_spec, ) diff --git a/plugins/modules/vyos_ping.py b/plugins/modules/vyos_ping.py index c770804..4b21927 100644 --- a/plugins/modules/vyos_ping.py +++ b/plugins/modules/vyos_ping.py @@ -136,11 +136,9 @@ from ansible.module_utils.basic import AnsibleModule from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import ( run_commands, ) - from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import ( vyos_argument_spec, ) - import re diff --git a/plugins/modules/vyos_static_route.py b/plugins/modules/vyos_static_route.py index 734a1b0..b7307ef 100644 --- a/plugins/modules/vyos_static_route.py +++ b/plugins/modules/vyos_static_route.py @@ -114,7 +114,6 @@ from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import get_config, load_config, ) - from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import ( vyos_argument_spec, ) diff --git a/plugins/modules/vyos_system.py b/plugins/modules/vyos_system.py index 3f306f8..9fee88f 100644 --- a/plugins/modules/vyos_system.py +++ b/plugins/modules/vyos_system.py @@ -98,7 +98,6 @@ from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import get_config, load_config, ) - from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import ( vyos_argument_spec, ) diff --git a/plugins/modules/vyos_user.py b/plugins/modules/vyos_user.py index 2bccd49..2a1181a 100644 --- a/plugins/modules/vyos_user.py +++ b/plugins/modules/vyos_user.py @@ -143,7 +143,6 @@ from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import get_config, load_config, ) - from ansible.module_utils.six import iteritems from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import ( vyos_argument_spec, diff --git a/plugins/modules/vyos_vlan.py b/plugins/modules/vyos_vlan.py index 6c0fad8..10eaecd 100644 --- a/plugins/modules/vyos_vlan.py +++ b/plugins/modules/vyos_vlan.py @@ -129,7 +129,6 @@ from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import load_config, run_commands, ) - from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import ( vyos_argument_spec, ) |