summaryrefslogtreecommitdiff
path: root/plugins/module_utils
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/module_utils')
-rw-r--r--plugins/module_utils/network/vyos/argspec/interfaces/interfaces.py11
-rw-r--r--plugins/module_utils/network/vyos/argspec/l3_interfaces/l3_interfaces.py12
-rw-r--r--plugins/module_utils/network/vyos/argspec/lag_interfaces/lag_interfaces.py12
-rw-r--r--plugins/module_utils/network/vyos/argspec/lldp_global/lldp_global.py11
-rw-r--r--plugins/module_utils/network/vyos/argspec/lldp_interfaces/lldp_interfaces.py11
-rw-r--r--plugins/module_utils/network/vyos/config/interfaces/interfaces.py70
-rw-r--r--plugins/module_utils/network/vyos/config/l3_interfaces/l3_interfaces.py60
-rw-r--r--plugins/module_utils/network/vyos/config/lag_interfaces/lag_interfaces.py72
-rw-r--r--plugins/module_utils/network/vyos/config/lldp_global/lldp_global.py58
-rw-r--r--plugins/module_utils/network/vyos/config/lldp_interfaces/lldp_interfaces.py75
-rw-r--r--plugins/module_utils/network/vyos/config/static_routes/static_routes.py8
-rw-r--r--plugins/module_utils/network/vyos/facts/l3_interfaces/l3_interfaces.py7
-rw-r--r--plugins/module_utils/network/vyos/facts/lag_interfaces/lag_interfaces.py26
13 files changed, 285 insertions, 148 deletions
diff --git a/plugins/module_utils/network/vyos/argspec/interfaces/interfaces.py b/plugins/module_utils/network/vyos/argspec/interfaces/interfaces.py
index 3542cb19..fd8b6123 100644
--- a/plugins/module_utils/network/vyos/argspec/interfaces/interfaces.py
+++ b/plugins/module_utils/network/vyos/argspec/interfaces/interfaces.py
@@ -61,8 +61,17 @@ class InterfacesArgs(object): # pylint: disable=R0903
},
"type": "list",
},
+ "running_config": {"type": "str"},
"state": {
- "choices": ["merged", "replaced", "overridden", "deleted"],
+ "choices": [
+ "merged",
+ "replaced",
+ "overridden",
+ "deleted",
+ "rendered",
+ "parsed",
+ "gathered",
+ ],
"default": "merged",
"type": "str",
},
diff --git a/plugins/module_utils/network/vyos/argspec/l3_interfaces/l3_interfaces.py b/plugins/module_utils/network/vyos/argspec/l3_interfaces/l3_interfaces.py
index 91434e4b..2f1dfe45 100644
--- a/plugins/module_utils/network/vyos/argspec/l3_interfaces/l3_interfaces.py
+++ b/plugins/module_utils/network/vyos/argspec/l3_interfaces/l3_interfaces.py
@@ -25,7 +25,6 @@
The arg spec for the vyos_l3_interfaces module
"""
-
from __future__ import absolute_import, division, print_function
__metaclass__ = type
@@ -73,8 +72,17 @@ class L3_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/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/argspec/lldp_global/lldp_global.py b/plugins/module_utils/network/vyos/argspec/lldp_global/lldp_global.py
index 84bbc00c..6205fd77 100644
--- a/plugins/module_utils/network/vyos/argspec/lldp_global/lldp_global.py
+++ b/plugins/module_utils/network/vyos/argspec/lldp_global/lldp_global.py
@@ -19,7 +19,6 @@
# builder template.
#
#############################################
-
"""
The arg spec for the vyos_lldp_global module
"""
@@ -48,8 +47,16 @@ class Lldp_globalArgs(object): # pylint: disable=R0903
},
"type": "dict",
},
+ "running_config": {"type": "str"},
"state": {
- "choices": ["merged", "replaced", "deleted"],
+ "choices": [
+ "merged",
+ "replaced",
+ "deleted",
+ "rendered",
+ "parsed",
+ "gathered",
+ ],
"default": "merged",
"type": "str",
},
diff --git a/plugins/module_utils/network/vyos/argspec/lldp_interfaces/lldp_interfaces.py b/plugins/module_utils/network/vyos/argspec/lldp_interfaces/lldp_interfaces.py
index 2976fc09..109ea430 100644
--- a/plugins/module_utils/network/vyos/argspec/lldp_interfaces/lldp_interfaces.py
+++ b/plugins/module_utils/network/vyos/argspec/lldp_interfaces/lldp_interfaces.py
@@ -81,8 +81,17 @@ class Lldp_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/interfaces/interfaces.py b/plugins/module_utils/network/vyos/config/interfaces/interfaces.py
index deb504c2..51bf98e3 100644
--- a/plugins/module_utils/network/vyos/config/interfaces/interfaces.py
+++ b/plugins/module_utils/network/vyos/config/interfaces/interfaces.py
@@ -13,7 +13,6 @@ 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,
@@ -49,14 +48,14 @@ class Interfaces(ConfigBase):
def __init__(self, module):
super(Interfaces, self).__init__(module)
- def get_interfaces_facts(self):
+ def get_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
)
interfaces_facts = facts["ansible_network_resources"].get("interfaces")
if not interfaces_facts:
@@ -72,25 +71,42 @@ class Interfaces(ConfigBase):
commands = list()
warnings = list()
- existing_interfaces_facts = self.get_interfaces_facts()
- commands.extend(self.set_config(existing_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
+ if self.state in self.ACTION_STATES:
+ existing_interfaces_facts = self.get_interfaces_facts()
+ else:
+ existing_interfaces_facts = []
- result["commands"] = commands
+ if self.state in self.ACTION_STATES or self.state == "rendered":
+ commands.extend(self.set_config(existing_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_interfaces_facts = self.get_interfaces_facts()
+ if self.state in self.ACTION_STATES:
+ result["commands"] = commands
+
+ if self.state in self.ACTION_STATES or self.state == "gathered":
+ changed_interfaces_facts = self.get_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_interfaces_facts(data=running_config)
+ else:
+ changed_interfaces_facts = []
- result["before"] = existing_interfaces_facts
- if result["changed"]:
- result["after"] = changed_interfaces_facts
+ if self.state in self.ACTION_STATES:
+ result["before"] = existing_interfaces_facts
+ if result["changed"]:
+ result["after"] = changed_interfaces_facts
+ elif self.state == "gathered":
+ result["gathered"] = changed_interfaces_facts
result["warnings"] = warnings
return result
@@ -118,19 +134,21 @@ class 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=want, have=have))
- elif state == "deleted":
+ elif self.state == "deleted":
if not want:
for intf in have:
commands.extend(
@@ -146,12 +164,12 @@ class Interfaces(ConfigBase):
obj_in_have = search_obj_in_list(name, have)
if not obj_in_have:
- obj_in_have = {"name": item["name"]}
+ obj_in_have = {"name": name}
- elif state == "merged":
+ if self.state in ("merged", "rendered"):
commands.extend(self._state_merged(item, obj_in_have))
- elif state == "replaced":
+ elif self.state == "replaced":
commands.extend(self._state_replaced(item, obj_in_have))
return commands
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 a23e417f..122cc1eb 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
@@ -52,14 +52,14 @@ class L3_interfaces(ConfigBase):
def __init__(self, module):
super(L3_interfaces, self).__init__(module)
- def get_l3_interfaces_facts(self):
+ def get_l3_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
)
l3_interfaces_facts = facts["ansible_network_resources"].get(
"l3_interfaces"
@@ -78,25 +78,44 @@ class L3_interfaces(ConfigBase):
warnings = list()
commands = list()
- existing_l3_interfaces_facts = self.get_l3_interfaces_facts()
- commands.extend(self.set_config(existing_l3_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
+ if self.state in self.ACTION_STATES:
+ existing_l3_interfaces_facts = self.get_l3_interfaces_facts()
+ else:
+ existing_l3_interfaces_facts = []
- result["commands"] = commands
+ if self.state in self.ACTION_STATES or self.state == "rendered":
+ commands.extend(self.set_config(existing_l3_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_l3_interfaces_facts = self.get_l3_interfaces_facts()
+ if self.state in self.ACTION_STATES:
+ result["commands"] = commands
+
+ if self.state in self.ACTION_STATES or self.state == "gathered":
+ changed_l3_interfaces_facts = self.get_l3_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_l3_interfaces_facts(
+ data=running_config
+ )
+ else:
+ changed_l3_interfaces_facts = []
- result["before"] = existing_l3_interfaces_facts
- if result["changed"]:
- result["after"] = changed_l3_interfaces_facts
+ if self.state in self.ACTION_STATES:
+ result["before"] = existing_l3_interfaces_facts
+ if result["changed"]:
+ result["after"] = changed_l3_interfaces_facts
+ elif self.state == "gathered":
+ result["gathered"] = changed_l3_interfaces_facts
result["warnings"] = warnings
return result
@@ -126,7 +145,10 @@ class L3_interfaces(ConfigBase):
commands = []
state = self._module.params["state"]
- if state in ("merged", "replaced", "overridden") 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
@@ -154,7 +176,7 @@ class L3_interfaces(ConfigBase):
if not obj_in_have:
obj_in_have = {"name": item["name"]}
- if state == "merged":
+ if state in ("merged", "rendered"):
commands.extend(self._state_merged(item, obj_in_have))
elif state == "replaced":
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/config/lldp_global/lldp_global.py b/plugins/module_utils/network/vyos/config/lldp_global/lldp_global.py
index 010e96dd..c70d27ff 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
@@ -47,20 +47,20 @@ class Lldp_global(ConfigBase):
def __init__(self, module):
super(Lldp_global, self).__init__(module)
- def get_lldp_global_facts(self):
+ def get_lldp_global_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
)
lldp_global_facts = facts["ansible_network_resources"].get(
"lldp_global"
)
if not lldp_global_facts:
- return {}
+ return []
return lldp_global_facts
def execute_module(self):
@@ -70,22 +70,45 @@ class Lldp_global(ConfigBase):
:returns: The result from module execution
"""
result = {"changed": False}
- commands = list()
warnings = list()
+ commands = list()
+
+ if self.state in self.ACTION_STATES:
+ existing_lldp_global_facts = self.get_lldp_global_facts()
+ else:
+ existing_lldp_global_facts = []
- existing_lldp_global_facts = self.get_lldp_global_facts()
- commands.extend(self.set_config(existing_lldp_global_facts))
- if commands:
+ if self.state in self.ACTION_STATES or self.state == "rendered":
+ commands.extend(self.set_config(existing_lldp_global_facts))
+
+ if commands and self.state in self.ACTION_STATES:
if not self._module.check_mode:
self._connection.edit_config(commands)
result["changed"] = True
- result["commands"] = commands
- changed_lldp_global_facts = self.get_lldp_global_facts()
+ if self.state in self.ACTION_STATES:
+ result["commands"] = commands
+
+ if self.state in self.ACTION_STATES or self.state == "gathered":
+ changed_lldp_global_facts = self.get_lldp_global_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_lldp_global_facts(data=running_config)
+ else:
+ changed_lldp_global_facts = []
- result["before"] = existing_lldp_global_facts
- if result["changed"]:
- result["after"] = changed_lldp_global_facts
+ if self.state in self.ACTION_STATES:
+ result["before"] = existing_lldp_global_facts
+ if result["changed"]:
+ result["after"] = changed_lldp_global_facts
+ elif self.state == "gathered":
+ result["gathered"] = changed_lldp_global_facts
result["warnings"] = warnings
return result
@@ -113,18 +136,17 @@ class Lldp_global(ConfigBase):
to the desired configuration
"""
commands = []
- state = self._module.params["state"]
- if state in ("merged", "replaced") and not want:
+ 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(
- state
+ self.state
)
)
- if state == "deleted":
+ if self.state == "deleted":
commands.extend(self._state_deleted(want=None, have=have))
- elif state == "merged":
+ elif self.state in ("merged", "rendered"):
commands.extend(self._state_merged(want=want, have=have))
- elif state == "replaced":
+ elif self.state == "replaced":
commands.extend(self._state_replaced(want=want, have=have))
return commands
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 377fec9a..94e39c35 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,7 +15,6 @@ from __future__ import absolute_import, division, print_function
__metaclass__ = type
-
from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base import (
ConfigBase,
)
@@ -54,14 +53,14 @@ class Lldp_interfaces(ConfigBase):
def __init__(self, module):
super(Lldp_interfaces, self).__init__(module)
- def get_lldp_interfaces_facts(self):
+ def get_lldp_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
)
lldp_interfaces_facts = facts["ansible_network_resources"].get(
"lldp_interfaces"
@@ -77,26 +76,47 @@ class Lldp_interfaces(ConfigBase):
:returns: The result from module execution
"""
result = {"changed": False}
- commands = list()
warnings = list()
- existing_lldp_interfaces_facts = self.get_lldp_interfaces_facts()
- commands.extend(self.set_config(existing_lldp_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_lldp_interfaces_facts = self.get_lldp_interfaces_facts()
+ else:
+ existing_lldp_interfaces_facts = []
- result["commands"] = commands
+ if self.state in self.ACTION_STATES or self.state == "rendered":
+ commands.extend(self.set_config(existing_lldp_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_lldp_interfaces_facts = self.get_lldp_interfaces_facts()
- result["before"] = existing_lldp_interfaces_facts
- if result["changed"]:
- result["after"] = changed_lldp_interfaces_facts
+ if self.state in self.ACTION_STATES:
+ result["commands"] = commands
+
+ if self.state in self.ACTION_STATES or self.state == "gathered":
+ changed_lldp_interfaces_facts = self.get_lldp_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_lldp_interfaces_facts(
+ data=running_config
+ )
+ else:
+ changed_lldp_interfaces_facts = []
+
+ if self.state in self.ACTION_STATES:
+ result["before"] = existing_lldp_interfaces_facts
+ if result["changed"]:
+ result["after"] = changed_lldp_interfaces_facts
+ elif self.state == "gathered":
+ result["gathered"] = changed_lldp_interfaces_facts
result["warnings"] = warnings
return result
@@ -124,16 +144,18 @@ class Lldp_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=want, have=have))
- elif state == "deleted":
+ elif self.state == "deleted":
if want:
for item in want:
name = item["name"]
@@ -150,11 +172,11 @@ class Lldp_interfaces(ConfigBase):
for want_item in want:
name = want_item["name"]
have_item = search_obj_in_list(name, have)
- if state == "merged":
+ if self.state in ("merged", "rendered"):
commands.extend(
self._state_merged(want=want_item, have=have_item)
)
- else:
+ if self.state == "replaced":
commands.extend(
self._state_replaced(want=want_item, have=have_item)
)
@@ -243,7 +265,6 @@ class Lldp_interfaces(ConfigBase):
lldp_name = want["name"]
params = Lldp_interfaces.params
- commands.extend(self._add_location(lldp_name, want, have))
for attrib in params:
value = want[attrib]
if value:
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 e93d4ee3..b359dbba 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
@@ -160,7 +160,7 @@ class Static_routes(ConfigBase):
routes = self._get_routes(want)
for r in routes:
h_item = self.search_route_in_have(have, r["dest"])
- if self.state == "merged" or self.state == "rendered":
+ if self.state in ("merged", "rendered"):
commands.extend(self._state_merged(want=r, have=h_item))
elif self.state == "replaced":
commands.extend(self._state_replaced(want=r, have=h_item))
@@ -253,12 +253,6 @@ class Static_routes(ConfigBase):
afi=item["afi"], remove=True
)
)
- for r in routes:
- h_route = self.search_route_in_have(have, r["dest"])
- if h_route:
- commands.extend(
- self._render_updates(r, h_route, opr=False)
- )
else:
routes = self._get_routes(have)
if self._is_ip_route_exist(routes):
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 d1d62c23..3b99d347 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
@@ -10,7 +10,12 @@ for a given resource, parsed, and the facts tree is populated
based on the configuration.
"""
-from __future__ import absolute_import, division, print_function
+from __future__ import (
+ absolute_import,
+ division,
+ print_function,
+ unicode_literals,
+)
__metaclass__ = type
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"] = []