Skip to content

Commit 9d9c95c

Browse files
committed
update facts scaffolding
Signed-off-by: Trishna Guha <[email protected]>
1 parent 5e5e206 commit 9d9c95c

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

roles/resource_module/templates/module_utils/network_os/argspec/facts/facts.py.j2

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ class FactsArgs(object): #pylint: disable=R0903
1313
def __init__(self, **kwargs):
1414
pass
1515

16+
choices = [
17+
'all',
18+
'net_configuration_{{ resource }}',
19+
]
20+
1621
argument_spec = {
17-
'gather_subset': dict(default=['all'], type='list')
22+
'gather_subset': dict(default=['all'], choices=choices, type='list')
1823
}

roles/resource_module/templates/module_utils/network_os/facts/facts.py.j2

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,7 @@ class Facts(FactsArgs, FactsBase): #pylint: disable=R0903
2121
""" The fact class for {{ network_os }}
2222
"""
2323

24-
VALID_SUBSETS = [
25-
'net_configuration_{{ resource }}',
26-
]
27-
28-
def get_facts(self, module, connection, gather_subset=None):
24+
def get_facts(self, module, connection, gather_subset=['all']):
2925
""" Collect the facts for {{ network_os }}
3026
3127
:param module: The module instance
@@ -34,25 +30,29 @@ class Facts(FactsArgs, FactsBase): #pylint: disable=R0903
3430
:rtype: dict
3531
:returns: the facts gathered
3632
"""
33+
valid_subsets = self.argument_spec['gather_subset'].get('choices', [])
34+
if valid_subsets and 'all' in valid_subsets:
35+
valid_subsets.remove('all')
36+
3737
runable_subsets = set()
3838
exclude_subsets = set()
3939
if not gather_subset:
4040
gather_subset = ['all']
4141

4242
for subset in gather_subset:
4343
if subset == 'all':
44-
runable_subsets.update(self.VALID_SUBSETS)
44+
runable_subsets.update(valid_subsets)
4545
continue
4646
if subset.startswith('!'):
4747
subset = subset[1:]
4848
if subset == 'all':
49-
exclude_subsets.update(self.VALID_SUBSETS)
49+
exclude_subsets.update(valid_subsets)
5050
continue
5151
exclude = True
5252
else:
5353
exclude = False
5454

55-
if subset not in self.VALID_SUBSETS:
55+
if subset not in valid_subsets:
5656
module.fail_json(msg='Bad subset')
5757

5858
if exclude:
@@ -61,7 +61,7 @@ class Facts(FactsArgs, FactsBase): #pylint: disable=R0903
6161
runable_subsets.add(subset)
6262

6363
if not runable_subsets:
64-
runable_subsets.update(self.VALID_SUBSETS)
64+
runable_subsets.update(valid_subsets)
6565

6666
runable_subsets.difference_update(exclude_subsets)
6767
self.ansible_facts['gather_subset'] = list(runable_subsets)

0 commit comments

Comments
 (0)