Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(edgeswitch): allow to differentiate between running and startup config #105

Merged
merged 10 commits into from
Sep 3, 2020
2 changes: 2 additions & 0 deletions changelogs/fragments/105_edgeswitch_add-startupconfig.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- edgeswitch_facts - added ``startupconfig`` to facts module - to allow the comparision between startup and running config (https://github.com/ansible-collections/community.network/pull/105).
21 changes: 20 additions & 1 deletion plugins/modules/network/edgeswitch/edgeswitch_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@
community.network.edgeswitch_facts:
gather_subset: all

- name: Collect only the config and default facts
- name: Collect only the running config and default facts
community.network.edgeswitch_facts:
gather_subset:
- config

"""

RETURN = """
Expand Down Expand Up @@ -69,6 +70,12 @@
type: str

# config
ansible_net_startupconfig:
description: The startup config from the device
returned: when config is configured
type: str
mrwiora marked this conversation as resolved.
Show resolved Hide resolved
version_added: 1.2.0

ansible_net_config:
description: The current active config from the device
returned: when config is configured
Expand Down Expand Up @@ -148,6 +155,17 @@ def populate(self):
self.facts['config'] = data


class StartupConfig(FactsBase):

COMMANDS = ['show startup-config']

def populate(self):
super(StartupConfig, self).populate()
data = self.responses[0]
if data:
self.facts['startupconfig'] = data


class Interfaces(FactsBase):

COMMANDS = [
Expand Down Expand Up @@ -192,6 +210,7 @@ def parse_interfaces_status(self, data, interfaces):
FACT_SUBSETS = dict(
default=Default,
config=Config,
startupconfig=StartupConfig,
interfaces=Interfaces,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def load_from_file(*args, **kwargs):
self.run_commands.side_effect = load_from_file

def test_edgeswitch_facts_default(self):
set_module_args(dict(gather_subset=['all', '!interfaces', '!config']))
set_module_args(dict(gather_subset=['all', '!interfaces', '!config', '!startupconfig']))
result = self.execute_module()
facts = result.get('ansible_facts')
self.assertEqual(len(facts), 5)
Expand Down