summaryrefslogtreecommitdiff
path: root/plugins/module_utils/network
diff options
context:
space:
mode:
authorRohit Thakur <rohitthakur2590@outlook.com>2020-04-29 23:59:44 +0530
committerRohit Thakur <rohitthakur2590@outlook.com>2020-04-29 23:59:44 +0530
commitd14344f56803e0564f273e9451a76ef84f8b1313 (patch)
tree675d749d2ac9d3570ad78f28a2c5377c38b8801e /plugins/module_utils/network
parent77e8b041b2983415ac36eb6264f6e385ac87b074 (diff)
downloadvyos.vyos-d14344f56803e0564f273e9451a76ef84f8b1313.tar.gz
vyos.vyos-d14344f56803e0564f273e9451a76ef84f8b1313.zip
new states added
Signed-off-by: Rohit Thakur <rohitthakur2590@outlook.com>
Diffstat (limited to 'plugins/module_utils/network')
-rw-r--r--plugins/module_utils/network/vyos/argspec/lag_interfaces/lag_interfaces.py12
-rw-r--r--plugins/module_utils/network/vyos/config/lag_interfaces/lag_interfaces.py72
-rw-r--r--plugins/module_utils/network/vyos/facts/lag_interfaces/lag_interfaces.py26
3 files changed, 66 insertions, 44 deletions
diff --git a/plugins/module_utils/network/vyos/argspec/lag_interfaces/lag_interfaces.py b/plugins/module_utils/network/vyos/argspec/lag_interfaces/lag_interfaces.py
index 97c5d5a2..6cfdabf1 100644
--- a/plugins/module_utils/network/vyos/argspec/lag_interfaces/lag_interfaces.py
+++ b/plugins/module_utils/network/vyos/argspec/lag_interfaces/lag_interfaces.py
@@ -19,7 +19,6 @@
# builder template.
#
#############################################
-
"""
The arg spec for the vyos_lag_interfaces module
"""
@@ -72,8 +71,17 @@ class Lag_interfacesArgs(object): # pylint: disable=R0903
},
"type": "list",
},
+ "running_config": {"type": "str"},
"state": {
- "choices": ["merged", "replaced", "overridden", "deleted"],
+ "choices": [
+ "merged",
+ "replaced",
+ "overridden",
+ "deleted",
+ "rendered",
+ "gathered",
+ "parsed",
+ ],
"default": "merged",
"type": "str",
},
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 2a9efd99..452670f1 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
@@ -56,14 +56,14 @@ class Lag_interfaces(ConfigBase):
def __init__(self, module):
super(Lag_interfaces, self).__init__(module)
- def get_lag_interfaces_facts(self):
+ def get_lag_interfaces_facts(self, data=None):
""" Get the 'facts' (the current configuration)
:rtype: A dictionary
:returns: The current configuration as a dictionary
"""
facts, _warnings = Facts(self._module).get_facts(
- self.gather_subset, self.gather_network_resources
+ self.gather_subset, self.gather_network_resources, data=data
)
lag_interfaces_facts = facts["ansible_network_resources"].get(
"lag_interfaces"
@@ -79,27 +79,47 @@ class Lag_interfaces(ConfigBase):
:returns: The result from module execution
"""
result = {"changed": False}
- commands = list()
warnings = list()
- existing_lag_interfaces_facts = self.get_lag_interfaces_facts()
- commands.extend(self.set_config(existing_lag_interfaces_facts))
- if commands:
- if self._module.check_mode:
- resp = self._connection.edit_config(commands, commit=False)
- else:
- resp = self._connection.edit_config(commands)
- result["changed"] = True
+ commands = list()
+
+ if self.state in self.ACTION_STATES:
+ existing_lag_interfaces_facts = self.get_lag_interfaces_facts()
+ else:
+ existing_lag_interfaces_facts = []
- result["commands"] = commands
+ if self.state in self.ACTION_STATES or self.state == "rendered":
+ commands.extend(self.set_config(existing_lag_interfaces_facts))
- if self._module._diff:
- result["diff"] = resp["diff"] if result["changed"] else None
+ if commands and self.state in self.ACTION_STATES:
+ if not self._module.check_mode:
+ self._connection.edit_config(commands)
+ result["changed"] = True
- changed_lag_interfaces_facts = self.get_lag_interfaces_facts()
+ if self.state in self.ACTION_STATES:
+ result["commands"] = commands
+
+ if self.state in self.ACTION_STATES or self.state == "gathered":
+ changed_lag_interfaces_facts = self.get_lag_interfaces_facts()
+ elif self.state == "rendered":
+ result["rendered"] = commands
+ elif self.state == "parsed":
+ running_config = self._module.params["running_config"]
+ if not running_config:
+ 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
+ )
+ else:
+ changed_lag_interfaces_facts = []
- result["before"] = existing_lag_interfaces_facts
- if result["changed"]:
- result["after"] = changed_lag_interfaces_facts
+ if self.state in self.ACTION_STATES:
+ result["before"] = existing_lag_interfaces_facts
+ if result["changed"]:
+ result["after"] = changed_lag_interfaces_facts
+ elif self.state == "gathered":
+ result["gathered"] = changed_lag_interfaces_facts
result["warnings"] = warnings
return result
@@ -127,16 +147,18 @@ class Lag_interfaces(ConfigBase):
to the desired configuration
"""
commands = []
- state = self._module.params["state"]
- if state in ("merged", "replaced", "overridden") 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(
- state
+ self.state
)
)
- if state == "overridden":
+ if self.state == "overridden":
commands.extend(self._state_overridden(want, have))
- elif state == "deleted":
+ elif self.state == "deleted":
if want:
for want_item in want:
name = want_item["name"]
@@ -149,9 +171,9 @@ class Lag_interfaces(ConfigBase):
for want_item in want:
name = want_item["name"]
obj_in_have = search_obj_in_list(name, have)
- if state == "merged":
+ if self.state in ("merged", "rendered"):
commands.extend(self._state_merged(want_item, obj_in_have))
- elif state == "replaced":
+ elif self.state == "replaced":
commands.extend(
self._state_replaced(want_item, obj_in_have)
)
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 9201e5c6..90562947 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
@@ -12,6 +12,7 @@ based on the configuration.
from __future__ import absolute_import, division, print_function
__metaclass__ = type
+
from re import findall, search, M
from copy import deepcopy
@@ -59,30 +60,21 @@ class Lag_interfacesFacts(object):
lag_regex = r" %s .+$" % lag
cfg = findall(lag_regex, data, M)
obj = self.render_config(cfg)
-
- output = connection.run_commands(
- ["show interfaces bonding " + lag + " slaves"]
- )
- lines = output[0].splitlines()
members = []
member = {}
- if len(lines) > 1:
- for line in lines[2:]:
- splitted_line = line.split()
-
- if len(splitted_line) > 1:
- member["member"] = splitted_line[0]
- members.append(member)
- else:
- members = []
- member = {}
+
+ group_regex = r".*eth.* '%s'" % lag
+ g_cfg = findall(group_regex, data, M)
+ for item in g_cfg:
+ output = search("^set interfaces ethernet (\\S+)", item, M)
+ if output:
+ member["member"] = output.group(1).strip("'")
+ members.append(member)
obj["name"] = lag.strip("'")
if members:
obj["members"] = members
-
if obj:
objs.append(obj)
-
facts = {}
if objs:
facts["lag_interfaces"] = []