summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/action/vyos.py6
-rw-r--r--plugins/cliconf/vyos.py55
-rw-r--r--plugins/module_utils/network/vyos/argspec/firewall_rules/firewall_rules.py16
-rw-r--r--plugins/module_utils/network/vyos/argspec/ospfv2/ospfv2.py4
-rw-r--r--plugins/module_utils/network/vyos/argspec/route_maps/route_maps.py4
-rw-r--r--plugins/module_utils/network/vyos/config/bgp_address_family/bgp_address_family.py37
-rw-r--r--plugins/module_utils/network/vyos/config/bgp_global/bgp_global.py43
-rw-r--r--plugins/module_utils/network/vyos/config/firewall_global/firewall_global.py182
-rw-r--r--plugins/module_utils/network/vyos/config/firewall_interfaces/firewall_interfaces.py87
-rw-r--r--plugins/module_utils/network/vyos/config/firewall_rules/firewall_rules.py351
-rw-r--r--plugins/module_utils/network/vyos/config/hostname/hostname.py5
-rw-r--r--plugins/module_utils/network/vyos/config/interfaces/interfaces.py59
-rw-r--r--plugins/module_utils/network/vyos/config/l3_interfaces/l3_interfaces.py67
-rw-r--r--plugins/module_utils/network/vyos/config/lag_interfaces/lag_interfaces.py76
-rw-r--r--plugins/module_utils/network/vyos/config/lldp_global/lldp_global.py57
-rw-r--r--plugins/module_utils/network/vyos/config/lldp_interfaces/lldp_interfaces.py98
-rw-r--r--plugins/module_utils/network/vyos/config/logging_global/logging_global.py37
-rw-r--r--plugins/module_utils/network/vyos/config/ntp_global/ntp_global.py25
-rw-r--r--plugins/module_utils/network/vyos/config/ospf_interfaces/ospf_interfaces.py9
-rw-r--r--plugins/module_utils/network/vyos/config/ospfv2/ospfv2.py239
-rw-r--r--plugins/module_utils/network/vyos/config/ospfv3/ospfv3.py96
-rw-r--r--plugins/module_utils/network/vyos/config/prefix_lists/prefix_lists.py25
-rw-r--r--plugins/module_utils/network/vyos/config/route_maps/route_maps.py20
-rw-r--r--plugins/module_utils/network/vyos/config/snmp_server/snmp_server.py36
-rw-r--r--plugins/module_utils/network/vyos/config/static_routes/static_routes.py92
-rw-r--r--plugins/module_utils/network/vyos/facts/bgp_address_family/bgp_address_family.py38
-rw-r--r--plugins/module_utils/network/vyos/facts/bgp_global/bgp_global.py36
-rw-r--r--plugins/module_utils/network/vyos/facts/facts.py84
-rw-r--r--plugins/module_utils/network/vyos/facts/firewall_global/firewall_global.py12
-rw-r--r--plugins/module_utils/network/vyos/facts/firewall_interfaces/firewall_interfaces.py24
-rw-r--r--plugins/module_utils/network/vyos/facts/firewall_rules/firewall_rules.py16
-rw-r--r--plugins/module_utils/network/vyos/facts/hostname/hostname.py21
-rw-r--r--plugins/module_utils/network/vyos/facts/interfaces/interfaces.py16
-rw-r--r--plugins/module_utils/network/vyos/facts/l3_interfaces/l3_interfaces.py16
-rw-r--r--plugins/module_utils/network/vyos/facts/lag_interfaces/lag_interfaces.py19
-rw-r--r--plugins/module_utils/network/vyos/facts/legacy/base.py3
-rw-r--r--plugins/module_utils/network/vyos/facts/lldp_global/lldp_global.py15
-rw-r--r--plugins/module_utils/network/vyos/facts/lldp_interfaces/lldp_interfaces.py15
-rw-r--r--plugins/module_utils/network/vyos/facts/logging_global/logging_global.py29
-rw-r--r--plugins/module_utils/network/vyos/facts/ntp_global/ntp_global.py22
-rw-r--r--plugins/module_utils/network/vyos/facts/ospf_interfaces/ospf_interfaces.py17
-rw-r--r--plugins/module_utils/network/vyos/facts/ospfv2/ospfv2.py43
-rw-r--r--plugins/module_utils/network/vyos/facts/ospfv3/ospfv3.py16
-rw-r--r--plugins/module_utils/network/vyos/facts/prefix_lists/prefix_lists.py17
-rw-r--r--plugins/module_utils/network/vyos/facts/route_maps/route_maps.py13
-rw-r--r--plugins/module_utils/network/vyos/facts/snmp_server/snmp_server.py20
-rw-r--r--plugins/module_utils/network/vyos/facts/static_routes/static_routes.py29
-rw-r--r--plugins/module_utils/network/vyos/rm_templates/bgp_address_family.py86
-rw-r--r--plugins/module_utils/network/vyos/rm_templates/bgp_global.py60
-rw-r--r--plugins/module_utils/network/vyos/rm_templates/hostname.py1
-rw-r--r--plugins/module_utils/network/vyos/rm_templates/logging_global.py15
-rw-r--r--plugins/module_utils/network/vyos/rm_templates/ntp_global.py5
-rw-r--r--plugins/module_utils/network/vyos/rm_templates/ospf_interfaces.py28
-rw-r--r--plugins/module_utils/network/vyos/rm_templates/prefix_lists.py1
-rw-r--r--plugins/module_utils/network/vyos/rm_templates/route_maps.py5
-rw-r--r--plugins/module_utils/network/vyos/rm_templates/snmp_server.py17
-rw-r--r--plugins/module_utils/network/vyos/utils/utils.py34
-rw-r--r--plugins/module_utils/network/vyos/vyos.py8
-rw-r--r--plugins/modules/vyos_banner.py17
-rw-r--r--plugins/modules/vyos_bgp_address_family.py1
-rw-r--r--plugins/modules/vyos_bgp_global.py1
-rw-r--r--plugins/modules/vyos_command.py11
-rw-r--r--plugins/modules/vyos_config.py19
-rw-r--r--plugins/modules/vyos_facts.py11
-rw-r--r--plugins/modules/vyos_firewall_global.py1
-rw-r--r--plugins/modules/vyos_firewall_interfaces.py1
-rw-r--r--plugins/modules/vyos_firewall_rules.py1
-rw-r--r--plugins/modules/vyos_hostname.py1
-rw-r--r--plugins/modules/vyos_interfaces.py1
-rw-r--r--plugins/modules/vyos_l3_interfaces.py1
-rw-r--r--plugins/modules/vyos_lag_interfaces.py1
-rw-r--r--plugins/modules/vyos_lldp_global.py1
-rw-r--r--plugins/modules/vyos_lldp_interfaces.py1
-rw-r--r--plugins/modules/vyos_logging.py18
-rw-r--r--plugins/modules/vyos_logging_global.py1
-rw-r--r--plugins/modules/vyos_ntp_global.py1
-rw-r--r--plugins/modules/vyos_ospf_interfaces.py1
-rw-r--r--plugins/modules/vyos_ospfv2.py1
-rw-r--r--plugins/modules/vyos_ospfv3.py1
-rw-r--r--plugins/modules/vyos_ping.py16
-rw-r--r--plugins/modules/vyos_prefix_lists.py1
-rw-r--r--plugins/modules/vyos_route_maps.py1
-rw-r--r--plugins/modules/vyos_snmp_server.py1
-rw-r--r--plugins/modules/vyos_static_routes.py1
-rw-r--r--plugins/modules/vyos_system.py17
-rw-r--r--plugins/modules/vyos_user.py15
-rw-r--r--plugins/modules/vyos_vlan.py36
-rw-r--r--plugins/terminal/vyos.py8
88 files changed, 753 insertions, 1942 deletions
diff --git a/plugins/action/vyos.py b/plugins/action/vyos.py
index f6f9aad..df8e712 100644
--- a/plugins/action/vyos.py
+++ b/plugins/action/vyos.py
@@ -20,10 +20,10 @@ from __future__ import absolute_import, division, print_function
__metaclass__ = type
+from ansible.utils.display import Display
from ansible_collections.ansible.netcommon.plugins.action.network import (
ActionModule as ActionNetworkModule,
)
-from ansible.utils.display import Display
display = Display()
@@ -33,9 +33,7 @@ class ActionModule(ActionNetworkModule):
del tmp # tmp no longer has any effect
module_name = self._task.action.split(".")[-1]
- self._config_module = (
- True if module_name in ["vyos_config", "config"] else False
- )
+ self._config_module = True if module_name in ["vyos_config", "config"] else False
persistent_connection = self._play_context.connection.split(".")[-1]
warnings = []
diff --git a/plugins/cliconf/vyos.py b/plugins/cliconf/vyos.py
index 885cf1f..4916d52 100644
--- a/plugins/cliconf/vyos.py
+++ b/plugins/cliconf/vyos.py
@@ -42,8 +42,8 @@ options:
- name: ansible_vyos_config_commands
"""
-import re
import json
+import re
from ansible.errors import AnsibleConnectionFailure
from ansible.module_utils._text import to_text
@@ -51,12 +51,8 @@ from ansible.module_utils.common._collections_compat import Mapping
from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.config import (
NetworkConfig,
)
-from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import (
- to_list,
-)
-from ansible_collections.ansible.netcommon.plugins.plugin_utils.cliconf_base import (
- CliconfBase,
-)
+from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import to_list
+from ansible_collections.ansible.netcommon.plugins.plugin_utils.cliconf_base import CliconfBase
class Cliconf(CliconfBase):
@@ -119,14 +115,10 @@ class Cliconf(CliconfBase):
out = self.send_command(command)
return out
- def edit_config(
- self, candidate=None, commit=True, replace=None, comment=None
- ):
+ def edit_config(self, candidate=None, commit=True, replace=None, comment=None):
resp = {}
operations = self.get_device_operations()
- self.check_edit_config_capability(
- operations, candidate, commit, replace, comment
- )
+ self.check_edit_config_capability(operations, candidate, commit, replace, comment)
results = []
requests = []
@@ -156,9 +148,7 @@ class Cliconf(CliconfBase):
else:
self.send_command("exit")
if (
- to_text(
- self._connection.get_prompt(), errors="surrogate_or_strict"
- )
+ to_text(self._connection.get_prompt(), errors="surrogate_or_strict")
.strip()
.endswith("#")
):
@@ -183,9 +173,7 @@ class Cliconf(CliconfBase):
if not command:
raise ValueError("must provide value of command to execute")
if output:
- raise ValueError(
- "'output' value %s is not supported for get" % output
- )
+ raise ValueError("'output' value %s is not supported for get" % output)
return self.send_command(
command=command,
@@ -220,9 +208,7 @@ class Cliconf(CliconfBase):
option_values = self.get_option_values()
if candidate is None and device_operations["supports_generate_diff"]:
- raise ValueError(
- "candidate configuration is required to generate diff"
- )
+ raise ValueError("candidate configuration is required to generate diff")
if diff_match not in option_values["diff_match"]:
raise ValueError(
@@ -239,9 +225,7 @@ class Cliconf(CliconfBase):
if path:
raise ValueError("'path' in diff is not supported")
- set_format = candidate.startswith("set") or candidate.startswith(
- "delete"
- )
+ set_format = candidate.startswith("set") or candidate.startswith("delete")
candidate_obj = NetworkConfig(indent=4, contents=candidate)
if not set_format:
config = [c.line for c in candidate_obj.items]
@@ -254,9 +238,7 @@ class Cliconf(CliconfBase):
break
commands.append(item)
- candidate_commands = [
- "set %s" % cmd.replace(" {", "") for cmd in commands
- ]
+ candidate_commands = ["set %s" % cmd.replace(" {", "") for cmd in commands]
else:
candidate_commands = str(candidate).strip().split("\n")
@@ -265,9 +247,7 @@ class Cliconf(CliconfBase):
diff["config_diff"] = list(candidate_commands)
return diff
- running_commands = [
- str(c).replace("'", "") for c in running.splitlines()
- ]
+ running_commands = [str(c).replace("'", "") for c in running.splitlines()]
updates = list()
visited = set()
@@ -276,9 +256,7 @@ class Cliconf(CliconfBase):
item = str(line).replace("'", "")
if not item.startswith("set") and not item.startswith("delete"):
- raise ValueError(
- "line must start with either `set` or `delete`"
- )
+ raise ValueError("line must start with either `set` or `delete`")
elif item.startswith("set") and item not in running_commands:
updates.append(line)
@@ -307,10 +285,7 @@ class Cliconf(CliconfBase):
output = cmd.pop("output", None)
if output:
- raise ValueError(
- "'output' value %s is not supported for run_commands"
- % output
- )
+ raise ValueError("'output' value %s is not supported for run_commands" % output)
try:
out = self.send_command(**cmd)
@@ -358,6 +333,4 @@ class Cliconf(CliconfBase):
:return: None
"""
if self._connection.connected:
- self._update_cli_prompt_context(
- config_context="#", exit_command="exit discard"
- )
+ self._update_cli_prompt_context(config_context="#", exit_command="exit discard")
diff --git a/plugins/module_utils/network/vyos/argspec/firewall_rules/firewall_rules.py b/plugins/module_utils/network/vyos/argspec/firewall_rules/firewall_rules.py
index 61d9a55..0e80031 100644
--- a/plugins/module_utils/network/vyos/argspec/firewall_rules/firewall_rules.py
+++ b/plugins/module_utils/network/vyos/argspec/firewall_rules/firewall_rules.py
@@ -73,12 +73,8 @@ class Firewall_rulesArgs(object): # pylint: disable=R0903
"address": {"type": "str"},
"group": {
"options": {
- "address_group": {
- "type": "str"
- },
- "network_group": {
- "type": "str"
- },
+ "address_group": {"type": "str"},
+ "network_group": {"type": "str"},
"port_group": {"type": "str"},
},
"type": "dict",
@@ -203,12 +199,8 @@ class Firewall_rulesArgs(object): # pylint: disable=R0903
"address": {"type": "str"},
"group": {
"options": {
- "address_group": {
- "type": "str"
- },
- "network_group": {
- "type": "str"
- },
+ "address_group": {"type": "str"},
+ "network_group": {"type": "str"},
"port_group": {"type": "str"},
},
"type": "dict",
diff --git a/plugins/module_utils/network/vyos/argspec/ospfv2/ospfv2.py b/plugins/module_utils/network/vyos/argspec/ospfv2/ospfv2.py
index 0061e79..6c83372 100644
--- a/plugins/module_utils/network/vyos/argspec/ospfv2/ospfv2.py
+++ b/plugins/module_utils/network/vyos/argspec/ospfv2/ospfv2.py
@@ -145,9 +145,7 @@ class Ospfv2Args(object): # pylint: disable=R0903
},
"network": {
"elements": "dict",
- "options": {
- "address": {"required": True, "type": "str"}
- },
+ "options": {"address": {"required": True, "type": "str"}},
"type": "list",
},
"range": {
diff --git a/plugins/module_utils/network/vyos/argspec/route_maps/route_maps.py b/plugins/module_utils/network/vyos/argspec/route_maps/route_maps.py
index 790f5e6..6baa434 100644
--- a/plugins/module_utils/network/vyos/argspec/route_maps/route_maps.py
+++ b/plugins/module_utils/network/vyos/argspec/route_maps/route_maps.py
@@ -183,9 +183,7 @@ class Route_mapsArgs(object): # pylint: disable=R0903
"next_hop": {"type": "str"},
},
},
- "large_community_large_community_list": {
- "type": "str"
- },
+ "large_community_large_community_list": {"type": "str"},
"metric": {"type": "int"},
"origin": {
"type": "str",
diff --git a/plugins/module_utils/network/vyos/config/bgp_address_family/bgp_address_family.py b/plugins/module_utils/network/vyos/config/bgp_address_family/bgp_address_family.py
index a62e6a5..53defde 100644
--- a/plugins/module_utils/network/vyos/config/bgp_address_family/bgp_address_family.py
+++ b/plugins/module_utils/network/vyos/config/bgp_address_family/bgp_address_family.py
@@ -20,15 +20,14 @@ created.
import re
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.ansible.netcommon.plugins.module_utils.network.common.utils import (
+ dict_merge,
)
+
+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.bgp_address_family import (
Bgp_address_familyTemplate,
)
@@ -67,18 +66,13 @@ class Bgp_address_family(ResourceModule):
wantd = {}
haved = {}
- if (
- self.want.get("as_number") == self.have.get("as_number")
- or not self.have
- ):
+ if self.want.get("as_number") == self.have.get("as_number") or not self.have:
if self.want:
wantd = {self.want["as_number"]: self.want}
if self.have:
haved = {self.have["as_number"]: self.have}
else:
- self._module.fail_json(
- msg="Only one bgp instance is allowed per device"
- )
+ self._module.fail_json(msg="Only one bgp instance is allowed per device")
# turn all lists of dicts into dicts prior to merge
for entry in wantd, haved:
@@ -133,9 +127,7 @@ class Bgp_address_family(ResourceModule):
for name, entry in iteritems(haf):
if name not in waf.keys() and self.state == "replaced":
continue
- self._compare_lists(
- {}, entry, as_number=have["as_number"], afi=name
- )
+ self._compare_lists({}, entry, as_number=have["as_number"], afi=name)
def _delete_af(self, want, have):
for as_num, entry in iteritems(want):
@@ -162,9 +154,7 @@ class Bgp_address_family(ResourceModule):
self._tmplt.render(
{
"as_number": as_num,
- "neighbors": {
- "neighbor_address": neigh
- },
+ "neighbors": {"neighbor_address": neigh},
},
"neighbors",
True,
@@ -174,8 +164,7 @@ class Bgp_address_family(ResourceModule):
for k in neigh_entry["address_family"].keys():
if (
hnentry.get("address_family")
- and k
- in hnentry["address_family"].keys()
+ and k in hnentry["address_family"].keys()
):
self.commands.append(
self._tmplt.render(
@@ -183,9 +172,7 @@ class Bgp_address_family(ResourceModule):
"as_number": as_num,
"neighbors": {
"neighbor_address": neigh,
- "address_family": {
- "afi": k
- },
+ "address_family": {"afi": k},
},
},
"neighbors.address_family",
@@ -240,9 +227,7 @@ class Bgp_address_family(ResourceModule):
"neighbor_address": name,
"address_family": {
"afi": afi,
- k: hneigh[name]["address_family"][
- afi
- ].pop(k, {}),
+ k: hneigh[name]["address_family"][afi].pop(k, {}),
},
},
}
diff --git a/plugins/module_utils/network/vyos/config/bgp_global/bgp_global.py b/plugins/module_utils/network/vyos/config/bgp_global/bgp_global.py
index f8de74e..96c640f 100644
--- a/plugins/module_utils/network/vyos/config/bgp_global/bgp_global.py
+++ b/plugins/module_utils/network/vyos/config/bgp_global/bgp_global.py
@@ -17,16 +17,16 @@ necessary to bring the current configuration to its desired end-state is
created.
"""
import re
+
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.ansible.netcommon.plugins.module_utils.network.common.utils import (
+ dict_merge,
)
+
+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.bgp_global import (
Bgp_globalTemplate,
)
@@ -65,18 +65,13 @@ class Bgp_global(ResourceModule):
wantd = {}
haved = {}
- if (
- self.want.get("as_number") == self.have.get("as_number")
- or not self.have
- ):
+ if self.want.get("as_number") == self.have.get("as_number") or not self.have:
if self.want:
wantd = {self.want["as_number"]: self.want}
if self.have:
haved = {self.have["as_number"]: self.have}
else:
- self._module.fail_json(
- msg="Only one bgp instance is allowed per device"
- )
+ self._module.fail_json(msg="Only one bgp instance is allowed per device")
# turn all lists of dicts into dicts prior to merge
for entry in wantd, haved:
@@ -93,9 +88,7 @@ class Bgp_global(ResourceModule):
if k in wantd or not wantd:
h_del.update({k: v})
for num, entry in iteritems(h_del):
- self.commands.append(
- self._tmplt.render({"as_number": num}, "router", True)
- )
+ self.commands.append(self._tmplt.render({"as_number": num}, "router", True))
wantd = {}
if self.state == "deleted":
@@ -214,10 +207,7 @@ class Bgp_global(ResourceModule):
self._module.fail_json(msg=msg)
else:
self.commands.append(
- "delete protocols bgp "
- + str(have["as_number"])
- + " neighbor "
- + name
+ "delete protocols bgp " + str(have["as_number"]) + " neighbor " + name
)
continue
for k, v in entry.items():
@@ -297,18 +287,12 @@ class Bgp_global(ResourceModule):
},
)
if not wbgp and hbgp:
- self.commands.append(
- "delete protocols bgp "
- + str(have["as_number"])
- + " parameters"
- )
+ self.commands.append("delete protocols bgp " + str(have["as_number"]) + " parameters")
hbgp = {}
for name, entry in iteritems(hbgp):
if name == "confederation":
self.commands.append(
- "delete protocols bgp "
- + str(have["as_number"])
- + " parameters confederation"
+ "delete protocols bgp " + str(have["as_number"]) + " parameters confederation"
)
elif name == "distance":
distance_parsers = [
@@ -356,10 +340,7 @@ class Bgp_global(ResourceModule):
if not wdict and hdict:
attrib = re.sub("_", "-", attrib)
self.commands.append(
- "delete protocols bgp "
- + str(have["as_number"])
- + " "
- + attrib
+ "delete protocols bgp " + str(have["as_number"]) + " " + attrib
)
hdict = {}
for key, entry in iteritems(hdict):
diff --git a/plugins/module_utils/network/vyos/config/firewall_global/firewall_global.py b/plugins/module_utils/network/vyos/config/firewall_global/firewall_global.py
index be8b172..079cba6 100644
--- a/plugins/module_utils/network/vyos/config/firewall_global/firewall_global.py
+++ b/plugins/module_utils/network/vyos/config/firewall_global/firewall_global.py
@@ -15,17 +15,17 @@ from __future__ import absolute_import, division, print_function
__metaclass__ = type
from copy import deepcopy
+
+from ansible.module_utils.six import iteritems
from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base import (
ConfigBase,
)
from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import (
- to_list,
remove_empties,
+ to_list,
)
-from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.facts import (
- Facts,
-)
-from ansible.module_utils.six import iteritems
+
+from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.facts import Facts
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.utils.utils import (
list_diff_want_only,
)
@@ -52,9 +52,7 @@ class Firewall_global(ConfigBase):
facts, _warnings = Facts(self._module).get_facts(
self.gather_subset, self.gather_network_resources, data=data
)
- firewall_global_facts = facts["ansible_network_resources"].get(
- "firewall_global"
- )
+ firewall_global_facts = facts["ansible_network_resources"].get("firewall_global")
if not firewall_global_facts:
return []
return firewall_global_facts
@@ -95,9 +93,7 @@ class Firewall_global(ConfigBase):
self._module.fail_json(
msg="value of running_config parameter must not be empty for state parsed"
)
- result["parsed"] = self.get_firewall_global_facts(
- data=running_config
- )
+ result["parsed"] = self.get_firewall_global_facts(data=running_config)
else:
changed_firewall_global_facts = []
@@ -136,9 +132,7 @@ class Firewall_global(ConfigBase):
commands = []
if self.state in ("merged", "replaced", "rendered") and not w:
self._module.fail_json(
- msg="value of config parameter must not be empty for state {0}".format(
- self.state
- )
+ msg="value of config parameter must not be empty for state {0}".format(self.state)
)
if self.state == "deleted":
commands.extend(self._state_deleted(want=None, have=h))
@@ -191,13 +185,7 @@ class Firewall_global(ConfigBase):
for key, val in iteritems(want):
if val and key in b_set and not have:
commands.append(self._form_attr_cmd(attr=key, opr=False))
- elif (
- val
- and key in b_set
- and have
- and key in have
- and have[key] != val
- ):
+ elif val and key in b_set and have and key in have and have[key] != val:
commands.append(self._form_attr_cmd(attr=key, opr=False))
else:
commands.extend(self._render_attr_config(want, have, key))
@@ -252,22 +240,14 @@ class Firewall_global(ConfigBase):
)
if w_fg:
for key, val in iteritems(w_fg):
- if (
- opr
- and key in l_set
- and not (h and self._is_w_same(w_fg, h, key))
- ):
+ if opr and key in l_set and not (h and self._is_w_same(w_fg, h, key)):
commands.append(
- self._form_attr_cmd(
- attr=key, val=self._bool_to_str(val), opr=opr
- )
+ self._form_attr_cmd(attr=key, val=self._bool_to_str(val), opr=opr)
)
elif not opr:
if key and self._is_del(l_set, h):
commands.append(
- self._form_attr_cmd(
- attr=key, key=self._bool_to_str(val), opr=opr
- )
+ self._form_attr_cmd(attr=key, key=self._bool_to_str(val), opr=opr)
)
continue
if (
@@ -276,14 +256,10 @@ class Firewall_global(ConfigBase):
and not self._is_del(l_set, h)
):
commands.append(
- self._form_attr_cmd(
- attr=key, val=self._bool_to_str(val), opr=opr
- )
+ self._form_attr_cmd(attr=key, val=self._bool_to_str(val), opr=opr)
)
else:
- commands.extend(
- self._render_attr_config(w_fg, h, key, opr)
- )
+ commands.extend(self._render_attr_config(w_fg, h, key, opr))
return commands
def _render_ping(self, attr, w, h, opr):
@@ -314,9 +290,7 @@ class Firewall_global(ConfigBase):
and not (h_ping and self._is_w_same(w[attr], h_ping, item))
):
commands.append(
- self._form_attr_cmd(
- attr=item, val=self._bool_to_str(value), opr=opr
- )
+ self._form_attr_cmd(attr=item, val=self._bool_to_str(value), opr=opr)
)
elif (
not opr
@@ -343,19 +317,9 @@ class Firewall_global(ConfigBase):
if h:
h_grp = h.get("group") or {}
if w:
- commands.extend(
- self._render_grp_mem("port_group", w["group"], h_grp, opr)
- )
- commands.extend(
- self._render_grp_mem(
- "address_group", w["group"], h_grp, opr
- )
- )
- commands.extend(
- self._render_grp_mem(
- "network_group", w["group"], h_grp, opr
- )
- )
+ commands.extend(self._render_grp_mem("port_group", w["group"], h_grp, opr))
+ commands.extend(self._render_grp_mem("address_group", w["group"], h_grp, opr))
+ commands.extend(self._render_grp_mem("network_group", w["group"], h_grp, opr))
return commands
def _render_grp_mem(self, attr, w, h, opr):
@@ -380,20 +344,12 @@ class Firewall_global(ConfigBase):
for want in w_grp:
h = self.search_attrib_in_have(h_grp, want, "name")
if "afi" in want and want["afi"] == "ipv6":
- cmd = self._compute_command(
- key="group", attr="ipv6-" + attr, opr=opr
- )
+ cmd = self._compute_command(key="group", attr="ipv6-" + attr, opr=opr)
else:
- cmd = self._compute_command(
- key="group", attr=attr, opr=opr
- )
+ cmd = self._compute_command(key="group", attr=attr, opr=opr)
for key, val in iteritems(want):
if val:
- if (
- opr
- and key in l_set
- and not (h and self._is_w_same(want, h, key))
- ):
+ if opr and key in l_set and not (h and self._is_w_same(want, h, key)):
if key == "name":
commands.append(cmd + " " + str(val))
else:
@@ -408,22 +364,16 @@ class Firewall_global(ConfigBase):
+ "'"
)
elif not opr and key in l_set:
- if key == "name" and self._is_grp_del(
- h, want, key
- ):
+ if key == "name" and self._is_grp_del(h, want, key):
commands.append(cmd + " " + want["name"])
continue
- if not (
- h and self._in_target(h, key)
- ) and not self._is_grp_del(h, want, key):
- commands.append(
- cmd + " " + want["name"] + " " + key
- )
+ if not (h and self._in_target(h, key)) and not self._is_grp_del(
+ h, want, key
+ ):
+ commands.append(cmd + " " + want["name"] + " " + key)
elif key == "members":
commands.extend(
- self._render_ports_addrs(
- key, want, h, opr, cmd, want["name"], attr
- )
+ self._render_ports_addrs(key, want, h, opr, cmd, want["name"], attr)
)
return commands
@@ -505,11 +455,7 @@ class Firewall_global(ConfigBase):
h = self.search_attrib_in_have(have, w, "connection_type")
for key, val in iteritems(w):
if val and key != "connection_type":
- if (
- opr
- and key in l_set
- and not (h and self._is_w_same(w, h, key))
- ):
+ if opr and key in l_set and not (h and self._is_w_same(w, h, key)):
commands.append(
self._form_attr_cmd(
key=attr + " " + w["connection_type"],
@@ -519,24 +465,20 @@ class Firewall_global(ConfigBase):
)
)
elif not opr and key in l_set:
- if not (
- h and self._in_target(h, key)
- ) and not self._is_del(l_set, h):
+ if not (h and self._in_target(h, key)) and not self._is_del(
+ l_set, h
+ ):
if key == "action":
commands.append(
self._form_attr_cmd(
- attr=attr
- + " "
- + w["connection_type"],
+ attr=attr + " " + w["connection_type"],
opr=opr,
)
)
else:
commands.append(
self._form_attr_cmd(
- attr=attr
- + " "
- + w["connection_type"],
+ attr=attr + " " + w["connection_type"],
val=self._bool_to_str(val),
opr=opr,
)
@@ -566,11 +508,7 @@ class Firewall_global(ConfigBase):
h = self.search_attrib_in_have(have, w, "afi")
for key, val in iteritems(w):
if val and key != "afi":
- if (
- opr
- and key in l_set
- and not (h and self._is_w_same(w, h, key))
- ):
+ if opr and key in l_set and not (h and self._is_w_same(w, h, key)):
commands.append(
self._form_attr_cmd(
attr=key,
@@ -588,9 +526,7 @@ class Firewall_global(ConfigBase):
)
)
continue
- if not (
- h and self._in_target(h, key)
- ) and not self._is_del(l_set, h):
+ if not (h and self._in_target(h, key)) and not self._is_del(l_set, h):
commands.append(
self._form_attr_cmd(
attr=key,
@@ -599,9 +535,7 @@ class Firewall_global(ConfigBase):
)
)
elif key == "icmp_redirects":
- commands.extend(
- self._render_icmp_redirects(key, w, h, opr)
- )
+ commands.extend(self._render_icmp_redirects(key, w, h, opr))
return commands
def _render_icmp_redirects(self, attr, w, h, opr):
@@ -621,15 +555,9 @@ class Firewall_global(ConfigBase):
if h and attr in h.keys():
h_red = h.get(attr) or {}
for item, value in iteritems(w[attr]):
- if (
- opr
- and item in l_set
- and not (h_red and self._is_w_same(w[attr], h_red, item))
- ):
+ if opr and item in l_set and not (h_red and self._is_w_same(w[attr], h_red, item)):
commands.append(
- self._form_attr_cmd(
- attr=item, val=self._bool_to_str(value), opr=opr
- )
+ self._form_attr_cmd(attr=item, val=self._bool_to_str(value), opr=opr)
)
elif (
not opr
@@ -662,14 +590,10 @@ class Firewall_global(ConfigBase):
:param opr: True/False.
:return: generated command.
"""
- command = self._compute_command(
- key=key, attr=self._map_attrib(attr), val=val, opr=opr
- )
+ command = self._compute_command(key=key, attr=self._map_attrib(attr), val=val, opr=opr)
return command
- def _compute_command(
- self, key=None, attr=None, val=None, remove=False, opr=True
- ):
+ def _compute_command(self, key=None, attr=None, val=None, remove=False, opr=True):
"""
This function construct the add/delete command based on passed attributes.
:param key: parent key.
@@ -697,13 +621,7 @@ class Firewall_global(ConfigBase):
:param val: bool value.
:return: enable/disable.
"""
- return (
- "enable"
- if str(val) == "True"
- else "disable"
- if str(val) == "False"
- else val
- )
+ return "enable" if str(val) == "True" else "disable" if str(val) == "False" else val
def _grp_type(self, val):
"""
@@ -712,11 +630,7 @@ class Firewall_global(ConfigBase):
:return: member type.
"""
return (
- "address"
- if val == "address_group"
- else "network"
- if val == "network_group"
- else "port"
+ "address" if val == "address_group" else "network" if val == "network_group" else "port"
)
def _is_w_same(self, w, h, key):
@@ -748,11 +662,7 @@ class Firewall_global(ConfigBase):
:param key: group name.
:return: True/False.
"""
- return (
- True
- if h and key in h and (not w or key not in w or not w[key])
- else False
- )
+ return True if h and key in h and (not w or key not in w or not w[key]) else False
def _is_root_del(self, w, h, key):
"""
@@ -763,11 +673,7 @@ class Firewall_global(ConfigBase):
:param key: attribute name.
:return: True/False.
"""
- return (
- True
- if h and key in h and (not w or key not in w or not w[key])
- else False
- )
+ return True if h and key in h and (not w or key not in w or not w[key]) else False
def _is_del(self, b_set, h, key="number"):
"""
diff --git a/plugins/module_utils/network/vyos/config/firewall_interfaces/firewall_interfaces.py b/plugins/module_utils/network/vyos/config/firewall_interfaces/firewall_interfaces.py
index 45842f1..566bfeb 100644
--- a/plugins/module_utils/network/vyos/config/firewall_interfaces/firewall_interfaces.py
+++ b/plugins/module_utils/network/vyos/config/firewall_interfaces/firewall_interfaces.py
@@ -15,17 +15,17 @@ from __future__ import absolute_import, division, print_function
__metaclass__ = type
from copy import deepcopy
+
from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base import (
ConfigBase,
)
from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import (
- to_list,
remove_empties,
search_obj_in_list,
+ to_list,
)
-from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.facts import (
- Facts,
-)
+
+from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.facts import Facts
class Firewall_interfaces(ConfigBase):
@@ -54,9 +54,7 @@ class Firewall_interfaces(ConfigBase):
facts, _warnings = Facts(self._module).get_facts(
self.gather_subset, self.gather_network_resources, data=data
)
- firewall_interfaces_facts = facts["ansible_network_resources"].get(
- "firewall_interfaces"
- )
+ firewall_interfaces_facts = facts["ansible_network_resources"].get("firewall_interfaces")
if not firewall_interfaces_facts:
return []
return firewall_interfaces_facts
@@ -72,16 +70,12 @@ class Firewall_interfaces(ConfigBase):
commands = list()
if self.state in self.ACTION_STATES:
- existing_firewall_interfaces_facts = (
- self.get_firewall_interfaces_facts()
- )
+ existing_firewall_interfaces_facts = self.get_firewall_interfaces_facts()
else:
existing_firewall_interfaces_facts = []
if self.state in self.ACTION_STATES or self.state == "rendered":
- commands.extend(
- self.set_config(existing_firewall_interfaces_facts)
- )
+ commands.extend(self.set_config(existing_firewall_interfaces_facts))
if commands and self.state in self.ACTION_STATES:
if not self._module.check_mode:
@@ -92,9 +86,7 @@ class Firewall_interfaces(ConfigBase):
result["commands"] = commands
if self.state in self.ACTION_STATES or self.state == "gathered":
- changed_firewall_interfaces_facts = (
- self.get_firewall_interfaces_facts()
- )
+ changed_firewall_interfaces_facts = self.get_firewall_interfaces_facts()
elif self.state == "rendered":
result["rendered"] = commands
elif self.state == "parsed":
@@ -103,9 +95,7 @@ class Firewall_interfaces(ConfigBase):
self._module.fail_json(
msg="value of running_config parameter must not be empty for state parsed"
)
- result["parsed"] = self.get_firewall_interfaces_facts(
- data=running_config
- )
+ result["parsed"] = self.get_firewall_interfaces_facts(data=running_config)
else:
changed_firewall_interfaces_facts = []
@@ -142,14 +132,9 @@ class Firewall_interfaces(ConfigBase):
to the desired configuration
"""
commands = []
- if (
- self.state in ("merged", "replaced", "overridden", "rendered")
- and not w
- ):
+ if self.state in ("merged", "replaced", "overridden", "rendered") and not w:
self._module.fail_json(
- msg="value of config parameter must not be empty for state {0}".format(
- self.state
- )
+ msg="value of config parameter must not be empty for state {0}".format(self.state)
)
if self.state == "overridden":
commands.extend(self._state_overridden(w, h))
@@ -189,41 +174,27 @@ class Firewall_interfaces(ConfigBase):
for h_ar in have:
w_ar = search_obj_in_list(h_ar["name"], want)
if not w_ar and "access_rules" in h_ar:
- commands.append(
- self._compute_command(name=h_ar["name"], opr=False)
- )
+ commands.append(self._compute_command(name=h_ar["name"], opr=False))
else:
h_rules = h_ar.get("access_rules") or []
key = "direction"
if w_ar:
w_rules = w_ar.get("access_rules") or []
if not w_rules and h_rules:
- commands.append(
- self._compute_command(
- name=h_ar["name"], opr=False
- )
- )
+ commands.append(self._compute_command(name=h_ar["name"], opr=False))
if h_rules:
for h_rule in h_rules:
- w_rule = search_obj_in_list(
- h_rule["afi"], w_rules, key="afi"
- )
+ w_rule = search_obj_in_list(h_rule["afi"], w_rules, key="afi")
have_rules = h_rule.get("rules") or []
if w_rule:
want_rules = w_rule.get("rules") or []
for h in have_rules:
if key in h:
- w = search_obj_in_list(
- h[key], want_rules, key=key
- )
+ w = search_obj_in_list(h[key], want_rules, key=key)
if (
not w
or key not in w
- or (
- "name" in h
- and w
- and "name" not in w
- )
+ or ("name" in h and w and "name" not in w)
):
commands.append(
self._compute_command(
@@ -267,9 +238,7 @@ class Firewall_interfaces(ConfigBase):
elif have:
for h in have:
if "access_rules" in h:
- commands.append(
- self._compute_command(name=h["name"], opr=False)
- )
+ commands.append(self._compute_command(name=h["name"], opr=False))
return commands
def _delete_access_rules(self, want, have, opr=False):
@@ -321,9 +290,7 @@ class Firewall_interfaces(ConfigBase):
for h in h_rules:
if key in h:
commands.append(
- self._compute_command(
- afi=want["afi"], name=name, attrib=h[key], opr=opr
- )
+ self._compute_command(afi=want["afi"], name=name, attrib=h[key], opr=opr)
)
for w in w_rules:
h = search_obj_in_list(w[key], h_rules, key=key)
@@ -388,9 +355,7 @@ class Firewall_interfaces(ConfigBase):
h = search_obj_in_list(w[key], h_rules, key=key)
if key in w:
if opr:
- if "name" in w and not (
- h and h[key] == w[key] and h["name"] == w["name"]
- ):
+ if "name" in w and not (h and h[key] == w[key] and h["name"] == w["name"]):
commands.append(
self._compute_command(
afi=want["afi"],
@@ -401,16 +366,10 @@ class Firewall_interfaces(ConfigBase):
)
elif not (h and key in h):
commands.append(
- self._compute_command(
- afi=want["afi"], name=name, attrib=w[key]
- )
+ self._compute_command(afi=want["afi"], name=name, attrib=w[key])
)
elif not opr:
- if (
- not h
- or key not in h
- or ("name" in w and h and "name" not in h)
- ):
+ if not h or key not in h or ("name" in w and h and "name" not in h):
commands.append(
self._compute_command(
afi=want["afi"],
@@ -421,9 +380,7 @@ class Firewall_interfaces(ConfigBase):
)
return commands
- def _compute_command(
- self, afi=None, name=None, attrib=None, value=None, opr=True
- ):
+ def _compute_command(self, afi=None, name=None, attrib=None, value=None, opr=True):
"""
This function construct the add/delete command based on passed attributes.
:param afi: address type.
diff --git a/plugins/module_utils/network/vyos/config/firewall_rules/firewall_rules.py b/plugins/module_utils/network/vyos/config/firewall_rules/firewall_rules.py
index ca47652..aa18a7e 100644
--- a/plugins/module_utils/network/vyos/config/firewall_rules/firewall_rules.py
+++ b/plugins/module_utils/network/vyos/config/firewall_rules/firewall_rules.py
@@ -14,22 +14,22 @@ from __future__ import absolute_import, division, print_function
__metaclass__ = type
+import re
from copy import deepcopy
+
+from ansible.module_utils.six import iteritems
from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base import (
ConfigBase,
)
from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import (
- to_list,
remove_empties,
+ to_list,
)
-from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.facts import (
- Facts,
-)
-from ansible.module_utils.six import iteritems
+
+from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.facts import Facts
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.utils.utils import (
list_diff_want_only,
)
-import re
class Firewall_rules(ConfigBase):
@@ -58,9 +58,7 @@ class Firewall_rules(ConfigBase):
facts, _warnings = Facts(self._module).get_facts(
self.gather_subset, self.gather_network_resources, data=data
)
- firewall_rules_facts = facts["ansible_network_resources"].get(
- "firewall_rules"
- )
+ firewall_rules_facts = facts["ansible_network_resources"].get("firewall_rules")
if not firewall_rules_facts:
return []
return firewall_rules_facts
@@ -101,9 +99,7 @@ class Firewall_rules(ConfigBase):
self._module.fail_json(
msg="value of running_config parameter must not be empty for state parsed"
)
- result["parsed"] = self.get_firewall_rules_facts(
- data=running_config
- )
+ result["parsed"] = self.get_firewall_rules_facts(data=running_config)
else:
changed_firewall_rules_facts = []
@@ -140,14 +136,9 @@ class Firewall_rules(ConfigBase):
to the desired configuration
"""
commands = []
- if (
- self.state in ("merged", "replaced", "overridden", "rendered")
- and not w
- ):
+ if self.state in ("merged", "replaced", "overridden", "rendered") and not w:
self._module.fail_json(
- msg="value of config parameter must not be empty for state {0}".format(
- self.state
- )
+ msg="value of config parameter must not be empty for state {0}".format(self.state)
)
if self.state == "overridden":
commands.extend(self._state_overridden(w, h))
@@ -206,19 +197,11 @@ class Firewall_rules(ConfigBase):
for h in have:
r_sets = self._get_r_sets(h)
for rs in r_sets:
- w = self.search_r_sets_in_have(
- want, rs["name"], "r_list", h["afi"]
- )
+ w = self.search_r_sets_in_have(want, rs["name"], "r_list", h["afi"])
if not w:
- commands.append(
- self._compute_command(
- h["afi"], rs["name"], remove=True
- )
- )
+ commands.append(self._compute_command(h["afi"], rs["name"], remove=True))
else:
- commands.extend(
- self._add_r_sets(h["afi"], rs, w, opr=False)
- )
+ commands.extend(self._add_r_sets(h["afi"], rs, w, opr=False))
commands.extend(self._state_merged(want, have))
return commands
@@ -233,9 +216,7 @@ class Firewall_rules(ConfigBase):
for w in want:
r_sets = self._get_r_sets(w)
for rs in r_sets:
- h = self.search_r_sets_in_have(
- have, rs["name"], "r_list", w["afi"]
- )
+ h = self.search_r_sets_in_have(have, rs["name"], "r_list", w["afi"])
commands.extend(self._add_r_sets(w["afi"], rs, h))
return commands
@@ -252,28 +233,18 @@ class Firewall_rules(ConfigBase):
r_sets = self._get_r_sets(w)
if r_sets:
for rs in r_sets:
- h = self.search_r_sets_in_have(
- have, rs["name"], "r_list", w["afi"]
- )
+ h = self.search_r_sets_in_have(have, rs["name"], "r_list", w["afi"])
if h:
- commands.append(
- self._compute_command(
- w["afi"], h["name"], remove=True
- )
- )
+ commands.append(self._compute_command(w["afi"], h["name"], remove=True))
elif have:
for h in have:
if h["afi"] == w["afi"]:
- commands.append(
- self._compute_command(w["afi"], remove=True)
- )
+ commands.append(self._compute_command(w["afi"], remove=True))
elif have:
for h in have:
r_sets = self._get_r_sets(h)
if r_sets:
- commands.append(
- self._compute_command(afi=h["afi"], remove=True)
- )
+ commands.append(self._compute_command(afi=h["afi"], remove=True))
return commands
def _add_r_sets(self, afi, want, have, opr=True):
@@ -297,26 +268,12 @@ class Firewall_rules(ConfigBase):
h_rules = h_rs.pop("rules", None)
if w_rs:
for key, val in iteritems(w_rs):
- if (
- opr
- and key in l_set
- and not (h_rs and self._is_w_same(w_rs, h_rs, key))
- ):
+ if opr and key in l_set and not (h_rs and self._is_w_same(w_rs, h_rs, key)):
if key == "enable_default_log":
- if val and (
- not h_rs or key not in h_rs or not h_rs[key]
- ):
- commands.append(
- self._add_rs_base_attrib(
- afi, want["name"], key, w_rs
- )
- )
+ if val and (not h_rs or key not in h_rs or not h_rs[key]):
+ commands.append(self._add_rs_base_attrib(afi, want["name"], key, w_rs))
else:
- commands.append(
- self._add_rs_base_attrib(
- afi, want["name"], key, w_rs
- )
- )
+ commands.append(self._add_rs_base_attrib(afi, want["name"], key, w_rs))
elif not opr and key in l_set:
if (
key == "enable_default_log"
@@ -324,20 +281,10 @@ class Firewall_rules(ConfigBase):
and h_rs
and (key not in h_rs or not h_rs[key])
):
- commands.append(
- self._add_rs_base_attrib(
- afi, want["name"], key, w_rs, opr
- )
- )
+ commands.append(self._add_rs_base_attrib(afi, want["name"], key, w_rs, opr))
elif not (h_rs and self._in_target(h_rs, key)):
- commands.append(
- self._add_rs_base_attrib(
- afi, want["name"], key, w_rs, opr
- )
- )
- commands.extend(
- self._add_rules(afi, want["name"], w_rules, h_rules, opr)
- )
+ commands.append(self._add_rs_base_attrib(afi, want["name"], key, w_rs, opr))
+ commands.extend(self._add_rules(afi, want["name"], w_rules, h_rules, opr))
if h_rules:
have["rules"] = h_rules
if w_rules:
@@ -366,87 +313,43 @@ class Firewall_rules(ConfigBase):
if w_rules:
for w in w_rules:
cmd = self._compute_command(afi, name, w["number"], opr=opr)
- h = self.search_r_sets_in_have(
- h_rules, w["number"], type="rules"
- )
+ h = self.search_r_sets_in_have(h_rules, w["number"], type="rules")
for key, val in iteritems(w):
if val:
- if (
- opr
- and key in l_set
- and not (h and self._is_w_same(w, h, key))
- ):
+ if opr and key in l_set and not (h and self._is_w_same(w, h, key)):
if key == "disable":
- if not (
- not val
- and (not h or key not in h or not h[key])
- ):
- commands.append(
- self._add_r_base_attrib(
- afi, name, key, w
- )
- )
+ if not (not val and (not h or key not in h or not h[key])):
+ commands.append(self._add_r_base_attrib(afi, name, key, w))
else:
- commands.append(
- self._add_r_base_attrib(afi, name, key, w)
- )
+ commands.append(self._add_r_base_attrib(afi, name, key, w))
elif not opr:
if key == "number" and self._is_del(l_set, h):
- commands.append(
- self._add_r_base_attrib(
- afi, name, key, w, opr=opr
- )
- )
+ commands.append(self._add_r_base_attrib(afi, name, key, w, opr=opr))
continue
- if (
- key == "disable"
- and val
- and h
- and (key not in h or not h[key])
- ):
- commands.append(
- self._add_r_base_attrib(
- afi, name, key, w, opr=opr
- )
- )
+ if key == "disable" and val and h and (key not in h or not h[key]):
+ commands.append(self._add_r_base_attrib(afi, name, key, w, opr=opr))
elif (
key in l_set
and not (h and self._in_target(h, key))
and not self._is_del(l_set, h)
):
- commands.append(
- self._add_r_base_attrib(
- afi, name, key, w, opr=opr
- )
- )
+ commands.append(self._add_r_base_attrib(afi, name, key, w, opr=opr))
elif key == "p2p":
commands.extend(self._add_p2p(key, w, h, cmd, opr))
elif key == "tcp":
commands.extend(self._add_tcp(key, w, h, cmd, opr))
elif key == "time":
- commands.extend(
- self._add_time(key, w, h, cmd, opr)
- )
+ commands.extend(self._add_time(key, w, h, cmd, opr))
elif key == "icmp":
- commands.extend(
- self._add_icmp(key, w, h, cmd, opr)
- )
+ commands.extend(self._add_icmp(key, w, h, cmd, opr))
elif key == "state":
- commands.extend(
- self._add_state(key, w, h, cmd, opr)
- )
+ commands.extend(self._add_state(key, w, h, cmd, opr))
elif key == "limit":
- commands.extend(
- self._add_limit(key, w, h, cmd, opr)
- )
+ commands.extend(self._add_limit(key, w, h, cmd, opr))
elif key == "recent":
- commands.extend(
- self._add_recent(key, w, h, cmd, opr)
- )
+ commands.extend(self._add_recent(key, w, h, cmd, opr))
elif key == "destination" or key == "source":
- commands.extend(
- self._add_src_or_dest(key, w, h, cmd, opr)
- )
+ commands.extend(self._add_src_or_dest(key, w, h, cmd, opr))
return commands
def _add_p2p(self, attr, w, h, cmd, opr):
@@ -467,15 +370,11 @@ class Firewall_rules(ConfigBase):
if opr:
applications = list_diff_want_only(want, have)
for app in applications:
- commands.append(
- cmd + (" " + attr + " " + app["application"])
- )
+ commands.append(cmd + (" " + attr + " " + app["application"]))
elif not opr and have:
applications = list_diff_want_only(want, have)
for app in applications:
- commands.append(
- cmd + (" " + attr + " " + app["application"])
- )
+ commands.append(cmd + (" " + attr + " " + app["application"]))
return commands
def _add_state(self, attr, w, h, cmd, opr):
@@ -497,26 +396,10 @@ class Firewall_rules(ConfigBase):
if (
opr
and item in l_set
- and not (
- h_state and self._is_w_same(w[attr], h_state, item)
- )
- ):
- commands.append(
- cmd
- + (
- " "
- + attr
- + " "
- + item
- + " "
- + self._bool_to_str(val)
- )
- )
- elif (
- not opr
- and item in l_set
- and not (h_state and self._in_target(h_state, item))
+ and not (h_state and self._is_w_same(w[attr], h_state, item))
):
+ commands.append(cmd + (" " + attr + " " + item + " " + self._bool_to_str(val)))
+ elif not opr and item in l_set and not (h_state and self._in_target(h_state, item)):
commands.append(cmd + (" " + attr + " " + item))
return commands
@@ -539,17 +422,11 @@ class Firewall_rules(ConfigBase):
if (
opr
and item in l_set
- and not (
- h_recent and self._is_w_same(w[attr], h_recent, item)
- )
+ and not (h_recent and self._is_w_same(w[attr], h_recent, item))
):
- commands.append(
- cmd + (" " + attr + " " + item + " " + str(val))
- )
+ commands.append(cmd + (" " + attr + " " + item + " " + str(val)))
elif (
- not opr
- and item in l_set
- and not (h_recent and self._in_target(h_recent, item))
+ not opr and item in l_set and not (h_recent and self._in_target(h_recent, item))
):
commands.append(cmd + (" " + attr + " " + item))
return commands
@@ -587,38 +464,14 @@ class Firewall_rules(ConfigBase):
else:
param_name = "type"
if "ipv6-name" in cmd:
- commands.append(
- cmd
- + (
- " "
- + "icmpv6"
- + " "
- + param_name
- + " "
- + val
- )
- )
+ commands.append(cmd + (" " + "icmpv6" + " " + param_name + " " + val))
else:
commands.append(
- cmd
- + (
- " "
- + attr
- + " "
- + item.replace("_", "-")
- + " "
- + val
- )
+ cmd + (" " + attr + " " + item.replace("_", "-") + " " + val)
)
else:
- commands.append(
- cmd + (" " + attr + " " + item + " " + str(val))
- )
- elif (
- not opr
- and item in l_set
- and not (h_icmp and self._in_target(h_icmp, item))
- ):
+ commands.append(cmd + (" " + attr + " " + item + " " + str(val)))
+ elif not opr and item in l_set and not (h_icmp and self._in_target(h_icmp, item)):
commands.append(cmd + (" " + attr + " " + item))
return commands
@@ -652,14 +505,10 @@ class Firewall_rules(ConfigBase):
and not (h_time and self._is_w_same(w[attr], h_time, item))
):
if item == "utc":
- if not (
- not val and (not h_time or item not in h_time)
- ):
+ if not (not val and (not h_time or item not in h_time)):
commands.append(cmd + (" " + attr + " " + item))
else:
- commands.append(
- cmd + (" " + attr + " " + item + " " + val)
- )
+ commands.append(cmd + (" " + attr + " " + item + " " + val))
elif (
not opr
and item in l_set
@@ -686,18 +535,10 @@ class Firewall_rules(ConfigBase):
if h and key in h[attr].keys():
h_tcp = h[attr].get(key) or {}
if flags:
- if opr and not (
- h_tcp and self._is_w_same(w[attr], h[attr], key)
- ):
- commands.append(
- cmd + (" " + attr + " " + key + " " + flags)
- )
- if not opr and not (
- h_tcp and self._is_w_same(w[attr], h[attr], key)
- ):
- commands.append(
- cmd + (" " + attr + " " + key + " " + flags)
- )
+ if opr and not (h_tcp and self._is_w_same(w[attr], h[attr], key)):
+ commands.append(cmd + (" " + attr + " " + key + " " + flags))
+ if not opr and not (h_tcp and self._is_w_same(w[attr], h[attr], key)):
+ commands.append(cmd + (" " + attr + " " + key + " " + flags))
return commands
def _add_limit(self, attr, w, h, cmd, opr):
@@ -716,27 +557,15 @@ class Firewall_rules(ConfigBase):
if (
opr
and key in w[attr].keys()
- and not (
- h
- and attr in h.keys()
- and self._is_w_same(w[attr], h[attr], key)
- )
+ and not (h and attr in h.keys() and self._is_w_same(w[attr], h[attr], key))
):
- commands.append(
- cmd
- + (" " + attr + " " + key + " " + str(w[attr].get(key)))
- )
+ commands.append(cmd + (" " + attr + " " + key + " " + str(w[attr].get(key))))
elif (
not opr
and key in w[attr].keys()
- and not (
- h and attr in h.keys() and self._in_target(h[attr], key)
- )
+ and not (h and attr in h.keys() and self._in_target(h[attr], key))
):
- commands.append(
- cmd
- + (" " + attr + " " + key + " " + str(w[attr].get(key)))
- )
+ commands.append(cmd + (" " + attr + " " + key + " " + str(w[attr].get(key))))
key = "rate"
rate = w[attr].get(key) or {}
if rate:
@@ -787,31 +616,15 @@ class Firewall_rules(ConfigBase):
if (
opr
and key in w[attr].keys()
- and not (
- h
- and attr in h.keys()
- and self._is_w_same(w[attr], h[attr], key)
- )
+ and not (h and attr in h.keys() and self._is_w_same(w[attr], h[attr], key))
):
commands.append(
- cmd
- + (
- " "
- + attr
- + " "
- + key.replace("_", "-")
- + " "
- + w[attr].get(key)
- )
+ cmd + (" " + attr + " " + key.replace("_", "-") + " " + w[attr].get(key))
)
elif (
not opr
and key in w[attr].keys()
- and not (
- h
- and attr in h.keys()
- and self._in_target(h[attr], key)
- )
+ and not (h and attr in h.keys() and self._in_target(h[attr], key))
):
commands.append(cmd + (" " + attr + " " + key))
@@ -826,10 +639,7 @@ class Firewall_rules(ConfigBase):
if (
opr
and item in g_set
- and not (
- h_group
- and self._is_w_same(group, h_group, item)
- )
+ and not (h_group and self._is_w_same(group, h_group, item))
):
commands.append(
cmd
@@ -847,20 +657,10 @@ class Firewall_rules(ConfigBase):
elif (
not opr
and item in g_set
- and not (
- h_group and self._in_target(h_group, item)
- )
+ and not (h_group and self._in_target(h_group, item))
):
commands.append(
- cmd
- + (
- " "
- + attr
- + " "
- + key
- + " "
- + item.replace("_", "-")
- )
+ cmd + (" " + attr + " " + key + " " + item.replace("_", "-"))
)
return commands
@@ -938,12 +738,7 @@ class Firewall_rules(ConfigBase):
cmd += " rule " + str(number)
if attrib:
cmd += " " + attrib.replace("_", "-")
- if (
- value
- and opr
- and attrib != "enable_default_log"
- and attrib != "disable"
- ):
+ if value and opr and attrib != "enable_default_log" and attrib != "disable":
cmd += " '" + str(value) + "'"
return cmd
@@ -959,9 +754,7 @@ class Firewall_rules(ConfigBase):
:return: generated command.
"""
if attr == "number":
- command = self._compute_command(
- afi=afi, name=name, number=rule["number"], opr=opr
- )
+ command = self._compute_command(afi=afi, name=name, number=rule["number"], opr=opr)
else:
command = self._compute_command(
afi=afi,
@@ -1062,7 +855,5 @@ class Firewall_rules(ConfigBase):
def _get_os_version(self):
os_version = "1.2"
if self._connection:
- os_version = self._connection.get_device_info()[
- "network_os_version"
- ]
+ os_version = self._connection.get_device_info()["network_os_version"]
return os_version
diff --git a/plugins/module_utils/network/vyos/config/hostname/hostname.py b/plugins/module_utils/network/vyos/config/hostname/hostname.py
index cf2c8c2..8b30a69 100644
--- a/plugins/module_utils/network/vyos/config/hostname/hostname.py
+++ b/plugins/module_utils/network/vyos/config/hostname/hostname.py
@@ -20,9 +20,8 @@ created.
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.facts.facts import Facts
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.rm_templates.hostname import (
HostnameTemplate,
)
diff --git a/plugins/module_utils/network/vyos/config/interfaces/interfaces.py b/plugins/module_utils/network/vyos/config/interfaces/interfaces.py
index 484e600..852db46 100644
--- a/plugins/module_utils/network/vyos/config/interfaces/interfaces.py
+++ b/plugins/module_utils/network/vyos/config/interfaces/interfaces.py
@@ -14,22 +14,22 @@ from __future__ import absolute_import, division, print_function
__metaclass__ = type
from copy import deepcopy
+
+from ansible.module_utils.six import iteritems
from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base import (
ConfigBase,
)
from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import (
- to_list,
dict_diff,
remove_empties,
+ to_list,
)
-from ansible.module_utils.six import iteritems
-from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.facts import (
- Facts,
-)
+
+from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.facts import Facts
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.utils.utils import (
- search_obj_in_list,
- get_interface_type,
dict_delete,
+ get_interface_type,
+ search_obj_in_list,
)
@@ -135,14 +135,9 @@ class Interfaces(ConfigBase):
"""
commands = []
- if (
- self.state in ("merged", "replaced", "overridden", "rendered")
- and not want
- ):
+ if self.state in ("merged", "replaced", "overridden", "rendered") and not want:
self._module.fail_json(
- msg="value of config parameter must not be empty for state {0}".format(
- self.state
- )
+ msg="value of config parameter must not be empty for state {0}".format(self.state)
)
if self.state == "overridden":
@@ -151,9 +146,7 @@ class Interfaces(ConfigBase):
elif self.state == "deleted":
if not want:
for intf in have:
- commands.extend(
- self._state_deleted({"name": intf["name"]}, intf)
- )
+ commands.extend(self._state_deleted({"name": intf["name"]}, intf))
else:
for item in want:
obj_in_have = search_obj_in_list(item["name"], have)
@@ -201,9 +194,7 @@ class Interfaces(ConfigBase):
for intf in have:
intf_in_want = search_obj_in_list(intf["name"], want)
if not intf_in_want:
- commands.extend(
- self._state_deleted({"name": intf["name"]}, intf)
- )
+ commands.extend(self._state_deleted({"name": intf["name"]}, intf))
for intf in want:
intf_in_have = search_obj_in_list(intf["name"], have)
@@ -235,16 +226,12 @@ class Interfaces(ConfigBase):
if updates:
for key, value in iteritems(updates):
commands.append(
- self._compute_commands(
- key=key, value=value, interface=want_copy["name"]
- )
+ self._compute_commands(key=key, value=value, interface=want_copy["name"])
)
if want_vifs:
for want_vif in want_vifs:
- have_vif = search_obj_in_list(
- want_vif["vlan_id"], have_vifs, key="vlan_id"
- )
+ have_vif = search_obj_in_list(want_vif["vlan_id"], have_vifs, key="vlan_id")
if not have_vif:
have_vif = {
"vlan_id": want_vif["vlan_id"],
@@ -283,22 +270,16 @@ class Interfaces(ConfigBase):
if key == "enabled":
continue
commands.append(
- self._compute_commands(
- key=key, interface=want_copy["name"], remove=True
- )
+ self._compute_commands(key=key, interface=want_copy["name"], remove=True)
)
if have_copy["enabled"] is False:
commands.append(
- self._compute_commands(
- key="enabled", value=True, interface=want_copy["name"]
- )
+ self._compute_commands(key="enabled", value=True, interface=want_copy["name"])
)
if have_vifs:
for have_vif in have_vifs:
- want_vif = search_obj_in_list(
- have_vif["vlan_id"], want_vifs, key="vlan_id"
- )
+ want_vif = search_obj_in_list(have_vif["vlan_id"], want_vifs, key="vlan_id")
if not want_vif:
want_vif = {
"vlan_id": have_vif["vlan_id"],
@@ -327,12 +308,8 @@ class Interfaces(ConfigBase):
)
return commands
- def _compute_commands(
- self, interface, key, vif=None, value=None, remove=False
- ):
- intf_context = "interfaces {0} {1}".format(
- get_interface_type(interface), interface
- )
+ def _compute_commands(self, interface, key, vif=None, value=None, remove=False):
+ intf_context = "interfaces {0} {1}".format(get_interface_type(interface), interface)
set_cmd = "set {0}".format(intf_context)
del_cmd = "delete {0}".format(intf_context)
diff --git a/plugins/module_utils/network/vyos/config/l3_interfaces/l3_interfaces.py b/plugins/module_utils/network/vyos/config/l3_interfaces/l3_interfaces.py
index 6f143be..61dd1f4 100644
--- a/plugins/module_utils/network/vyos/config/l3_interfaces/l3_interfaces.py
+++ b/plugins/module_utils/network/vyos/config/l3_interfaces/l3_interfaces.py
@@ -17,21 +17,21 @@ __metaclass__ = type
from copy import deepcopy
+
+from ansible.module_utils.six import iteritems
from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base import (
ConfigBase,
)
from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import (
- to_list,
remove_empties,
+ to_list,
)
-from ansible.module_utils.six import iteritems
-from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.facts import (
- Facts,
-)
+
+from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.facts import Facts
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.utils.utils import (
- search_obj_in_list,
- get_interface_type,
diff_list_of_dicts,
+ get_interface_type,
+ search_obj_in_list,
)
@@ -61,9 +61,7 @@ class L3_interfaces(ConfigBase):
facts, _warnings = Facts(self._module).get_facts(
self.gather_subset, self.gather_network_resources, data=data
)
- l3_interfaces_facts = facts["ansible_network_resources"].get(
- "l3_interfaces"
- )
+ l3_interfaces_facts = facts["ansible_network_resources"].get("l3_interfaces")
if not l3_interfaces_facts:
return []
return l3_interfaces_facts
@@ -104,9 +102,7 @@ class L3_interfaces(ConfigBase):
self._module.fail_json(
msg="value of running_config parameter must not be empty for state parsed"
)
- result["parsed"] = self.get_l3_interfaces_facts(
- data=running_config
- )
+ result["parsed"] = self.get_l3_interfaces_facts(data=running_config)
else:
changed_l3_interfaces_facts = []
@@ -145,14 +141,9 @@ class L3_interfaces(ConfigBase):
commands = []
state = self._module.params["state"]
- if (
- state in ("merged", "replaced", "overridden", "rendered")
- and not want
- ):
+ if state in ("merged", "replaced", "overridden", "rendered") and not want:
self._module.fail_json(
- msg="value of config parameter must not be empty for state {0}".format(
- state
- )
+ msg="value of config parameter must not be empty for state {0}".format(state)
)
if state == "overridden":
@@ -161,9 +152,7 @@ class L3_interfaces(ConfigBase):
elif state == "deleted":
if not want:
for intf in have:
- commands.extend(
- self._state_deleted({"name": intf["name"]}, intf)
- )
+ commands.extend(self._state_deleted({"name": intf["name"]}, intf))
else:
for item in want:
obj_in_have = search_obj_in_list(item["name"], have)
@@ -211,9 +200,7 @@ class L3_interfaces(ConfigBase):
for intf in have:
intf_in_want = search_obj_in_list(intf["name"], want)
if not intf_in_want:
- commands.extend(
- self._state_deleted({"name": intf["name"]}, intf)
- )
+ commands.extend(self._state_deleted({"name": intf["name"]}, intf))
for intf in want:
intf_in_have = search_obj_in_list(intf["name"], have)
@@ -238,16 +225,12 @@ class L3_interfaces(ConfigBase):
for update in self._get_updates(want_copy, have_copy):
for key, value in iteritems(update):
commands.append(
- self._compute_commands(
- key=key, value=value, interface=want_copy["name"]
- )
+ self._compute_commands(key=key, value=value, interface=want_copy["name"])
)
if want_vifs:
for want_vif in want_vifs:
- have_vif = search_obj_in_list(
- want_vif["vlan_id"], have_vifs, key="vlan_id"
- )
+ have_vif = search_obj_in_list(want_vif["vlan_id"], have_vifs, key="vlan_id")
if not have_vif:
have_vif = {}
@@ -291,9 +274,7 @@ class L3_interfaces(ConfigBase):
if have_vifs:
for have_vif in have_vifs:
- want_vif = search_obj_in_list(
- have_vif["vlan_id"], want_vifs, key="vlan_id"
- )
+ want_vif = search_obj_in_list(have_vif["vlan_id"], want_vifs, key="vlan_id")
if not want_vif:
want_vif = {"vlan_id": have_vif["vlan_id"]}
@@ -311,12 +292,8 @@ class L3_interfaces(ConfigBase):
return commands
- def _compute_commands(
- self, interface, key, vif=None, value=None, remove=False
- ):
- intf_context = "interfaces {0} {1}".format(
- get_interface_type(interface), interface
- )
+ def _compute_commands(self, interface, key, vif=None, value=None, remove=False):
+ intf_context = "interfaces {0} {1}".format(get_interface_type(interface), interface)
set_cmd = "set {0}".format(intf_context)
del_cmd = "delete {0}".format(intf_context)
@@ -334,11 +311,7 @@ class L3_interfaces(ConfigBase):
def _get_updates(self, want, have):
updates = []
- updates = diff_list_of_dicts(
- want.get("ipv4", []), have.get("ipv4", [])
- )
- updates.extend(
- diff_list_of_dicts(want.get("ipv6", []), have.get("ipv6", []))
- )
+ updates = diff_list_of_dicts(want.get("ipv4", []), have.get("ipv4", []))
+ updates.extend(diff_list_of_dicts(want.get("ipv6", []), have.get("ipv6", [])))
return updates
diff --git a/plugins/module_utils/network/vyos/config/lag_interfaces/lag_interfaces.py b/plugins/module_utils/network/vyos/config/lag_interfaces/lag_interfaces.py
index 7e7b39a..314ff93 100644
--- a/plugins/module_utils/network/vyos/config/lag_interfaces/lag_interfaces.py
+++ b/plugins/module_utils/network/vyos/config/lag_interfaces/lag_interfaces.py
@@ -11,22 +11,21 @@ created
from __future__ import absolute_import, division, print_function
__metaclass__ = type
+from ansible.module_utils.six import iteritems
from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base import (
ConfigBase,
)
-from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.facts import (
- Facts,
-)
from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import (
- to_list,
dict_diff,
+ to_list,
)
-from ansible.module_utils.six import iteritems
+
+from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.facts import Facts
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.utils.utils import (
- search_obj_in_list,
get_lst_diff_for_dicts,
- list_diff_want_only,
list_diff_have_only,
+ list_diff_want_only,
+ search_obj_in_list,
)
@@ -65,9 +64,7 @@ class Lag_interfaces(ConfigBase):
facts, _warnings = Facts(self._module).get_facts(
self.gather_subset, self.gather_network_resources, data=data
)
- lag_interfaces_facts = facts["ansible_network_resources"].get(
- "lag_interfaces"
- )
+ lag_interfaces_facts = facts["ansible_network_resources"].get("lag_interfaces")
if not lag_interfaces_facts:
return []
return lag_interfaces_facts
@@ -108,9 +105,7 @@ class Lag_interfaces(ConfigBase):
self._module.fail_json(
msg="value of running_config parameter must not be empty for state parsed"
)
- result["parsed"] = self.get_lag_interfaces_facts(
- data=running_config
- )
+ result["parsed"] = self.get_lag_interfaces_facts(data=running_config)
else:
changed_lag_interfaces_facts = []
@@ -147,14 +142,9 @@ class Lag_interfaces(ConfigBase):
to the desired configuration
"""
commands = []
- if (
- self.state in ("merged", "replaced", "overridden", "rendered")
- and not want
- ):
+ if self.state in ("merged", "replaced", "overridden", "rendered") and not want:
self._module.fail_json(
- msg="value of config parameter must not be empty for state {0}".format(
- self.state
- )
+ msg="value of config parameter must not be empty for state {0}".format(self.state)
)
if self.state == "overridden":
commands.extend(self._state_overridden(want, have))
@@ -174,9 +164,7 @@ class Lag_interfaces(ConfigBase):
if self.state in ("merged", "rendered"):
commands.extend(self._state_merged(want_item, obj_in_have))
elif self.state == "replaced":
- commands.extend(
- self._state_replaced(want_item, obj_in_have)
- )
+ commands.extend(self._state_replaced(want_item, obj_in_have))
return commands
def _state_replaced(self, want, have):
@@ -257,15 +245,9 @@ class Lag_interfaces(ConfigBase):
for key, value in iteritems(updates):
if value:
if key == "arp_monitor":
- commands.extend(
- self._add_arp_monitor(updates, key, want, have)
- )
+ commands.extend(self._add_arp_monitor(updates, key, want, have))
else:
- commands.append(
- self._compute_command(
- have["name"], key, str(value)
- )
- )
+ commands.append(self._compute_command(have["name"], key, str(value)))
return commands
def _render_set_commands(self, want):
@@ -278,17 +260,11 @@ class Lag_interfaces(ConfigBase):
value = want[attrib]
if value:
if attrib == "arp_monitor":
- commands.extend(
- self._add_arp_monitor(want, attrib, want, have)
- )
+ commands.extend(self._add_arp_monitor(want, attrib, want, have))
elif attrib == "members":
commands.extend(self._add_bond_members(want, have))
elif attrib != "name":
- commands.append(
- self._compute_command(
- want["name"], attrib, value=str(value)
- )
- )
+ commands.append(self._compute_command(want["name"], attrib, value=str(value)))
return commands
def _purge_attribs(self, have):
@@ -298,11 +274,7 @@ class Lag_interfaces(ConfigBase):
if item == "members":
commands.extend(self._delete_bond_members(have))
elif item != "name":
- commands.append(
- self._compute_command(
- have["name"], attrib=item, remove=True
- )
- )
+ commands.append(self._compute_command(have["name"], attrib=item, remove=True))
return commands
def _render_del_commands(self, want, have):
@@ -315,9 +287,7 @@ class Lag_interfaces(ConfigBase):
elif attrib == "arp_monitor":
commands.extend(self._update_arp_monitor(attrib, want, have))
elif have.get(attrib) and not want.get(attrib):
- commands.append(
- self._compute_command(have["name"], attrib, remove=True)
- )
+ commands.append(self._compute_command(have["name"], attrib, remove=True))
return commands
def _add_bond_members(self, want, have):
@@ -338,9 +308,7 @@ class Lag_interfaces(ConfigBase):
def _add_arp_monitor(self, updates, key, want, have):
commands = []
arp_monitor = updates.get(key) or {}
- diff_targets = self._get_arp_monitor_target_diff(
- want, have, key, "target"
- )
+ diff_targets = self._get_arp_monitor_target_diff(want, have, key, "target")
if "interval" in arp_monitor:
commands.append(
@@ -430,9 +398,7 @@ class Lag_interfaces(ConfigBase):
)
return commands
- def _get_arp_monitor_target_diff(
- self, want_list, have_list, dict_name, lst
- ):
+ def _get_arp_monitor_target_diff(self, want_list, have_list, dict_name, lst):
want_arp_target = []
have_arp_target = []
@@ -450,9 +416,7 @@ class Lag_interfaces(ConfigBase):
diff = list_diff_want_only(want_arp_target, have_arp_target)
return diff
- def _compute_command(
- self, key, attrib, value=None, remove=False, type="bonding"
- ):
+ def _compute_command(self, key, attrib, value=None, remove=False, type="bonding"):
if remove:
cmd = "delete interfaces " + type
else:
diff --git a/plugins/module_utils/network/vyos/config/lldp_global/lldp_global.py b/plugins/module_utils/network/vyos/config/lldp_global/lldp_global.py
index d66e9c6..b2571e0 100644
--- a/plugins/module_utils/network/vyos/config/lldp_global/lldp_global.py
+++ b/plugins/module_utils/network/vyos/config/lldp_global/lldp_global.py
@@ -11,17 +11,16 @@ created
from __future__ import absolute_import, division, print_function
__metaclass__ = type
+from ansible.module_utils.six import iteritems
from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base import (
ConfigBase,
)
from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import (
- to_list,
dict_diff,
+ to_list,
)
-from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.facts import (
- Facts,
-)
-from ansible.module_utils.six import iteritems
+
+from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.facts import Facts
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.utils.utils import (
get_lst_diff_for_dicts,
list_diff_have_only,
@@ -56,9 +55,7 @@ class Lldp_global(ConfigBase):
facts, _warnings = Facts(self._module).get_facts(
self.gather_subset, self.gather_network_resources, data=data
)
- lldp_global_facts = facts["ansible_network_resources"].get(
- "lldp_global"
- )
+ lldp_global_facts = facts["ansible_network_resources"].get("lldp_global")
if not lldp_global_facts:
return []
return lldp_global_facts
@@ -138,9 +135,7 @@ class Lldp_global(ConfigBase):
commands = []
if self.state in ("merged", "replaced", "rendered") and not want:
self._module.fail_json(
- msg="value of config parameter must not be empty for state {0}".format(
- self.state
- )
+ msg="value of config parameter must not be empty for state {0}".format(self.state)
)
if self.state == "deleted":
commands.extend(self._state_deleted(want=None, have=have))
@@ -186,29 +181,17 @@ class Lldp_global(ConfigBase):
for item in Lldp_global.params:
if item == "legacy_protocols":
commands.extend(self._update_lldp_protocols(want, have))
- elif (
- have.get(item) and not want.get(item) and item != "enable"
- ):
+ elif have.get(item) and not want.get(item) and item != "enable":
commands.append(Lldp_global.del_cmd + item)
elif have:
for item in Lldp_global.params:
if have.get(item):
if item == "legacy_protocols":
- commands.append(
- self._compute_command(
- "legacy-protocols", remove=True
- )
- )
+ commands.append(self._compute_command("legacy-protocols", remove=True))
elif item == "address":
- commands.append(
- self._compute_command(
- "management-address", remove=True
- )
- )
+ commands.append(self._compute_command("management-address", remove=True))
elif item == "snmp":
- commands.append(
- self._compute_command(item, remove=True)
- )
+ commands.append(self._compute_command(item, remove=True))
return commands
@@ -235,20 +218,12 @@ class Lldp_global(ConfigBase):
if key == "enable":
commands.append(self._compute_command())
elif key == "address":
- commands.append(
- self._compute_command(
- "management-address", str(value)
- )
- )
+ commands.append(self._compute_command("management-address", str(value)))
elif key == "snmp":
if value == "disable":
- commands.append(
- self._compute_command(key, remove=True)
- )
+ commands.append(self._compute_command(key, remove=True))
else:
- commands.append(
- self._compute_command(key, str(value))
- )
+ commands.append(self._compute_command(key, str(value)))
return commands
def _add_lldp_protocols(self, want, have):
@@ -266,11 +241,7 @@ class Lldp_global(ConfigBase):
members_diff = list_diff_have_only(want_protocols, have_protocols)
if members_diff:
for member in members_diff:
- commands.append(
- self._compute_command(
- "legacy-protocols", member, remove=True
- )
- )
+ commands.append(self._compute_command("legacy-protocols", member, remove=True))
return commands
def _compute_command(self, key=None, value=None, remove=False):
diff --git a/plugins/module_utils/network/vyos/config/lldp_interfaces/lldp_interfaces.py b/plugins/module_utils/network/vyos/config/lldp_interfaces/lldp_interfaces.py
index f1f299f..11b950b 100644
--- a/plugins/module_utils/network/vyos/config/lldp_interfaces/lldp_interfaces.py
+++ b/plugins/module_utils/network/vyos/config/lldp_interfaces/lldp_interfaces.py
@@ -15,22 +15,21 @@ from __future__ import absolute_import, division, print_function
__metaclass__ = type
+from ansible.module_utils.six import iteritems
from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base import (
ConfigBase,
)
-from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.facts import (
- Facts,
-)
from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import (
- to_list,
dict_diff,
+ to_list,
)
-from ansible.module_utils.six import iteritems
+
+from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.facts import Facts
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.utils.utils import (
- search_obj_in_list,
- search_dict_tv_in_list,
- key_value_in_dict,
is_dict_element_present,
+ key_value_in_dict,
+ search_dict_tv_in_list,
+ search_obj_in_list,
)
@@ -62,9 +61,7 @@ class Lldp_interfaces(ConfigBase):
facts, _warnings = Facts(self._module).get_facts(
self.gather_subset, self.gather_network_resources, data=data
)
- lldp_interfaces_facts = facts["ansible_network_resources"].get(
- "lldp_interfaces"
- )
+ lldp_interfaces_facts = facts["ansible_network_resources"].get("lldp_interfaces")
if not lldp_interfaces_facts:
return []
return lldp_interfaces_facts
@@ -105,9 +102,7 @@ class Lldp_interfaces(ConfigBase):
self._module.fail_json(
msg="value of running_config parameter must not be empty for state parsed"
)
- result["parsed"] = self.get_lldp_interfaces_facts(
- data=running_config
- )
+ result["parsed"] = self.get_lldp_interfaces_facts(data=running_config)
else:
changed_lldp_interfaces_facts = []
@@ -144,14 +139,9 @@ class Lldp_interfaces(ConfigBase):
to the desired configuration
"""
commands = []
- if (
- self.state in ("merged", "replaced", "overridden", "rendered")
- and not want
- ):
+ if self.state in ("merged", "replaced", "overridden", "rendered") and not want:
self._module.fail_json(
- msg="value of config parameter must not be empty for state {0}".format(
- self.state
- )
+ msg="value of config parameter must not be empty for state {0}".format(self.state)
)
if self.state == "overridden":
commands.extend(self._state_overridden(want=want, have=have))
@@ -160,26 +150,18 @@ class Lldp_interfaces(ConfigBase):
for item in want:
name = item["name"]
have_item = search_obj_in_list(name, have)
- commands.extend(
- self._state_deleted(want=None, have=have_item)
- )
+ commands.extend(self._state_deleted(want=None, have=have_item))
else:
for have_item in have:
- commands.extend(
- self._state_deleted(want=None, have=have_item)
- )
+ commands.extend(self._state_deleted(want=None, have=have_item))
else:
for want_item in want:
name = want_item["name"]
have_item = search_obj_in_list(name, have)
if self.state in ("merged", "rendered"):
- commands.extend(
- self._state_merged(want=want_item, have=have_item)
- )
+ commands.extend(self._state_merged(want=want_item, have=have_item))
if self.state == "replaced":
- commands.extend(
- self._state_replaced(want=want_item, have=have_item)
- )
+ commands.extend(self._state_replaced(want=want_item, have=have_item))
return commands
def _state_replaced(self, want, have):
@@ -207,9 +189,7 @@ class Lldp_interfaces(ConfigBase):
lldp_name = have_item["name"]
lldp_in_want = search_obj_in_list(lldp_name, want)
if not lldp_in_want:
- commands.append(
- self._compute_command(have_item["name"], remove=True)
- )
+ commands.append(self._compute_command(have_item["name"], remove=True))
for want_item in want:
name = want_item["name"]
@@ -243,9 +223,7 @@ class Lldp_interfaces(ConfigBase):
params = Lldp_interfaces.params
for attrib in params:
if attrib == "location":
- commands.extend(
- self._update_location(have["name"], want, have)
- )
+ commands.extend(self._update_location(have["name"], want, have))
elif have:
commands.append(self._compute_command(have["name"], remove=True))
@@ -272,9 +250,7 @@ class Lldp_interfaces(ConfigBase):
commands.extend(self._add_location(lldp_name, want, have))
elif attrib == "enable":
if not value:
- commands.append(
- self._compute_command(lldp_name, value="disable")
- )
+ commands.append(self._compute_command(lldp_name, value="disable"))
else:
commands.append(self._compute_command(lldp_name))
@@ -288,9 +264,7 @@ class Lldp_interfaces(ConfigBase):
temp_have_item = True
if want_item["enable"] != temp_have_item:
if want_item["enable"]:
- commands.append(
- self._compute_command(name, value="disable", remove=True)
- )
+ commands.append(self._compute_command(name, value="disable", remove=True))
else:
commands.append(self._compute_command(name, value="disable"))
return commands
@@ -311,11 +285,7 @@ class Lldp_interfaces(ConfigBase):
updates = dict_diff(have_dict, want_dict)
for key, value in iteritems(updates):
if value:
- commands.append(
- self._compute_command(
- set_cmd + location_type, key, str(value)
- )
- )
+ commands.append(self._compute_command(set_cmd + location_type, key, str(value)))
elif want_location_type["civic_based"]:
location_type = "civic-based"
@@ -345,9 +315,7 @@ class Lldp_interfaces(ConfigBase):
elif want_location_type["elin"]:
location_type = "elin"
if is_dict_element_present(have_location_type, "elin"):
- if want_location_type.get("elin") != have_location_type.get(
- "elin"
- ):
+ if want_location_type.get("elin") != have_location_type.get("elin"):
commands.append(
self._compute_command(
set_cmd + location_type,
@@ -378,9 +346,7 @@ class Lldp_interfaces(ConfigBase):
only_in_have = key_value_in_dict(key, value, want_dict)
if not only_in_have:
commands.append(
- self._compute_command(
- del_cmd + location_type, key, str(value), True
- )
+ self._compute_command(del_cmd + location_type, key, str(value), True)
)
else:
commands.append(self._compute_command(del_cmd, remove=True))
@@ -391,20 +357,14 @@ class Lldp_interfaces(ConfigBase):
if is_dict_element_present(have_location_type, "civic_based"):
have_dict = have_location_type.get("civic_based") or {}
have_ca = have_dict.get("ca_info")
- commands.extend(
- self._update_civic_address(name, want_ca, have_ca)
- )
+ commands.extend(self._update_civic_address(name, want_ca, have_ca))
else:
commands.append(self._compute_command(del_cmd, remove=True))
else:
if is_dict_element_present(have_location_type, "elin"):
- if want_location_type.get("elin") != have_location_type.get(
- "elin"
- ):
- commands.append(
- self._compute_command(del_cmd, remove=True)
- )
+ if want_location_type.get("elin") != have_location_type.get("elin"):
+ commands.append(self._compute_command(del_cmd, remove=True))
else:
commands.append(self._compute_command(del_cmd, remove=True))
return commands
@@ -414,9 +374,7 @@ class Lldp_interfaces(ConfigBase):
for item in want:
ca_type = item["ca_type"]
ca_value = item["ca_value"]
- obj_in_have = search_dict_tv_in_list(
- ca_type, ca_value, have, "ca_type", "ca_value"
- )
+ obj_in_have = search_dict_tv_in_list(ca_type, ca_value, have, "ca_type", "ca_value")
if not obj_in_have:
commands.append(
self._compute_command(
@@ -432,9 +390,7 @@ class Lldp_interfaces(ConfigBase):
for item in have:
ca_type = item["ca_type"]
ca_value = item["ca_value"]
- in_want = search_dict_tv_in_list(
- ca_type, ca_value, want, "ca_type", "ca_value"
- )
+ in_want = search_dict_tv_in_list(ca_type, ca_value, want, "ca_type", "ca_value")
if not in_want:
commands.append(
self._compute_command(
diff --git a/plugins/module_utils/network/vyos/config/logging_global/logging_global.py b/plugins/module_utils/network/vyos/config/logging_global/logging_global.py
index 696090d..27c33b3 100644
--- a/plugins/module_utils/network/vyos/config/logging_global/logging_global.py
+++ b/plugins/module_utils/network/vyos/config/logging_global/logging_global.py
@@ -20,16 +20,15 @@ created.
from copy import deepcopy
from ansible.module_utils.six import iteritems
-from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import (
- dict_merge,
- get_from_dict,
-)
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.ansible.netcommon.plugins.module_utils.network.common.utils import (
+ dict_merge,
+ get_from_dict,
)
+
+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.logging_global import (
Logging_globalTemplate,
)
@@ -173,9 +172,7 @@ class Logging_global(ResourceModule):
temp_param[pk + k] = {
element: {
"facilities": dat,
- self.pkey.get(element): v.get(
- self.pkey.get(element)
- ),
+ self.pkey.get(element): v.get(self.pkey.get(element)),
}
}
del v["facilities"]
@@ -202,19 +199,9 @@ class Logging_global(ResourceModule):
_tem_par = {}
for par in val:
if par.get("facility") and par.get("severity"):
- _tem_par.update(
- {
- par.get("facility")
- + par.get("severity"): par
- }
- )
+ _tem_par.update({par.get("facility") + par.get("severity"): par})
elif par.get("facility") and par.get("protocol"):
- _tem_par.update(
- {
- par.get("facility")
- + par.get("protocol"): par
- }
- )
+ _tem_par.update({par.get("facility") + par.get("protocol"): par})
else:
_tem_par.update({par.get("facility"): par})
return _tem_par
@@ -227,11 +214,7 @@ class Logging_global(ResourceModule):
if v.get("facilities"):
v["facilities"] = self.list_to_dict(v)
if updated_param.get(element):
- updated_param[element].update(
- {v.get(self.pkey.get(element)): v}
- )
+ updated_param[element].update({v.get(self.pkey.get(element)): v})
else:
- updated_param[element] = {
- v.get(self.pkey.get(element)): v
- }
+ updated_param[element] = {v.get(self.pkey.get(element)): v}
return updated_param
diff --git a/plugins/module_utils/network/vyos/config/ntp_global/ntp_global.py b/plugins/module_utils/network/vyos/config/ntp_global/ntp_global.py
index 0a0e389..cd677d4 100644
--- a/plugins/module_utils/network/vyos/config/ntp_global/ntp_global.py
+++ b/plugins/module_utils/network/vyos/config/ntp_global/ntp_global.py
@@ -18,15 +18,14 @@ 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.ansible.netcommon.plugins.module_utils.network.common.utils import (
+ dict_merge,
)
+
+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.ntp_global import (
NtpTemplate,
)
@@ -79,9 +78,7 @@ class Ntp_global(ResourceModule):
# 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
- }
+ haved = {k: v for k, v in iteritems(haved) if k in wantd or not wantd}
wantd = {}
commandlist = self._commandlist(haved)
@@ -92,16 +89,12 @@ class Ntp_global(ResourceModule):
for hk, hval in iteritems(have):
if hk == "allow_clients" and hk in commandlist:
self.commands.append(
- self._tmplt.render(
- {"": hk}, "allow_clients_delete", True
- )
+ self._tmplt.render({"": hk}, "allow_clients_delete", True)
)
commandlist.remove(hk)
elif hk == "listen_addresses" and hk in commandlist:
self.commands.append(
- self._tmplt.render(
- {"": hk}, "listen_addresses_delete", True
- )
+ self._tmplt.render({"": hk}, "listen_addresses_delete", True)
)
commandlist.remove(hk)
elif hk == "server" and have["server"] in servernames:
@@ -170,9 +163,7 @@ class Ntp_global(ResourceModule):
dict = {}
dict.update({"server": entry["server"]})
dict.update({Opk: val})
- serveroptions_dict.update(
- {entry["server"] + "_" + val: dict}
- )
+ serveroptions_dict.update({entry["server"] + "_" + val: dict})
return serveroptions_dict
def _commandlist(self, haved):
diff --git a/plugins/module_utils/network/vyos/config/ospf_interfaces/ospf_interfaces.py b/plugins/module_utils/network/vyos/config/ospf_interfaces/ospf_interfaces.py
index dbdce48..527f062 100644
--- a/plugins/module_utils/network/vyos/config/ospf_interfaces/ospf_interfaces.py
+++ b/plugins/module_utils/network/vyos/config/ospf_interfaces/ospf_interfaces.py
@@ -17,15 +17,14 @@ 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.ansible.netcommon.plugins.module_utils.network.common.utils import (
+ dict_merge,
)
+
+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.ospf_interfaces import (
Ospf_interfacesTemplate,
)
diff --git a/plugins/module_utils/network/vyos/config/ospfv2/ospfv2.py b/plugins/module_utils/network/vyos/config/ospfv2/ospfv2.py
index 059b92d..9287fbc 100644
--- a/plugins/module_utils/network/vyos/config/ospfv2/ospfv2.py
+++ b/plugins/module_utils/network/vyos/config/ospfv2/ospfv2.py
@@ -15,23 +15,22 @@ from __future__ import absolute_import, division, print_function
__metaclass__ = type
from copy import deepcopy
+
+from ansible.module_utils.six import iteritems
from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base import (
ConfigBase,
)
from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import (
- to_list,
remove_empties,
+ to_list,
)
-from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.facts import (
- Facts,
-)
-from ansible.module_utils.six import iteritems
+from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.facts import Facts
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.utils.utils import (
- list_diff_want_only,
+ _bool_to_str,
_in_target,
_is_w_same,
- _bool_to_str,
+ list_diff_want_only,
)
@@ -137,14 +136,9 @@ class Ospfv2(ConfigBase):
"""
commands = []
- if (
- self.state in ("merged", "replaced", "overridden", "rendered")
- and not w
- ):
+ if self.state in ("merged", "replaced", "overridden", "rendered") and not w:
self._module.fail_json(
- msg="value of config parameter must not be empty for state {0}".format(
- self.state
- )
+ msg="value of config parameter must not be empty for state {0}".format(self.state)
)
if self.state == "deleted":
@@ -226,21 +220,11 @@ class Ospfv2(ConfigBase):
if w:
for (key, val) in iteritems(w):
if opr and key in leaf and not _is_w_same(w, have, key):
- commands.append(
- self._form_attr_cmd(
- attr=key, val=_bool_to_str(val), opr=opr
- )
- )
+ commands.append(self._form_attr_cmd(attr=key, val=_bool_to_str(val), opr=opr))
elif not opr and key in leaf and not _in_target(have, key):
- commands.append(
- self._form_attr_cmd(
- attr=key, val=_bool_to_str(val), opr=opr
- )
- )
+ commands.append(self._form_attr_cmd(attr=key, val=_bool_to_str(val), opr=opr))
else:
- commands.extend(
- self._render_child_param(w, have, key, opr)
- )
+ commands.extend(self._render_child_param(w, have, key, opr))
return commands
def _render_child_param(self, w, h, key, opr=True):
@@ -304,11 +288,7 @@ class Ospfv2(ConfigBase):
}
leaf = leaf_dict[attr]
for (item, value) in iteritems(want[attr]):
- if (
- opr
- and item in leaf
- and not _is_w_same(want[attr], h, item)
- ):
+ if opr and item in leaf and not _is_w_same(want[attr], h, item):
if item == "enabled":
item = "enable"
if item in (
@@ -316,26 +296,16 @@ class Ospfv2(ConfigBase):
"enable",
"rfc1583_compatibility",
):
- commands.append(
- self._form_attr_cmd(key=attr, attr=item, opr=opr)
- )
+ commands.append(self._form_attr_cmd(key=attr, attr=item, opr=opr))
else:
commands.append(
- self._form_attr_cmd(
- key=attr, attr=item, val=value, opr=opr
- )
+ self._form_attr_cmd(key=attr, attr=item, val=value, opr=opr)
)
elif not opr and item in leaf and not _in_target(h, item):
if item == "enabled":
- commands.append(
- self._form_attr_cmd(
- key=attr, attr="enable", opr=opr
- )
- )
+ commands.append(self._form_attr_cmd(key=attr, attr="enable", opr=opr))
else:
- commands.append(
- self._form_attr_cmd(key=attr, attr=item, opr=opr)
- )
+ commands.append(self._form_attr_cmd(key=attr, attr=item, opr=opr))
return commands
def _render_list_param(self, attr, want, have, cmd=None, opr=True):
@@ -371,19 +341,12 @@ class Ospfv2(ConfigBase):
if h:
for member in w:
if attr == "network":
- if not self.search_obj_in_have(
- h, member, "address"
- ):
+ if not self.search_obj_in_have(h, member, "address"):
commands.append(
- cmd
- + attr.replace("_", "-")
- + " "
- + member["address"]
+ cmd + attr.replace("_", "-") + " " + member["address"]
)
elif member not in h:
- commands.append(
- cmd + attr.replace("_", "-") + " " + member
- )
+ commands.append(cmd + attr.replace("_", "-") + " " + member)
else:
commands.append(cmd + " " + attr.replace("_", "-"))
return commands
@@ -424,15 +387,9 @@ class Ospfv2(ConfigBase):
if not cmd:
cmd = self._compute_command(opr=opr)
h_item = self.search_obj_in_have(h, w_item, name[attr])
- if (
- opr
- and key in leaf
- and not _is_w_same(w_item, h_item, key)
- ):
+ if opr and key in leaf and not _is_w_same(w_item, h_item, key):
if key in "address":
- commands.append(
- cmd + attr.replace("_", "-") + " " + str(val)
- )
+ commands.append(cmd + attr.replace("_", "-") + " " + str(val))
else:
commands.append(
cmd
@@ -444,21 +401,12 @@ class Ospfv2(ConfigBase):
+ " "
+ str(val)
)
- elif (
- not opr and key in leaf and not _in_target(h_item, key)
- ):
+ elif not opr and key in leaf and not _in_target(h_item, key):
if key in "address":
- commands.append(
- cmd + attr.replace("_", "-") + " " + str(val)
- )
+ commands.append(cmd + attr.replace("_", "-") + " " + str(val))
else:
commands.append(
- cmd
- + attr.replace("_", "-")
- + " "
- + w_item[name[attr]]
- + " "
- + key
+ cmd + attr.replace("_", "-") + " " + w_item[name[attr]] + " " + key
)
elif key == "authentication":
commands.extend(
@@ -474,9 +422,7 @@ class Ospfv2(ConfigBase):
)
return commands
- def _render_vlink_auth(
- self, attr, key, want, have, address, cmd=None, opr=True
- ):
+ def _render_vlink_auth(self, attr, key, want, have, address, cmd=None, opr=True):
"""
This function forms the set/delete commands based on the 'opr' type
for attributes with in desired list of dictionary.
@@ -549,11 +495,7 @@ class Ospfv2(ConfigBase):
if not cmd:
cmd = self._compute_command(opr=opr)
h_item = self.search_obj_in_have(h, w_item, name[attr])
- if (
- opr
- and key in leaf
- and not _is_w_same(w_item, h_item, key)
- ):
+ if opr and key in leaf and not _is_w_same(w_item, h_item, key):
if key in (
"route_type",
"neighbor_id",
@@ -563,23 +505,11 @@ class Ospfv2(ConfigBase):
commands.append(cmd + attr + " " + str(val))
elif key == "cost":
commands.append(
- cmd
- + attr
- + " "
- + w_item[name[attr]]
- + " "
- + key
- + " "
- + str(val)
+ cmd + attr + " " + w_item[name[attr]] + " " + key + " " + str(val)
)
elif key == "not_advertise":
commands.append(
- cmd
- + attr
- + " "
- + w_item[name[attr]]
- + " "
- + key.replace("_", "-")
+ cmd + attr + " " + w_item[name[attr]] + " " + key.replace("_", "-")
)
elif key == "md5_key":
commands.append(
@@ -605,9 +535,7 @@ class Ospfv2(ConfigBase):
+ " "
+ str(val)
)
- elif (
- not opr and key in leaf and not _in_target(h_item, key)
- ):
+ elif not opr and key in leaf and not _in_target(h_item, key):
if key in (
"route_type",
"neighbor_id",
@@ -616,14 +544,7 @@ class Ospfv2(ConfigBase):
):
commands.append(cmd + attr + " " + str(val))
else:
- commands.append(
- cmd
- + attr
- + " "
- + w_item[name[attr]]
- + " "
- + key
- )
+ commands.append(cmd + attr + " " + w_item[name[attr]] + " " + key)
return commands
def _render_nested_dict_param(self, attr, want, have, opr=True):
@@ -668,11 +589,7 @@ class Ospfv2(ConfigBase):
if h and key in h.keys():
h_attrib = h.get(key) or {}
for (item, val) in iteritems(w[key]):
- if (
- opr
- and item in leaf
- and not _is_w_same(w[key], h_attrib, item)
- ):
+ if opr and item in leaf and not _is_w_same(w[key], h_attrib, item):
if item in ("administrative", "always") and val:
commands.append(
cmd
@@ -693,11 +610,7 @@ class Ospfv2(ConfigBase):
+ " "
+ str(val)
)
- elif (
- not opr
- and item in leaf
- and not _in_target(h_attrib, item)
- ):
+ elif not opr and item in leaf and not _in_target(h_attrib, item):
commands.append(cmd + attr + " " + item)
return commands
@@ -734,17 +647,11 @@ class Ospfv2(ConfigBase):
h_area = self.search_obj_in_have(h_lst, w_area, "area_id")
if not opr and not h_area:
commands.append(
- self._form_attr_cmd(
- key="area", attr=w_area["area_id"], opr=opr
- )
+ self._form_attr_cmd(key="area", attr=w_area["area_id"], opr=opr)
)
else:
for (key, val) in iteritems(w_area):
- if (
- opr
- and key in l_set
- and not _is_w_same(w_area, h_area, key)
- ):
+ if opr and key in l_set and not _is_w_same(w_area, h_area, key):
if key == "area_id":
commands.append(
self._form_attr_cmd(
@@ -755,45 +662,24 @@ class Ospfv2(ConfigBase):
)
else:
commands.append(
- cmd
- + key
- + " "
- + _bool_to_str(val).replace("_", "-")
+ cmd + key + " " + _bool_to_str(val).replace("_", "-")
)
elif not opr and key in l_set:
- if key == "area_id" and not _in_target(
- h_area, key
- ):
+ if key == "area_id" and not _in_target(h_area, key):
commands.append(cmd)
continue
- if key != "area_id" and not _in_target(
- h_area, key
- ):
+ if key != "area_id" and not _in_target(h_area, key):
commands.append(cmd + val + " " + key)
elif key == "area_type":
- commands.extend(
- self._render_area_type(
- w_area, h_area, key, cmd, opr
- )
- )
+ commands.extend(self._render_area_type(w_area, h_area, key, cmd, opr))
elif key == "network":
- commands.extend(
- self._render_list_param(
- key, w_area, h_area, cmd, opr
- )
- )
+ commands.extend(self._render_list_param(key, w_area, h_area, cmd, opr))
elif key == "range":
commands.extend(
- self._render_list_dict_param(
- key, w_area, h_area, cmd, opr
- )
+ self._render_list_dict_param(key, w_area, h_area, cmd, opr)
)
elif key == "virtual_link":
- commands.extend(
- self._render_vlink(
- key, w_area, h_area, cmd, opr
- )
- )
+ commands.extend(self._render_vlink(key, w_area, h_area, cmd, opr))
return commands
def _render_area_type(self, want, have, attr, cmd, opr=True):
@@ -817,28 +703,15 @@ class Ospfv2(ConfigBase):
commands.append(cmd + attr.replace("_", "-"))
elif w_type:
key = "normal"
- if (
- opr
- and key in w_type.keys()
- and not _is_w_same(w_type, h_type, key)
- ):
+ if opr and key in w_type.keys() and not _is_w_same(w_type, h_type, key):
if not w_type[key] and h_type and h_type[key]:
commands.append(
- cmd.replace("set", "delete")
- + attr.replace("_", "-")
- + " "
- + key
+ cmd.replace("set", "delete") + attr.replace("_", "-") + " " + key
)
elif w_type[key]:
commands.append(cmd + attr.replace("_", "-") + " " + key)
- elif (
- not opr
- and key in w_type.keys()
- and not (h_type and key in h_type.keys())
- ):
- commands.append(
- cmd + want["area"] + " " + attr.replace("_", "-")
- )
+ elif not opr and key in w_type.keys() and not (h_type and key in h_type.keys()):
+ commands.append(cmd + want["area"] + " " + attr.replace("_", "-"))
a_type = {
"nssa": ("set", "default_cost", "no_summary", "translate"),
@@ -857,9 +730,7 @@ class Ospfv2(ConfigBase):
and not _is_w_same(w_type[key], h_area, item)
):
if item == "set" and val:
- commands.append(
- cmd + attr.replace("_", "-") + " " + key
- )
+ commands.append(cmd + attr.replace("_", "-") + " " + key)
elif not val and h_area and h_area[item]:
commands.append(
cmd.replace("set", "delete")
@@ -878,15 +749,9 @@ class Ospfv2(ConfigBase):
+ " "
+ str(val)
)
- elif (
- not opr
- and item in a_type[key]
- and not (h_type and key in h_type)
- ):
+ elif not opr and item in a_type[key] and not (h_type and key in h_type):
if item == "set":
- commands.append(
- cmd + attr.replace("_", "-") + " " + key
- )
+ commands.append(cmd + attr.replace("_", "-") + " " + key)
else:
commands.append(
cmd
@@ -910,13 +775,9 @@ class Ospfv2(ConfigBase):
:return: generated command.
"""
- return self._compute_command(
- key, attr=self._map_attrib(attr), val=val, opr=opr
- )
+ return self._compute_command(key, attr=self._map_attrib(attr), val=val, opr=opr)
- def _compute_command(
- self, key=None, attr=None, val=None, remove=False, opr=True
- ):
+ def _compute_command(self, key=None, attr=None, val=None, remove=False, opr=True):
"""
This function construct the add/delete command based on passed attributes.
:param key: parent key.
diff --git a/plugins/module_utils/network/vyos/config/ospfv3/ospfv3.py b/plugins/module_utils/network/vyos/config/ospfv3/ospfv3.py
index c43dfe7..abafc90 100644
--- a/plugins/module_utils/network/vyos/config/ospfv3/ospfv3.py
+++ b/plugins/module_utils/network/vyos/config/ospfv3/ospfv3.py
@@ -15,23 +15,22 @@ from __future__ import absolute_import, division, print_function
__metaclass__ = type
from copy import deepcopy
+
+from ansible.module_utils.six import iteritems
from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base import (
ConfigBase,
)
from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import (
- to_list,
remove_empties,
search_obj_in_list,
+ to_list,
)
-from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.facts import (
- Facts,
-)
-from ansible.module_utils.six import iteritems
+from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.facts import Facts
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.utils.utils import (
+ _bool_to_str,
_in_target,
_is_w_same,
- _bool_to_str,
)
@@ -137,14 +136,9 @@ class Ospfv3(ConfigBase):
to the desired configuration
"""
commands = []
- if (
- self.state in ("merged", "replaced", "overridden", "rendered")
- and not w
- ):
+ if self.state in ("merged", "replaced", "overridden", "rendered") and not w:
self._module.fail_json(
- msg="value of config parameter must not be empty for state {0}".format(
- self.state
- )
+ msg="value of config parameter must not be empty for state {0}".format(self.state)
)
if self.state == "deleted":
commands.extend(self._state_deleted(w, h))
@@ -245,20 +239,10 @@ class Ospfv3(ConfigBase):
leaf_dict = {"parameters": "router_id"}
leaf = leaf_dict[attr]
for item, value in iteritems(want[attr]):
- if (
- opr
- and item in leaf
- and not _is_w_same(want[attr], h, item)
- ):
- commands.append(
- self._form_attr_cmd(
- key=attr, attr=item, val=value, opr=opr
- )
- )
+ if opr and item in leaf and not _is_w_same(want[attr], h, item):
+ commands.append(self._form_attr_cmd(key=attr, attr=item, val=value, opr=opr))
elif not opr and item in leaf and not _in_target(h, item):
- commands.append(
- self._form_attr_cmd(key=attr, attr=item, opr=opr)
- )
+ commands.append(self._form_attr_cmd(key=attr, attr=item, opr=opr))
return commands
def _render_list_dict_param(self, attr, want, have, cmd=None, opr=True):
@@ -293,14 +277,8 @@ class Ospfv3(ConfigBase):
for key, val in iteritems(w_item):
if not cmd:
cmd = self._compute_command(opr=opr)
- h_item = search_obj_in_list(
- w_item[name[attr]], h, name[attr]
- )
- if (
- opr
- and key in leaf
- and not _is_w_same(w_item, h_item, key)
- ):
+ h_item = search_obj_in_list(w_item[name[attr]], h, name[attr])
+ if opr and key in leaf and not _is_w_same(w_item, h_item, key):
if key == "route_type" or (
key == "address"
and "advertise" not in w_item
@@ -311,12 +289,7 @@ class Ospfv3(ConfigBase):
commands.append(cmd + attr + " " + str(val))
elif key in leaf_dict["range"] and key != "address":
commands.append(
- cmd
- + attr
- + " "
- + w_item[name[attr]]
- + " "
- + key.replace("_", "-")
+ cmd + attr + " " + w_item[name[attr]] + " " + key.replace("_", "-")
)
elif key == "route_map":
commands.append(
@@ -329,16 +302,11 @@ class Ospfv3(ConfigBase):
+ " "
+ str(val)
)
- elif (
- not opr and key in leaf and not _in_target(h_item, key)
- ):
+ elif not opr and key in leaf and not _in_target(h_item, key):
if key in ("route_type", "address"):
commands.append(cmd + attr + " " + str(val))
else:
- commands.append(
- cmd
- + (attr + " " + w_item[name[attr]] + " " + key)
- )
+ commands.append(cmd + (attr + " " + w_item[name[attr]] + " " + key))
return commands
def _render_areas(self, attr, want, have, opr=True):
@@ -369,22 +337,14 @@ class Ospfv3(ConfigBase):
)
+ " "
)
- h_area = search_obj_in_list(
- w_area["area_id"], h_lst, "area_id"
- )
+ h_area = search_obj_in_list(w_area["area_id"], h_lst, "area_id")
if not opr and not h_area:
commands.append(
- self._form_attr_cmd(
- key="area", attr=w_area["area_id"], opr=opr
- )
+ self._form_attr_cmd(key="area", attr=w_area["area_id"], opr=opr)
)
else:
for key, val in iteritems(w_area):
- if (
- opr
- and key in l_set
- and not _is_w_same(w_area, h_area, key)
- ):
+ if opr and key in l_set and not _is_w_same(w_area, h_area, key):
if key == "area_id":
commands.append(
self._form_attr_cmd(
@@ -401,20 +361,14 @@ class Ospfv3(ConfigBase):
+ _bool_to_str(val).replace("_", "-")
)
elif not opr and key in l_set:
- if key == "area_id" and not _in_target(
- h_area, key
- ):
+ if key == "area_id" and not _in_target(h_area, key):
commands.append(cmd)
continue
- if key != "area_id" and not _in_target(
- h_area, key
- ):
+ if key != "area_id" and not _in_target(h_area, key):
commands.append(cmd + val + " " + key)
elif key == "range":
commands.extend(
- self._render_list_dict_param(
- key, w_area, h_area, cmd, opr
- )
+ self._render_list_dict_param(key, w_area, h_area, cmd, opr)
)
return commands
@@ -427,13 +381,9 @@ class Ospfv3(ConfigBase):
:param opr: True/False.
:return: generated command.
"""
- return self._compute_command(
- key, attr=self._map_attrib(attr), val=val, opr=opr
- )
+ return self._compute_command(key, attr=self._map_attrib(attr), val=val, opr=opr)
- def _compute_command(
- self, key=None, attr=None, val=None, remove=False, opr=True
- ):
+ def _compute_command(self, key=None, attr=None, val=None, remove=False, opr=True):
"""
This function construct the add/delete command based on passed attributes.
:param key: parent key.
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
index b2c119d..a8cc69e 100644
--- a/plugins/module_utils/network/vyos/config/prefix_lists/prefix_lists.py
+++ b/plugins/module_utils/network/vyos/config/prefix_lists/prefix_lists.py
@@ -19,15 +19,14 @@ 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.ansible.netcommon.plugins.module_utils.network.common.utils import (
+ dict_merge,
)
+
+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,
)
@@ -86,18 +85,14 @@ class Prefix_lists(ResourceModule):
# 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
- }
+ 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
+ k: v for k, v in iteritems(hplists) if k in wplists or not wplists
}
# remove superfluous config for overridden and deleted
@@ -174,9 +169,5 @@ class Prefix_lists(ResourceModule):
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"]
- }
+ 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/config/route_maps/route_maps.py b/plugins/module_utils/network/vyos/config/route_maps/route_maps.py
index c719e6d..dd6fbf6 100644
--- a/plugins/module_utils/network/vyos/config/route_maps/route_maps.py
+++ b/plugins/module_utils/network/vyos/config/route_maps/route_maps.py
@@ -19,15 +19,14 @@ 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.ansible.netcommon.plugins.module_utils.network.common.utils import (
+ dict_merge,
)
+
+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.route_maps import (
Route_mapsTemplate,
)
@@ -116,18 +115,14 @@ class Route_maps(ResourceModule):
# 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
- }
+ haved = {k: v for k, v in iteritems(haved) if k in wantd or not wantd}
wantd = {}
# 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.commands.append(
- self._tmplt.render({"route_map": k}, "route_map", True)
- )
+ self.commands.append(self._tmplt.render({"route_map": k}, "route_map", True))
for wk, want in iteritems(wantd):
self._compare(want=want, have=haved.pop(wk, {}))
@@ -154,7 +149,6 @@ class Route_maps(ResourceModule):
for x in data["entries"]:
x.update({"route_map": rmap})
data["entries"] = {
- (rmap, entry.get("sequence")): entry
- for entry in data["entries"]
+ (rmap, entry.get("sequence")): entry for entry in data["entries"]
}
return entry
diff --git a/plugins/module_utils/network/vyos/config/snmp_server/snmp_server.py b/plugins/module_utils/network/vyos/config/snmp_server/snmp_server.py
index 5ddd429..b942f8b 100644
--- a/plugins/module_utils/network/vyos/config/snmp_server/snmp_server.py
+++ b/plugins/module_utils/network/vyos/config/snmp_server/snmp_server.py
@@ -17,23 +17,21 @@ necessary to bring the current configuration to its desired end-state is
created.
"""
+import re
+
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.ansible.netcommon.plugins.module_utils.network.common.utils import (
+ dict_merge,
+ get_from_dict,
)
+
+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.snmp_server import (
Snmp_serverTemplate,
)
-from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import (
- get_from_dict,
-)
-import re
class Snmp_server(ResourceModule):
@@ -164,9 +162,7 @@ class Snmp_server(ResourceModule):
want={},
)
else:
- self.compare(
- parsers=parsers, want={}, have={attrib: entry}
- )
+ self.compare(parsers=parsers, want={}, have={attrib: entry})
def _compare_snmp_v3(self, want, have):
parsers = [
@@ -192,9 +188,7 @@ class Snmp_server(ResourceModule):
wattrib = get_from_dict(wdict, attrib) or {}
hattrib = get_from_dict(hdict, attrib) or {}
for key, entry in iteritems(wattrib):
- self._compare_snmp_v3_auth_privacy(
- entry, hattrib.get(key, {}), attrib
- )
+ self._compare_snmp_v3_auth_privacy(entry, hattrib.get(key, {}), attrib)
for k, v in iteritems(entry):
if k != attribute_dict[attrib]:
h = {}
@@ -215,9 +209,7 @@ class Snmp_server(ResourceModule):
"snmp_v3": {
attrib: {
k: v,
- attribute_dict[attrib]: entry[
- attribute_dict[attrib]
- ],
+ attribute_dict[attrib]: entry[attribute_dict[attrib]],
}
}
},
@@ -226,9 +218,7 @@ class Snmp_server(ResourceModule):
# remove remaining items in have for replaced
for key, entry in iteritems(hattrib):
self._compare_snmp_v3_auth_privacy({}, entry, attrib)
- self.compare(
- parsers=parsers, want={}, have={"snmp_v3": {attrib: entry}}
- )
+ self.compare(parsers=parsers, want={}, have={"snmp_v3": {attrib: entry}})
hdict.pop(attrib, {})
for key, entry in iteritems(wdict):
# self.addcmd(entry, attrib, False)
@@ -239,9 +229,7 @@ class Snmp_server(ResourceModule):
)
# remove remaining items in have for replaced
for key, entry in iteritems(hdict):
- self.compare(
- parsers=parsers, want={}, have={"snmp_v3": {key: entry}}
- )
+ self.compare(parsers=parsers, want={}, have={"snmp_v3": {key: entry}})
def _compare_snmp_v3_auth_privacy(self, wattrib, hattrib, attrib):
parsers = [
diff --git a/plugins/module_utils/network/vyos/config/static_routes/static_routes.py b/plugins/module_utils/network/vyos/config/static_routes/static_routes.py
index bd7fd15..230a47c 100644
--- a/plugins/module_utils/network/vyos/config/static_routes/static_routes.py
+++ b/plugins/module_utils/network/vyos/config/static_routes/static_routes.py
@@ -15,23 +15,23 @@ from __future__ import absolute_import, division, print_function
__metaclass__ = type
from copy import deepcopy
+
+from ansible.module_utils.six import iteritems
from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base import (
ConfigBase,
)
from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import (
- to_list,
dict_diff,
remove_empties,
+ to_list,
)
-from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.facts import (
- Facts,
-)
-from ansible.module_utils.six import iteritems
+
+from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.facts import Facts
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.utils.utils import (
- get_route_type,
+ dict_delete,
get_lst_diff_for_dicts,
get_lst_same_for_dicts,
- dict_delete,
+ get_route_type,
)
@@ -56,9 +56,7 @@ class Static_routes(ConfigBase):
facts, _warnings = Facts(self._module).get_facts(
self.gather_subset, self.gather_network_resources, data=data
)
- static_routes_facts = facts["ansible_network_resources"].get(
- "static_routes"
- )
+ static_routes_facts = facts["ansible_network_resources"].get("static_routes")
if not static_routes_facts:
return []
return static_routes_facts
@@ -99,9 +97,7 @@ class Static_routes(ConfigBase):
self._module.fail_json(
msg="value of running_config parameter must not be empty for state parsed"
)
- result["parsed"] = self.get_static_routes_facts(
- data=running_config
- )
+ result["parsed"] = self.get_static_routes_facts(data=running_config)
else:
changed_static_routes_facts = []
@@ -138,14 +134,9 @@ class Static_routes(ConfigBase):
to the desired configuration
"""
commands = []
- if (
- self.state in ("merged", "replaced", "overridden", "rendered")
- and not want
- ):
+ if self.state in ("merged", "replaced", "overridden", "rendered") and not want:
self._module.fail_json(
- msg="value of config parameter must not be empty for state {0}".format(
- self.state
- )
+ msg="value of config parameter must not be empty for state {0}".format(self.state)
)
if self.state == "overridden":
commands.extend(self._state_overridden(want=want, have=have))
@@ -189,9 +180,7 @@ class Static_routes(ConfigBase):
if key == "next_hops":
commands.extend(self._update_next_hop(want, have))
elif key == "blackhole_config":
- commands.extend(
- self._update_blackhole(key, want, have)
- )
+ commands.extend(self._update_blackhole(key, want, have))
commands.extend(self._state_merged(want, have))
return commands
@@ -243,11 +232,7 @@ class Static_routes(ConfigBase):
af = w["address_families"]
for item in af:
if self.afi_in_have(have, item):
- commands.append(
- self._compute_command(
- afi=item["afi"], remove=True
- )
- )
+ commands.append(self._compute_command(afi=item["afi"], remove=True))
else:
routes = self._get_routes(have)
if self._is_ip_route_exist(routes):
@@ -308,11 +293,7 @@ class Static_routes(ConfigBase):
)
)
elif attrib == "type":
- commands.append(
- self._compute_command(
- dest=want["dest"], key="blackhole"
- )
- )
+ commands.append(self._compute_command(dest=want["dest"], key="blackhole"))
return commands
def _add_next_hop(self, want, have, opr=True):
@@ -327,13 +308,9 @@ class Static_routes(ConfigBase):
want_copy = deepcopy(remove_empties(want))
have_copy = deepcopy(remove_empties(have))
if not opr:
- diff_next_hops = get_lst_same_for_dicts(
- want_copy, have_copy, "next_hops"
- )
+ diff_next_hops = get_lst_same_for_dicts(want_copy, have_copy, "next_hops")
else:
- diff_next_hops = get_lst_diff_for_dicts(
- want_copy, have_copy, "next_hops"
- )
+ diff_next_hops = get_lst_diff_for_dicts(want_copy, have_copy, "next_hops")
if diff_next_hops:
for hop in diff_next_hops:
for element in hop:
@@ -361,9 +338,7 @@ class Static_routes(ConfigBase):
self._compute_command(
dest=want["dest"],
key="next-hop",
- attrib=hop["forward_router_address"]
- + " "
- + "distance",
+ attrib=hop["forward_router_address"] + " " + "distance",
value=str(hop[element]),
opr=opr,
)
@@ -373,9 +348,7 @@ class Static_routes(ConfigBase):
self._compute_command(
dest=want["dest"],
key="next-hop",
- attrib=hop["forward_router_address"]
- + " "
- + "next-hop-interface",
+ attrib=hop["forward_router_address"] + " " + "next-hop-interface",
value=hop[element],
opr=opr,
)
@@ -414,14 +387,9 @@ class Static_routes(ConfigBase):
value=str(value),
)
)
- elif (
- attrib == "type"
- and "distance" not in want_blackhole.keys()
- ):
+ elif attrib == "type" and "distance" not in want_blackhole.keys():
commands.append(
- self._compute_command(
- dest=want["dest"], key="blackhole", remove=True
- )
+ self._compute_command(dest=want["dest"], key="blackhole", remove=True)
)
return commands
@@ -438,9 +406,7 @@ class Static_routes(ConfigBase):
want_copy = deepcopy(remove_empties(want))
have_copy = deepcopy(remove_empties(have))
- diff_next_hops = get_lst_diff_for_dicts(
- have_copy, want_copy, "next_hops"
- )
+ diff_next_hops = get_lst_diff_for_dicts(have_copy, want_copy, "next_hops")
if diff_next_hops:
for hop in diff_next_hops:
for element in hop:
@@ -468,9 +434,7 @@ class Static_routes(ConfigBase):
self._compute_command(
dest=want["dest"],
key="next-hop",
- attrib=hop["forward_router_address"]
- + " "
- + "distance",
+ attrib=hop["forward_router_address"] + " " + "distance",
value=str(hop[element]),
remove=True,
)
@@ -480,9 +444,7 @@ class Static_routes(ConfigBase):
self._compute_command(
dest=want["dest"],
key="next-hop",
- attrib=hop["forward_router_address"]
- + " "
- + "next-hop-interface",
+ attrib=hop["forward_router_address"] + " " + "next-hop-interface",
value=hop[element],
remove=True,
)
@@ -502,9 +464,7 @@ class Static_routes(ConfigBase):
want_nh = want.get("next_hops") or []
# delete static route operation per destination
if not opr and not want_nh:
- commands.append(
- self._compute_command(dest=want["dest"], remove=True)
- )
+ commands.append(self._compute_command(dest=want["dest"], remove=True))
else:
temp_have_next_hops = have.pop("next_hops", None)
@@ -520,9 +480,7 @@ class Static_routes(ConfigBase):
for key, value in iteritems(updates):
if value:
if key == "blackhole_config":
- commands.extend(
- self._add_blackhole(key, want, have)
- )
+ commands.extend(self._add_blackhole(key, want, have))
return commands
def _compute_command(
diff --git a/plugins/module_utils/network/vyos/facts/bgp_address_family/bgp_address_family.py b/plugins/module_utils/network/vyos/facts/bgp_address_family/bgp_address_family.py
index a7296f2..5d60184 100644
--- a/plugins/module_utils/network/vyos/facts/bgp_address_family/bgp_address_family.py
+++ b/plugins/module_utils/network/vyos/facts/bgp_address_family/bgp_address_family.py
@@ -15,15 +15,15 @@ based on the configuration.
"""
import re
-from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import (
- utils,
+
+from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import utils
+
+from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.bgp_address_family.bgp_address_family import (
+ Bgp_address_familyArgs,
)
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.rm_templates.bgp_address_family import (
Bgp_address_familyTemplate,
)
-from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.bgp_address_family.bgp_address_family import (
- Bgp_address_familyArgs,
-)
class Bgp_address_familyFacts(object):
@@ -34,9 +34,7 @@ class Bgp_address_familyFacts(object):
self.argument_spec = Bgp_address_familyArgs.argument_spec
def get_device_data(self, connection):
- return connection.get(
- 'show configuration commands | match "set protocols bgp"'
- )
+ return connection.get('show configuration commands | match "set protocols bgp"')
def populate_facts(self, connection, ansible_facts, data=None):
"""Populate the facts for Bgp_address_family network resource
@@ -60,40 +58,28 @@ class Bgp_address_familyFacts(object):
config_lines.append(re.sub("'", "", resource))
# parse native config using the Bgp_address_family template
- bgp_address_family_parser = Bgp_address_familyTemplate(
- lines=config_lines
- )
+ bgp_address_family_parser = Bgp_address_familyTemplate(lines=config_lines)
objs = bgp_address_family_parser.parse()
if objs:
if "address_family" in objs:
objs["address_family"] = list(objs["address_family"].values())
for af in objs["address_family"]:
if "networks" in af:
- af["networks"] = sorted(
- af["networks"], key=lambda k: k["prefix"]
- )
+ af["networks"] = sorted(af["networks"], key=lambda k: k["prefix"])
if "aggregate_address" in af:
af["aggregate_address"] = sorted(
af["aggregate_address"], key=lambda k: k["prefix"]
)
if "neighbors" in objs:
objs["neighbors"] = list(objs["neighbors"].values())
- objs["neighbors"] = sorted(
- objs["neighbors"], key=lambda k: k["neighbor_address"]
- )
+ objs["neighbors"] = sorted(objs["neighbors"], key=lambda k: k["neighbor_address"])
for neigh in objs["neighbors"]:
if "address_family" in neigh:
- neigh["address_family"] = list(
- neigh["address_family"].values()
- )
+ neigh["address_family"] = list(neigh["address_family"].values())
- ansible_facts["ansible_network_resources"].pop(
- "bgp_address_family", None
- )
+ ansible_facts["ansible_network_resources"].pop("bgp_address_family", None)
- params = utils.remove_empties(
- utils.validate_config(self.argument_spec, {"config": objs})
- )
+ params = utils.remove_empties(utils.validate_config(self.argument_spec, {"config": objs}))
facts["bgp_address_family"] = params.get("config", [])
ansible_facts["ansible_network_resources"].update(facts)
diff --git a/plugins/module_utils/network/vyos/facts/bgp_global/bgp_global.py b/plugins/module_utils/network/vyos/facts/bgp_global/bgp_global.py
index 1efd877..c6105a0 100644
--- a/plugins/module_utils/network/vyos/facts/bgp_global/bgp_global.py
+++ b/plugins/module_utils/network/vyos/facts/bgp_global/bgp_global.py
@@ -14,16 +14,16 @@ 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,
+import re
+
+from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import utils
+
+from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.bgp_global.bgp_global import (
+ Bgp_globalArgs,
)
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.rm_templates.bgp_global import (
Bgp_globalTemplate,
)
-from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.bgp_global.bgp_global import (
- Bgp_globalArgs,
-)
-import re
class Bgp_globalFacts(object):
@@ -34,9 +34,7 @@ class Bgp_globalFacts(object):
self.argument_spec = Bgp_globalArgs.argument_spec
def get_device_data(self, connection):
- return connection.get(
- 'show configuration commands | match "set protocols bgp"'
- )
+ return connection.get('show configuration commands | match "set protocols bgp"')
def populate_facts(self, connection, ansible_facts, data=None):
"""Populate the facts for Bgp_global network resource
@@ -59,31 +57,21 @@ class Bgp_globalFacts(object):
if "address-family" not in resource:
config_lines.append(re.sub("'", "", resource))
- bgp_global_parser = Bgp_globalTemplate(
- lines=config_lines, module=self._module
- )
+ bgp_global_parser = Bgp_globalTemplate(lines=config_lines, module=self._module)
objs = bgp_global_parser.parse()
if "neighbor" in objs:
objs["neighbor"] = list(objs["neighbor"].values())
- objs["neighbor"] = sorted(
- objs["neighbor"], key=lambda k: k["address"]
- )
+ objs["neighbor"] = sorted(objs["neighbor"], key=lambda k: k["address"])
if "network" in objs:
- objs["network"] = sorted(
- objs["network"], key=lambda k: k["address"]
- )
+ objs["network"] = sorted(objs["network"], key=lambda k: k["address"])
if "aggregate_address" in objs:
- objs["aggregate_address"] = sorted(
- objs["aggregate_address"], key=lambda k: k["prefix"]
- )
+ objs["aggregate_address"] = sorted(objs["aggregate_address"], key=lambda k: k["prefix"])
ansible_facts["ansible_network_resources"].pop("bgp_global", None)
params = utils.remove_empties(
- bgp_global_parser.validate_config(
- self.argument_spec, {"config": objs}, redact=True
- )
+ bgp_global_parser.validate_config(self.argument_spec, {"config": objs}, redact=True)
)
facts["bgp_global"] = params.get("config", [])
diff --git a/plugins/module_utils/network/vyos/facts/facts.py b/plugins/module_utils/network/vyos/facts/facts.py
index 867c427..f7b2b4e 100644
--- a/plugins/module_utils/network/vyos/facts/facts.py
+++ b/plugins/module_utils/network/vyos/facts/facts.py
@@ -13,6 +13,25 @@ __metaclass__ = type
from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.facts.facts import (
FactsBase,
)
+
+from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.bgp_address_family.bgp_address_family import (
+ Bgp_address_familyFacts,
+)
+from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.bgp_global.bgp_global import (
+ Bgp_globalFacts,
+)
+from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.firewall_global.firewall_global import (
+ Firewall_globalFacts,
+)
+from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.firewall_interfaces.firewall_interfaces import (
+ Firewall_interfacesFacts,
+)
+from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.firewall_rules.firewall_rules import (
+ Firewall_rulesFacts,
+)
+from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.hostname.hostname import (
+ HostnameFacts,
+)
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.interfaces.interfaces import (
InterfacesFacts,
)
@@ -22,64 +41,45 @@ from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.l3_in
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.lag_interfaces.lag_interfaces import (
Lag_interfacesFacts,
)
+from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.legacy.base import (
+ Config,
+ Default,
+ Neighbors,
+)
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.lldp_global.lldp_global import (
Lldp_globalFacts,
)
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.lldp_interfaces.lldp_interfaces import (
Lldp_interfacesFacts,
)
-from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.firewall_rules.firewall_rules import (
- Firewall_rulesFacts,
-)
-from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.static_routes.static_routes import (
- Static_routesFacts,
-)
-from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.firewall_global.firewall_global import (
- Firewall_globalFacts,
-)
-from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.firewall_interfaces.firewall_interfaces import (
- Firewall_interfacesFacts,
-)
-from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.ospfv3.ospfv3 import (
- Ospfv3Facts,
+from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.logging_global.logging_global import (
+ Logging_globalFacts,
)
-from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.ospfv2.ospfv2 import (
- Ospfv2Facts,
+from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.ntp_global.ntp_global import (
+ Ntp_globalFacts,
)
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.ospf_interfaces.ospf_interfaces import (
Ospf_interfacesFacts,
)
-from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.bgp_global.bgp_global import (
- Bgp_globalFacts,
-)
-from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.bgp_address_family.bgp_address_family import (
- Bgp_address_familyFacts,
+from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.ospfv2.ospfv2 import (
+ Ospfv2Facts,
)
-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.ospfv3.ospfv3 import (
+ Ospfv3Facts,
)
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.logging_global.logging_global import (
- Logging_globalFacts,
-)
-from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.ntp_global.ntp_global import (
- Ntp_globalFacts,
+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.snmp_server.snmp_server import (
Snmp_serverFacts,
)
-from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.hostname.hostname import (
- HostnameFacts,
-)
-from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.legacy.base import (
- Default,
- Neighbors,
- Config,
+from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.static_routes.static_routes import (
+ Static_routesFacts,
)
-
FACT_LEGACY_SUBSETS = dict(default=Default, neighbors=Neighbors, config=Config)
FACT_RESOURCE_SUBSETS = dict(
interfaces=InterfacesFacts,
@@ -114,9 +114,7 @@ class Facts(FactsBase):
def __init__(self, module):
super(Facts, self).__init__(module)
- def get_facts(
- self, legacy_facts_type=None, resource_facts_type=None, data=None
- ):
+ def get_facts(self, legacy_facts_type=None, resource_facts_type=None, data=None):
"""Collect the facts for vyos
:param legacy_facts_type: List of legacy facts types
:param resource_facts_type: List of resource fact types
@@ -125,11 +123,7 @@ class Facts(FactsBase):
:return: the facts gathered
"""
if self.VALID_RESOURCE_SUBSETS:
- self.get_network_resources_facts(
- FACT_RESOURCE_SUBSETS, resource_facts_type, data
- )
+ self.get_network_resources_facts(FACT_RESOURCE_SUBSETS, resource_facts_type, data)
if self.VALID_LEGACY_GATHER_SUBSETS:
- self.get_network_legacy_facts(
- FACT_LEGACY_SUBSETS, legacy_facts_type
- )
+ self.get_network_legacy_facts(FACT_LEGACY_SUBSETS, legacy_facts_type)
return self.ansible_facts, self._warnings
diff --git a/plugins/module_utils/network/vyos/facts/firewall_global/firewall_global.py b/plugins/module_utils/network/vyos/facts/firewall_global/firewall_global.py
index 1b1076c..6441c26 100644
--- a/plugins/module_utils/network/vyos/facts/firewall_global/firewall_global.py
+++ b/plugins/module_utils/network/vyos/facts/firewall_global/firewall_global.py
@@ -14,10 +14,10 @@ from __future__ import absolute_import, division, print_function
__metaclass__ = type
from copy import deepcopy
-from re import findall, search, M
-from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import (
- utils,
-)
+from re import M, findall, search
+
+from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import utils
+
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.firewall_global.firewall_global import (
Firewall_globalArgs,
)
@@ -207,9 +207,7 @@ class Firewall_globalFacts(object):
:return: generated config dictionary.
"""
cfg_dict = {}
- cfg_dict["port_group"] = self.parse_group_lst(
- conf, "port-group", False
- )
+ cfg_dict["port_group"] = self.parse_group_lst(conf, "port-group", False)
cfg_dict["address_group"] = self.parse_group_lst(
conf, "address-group"
) + self.parse_group_lst(conf, "ipv6-address-group")
diff --git a/plugins/module_utils/network/vyos/facts/firewall_interfaces/firewall_interfaces.py b/plugins/module_utils/network/vyos/facts/firewall_interfaces/firewall_interfaces.py
index d0cfb53..3e0d323 100644
--- a/plugins/module_utils/network/vyos/facts/firewall_interfaces/firewall_interfaces.py
+++ b/plugins/module_utils/network/vyos/facts/firewall_interfaces/firewall_interfaces.py
@@ -13,11 +13,11 @@ from __future__ import absolute_import, division, print_function
__metaclass__ = type
-from re import findall, search, M
from copy import deepcopy
-from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import (
- utils,
-)
+from re import M, findall, search
+
+from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import utils
+
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.firewall_interfaces.firewall_interfaces import (
Firewall_interfacesArgs,
)
@@ -57,20 +57,14 @@ class Firewall_interfacesFacts(object):
# using mock data instead
data = self.get_device_data(connection)
objs = []
- interfaces = findall(
- r"^set interfaces ethernet (?:\'*)(\S+)(?:\'*)", data, M
- )
+ interfaces = findall(r"^set interfaces ethernet (?:\'*)(\S+)(?:\'*)", data, M)
if interfaces:
objs = self.get_names(data, interfaces)
- ansible_facts["ansible_network_resources"].pop(
- "firewall_interfaces", None
- )
+ ansible_facts["ansible_network_resources"].pop("firewall_interfaces", None)
facts = {}
if objs:
facts["firewall_interfaces"] = []
- params = utils.validate_config(
- self.argument_spec, {"config": objs}
- )
+ params = utils.validate_config(self.argument_spec, {"config": objs})
for cfg in params["config"]:
facts["firewall_interfaces"].append(utils.remove_empties(cfg))
@@ -127,9 +121,7 @@ class Firewall_interfacesFacts(object):
if config:
ar_lst.append(config)
if v6_ar:
- v6_conf = "\n".join(
- findall(r"(^.*?%s.*?$)" % " ipv6-name", conf, M)
- )
+ v6_conf = "\n".join(findall(r"(^.*?%s.*?$)" % " ipv6-name", conf, M))
config = self.parse_int_rules(v6_conf, "ipv6")
if config:
ar_lst.append(config)
diff --git a/plugins/module_utils/network/vyos/facts/firewall_rules/firewall_rules.py b/plugins/module_utils/network/vyos/facts/firewall_rules/firewall_rules.py
index cb1d4bb..69daad9 100644
--- a/plugins/module_utils/network/vyos/facts/firewall_rules/firewall_rules.py
+++ b/plugins/module_utils/network/vyos/facts/firewall_rules/firewall_rules.py
@@ -14,11 +14,11 @@ from __future__ import absolute_import, division, print_function
__metaclass__ = type
import re
-from re import findall, search, M
from copy import deepcopy
-from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import (
- utils,
-)
+from re import M, findall, search
+
+from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import utils
+
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.firewall_rules.firewall_rules import (
Firewall_rulesArgs,
)
@@ -59,9 +59,7 @@ class Firewall_rulesFacts(object):
data = self.get_device_data(connection)
# split the config into instances of the resource
objs = []
- v6_rules = findall(
- r"^set firewall ipv6-name (?:\'*)(\S+)(?:\'*)", data, M
- )
+ v6_rules = findall(r"^set firewall ipv6-name (?:\'*)(\S+)(?:\'*)", data, M)
v4_rules = findall(r"^set firewall name (?:\'*)(\S+)(?:\'*)", data, M)
if v6_rules:
config = self.get_rules(data, v6_rules, type="ipv6")
@@ -78,9 +76,7 @@ class Firewall_rulesFacts(object):
facts = {}
if objs:
facts["firewall_rules"] = []
- params = utils.validate_config(
- self.argument_spec, {"config": objs}
- )
+ params = utils.validate_config(self.argument_spec, {"config": objs})
for cfg in params["config"]:
facts["firewall_rules"].append(utils.remove_empties(cfg))
diff --git a/plugins/module_utils/network/vyos/facts/hostname/hostname.py b/plugins/module_utils/network/vyos/facts/hostname/hostname.py
index acdddca..77ecc8c 100644
--- a/plugins/module_utils/network/vyos/facts/hostname/hostname.py
+++ b/plugins/module_utils/network/vyos/facts/hostname/hostname.py
@@ -14,17 +14,16 @@ 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,
+import re
+
+from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import utils
+
+from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.hostname.hostname import (
+ HostnameArgs,
)
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.rm_templates.hostname import (
HostnameTemplate,
)
-from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.hostname.hostname import (
- HostnameArgs,
-)
-
-import re
class HostnameFacts(object):
@@ -57,17 +56,13 @@ class HostnameFacts(object):
config_lines.append(re.sub("'", "", resource))
# parse native config using the Hostname template
- hostname_parser = HostnameTemplate(
- lines=config_lines, module=self._module
- )
+ hostname_parser = HostnameTemplate(lines=config_lines, module=self._module)
objs = hostname_parser.parse()
ansible_facts["ansible_network_resources"].pop("hostname", None)
params = utils.remove_empties(
- hostname_parser.validate_config(
- self.argument_spec, {"config": objs}, redact=True
- )
+ hostname_parser.validate_config(self.argument_spec, {"config": objs}, redact=True)
)
facts["hostname"] = params.get("config", {})
diff --git a/plugins/module_utils/network/vyos/facts/interfaces/interfaces.py b/plugins/module_utils/network/vyos/facts/interfaces/interfaces.py
index ea3933c..c9479db 100644
--- a/plugins/module_utils/network/vyos/facts/interfaces/interfaces.py
+++ b/plugins/module_utils/network/vyos/facts/interfaces/interfaces.py
@@ -15,11 +15,11 @@ from __future__ import absolute_import, division, print_function
__metaclass__ = type
-from re import findall, M
from copy import deepcopy
-from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import (
- utils,
-)
+from re import M, findall
+
+from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import utils
+
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.interfaces.interfaces import (
InterfacesArgs,
)
@@ -75,9 +75,7 @@ class InterfacesFacts(object):
facts = {}
if objs:
facts["interfaces"] = []
- params = utils.validate_config(
- self.argument_spec, {"config": objs}
- )
+ params = utils.validate_config(self.argument_spec, {"config": objs})
for cfg in params["config"]:
facts["interfaces"].append(utils.remove_empties(cfg))
@@ -96,9 +94,7 @@ class InterfacesFacts(object):
"""
vif_conf = "\n".join(filter(lambda x: ("vif" in x), conf))
eth_conf = "\n".join(filter(lambda x: ("vif" not in x), conf))
- config = self.parse_attribs(
- ["description", "speed", "mtu", "duplex"], eth_conf
- )
+ config = self.parse_attribs(["description", "speed", "mtu", "duplex"], eth_conf)
config["vifs"] = self.parse_vifs(vif_conf)
return utils.remove_empties(config)
diff --git a/plugins/module_utils/network/vyos/facts/l3_interfaces/l3_interfaces.py b/plugins/module_utils/network/vyos/facts/l3_interfaces/l3_interfaces.py
index 09ab994..ea4cf69 100644
--- a/plugins/module_utils/network/vyos/facts/l3_interfaces/l3_interfaces.py
+++ b/plugins/module_utils/network/vyos/facts/l3_interfaces/l3_interfaces.py
@@ -17,16 +17,16 @@ __metaclass__ = type
import re
from copy import deepcopy
-from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import (
- utils,
-)
+
from ansible.module_utils.six import iteritems
-from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.utils.utils import (
- get_ip_address_version,
-)
+from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import utils
+
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.l3_interfaces.l3_interfaces import (
L3_interfacesArgs,
)
+from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.utils.utils import (
+ get_ip_address_version,
+)
class L3_interfacesFacts(object):
@@ -77,9 +77,7 @@ class L3_interfacesFacts(object):
facts = {}
if objs:
facts["l3_interfaces"] = []
- params = utils.validate_config(
- self.argument_spec, {"config": objs}
- )
+ params = utils.validate_config(self.argument_spec, {"config": objs})
for cfg in params["config"]:
facts["l3_interfaces"].append(utils.remove_empties(cfg))
diff --git a/plugins/module_utils/network/vyos/facts/lag_interfaces/lag_interfaces.py b/plugins/module_utils/network/vyos/facts/lag_interfaces/lag_interfaces.py
index ff02cb0..251178a 100644
--- a/plugins/module_utils/network/vyos/facts/lag_interfaces/lag_interfaces.py
+++ b/plugins/module_utils/network/vyos/facts/lag_interfaces/lag_interfaces.py
@@ -13,12 +13,11 @@ from __future__ import absolute_import, division, print_function
__metaclass__ = type
-from re import findall, search, M
from copy import deepcopy
+from re import M, findall, search
+
+from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import utils
-from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import (
- utils,
-)
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.lag_interfaces.lag_interfaces import (
Lag_interfacesArgs,
)
@@ -77,9 +76,7 @@ class Lag_interfacesFacts(object):
facts = {}
if objs:
facts["lag_interfaces"] = []
- params = utils.validate_config(
- self.argument_spec, {"config": objs}
- )
+ params = utils.validate_config(self.argument_spec, {"config": objs})
for cfg in params["config"]:
facts["lag_interfaces"].append(utils.remove_empties(cfg))
@@ -96,12 +93,8 @@ class Lag_interfacesFacts(object):
:rtype: dictionary
:returns: The generated config
"""
- arp_monitor_conf = "\n".join(
- filter(lambda x: ("arp-monitor" in x), conf)
- )
- hash_policy_conf = "\n".join(
- filter(lambda x: ("hash-policy" in x), conf)
- )
+ arp_monitor_conf = "\n".join(filter(lambda x: ("arp-monitor" in x), conf))
+ hash_policy_conf = "\n".join(filter(lambda x: ("hash-policy" in x), conf))
lag_conf = "\n".join(filter(lambda x: ("bond" in x), conf))
config = self.parse_attribs(["mode", "primary"], lag_conf)
config["arp_monitor"] = self.parse_arp_monitor(arp_monitor_conf)
diff --git a/plugins/module_utils/network/vyos/facts/legacy/base.py b/plugins/module_utils/network/vyos/facts/legacy/base.py
index 6f063d6..719df3f 100644
--- a/plugins/module_utils/network/vyos/facts/legacy/base.py
+++ b/plugins/module_utils/network/vyos/facts/legacy/base.py
@@ -14,9 +14,10 @@ from __future__ import absolute_import, division, print_function
__metaclass__ = type
import platform
import re
+
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import (
- run_commands,
get_capabilities,
+ run_commands,
)
diff --git a/plugins/module_utils/network/vyos/facts/lldp_global/lldp_global.py b/plugins/module_utils/network/vyos/facts/lldp_global/lldp_global.py
index 22b6bc8..e563999 100644
--- a/plugins/module_utils/network/vyos/facts/lldp_global/lldp_global.py
+++ b/plugins/module_utils/network/vyos/facts/lldp_global/lldp_global.py
@@ -13,12 +13,11 @@ from __future__ import absolute_import, division, print_function
__metaclass__ = type
-from re import findall, M
from copy import deepcopy
+from re import M, findall
+
+from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import utils
-from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import (
- utils,
-)
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.lldp_global.lldp_global import (
Lldp_globalArgs,
)
@@ -84,12 +83,8 @@ class Lldp_globalFacts(object):
:rtype: dictionary
:returns: The generated config
"""
- protocol_conf = "\n".join(
- filter(lambda x: ("legacy-protocols" in x), conf)
- )
- att_conf = "\n".join(
- filter(lambda x: ("legacy-protocols" not in x), conf)
- )
+ protocol_conf = "\n".join(filter(lambda x: ("legacy-protocols" in x), conf))
+ att_conf = "\n".join(filter(lambda x: ("legacy-protocols" not in x), conf))
config = self.parse_attribs(["snmp", "address"], att_conf)
config["legacy_protocols"] = self.parse_protocols(protocol_conf)
return utils.remove_empties(config)
diff --git a/plugins/module_utils/network/vyos/facts/lldp_interfaces/lldp_interfaces.py b/plugins/module_utils/network/vyos/facts/lldp_interfaces/lldp_interfaces.py
index 64d6a79..bfe684f 100644
--- a/plugins/module_utils/network/vyos/facts/lldp_interfaces/lldp_interfaces.py
+++ b/plugins/module_utils/network/vyos/facts/lldp_interfaces/lldp_interfaces.py
@@ -15,12 +15,11 @@ from __future__ import absolute_import, division, print_function
__metaclass__ = type
-from re import findall, search, M
from copy import deepcopy
+from re import M, findall, search
+
+from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import utils
-from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import (
- utils,
-)
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.lldp_interfaces.lldp_interfaces import (
Lldp_interfacesArgs,
)
@@ -87,9 +86,7 @@ class Lldp_interfacesFacts(object):
civic_conf = "\n".join(filter(lambda x: ("civic-based" in x), conf))
elin_conf = "\n".join(filter(lambda x: ("elin" in x), conf))
- coordinate_conf = "\n".join(
- filter(lambda x: ("coordinate-based" in x), conf)
- )
+ coordinate_conf = "\n".join(filter(lambda x: ("coordinate-based" in x), conf))
disable = "\n".join(filter(lambda x: ("disable" in x), conf))
coordinate_based_conf = self.parse_attribs(
@@ -137,9 +134,7 @@ class Lldp_interfacesFacts(object):
c_add["ca_value"] = ca[2].strip("'")
civic_info_list.append(c_add)
- country_code = search(
- r"^.*civic-based country-code (.+)", conf, M
- )
+ country_code = search(r"^.*civic-based country-code (.+)", conf, M)
civic_based = {}
civic_based["ca_info"] = civic_info_list
civic_based["country_code"] = country_code.group(1).strip("'")
diff --git a/plugins/module_utils/network/vyos/facts/logging_global/logging_global.py b/plugins/module_utils/network/vyos/facts/logging_global/logging_global.py
index 5f9d65d..e0434d9 100644
--- a/plugins/module_utils/network/vyos/facts/logging_global/logging_global.py
+++ b/plugins/module_utils/network/vyos/facts/logging_global/logging_global.py
@@ -15,15 +15,14 @@ based on the configuration.
"""
from ansible.module_utils.six import iteritems
-from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import (
- utils,
+from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import utils
+
+from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.logging_global.logging_global import (
+ Logging_globalArgs,
)
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.rm_templates.logging_global import (
Logging_globalTemplate,
)
-from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.logging_global.logging_global import (
- Logging_globalArgs,
-)
class Logging_globalFacts(object):
@@ -44,25 +43,19 @@ class Logging_globalFacts(object):
for k, v in vl.items():
_files.append(v)
objFinal[ke] = _files
- objFinal[ke] = sorted(
- objFinal[ke], key=lambda item: item["path"]
- )
+ objFinal[ke] = sorted(objFinal[ke], key=lambda item: item["path"])
elif ke == "hosts":
_hosts = []
for k, v in vl.items():
_hosts.append(v)
objFinal[ke] = _hosts
- objFinal[ke] = sorted(
- objFinal[ke], key=lambda item: item["hostname"]
- )
+ objFinal[ke] = sorted(objFinal[ke], key=lambda item: item["hostname"])
elif ke == "users":
_users = []
for k, v in vl.items():
_users.append(v)
objFinal[ke] = _users
- objFinal[ke] = sorted(
- objFinal[ke], key=lambda item: item["username"]
- )
+ objFinal[ke] = sorted(objFinal[ke], key=lambda item: item["username"])
elif ke == "console" or ke == "global_params":
if objFinal[ke].get("facilities"):
objFinal[ke]["facilities"] = sorted(
@@ -88,17 +81,13 @@ class Logging_globalFacts(object):
data = self.get_logging_data(connection)
# parse native config using the Logging_global template
- logging_global_parser = Logging_globalTemplate(
- lines=data.splitlines(), module=self._module
- )
+ logging_global_parser = Logging_globalTemplate(lines=data.splitlines(), module=self._module)
objs = logging_global_parser.parse()
ansible_facts["ansible_network_resources"].pop("logging_global", None)
objs = self.process_facts(objs)
params = utils.remove_empties(
- logging_global_parser.validate_config(
- self.argument_spec, {"config": objs}, redact=True
- )
+ logging_global_parser.validate_config(self.argument_spec, {"config": objs}, redact=True)
)
facts["logging_global"] = params.get("config", {})
diff --git a/plugins/module_utils/network/vyos/facts/ntp_global/ntp_global.py b/plugins/module_utils/network/vyos/facts/ntp_global/ntp_global.py
index bb20e2d..cead241 100644
--- a/plugins/module_utils/network/vyos/facts/ntp_global/ntp_global.py
+++ b/plugins/module_utils/network/vyos/facts/ntp_global/ntp_global.py
@@ -5,7 +5,6 @@
from __future__ import absolute_import, division, print_function
-
__metaclass__ = type
"""
@@ -17,15 +16,14 @@ based on the configuration.
import re
-from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import (
- utils,
+from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import utils
+
+from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.ntp_global.ntp_global import (
+ Ntp_globalArgs,
)
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.rm_templates.ntp_global import (
NtpTemplate,
)
-from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.ntp_global.ntp_global import (
- Ntp_globalArgs,
-)
class Ntp_globalFacts(object):
@@ -67,9 +65,7 @@ class Ntp_globalFacts(object):
objs["allow_clients"] = sorted(list(objs["allow_clients"]))
if "listen_addresses" in objs:
- objs["listen_addresses"] = sorted(
- list(objs["listen_addresses"])
- )
+ objs["listen_addresses"] = sorted(list(objs["listen_addresses"]))
""" if "options" in objs["servers"].values():
val = objs["servers"].values()
@@ -77,9 +73,7 @@ class Ntp_globalFacts(object):
if "servers" in objs:
objs["servers"] = list(objs["servers"].values())
- objs["servers"] = sorted(
- objs["servers"], key=lambda k: k["server"]
- )
+ objs["servers"] = sorted(objs["servers"], key=lambda k: k["server"])
for i in objs["servers"]:
if "options" in i:
i["options"] = sorted(list(i["options"]))
@@ -87,9 +81,7 @@ class Ntp_globalFacts(object):
ansible_facts["ansible_network_resources"].pop("ntp_global", None)
params = utils.remove_empties(
- ntp_parser.validate_config(
- self.argument_spec, {"config": objs}, redact=True
- )
+ ntp_parser.validate_config(self.argument_spec, {"config": objs}, redact=True)
)
if params.get("config"):
diff --git a/plugins/module_utils/network/vyos/facts/ospf_interfaces/ospf_interfaces.py b/plugins/module_utils/network/vyos/facts/ospf_interfaces/ospf_interfaces.py
index 4057db5..c89e2bd 100644
--- a/plugins/module_utils/network/vyos/facts/ospf_interfaces/ospf_interfaces.py
+++ b/plugins/module_utils/network/vyos/facts/ospf_interfaces/ospf_interfaces.py
@@ -16,15 +16,14 @@ based on the configuration.
import re
-from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import (
- utils,
+from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import utils
+
+from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.ospf_interfaces.ospf_interfaces import (
+ Ospf_interfacesArgs,
)
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.rm_templates.ospf_interfaces import (
Ospf_interfacesTemplate,
)
-from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.ospf_interfaces.ospf_interfaces import (
- Ospf_interfacesArgs,
-)
class Ospf_interfacesFacts(object):
@@ -35,9 +34,7 @@ class Ospf_interfacesFacts(object):
self.argument_spec = Ospf_interfacesArgs.argument_spec
def get_device_data(self, connection):
- return connection.get(
- 'show configuration commands | match "set interfaces"'
- )
+ return connection.get('show configuration commands | match "set interfaces"')
def get_config_set(self, data):
"""To classify the configurations beased on interface"""
@@ -69,9 +66,7 @@ class Ospf_interfacesFacts(object):
"""
facts = {}
objs = []
- ospf_interfaces_parser = Ospf_interfacesTemplate(
- lines=[], module=self._module
- )
+ ospf_interfaces_parser = Ospf_interfacesTemplate(lines=[], module=self._module)
if not data:
data = self.get_device_data(connection)
diff --git a/plugins/module_utils/network/vyos/facts/ospfv2/ospfv2.py b/plugins/module_utils/network/vyos/facts/ospfv2/ospfv2.py
index b0c9df2..4dcd546 100644
--- a/plugins/module_utils/network/vyos/facts/ospfv2/ospfv2.py
+++ b/plugins/module_utils/network/vyos/facts/ospfv2/ospfv2.py
@@ -13,11 +13,10 @@ from __future__ import absolute_import, division, print_function
__metaclass__ = type
-from re import findall, search, M
from copy import deepcopy
-from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import (
- utils,
-)
+from re import M, findall, search
+
+from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import utils
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.ospfv2.ospfv2 import (
Ospfv2Args,
@@ -99,18 +98,10 @@ class Ospfv2Facts(object):
config["route_map"] = self.parse_leaf_list(conf, "route-map")
config["mpls_te"] = self.parse_attrib(conf, "mpls_te", "mpls-te")
config["areas"] = self.parse_attrib_list(conf, "area", "area_id")
- config["parameters"] = self.parse_attrib(
- conf, "parameters", "parameters"
- )
- config["neighbor"] = self.parse_attrib_list(
- conf, "neighbor", "neighbor_id"
- )
- config["passive_interface"] = self.parse_leaf_list(
- conf, "passive-interface"
- )
- config["redistribute"] = self.parse_attrib_list(
- conf, "redistribute", "route_type"
- )
+ config["parameters"] = self.parse_attrib(conf, "parameters", "parameters")
+ config["neighbor"] = self.parse_attrib_list(conf, "neighbor", "neighbor_id")
+ config["passive_interface"] = self.parse_leaf_list(conf, "passive-interface")
+ config["redistribute"] = self.parse_attrib_list(conf, "redistribute", "route_type")
config["passive_interface_exclude"] = self.parse_leaf_list(
conf, "passive-interface-exclude"
)
@@ -199,9 +190,7 @@ class Ospfv2Facts(object):
"""
cfg_dict = {}
- cfg_dict["router_lsa"] = self.parse_attrib(
- conf, "router_lsa", match="router-lsa"
- )
+ cfg_dict["router_lsa"] = self.parse_attrib(conf, "router_lsa", match="router-lsa")
return cfg_dict
def parse_auto_cost(self, conf, attrib=None):
@@ -223,9 +212,7 @@ class Ospfv2Facts(object):
"""
cfg_dict = {}
- cfg_dict["originate"] = self.parse_attrib(
- conf, "originate", "originate"
- )
+ cfg_dict["originate"] = self.parse_attrib(conf, "originate", "originate")
return cfg_dict
def parse_area(self, conf, area_id):
@@ -241,9 +228,7 @@ class Ospfv2Facts(object):
"area_type": self.parse_area_type(conf, "area-type"),
"network": self.parse_network(conf),
"range": self.parse_attrib_list(conf, "range", "address"),
- "virtual_link": self.parse_attrib_list(
- conf, "virtual-link", "address"
- ),
+ "virtual_link": self.parse_attrib_list(conf, "virtual-link", "address"),
}
rule.update(r_sub)
return rule
@@ -297,9 +282,7 @@ class Ospfv2Facts(object):
"""
rule = self.parse_attrib(conf, "vlink")
- r_sub = {
- "authentication": self.parse_authentication(conf, "authentication")
- }
+ r_sub = {"authentication": self.parse_authentication(conf, "authentication")}
rule.update(r_sub)
return rule
@@ -451,9 +434,7 @@ class Ospfv2Facts(object):
else (
"enable"
if attrib == "enabled"
- else (
- "area" if attrib == "area_id" else attrib.replace("_", "-")
- )
+ else ("area" if attrib == "area_id" else attrib.replace("_", "-"))
)
)
diff --git a/plugins/module_utils/network/vyos/facts/ospfv3/ospfv3.py b/plugins/module_utils/network/vyos/facts/ospfv3/ospfv3.py
index 414c65e..121a348 100644
--- a/plugins/module_utils/network/vyos/facts/ospfv3/ospfv3.py
+++ b/plugins/module_utils/network/vyos/facts/ospfv3/ospfv3.py
@@ -13,11 +13,11 @@ from __future__ import absolute_import, division, print_function
__metaclass__ = type
-from re import findall, search, M
from copy import deepcopy
-from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import (
- utils,
-)
+from re import M, findall, search
+
+from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import utils
+
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.ospfv3.ospfv3 import (
Ospfv3Args,
)
@@ -75,13 +75,9 @@ class Ospfv3Facts(object):
"""
conf = "\n".join(filter(lambda x: x, conf))
config = {}
- config["parameters"] = self.parse_attrib(
- conf, "parameters", "parameters"
- )
+ config["parameters"] = self.parse_attrib(conf, "parameters", "parameters")
config["areas"] = self.parse_attrib_list(conf, "area", "area_id")
- config["redistribute"] = self.parse_attrib_list(
- conf, "redistribute", "route_type"
- )
+ config["redistribute"] = self.parse_attrib_list(conf, "redistribute", "route_type")
return config
def parse_attrib_list(self, conf, attrib, param):
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
index 15a2db9..19004c8 100644
--- a/plugins/module_utils/network/vyos/facts/prefix_lists/prefix_lists.py
+++ b/plugins/module_utils/network/vyos/facts/prefix_lists/prefix_lists.py
@@ -15,15 +15,14 @@ based on the configuration.
"""
-from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import (
- utils,
+from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import utils
+
+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.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):
@@ -53,9 +52,7 @@ class Prefix_listsFacts(object):
data = self.get_config(connection)
# parse native config using the Prefix_lists template
- prefix_lists_parser = Prefix_listsTemplate(
- lines=data.splitlines(), module=self._module
- )
+ prefix_lists_parser = Prefix_listsTemplate(lines=data.splitlines(), module=self._module)
objs = prefix_lists_parser.parse()
objs = sorted(
@@ -79,9 +76,7 @@ class Prefix_listsFacts(object):
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
- )
+ prefix_lists_parser.validate_config(self.argument_spec, {"config": objs}, redact=True)
)
if params.get("config"):
diff --git a/plugins/module_utils/network/vyos/facts/route_maps/route_maps.py b/plugins/module_utils/network/vyos/facts/route_maps/route_maps.py
index 51e8f97..9f53264 100644
--- a/plugins/module_utils/network/vyos/facts/route_maps/route_maps.py
+++ b/plugins/module_utils/network/vyos/facts/route_maps/route_maps.py
@@ -16,15 +16,14 @@ based on the configuration.
from copy import deepcopy
-from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import (
- utils,
+from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import utils
+
+from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.route_maps.route_maps import (
+ Route_mapsArgs,
)
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.rm_templates.route_maps import (
Route_mapsTemplate,
)
-from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.route_maps.route_maps import (
- Route_mapsArgs,
-)
class Route_mapsFacts(object):
@@ -73,9 +72,7 @@ class Route_mapsFacts(object):
ansible_facts["ansible_network_resources"].pop("route_maps", None)
# import epdb;epdb.serve()
- params = utils.remove_empties(
- utils.validate_config(self.argument_spec, {"config": objs})
- )
+ params = utils.remove_empties(utils.validate_config(self.argument_spec, {"config": objs}))
if params.get("config"):
facts["route_maps"] = params["config"]
diff --git a/plugins/module_utils/network/vyos/facts/snmp_server/snmp_server.py b/plugins/module_utils/network/vyos/facts/snmp_server/snmp_server.py
index 2a9ba48..54339f5 100644
--- a/plugins/module_utils/network/vyos/facts/snmp_server/snmp_server.py
+++ b/plugins/module_utils/network/vyos/facts/snmp_server/snmp_server.py
@@ -14,17 +14,17 @@ for a given resource, parsed, and the facts tree is populated
based on the configuration.
"""
+import re
+
from ansible.module_utils.six import iteritems
-from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import (
- utils,
+from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import utils
+
+from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.snmp_server.snmp_server import (
+ Snmp_serverArgs,
)
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.rm_templates.snmp_server import (
Snmp_serverTemplate,
)
-from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.snmp_server.snmp_server import (
- Snmp_serverArgs,
-)
-import re
class Snmp_serverFacts(object):
@@ -57,9 +57,7 @@ class Snmp_serverFacts(object):
config_lines.append(re.sub("'", "", resource))
# parse native config using the Snmp_server template
- snmp_server_parser = Snmp_serverTemplate(
- lines=config_lines, module=self._module
- )
+ snmp_server_parser = Snmp_serverTemplate(lines=config_lines, module=self._module)
objs = snmp_server_parser.parse()
if objs:
if "communities" in objs:
@@ -106,9 +104,7 @@ class Snmp_serverFacts(object):
ansible_facts["ansible_network_resources"].pop("snmp_server", None)
params = utils.remove_empties(
- snmp_server_parser.validate_config(
- self.argument_spec, {"config": objs}, redact=True
- )
+ snmp_server_parser.validate_config(self.argument_spec, {"config": objs}, redact=True)
)
facts["snmp_server"] = params.get("config", {})
diff --git a/plugins/module_utils/network/vyos/facts/static_routes/static_routes.py b/plugins/module_utils/network/vyos/facts/static_routes/static_routes.py
index bce2731..019706b 100644
--- a/plugins/module_utils/network/vyos/facts/static_routes/static_routes.py
+++ b/plugins/module_utils/network/vyos/facts/static_routes/static_routes.py
@@ -13,11 +13,11 @@ based on the configuration.
from __future__ import absolute_import, division, print_function
__metaclass__ = type
-from re import findall, search, M
from copy import deepcopy
-from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import (
- utils,
-)
+from re import M, findall, search
+
+from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import utils
+
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.static_routes.static_routes import (
Static_routesArgs,
)
@@ -63,9 +63,7 @@ class Static_routesFacts(object):
r_v4 = []
r_v6 = []
af = []
- static_routes = findall(
- r"set protocols static route(6)? (\S+)", data, M
- )
+ static_routes = findall(r"set protocols static route(6)? (\S+)", data, M)
if static_routes:
for route in set(static_routes):
route_regex = r" %s .+$" % route[1]
@@ -91,9 +89,7 @@ class Static_routesFacts(object):
facts = {}
if objs:
facts["static_routes"] = []
- params = utils.validate_config(
- self.argument_spec, {"config": objs}
- )
+ params = utils.validate_config(self.argument_spec, {"config": objs})
for cfg in params["config"]:
facts["static_routes"].append(utils.remove_empties(cfg))
@@ -151,9 +147,7 @@ class Static_routesFacts(object):
dis = hop.find("disable")
hop_info = hop.split(" ")
- nh_info = {
- "forward_router_address": hop_info[0].strip("'")
- }
+ nh_info = {"forward_router_address": hop_info[0].strip("'")}
if interface:
nh_info["interface"] = interface.group(1).strip("'")
if distance:
@@ -162,16 +156,11 @@ class Static_routesFacts(object):
elif dis >= 1:
nh_info["enabled"] = False
for element in nh_list:
- if (
- element["forward_router_address"]
- == nh_info["forward_router_address"]
- ):
+ if element["forward_router_address"] == nh_info["forward_router_address"]:
if "interface" in nh_info.keys():
element["interface"] = nh_info["interface"]
if "admin_distance" in nh_info.keys():
- element["admin_distance"] = nh_info[
- "admin_distance"
- ]
+ element["admin_distance"] = nh_info["admin_distance"]
if "enabled" in nh_info.keys():
element["enabled"] = nh_info["enabled"]
nh_info = None
diff --git a/plugins/module_utils/network/vyos/rm_templates/bgp_address_family.py b/plugins/module_utils/network/vyos/rm_templates/bgp_address_family.py
index ddff1bb..b1bb27c 100644
--- a/plugins/module_utils/network/vyos/rm_templates/bgp_address_family.py
+++ b/plugins/module_utils/network/vyos/rm_templates/bgp_address_family.py
@@ -15,6 +15,7 @@ the given network resource.
"""
import re
+
from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.network_template import (
NetworkTemplate,
)
@@ -38,9 +39,7 @@ def _tmplt_bgp_af_aggregate_address(config_data):
def _tmplt_bgp_af_redistribute_metric(config_data):
if config_data["address_family"]["redistribute"].get("metric"):
afi = config_data["address_family"]["afi"] + "-unicast"
- command = "protocols bgp {as_number} address-family ".format(
- **config_data
- )
+ command = "protocols bgp {as_number} address-family ".format(**config_data)
if config_data["address_family"]["redistribute"].get("metric"):
command += afi + " redistribute {protocol} metric {metric}".format(
**config_data["address_family"]["redistribute"]
@@ -51,15 +50,10 @@ def _tmplt_bgp_af_redistribute_metric(config_data):
def _tmplt_bgp_af_redistribute_route_map(config_data):
if config_data["address_family"]["redistribute"].get("route_map"):
afi = config_data["address_family"]["afi"] + "-unicast"
- command = "protocols bgp {as_number} address-family ".format(
- **config_data
- )
+ command = "protocols bgp {as_number} address-family ".format(**config_data)
if config_data["address_family"]["redistribute"].get("route_map"):
- command += (
- afi
- + " redistribute {protocol} route-map {route_map}".format(
- **config_data["address_family"]["redistribute"]
- )
+ command += afi + " redistribute {protocol} route-map {route_map}".format(
+ **config_data["address_family"]["redistribute"]
)
return command
@@ -67,9 +61,7 @@ def _tmplt_bgp_af_redistribute_route_map(config_data):
def _tmplt_bgp_af_redistribute_table(config_data):
if config_data["address_family"]["redistribute"].get("table"):
afi = config_data["address_family"]["afi"] + "-unicast"
- command = "protocols bgp {as_number} address-family ".format(
- **config_data
- )
+ command = "protocols bgp {as_number} address-family ".format(**config_data)
if config_data["address_family"]["redistribute"].get("table"):
command += afi + " table {table}".format(
**config_data["address_family"]["redistribute"]
@@ -81,9 +73,7 @@ def _tmplt_bgp_af_delete_redistribute(config_data):
afi = config_data["address_family"]["afi"] + "-unicast"
command = "protocols bgp {as_number} address-family ".format(**config_data)
config_data = config_data["address_family"]
- command += afi + " redistribute {protocol}".format(
- **config_data["redistribute"]
- )
+ command += afi + " redistribute {protocol}".format(**config_data["redistribute"])
return command
@@ -91,18 +81,11 @@ def _tmplt_bgp_af_neighbor_distribute_list(config_data):
command = []
afi = config_data["neighbors"]["address_family"]["afi"] + "-unicast"
cmd = "protocols bgp {as_number} neighbor ".format(**config_data)
- cmd += "{neighbor_address} address-family ".format(
- **config_data["neighbors"]
- )
+ cmd += "{neighbor_address} address-family ".format(**config_data["neighbors"])
config_data = config_data["neighbors"]["address_family"]
for list_el in config_data["distribute_list"]:
command.append(
- cmd
- + afi
- + " distribute-list "
- + list_el["action"]
- + " "
- + str(list_el["acl"])
+ cmd + afi + " distribute-list " + list_el["action"] + " " + str(list_el["acl"])
)
return command
@@ -111,18 +94,11 @@ def _tmplt_bgp_af_neighbor_route_map(config_data):
command = []
afi = config_data["neighbors"]["address_family"]["afi"] + "-unicast"
cmd = "protocols bgp {as_number} neighbor ".format(**config_data)
- cmd += "{neighbor_address} address-family ".format(
- **config_data["neighbors"]
- )
+ cmd += "{neighbor_address} address-family ".format(**config_data["neighbors"])
config_data = config_data["neighbors"]["address_family"]
for list_el in config_data["route_map"]:
command.append(
- cmd
- + afi
- + " route-map "
- + list_el["action"]
- + " "
- + str(list_el["route_map"])
+ cmd + afi + " route-map " + list_el["action"] + " " + str(list_el["route_map"])
)
return command
@@ -131,18 +107,11 @@ def _tmplt_bgp_af_neighbor_prefix_list(config_data):
command = []
afi = config_data["neighbors"]["address_family"]["afi"] + "-unicast"
cmd = "protocols bgp {as_number} neighbor ".format(**config_data)
- cmd += "{neighbor_address} address-family ".format(
- **config_data["neighbors"]
- )
+ cmd += "{neighbor_address} address-family ".format(**config_data["neighbors"])
config_data = config_data["neighbors"]["address_family"]
for list_el in config_data["prefix_list"]:
command.append(
- cmd
- + afi
- + " prefix-list "
- + list_el["action"]
- + " "
- + str(list_el["prefix_list"])
+ cmd + afi + " prefix-list " + list_el["action"] + " " + str(list_el["prefix_list"])
)
return command
@@ -151,18 +120,11 @@ def _tmplt_bgp_af_neighbor_filter_list(config_data):
command = []
afi = config_data["neighbors"]["address_family"]["afi"] + "-unicast"
cmd = "protocols bgp {as_number} neighbor ".format(**config_data)
- cmd += "{neighbor_address} address-family ".format(
- **config_data["neighbors"]
- )
+ cmd += "{neighbor_address} address-family ".format(**config_data["neighbors"])
config_data = config_data["neighbors"]["address_family"]
for list_el in config_data["filter_list"]:
command.append(
- cmd
- + afi
- + " filter-list "
- + list_el["action"]
- + " "
- + str(list_el["path_list"])
+ cmd + afi + " filter-list " + list_el["action"] + " " + str(list_el["path_list"])
)
return command
@@ -171,9 +133,7 @@ def _tmplt_bgp_af_neighbor_attribute(config_data):
command = []
afi = config_data["neighbors"]["address_family"]["afi"] + "-unicast"
cmd = "protocols bgp {as_number} neighbor ".format(**config_data)
- cmd += "{neighbor_address} address-family ".format(
- **config_data["neighbors"]
- )
+ cmd += "{neighbor_address} address-family ".format(**config_data["neighbors"])
config_data = config_data["neighbors"]["address_family"]
for k in config_data["attribute_unchanged"].keys():
if config_data["attribute_unchanged"][k]:
@@ -187,10 +147,7 @@ def _tmplt_bgp_af_neighbor_delete(config_data):
afi = config_data["neighbors"]["address_family"]["afi"] + "-unicast"
command = "protocols bgp {as_number} ".format(**config_data)
command += (
- "neighbor {neighbor_address} address-family ".format(
- **config_data["neighbors"]
- )
- + afi
+ "neighbor {neighbor_address} address-family ".format(**config_data["neighbors"]) + afi
)
config_data = config_data["neighbors"]["address_family"]
if config_data.get("allowas_in"):
@@ -238,10 +195,7 @@ def _tmplt_bgp_af_neighbor(config_data):
afi = config_data["neighbors"]["address_family"]["afi"] + "-unicast"
command = "protocols bgp {as_number} ".format(**config_data)
command += (
- "neighbor {neighbor_address} address-family ".format(
- **config_data["neighbors"]
- )
- + afi
+ "neighbor {neighbor_address} address-family ".format(**config_data["neighbors"]) + afi
)
config_data = config_data["neighbors"]["address_family"]
if config_data.get("allowas_in"):
@@ -255,9 +209,7 @@ def _tmplt_bgp_af_neighbor(config_data):
elif config_data["capability"].get("orf"):
command += " prefix-list {orf}".format(**config_data["capability"])
elif config_data.get("default_originate"):
- command += " default-originate route-map {default_originate}".format(
- **config_data
- )
+ command += " default-originate route-map {default_originate}".format(**config_data)
elif config_data.get("maximum_prefix"):
command += " maximum-prefix {maximum_prefix}".format(**config_data)
elif config_data.get("nexthop_local"):
diff --git a/plugins/module_utils/network/vyos/rm_templates/bgp_global.py b/plugins/module_utils/network/vyos/rm_templates/bgp_global.py
index 0671ff7..0f7fd8b 100644
--- a/plugins/module_utils/network/vyos/rm_templates/bgp_global.py
+++ b/plugins/module_utils/network/vyos/rm_templates/bgp_global.py
@@ -15,8 +15,8 @@ the given network resource.
"""
import re
-from ansible.module_utils.six import iteritems
+from ansible.module_utils.six import iteritems
from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.network_template import (
NetworkTemplate,
)
@@ -27,9 +27,7 @@ def _tmplt_bgp_params_confederation(config_data):
for list_el in config_data["bgp_params"]["confederation"]:
for k, v in iteritems(list_el):
command.append(
- "protocols bgp {as_number} parameters confederation ".format(
- **config_data
- )
+ "protocols bgp {as_number} parameters confederation ".format(**config_data)
+ k
+ " "
+ str(v)
@@ -51,17 +49,11 @@ def _tmplt_bgp_maximum_paths(config_data):
def _tmplt_bgp_aggregate_address(config_data):
- command = "protocols bgp {as_number} aggregate-address".format(
- **config_data
- )
+ command = "protocols bgp {as_number} aggregate-address".format(**config_data)
if config_data["aggregate_address"].get("as_set"):
- command += " {prefix} as-set".format(
- **config_data["aggregate_address"]
- )
+ command += " {prefix} as-set".format(**config_data["aggregate_address"])
if config_data["aggregate_address"].get("summary_only"):
- command += " {prefix} summary-only".format(
- **config_data["aggregate_address"]
- )
+ command += " {prefix} summary-only".format(**config_data["aggregate_address"])
return command
@@ -71,15 +63,11 @@ def _tmplt_delete_bgp_maximum_paths(config_data):
def _tmplt_bgp_params_default(config_data):
- command = "protocols bgp {as_number} parameters default".format(
- **config_data
- )
+ command = "protocols bgp {as_number} parameters default".format(**config_data)
if config_data["bgp_params"]["default"].get("no_ipv4_unicast"):
command += " no-ipv4-unicast"
if config_data["bgp_params"]["default"].get("local_pref"):
- command += " local-pref {local_pref}".format(
- **config_data["bgp_params"]["default"]
- )
+ command += " local-pref {local_pref}".format(**config_data["bgp_params"]["default"])
return command
@@ -110,11 +98,7 @@ def _tmplt_bgp_timers(config_data):
command = []
for k, v in iteritems(config_data["timers"]):
command.append(
- "protocols bgp {as_number} ".format(**config_data)
- + "timers "
- + k
- + " "
- + str(v)
+ "protocols bgp {as_number} ".format(**config_data) + "timers " + k + " " + str(v)
)
return command
@@ -123,27 +107,21 @@ def _tmplt_bgp_timers(config_data):
def _tmplt_bgp_neighbor_attribute_unchanged_as_path(config_data):
command = "protocols bgp {as_number} ".format(
**config_data
- ) + "neighbor {address} attribute-unchanged as-path".format(
- **config_data["neighbor"]
- )
+ ) + "neighbor {address} attribute-unchanged as-path".format(**config_data["neighbor"])
return command
def _tmplt_bgp_neighbor_attribute_unchanged_med(config_data):
command = "protocols bgp {as_number} ".format(
**config_data
- ) + "neighbor {address} attribute-unchanged med".format(
- **config_data["neighbor"]
- )
+ ) + "neighbor {address} attribute-unchanged med".format(**config_data["neighbor"])
return command
def _tmplt_bgp_neighbor_attribute_unchanged_next_hop(config_data):
command = "protocols bgp {as_number} ".format(
**config_data
- ) + "neighbor {address} attribute-unchanged next-hop".format(
- **config_data["neighbor"]
- )
+ ) + "neighbor {address} attribute-unchanged next-hop".format(**config_data["neighbor"])
return command
@@ -152,9 +130,7 @@ def _tmplt_bgp_neighbor_distribute_list(config_data):
for list_el in config_data["neighbor"]["distribute_list"]:
command.append(
"protocols bgp {as_number} ".format(**config_data)
- + "neighbor {address} distribute-list ".format(
- **config_data["neighbor"]
- )
+ + "neighbor {address} distribute-list ".format(**config_data["neighbor"])
+ list_el["action"]
+ " "
+ str(list_el["acl"])
@@ -180,9 +156,7 @@ def _tmplt_bgp_neighbor_prefix_list(config_data):
for list_el in config_data["neighbor"]["prefix_list"]:
command.append(
"protocols bgp {as_number} ".format(**config_data)
- + "neighbor {address} prefix-list ".format(
- **config_data["neighbor"]
- )
+ + "neighbor {address} prefix-list ".format(**config_data["neighbor"])
+ list_el["action"]
+ " "
+ str(list_el["prefix_list"])
@@ -195,9 +169,7 @@ def _tmplt_bgp_neighbor_filter_list(config_data):
for list_el in config_data["neighbor"]["filter_list"]:
command.append(
"protocols bgp {as_number} ".format(**config_data)
- + "neighbor {address} filter-list ".format(
- **config_data["neighbor"]
- )
+ + "neighbor {address} filter-list ".format(**config_data["neighbor"])
+ list_el["action"]
+ " "
+ str(list_el["path_list"])
@@ -207,9 +179,7 @@ def _tmplt_bgp_neighbor_filter_list(config_data):
def _tmplt_bgp_params_distance(config_data):
command = (
- "protocols bgp {as_number} parameters distance global ".format(
- **config_data
- )
+ "protocols bgp {as_number} parameters distance global ".format(**config_data)
+ config_data["bgp_params"]["distance"]["type"]
+ " "
+ str(config_data["bgp_params"]["distance"]["value"])
diff --git a/plugins/module_utils/network/vyos/rm_templates/hostname.py b/plugins/module_utils/network/vyos/rm_templates/hostname.py
index 79caee6..7352794 100644
--- a/plugins/module_utils/network/vyos/rm_templates/hostname.py
+++ b/plugins/module_utils/network/vyos/rm_templates/hostname.py
@@ -15,6 +15,7 @@ the given network resource.
"""
import re
+
from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.network_template import (
NetworkTemplate,
)
diff --git a/plugins/module_utils/network/vyos/rm_templates/logging_global.py b/plugins/module_utils/network/vyos/rm_templates/logging_global.py
index 8cfe7a6..82a4963 100644
--- a/plugins/module_utils/network/vyos/rm_templates/logging_global.py
+++ b/plugins/module_utils/network/vyos/rm_templates/logging_global.py
@@ -15,6 +15,7 @@ the given network resource.
"""
import re
+
from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.network_template import (
NetworkTemplate,
)
@@ -43,21 +44,13 @@ def tmplt_params(config_data):
elif config_data.get("users"):
val = config_data.get("users")
if val.get("username") and not val.get("archive"):
- tmplt += "system syslog user {username}".format(
- username=val["username"]
- )
+ tmplt += "system syslog user {username}".format(username=val["username"])
if val.get("facilities"):
tmplt = templt_common(val.get("facilities"), tmplt)
elif config_data.get("hosts"):
val = config_data.get("hosts")
- if (
- val.get("hostname")
- and not val.get("archive")
- and not val.get("port")
- ):
- tmplt += "system syslog host {hostname}".format(
- hostname=val["hostname"]
- )
+ if val.get("hostname") and not val.get("archive") and not val.get("port"):
+ tmplt += "system syslog host {hostname}".format(hostname=val["hostname"])
if val.get("facilities"):
tmplt = templt_common(val.get("facilities"), tmplt)
elif config_data.get("files"):
diff --git a/plugins/module_utils/network/vyos/rm_templates/ntp_global.py b/plugins/module_utils/network/vyos/rm_templates/ntp_global.py
index f4589a2..5254035 100644
--- a/plugins/module_utils/network/vyos/rm_templates/ntp_global.py
+++ b/plugins/module_utils/network/vyos/rm_templates/ntp_global.py
@@ -15,6 +15,7 @@ the given network resource.
"""
import re
+
from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.network_template import (
NetworkTemplate,
)
@@ -23,9 +24,7 @@ from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.r
class NtpTemplate(NetworkTemplate):
def __init__(self, lines=None, module=None):
prefix = {"set": "set", "remove": "delete"}
- super(NtpTemplate, self).__init__(
- lines=lines, tmplt=self, prefix=prefix, module=module
- )
+ super(NtpTemplate, self).__init__(lines=lines, tmplt=self, prefix=prefix, module=module)
# fmt: off
PARSERS = [
diff --git a/plugins/module_utils/network/vyos/rm_templates/ospf_interfaces.py b/plugins/module_utils/network/vyos/rm_templates/ospf_interfaces.py
index bda17df..de3beba 100644
--- a/plugins/module_utils/network/vyos/rm_templates/ospf_interfaces.py
+++ b/plugins/module_utils/network/vyos/rm_templates/ospf_interfaces.py
@@ -15,6 +15,7 @@ the given network resource.
"""
import re
+
from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.network_template import (
NetworkTemplate,
)
@@ -36,12 +37,7 @@ def _tmplt_ospf_int_delete(config_data):
int_type = get_interface_type(config_data["name"])
params = _get_parameters(config_data["address_family"])
command = (
- "interfaces "
- + int_type
- + " {name} ".format(**config_data)
- + params[1]
- + " "
- + params[0]
+ "interfaces " + int_type + " {name} ".format(**config_data) + params[1] + " " + params[0]
)
return command
@@ -93,9 +89,7 @@ def _tmplt_ospf_int_auth_md5(config_data):
+ " authentication md5 key-id {key_id} ".format(
**config_data["address_family"]["authentication"]["md5_key"]
)
- + "md5-key {key}".format(
- **config_data["address_family"]["authentication"]["md5_key"]
- )
+ + "md5-key {key}".format(**config_data["address_family"]["authentication"]["md5_key"])
)
return command
@@ -143,9 +137,7 @@ def _tmplt_ospf_int_hello_interval(config_data):
+ params[1]
+ " "
+ params[0]
- + " hello-interval {hello_interval}".format(
- **config_data["address_family"]
- )
+ + " hello-interval {hello_interval}".format(**config_data["address_family"])
)
return command
@@ -161,9 +153,7 @@ def _tmplt_ospf_int_dead_interval(config_data):
+ params[1]
+ " "
+ params[0]
- + " dead-interval {dead_interval}".format(
- **config_data["address_family"]
- )
+ + " dead-interval {dead_interval}".format(**config_data["address_family"])
)
return command
@@ -227,9 +217,7 @@ def _tmplt_ospf_int_retransmit_interval(config_data):
+ params[1]
+ " "
+ params[0]
- + " retransmit-interval {retransmit_interval}".format(
- **config_data["address_family"]
- )
+ + " retransmit-interval {retransmit_interval}".format(**config_data["address_family"])
)
return command
@@ -245,9 +233,7 @@ def _tmplt_ospf_int_transmit_delay(config_data):
+ params[1]
+ " "
+ params[0]
- + " transmit-delay {transmit_delay}".format(
- **config_data["address_family"]
- )
+ + " transmit-delay {transmit_delay}".format(**config_data["address_family"])
)
return command
diff --git a/plugins/module_utils/network/vyos/rm_templates/prefix_lists.py b/plugins/module_utils/network/vyos/rm_templates/prefix_lists.py
index 9a66a8d..00a157e 100644
--- a/plugins/module_utils/network/vyos/rm_templates/prefix_lists.py
+++ b/plugins/module_utils/network/vyos/rm_templates/prefix_lists.py
@@ -15,6 +15,7 @@ the given network resource.
"""
import re
+
from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.network_template import (
NetworkTemplate,
)
diff --git a/plugins/module_utils/network/vyos/rm_templates/route_maps.py b/plugins/module_utils/network/vyos/rm_templates/route_maps.py
index 262721e..1652a23 100644
--- a/plugins/module_utils/network/vyos/rm_templates/route_maps.py
+++ b/plugins/module_utils/network/vyos/rm_templates/route_maps.py
@@ -15,6 +15,7 @@ the given network resource.
"""
import re
+
from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.network_template import (
NetworkTemplate,
)
@@ -23,9 +24,7 @@ from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.r
class Route_mapsTemplate(NetworkTemplate):
def __init__(self, lines=None):
prefix = {"set": "set", "remove": "delete"}
- super(Route_mapsTemplate, self).__init__(
- lines=lines, tmplt=self, prefix=prefix
- )
+ super(Route_mapsTemplate, self).__init__(lines=lines, tmplt=self, prefix=prefix)
# fmt: off
PARSERS = [
diff --git a/plugins/module_utils/network/vyos/rm_templates/snmp_server.py b/plugins/module_utils/network/vyos/rm_templates/snmp_server.py
index c1e385a..15a0804 100644
--- a/plugins/module_utils/network/vyos/rm_templates/snmp_server.py
+++ b/plugins/module_utils/network/vyos/rm_templates/snmp_server.py
@@ -15,6 +15,7 @@ the given network resource.
"""
import re
+
from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.network_template import (
NetworkTemplate,
)
@@ -25,9 +26,7 @@ def _tmplt_snmp_server_communities(config_data):
command = []
cmd = "service snmp community {name}".format(**config_data)
if "authorization_type" in config_data:
- auth_cmd = cmd + " authorization {authorization_type}".format(
- **config_data
- )
+ auth_cmd = cmd + " authorization {authorization_type}".format(**config_data)
command.append(auth_cmd)
if "clients" in config_data:
for c in config_data["clients"]:
@@ -103,18 +102,10 @@ def _tmplt_snmp_server_v3_user(config_data):
type_cmd = cmd + val + " type {type}".format(**config)
command.append(type_cmd)
if "encrypted_key" in config:
- enc_cmd = (
- cmd
- + val
- + " encrypted-key {encrypted_key}".format(**config)
- )
+ enc_cmd = cmd + val + " encrypted-key {encrypted_key}".format(**config)
command.append(enc_cmd)
if "plaintext_key" in config:
- plain_cmd = (
- cmd
- + val
- + " plaintext-key {plaintext_key}".format(**config)
- )
+ plain_cmd = cmd + val + " plaintext-key {plaintext_key}".format(**config)
command.append(plain_cmd)
return command
diff --git a/plugins/module_utils/network/vyos/utils/utils.py b/plugins/module_utils/network/vyos/utils/utils.py
index 43f3fc9..4d44744 100644
--- a/plugins/module_utils/network/vyos/utils/utils.py
+++ b/plugins/module_utils/network/vyos/utils/utils.py
@@ -7,8 +7,8 @@
from __future__ import absolute_import, division, print_function
__metaclass__ = type
-from ansible.module_utils.six import iteritems
from ansible.module_utils.basic import missing_required_lib
+from ansible.module_utils.six import iteritems
try:
import ipaddress
@@ -112,11 +112,7 @@ def get_lst_same_for_dicts(want, have, lst):
if want and have:
want_list = want.get(lst) or {}
have_list = have.get(lst) or {}
- diff = [
- i
- for i in want_list and have_list
- if i in have_list and i in want_list
- ]
+ diff = [i for i in want_list and have_list if i in have_list and i in want_list]
return diff
@@ -133,11 +129,7 @@ def list_diff_have_only(want_list, have_list):
elif not have_list:
diff = None
else:
- diff = [
- i
- for i in have_list + want_list
- if i in have_list and i not in want_list
- ]
+ diff = [i for i in have_list + want_list if i in have_list and i not in want_list]
return diff
@@ -154,11 +146,7 @@ def list_diff_want_only(want_list, have_list):
elif not have_list:
diff = want_list
else:
- diff = [
- i
- for i in have_list + want_list
- if i in want_list and i not in have_list
- ]
+ diff = [i for i in have_list + want_list if i in want_list and i not in have_list]
return diff
@@ -173,11 +161,7 @@ def search_dict_tv_in_list(d_val1, d_val2, lst, key1, key2):
:return:
"""
obj = next(
- (
- item
- for item in lst
- if item[key1] == d_val1 and item[key2] == d_val2
- ),
+ (item for item in lst if item[key1] == d_val1 and item[key2] == d_val2),
None,
)
if obj:
@@ -249,13 +233,7 @@ def _bool_to_str(val):
:param val: bool value.
:return: enable/disable.
"""
- return (
- "enable"
- if str(val) == "True"
- else "disable"
- if str(val) == "False"
- else val
- )
+ return "enable" if str(val) == "True" else "disable" if str(val) == "False" else val
def _is_w_same(w, h, key):
diff --git a/plugins/module_utils/network/vyos/vyos.py b/plugins/module_utils/network/vyos/vyos.py
index 42fc57c..da364f9 100644
--- a/plugins/module_utils/network/vyos/vyos.py
+++ b/plugins/module_utils/network/vyos/vyos.py
@@ -83,9 +83,7 @@ def get_config(module, flags=None, format=None):
def run_commands(module, commands, check_rc=True):
connection = get_connection(module)
try:
- response = connection.run_commands(
- commands=commands, check_rc=check_rc
- )
+ response = connection.run_commands(commands=commands, check_rc=check_rc)
except ConnectionError as exc:
module.fail_json(msg=to_text(exc, errors="surrogate_then_replace"))
return response
@@ -95,9 +93,7 @@ def load_config(module, commands, commit=False, comment=None):
connection = get_connection(module)
try:
- response = connection.edit_config(
- candidate=commands, commit=commit, comment=comment
- )
+ response = connection.edit_config(candidate=commands, commit=commit, comment=comment)
except ConnectionError as exc:
module.fail_json(msg=to_text(exc, errors="surrogate_then_replace"))
diff --git a/plugins/modules/vyos_banner.py b/plugins/modules/vyos_banner.py
index a5f3fb9..0ee10f5 100644
--- a/plugins/modules/vyos_banner.py
+++ b/plugins/modules/vyos_banner.py
@@ -91,6 +91,7 @@ commands:
import re
from ansible.module_utils.basic import AnsibleModule
+
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import (
get_config,
load_config,
@@ -104,21 +105,13 @@ def spec_to_commands(updates, module):
if state == "absent":
if have.get("state") != "absent" or (
- have.get("state") != "absent"
- and "text" in have.keys()
- and have["text"]
+ have.get("state") != "absent" and "text" in have.keys() and have["text"]
):
- commands.append(
- "delete system login banner %s" % module.params["banner"]
- )
+ commands.append("delete system login banner %s" % module.params["banner"])
elif state == "present":
- if want["text"] and want["text"].encode().decode(
- "unicode_escape"
- ) != have.get("text"):
- banner_cmd = (
- "set system login banner %s " % module.params["banner"]
- )
+ if want["text"] and want["text"].encode().decode("unicode_escape") != have.get("text"):
+ banner_cmd = "set system login banner %s " % module.params["banner"]
banner_cmd += want["text"].strip()
commands.append(banner_cmd)
diff --git a/plugins/modules/vyos_bgp_address_family.py b/plugins/modules/vyos_bgp_address_family.py
index ab98e3b..ba56309 100644
--- a/plugins/modules/vyos_bgp_address_family.py
+++ b/plugins/modules/vyos_bgp_address_family.py
@@ -1163,6 +1163,7 @@ EXAMPLES = """
"""
from ansible.module_utils.basic import AnsibleModule
+
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.bgp_address_family.bgp_address_family import (
Bgp_address_familyArgs,
)
diff --git a/plugins/modules/vyos_bgp_global.py b/plugins/modules/vyos_bgp_global.py
index 49e0a72..1e3578d 100644
--- a/plugins/modules/vyos_bgp_global.py
+++ b/plugins/modules/vyos_bgp_global.py
@@ -1411,6 +1411,7 @@ EXAMPLES = """
"""
from ansible.module_utils.basic import AnsibleModule
+
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.bgp_global.bgp_global import (
Bgp_globalArgs,
)
diff --git a/plugins/modules/vyos_command.py b/plugins/modules/vyos_command.py
index d5ab918..94f16f3 100644
--- a/plugins/modules/vyos_command.py
+++ b/plugins/modules/vyos_command.py
@@ -148,13 +148,12 @@ from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.p
Conditional,
)
from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import (
- transform_commands,
to_lines,
-)
-from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import (
- run_commands,
+ transform_commands,
)
+from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import run_commands
+
def parse_commands(module, warnings):
commands = transform_commands(module)
@@ -216,9 +215,7 @@ def main():
msg = "One or more conditional statements have not been satisfied"
module.fail_json(msg=msg, failed_conditions=failed_conditions)
- result.update(
- {"stdout": responses, "stdout_lines": list(to_lines(responses))}
- )
+ result.update({"stdout": responses, "stdout_lines": list(to_lines(responses))})
module.exit_json(**result)
diff --git a/plugins/modules/vyos_config.py b/plugins/modules/vyos_config.py
index 4b2b31d..2a03d0c 100644
--- a/plugins/modules/vyos_config.py
+++ b/plugins/modules/vyos_config.py
@@ -197,21 +197,17 @@ import re
from ansible.module_utils._text import to_text
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.connection import ConnectionError
+
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import (
- load_config,
get_config,
- run_commands,
-)
-from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import (
get_connection,
+ load_config,
+ run_commands,
)
-
DEFAULT_COMMENT = "configured by vyos_config"
-CONFIG_FILTERS = [
- re.compile(r"set system login user \S+ authentication encrypted-password")
-]
+CONFIG_FILTERS = [re.compile(r"set system login user \S+ authentication encrypted-password")]
def get_candidate(module):
@@ -316,8 +312,7 @@ def run(module, result):
if result.get("filtered"):
result["warnings"].append(
- "Some configuration commands were "
- "removed, please see the filtered key"
+ "Some configuration commands were removed, please see the filtered key"
)
result["changed"] = True
@@ -365,9 +360,7 @@ def main():
result["changed"] = True
run_commands(module, commands=["exit"])
- if result.get("changed") and any(
- (module.params["src"], module.params["lines"])
- ):
+ if result.get("changed") and any((module.params["src"], module.params["lines"])):
msg = (
"To ensure idempotency and correct diff the input configuration lines should be"
" similar to how they appear if present in"
diff --git a/plugins/modules/vyos_facts.py b/plugins/modules/vyos_facts.py
index 5e57821..ae7543c 100644
--- a/plugins/modules/vyos_facts.py
+++ b/plugins/modules/vyos_facts.py
@@ -139,12 +139,13 @@ ansible_net_gather_network_resources:
"""
from ansible.module_utils.basic import AnsibleModule
+
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.facts.facts import (
FactsArgs,
)
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.facts import (
- Facts,
FACT_RESOURCE_SUBSETS,
+ Facts,
)
@@ -156,17 +157,13 @@ def main():
"""
argument_spec = FactsArgs.argument_spec
- module = AnsibleModule(
- argument_spec=argument_spec, supports_check_mode=True
- )
+ module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True)
warnings = []
ansible_facts = {}
if module.params.get("available_network_resources"):
- ansible_facts["available_network_resources"] = sorted(
- FACT_RESOURCE_SUBSETS.keys()
- )
+ ansible_facts["available_network_resources"] = sorted(FACT_RESOURCE_SUBSETS.keys())
result = Facts(module).get_facts()
additional_facts, additional_warnings = result
ansible_facts.update(additional_facts)
diff --git a/plugins/modules/vyos_firewall_global.py b/plugins/modules/vyos_firewall_global.py
index 02f4f60..78db9f3 100644
--- a/plugins/modules/vyos_firewall_global.py
+++ b/plugins/modules/vyos_firewall_global.py
@@ -1185,6 +1185,7 @@ commands:
from ansible.module_utils.basic import AnsibleModule
+
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.firewall_global.firewall_global import (
Firewall_globalArgs,
)
diff --git a/plugins/modules/vyos_firewall_interfaces.py b/plugins/modules/vyos_firewall_interfaces.py
index 7ca936d..32ad09f 100644
--- a/plugins/modules/vyos_firewall_interfaces.py
+++ b/plugins/modules/vyos_firewall_interfaces.py
@@ -1251,6 +1251,7 @@ commands:
from ansible.module_utils.basic import AnsibleModule
+
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.firewall_interfaces.firewall_interfaces import (
Firewall_interfacesArgs,
)
diff --git a/plugins/modules/vyos_firewall_rules.py b/plugins/modules/vyos_firewall_rules.py
index 9730c4a..c219f54 100644
--- a/plugins/modules/vyos_firewall_rules.py
+++ b/plugins/modules/vyos_firewall_rules.py
@@ -1486,6 +1486,7 @@ commands:
from ansible.module_utils.basic import AnsibleModule
+
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.firewall_rules.firewall_rules import (
Firewall_rulesArgs,
)
diff --git a/plugins/modules/vyos_hostname.py b/plugins/modules/vyos_hostname.py
index da22f41..46b692a 100644
--- a/plugins/modules/vyos_hostname.py
+++ b/plugins/modules/vyos_hostname.py
@@ -249,6 +249,7 @@ parsed:
"""
from ansible.module_utils.basic import AnsibleModule
+
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.hostname.hostname import (
HostnameArgs,
)
diff --git a/plugins/modules/vyos_interfaces.py b/plugins/modules/vyos_interfaces.py
index 4429e4b..47ff604 100644
--- a/plugins/modules/vyos_interfaces.py
+++ b/plugins/modules/vyos_interfaces.py
@@ -1097,6 +1097,7 @@ commands:
from ansible.module_utils.basic import AnsibleModule
+
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.interfaces.interfaces import (
InterfacesArgs,
)
diff --git a/plugins/modules/vyos_l3_interfaces.py b/plugins/modules/vyos_l3_interfaces.py
index 7ec9e2a..cdf5842 100644
--- a/plugins/modules/vyos_l3_interfaces.py
+++ b/plugins/modules/vyos_l3_interfaces.py
@@ -537,6 +537,7 @@ commands:
from ansible.module_utils.basic import AnsibleModule
+
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.l3_interfaces.l3_interfaces import (
L3_interfacesArgs,
)
diff --git a/plugins/modules/vyos_lag_interfaces.py b/plugins/modules/vyos_lag_interfaces.py
index a530789..fb36592 100644
--- a/plugins/modules/vyos_lag_interfaces.py
+++ b/plugins/modules/vyos_lag_interfaces.py
@@ -743,6 +743,7 @@ commands:
from ansible.module_utils.basic import AnsibleModule
+
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.lag_interfaces.lag_interfaces import (
Lag_interfacesArgs,
)
diff --git a/plugins/modules/vyos_lldp_global.py b/plugins/modules/vyos_lldp_global.py
index 192aa7f..f59327a 100644
--- a/plugins/modules/vyos_lldp_global.py
+++ b/plugins/modules/vyos_lldp_global.py
@@ -467,6 +467,7 @@ commands:
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,
)
diff --git a/plugins/modules/vyos_lldp_interfaces.py b/plugins/modules/vyos_lldp_interfaces.py
index 43ff75c..9260cb6 100644
--- a/plugins/modules/vyos_lldp_interfaces.py
+++ b/plugins/modules/vyos_lldp_interfaces.py
@@ -635,6 +635,7 @@ commands:
from ansible.module_utils.basic import AnsibleModule
+
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.lldp_interfaces.lldp_interfaces import (
Lldp_interfacesArgs,
)
diff --git a/plugins/modules/vyos_logging.py b/plugins/modules/vyos_logging.py
index 4b3eaaf..7e1dea7 100644
--- a/plugins/modules/vyos_logging.py
+++ b/plugins/modules/vyos_logging.py
@@ -153,7 +153,6 @@ commands:
"""
import re
-
from copy import deepcopy
from ansible.module_utils._text import to_text
@@ -162,6 +161,7 @@ from ansible.module_utils.common.validation import check_required_if
from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import (
remove_default_spec,
)
+
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import (
get_config,
load_config,
@@ -189,9 +189,7 @@ def spec_to_commands(updates, module):
)
else:
commands.append(
- "delete system syslog {0} facility {1} level {2}".format(
- dest, facility, level
- )
+ "delete system syslog {0} facility {1} level {2}".format(dest, facility, level)
)
elif state == "present" and w not in have:
if w["name"]:
@@ -202,9 +200,7 @@ def spec_to_commands(updates, module):
)
else:
commands.append(
- "set system syslog {0} facility {1} level {2}".format(
- dest, facility, level
- )
+ "set system syslog {0} facility {1} level {2}".format(dest, facility, level)
)
return commands
@@ -285,9 +281,7 @@ def map_params_to_obj(module, required_if=None):
def main():
"""main entry point for module execution"""
element_spec = dict(
- dest=dict(
- type="str", choices=["console", "file", "global", "host", "user"]
- ),
+ dest=dict(type="str", choices=["console", "file", "global", "host", "user"]),
name=dict(type="str"),
facility=dict(type="str"),
level=dict(type="str"),
@@ -299,9 +293,7 @@ def main():
# remove default in aggregate spec, to handle common arguments
remove_default_spec(aggregate_spec)
- argument_spec = dict(
- aggregate=dict(type="list", elements="dict", options=aggregate_spec)
- )
+ argument_spec = dict(aggregate=dict(type="list", elements="dict", options=aggregate_spec))
argument_spec.update(element_spec)
diff --git a/plugins/modules/vyos_logging_global.py b/plugins/modules/vyos_logging_global.py
index 6a4e2dd..18248d6 100644
--- a/plugins/modules/vyos_logging_global.py
+++ b/plugins/modules/vyos_logging_global.py
@@ -741,6 +741,7 @@ parsed:
"""
from ansible.module_utils.basic import AnsibleModule
+
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.logging_global.logging_global import (
Logging_globalArgs,
)
diff --git a/plugins/modules/vyos_ntp_global.py b/plugins/modules/vyos_ntp_global.py
index d06d878..10a2170 100644
--- a/plugins/modules/vyos_ntp_global.py
+++ b/plugins/modules/vyos_ntp_global.py
@@ -780,6 +780,7 @@ parsed:
from ansible.module_utils.basic import AnsibleModule
+
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.ntp_global.ntp_global import (
Ntp_globalArgs,
)
diff --git a/plugins/modules/vyos_ospf_interfaces.py b/plugins/modules/vyos_ospf_interfaces.py
index 61ef32e..9a78ebd 100644
--- a/plugins/modules/vyos_ospf_interfaces.py
+++ b/plugins/modules/vyos_ospf_interfaces.py
@@ -888,6 +888,7 @@ EXAMPLES = """
"""
from ansible.module_utils.basic import AnsibleModule
+
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.ospf_interfaces.ospf_interfaces import (
Ospf_interfacesArgs,
)
diff --git a/plugins/modules/vyos_ospfv2.py b/plugins/modules/vyos_ospfv2.py
index 43b0675..863bc6f 100644
--- a/plugins/modules/vyos_ospfv2.py
+++ b/plugins/modules/vyos_ospfv2.py
@@ -1782,6 +1782,7 @@ commands:
from ansible.module_utils.basic import AnsibleModule
+
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.ospfv2.ospfv2 import (
Ospfv2Args,
)
diff --git a/plugins/modules/vyos_ospfv3.py b/plugins/modules/vyos_ospfv3.py
index 8942cef..4ff6106 100644
--- a/plugins/modules/vyos_ospfv3.py
+++ b/plugins/modules/vyos_ospfv3.py
@@ -631,6 +631,7 @@ commands:
from ansible.module_utils.basic import AnsibleModule
+
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.ospfv3.ospfv3 import (
Ospfv3Args,
)
diff --git a/plugins/modules/vyos_ping.py b/plugins/modules/vyos_ping.py
index 7934583..8c0330d 100644
--- a/plugins/modules/vyos_ping.py
+++ b/plugins/modules/vyos_ping.py
@@ -134,12 +134,12 @@ rtt:
sample: {"avg": 2, "max": 8, "min": 1, "mdev": 24}
"""
-from ansible.module_utils.basic import AnsibleModule
-from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import (
- run_commands,
-)
import re
+from ansible.module_utils.basic import AnsibleModule
+
+from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import run_commands
+
def main():
"""main entry point for module execution"""
@@ -150,9 +150,7 @@ def main():
ttl=dict(type="int"),
size=dict(type="int"),
interval=dict(type="int"),
- state=dict(
- type="str", choices=["absent", "present"], default="present"
- ),
+ state=dict(type="str", choices=["absent", "present"], default="present"),
)
module = AnsibleModule(argument_spec=argument_spec)
@@ -170,9 +168,7 @@ def main():
if warnings:
results["warnings"] = warnings
- results["commands"] = [
- build_ping(dest, count, size, interval, source, ttl)
- ]
+ results["commands"] = [build_ping(dest, count, size, interval, source, ttl)]
ping_results = run_commands(module, commands=results["commands"])
ping_results_list = ping_results[0].split("\n")
diff --git a/plugins/modules/vyos_prefix_lists.py b/plugins/modules/vyos_prefix_lists.py
index 8b67caf..ed190d4 100644
--- a/plugins/modules/vyos_prefix_lists.py
+++ b/plugins/modules/vyos_prefix_lists.py
@@ -1294,6 +1294,7 @@ parsed:
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,
)
diff --git a/plugins/modules/vyos_route_maps.py b/plugins/modules/vyos_route_maps.py
index 27fac07..d49261c 100644
--- a/plugins/modules/vyos_route_maps.py
+++ b/plugins/modules/vyos_route_maps.py
@@ -918,6 +918,7 @@ EXAMPLES = """
"""
from ansible.module_utils.basic import AnsibleModule
+
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.route_maps.route_maps import (
Route_mapsArgs,
)
diff --git a/plugins/modules/vyos_snmp_server.py b/plugins/modules/vyos_snmp_server.py
index 1651226..74bae3f 100644
--- a/plugins/modules/vyos_snmp_server.py
+++ b/plugins/modules/vyos_snmp_server.py
@@ -1093,6 +1093,7 @@ parsed:
"""
from ansible.module_utils.basic import AnsibleModule
+
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.snmp_server.snmp_server import (
Snmp_serverArgs,
)
diff --git a/plugins/modules/vyos_static_routes.py b/plugins/modules/vyos_static_routes.py
index 09105ef..0761599 100644
--- a/plugins/modules/vyos_static_routes.py
+++ b/plugins/modules/vyos_static_routes.py
@@ -900,6 +900,7 @@ commands:
from ansible.module_utils.basic import AnsibleModule
+
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.static_routes.static_routes import (
Static_routesArgs,
)
diff --git a/plugins/modules/vyos_system.py b/plugins/modules/vyos_system.py
index fd98507..66a3fd4 100644
--- a/plugins/modules/vyos_system.py
+++ b/plugins/modules/vyos_system.py
@@ -95,6 +95,7 @@ EXAMPLES = """
"""
from ansible.module_utils.basic import AnsibleModule
+
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import (
get_config,
load_config,
@@ -155,13 +156,9 @@ def spec_to_commands(want, have):
commands.append("delete system %s" % device_key)
for config in proposed:
if state == "absent" and config in current:
- commands.append(
- "delete system %s '%s'" % (device_key, config)
- )
+ commands.append("delete system %s '%s'" % (device_key, config))
elif state == "present" and config not in current:
- commands.append(
- "set system %s '%s'" % (device_key, config)
- )
+ commands.append("set system %s '%s'" % (device_key, config))
else:
if state == "absent" and current and proposed:
commands.append("delete system %s" % device_key)
@@ -186,12 +183,8 @@ def main():
host_name=dict(type="str"),
domain_name=dict(type="str"),
domain_search=dict(type="list", elements="str"),
- name_server=dict(
- type="list", aliases=["name_servers"], elements="str"
- ),
- state=dict(
- type="str", default="present", choices=["present", "absent"]
- ),
+ name_server=dict(type="list", aliases=["name_servers"], elements="str"),
+ state=dict(type="str", default="present", choices=["present", "absent"]),
)
module = AnsibleModule(
diff --git a/plugins/modules/vyos_user.py b/plugins/modules/vyos_user.py
index b2e1acc..5494df3 100644
--- a/plugins/modules/vyos_user.py
+++ b/plugins/modules/vyos_user.py
@@ -181,26 +181,24 @@ commands:
"""
import re
-
from copy import deepcopy
from functools import partial
from ansible.module_utils.basic import AnsibleModule
+from ansible.module_utils.six import iteritems
from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import (
remove_default_spec,
)
+
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import (
get_config,
load_config,
)
-from ansible.module_utils.six import iteritems
def validate_level(value, module):
if value not in ("admin", "operator"):
- module.fail_json(
- msg="level must be either admin or operator, got %s" % value
- )
+ module.fail_json(msg="level must be either admin or operator, got %s" % value)
def spec_to_commands(updates, module):
@@ -231,8 +229,7 @@ def spec_to_commands(updates, module):
add(
commands,
want,
- "authentication plaintext-password %s"
- % want["configured_password"],
+ "authentication plaintext-password %s" % want["configured_password"],
)
return commands
@@ -338,9 +335,7 @@ def main():
full_name=dict(),
level=dict(aliases=["role"]),
configured_password=dict(no_log=True),
- update_password=dict(
- default="always", choices=["on_create", "always"]
- ),
+ update_password=dict(default="always", choices=["on_create", "always"]),
state=dict(default="present", choices=["present", "absent"]),
)
diff --git a/plugins/modules/vyos_vlan.py b/plugins/modules/vyos_vlan.py
index 8325366..de20d87 100644
--- a/plugins/modules/vyos_vlan.py
+++ b/plugins/modules/vyos_vlan.py
@@ -164,7 +164,6 @@ commands:
"""
import re
import time
-
from copy import deepcopy
from ansible.module_utils._text import to_text
@@ -173,6 +172,7 @@ from ansible.module_utils.common.validation import check_required_one_of
from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import (
remove_default_spec,
)
+
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import (
load_config,
run_commands,
@@ -204,27 +204,17 @@ def map_obj_to_commands(updates, module):
if obj_in_have:
for obj in obj_in_have:
for i in obj["interfaces"]:
- commands.append(
- "delete interfaces ethernet {0} vif {1}".format(
- i, vlan_id
- )
- )
+ commands.append("delete interfaces ethernet {0} vif {1}".format(i, vlan_id))
elif state == "present":
if not obj_in_have:
if w["interfaces"] and w["vlan_id"]:
for i in w["interfaces"]:
- cmd = "set interfaces ethernet {0} vif {1}".format(
- i, vlan_id
- )
+ cmd = "set interfaces ethernet {0} vif {1}".format(i, vlan_id)
if w["name"]:
- commands.append(
- cmd + " description {0}".format(name)
- )
+ commands.append(cmd + " description {0}".format(name))
elif w["address"]:
- commands.append(
- cmd + " address {0}".format(address)
- )
+ commands.append(cmd + " address {0}".format(address))
else:
commands.append(cmd)
@@ -234,9 +224,7 @@ def map_obj_to_commands(updates, module):
if not obj_in_want:
for i in h["interfaces"]:
commands.append(
- "delete interfaces ethernet {0} vif {1}".format(
- i, h["vlan_id"]
- )
+ "delete interfaces ethernet {0} vif {1}".format(i, h["vlan_id"])
)
return commands
@@ -271,9 +259,7 @@ def map_params_to_obj(module):
"address": module.params["address"],
"state": module.params["state"],
"interfaces": module.params["interfaces"],
- "associated_interfaces": module.params[
- "associated_interfaces"
- ],
+ "associated_interfaces": module.params["associated_interfaces"],
}
)
@@ -338,13 +324,9 @@ def check_declarative_intent_params(want, module, result):
if w.get("associated_interfaces") is None:
continue
for i in w["associated_interfaces"]:
- if (set(obj_interface) - set(w["associated_interfaces"])) != set(
- []
- ):
+ if (set(obj_interface) - set(w["associated_interfaces"])) != set([]):
module.fail_json(
- msg="Interface {0} not configured on vlan {1}".format(
- i, w["vlan_id"]
- )
+ msg="Interface {0} not configured on vlan {1}".format(i, w["vlan_id"])
)
diff --git a/plugins/terminal/vyos.py b/plugins/terminal/vyos.py
index ef036ac..b9e84d7 100644
--- a/plugins/terminal/vyos.py
+++ b/plugins/terminal/vyos.py
@@ -24,9 +24,7 @@ import os
import re
from ansible.errors import AnsibleConnectionFailure
-from ansible_collections.ansible.netcommon.plugins.plugin_utils.terminal_base import (
- TerminalBase,
-)
+from ansible_collections.ansible.netcommon.plugins.plugin_utils.terminal_base import TerminalBase
class TerminalModule(TerminalBase):
@@ -71,8 +69,6 @@ class TerminalModule(TerminalBase):
try:
for cmd in (b"set terminal length 0", b"set terminal width 512"):
self._exec_cli_command(cmd)
- self._exec_cli_command(
- b"set terminal length %d" % self.terminal_length
- )
+ self._exec_cli_command(b"set terminal length %d" % self.terminal_length)
except AnsibleConnectionFailure:
raise AnsibleConnectionFailure("unable to set terminal parameters")