diff options
Diffstat (limited to 'plugins/modules')
| -rw-r--r-- | plugins/modules/_vyos_lldp.py | 144 | ||||
| -rw-r--r-- | plugins/modules/vyos_facts.py | 2 | ||||
| l---------[-rw-r--r--] | plugins/modules/vyos_lldp.py | 131 | ||||
| -rw-r--r-- | plugins/modules/vyos_lldp_global.py | 333 | 
4 files changed, 479 insertions, 131 deletions
| diff --git a/plugins/modules/_vyos_lldp.py b/plugins/modules/_vyos_lldp.py new file mode 100644 index 00000000..69787543 --- /dev/null +++ b/plugins/modules/_vyos_lldp.py @@ -0,0 +1,144 @@ +#!/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/>. +# + +from __future__ import absolute_import, division, print_function + +__metaclass__ = type + + +ANSIBLE_METADATA = { +    "metadata_version": "1.1", +    "status": ["deprecated"], +    "supported_by": "network", +} + + +DOCUMENTATION = """ +--- +module: vyos_lldp +version_added: "2.4" +author: "Ricardo Carrillo Cruz (@rcarrillocruz)" +short_description: Manage LLDP configuration on VyOS network devices +description: +  - This module provides declarative management of LLDP service +    on VyOS network devices. +deprecated: +  removed_in: '2.13' +  alternative: vyos_lldp_global +  why: Updated modules released with more functionality. +notes: +  - Tested against VYOS 1.1.7 +options: +  interfaces: +    description: +      - Name of the interfaces. +    type: list +  state: +    description: +      - State of the link aggregation group. +    default: present +    choices: ['present', 'absent', 'enabled', 'disabled'] +    type: str +extends_documentation_fragment: vyos +""" + +EXAMPLES = """ +- name: Enable LLDP service +  vyos_lldp: +    state: present + +- name: Disable LLDP service +  vyos_lldp: +    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 service lldp +""" +from ansible.module_utils.basic import AnsibleModule +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, +) + + +def has_lldp(module): +    config = get_config(module).splitlines() + +    if "set service 'lldp'" in config or "set service lldp" in config: +        return True +    else: +        return False + + +def main(): +    """ main entry point for module execution +    """ +    argument_spec = dict( +        interfaces=dict(type="list"), +        state=dict( +            default="present", +            choices=["present", "absent", "enabled", "disabled"], +        ), +    ) + +    argument_spec.update(vyos_argument_spec) + +    module = AnsibleModule( +        argument_spec=argument_spec, supports_check_mode=True +    ) + +    warnings = list() + +    result = {"changed": False} + +    if warnings: +        result["warnings"] = warnings + +    HAS_LLDP = has_lldp(module) + +    commands = [] + +    if module.params["state"] == "absent" and HAS_LLDP: +        commands.append("delete service lldp") +    elif module.params["state"] == "present" and not HAS_LLDP: +        commands.append("set service lldp") + +    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_facts.py b/plugins/modules/vyos_facts.py index 6ceb2343..561b149e 100644 --- a/plugins/modules/vyos_facts.py +++ b/plugins/modules/vyos_facts.py @@ -54,7 +54,7 @@ options:          specific subset should not be collected.      required: false      version_added: "2.9" -    choices: ['all', 'interfaces', '!interfaces', 'l3_interfaces', '!l3_interfaces', 'lag_interfaces', '!lag_interfaces'] +    choices: ['all', 'interfaces', '!interfaces', 'l3_interfaces', '!l3_interfaces', 'lag_interfaces', '!lag_interfaces', 'lldp_global', '!lldp_global']  """  EXAMPLES = """ diff --git a/plugins/modules/vyos_lldp.py b/plugins/modules/vyos_lldp.py index fdec8149..259de8c9 100644..120000 --- a/plugins/modules/vyos_lldp.py +++ b/plugins/modules/vyos_lldp.py @@ -1,130 +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_lldp -version_added: "2.4" -author: "Ricardo Carrillo Cruz (@rcarrillocruz)" -short_description: Manage LLDP configuration on VyOS network devices -description: -  - This module provides declarative management of LLDP service -    on VyOS network devices. -notes: -  - Tested against VYOS 1.1.7 -options: -  state: -    description: -      - State of the LLDP configuration. -    default: present -    choices: ['present', 'absent'] -extends_documentation_fragment: vyos -""" - -EXAMPLES = """ -- name: Enable LLDP service -  vyos_lldp: -    state: present - -- name: Disable LLDP service -  vyos_lldp: -    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 service lldp -""" -from ansible.module_utils.basic import AnsibleModule -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, -) - - -def has_lldp(module): -    config = get_config(module).splitlines() - -    if "set service 'lldp'" in config or "set service lldp" in config: -        return True -    else: -        return False - - -def main(): -    """ main entry point for module execution -    """ -    argument_spec = dict( -        interfaces=dict(type="list"), -        state=dict( -            default="present", -            choices=["present", "absent", "enabled", "disabled"], -        ), -    ) - -    argument_spec.update(vyos_argument_spec) - -    module = AnsibleModule( -        argument_spec=argument_spec, supports_check_mode=True -    ) - -    warnings = list() - -    result = {"changed": False} - -    if warnings: -        result["warnings"] = warnings - -    HAS_LLDP = has_lldp(module) - -    commands = [] - -    if module.params["state"] == "absent" and HAS_LLDP: -        commands.append("delete service lldp") -    elif module.params["state"] == "present" and not HAS_LLDP: -        commands.append("set service lldp") - -    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_lldp.py
\ No newline at end of file diff --git a/plugins/modules/vyos_lldp_global.py b/plugins/modules/vyos_lldp_global.py new file mode 100644 index 00000000..3783dcbc --- /dev/null +++ b/plugins/modules/vyos_lldp_global.py @@ -0,0 +1,333 @@ +#!/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_lldp_global +""" + +from __future__ import absolute_import, division, print_function + +__metaclass__ = type + +ANSIBLE_METADATA = { +    "metadata_version": "1.1", +    "status": ["preview"], +    "supported_by": "network", +} + +DOCUMENTATION = """ +--- +module: vyos_lldp_global +version_added: 2.9 +short_description: Manage link layer discovery protocol (LLDP) attributes on VyOS devices.. +description: This module manages link layer discovery protocol (LLDP) attributes on VyOS devices. +notes: +  - Tested against VyOS 1.1.8 (helium). +  - This module works with connection C(network_cli). +author: +   - Rohit Thakur (@rohitthakur2590) +options: +  config: +    description: The provided link layer discovery protocol (LLDP) configuration. +    type: dict +    suboptions: +      enable: +        description: +          - This argument is a boolean value to enable or disable LLDP. +        type: bool +      address: +        description: +          - This argument defines management-address. +        type: str +      snmp: +        description: +          - This argument enable the SNMP queries to LLDP database. +        type: str +      legacy_protocols: +        description: +          - List of the supported legacy protocols. +        type: list +        choices: +          - cdp +          - edp +          - fdp +          - sonmp +  state: +    description: +      - The state the configuration should be left in. +    type: str +    choices: +    - merged +    - replaced +    - deleted +    default: merged +""" +EXAMPLES = """ +# Using merged +# +# Before state: +# ------------- +# +# vyos@vyos:~$ show configuration commands|grep lldp +# vyos@vyos:~$ +# +- name: Merge provided configuration with device configuration +  vyos_lldp_global: +    config: +      legacy_protocols: +        - 'fdp' +        - 'cdp' +      snmp: 'enable' +      address: 192.0.2.11 +    state: merged +# +# +# ------------------------ +# Module Execution Results +# ------------------------ +# +# "before": [] +# +# "commands": [ +#        "set service lldp legacy-protocols fdp", +#        "set service lldp legacy-protocols cdp", +#        "set service lldp snmp enable", +#        "set service lldp management-address '192.0.2.11'" +#    ] +# +# "after": [ +#        { +#            "snmp": "enable" +#        }, +#        { +#            "address": "192.0.2.11" +#        }, +#        { +#            "legacy_protocols": [ +#                "cdp", +#                "fdp" +#            ] +#        } +#        { +#            "enable": true +#        } +#    ] +# +# After state: +# ------------- +# +# set service lldp legacy-protocols cdp +# set service lldp legacy-protocols fdp +# set service lldp management-address '192.0.2.11' +# set service lldp snmp enable + + +# Using replaced +# +# Before state: +# ------------- +# +# vyos@vyos:~$ show configuration commands | grep lldp +# set service lldp legacy-protocols cdp +# set service lldp legacy-protocols fdp +# set service lldp management-address '192.0.2.11' +# set service lldp snmp enable +# +- name: Replace device configurations with provided configurations +  vyos_lldp_global: +    config: +      legacy_protocols: +        - 'edp' +        - 'sonmp' +        - 'cdp' +      address: 192.0.2.14 +    state: replaced +# +# +# ------------------------ +# Module Execution Results +# ------------------------ +# +# +# "before": [ +#        { +#            "snmp": "enable" +#        }, +#        { +#            "address": "192.0.2.11" +#        }, +#        { +#            "legacy_protocols": [ +#                "cdp", +#                "fdp" +#            ] +#        } +#        { +#            "enable": true +#        } +#    ] +# "commands": [ +#        "delete service lldp snmp", +#        "delete service lldp legacy-protocols fdp", +#        "set service lldp management-address '192.0.2.14'", +#        "set service lldp legacy-protocols edp", +#        "set service lldp legacy-protocols sonmp" +#    ] +# +# "after": [ +#        { +#            "address": "192.0.2.14" +#        }, +#        { +#            "legacy_protocols": [ +#                "cdp", +#                "edp", +#                "sonmp" +#            ] +#        } +#        { +#            "enable": true +#        } +#    ] +# +# After state: +# ------------- +# +# vyos@vyos:~$ show configuration commands|grep lldp +# set service lldp legacy-protocols cdp +# set service lldp legacy-protocols edp +# set service lldp legacy-protocols sonmp +# set service lldp management-address '192.0.2.14' + + +# Using deleted +# +# Before state +# ------------- +# vyos@vyos:~$ show configuration commands|grep lldp +# set service lldp legacy-protocols cdp +# set service lldp legacy-protocols edp +# set service lldp legacy-protocols sonmp +# set service lldp management-address '192.0.2.14' +# +- name: Delete attributes of given lldp service (This won't delete the LLDP service itself) +  vyos_lldp_global: +    config: +    state: deleted +# +# +# ------------------------ +# Module Execution Results +# ------------------------ +# +# "before": [ +#        { +#            "address": "192.0.2.14" +#        }, +#        { +#            "legacy_protocols": [ +#                "cdp", +#                "edp", +#                "sonmp" +#            ] +#        } +#        { +#            "enable": true +#        } +#    ] +# +#  "commands": [ +#       "delete service lldp management-address", +#        "delete service lldp legacy-protocols" +#    ] +# +# "after": [ +#        { +#            "enable": true +#        } +#          ] +# +# After state +# ------------ +# vyos@vyos:~$ show configuration commands | grep lldp +# set service lldp + + +""" +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 service lldp legacy-protocols sonmp +    - set service lldp management-address '192.0.2.14' +""" + + +from ansible.module_utils.basic import AnsibleModule +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.lldp_global.lldp_global import ( +    Lldp_globalArgs, +) +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.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() | 
