Skip to content

Commit

Permalink
Refactor nxos_facts to support resource module (ansible#58705)
Browse files Browse the repository at this point in the history
Signed-off-by: Trishna Guha <[email protected]>
  • Loading branch information
trishnaguha authored Jul 5, 2019
1 parent a6b7d0d commit 5c5d9ad
Show file tree
Hide file tree
Showing 11 changed files with 1,026 additions and 827 deletions.
Empty file.
Empty file.
24 changes: 24 additions & 0 deletions lib/ansible/module_utils/network/nxos/argspec/facts/facts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#
# -*- coding: utf-8 -*-
# Copyright 2019 Red Hat
# GNU General Public License v3.0+
# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
"""
The arg spec for the nxos facts module.
"""
CHOICES = [
'all',
]


class FactsArgs(object):
""" The arg spec for the nxos facts module
"""

def __init__(self, **kwargs):
pass

argument_spec = {
'gather_subset': dict(default=['!config'], type='list'),
'gather_network_resources': dict(choices=CHOICES, type='list'),
}
Empty file.
Empty file.
53 changes: 53 additions & 0 deletions lib/ansible/module_utils/network/nxos/facts/facts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#
# -*- coding: utf-8 -*-
# Copyright 2019 Red Hat
# GNU General Public License v3.0+
# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
"""
The facts class for nxos
this file validates each subset of facts and selectively
calls the appropriate facts gathering function
"""

from ansible.module_utils.network.nxos.argspec.facts.facts import FactsArgs
from ansible.module_utils.network.common.facts.facts import FactsBase
from ansible.module_utils.network.nxos.facts.legacy.base import Default, Legacy, Hardware, Config, Interfaces, Features

FACT_LEGACY_SUBSETS = dict(
default=Default,
legacy=Legacy,
hardware=Hardware,
interfaces=Interfaces,
config=Config,
features=Features,
)
FACT_RESOURCE_SUBSETS = dict(
)


class Facts(FactsBase):
""" The fact class for nxos
"""

VALID_LEGACY_GATHER_SUBSETS = frozenset(FACT_LEGACY_SUBSETS.keys())
VALID_RESOURCE_SUBSETS = frozenset(FACT_RESOURCE_SUBSETS.keys())

def __init__(self, module):
super(Facts, self).__init__(module)

def get_facts(self, legacy_facts_type=None, resource_facts_type=None, data=None):
""" Collect the facts for nxos
:param legacy_facts_type: List of legacy facts types
:param resource_facts_type: List of resource fact types
:param data: previously collected conf
:rtype: dict
:return: the facts gathered
"""
netres_choices = FactsArgs.argument_spec['gather_network_resources'].get('choices', [])
if self.VALID_RESOURCE_SUBSETS:
self.get_network_resources_facts(netres_choices, FACT_RESOURCE_SUBSETS, resource_facts_type, data)

if self.VALID_LEGACY_GATHER_SUBSETS:
self.get_network_legacy_facts(FACT_LEGACY_SUBSETS, legacy_facts_type)

return self.ansible_facts, self._warnings
Empty file.
Loading

0 comments on commit 5c5d9ad

Please sign in to comment.