Skip to content

Commit a0bde34

Browse files
Merge pull request #48 from ganeshrn/rmb_refactor
Resource module facts and config code refactor Reviewed-by: Ganesh Nalawade https://github.com/ganeshrn
2 parents ca0ef91 + 69804f2 commit a0bde34

File tree

17 files changed

+159
-633
lines changed

17 files changed

+159
-633
lines changed

rmb_tests/roles/my_role/library/myos_facts.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,11 @@
88
"""
99

1010
from __future__ import absolute_import, division, print_function
11-
from ansible.module_utils.basic import AnsibleModule
12-
from ansible.module_utils.connection import Connection
13-
from ansible.module_utils.network. \
14-
myos.facts.facts import Facts
11+
__metaclass__ = type
12+
1513

1614
ANSIBLE_METADATA = {'metadata_version': '1.1',
17-
'status': ['preview'],
15+
'status': [u'preview'],
1816
'supported_by': '<support_group>'}
1917

2018

@@ -83,23 +81,23 @@
8381
See the respective resource module parameters for the tree.
8482
"""
8583

84+
from ansible.module_utils.basic import AnsibleModule
85+
from ansible.module_utils.network.myos.argspec.facts.facts import FactsArgs
86+
from ansible.module_utils.network.myos.facts.facts import Facts
87+
8688

8789
def main():
8890
"""
8991
Main entry point for module execution
9092
9193
:returns: ansible_facts
9294
"""
93-
module = AnsibleModule(argument_spec=Facts.argument_spec,
95+
module = AnsibleModule(argument_spec=FactsArgs.argument_spec,
9496
supports_check_mode=True)
95-
warnings = ['default value for `gather_subset` \
96-
will be changed to `min` from `!config` v2.11 onwards']
97-
98-
connection = Connection(module._socket_path) # pylint: disable=W0212
99-
gather_subset = module.params['gather_subset']
100-
gather_network_resources = module.params['gather_network_resources']
101-
result = Facts().get_facts(module, connection, gather_subset,
102-
gather_network_resources)
97+
warnings = ['default value for `gather_subset` '
98+
'will be changed to `min` from `!config` v2.11 onwards']
99+
100+
result = Facts(module).get_facts()
103101

104102
ansible_facts, additional_warnings = result
105103
warnings.extend(additional_warnings)

rmb_tests/roles/my_role/library/myos_interfaces.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"""
2828

2929
from __future__ import absolute_import, division, print_function
30-
__metaclass__ = type # pylint: disable=C0103
30+
__metaclass__ = type
3131

3232
ANSIBLE_METADATA = {
3333
'metadata_version': '1.1',
@@ -179,11 +179,9 @@
179179
"""
180180

181181

182-
# pylint: disable=C0413
183182
from ansible.module_utils.basic import AnsibleModule
184-
from ansible.module_utils.network. \
185-
myos.config.interfaces.interfaces import Interfaces
186-
# pylint: enable=C0413
183+
from ansible.module_utils.network.myos.argspec.interfaces.interfaces import InterfacesArgs
184+
from ansible.module_utils.network.myos.config.interfaces.interfaces import Interfaces
187185

188186

189187
def main():
@@ -192,7 +190,7 @@ def main():
192190
193191
:returns: the result form module invocation
194192
"""
195-
module = AnsibleModule(argument_spec=Interfaces.argument_spec,
193+
module = AnsibleModule(argument_spec=InterfacesArgs.argument_spec,
196194
supports_check_mode=True)
197195

198196
result = Interfaces(module).execute_module()

rmb_tests/roles/my_role/module_utils/network/myos/config/base.py

Lines changed: 0 additions & 28 deletions
This file was deleted.

rmb_tests/roles/my_role/module_utils/network/myos/config/interfaces/interfaces.py

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/python
1+
#
22
# -*- coding: utf-8 -*-
33
# Copyright 2019 Red Hat
44
# GNU General Public License v3.0+
@@ -10,19 +10,12 @@
1010
necessary to bring the current configuration to it's desired end-state is
1111
created
1212
"""
13-
13+
from ansible.module_utils.network.common.cfg.base import ConfigBase
1414
from ansible.module_utils.network.common.utils import to_list
15-
16-
from ansible.module_utils.network. \
17-
myos.argspec.interfaces.interfaces import InterfacesArgs
18-
from ansible.module_utils.network. \
19-
myos. \
20-
config.base import ConfigBase
21-
from ansible.module_utils.network. \
22-
myos.facts.facts import Facts
15+
from ansible.module_utils.network.myos.facts.facts import Facts
2316

2417

25-
class Interfaces(ConfigBase, InterfacesArgs):
18+
class Interfaces(ConfigBase):
2619
"""
2720
The myos_interfaces class
2821
"""
@@ -36,16 +29,16 @@ class Interfaces(ConfigBase, InterfacesArgs):
3629
'interfaces',
3730
]
3831

32+
def __init__(self, module):
33+
super(Interfaces, self).__init__(module)
34+
3935
def get_interfaces_facts(self):
4036
""" Get the 'facts' (the current configuration)
4137
4238
:rtype: A dictionary
4339
:returns: The current configuration as a dictionary
4440
"""
45-
facts, _warnings = Facts().get_facts(self._module,
46-
self._connection,
47-
self.gather_subset,
48-
self.gather_network_resources)
41+
facts, _warnings = Facts(self._module).get_facts(self.gather_subset, self.gather_network_resources)
4942
interfaces_facts = facts['ansible_network_resources'].get('interfaces')
5043
if not interfaces_facts:
5144
return []

rmb_tests/roles/my_role/module_utils/network/myos/facts/base.py

Lines changed: 0 additions & 118 deletions
This file was deleted.

0 commit comments

Comments
 (0)