summaryrefslogtreecommitdiff
path: root/plugins/modules
diff options
context:
space:
mode:
authorRohit Thakur <rohitthakur2590@outlook.com>2020-05-08 18:53:03 +0530
committerRohit Thakur <rohitthakur2590@outlook.com>2020-05-08 18:53:03 +0530
commite584c5ce7db0adbdcced3427411bbd82c6dc1b68 (patch)
treead568efa32cd42d4f17f59a30ce57af18a7c4b72 /plugins/modules
parent6726b46caabe79f27485e5b33f7f1e324ded6dd1 (diff)
downloadvyos.vyos-e584c5ce7db0adbdcced3427411bbd82c6dc1b68.tar.gz
vyos.vyos-e584c5ce7db0adbdcced3427411bbd82c6dc1b68.zip
ospfv3 test cases updated
Signed-off-by: Rohit Thakur <rohitthakur2590@outlook.com>
Diffstat (limited to 'plugins/modules')
-rw-r--r--plugins/modules/vyos_ospfv3.py516
1 files changed, 501 insertions, 15 deletions
diff --git a/plugins/modules/vyos_ospfv3.py b/plugins/modules/vyos_ospfv3.py
index e620fe1..ae93500 100644
--- a/plugins/modules/vyos_ospfv3.py
+++ b/plugins/modules/vyos_ospfv3.py
@@ -27,21 +27,23 @@ The module file for vyos_ospfv3
"""
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_ospfv3
version_added: 2.10
-short_description: OSPFv3 resource module.
+short_description: OSPFV3 resource module.
description: This resource module configures and manages attributes of OSPFv3 routes on VyOS network devices.
-author: Rohit Thakur (@rohitthakur2590)
+version_added: "1.0.0"
+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).
+author:
+- Rohit Thakur (@rohitthakur2590)
options:
config:
description: A provided OSPFv3 route configuration.
@@ -96,7 +98,12 @@ options:
type: str
running_config:
description:
- - The configuration to be parsed.
+ - 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 ospfv3).
+ - 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:
@@ -112,22 +119,493 @@ options:
default: merged
"""
EXAMPLES = """
+# Using merged
+#
+# Before state:
+# -------------
+#
+# vyos@vyos# run show configuration commands | grep ospfv3
+#
+#
+- name: Merge the provided configuration with the exisiting running configuration
+ vyos.vyos.vyos_ospfv3:
+ config:
+ redistribute:
+ - route_type: 'bgp'
+ parameters:
+ router_id: '192.0.2.10'
+ areas:
+ - area_id: '2'
+ export_list: 'export1'
+ import_list: 'import1'
+ range:
+ - address: '2001:db10::/32'
+ - address: '2001:db20::/32'
+ - address: '2001:db30::/32'
+ - area_id: '3'
+ range:
+ - address: '2001:db40::/32'
+ state: merged
+#
+#
+# -------------------------
+# Module Execution Result
+# -------------------------
+#
+# before": {}
+#
+# "commands": [
+# "set protocols ospfv3 redistribute bgp",
+# "set protocols ospfv3 parameters router-id '192.0.2.10'",
+# "set protocols ospfv3 area 2 range 2001:db10::/32",
+# "set protocols ospfv3 area 2 range 2001:db20::/32",
+# "set protocols ospfv3 area 2 range 2001:db30::/32",
+# "set protocols ospfv3 area '2'",
+# "set protocols ospfv3 area 2 export-list export1",
+# "set protocols ospfv3 area 2 import-list import1",
+# "set protocols ospfv3 area '3'",
+# "set protocols ospfv3 area 3 range 2001:db40::/32"
+# ]
+#
+# "after": {
+# "areas": [
+# {
+# "area_id": "2",
+# "export_list": "export1",
+# "import_list": "import1",
+# "range": [
+# {
+# "address": "2001:db10::/32"
+# },
+# {
+# "address": "2001:db20::/32"
+# },
+# {
+# "address": "2001:db30::/32"
+# }
+# ]
+# },
+# {
+# "area_id": "3",
+# "range": [
+# {
+# "address": "2001:db40::/32"
+# }
+# ]
+# }
+# ],
+# "parameters": {
+# "router_id": "192.0.2.10"
+# },
+# "redistribute": [
+# {
+# "route_type": "bgp"
+# }
+# ]
+# }
+#
+# After state:
+# -------------
+#
+# vyos@192# run show configuration commands | grep ospfv3
+# set protocols ospfv3 area 2 export-list 'export1'
+# set protocols ospfv3 area 2 import-list 'import1'
+# set protocols ospfv3 area 2 range '2001:db10::/32'
+# set protocols ospfv3 area 2 range '2001:db20::/32'
+# set protocols ospfv3 area 2 range '2001:db30::/32'
+# set protocols ospfv3 area 3 range '2001:db40::/32'
+# set protocols ospfv3 parameters router-id '192.0.2.10'
+# set protocols ospfv3 redistribute 'bgp'
+# Using replaced
+#
+# Before state:
+# -------------
+#
+# vyos@192# run show configuration commands | grep ospfv3
+# set protocols ospfv3 area 2 export-list 'export1'
+# set protocols ospfv3 area 2 import-list 'import1'
+# set protocols ospfv3 area 2 range '2001:db10::/32'
+# set protocols ospfv3 area 2 range '2001:db20::/32'
+# set protocols ospfv3 area 2 range '2001:db30::/32'
+# set protocols ospfv3 area 3 range '2001:db40::/32'
+# set protocols ospfv3 parameters router-id '192.0.2.10'
+# set protocols ospfv3 redistribute 'bgp'
+#
+- name: Replace ospfv3 routes attributes configuration.
+ vyos.vyos.vyos_ospfv3:
+ config:
+ redistribute:
+ - route_type: 'bgp'
+ parameters:
+ router_id: '192.0.2.10'
+ areas:
+ - area_id: '2'
+ export_list: 'export1'
+ import_list: 'import1'
+ range:
+ - address: '2001:db10::/32'
+ - address: '2001:db30::/32'
+ - address: '2001:db50::/32'
+ - area_id: '4'
+ range:
+ - address: '2001:db60::/32'
+ state: replaced
+#
+#
+# -------------------------
+# Module Execution Result
+# -------------------------
+#
+# "before": {
+# "areas": [
+# {
+# "area_id": "2",
+# "export_list": "export1",
+# "import_list": "import1",
+# "range": [
+# {
+# "address": "2001:db10::/32"
+# },
+# {
+# "address": "2001:db20::/32"
+# },
+# {
+# "address": "2001:db30::/32"
+# }
+# ]
+# },
+# {
+# "area_id": "3",
+# "range": [
+# {
+# "address": "2001:db40::/32"
+# }
+# ]
+# }
+# ],
+# "parameters": {
+# "router_id": "192.0.2.10"
+# },
+# "redistribute": [
+# {
+# "route_type": "bgp"
+# }
+# ]
+# }
+#
+# "commands": [
+# "delete protocols ospfv3 area 2 range 2001:db20::/32",
+# "delete protocols ospfv3 area 3",
+# "set protocols ospfv3 area 2 range 2001:db50::/32",
+# "set protocols ospfv3 area '4'",
+# "set protocols ospfv3 area 4 range 2001:db60::/32"
+# ]
+#
+# "after": {
+# "areas": [
+# {
+# "area_id": "2",
+# "export_list": "export1",
+# "import_list": "import1",
+# "range": [
+# {
+# "address": "2001:db10::/32"
+# },
+# {
+# "address": "2001:db30::/32"
+# },
+# {
+# "address": "2001:db50::/32"
+# }
+# ]
+# },
+# {
+# "area_id": "4",
+# "range": [
+# {
+# "address": "2001:db60::/32"
+# }
+# ]
+# }
+# ],
+# "parameters": {
+# "router_id": "192.0.2.10"
+# },
+# "redistribute": [
+# {
+# "route_type": "bgp"
+# }
+# ]
+# }
+#
+# After state:
+# -------------
+#
+# vyos@192# run show configuration commands | grep ospfv3
+# set protocols ospfv3 area 2 export-list 'export1'
+# set protocols ospfv3 area 2 import-list 'import1'
+# set protocols ospfv3 area 2 range '2001:db10::/32'
+# set protocols ospfv3 area 2 range '2001:db30::/32'
+# set protocols ospfv3 area 2 range '2001:db50::/32'
+# set protocols ospfv3 area 4 range '2001:db60::/32'
+# set protocols ospfv3 parameters router-id '192.0.2.10'
+# set protocols ospfv3 redistribute 'bgp'
+# Using rendered
+#
+#
+- name: Render the commands for provided configuration
+ vyos.vyos.vyos_ospfv3:
+ config:
+ redistribute:
+ - route_type: 'bgp'
+ parameters:
+ router_id: '192.0.2.10'
+ areas:
+ - area_id: '2'
+ export_list: 'export1'
+ import_list: 'import1'
+ range:
+ - address: '2001:db10::/32'
+ - address: '2001:db20::/32'
+ - address: '2001:db30::/32'
+ - area_id: '3'
+ range:
+ - address: '2001:db40::/32'
+ state: rendered
+#
+#
+# -------------------------
+# Module Execution Result
+# -------------------------
+#
+#
+# "rendered": [
+# [
+# "set protocols ospfv3 redistribute bgp",
+# "set protocols ospfv3 parameters router-id '192.0.2.10'",
+# "set protocols ospfv3 area 2 range 2001:db10::/32",
+# "set protocols ospfv3 area 2 range 2001:db20::/32",
+# "set protocols ospfv3 area 2 range 2001:db30::/32",
+# "set protocols ospfv3 area '2'",
+# "set protocols ospfv3 area 2 export-list export1",
+# "set protocols ospfv3 area 2 import-list import1",
+# "set protocols ospfv3 area '3'",
+# "set protocols ospfv3 area 3 range 2001:db40::/32"
+# ]
+# Using parsed
+#
+#
+- name: Parse the commands to provide structured configuration.
+ vyos.vyos.vyos_ospfv3:
+ running_config:
+ "set protocols ospfv3 area 2 export-list 'export1'
+set protocols ospfv3 area 2 import-list 'import1'
+set protocols ospfv3 area 2 range '2001:db10::/32'
+set protocols ospfv3 area 2 range '2001:db20::/32'
+set protocols ospfv3 area 2 range '2001:db30::/32'
+set protocols ospfv3 area 3 range '2001:db40::/32'
+set protocols ospfv3 parameters router-id '192.0.2.10'
+set protocols ospfv3 redistribute 'bgp'"
+ state: parsed
+#
+#
+# -------------------------
+# Module Execution Result
+# -------------------------
+#
+#
+# "parsed": {
+# "areas": [
+# {
+# "area_id": "2",
+# "export_list": "export1",
+# "import_list": "import1",
+# "range": [
+# {
+# "address": "2001:db10::/32"
+# },
+# {
+# "address": "2001:db20::/32"
+# },
+# {
+# "address": "2001:db30::/32"
+# }
+# ]
+# },
+# {
+# "area_id": "3",
+# "range": [
+# {
+# "address": "2001:db40::/32"
+# }
+# ]
+# }
+# ],
+# "parameters": {
+# "router_id": "192.0.2.10"
+# },
+# "redistribute": [
+# {
+# "route_type": "bgp"
+# }
+# ]
+# }
+# Using gathered
+#
+# Before state:
+# -------------
+#
+# vyos@192# run show configuration commands | grep ospfv3
+# set protocols ospfv3 area 2 export-list 'export1'
+# set protocols ospfv3 area 2 import-list 'import1'
+# set protocols ospfv3 area 2 range '2001:db10::/32'
+# set protocols ospfv3 area 2 range '2001:db20::/32'
+# set protocols ospfv3 area 2 range '2001:db30::/32'
+# set protocols ospfv3 area 3 range '2001:db40::/32'
+# set protocols ospfv3 parameters router-id '192.0.2.10'
+# set protocols ospfv3 redistribute 'bgp'
+#
+- name: Gather ospfv3 routes config with provided configurations
+ vyos.vyos.vyos_ospfv3:
+ config:
+ state: gathered
+#
+#
+# -------------------------
+# Module Execution Result
+# -------------------------
+#
+# "gathered": {
+# "areas": [
+# {
+# "area_id": "2",
+# "export_list": "export1",
+# "import_list": "import1",
+# "range": [
+# {
+# "address": "2001:db10::/32"
+# },
+# {
+# "address": "2001:db20::/32"
+# },
+# {
+# "address": "2001:db30::/32"
+# }
+# ]
+# },
+# {
+# "area_id": "3",
+# "range": [
+# {
+# "address": "2001:db40::/32"
+# }
+# ]
+# }
+# ],
+# "parameters": {
+# "router_id": "192.0.2.10"
+# },
+# "redistribute": [
+# {
+# "route_type": "bgp"
+# }
+# ]
+# }
+#
+# After state:
+# -------------
+#
+# vyos@192# run show configuration commands | grep ospfv3
+# set protocols ospfv3 area 2 export-list 'export1'
+# set protocols ospfv3 area 2 import-list 'import1'
+# set protocols ospfv3 area 2 range '2001:db10::/32'
+# set protocols ospfv3 area 2 range '2001:db20::/32'
+# set protocols ospfv3 area 2 range '2001:db30::/32'
+# set protocols ospfv3 area 3 range '2001:db40::/32'
+# set protocols ospfv3 parameters router-id '192.0.2.10'
+# set protocols ospfv3 redistribute 'bgp'
-
-
-
+# Using deleted
+#
+# Before state
+# -------------
+#
+# vyos@192# run show configuration commands | grep ospfv3
+# set protocols ospfv3 area 2 export-list 'export1'
+# set protocols ospfv3 area 2 import-list 'import1'
+# set protocols ospfv3 area 2 range '2001:db10::/32'
+# set protocols ospfv3 area 2 range '2001:db20::/32'
+# set protocols ospfv3 area 2 range '2001:db30::/32'
+# set protocols ospfv3 area 3 range '2001:db40::/32'
+# set protocols ospfv3 parameters router-id '192.0.2.10'
+# set protocols ospfv3 redistribute 'bgp'
+#
+- name: Delete attributes of ospfv3 routes.
+ vyos.vyos.vyos_ospfv3:
+ config:
+ state: deleted
+#
+#
+# ------------------------
+# Module Execution Results
+# ------------------------
+#
+# "before": {
+# "areas": [
+# {
+# "area_id": "2",
+# "export_list": "export1",
+# "import_list": "import1",
+# "range": [
+# {
+# "address": "2001:db10::/32"
+# },
+# {
+# "address": "2001:db20::/32"
+# },
+# {
+# "address": "2001:db30::/32"
+# }
+# ]
+# },
+# {
+# "area_id": "3",
+# "range": [
+# {
+# "address": "2001:db40::/32"
+# }
+# ]
+# }
+# ],
+# "parameters": {
+# "router_id": "192.0.2.10"
+# },
+# "redistribute": [
+# {
+# "route_type": "bgp"
+# }
+# ]
+# }
+# "commands": [
+# "delete protocols ospfv3"
+# ]
+#
+# "after": {}
+# After state
+# ------------
+# vyos@192# run show configuration commands | grep ospfv3
"""
@@ -135,12 +613,14 @@ RETURN = """
before:
description: The configuration prior to the model invocation.
returned: always
+ type: dict
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: dict
sample: >
The configuration returned will always be in the same format
of the parameters above.
@@ -148,13 +628,18 @@ commands:
description: The set of commands pushed to the remote device.
returned: always
type: list
- sample: ['command 1', 'command 2', 'command 3']
+ sample: ['set protocols ospf parameters router-id 192.0.1.1',
+ 'set protocols ospfv3 area 2 range '2001:db10::/32']
"""
from ansible.module_utils.basic import AnsibleModule
-from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.ospfv3.ospfv3 import Ospfv3Args
-from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.config.ospfv3.ospfv3 import Ospfv3
+from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.ospfv3.ospfv3 import (
+ Ospfv3Args,
+)
+from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.config.ospfv3.ospfv3 import (
+ Ospfv3,
+)
def main():
@@ -166,6 +651,7 @@ def main():
required_if = [
("state", "merged", ("config",)),
("state", "replaced", ("config",)),
+ ("state", "rendered", ("config",)),
("state", "parsed", ("running_config",)),
]
mutually_exclusive = [("config", "running_config")]
@@ -180,5 +666,5 @@ def main():
module.exit_json(**result)
-if __name__ == '__main__':
+if __name__ == "__main__":
main()