mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-23 05:10:22 -07:00
Added feature facts to nxos_facts (#45934)
* Added feature facts to nxos_facts * Fixed ansibot indentation * Resolved ansibot whitespace missing after ',' * Per PR suggestion, created method in base class to gather switch config and store in global variable to prevent multiple calls to switch. * Addressed ansibot blank line & whitespace after ,
This commit is contained in:
parent
2b216384eb
commit
b427499e3e
2 changed files with 43 additions and 1 deletions
|
@ -178,6 +178,9 @@ from ansible.module_utils.connection import ConnectionError
|
||||||
from ansible.module_utils.six import string_types, iteritems
|
from ansible.module_utils.six import string_types, iteritems
|
||||||
|
|
||||||
|
|
||||||
|
g_config = None
|
||||||
|
|
||||||
|
|
||||||
class FactsBase(object):
|
class FactsBase(object):
|
||||||
|
|
||||||
def __init__(self, module):
|
def __init__(self, module):
|
||||||
|
@ -201,6 +204,12 @@ class FactsBase(object):
|
||||||
self.warnings.append('command %s failed, facts for this command will not be populated' % command_string)
|
self.warnings.append('command %s failed, facts for this command will not be populated' % command_string)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def get_config(self):
|
||||||
|
global g_config
|
||||||
|
if not g_config:
|
||||||
|
g_config = get_config(self.module)
|
||||||
|
return g_config
|
||||||
|
|
||||||
def transform_dict(self, data, keymap):
|
def transform_dict(self, data, keymap):
|
||||||
transform = dict()
|
transform = dict()
|
||||||
for key, fact in keymap:
|
for key, fact in keymap:
|
||||||
|
@ -287,7 +296,22 @@ class Config(FactsBase):
|
||||||
|
|
||||||
def populate(self):
|
def populate(self):
|
||||||
super(Config, self).populate()
|
super(Config, self).populate()
|
||||||
self.facts['config'] = get_config(self.module)
|
self.facts['config'] = self.get_config()
|
||||||
|
|
||||||
|
|
||||||
|
class Features(FactsBase):
|
||||||
|
|
||||||
|
def populate(self):
|
||||||
|
super(Features, self).populate()
|
||||||
|
data = self.get_config()
|
||||||
|
|
||||||
|
if data:
|
||||||
|
features = []
|
||||||
|
for line in data.splitlines():
|
||||||
|
if line.startswith('feature'):
|
||||||
|
features.append(line.replace('feature', '').strip())
|
||||||
|
|
||||||
|
self.facts['features_enabled'] = features
|
||||||
|
|
||||||
|
|
||||||
class Hardware(FactsBase):
|
class Hardware(FactsBase):
|
||||||
|
@ -903,6 +927,7 @@ FACT_SUBSETS = dict(
|
||||||
hardware=Hardware,
|
hardware=Hardware,
|
||||||
interfaces=Interfaces,
|
interfaces=Interfaces,
|
||||||
config=Config,
|
config=Config,
|
||||||
|
features=Features
|
||||||
)
|
)
|
||||||
|
|
||||||
VALID_SUBSETS = frozenset(FACT_SUBSETS.keys())
|
VALID_SUBSETS = frozenset(FACT_SUBSETS.keys())
|
||||||
|
|
|
@ -77,4 +77,21 @@
|
||||||
- "result.ansible_facts.ansible_net_memfree_mb > 1"
|
- "result.ansible_facts.ansible_net_memfree_mb > 1"
|
||||||
- "result.ansible_facts.ansible_net_memtotal_mb > 1"
|
- "result.ansible_facts.ansible_net_memtotal_mb > 1"
|
||||||
|
|
||||||
|
- name: "nxos_facts gather features facts"
|
||||||
|
nxos_facts:
|
||||||
|
gather_subset: features
|
||||||
|
provider: "{{ connection }}"
|
||||||
|
register: result
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
# _facts modules should never report a change
|
||||||
|
- "result.changed == false"
|
||||||
|
|
||||||
|
# Correct subsets are present
|
||||||
|
- "'features' in result.ansible_facts.ansible_net_gather_subset"
|
||||||
|
|
||||||
|
# Items from the subset is present
|
||||||
|
- "result.ansible_facts.ansible_net_features_enabled is defined"
|
||||||
|
|
||||||
- debug: msg="END connection={{ ansible_connection }} nxos_facts sanity test"
|
- debug: msg="END connection={{ ansible_connection }} nxos_facts sanity test"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue