summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorPriyam Sahoo <42550351+priyamsahoo@users.noreply.github.com>2021-07-06 00:53:20 +0530
committerGitHub <noreply@github.com>2021-07-05 19:23:20 +0000
commitaf07511dee4d74b4159482c6b7aed6efff0e5949 (patch)
tree559e0093e82118d601108dc81efb88200e3a2c6b /plugins
parent8264a29424c79c25d03cf89c376a72ec6a0f600f (diff)
downloadvyos-ansible-old-af07511dee4d74b4159482c6b7aed6efff0e5949.tar.gz
vyos-ansible-old-af07511dee4d74b4159482c6b7aed6efff0e5949.zip
VyOS Prefix Lists Resource Module Added (#178)
VyOS Prefix Lists Resource Module Added SUMMARY PR for vyos_prefix_lists rm resolves: #99 ISSUE TYPE New Module Pull Request COMPONENT NAME ADDITIONAL INFORMATION Reviewed-by: Rohit Thakur <rohitthakur2590@outlook.com> Reviewed-by: Nilashish Chakraborty <nilashishchakraborty8@gmail.com> Reviewed-by: Priyam Sahoo <None>
Diffstat (limited to 'plugins')
-rw-r--r--plugins/module_utils/network/vyos/argspec/prefix_lists/__init__.py0
-rw-r--r--plugins/module_utils/network/vyos/argspec/prefix_lists/prefix_lists.py82
-rw-r--r--plugins/module_utils/network/vyos/config/prefix_lists/__init__.py0
-rw-r--r--plugins/module_utils/network/vyos/config/prefix_lists/prefix_lists.py182
-rw-r--r--plugins/module_utils/network/vyos/facts/facts.py4
-rw-r--r--plugins/module_utils/network/vyos/facts/prefix_lists/__init__.py0
-rw-r--r--plugins/module_utils/network/vyos/facts/prefix_lists/prefix_lists.py93
-rw-r--r--plugins/module_utils/network/vyos/rm_templates/prefix_lists.py265
-rw-r--r--plugins/modules/vyos_prefix_lists.py1329
9 files changed, 1955 insertions, 0 deletions
diff --git a/plugins/module_utils/network/vyos/argspec/prefix_lists/__init__.py b/plugins/module_utils/network/vyos/argspec/prefix_lists/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/plugins/module_utils/network/vyos/argspec/prefix_lists/__init__.py
diff --git a/plugins/module_utils/network/vyos/argspec/prefix_lists/prefix_lists.py b/plugins/module_utils/network/vyos/argspec/prefix_lists/prefix_lists.py
new file mode 100644
index 0000000..c7d2e98
--- /dev/null
+++ b/plugins/module_utils/network/vyos/argspec/prefix_lists/prefix_lists.py
@@ -0,0 +1,82 @@
+# -*- coding: utf-8 -*-
+# Copyright 2021 Red Hat
+# 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
+
+#############################################
+# WARNING #
+#############################################
+#
+# This file is auto generated by the
+# cli_rm_builder.
+#
+# Manually editing this file is not advised.
+#
+# To update the argspec make the desired changes
+# in the module docstring and re-run
+# cli_rm_builder.
+#
+#############################################
+
+"""
+The arg spec for the vyos_prefix_lists module
+"""
+
+
+class Prefix_listsArgs(object): # pylint: disable=R0903
+ """The arg spec for the vyos_prefix_lists module"""
+
+ argument_spec = {
+ "config": {
+ "type": "list",
+ "elements": "dict",
+ "options": {
+ "afi": {
+ "type": "str",
+ "choices": ["ipv4", "ipv6"],
+ "required": True,
+ },
+ "prefix_lists": {
+ "type": "list",
+ "elements": "dict",
+ "options": {
+ "name": {"type": "str", "required": True},
+ "description": {"type": "str"},
+ "entries": {
+ "type": "list",
+ "elements": "dict",
+ "options": {
+ "sequence": {"type": "int", "required": True},
+ "description": {"type": "str"},
+ "action": {
+ "type": "str",
+ "choices": ["permit", "deny"],
+ },
+ "ge": {"type": "int"},
+ "le": {"type": "int"},
+ "prefix": {"type": "str"},
+ },
+ },
+ },
+ },
+ },
+ },
+ "running_config": {"type": "str"},
+ "state": {
+ "type": "str",
+ "choices": [
+ "merged",
+ "replaced",
+ "overridden",
+ "deleted",
+ "gathered",
+ "rendered",
+ "parsed",
+ ],
+ "default": "merged",
+ },
+ } # pylint: disable=C0301
diff --git a/plugins/module_utils/network/vyos/config/prefix_lists/__init__.py b/plugins/module_utils/network/vyos/config/prefix_lists/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/plugins/module_utils/network/vyos/config/prefix_lists/__init__.py
diff --git a/plugins/module_utils/network/vyos/config/prefix_lists/prefix_lists.py b/plugins/module_utils/network/vyos/config/prefix_lists/prefix_lists.py
new file mode 100644
index 0000000..b2c119d
--- /dev/null
+++ b/plugins/module_utils/network/vyos/config/prefix_lists/prefix_lists.py
@@ -0,0 +1,182 @@
+#
+# -*- coding: utf-8 -*-
+# Copyright 2021 Red Hat
+# 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
+
+"""
+The vyos_prefix_lists config file.
+It is in this file where the current configuration (as dict)
+is compared to the provided configuration (as dict) and the command set
+necessary to bring the current configuration to its desired end-state is
+created.
+"""
+
+
+from ansible.module_utils.six import iteritems
+from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import (
+ dict_merge,
+)
+from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module import (
+ ResourceModule,
+)
+from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.facts import (
+ Facts,
+)
+from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.rm_templates.prefix_lists import (
+ Prefix_listsTemplate,
+)
+
+
+class Prefix_lists(ResourceModule):
+ """
+ The vyos_prefix_lists config class
+ """
+
+ def __init__(self, module):
+ super(Prefix_lists, self).__init__(
+ empty_fact_val=[],
+ facts_module=Facts(module),
+ module=module,
+ resource="prefix_lists",
+ tmplt=Prefix_listsTemplate(),
+ )
+ self.plist_parsers = [
+ "name",
+ "description",
+ ]
+ self.entries_parsers = [
+ "sequence",
+ "action",
+ "rule_description",
+ "ge",
+ "le",
+ "prefix",
+ ]
+
+ def execute_module(self):
+ """Execute the module
+
+ :rtype: A dictionary
+ :returns: The result from module execution
+ """
+ if self.state not in ["parsed", "gathered"]:
+ self.generate_commands()
+ self.run_commands()
+ return self.result
+
+ def generate_commands(self):
+ """Generate configuration commands to send based on
+ want, have and desired state.
+ """
+ wantd = {entry["afi"]: entry for entry in self.want}
+ haved = {entry["afi"]: entry for entry in self.have}
+
+ self._prefix_list_list_to_dict(wantd)
+ self._prefix_list_list_to_dict(haved)
+
+ # if state is merged, merge want onto have and then compare
+ if self.state == "merged":
+ wantd = dict_merge(haved, wantd)
+
+ # if state is deleted, empty out wantd and set haved to wantd
+ if self.state == "deleted":
+ haved = {
+ k: v for k, v in iteritems(haved) if k in wantd or not wantd
+ }
+ for key, hvalue in iteritems(haved):
+ wvalue = wantd.pop(key, {})
+ if wvalue:
+ wplists = wvalue.get("prefix_lists", {})
+ hplists = hvalue.get("prefix_lists", {})
+ hvalue["prefix_lists"] = {
+ k: v
+ for k, v in iteritems(hplists)
+ if k in wplists or not wplists
+ }
+
+ # remove superfluous config for overridden and deleted
+ if self.state in ["overridden", "deleted"]:
+ for k, have in iteritems(haved):
+ if k not in wantd:
+ self._compare(want={}, have=have)
+
+ for k, want in iteritems(wantd):
+ self._compare(want=want, have=haved.pop(k, {}))
+
+ def _compare(self, want, have):
+ """Leverages the base class `compare()` method and
+ populates the list of commands to be run by comparing
+ the `want` and `have` data with the `parsers` defined
+ for the Prefix_lists network resource.
+ """
+ wplists = want.get("prefix_lists", {})
+ hplists = have.get("prefix_lists", {})
+
+ self._compare_plists(want=wplists, have=hplists)
+
+ if self.state in ["overridden", "deleted"]:
+ # remove remaining prefix lists
+ for h in hplists.values():
+ self.commands.append(
+ "delete policy prefix-{0} {1}".format(
+ "list" if h["afi"] == "ipv4" else "list6", h["name"]
+ )
+ )
+
+ def _compare_plists(self, want, have):
+ for wk, wentry in iteritems(want):
+ hentry = have.pop(wk, {})
+
+ # parser list for name and descriptions
+ self.compare(
+ parsers=self.plist_parsers,
+ want=wentry,
+ have=hentry,
+ )
+
+ wplrules = wentry.get("entries", {})
+ hplrules = hentry.get("entries", {})
+
+ self._compare_rules(want=wplrules, have=hplrules)
+
+ def _compare_rules(self, want, have):
+ for wr, wrule in iteritems(want):
+ hrule = have.pop(wr, {})
+
+ # parser list for entries
+ self.compare(
+ parsers=self.entries_parsers,
+ want=wrule,
+ have=hrule,
+ )
+
+ # remove remaining entries
+ for hr in have.values():
+ self.commands.append(
+ "delete policy prefix-{0} {1} rule {2}".format(
+ "list" if hr["afi"] == "ipv4" else "list6",
+ hr["name"],
+ hr["sequence"],
+ )
+ )
+
+ def _prefix_list_list_to_dict(self, entry):
+ for afi, value in iteritems(entry):
+ if "prefix_lists" in value:
+ for pl in value["prefix_lists"]:
+ pl.update({"afi": afi})
+ if "entries" in pl:
+ for entry in pl["entries"]:
+ entry.update({"afi": afi, "name": pl["name"]})
+ pl["entries"] = {
+ x["sequence"]: x for x in pl["entries"]
+ }
+ value["prefix_lists"] = {
+ entry["name"]: entry for entry in value["prefix_lists"]
+ }
diff --git a/plugins/module_utils/network/vyos/facts/facts.py b/plugins/module_utils/network/vyos/facts/facts.py
index 81518f8..90ee03c 100644
--- a/plugins/module_utils/network/vyos/facts/facts.py
+++ b/plugins/module_utils/network/vyos/facts/facts.py
@@ -58,6 +58,9 @@ from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.bgp_a
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.route_maps.route_maps import (
Route_mapsFacts,
)
+from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.prefix_lists.prefix_lists import (
+ Prefix_listsFacts,
+)
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.legacy.base import (
Default,
Neighbors,
@@ -82,6 +85,7 @@ FACT_RESOURCE_SUBSETS = dict(
bgp_global=Bgp_globalFacts,
bgp_address_family=Bgp_address_familyFacts,
route_maps=Route_mapsFacts,
+ prefix_lists=Prefix_listsFacts,
)
diff --git a/plugins/module_utils/network/vyos/facts/prefix_lists/__init__.py b/plugins/module_utils/network/vyos/facts/prefix_lists/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/plugins/module_utils/network/vyos/facts/prefix_lists/__init__.py
diff --git a/plugins/module_utils/network/vyos/facts/prefix_lists/prefix_lists.py b/plugins/module_utils/network/vyos/facts/prefix_lists/prefix_lists.py
new file mode 100644
index 0000000..15a2db9
--- /dev/null
+++ b/plugins/module_utils/network/vyos/facts/prefix_lists/prefix_lists.py
@@ -0,0 +1,93 @@
+# -*- coding: utf-8 -*-
+# Copyright 2021 Red Hat
+# 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
+
+"""
+The vyos prefix_lists fact class
+It is in this file the configuration is collected from the device
+for a given resource, parsed, and the facts tree is populated
+based on the configuration.
+"""
+
+
+from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import (
+ utils,
+)
+from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.rm_templates.prefix_lists import (
+ Prefix_listsTemplate,
+)
+from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.prefix_lists.prefix_lists import (
+ Prefix_listsArgs,
+)
+
+
+class Prefix_listsFacts(object):
+ """The vyos prefix_lists facts class"""
+
+ def __init__(self, module, subspec="config", options="options"):
+ self._module = module
+ self.argument_spec = Prefix_listsArgs.argument_spec
+
+ def get_config(self, connection):
+ return connection.get("show configuration commands | grep prefix-list")
+
+ def populate_facts(self, connection, ansible_facts, data=None):
+ """Populate the facts for Prefix_lists network resource
+
+ :param connection: the device connection
+ :param ansible_facts: Facts dictionary
+ :param data: previously collected conf
+
+ :rtype: dictionary
+ :returns: facts
+ """
+ facts = {}
+ objs = []
+
+ if not data:
+ data = self.get_config(connection)
+
+ # parse native config using the Prefix_lists template
+ prefix_lists_parser = Prefix_listsTemplate(
+ lines=data.splitlines(), module=self._module
+ )
+
+ objs = prefix_lists_parser.parse()
+ objs = sorted(
+ list(objs.values()),
+ key=lambda k: k["afi"],
+ )
+
+ if objs:
+ for item in objs:
+ item["prefix_lists"] = sorted(
+ list(item["prefix_lists"].values()),
+ key=lambda k: k["name"],
+ )
+ for pl in item["prefix_lists"]:
+ if "entries" in pl:
+ pl["entries"] = sorted(
+ list(pl["entries"].values()),
+ key=lambda k: k["sequence"],
+ )
+
+ ansible_facts["ansible_network_resources"].pop("prefix_lists", None)
+
+ params = utils.remove_empties(
+ prefix_lists_parser.validate_config(
+ self.argument_spec, {"config": objs}, redact=True
+ )
+ )
+
+ if params.get("config"):
+ facts["prefix_lists"] = params["config"]
+ else:
+ facts["prefix_lists"] = []
+ ansible_facts["ansible_network_resources"].update(facts)
+
+ return ansible_facts
diff --git a/plugins/module_utils/network/vyos/rm_templates/prefix_lists.py b/plugins/module_utils/network/vyos/rm_templates/prefix_lists.py
new file mode 100644
index 0000000..9a66a8d
--- /dev/null
+++ b/plugins/module_utils/network/vyos/rm_templates/prefix_lists.py
@@ -0,0 +1,265 @@
+# -*- coding: utf-8 -*-
+# Copyright 2021 Red Hat
+# 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
+
+"""
+The Prefix_lists parser templates file. This contains
+a list of parser definitions and associated functions that
+facilitates both facts gathering and native command generation for
+the given network resource.
+"""
+
+import re
+from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.network_template import (
+ NetworkTemplate,
+)
+
+
+class Prefix_listsTemplate(NetworkTemplate):
+ def __init__(self, lines=None, module=None):
+ prefix = {"set": "set", "remove": "delete"}
+ super(Prefix_listsTemplate, self).__init__(
+ lines=lines, tmplt=self, module=module, prefix=prefix
+ )
+
+ # fmt: off
+ PARSERS = [
+ # policy prefix-list <list-name>
+ {
+ "name": "name",
+ "getval": re.compile(
+ r"""
+ ^set
+ \spolicy
+ \sprefix-(?P<afi>\S+)
+ \s(?P<name>\S+)
+ $""", re.VERBOSE),
+ "setval": "policy prefix-{{ 'list' if afi == 'ipv4' else 'list6' }} {{ name }}",
+ "result": {
+ "{{ 'ipv4' if afi == 'list' else 'ipv6' }}": {
+ "afi": "{{ 'ipv4' if afi == 'list' else 'ipv6' }}",
+ "prefix_lists": {
+ "{{ name }}": {
+ "name": "{{ name }}",
+ }
+ }
+ }
+ },
+ },
+
+ # policy prefix-list <list-name> description <desc>
+ {
+ "name": "description",
+ "getval": re.compile(
+ r"""
+ ^set
+ \spolicy
+ \sprefix-(?P<afi>\S+)
+ \s(?P<name>\S+)
+ \sdescription\s'(?P<description>.+)'
+ $""", re.VERBOSE),
+ "setval": "policy prefix-{{ 'list' if afi == 'ipv4' else 'list6' }} {{ name }} description '{{ description }}'",
+ "result": {
+ "{{ 'ipv4' if afi == 'list' else 'ipv6' }}": {
+ "afi": "{{ 'ipv4' if afi == 'list' else 'ipv6' }}",
+ "prefix_lists": {
+ "{{ name }}": {
+ "name": "{{ name }}",
+ "description": "{{ description }}"
+ }
+ }
+ }
+ },
+ },
+
+ # policy prefix-list <list-name> rule <rule-num>
+ {
+ "name": "sequence",
+ "getval": re.compile(
+ r"""
+ ^set
+ \spolicy
+ \sprefix-(?P<afi>\S+)
+ \s(?P<name>\S+)
+ \srule\s(?P<sequence>\d+)
+ $""", re.VERBOSE),
+ "setval": "policy prefix-{{ 'list' if afi == 'ipv4' else 'list6' }} {{ name }} rule {{ sequence }}",
+ "result": {
+ "{{ 'ipv4' if afi == 'list' else 'ipv6' }}": {
+ "afi": "{{ 'ipv4' if afi == 'list' else 'ipv6' }}",
+ "prefix_lists": {
+ "{{ name }}": {
+ "name": "{{ name }}",
+ "entries": {
+ "{{ sequence }}": {
+ "sequence": "{{ sequence }}"
+ }
+ }
+ }
+ }
+ }
+ },
+ },
+
+ # policy prefix-list <list-name> rule <rule-num> action
+ {
+ "name": "action",
+ "getval": re.compile(
+ r"""
+ ^set
+ \spolicy
+ \sprefix-(?P<afi>\S+)
+ \s(?P<name>\S+)
+ \srule\s(?P<sequence>\d+)
+ \saction\s'(?P<action>permit|deny)'
+ $""", re.VERBOSE),
+ "setval": "policy prefix-{{ 'list' if afi == 'ipv4' else 'list6' }} {{ name }} rule {{ sequence }} action '{{ action }}'",
+ "result": {
+ "{{ 'ipv4' if afi == 'list' else 'ipv6' }}": {
+ "afi": "{{ 'ipv4' if afi == 'list' else 'ipv6' }}",
+ "prefix_lists": {
+ "{{ name }}": {
+ "name": "{{ name }}",
+ "entries": {
+ "{{ sequence }}": {
+ "sequence": "{{ sequence }}",
+ "action": "{{ action }}"
+ }
+ }
+ }
+ }
+ }
+ },
+ },
+
+ # policy prefix-list <list-name> rule <rule-num> description <desc>
+ {
+ "name": "rule_description",
+ "getval": re.compile(
+ r"""
+ ^set
+ \spolicy
+ \sprefix-(?P<afi>\S+)
+ \s(?P<name>\S+)
+ \srule\s(?P<sequence>\d+)
+ \sdescription\s'(?P<rule_description>.+)'
+ $""", re.VERBOSE),
+ "compval": "description",
+ "setval": "policy prefix-{{ 'list' if afi == 'ipv4' else 'list6' }} {{ name }} rule {{ sequence }} description '{{ description }}'",
+ "result": {
+ "{{ 'ipv4' if afi == 'list' else 'ipv6' }}": {
+ "afi": "{{ 'ipv4' if afi == 'list' else 'ipv6' }}",
+ "prefix_lists": {
+ "{{ name }}": {
+ "name": "{{ name }}",
+ "entries": {
+ "{{ sequence }}": {
+ "sequence": "{{ sequence }}",
+ "description": "{{ rule_description }}"
+ }
+ }
+ }
+ }
+ }
+ },
+ },
+
+ # policy prefix-list <list-name> rule <rule-num> ge <value>
+ {
+ "name": "ge",
+ "getval": re.compile(
+ r"""
+ ^set
+ \spolicy
+ \sprefix-(?P<afi>\S+)
+ \s(?P<name>\S+)
+ \srule\s(?P<sequence>\d+)
+ \sge\s'(?P<ge>\d+)'
+ $""", re.VERBOSE),
+ "setval": "policy prefix-{{ 'list' if afi == 'ipv4' else 'list6' }} {{ name }} rule {{ sequence }} ge '{{ ge }}'",
+ "result": {
+ "{{ 'ipv4' if afi == 'list' else 'ipv6' }}": {
+ "afi": "{{ 'ipv4' if afi == 'list' else 'ipv6' }}",
+ "prefix_lists": {
+ "{{ name }}": {
+ "name": "{{ name }}",
+ "entries": {
+ "{{ sequence }}": {
+ "sequence": "{{ sequence }}",
+ "ge": "{{ ge }}"
+ }
+ }
+ }
+ }
+ }
+ },
+ },
+
+ # policy prefix-list <list-name> rule <rule-num> le <value>
+ {
+ "name": "le",
+ "getval": re.compile(
+ r"""
+ ^set
+ \spolicy
+ \sprefix-(?P<afi>\S+)
+ \s(?P<name>\S+)
+ \srule\s(?P<sequence>\d+)
+ \sle\s'(?P<le>\d+)'
+ $""", re.VERBOSE),
+ "setval": "policy prefix-{{ 'list' if afi == 'ipv4' else 'list6' }} {{ name }} rule {{ sequence }} le '{{ le }}'",
+ "result": {
+ "{{ 'ipv4' if afi == 'list' else 'ipv6' }}": {
+ "afi": "{{ 'ipv4' if afi == 'list' else 'ipv6' }}",
+ "prefix_lists": {
+ "{{ name }}": {
+ "name": "{{ name }}",
+ "entries": {
+ "{{ sequence }}": {
+ "sequence": "{{ sequence }}",
+ "le": "{{ le }}"
+ }
+ }
+ }
+ }
+ }
+ },
+ },
+
+ # policy prefix-list <list-name> rule <rule-num> prefix <ip>
+ {
+ "name": "prefix",
+ "getval": re.compile(
+ r"""
+ ^set
+ \spolicy
+ \sprefix-(?P<afi>\S+)
+ \s(?P<name>\S+)
+ \srule\s(?P<sequence>\d+)
+ \sprefix\s'(?P<prefix>\S+)'
+ $""", re.VERBOSE),
+ "setval": "policy prefix-{{ 'list' if afi == 'ipv4' else 'list6' }} {{ name }} rule {{ sequence }} prefix '{{ prefix }}'",
+ "result": {
+ "{{ 'ipv4' if afi == 'list' else 'ipv6' }}": {
+ "afi": "{{ 'ipv4' if afi == 'list' else 'ipv6' }}",
+ "prefix_lists": {
+ "{{ name }}": {
+ "name": "{{ name }}",
+ "entries": {
+ "{{ sequence }}": {
+ "sequence": "{{ sequence }}",
+ "prefix": "{{ prefix }}"
+ }
+ }
+ }
+ }
+ }
+ },
+ },
+ ]
+ # fmt: on
diff --git a/plugins/modules/vyos_prefix_lists.py b/plugins/modules/vyos_prefix_lists.py
new file mode 100644
index 0000000..8b67caf
--- /dev/null
+++ b/plugins/modules/vyos_prefix_lists.py
@@ -0,0 +1,1329 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+# Copyright 2021 Red Hat
+# GNU General Public License v3.0+
+# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
+
+"""
+The module file for vyos_prefix_lists
+"""
+
+from __future__ import absolute_import, division, print_function
+
+__metaclass__ = type
+
+DOCUMENTATION = """
+module: vyos_prefix_lists
+short_description: Prefix-Lists resource module for VyOS
+description:
+ - This module manages prefix-lists configuration on devices running VyOS
+version_added: 2.4.0
+author: Priyam Sahoo (@priyamsahoo)
+notes:
+ - Tested against VyOS 1.1.8 (helium)
+ - This module works with connection C(network_cli)
+options:
+ config:
+ description: A list of prefix-list options
+ type: list
+ elements: dict
+ suboptions:
+ afi:
+ description: The Address Family Indicator (AFI) for the prefix-lists
+ type: str
+ choices: ["ipv4", "ipv6"]
+ required: true
+ prefix_lists:
+ description: A list of prefix-list configurations
+ type: list
+ elements: dict
+ suboptions:
+ name:
+ description: The name of a defined prefix-list
+ type: str
+ required: true
+ description:
+ description: A brief text description for the prefix-list
+ type: str
+ entries:
+ description: Rule configurations for the prefix-list
+ type: list
+ elements: dict
+ suboptions:
+ sequence:
+ description: A numeric identifier for the rule
+ type: int
+ required: true
+ description:
+ description: A brief text description for the prefix list rule
+ type: str
+ action:
+ description: The action to be taken for packets matching a prefix list rule
+ type: str
+ choices: ["permit", "deny"]
+ ge:
+ description: Minimum prefix length to be matched
+ type: int
+ le:
+ description: Maximum prefix list length to be matched
+ type: int
+ prefix:
+ description: IPv4 or IPv6 prefix in A.B.C.D/LEN or A:B::C:D/LEN format
+ 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 prefix-list).
+ - 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 the configuration should be left in
+ type: str
+ choices:
+ - merged
+ - replaced
+ - overridden
+ - deleted
+ - gathered
+ - rendered
+ - parsed
+ default: merged
+"""
+
+EXAMPLES = """
+# # -------------------
+# # 1. Using merged
+# # -------------------
+
+# # Before state:
+# # -------------
+# vyos@vyos:~$ show configuration commands | grep prefix-list
+# vyos@vyos:~$
+
+# # Task
+# # -------------
+# - name: Merge the provided configuration with the existing running configuration
+# vyos.vyos.vyos_prefix_lists:
+# config:
+# - afi: "ipv4"
+# prefix_lists:
+# - name: "AnsibleIPv4PrefixList"
+# description: "PL configured by ansible"
+# entries:
+# - sequence: 2
+# description: "Rule 2 given by ansible"
+# action: "permit"
+# prefix: "92.168.10.0/26"
+# le: 32
+
+# - sequence: 3
+# description: "Rule 3"
+# action: "deny"
+# prefix: "72.168.2.0/24"
+# ge: 26
+
+# - afi: "ipv6"
+# prefix_lists:
+# - name: "AllowIPv6Prefix"
+# description: "Configured by ansible for allowing IPv6 networks"
+# entries:
+# - sequence: 5
+# description: "Permit rule"
+# action: "permit"
+# prefix: "2001:db8:8000::/35"
+# le: 37
+
+# - name: DenyIPv6Prefix
+# description: "Configured by ansible for disallowing IPv6 networks"
+# entries:
+# - sequence: 8
+# action: deny
+# prefix: "2001:db8:2000::/35"
+# le: 37
+# state: merged
+
+# # Task output:
+# # -------------
+# "after": [
+# {
+# "afi": "ipv4",
+# "prefix_lists": [
+# {
+# "description": "PL configured by ansible",
+# "name": "AnsibleIPv4PrefixList",
+# "entries": [
+# {
+# "action": "permit",
+# "description": "Rule 2 given by ansible",
+# "sequence": 2,
+# "le": 32,
+# "prefix": "92.168.10.0/26"
+# },
+# {
+# "action": "deny",
+# "description": "Rule 3",
+# "ge": 26,
+# "sequence": 3,
+# "prefix": "72.168.2.0/24"
+# }
+# ]
+# }
+# ]
+# },
+# {
+# "afi": "ipv6",
+# "prefix_lists": [
+# {
+# "description": "Configured by ansible for allowing IPv6 networks",
+# "name": "AllowIPv6Prefix",
+# "entries": [
+# {
+# "action": "permit",
+# "description": "Permit rule",
+# "sequence": 5,
+# "le": 37,
+# "prefix": "2001:db8:8000::/35"
+# }
+# ]
+# },
+# {
+# "description": "Configured by ansible for disallowing IPv6 networks",
+# "name": "DenyIPv6Prefix",
+# "entries": [
+# {
+# "action": "deny",
+# "sequence": 8,
+# "le": 37,
+# "prefix": "2001:db8:2000::/35"
+# }
+# ]
+# }
+# ]
+# }
+# ],
+# "before": [],
+# "changed": true,
+# "commands": [
+# "set policy prefix-list AnsibleIPv4PrefixList",
+# "set policy prefix-list AnsibleIPv4PrefixList description 'PL configured by ansible'",
+# "set policy prefix-list AnsibleIPv4PrefixList rule 2",
+# "set policy prefix-list AnsibleIPv4PrefixList rule 2 action 'permit'",
+# "set policy prefix-list AnsibleIPv4PrefixList rule 2 description 'Rule 2 given by ansible'",
+# "set policy prefix-list AnsibleIPv4PrefixList rule 2 le '32'",
+# "set policy prefix-list AnsibleIPv4PrefixList rule 2 prefix '92.168.10.0/26'",
+# "set policy prefix-list AnsibleIPv4PrefixList rule 3",
+# "set policy prefix-list AnsibleIPv4PrefixList rule 3 action 'deny'",
+# "set policy prefix-list AnsibleIPv4PrefixList rule 3 description 'Rule 3'",
+# "set policy prefix-list AnsibleIPv4PrefixList rule 3 ge '26'",
+# "set policy prefix-list AnsibleIPv4PrefixList rule 3 prefix '72.168.2.0/24'",
+# "set policy prefix-list6 AllowIPv6Prefix",
+# "set policy prefix-list6 AllowIPv6Prefix description 'Configured by ansible for allowing IPv6 networks'",
+# "set policy prefix-list6 AllowIPv6Prefix rule 5",
+# "set policy prefix-list6 AllowIPv6Prefix rule 5 action 'permit'",
+# "set policy prefix-list6 AllowIPv6Prefix rule 5 description 'Permit rule'",
+# "set policy prefix-list6 AllowIPv6Prefix rule 5 le '37'",
+# "set policy prefix-list6 AllowIPv6Prefix rule 5 prefix '2001:db8:8000::/35'",
+# "set policy prefix-list6 DenyIPv6Prefix",
+# "set policy prefix-list6 DenyIPv6Prefix description 'Configured by ansible for disallowing IPv6 networks'",
+# "set policy prefix-list6 DenyIPv6Prefix rule 8",
+# "set policy prefix-list6 DenyIPv6Prefix rule 8 action 'deny'",
+# "set policy prefix-list6 DenyIPv6Prefix rule 8 le '37'",
+# "set policy prefix-list6 DenyIPv6Prefix rule 8 prefix '2001:db8:2000::/35'"
+# ]
+
+# After state:
+# # -------------
+# vyos@vyos:~$ show configuration commands | grep prefix-list
+# set policy prefix-list AnsibleIPv4PrefixList description 'PL configured by ansible'
+# set policy prefix-list AnsibleIPv4PrefixList rule 2 action 'permit'
+# set policy prefix-list AnsibleIPv4PrefixList rule 2 description 'Rule 2 given by ansible'
+# set policy prefix-list AnsibleIPv4PrefixList rule 2 le '32'
+# set policy prefix-list AnsibleIPv4PrefixList rule 2 prefix '92.168.10.0/26'
+# set policy prefix-list AnsibleIPv4PrefixList rule 3 action 'deny'
+# set policy prefix-list AnsibleIPv4PrefixList rule 3 description 'Rule 3'
+# set policy prefix-list AnsibleIPv4PrefixList rule 3 ge '26'
+# set policy prefix-list AnsibleIPv4PrefixList rule 3 prefix '72.168.2.0/24'
+# set policy prefix-list6 AllowIPv6Prefix description 'Configured by ansible for allowing IPv6 networks'
+# set policy prefix-list6 AllowIPv6Prefix rule 5 action 'permit'
+# set policy prefix-list6 AllowIPv6Prefix rule 5 description 'Permit rule'
+# set policy prefix-list6 AllowIPv6Prefix rule 5 le '37'
+# set policy prefix-list6 AllowIPv6Prefix rule 5 prefix '2001:db8:8000::/35'
+# set policy prefix-list6 DenyIPv6Prefix description 'Configured by ansible for disallowing IPv6 networks'
+# set policy prefix-list6 DenyIPv6Prefix rule 8 action 'deny'
+# set policy prefix-list6 DenyIPv6Prefix rule 8 le '37'
+# set policy prefix-list6 DenyIPv6Prefix rule 8 prefix '2001:db8:2000::/35'
+# vyos@vyos:~$
+
+
+# # -------------------
+# # 2. Using replaced
+# # -------------------
+
+# # Before state:
+# # -------------
+# vyos@vyos:~$ show configuration commands | grep prefix-list
+# set policy prefix-list AnsibleIPv4PrefixList description 'PL configured by ansible'
+# set policy prefix-list AnsibleIPv4PrefixList rule 2 action 'permit'
+# set policy prefix-list AnsibleIPv4PrefixList rule 2 description 'Rule 2 given by ansible'
+# set policy prefix-list AnsibleIPv4PrefixList rule 2 le '32'
+# set policy prefix-list AnsibleIPv4PrefixList rule 2 prefix '92.168.10.0/26'
+# set policy prefix-list AnsibleIPv4PrefixList rule 3 action 'deny'
+# set policy prefix-list AnsibleIPv4PrefixList rule 3 description 'Rule 3'
+# set policy prefix-list AnsibleIPv4PrefixList rule 3 ge '26'
+# set policy prefix-list AnsibleIPv4PrefixList rule 3 prefix '72.168.2.0/24'
+# set policy prefix-list6 AllowIPv6Prefix description 'Configured by ansible for allowing IPv6 networks'
+# set policy prefix-list6 AllowIPv6Prefix rule 5 action 'permit'
+# set policy prefix-list6 AllowIPv6Prefix rule 5 description 'Permit rule'
+# set policy prefix-list6 AllowIPv6Prefix rule 5 le '37'
+# set policy prefix-list6 AllowIPv6Prefix rule 5 prefix '2001:db8:8000::/35'
+# set policy prefix-list6 DenyIPv6Prefix description 'Configured by ansible for disallowing IPv6 networks'
+# set policy prefix-list6 DenyIPv6Prefix rule 8 action 'deny'
+# set policy prefix-list6 DenyIPv6Prefix rule 8 le '37'
+# set policy prefix-list6 DenyIPv6Prefix rule 8 prefix '2001:db8:2000::/35'
+# vyos@vyos:~$
+
+# # Task:
+# # -------------
+# - name: Replace prefix-lists configurations of listed prefix-lists with provided configurations
+# vyos.vyos.vyos_prefix_lists:
+# config:
+# - afi: "ipv4"
+# prefix_lists:
+# - name: "AnsibleIPv4PrefixList"
+# description: "Configuration replaced by ansible"
+# entries:
+# - sequence: 3
+# description: "Rule 3 replaced by ansible"
+# action: "permit"
+# prefix: "82.168.2.0/24"
+# ge: 26
+# state: replaced
+
+# # Task output:
+# # -------------
+# "after": [
+# {
+# "afi": "ipv4",
+# "prefix_lists": [
+# {
+# "description": "Configuration replaced by ansible",
+# "name": "AnsibleIPv4PrefixList",
+# "entries": [
+# {
+# "action": "permit",
+# "description": "Rule 3 replaced by ansible",
+# "ge": 26,
+# "sequence": 3,
+# "prefix": "82.168.2.0/24"
+# }
+# ]
+# }
+# ]
+# },
+# {
+# "afi": "ipv6",
+# "prefix_lists": [
+# {
+# "description": "Configured by ansible for allowing IPv6 networks",
+# "name": "AllowIPv6Prefix",
+# "entries": [
+# {
+# "action": "permit",
+# "description": "Permit rule",
+# "sequence": 5,
+# "le": 37,
+# "prefix": "2001:db8:8000::/35"
+# }
+# ]
+# },
+# {
+# "description": "Configured by ansible for disallowing IPv6 networks",
+# "name": "DenyIPv6Prefix",
+# "entries": [
+# {
+# "action": "deny",
+# "sequence": 8,
+# "le": 37,
+# "prefix": "2001:db8:2000::/35"
+# }
+# ]
+# }
+# ]
+# }
+# ],
+# "before": [
+# {
+# "afi": "ipv4",
+# "prefix_lists": [
+# {
+# "description": "PL configured by ansible",
+# "name": "AnsibleIPv4PrefixList",
+# "entries": [
+# {
+# "action": "permit",
+# "description": "Rule 2 given by ansible",
+# "sequence": 2,
+# "le": 32,
+# "prefix": "92.168.10.0/26"
+# },
+# {
+# "action": "deny",
+# "description": "Rule 3",
+# "ge": 26,
+# "sequence": 3,
+# "prefix": "72.168.2.0/24"
+# }
+# ]
+# }
+# ]
+# },
+# {
+# "afi": "ipv6",
+# "prefix_lists": [
+# {
+# "description": "Configured by ansible for allowing IPv6 networks",
+# "name": "AllowIPv6Prefix",
+# "entries": [
+# {
+# "action": "permit",
+# "description": "Permit rule",
+# "sequence": 5,
+# "le": 37,
+# "prefix": "2001:db8:8000::/35"
+# }
+# ]
+# },
+# {
+# "description": "Configured by ansible for disallowing IPv6 networks",
+# "name": "DenyIPv6Prefix",
+# "entries": [
+# {
+# "action": "deny",
+# "sequence": 8,
+# "le": 37,
+# "prefix": "2001:db8:2000::/35"
+# }
+# ]
+# }
+# ]
+# }
+# ],
+# "changed": true,
+# "commands": [
+# "set policy prefix-list AnsibleIPv4PrefixList description 'Configuration replaced by ansible'",
+# "set policy prefix-list AnsibleIPv4PrefixList rule 3 action 'permit'",
+# "set policy prefix-list AnsibleIPv4PrefixList rule 3 description 'Rule 3 replaced by ansible'",
+# "set policy prefix-list AnsibleIPv4PrefixList rule 3 prefix '82.168.2.0/24'",
+# "delete policy prefix-list AnsibleIPv4PrefixList rule 2"
+# ]
+
+# # After state:
+# # -------------
+# vyos@vyos:~$ show configuration commands | grep prefix-list
+# set policy prefix-list AnsibleIPv4PrefixList description 'Configuration replaced by ansible'
+# set policy prefix-list AnsibleIPv4PrefixList rule 3 action 'permit'
+# set policy prefix-list AnsibleIPv4PrefixList rule 3 description 'Rule 3 replaced by ansible'
+# set policy prefix-list AnsibleIPv4PrefixList rule 3 ge '26'
+# set policy prefix-list AnsibleIPv4PrefixList rule 3 prefix '82.168.2.0/24'
+# set policy prefix-list6 AllowIPv6Prefix description 'Configured by ansible for allowing IPv6 networks'
+# set policy prefix-list6 AllowIPv6Prefix rule 5 action 'permit'
+# set policy prefix-list6 AllowIPv6Prefix rule 5 description 'Permit rule'
+# set policy prefix-list6 AllowIPv6Prefix rule 5 le '37'
+# set policy prefix-list6 AllowIPv6Prefix rule 5 prefix '2001:db8:8000::/35'
+# set policy prefix-list6 DenyIPv6Prefix description 'Configured by ansible for disallowing IPv6 networks'
+# set policy prefix-list6 DenyIPv6Prefix rule 8 action 'deny'
+# set policy prefix-list6 DenyIPv6Prefix rule 8 le '37'
+# set policy prefix-list6 DenyIPv6Prefix rule 8 prefix '2001:db8:2000::/35'
+# vyos@vyos:~$
+
+
+# # -------------------
+# # 3. Using overridden
+# # -------------------
+
+# # Before state:
+# # -------------
+# vyos@vyos:~$ show configuration commands | grep prefix-list
+# set policy prefix-list AnsibleIPv4PrefixList description 'PL configured by ansible'
+# set policy prefix-list AnsibleIPv4PrefixList rule 2 action 'permit'
+# set policy prefix-list AnsibleIPv4PrefixList rule 2 description 'Rule 2 given by ansible'
+# set policy prefix-list AnsibleIPv4PrefixList rule 2 le '32'
+# set policy prefix-list AnsibleIPv4PrefixList rule 2 prefix '92.168.10.0/26'
+# set policy prefix-list AnsibleIPv4PrefixList rule 3 action 'deny'
+# set policy prefix-list AnsibleIPv4PrefixList rule 3 description 'Rule 3'
+# set policy prefix-list AnsibleIPv4PrefixList rule 3 ge '26'
+# set policy prefix-list AnsibleIPv4PrefixList rule 3 prefix '72.168.2.0/24'
+# set policy prefix-list6 AllowIPv6Prefix description 'Configured by ansible for allowing IPv6 networks'
+# set policy prefix-list6 AllowIPv6Prefix rule 5 action 'permit'
+# set policy prefix-list6 AllowIPv6Prefix rule 5 description 'Permit rule'
+# set policy prefix-list6 AllowIPv6Prefix rule 5 le '37'
+# set policy prefix-list6 AllowIPv6Prefix rule 5 prefix '2001:db8:8000::/35'
+# set policy prefix-list6 DenyIPv6Prefix description 'Configured by ansible for disallowing IPv6 networks'
+# set policy prefix-list6 DenyIPv6Prefix rule 8 action 'deny'
+# set policy prefix-list6 DenyIPv6Prefix rule 8 le '37'
+# set policy prefix-list6 DenyIPv6Prefix rule 8 prefix '2001:db8:2000::/35'
+# vyos@vyos:~$
+
+# # Task:
+# # -------------
+# - name: Override all prefix-lists configuration with provided configuration
+# vyos.vyos.vyos_prefix_lists:
+# config:
+# - afi: "ipv4"
+# prefix_lists:
+# - name: "AnsibleIPv4PrefixList"
+# description: Rule 2 overridden by ansible
+# entries:
+# - sequence: 2
+# action: "deny"
+# ge: 26
+# prefix: "82.168.2.0/24"
+
+# - name: "OverriddenPrefixList"
+# description: Configuration overridden by ansible
+# entries:
+# - sequence: 10
+# action: permit
+# prefix: "203.0.113.96/27"
+# le: 32
+# state: overridden
+
+# # Task output:
+# # -------------
+# "after": [
+# {
+# "afi": "ipv4",
+# "prefix_lists": [
+# {
+# "description": "Rule 2 overridden by ansible",
+# "name": "AnsibleIPv4PrefixList",
+# "entries": [
+# {
+# "action": "deny",
+# "ge": 26,
+# "sequence": 2,
+# "prefix": "82.168.2.0/24"
+# }
+# ]
+# },
+# {
+# "description": "Configuration overridden by ansible",
+# "name": "OverriddenPrefixList",
+# "entries": [
+# {
+# "action": "permit",
+# "sequence": 10,
+# "le": 32,
+# "prefix": "203.0.113.96/27"
+# }
+# ]
+# }
+# ]
+# }
+# ],
+# "before": [
+# {
+# "afi": "ipv4",
+# "prefix_lists": [
+# {
+# "description": "PL configured by ansible",
+# "name": "AnsibleIPv4PrefixList",
+# "entries": [
+# {
+# "action": "permit",
+# "description": "Rule 2 given by ansible",
+# "sequence": 2,
+# "le": 32,
+# "prefix": "92.168.10.0/26"
+# },
+# {
+# "action": "deny",
+# "description": "Rule 3",
+# "ge": 26,
+# "sequence": 3,
+# "prefix": "72.168.2.0/24"
+# }
+# ]
+# }
+# ]
+# },
+# {
+# "afi": "ipv6",
+# "prefix_lists": [
+# {
+# "description": "Configured by ansible for allowing IPv6 networks",
+# "name": "AllowIPv6Prefix",
+# "entries": [
+# {
+# "action": "permit",
+# "description": "Permit rule",
+# "sequence": 5,
+# "le": 37,
+# "prefix": "2001:db8:8000::/35"
+# }
+# ]
+# },
+# {
+# "description": "Configured by ansible for disallowing IPv6 networks",
+# "name": "DenyIPv6Prefix",
+# "entries": [
+# {
+# "action": "deny",
+# "sequence": 8,
+# "le": 37,
+# "prefix": "2001:db8:2000::/35"
+# }
+# ]
+# }
+# ]
+# }
+# ],
+# "changed": true,
+# "commands": [
+# "delete policy prefix-list6 AllowIPv6Prefix",
+# "delete policy prefix-list6 DenyIPv6Prefix",
+# "set policy prefix-list AnsibleIPv4PrefixList description 'Rule 2 overridden by ansible'",
+# "set policy prefix-list AnsibleIPv4PrefixList rule 2 action 'deny'",
+# "delete policy prefix-list AnsibleIPv4PrefixList rule 2 description 'Rule 2 given by ansible'",
+# "set policy prefix-list AnsibleIPv4PrefixList rule 2 ge '26'",
+# "delete policy prefix-list AnsibleIPv4PrefixList rule 2 le '32'",
+# "set policy prefix-list AnsibleIPv4PrefixList rule 2 prefix '82.168.2.0/24'",
+# "delete policy prefix-list AnsibleIPv4PrefixList rule 3",
+# "set policy prefix-list OverriddenPrefixList",
+# "set policy prefix-list OverriddenPrefixList description 'Configuration overridden by ansible'",
+# "set policy prefix-list OverriddenPrefixList rule 10",
+# "set policy prefix-list OverriddenPrefixList rule 10 action 'permit'",
+# "set policy prefix-list OverriddenPrefixList rule 10 le '32'",
+# "set policy prefix-list OverriddenPrefixList rule 10 prefix '203.0.113.96/27'"
+# ]
+
+# # After state:
+# # -------------
+# vyos@vyos:~$ show configuration commands | grep prefix-list
+# set policy prefix-list AnsibleIPv4PrefixList description 'Rule 2 overridden by ansible'
+# set policy prefix-list AnsibleIPv4PrefixList rule 2 action 'deny'
+# set policy prefix-list AnsibleIPv4PrefixList rule 2 ge '26'
+# set policy prefix-list AnsibleIPv4PrefixList rule 2 prefix '82.168.2.0/24'
+# set policy prefix-list OverriddenPrefixList description 'Configuration overridden by ansible'
+# set policy prefix-list OverriddenPrefixList rule 10 action 'permit'
+# set policy prefix-list OverriddenPrefixList rule 10 le '32'
+# set policy prefix-list OverriddenPrefixList rule 10 prefix '203.0.113.96/27'
+# vyos@vyos:~$
+
+
+# # -------------------
+# # 4(i). Using deleted (to delete all prefix lists from the device)
+# # -------------------
+
+# # Before state:
+# # -------------
+# vyos@vyos:~$ show configuration commands | grep prefix-list
+# set policy prefix-list AnsibleIPv4PrefixList description 'PL configured by ansible'
+# set policy prefix-list AnsibleIPv4PrefixList rule 2 action 'permit'
+# set policy prefix-list AnsibleIPv4PrefixList rule 2 description 'Rule 2 given by ansible'
+# set policy prefix-list AnsibleIPv4PrefixList rule 2 le '32'
+# set policy prefix-list AnsibleIPv4PrefixList rule 2 prefix '92.168.10.0/26'
+# set policy prefix-list AnsibleIPv4PrefixList rule 3 action 'deny'
+# set policy prefix-list AnsibleIPv4PrefixList rule 3 description 'Rule 3'
+# set policy prefix-list AnsibleIPv4PrefixList rule 3 ge '26'
+# set policy prefix-list AnsibleIPv4PrefixList rule 3 prefix '72.168.2.0/24'
+# set policy prefix-list6 AllowIPv6Prefix description 'Configured by ansible for allowing IPv6 networks'
+# set policy prefix-list6 AllowIPv6Prefix rule 5 action 'permit'
+# set policy prefix-list6 AllowIPv6Prefix rule 5 description 'Permit rule'
+# set policy prefix-list6 AllowIPv6Prefix rule 5 le '37'
+# set policy prefix-list6 AllowIPv6Prefix rule 5 prefix '2001:db8:8000::/35'
+# set policy prefix-list6 DenyIPv6Prefix description 'Configured by ansible for disallowing IPv6 networks'
+# set policy prefix-list6 DenyIPv6Prefix rule 8 action 'deny'
+# set policy prefix-list6 DenyIPv6Prefix rule 8 le '37'
+# set policy prefix-list6 DenyIPv6Prefix rule 8 prefix '2001:db8:2000::/35'
+# vyos@vyos:~$
+
+# # Task:
+# # -------------
+# - name: Delete all prefix-lists
+# vyos.vyos.vyos_prefix_lists:
+# config:
+# state: deleted
+
+# # Task output:
+# # -------------
+# "after": [],
+# "before": [
+# {
+# "afi": "ipv4",
+# "prefix_lists": [
+# {
+# "description": "PL configured by ansible",
+# "name": "AnsibleIPv4PrefixList",
+# "entries": [
+# {
+# "action": "permit",
+# "description": "Rule 2 given by ansible",
+# "sequence": 2,
+# "le": 32,
+# "prefix": "92.168.10.0/26"
+# },
+# {
+# "action": "deny",
+# "description": "Rule 3",
+# "ge": 26,
+# "sequence": 3,
+# "prefix": "72.168.2.0/24"
+# }
+# ]
+# }
+# ]
+# },
+# {
+# "afi": "ipv6",
+# "prefix_lists": [
+# {
+# "description": "Configured by ansible for allowing IPv6 networks",
+# "name": "AllowIPv6Prefix",
+# "entries": [
+# {
+# "action": "permit",
+# "description": "Permit rule",
+# "sequence": 5,
+# "le": 37,
+# "prefix": "2001:db8:8000::/35"
+# }
+# ]
+# },
+# {
+# "description": "Configured by ansible for disallowing IPv6 networks",
+# "name": "DenyIPv6Prefix",
+# "entries": [
+# {
+# "action": "deny",
+# "sequence": 8,
+# "le": 37,
+# "prefix": "2001:db8:2000::/35"
+# }
+# ]
+# }
+# ]
+# }
+# ],
+# "changed": true,
+# "commands": [
+# "delete policy prefix-list AnsibleIPv4PrefixList",
+# "delete policy prefix-list6 AllowIPv6Prefix",
+# "delete policy prefix-list6 DenyIPv6Prefix"
+# ]
+
+# # After state:
+# # -------------
+# vyos@vyos:~$ show configuration commands | grep prefix-list
+# vyos@vyos:~$
+
+
+# # -------------------
+# # 4(ii). Using deleted (to delete all prefix lists for an AFI)
+# # -------------------
+
+# # Before state:
+# # -------------
+# vyos@vyos:~$ show configuration commands | grep prefix-list
+# set policy prefix-list AnsibleIPv4PrefixList description 'PL configured by ansible'
+# set policy prefix-list AnsibleIPv4PrefixList rule 2 action 'permit'
+# set policy prefix-list AnsibleIPv4PrefixList rule 2 description 'Rule 2 given by ansible'
+# set policy prefix-list AnsibleIPv4PrefixList rule 2 le '32'
+# set policy prefix-list AnsibleIPv4PrefixList rule 2 prefix '92.168.10.0/26'
+# set policy prefix-list AnsibleIPv4PrefixList rule 3 action 'deny'
+# set policy prefix-list AnsibleIPv4PrefixList rule 3 description 'Rule 3'
+# set policy prefix-list AnsibleIPv4PrefixList rule 3 ge '26'
+# set policy prefix-list AnsibleIPv4PrefixList rule 3 prefix '72.168.2.0/24'
+# set policy prefix-list6 AllowIPv6Prefix description 'Configured by ansible for allowing IPv6 networks'
+# set policy prefix-list6 AllowIPv6Prefix rule 5 action 'permit'
+# set policy prefix-list6 AllowIPv6Prefix rule 5 description 'Permit rule'
+# set policy prefix-list6 AllowIPv6Prefix rule 5 le '37'
+# set policy prefix-list6 AllowIPv6Prefix rule 5 prefix '2001:db8:8000::/35'
+# set policy prefix-list6 DenyIPv6Prefix description 'Configured by ansible for disallowing IPv6 networks'
+# set policy prefix-list6 DenyIPv6Prefix rule 8 action 'deny'
+# set policy prefix-list6 DenyIPv6Prefix rule 8 le '37'
+# set policy prefix-list6 DenyIPv6Prefix rule 8 prefix '2001:db8:2000::/35'
+# vyos@vyos:~$
+
+# # Task:
+# # -------------
+# - name: Delete all prefix-lists for IPv6 AFI
+# vyos.vyos.vyos_prefix_lists:
+# config:
+# - afi: "ipv6"
+# state: deleted
+
+# # Task output:
+# # -------------
+# "after": [
+# {
+# "afi": "ipv4",
+# "prefix_lists": [
+# {
+# "description": "PL configured by ansible",
+# "name": "AnsibleIPv4PrefixList",
+# "entries": [
+# {
+# "action": "permit",
+# "description": "Rule 2 given by ansible",
+# "sequence": 2,
+# "le": 32,
+# "prefix": "92.168.10.0/26"
+# },
+# {
+# "action": "deny",
+# "description": "Rule 3",
+# "ge": 26,
+# "sequence": 3,
+# "prefix": "72.168.2.0/24"
+# }
+# ]
+# }
+# ]
+# }
+# ],
+# "before": [
+# {
+# "afi": "ipv4",
+# "prefix_lists": [
+# {
+# "description": "PL configured by ansible",
+# "name": "AnsibleIPv4PrefixList",
+# "entries": [
+# {
+# "action": "permit",
+# "description": "Rule 2 given by ansible",
+# "sequence": 2,
+# "le": 32,
+# "prefix": "92.168.10.0/26"
+# },
+# {
+# "action": "deny",
+# "description": "Rule 3",
+# "ge": 26,
+# "sequence": 3,
+# "prefix": "72.168.2.0/24"
+# }
+# ]
+# }
+# ]
+# },
+# {
+# "afi": "ipv6",
+# "prefix_lists": [
+# {
+# "description": "Configured by ansible for allowing IPv6 networks",
+# "name": "AllowIPv6Prefix",
+# "entries": [
+# {
+# "action": "permit",
+# "description": "Permit rule",
+# "sequence": 5,
+# "le": 37,
+# "prefix": "2001:db8:8000::/35"
+# }
+# ]
+# },
+# {
+# "description": "Configured by ansible for disallowing IPv6 networks",
+# "name": "DenyIPv6Prefix",
+# "entries": [
+# {
+# "action": "deny",
+# "sequence": 8,
+# "le": 37,
+# "prefix": "2001:db8:2000::/35"
+# }
+# ]
+# }
+# ]
+# }
+# ],
+# "changed": true,
+# "commands": [
+# "delete policy prefix-list6 AllowIPv6Prefix",
+# "delete policy prefix-list6 DenyIPv6Prefix"
+# ]
+
+# # After state:
+# # -------------
+# vyos@vyos:~$ show configuration commands | grep prefix-list
+# set policy prefix-list AnsibleIPv4PrefixList description 'PL configured by ansible'
+# set policy prefix-list AnsibleIPv4PrefixList rule 2 action 'permit'
+# set policy prefix-list AnsibleIPv4PrefixList rule 2 description 'Rule 2 given by ansible'
+# set policy prefix-list AnsibleIPv4PrefixList rule 2 le '32'
+# set policy prefix-list AnsibleIPv4PrefixList rule 2 prefix '92.168.10.0/26'
+# set policy prefix-list AnsibleIPv4PrefixList rule 3 action 'deny'
+# set policy prefix-list AnsibleIPv4PrefixList rule 3 description 'Rule 3'
+# set policy prefix-list AnsibleIPv4PrefixList rule 3 ge '26'
+# set policy prefix-list AnsibleIPv4PrefixList rule 3 prefix '72.168.2.0/24'
+# vyos@vyos:~$
+
+
+# # -------------------
+# # 4(iii). Using deleted (to delete single prefix list by name in different AFIs)
+# # -------------------
+
+# # Before state:
+# # -------------
+# vyos@vyos:~$ show configuration commands | grep prefix-list
+# set policy prefix-list AnsibleIPv4PrefixList description 'PL configured by ansible'
+# set policy prefix-list AnsibleIPv4PrefixList rule 2 action 'permit'
+# set policy prefix-list AnsibleIPv4PrefixList rule 2 description 'Rule 2 given by ansible'
+# set policy prefix-list AnsibleIPv4PrefixList rule 2 le '32'
+# set policy prefix-list AnsibleIPv4PrefixList rule 2 prefix '92.168.10.0/26'
+# set policy prefix-list AnsibleIPv4PrefixList rule 3 action 'deny'
+# set policy prefix-list AnsibleIPv4PrefixList rule 3 description 'Rule 3'
+# set policy prefix-list AnsibleIPv4PrefixList rule 3 ge '26'
+# set policy prefix-list AnsibleIPv4PrefixList rule 3 prefix '72.168.2.0/24'
+# set policy prefix-list6 AllowIPv6Prefix description 'Configured by ansible for allowing IPv6 networks'
+# set policy prefix-list6 AllowIPv6Prefix rule 5 action 'permit'
+# set policy prefix-list6 AllowIPv6Prefix rule 5 description 'Permit rule'
+# set policy prefix-list6 AllowIPv6Prefix rule 5 le '37'
+# set policy prefix-list6 AllowIPv6Prefix rule 5 prefix '2001:db8:8000::/35'
+# set policy prefix-list6 DenyIPv6Prefix description 'Configured by ansible for disallowing IPv6 networks'
+# set policy prefix-list6 DenyIPv6Prefix rule 8 action 'deny'
+# set policy prefix-list6 DenyIPv6Prefix rule 8 le '37'
+# set policy prefix-list6 DenyIPv6Prefix rule 8 prefix '2001:db8:2000::/35'
+# vyos@vyos:~$
+
+# # Task:
+# # -------------
+# - name: Delete a single prefix-list from different AFIs
+# vyos.vyos.vyos_prefix_lists:
+# config:
+# - afi: "ipv4"
+# prefix_lists:
+# - name: "AnsibleIPv4PrefixList"
+# - afi: "ipv6"
+# prefix_lists:
+# - name: "DenyIPv6Prefix"
+# state: deleted
+
+# # Task output:
+# # -------------
+# "after": [
+# {
+# "afi": "ipv6",
+# "prefix_lists": [
+# {
+# "description": "Configured by ansible for allowing IPv6 networks",
+# "name": "AllowIPv6Prefix",
+# "entries": [
+# {
+# "action": "permit",
+# "description": "Permit rule",
+# "sequence": 5,
+# "le": 37,
+# "prefix": "2001:db8:8000::/35"
+# }
+# ]
+# }
+# ]
+# }
+# ],
+# "before": [
+# {
+# "afi": "ipv4",
+# "prefix_lists": [
+# {
+# "description": "PL configured by ansible",
+# "name": "AnsibleIPv4PrefixList",
+# "entries": [
+# {
+# "action": "permit",
+# "description": "Rule 2 given by ansible",
+# "sequence": 2,
+# "le": 32,
+# "prefix": "92.168.10.0/26"
+# },
+# {
+# "action": "deny",
+# "description": "Rule 3",
+# "ge": 26,
+# "sequence": 3,
+# "prefix": "72.168.2.0/24"
+# }
+# ]
+# }
+# ]
+# },
+# {
+# "afi": "ipv6",
+# "prefix_lists": [
+# {
+# "description": "Configured by ansible for allowing IPv6 networks",
+# "name": "AllowIPv6Prefix",
+# "entries": [
+# {
+# "action": "permit",
+# "description": "Permit rule",
+# "sequence": 5,
+# "le": 37,
+# "prefix": "2001:db8:8000::/35"
+# }
+# ]
+# },
+# {
+# "description": "Configured by ansible for disallowing IPv6 networks",
+# "name": "DenyIPv6Prefix",
+# "entries": [
+# {
+# "action": "deny",
+# "sequence": 8,
+# "le": 37,
+# "prefix": "2001:db8:2000::/35"
+# }
+# ]
+# }
+# ]
+# }
+# ],
+# "changed": true,
+# "commands": [
+# "delete policy prefix-list AnsibleIPv4PrefixList",
+# "delete policy prefix-list6 DenyIPv6Prefix"
+# ]
+
+# # After state:
+# # -------------
+# vyos@vyos:~$ show configuration commands | grep prefix-list
+# set policy prefix-list6 AllowIPv6Prefix description 'Configured by ansible for allowing IPv6 networks'
+# set policy prefix-list6 AllowIPv6Prefix rule 5 action 'permit'
+# set policy prefix-list6 AllowIPv6Prefix rule 5 description 'Permit rule'
+# set policy prefix-list6 AllowIPv6Prefix rule 5 le '37'
+# set policy prefix-list6 AllowIPv6Prefix rule 5 prefix '2001:db8:8000::/35'
+# vyos@vyos:~$
+
+
+# # -------------------
+# # 5. Using gathered
+# # -------------------
+
+# # Task:
+# # -------------
+# - name: Gather prefix-lists configurations
+# vyos.vyos.vyos_prefix_lists:
+# config:
+# state: gathered
+
+# # Task output:
+# # -------------
+# "gathered": [
+# {
+# "afi": "ipv4",
+# "prefix_lists": [
+# {
+# "description": "PL configured by ansible",
+# "name": "AnsibleIPv4PrefixList",
+# "entries": [
+# {
+# "action": "permit",
+# "description": "Rule 2 given by ansible",
+# "sequence": 2,
+# "le": 32,
+# "prefix": "92.168.10.0/26"
+# },
+# {
+# "action": "deny",
+# "description": "Rule 3",
+# "ge": 26,
+# "sequence": 3,
+# "prefix": "72.168.2.0/24"
+# }
+# ]
+# }
+# ]
+# },
+# {
+# "afi": "ipv6",
+# "prefix_lists": [
+# {
+# "description": "Configured by ansible for allowing IPv6 networks",
+# "name": "AllowIPv6Prefix",
+# "entries": [
+# {
+# "action": "permit",
+# "description": "Permit rule",
+# "sequence": 5,
+# "le": 37,
+# "prefix": "2001:db8:8000::/35"
+# }
+# ]
+# },
+# {
+# "description": "Configured by ansible for disallowing IPv6 networks",
+# "name": "DenyIPv6Prefix",
+# "entries": [
+# {
+# "action": "deny",
+# "sequence": 8,
+# "le": 37,
+# "prefix": "2001:db8:2000::/35"
+# }
+# ]
+# }
+# ]
+# }
+# ]
+
+
+# # -------------------
+# # 6. Using rendered
+# # -------------------
+
+# # Task:
+# # -------------
+# - name: Render commands externally for the described prefix-list configurations
+# vyos.vyos.vyos_prefix_lists:
+# config:
+# - afi: "ipv4"
+# prefix_lists:
+# - name: "AnsibleIPv4PrefixList"
+# description: "PL configured by ansible"
+# entries:
+# - sequence: 2
+# description: "Rule 2 given by ansible"
+# action: "permit"
+# prefix: "92.168.10.0/26"
+# le: 32
+
+# - sequence: 3
+# description: "Rule 3"
+# action: "deny"
+# prefix: "72.168.2.0/24"
+# ge: 26
+
+# - afi: "ipv6"
+# prefix_lists:
+# - name: "AllowIPv6Prefix"
+# description: "Configured by ansible for allowing IPv6 networks"
+# entries:
+# - sequence: 5
+# description: "Permit rule"
+# action: "permit"
+# prefix: "2001:db8:8000::/35"
+# le: 37
+
+# - name: DenyIPv6Prefix
+# description: "Configured by ansible for disallowing IPv6 networks"
+# entries:
+# - sequence: 8
+# action: deny
+# prefix: "2001:db8:2000::/35"
+# le: 37
+# state: rendered
+
+# # Task output:
+# # -------------
+# "rendered": [
+# "set policy prefix-list AnsibleIPv4PrefixList",
+# "set policy prefix-list AnsibleIPv4PrefixList description 'PL configured by ansible'",
+# "set policy prefix-list AnsibleIPv4PrefixList rule 2",
+# "set policy prefix-list AnsibleIPv4PrefixList rule 2 action 'permit'",
+# "set policy prefix-list AnsibleIPv4PrefixList rule 2 description 'Rule 2 given by ansible'",
+# "set policy prefix-list AnsibleIPv4PrefixList rule 2 le '32'",
+# "set policy prefix-list AnsibleIPv4PrefixList rule 2 prefix '92.168.10.0/26'",
+# "set policy prefix-list AnsibleIPv4PrefixList rule 3",
+# "set policy prefix-list AnsibleIPv4PrefixList rule 3 action 'deny'",
+# "set policy prefix-list AnsibleIPv4PrefixList rule 3 description 'Rule 3'",
+# "set policy prefix-list AnsibleIPv4PrefixList rule 3 ge '26'",
+# "set policy prefix-list AnsibleIPv4PrefixList rule 3 prefix '72.168.2.0/24'",
+# "set policy prefix-list6 AllowIPv6Prefix",
+# "set policy prefix-list6 AllowIPv6Prefix description 'Configured by ansible for allowing IPv6 networks'",
+# "set policy prefix-list6 AllowIPv6Prefix rule 5",
+# "set policy prefix-list6 AllowIPv6Prefix rule 5 action 'permit'",
+# "set policy prefix-list6 AllowIPv6Prefix rule 5 description 'Permit rule'",
+# "set policy prefix-list6 AllowIPv6Prefix rule 5 le '37'",
+# "set policy prefix-list6 AllowIPv6Prefix rule 5 prefix '2001:db8:8000::/35'",
+# "set policy prefix-list6 DenyIPv6Prefix",
+# "set policy prefix-list6 DenyIPv6Prefix description 'Configured by ansible for disallowing IPv6 networks'",
+# "set policy prefix-list6 DenyIPv6Prefix rule 8",
+# "set policy prefix-list6 DenyIPv6Prefix rule 8 action 'deny'",
+# "set policy prefix-list6 DenyIPv6Prefix rule 8 le '37'",
+# "set policy prefix-list6 DenyIPv6Prefix rule 8 prefix '2001:db8:2000::/35'"
+# ]
+
+
+# # -------------------
+# # 7. Using parsed
+# # -------------------
+
+# # sample_config.cfg:
+# # -------------
+# set policy prefix-list AnsibleIPv4PrefixList description 'PL configured by ansible'
+# set policy prefix-list AnsibleIPv4PrefixList rule 2 action 'permit'
+# set policy prefix-list AnsibleIPv4PrefixList rule 2 description 'Rule 2 given by ansible'
+# set policy prefix-list AnsibleIPv4PrefixList rule 2 le '32'
+# set policy prefix-list AnsibleIPv4PrefixList rule 2 prefix '92.168.10.0/26'
+# set policy prefix-list AnsibleIPv4PrefixList rule 3 action 'deny'
+# set policy prefix-list AnsibleIPv4PrefixList rule 3 description 'Rule 3'
+# set policy prefix-list AnsibleIPv4PrefixList rule 3 ge '26'
+# set policy prefix-list AnsibleIPv4PrefixList rule 3 prefix '72.168.2.0/24'
+# set policy prefix-list6 AllowIPv6Prefix description 'Configured by ansible for allowing IPv6 networks'
+# set policy prefix-list6 AllowIPv6Prefix rule 5 action 'permit'
+# set policy prefix-list6 AllowIPv6Prefix rule 5 description 'Permit rule'
+# set policy prefix-list6 AllowIPv6Prefix rule 5 le '37'
+# set policy prefix-list6 AllowIPv6Prefix rule 5 prefix '2001:db8:8000::/35'
+# set policy prefix-list6 DenyIPv6Prefix description 'Configured by ansible for disallowing IPv6 networks'
+# set policy prefix-list6 DenyIPv6Prefix rule 8 action 'deny'
+# set policy prefix-list6 DenyIPv6Prefix rule 8 le '37'
+# set policy prefix-list6 DenyIPv6Prefix rule 8 prefix '2001:db8:2000::/35'
+
+# # Task:
+# # -------------
+# - name: Parse externally provided prefix-lists configuration
+# vyos.vyos.vyos_prefix_lists:
+# running_config: "{{ lookup('file', './sample_config.cfg') }}"
+# state: parsed
+
+# # Task output:
+# # -------------
+# "parsed": [
+# {
+# "afi": "ipv4",
+# "prefix_lists": [
+# {
+# "description": "PL configured by ansible",
+# "name": "AnsibleIPv4PrefixList",
+# "entries": [
+# {
+# "action": "permit",
+# "description": "Rule 2 given by ansible",
+# "sequence": 2,
+# "le": 32,
+# "prefix": "92.168.10.0/26"
+# },
+# {
+# "action": "deny",
+# "description": "Rule 3",
+# "ge": 26,
+# "sequence": 3,
+# "prefix": "72.168.2.0/24"
+# }
+# ]
+# }
+# ]
+# },
+# {
+# "afi": "ipv6",
+# "prefix_lists": [
+# {
+# "description": "Configured by ansible for allowing IPv6 networks",
+# "name": "AllowIPv6Prefix",
+# "entries": [
+# {
+# "action": "permit",
+# "description": "Permit rule",
+# "sequence": 5,
+# "le": 37,
+# "prefix": "2001:db8:8000::/35"
+# }
+# ]
+# },
+# {
+# "description": "Configured by ansible for disallowing IPv6 networks",
+# "name": "DenyIPv6Prefix",
+# "entries": [
+# {
+# "action": "deny",
+# "sequence": 8,
+# "le": 37,
+# "prefix": "2001:db8:2000::/35"
+# }
+# ]
+# }
+# ]
+# }
+# ]
+
+"""
+
+RETURN = """
+
+before:
+ description: The configuration prior to the module invocation.
+ returned: when state is I(merged), I(replaced), I(overridden) or I(deleted)
+ type: list
+ sample: >
+ This output will always be in the same format as the
+ module argspec.
+after:
+ description: The resulting configuration after the module invocation.
+ returned: when changed
+ type: list
+ sample: >
+ This output will always be in the same format as the
+ module argspec.
+commands:
+ description: The set of commands pushed to the remote device for the required configurations to take place.
+ returned: when state is I(merged), I(replaced), I(overridden) or I(deleted)
+ type: list
+ sample:
+ - set policy prefix-list AnsibleIPv4PrefixList description 'PL configured by ansible'
+ - set policy prefix-list AnsibleIPv4PrefixList rule 2 action 'permit'
+ - set policy prefix-list6 AllowIPv6Prefix description 'Configured by ansible for allowing IPv6 networks'
+rendered:
+ description: The provided configuration in the task rendered in device-native format (offline).
+ returned: when state is I(rendered)
+ type: list
+ sample:
+ - set policy prefix-list AnsibleIPv4PrefixList description 'PL configured by ansible'
+ - set policy prefix-list AnsibleIPv4PrefixList rule 2 action 'permit'
+ - set policy prefix-list6 AllowIPv6Prefix description 'Configured by ansible for allowing IPv6 networks'
+gathered:
+ description: Facts about the network resource gathered from the remote device as structured data.
+ returned: when state is I(gathered)
+ type: list
+ sample: >
+ This output will always be in the same format as the
+ module argspec.
+parsed:
+ description: The device native config provided in I(running_config) option parsed into structured data as per module argspec.
+ returned: when state is I(parsed)
+ type: list
+ sample: >
+ This output will always be in the same format as the
+ module argspec.
+
+"""
+
+
+from ansible.module_utils.basic import AnsibleModule
+from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.prefix_lists.prefix_lists import (
+ Prefix_listsArgs,
+)
+from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.config.prefix_lists.prefix_lists import (
+ Prefix_lists,
+)
+
+
+def main():
+ """
+ Main entry point for module execution
+
+ :returns: the result form module invocation
+ """
+ module = AnsibleModule(
+ argument_spec=Prefix_listsArgs.argument_spec,
+ mutually_exclusive=[["config", "running_config"]],
+ required_if=[
+ ["state", "merged", ["config"]],
+ ["state", "replaced", ["config"]],
+ ["state", "overridden", ["config"]],
+ ["state", "rendered", ["config"]],
+ ["state", "parsed", ["running_config"]],
+ ],
+ supports_check_mode=True,
+ )
+
+ result = Prefix_lists(module).execute_module()
+ module.exit_json(**result)
+
+
+if __name__ == "__main__":
+ main()