summaryrefslogtreecommitdiff
path: root/plugins/modules
diff options
context:
space:
mode:
authoransible-zuul[bot] <48994755+ansible-zuul[bot]@users.noreply.github.com>2019-08-09 19:11:48 +0000
committerGitHub <noreply@github.com>2019-08-09 19:11:48 +0000
commit66a01fb3cdcedff9205b2295870a7e1629bbae69 (patch)
treebe8d5d5490ec5c49a2f33b83184e35d58d635895 /plugins/modules
parentfbe294b702e757252a66f64edf66bce060e87494 (diff)
parent29c342fa51c7a9866366cfc20968be7270e02fc5 (diff)
downloadvyos.vyos-66a01fb3cdcedff9205b2295870a7e1629bbae69.tar.gz
vyos.vyos-66a01fb3cdcedff9205b2295870a7e1629bbae69.zip
Merge pull request #10 from ansible-network/bt_79
79 Reviewed-by: Paul Belanger https://github.com/pabelanger
Diffstat (limited to 'plugins/modules')
-rw-r--r--plugins/modules/_vyos_interface.py17
-rw-r--r--plugins/modules/_vyos_l3_interface.py41
-rw-r--r--plugins/modules/vyos_banner.py22
-rw-r--r--plugins/modules/vyos_command.py9
-rw-r--r--plugins/modules/vyos_config.py4
-rw-r--r--plugins/modules/vyos_facts.py4
-rw-r--r--plugins/modules/vyos_linkagg.py41
-rw-r--r--plugins/modules/vyos_lldp.py7
-rw-r--r--plugins/modules/vyos_lldp_interface.py19
-rw-r--r--plugins/modules/vyos_logging.py15
-rw-r--r--plugins/modules/vyos_ping.py8
-rw-r--r--plugins/modules/vyos_static_route.py4
-rw-r--r--plugins/modules/vyos_system.py12
-rw-r--r--plugins/modules/vyos_user.py8
-rw-r--r--plugins/modules/vyos_vlan.py28
15 files changed, 181 insertions, 58 deletions
diff --git a/plugins/modules/_vyos_interface.py b/plugins/modules/_vyos_interface.py
index ee82107..5128574 100644
--- a/plugins/modules/_vyos_interface.py
+++ b/plugins/modules/_vyos_interface.py
@@ -175,7 +175,10 @@ from time import sleep
from ansible.module_utils._text import to_text
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.connection import exec_command
-from ansible.module_utils.network.common.utils import conditional, remove_default_spec
+from ansible.module_utils.network.common.utils import (
+ conditional,
+ remove_default_spec,
+)
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import (
load_config,
get_config,
@@ -218,7 +221,9 @@ def map_obj_to_commands(updates):
if value and value != obj_in_have.get(item):
if item == "description":
value = "'" + str(value) + "'"
- commands.append(set_interface + " " + item + " " + str(value))
+ commands.append(
+ set_interface + " " + item + " " + str(value)
+ )
if disable and not obj_in_have.get("disable", False):
commands.append(set_interface + " disable")
@@ -231,7 +236,9 @@ def map_obj_to_commands(updates):
if value:
if item == "description":
value = "'" + str(value) + "'"
- commands.append(set_interface + " " + item + " " + str(value))
+ commands.append(
+ set_interface + " " + item + " " + str(value)
+ )
if disable:
commands.append(set_interface + " disable")
@@ -399,7 +406,9 @@ def main():
enabled=dict(default=True, type="bool"),
neighbors=dict(type="list", elements="dict", options=neighbors_spec),
delay=dict(default=10, type="int"),
- state=dict(default="present", choices=["present", "absent", "up", "down"]),
+ state=dict(
+ default="present", choices=["present", "absent", "up", "down"]
+ ),
)
aggregate_spec = deepcopy(element_spec)
diff --git a/plugins/modules/_vyos_l3_interface.py b/plugins/modules/_vyos_l3_interface.py
index 430217c..a504e7c 100644
--- a/plugins/modules/_vyos_l3_interface.py
+++ b/plugins/modules/_vyos_l3_interface.py
@@ -101,7 +101,10 @@ import re
from copy import deepcopy
from ansible.module_utils.basic import AnsibleModule
-from ansible.module_utils.network.common.utils import is_masklen, validate_ip_address
+from ansible.module_utils.network.common.utils import (
+ is_masklen,
+ validate_ip_address,
+)
from ansible.module_utils.network.common.utils import remove_default_spec
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import (
load_config,
@@ -154,30 +157,48 @@ def map_obj_to_commands(updates, module):
obj_in_have = search_obj_in_list(name, have)
if state == "absent" and obj_in_have:
- if not ipv4 and not ipv6 and (obj_in_have["ipv4"] or obj_in_have["ipv6"]):
+ if (
+ not ipv4
+ and not ipv6
+ and (obj_in_have["ipv4"] or obj_in_have["ipv6"])
+ ):
if name == "lo":
commands.append("delete interfaces loopback lo address")
else:
- commands.append("delete interfaces ethernet " + name + " address")
+ commands.append(
+ "delete interfaces ethernet " + name + " address"
+ )
else:
if ipv4 and ipv4 in obj_in_have["ipv4"]:
if name == "lo":
- commands.append("delete interfaces loopback lo address " + ipv4)
+ commands.append(
+ "delete interfaces loopback lo address " + ipv4
+ )
else:
commands.append(
- "delete interfaces ethernet " + name + " address " + ipv4
+ "delete interfaces ethernet "
+ + name
+ + " address "
+ + ipv4
)
if ipv6 and ipv6 in obj_in_have["ipv6"]:
if name == "lo":
- commands.append("delete interfaces loopback lo address " + ipv6)
+ commands.append(
+ "delete interfaces loopback lo address " + ipv6
+ )
else:
commands.append(
- "delete interfaces ethernet " + name + " address " + ipv6
+ "delete interfaces ethernet "
+ + name
+ + " address "
+ + ipv6
)
elif state == "present" and obj_in_have:
if ipv4 and ipv4 not in obj_in_have["ipv4"]:
if name == "lo":
- commands.append("set interfaces loopback lo address " + ipv4)
+ commands.append(
+ "set interfaces loopback lo address " + ipv4
+ )
else:
commands.append(
"set interfaces ethernet " + name + " address " + ipv4
@@ -185,7 +206,9 @@ def map_obj_to_commands(updates, module):
if ipv6 and ipv6 not in obj_in_have["ipv6"]:
if name == "lo":
- commands.append("set interfaces loopback lo address " + ipv6)
+ commands.append(
+ "set interfaces loopback lo address " + ipv6
+ )
else:
commands.append(
"set interfaces ethernet " + name + " address " + ipv6
diff --git a/plugins/modules/vyos_banner.py b/plugins/modules/vyos_banner.py
index 6738624..447c174 100644
--- a/plugins/modules/vyos_banner.py
+++ b/plugins/modules/vyos_banner.py
@@ -105,15 +105,21 @@ 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)
@@ -162,7 +168,9 @@ def main():
required_if = [("state", "present", ("text",))]
module = AnsibleModule(
- argument_spec=argument_spec, required_if=required_if, supports_check_mode=True
+ argument_spec=argument_spec,
+ required_if=required_if,
+ supports_check_mode=True,
)
warnings = list()
diff --git a/plugins/modules/vyos_command.py b/plugins/modules/vyos_command.py
index a3593ba..b812fae 100644
--- a/plugins/modules/vyos_command.py
+++ b/plugins/modules/vyos_command.py
@@ -143,7 +143,10 @@ import time
from ansible.module_utils._text import to_text
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.network.common.parsing import Conditional
-from ansible.module_utils.network.common.utils import transform_commands, to_lines
+from ansible.module_utils.network.common.utils import (
+ transform_commands,
+ to_lines,
+)
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import (
run_commands,
)
@@ -215,7 +218,9 @@ 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 530fdc3..2956063 100644
--- a/plugins/modules/vyos_config.py
+++ b/plugins/modules/vyos_config.py
@@ -275,7 +275,9 @@ def run(module, result):
connection = get_connection(module)
try:
response = connection.get_diff(
- candidate=candidate, running=config, diff_match=module.params["match"]
+ candidate=candidate,
+ running=config,
+ diff_match=module.params["match"],
)
except ConnectionError as exc:
module.fail_json(msg=to_text(exc, errors="surrogate_then_replace"))
diff --git a/plugins/modules/vyos_facts.py b/plugins/modules/vyos_facts.py
index 1e63c5d..1fa5214 100644
--- a/plugins/modules/vyos_facts.py
+++ b/plugins/modules/vyos_facts.py
@@ -160,7 +160,9 @@ def main():
argument_spec.update(vyos_argument_spec)
- module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True)
+ module = AnsibleModule(
+ argument_spec=argument_spec, supports_check_mode=True
+ )
warnings = [
"default value for `gather_subset` "
diff --git a/plugins/modules/vyos_linkagg.py b/plugins/modules/vyos_linkagg.py
index 7793b6d..2fc8d66 100644
--- a/plugins/modules/vyos_linkagg.py
+++ b/plugins/modules/vyos_linkagg.py
@@ -139,12 +139,16 @@ def map_obj_to_commands(updates, module):
if state == "absent":
if obj_in_have:
for m in obj_in_have["members"]:
- commands.append("delete interfaces ethernet " + m + " bond-group")
+ commands.append(
+ "delete interfaces ethernet " + m + " bond-group"
+ )
commands.append("delete interfaces bonding " + name)
else:
if not obj_in_have:
- commands.append("set interfaces bonding " + name + " mode " + mode)
+ commands.append(
+ "set interfaces bonding " + name + " mode " + mode
+ )
for m in members:
commands.append(
@@ -152,21 +156,31 @@ def map_obj_to_commands(updates, module):
)
if state == "down":
- commands.append("set interfaces bonding " + name + " disable")
+ commands.append(
+ "set interfaces bonding " + name + " disable"
+ )
else:
if mode != obj_in_have["mode"]:
- commands.append("set interfaces bonding " + name + " mode " + mode)
+ commands.append(
+ "set interfaces bonding " + name + " mode " + mode
+ )
- missing_members = list(set(members) - set(obj_in_have["members"]))
+ missing_members = list(
+ set(members) - set(obj_in_have["members"])
+ )
for m in missing_members:
commands.append(
"set interfaces ethernet " + m + " bond-group " + name
)
if state == "down" and obj_in_have["state"] == "up":
- commands.append("set interfaces bonding " + name + " disable")
+ commands.append(
+ "set interfaces bonding " + name + " disable"
+ )
elif state == "up" and obj_in_have["state"] == "down":
- commands.append("delete interfaces bonding " + name + " disable")
+ commands.append(
+ "delete interfaces bonding " + name + " disable"
+ )
return commands
@@ -189,7 +203,14 @@ def map_config_to_obj(module):
else:
members = []
- obj.append({"name": name, "mode": mode, "members": members, "state": state})
+ obj.append(
+ {
+ "name": name,
+ "mode": mode,
+ "members": members,
+ "state": state,
+ }
+ )
return obj
@@ -236,7 +257,9 @@ def main():
default="802.3ad",
),
members=dict(type="list"),
- state=dict(default="present", choices=["present", "absent", "up", "down"]),
+ state=dict(
+ default="present", choices=["present", "absent", "up", "down"]
+ ),
)
aggregate_spec = deepcopy(element_spec)
diff --git a/plugins/modules/vyos_lldp.py b/plugins/modules/vyos_lldp.py
index 69a62a3..18a013f 100644
--- a/plugins/modules/vyos_lldp.py
+++ b/plugins/modules/vyos_lldp.py
@@ -90,13 +90,16 @@ def main():
argument_spec = dict(
interfaces=dict(type="list"),
state=dict(
- default="present", choices=["present", "absent", "enabled", "disabled"]
+ default="present",
+ choices=["present", "absent", "enabled", "disabled"],
),
)
argument_spec.update(vyos_argument_spec)
- module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True)
+ module = AnsibleModule(
+ argument_spec=argument_spec, supports_check_mode=True
+ )
warnings = list()
diff --git a/plugins/modules/vyos_lldp_interface.py b/plugins/modules/vyos_lldp_interface.py
index 23d1eab..5d25ea3 100644
--- a/plugins/modules/vyos_lldp_interface.py
+++ b/plugins/modules/vyos_lldp_interface.py
@@ -133,13 +133,19 @@ def map_obj_to_commands(updates, module):
and obj_in_have["state"] == "disabled"
and state == "enabled"
):
- commands.append("delete service lldp interface " + name + " disable")
+ commands.append(
+ "delete service lldp interface " + name + " disable"
+ )
elif state == "disabled":
if not obj_in_have:
commands.append("set service lldp interface " + name)
- commands.append("set service lldp interface " + name + " disable")
+ commands.append(
+ "set service lldp interface " + name + " disable"
+ )
elif obj_in_have and obj_in_have["state"] != "disabled":
- commands.append("set service lldp interface " + name + " disable")
+ commands.append(
+ "set service lldp interface " + name + " disable"
+ )
return commands
@@ -179,7 +185,9 @@ def map_params_to_obj(module):
obj.append(item.copy())
else:
- obj.append({"name": module.params["name"], "state": module.params["state"]})
+ obj.append(
+ {"name": module.params["name"], "state": module.params["state"]}
+ )
return obj
@@ -190,7 +198,8 @@ def main():
element_spec = dict(
name=dict(),
state=dict(
- default="present", choices=["present", "absent", "enabled", "disabled"]
+ default="present",
+ choices=["present", "absent", "enabled", "disabled"],
),
)
diff --git a/plugins/modules/vyos_logging.py b/plugins/modules/vyos_logging.py
index 1fd0ca2..fa0d1cf 100644
--- a/plugins/modules/vyos_logging.py
+++ b/plugins/modules/vyos_logging.py
@@ -192,7 +192,12 @@ def config_to_dict(module):
level = match.group(1).strip("'")
obj.append(
- {"dest": dest, "name": name, "facility": facility, "level": level}
+ {
+ "dest": dest,
+ "name": name,
+ "facility": facility,
+ "level": level,
+ }
)
return obj
@@ -232,7 +237,9 @@ 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"),
@@ -260,7 +267,9 @@ def main():
]
module = AnsibleModule(
- argument_spec=argument_spec, required_if=required_if, supports_check_mode=True
+ argument_spec=argument_spec,
+ required_if=required_if,
+ supports_check_mode=True,
)
warnings = list()
diff --git a/plugins/modules/vyos_ping.py b/plugins/modules/vyos_ping.py
index 9e99d48..c770804 100644
--- a/plugins/modules/vyos_ping.py
+++ b/plugins/modules/vyos_ping.py
@@ -154,7 +154,9 @@ 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"
+ ),
)
argument_spec.update(vyos_argument_spec)
@@ -174,7 +176,9 @@ 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_static_route.py b/plugins/modules/vyos_static_route.py
index dfb1d21..734a1b0 100644
--- a/plugins/modules/vyos_static_route.py
+++ b/plugins/modules/vyos_static_route.py
@@ -132,7 +132,9 @@ def spec_to_commands(updates, module):
del w["state"]
if state == "absent" and w in have:
- commands.append("delete protocols static route %s/%s" % (prefix, mask))
+ commands.append(
+ "delete protocols static route %s/%s" % (prefix, mask)
+ )
elif state == "present" and w not in have:
cmd = "set protocols static route %s/%s next-hop %s" % (
prefix,
diff --git a/plugins/modules/vyos_system.py b/plugins/modules/vyos_system.py
index 9984154..4f0d5db 100644
--- a/plugins/modules/vyos_system.py
+++ b/plugins/modules/vyos_system.py
@@ -158,9 +158,13 @@ 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,7 +190,9 @@ def main():
domain_name=dict(type="str"),
domain_search=dict(type="list"),
name_server=dict(type="list", aliases=["name_servers"]),
- state=dict(type="str", default="present", choices=["present", "absent"]),
+ state=dict(
+ type="str", default="present", choices=["present", "absent"]
+ ),
)
argument_spec.update(vyos_argument_spec)
diff --git a/plugins/modules/vyos_user.py b/plugins/modules/vyos_user.py
index 74ec720..a309d2a 100644
--- a/plugins/modules/vyos_user.py
+++ b/plugins/modules/vyos_user.py
@@ -152,7 +152,9 @@ from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import
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):
@@ -292,7 +294,9 @@ 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 983a50a..7c3fa69 100644
--- a/plugins/modules/vyos_vlan.py
+++ b/plugins/modules/vyos_vlan.py
@@ -162,18 +162,26 @@ def map_obj_to_commands(updates, module):
for obj in obj_in_have:
for i in obj["interfaces"]:
commands.append(
- "delete interfaces ethernet {0} vif {1}".format(i, vlan_id)
+ "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)
@@ -183,7 +191,9 @@ 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
@@ -215,7 +225,9 @@ 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"
+ ],
}
)
@@ -281,7 +293,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"]