From c7039afea05ea49cd010e98359d7989cc1bd574e Mon Sep 17 00:00:00 2001 From: Rohit Thakur Date: Thu, 30 Apr 2020 14:34:01 +0530 Subject: new states added Signed-off-by: Rohit Thakur --- plugins/modules/vyos_lldp_interfaces.py | 180 +++++++++++++++++++++++++++++++- 1 file changed, 175 insertions(+), 5 deletions(-) (limited to 'plugins/modules') diff --git a/plugins/modules/vyos_lldp_interfaces.py b/plugins/modules/vyos_lldp_interfaces.py index 8fe572b..34ceb66 100644 --- a/plugins/modules/vyos_lldp_interfaces.py +++ b/plugins/modules/vyos_lldp_interfaces.py @@ -37,7 +37,7 @@ ANSIBLE_METADATA = { } DOCUMENTATION = """module: vyos_lldp_interfaces -short_description: Manages attributes of lldp interfaces on VyOS devices. +short_description: LLDP interfaces resource module description: This module manages attributes of lldp interfaces on VyOS network devices. notes: - Tested against VyOS 1.1.8 (helium). @@ -111,6 +111,15 @@ options: elin: description: Emergency Call Service ELIN number (between 10-25 numbers). type: str + running_config: + description: + - This option is used only with state I(parsed). + - The value of this option should be the output received from the VyOS device by executing + the command B(show configuration commands | grep lldp). + - The state I(parsed) reads the configuration from C(running_config) option and transforms + it into Ansible structured data as per the resource module's argspec and the value is then + returned in the I(parsed) key within the result. + type: str state: description: - The state of the configuration after module completion. @@ -120,6 +129,9 @@ options: - replaced - overridden - deleted + - rendered + - parsed + - gathered default: merged """ EXAMPLES = """ @@ -131,7 +143,7 @@ EXAMPLES = """ # vyos@vyos:~$ show configuration commands | grep lldp # - name: Merge provided configuration with device configuration - vyos_lldp_interfaces: + vyos.vyos.vyos_lldp_interfaces: config: - name: 'eth1' location: @@ -225,7 +237,7 @@ EXAMPLES = """ # set service lldp interface eth2 location coordinate-based longitude '222.267255W' # - name: Replace device configurations of listed LLDP interfaces with provided configurations - vyos_lldp_interfaces: + vyos.vyos.vyos_lldp_interfaces: config: - name: 'eth2' location: @@ -348,7 +360,7 @@ EXAMPLES = """ # set service lldp interface eth2 location civic-based country-code 'US' # - name: Overrides all device configuration with provided configuration - vyos_lag_interfaces: + vyos.vyos.vyos_lldp_interfaces: config: - name: 'eth2' location: @@ -423,7 +435,7 @@ EXAMPLES = """ # set service lldp interface eth2 location elin '0000000911' # - name: Delete lldp interface attributes of given interfaces. - vyos_lag_interfaces: + vyos.vyos.vyos_lldp_interfaces: config: - name: 'eth2' state: deleted @@ -453,6 +465,159 @@ EXAMPLES = """ # set service 'lldp' +# Using gathered +# +# Before state: +# ------------- +# +# vyos@192# run show configuration commands | grep lldp +# set service lldp interface eth1 location civic-based ca-type 0 ca-value 'ENGLISH' +# set service lldp interface eth1 location civic-based country-code 'US' +# set service lldp interface eth2 location coordinate-based altitude '2200' +# set service lldp interface eth2 location coordinate-based datum 'WGS84' +# set service lldp interface eth2 location coordinate-based latitude '33.524449N' +# set service lldp interface eth2 location coordinate-based longitude '222.267255W' +# +- name: Gather listed lldp interfaces from running configuration + vyos.vyos.vyos_lldp_interfaces: + config: + state: gathered +# +# +# ------------------------- +# Module Execution Result +# ------------------------- +# +# "gathered": [ +# { +# "location": { +# "coordinate_based": { +# "altitude": 2200, +# "datum": "WGS84", +# "latitude": "33.524449N", +# "longitude": "222.267255W" +# } +# }, +# "name": "eth2" +# }, +# { +# "location": { +# "civic_based": { +# "ca_info": [ +# { +# "ca_type": 0, +# "ca_value": "ENGLISH" +# } +# ], +# "country_code": "US" +# } +# }, +# "name": "eth1" +# } +# ] +# +# +# After state: +# ------------- +# +# vyos@192# run show configuration commands | grep lldp +# set service lldp interface eth1 location civic-based ca-type 0 ca-value 'ENGLISH' +# set service lldp interface eth1 location civic-based country-code 'US' +# set service lldp interface eth2 location coordinate-based altitude '2200' +# set service lldp interface eth2 location coordinate-based datum 'WGS84' +# set service lldp interface eth2 location coordinate-based latitude '33.524449N' +# set service lldp interface eth2 location coordinate-based longitude '222.267255W' + + +# Using rendered +# +# +- name: Render the commands for provided configuration + vyos.vyos.vyos_lldp_interfaces: + config: + - name: eth1 + location: + civic_based: + country_code: US + ca_info: + - ca_type: 0 + ca_value: ENGLISH + - name: eth2 + location: + coordinate_based: + altitude: 2200 + datum: WGS84 + longitude: 222.267255W + latitude: 33.524449N + state: rendered +# +# +# ------------------------- +# Module Execution Result +# ------------------------- +# +# +# "rendered": [ +# "set service lldp interface eth1 location civic-based country-code 'US'", +# "set service lldp interface eth1 location civic-based ca-type 0 ca-value 'ENGLISH'", +# "set service lldp interface eth1", +# "set service lldp interface eth2 location coordinate-based latitude '33.524449N'", +# "set service lldp interface eth2 location coordinate-based altitude '2200'", +# "set service lldp interface eth2 location coordinate-based datum 'WGS84'", +# "set service lldp interface eth2 location coordinate-based longitude '222.267255W'", +# "set service lldp interface eth2" +# ] + + +# Using parsed +# +# +- name: Parsed the commands to provide structured configuration. + vyos.vyos.vyos_lldp_interfaces: + running_config: + "set service lldp interface eth1 location civic-based ca-type 0 ca-value 'ENGLISH' + set service lldp interface eth1 location civic-based country-code 'US' + set service lldp interface eth2 location coordinate-based altitude '2200' + set service lldp interface eth2 location coordinate-based datum 'WGS84' + set service lldp interface eth2 location coordinate-based latitude '33.524449N' + set service lldp interface eth2 location coordinate-based longitude '222.267255W'" + state: parsed +# +# +# ------------------------- +# Module Execution Result +# ------------------------- +# +# +# "parsed": [ +# { +# "location": { +# "coordinate_based": { +# "altitude": 2200, +# "datum": "WGS84", +# "latitude": "33.524449N", +# "longitude": "222.267255W" +# } +# }, +# "name": "eth2" +# }, +# { +# "location": { +# "civic_based": { +# "ca_info": [ +# { +# "ca_type": 0, +# "ca_value": "ENGLISH" +# } +# ], +# "country_code": "US" +# } +# }, +# "name": "eth1" +# } +# ] + + """ RETURN = """ before: @@ -497,12 +662,17 @@ def main(): required_if = [ ("state", "merged", ("config",)), ("state", "replaced", ("config",)), + ("state", "rendered", ("config",)), ("state", "overridden", ("config",)), + ("state", "parsed", ("running_config",)), ] + mutually_exclusive = [("config", "running_config")] + module = AnsibleModule( argument_spec=Lldp_interfacesArgs.argument_spec, required_if=required_if, supports_check_mode=True, + mutually_exclusive=mutually_exclusive, ) result = Lldp_interfaces(module).execute_module() -- cgit v1.2.3 From b125abe2ac135589a2c3455ef74e1580f435489c Mon Sep 17 00:00:00 2001 From: Rohit Thakur Date: Mon, 4 May 2020 09:54:38 +0530 Subject: version added Signed-off-by: Rohit Thakur --- plugins/modules/vyos_lldp_interfaces.py | 1 + 1 file changed, 1 insertion(+) (limited to 'plugins/modules') diff --git a/plugins/modules/vyos_lldp_interfaces.py b/plugins/modules/vyos_lldp_interfaces.py index 34ceb66..9567511 100644 --- a/plugins/modules/vyos_lldp_interfaces.py +++ b/plugins/modules/vyos_lldp_interfaces.py @@ -120,6 +120,7 @@ options: it into Ansible structured data as per the resource module's argspec and the value is then returned in the I(parsed) key within the result. type: str + version_added: "1.0.0" state: description: - The state of the configuration after module completion. -- cgit v1.2.3 From df5f503a3603164cc4ba74723aa39e7f33be6605 Mon Sep 17 00:00:00 2001 From: Rohit Thakur Date: Wed, 6 May 2020 17:32:09 +0530 Subject: common comments incorporated Signed-off-by: Rohit Thakur --- plugins/modules/vyos_lldp_interfaces.py | 8 ++------ .../targets/vyos_lldp_interfaces/tests/cli/gathered.yaml | 11 +---------- .../targets/vyos_lldp_interfaces/tests/cli/parsed.yaml | 10 +--------- .../targets/vyos_lldp_interfaces/tests/cli/rendered.yaml | 11 +---------- 4 files changed, 5 insertions(+), 35 deletions(-) (limited to 'plugins/modules') diff --git a/plugins/modules/vyos_lldp_interfaces.py b/plugins/modules/vyos_lldp_interfaces.py index 9567511..b26da49 100644 --- a/plugins/modules/vyos_lldp_interfaces.py +++ b/plugins/modules/vyos_lldp_interfaces.py @@ -30,11 +30,7 @@ from __future__ import absolute_import, division, print_function __metaclass__ = type -ANSIBLE_METADATA = { - "metadata_version": "1.1", - "status": ["preview"], - "supported_by": "network", -} +ANSIBLE_METADATA = {"metadata_version": "1.1", "supported_by": "Ansible"} DOCUMENTATION = """module: vyos_lldp_interfaces short_description: LLDP interfaces resource module @@ -42,6 +38,7 @@ description: This module manages attributes of lldp interfaces on VyOS network d notes: - Tested against VyOS 1.1.8 (helium). - This module works with connection C(network_cli). See L(the VyOS OS Platform Options,../network/user_guide/platform_vyos.html). +version_added: "1.0.0" author: - Rohit Thakur (@rohitthakur2590) options: @@ -120,7 +117,6 @@ options: it into Ansible structured data as per the resource module's argspec and the value is then returned in the I(parsed) key within the result. type: str - version_added: "1.0.0" state: description: - The state of the configuration after module completion. diff --git a/tests/integration/targets/vyos_lldp_interfaces/tests/cli/gathered.yaml b/tests/integration/targets/vyos_lldp_interfaces/tests/cli/gathered.yaml index d440b53..30b804a 100644 --- a/tests/integration/targets/vyos_lldp_interfaces/tests/cli/gathered.yaml +++ b/tests/integration/targets/vyos_lldp_interfaces/tests/cli/gathered.yaml @@ -9,7 +9,7 @@ - block: - - name: Merge the provided configuration with the exisiting running configuration + - name: Gather the provided configuration with the exisiting running configuration register: result vyos.vyos.vyos_lldp_interfaces: &id001 config: @@ -20,15 +20,6 @@ that: - "{{ populate | symmetric_difference(result['gathered']) |length == 0\ \ }}" - - - name: Gather the existing running configuration (IDEMPOTENT) - register: result - vyos.vyos.vyos_lldp_interfaces: *id001 - - - name: Assert that the previous task was idempotent - assert: - that: - - result['changed'] == false always: - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_lldp_interfaces/tests/cli/parsed.yaml b/tests/integration/targets/vyos_lldp_interfaces/tests/cli/parsed.yaml index 7842152..c549ce7 100644 --- a/tests/integration/targets/vyos_lldp_interfaces/tests/cli/parsed.yaml +++ b/tests/integration/targets/vyos_lldp_interfaces/tests/cli/parsed.yaml @@ -19,7 +19,7 @@ - name: Provide the running configuration for parsing (config to be parsed) register: result - vyos.vyos.vyos_lldp_interfaces: &id001 + vyos.vyos.vyos_lldp_interfaces: running_config: "{{ lookup('file', '_parsed_config.cfg') }}" state: parsed @@ -28,14 +28,6 @@ that: "{{ ansible_facts['network_resources']['lldp_interfaces'] | symmetric_difference(result['parsed'])\ \ |length == 0 }}" - - name: Gather the existing running configuration (IDEMPOTENT) - register: result - vyos.vyos.vyos_lldp_interfaces: *id001 - - - name: Assert that the previous task was idempotent - assert: - that: - - result['changed'] == false always: - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_lldp_interfaces/tests/cli/rendered.yaml b/tests/integration/targets/vyos_lldp_interfaces/tests/cli/rendered.yaml index 6bb9f5a..d69e1c5 100644 --- a/tests/integration/targets/vyos_lldp_interfaces/tests/cli/rendered.yaml +++ b/tests/integration/targets/vyos_lldp_interfaces/tests/cli/rendered.yaml @@ -11,7 +11,7 @@ - name: Structure provided configuration into device specific commands register: result - vyos.vyos.vyos_lldp_interfaces: &id001 + vyos.vyos.vyos_lldp_interfaces: config: - name: eth1 location: @@ -34,15 +34,6 @@ that: - "{{ rendered['commands'] | symmetric_difference(result['rendered'])\ \ |length == 0 }}" - - - name: Structure provided configuration into device specific commands (IDEMPOTENT) - register: result - vyos.vyos.vyos_lldp_interfaces: *id001 - - - name: Assert that the previous task was idempotent - assert: - that: - - result['changed'] == false always: - include_tasks: _remove_config.yaml -- cgit v1.2.3