Refactors main() function and module manager in multiple modules in line with recent changes (#53979)

Adds variable types to docs
Refactors unit tests to remove deprecated parameters
This commit is contained in:
Wojciech Wypior 2019-03-19 06:40:40 +01:00 committed by Tim Rupp
commit 739df1c348
27 changed files with 447 additions and 326 deletions

View file

@ -26,15 +26,19 @@ options:
contact:
description:
- The name of the contact for the data center.
type: str
description:
description:
- The description of the data center.
type: str
location:
description:
- The location of the data center.
type: str
name:
description:
- The name of the data center.
type: str
required: True
state:
description:
@ -44,15 +48,17 @@ options:
the virtual address and enables it. If C(enabled), enable the virtual
address if it exists. If C(disabled), create the virtual address if
needed, and set state to C(disabled).
default: present
type: str
choices:
- present
- absent
- enabled
- disabled
default: present
partition:
description:
- Device partition to manage resources on.
type: str
default: Common
version_added: 2.5
extends_documentation_fragment: f5
@ -113,23 +119,17 @@ try:
from library.module_utils.network.f5.bigip import F5RestClient
from library.module_utils.network.f5.common import F5ModuleError
from library.module_utils.network.f5.common import AnsibleF5Parameters
from library.module_utils.network.f5.common import cleanup_tokens
from library.module_utils.network.f5.common import fq_name
from library.module_utils.network.f5.common import f5_argument_spec
from library.module_utils.network.f5.common import transform_name
from library.module_utils.network.f5.common import exit_json
from library.module_utils.network.f5.common import fail_json
from library.module_utils.network.f5.icontrol import module_provisioned
except ImportError:
from ansible.module_utils.network.f5.bigip import F5RestClient
from ansible.module_utils.network.f5.common import F5ModuleError
from ansible.module_utils.network.f5.common import AnsibleF5Parameters
from ansible.module_utils.network.f5.common import cleanup_tokens
from ansible.module_utils.network.f5.common import fq_name
from ansible.module_utils.network.f5.common import f5_argument_spec
from ansible.module_utils.network.f5.common import transform_name
from ansible.module_utils.network.f5.common import exit_json
from ansible.module_utils.network.f5.common import fail_json
from ansible.module_utils.network.f5.icontrol import module_provisioned
@ -266,7 +266,7 @@ class Difference(object):
class ModuleManager(object):
def __init__(self, *args, **kwargs):
self.module = kwargs.pop('module', None)
self.client = kwargs.pop('client', None)
self.client = F5RestClient(**self.module.params)
self.want = ModuleParameters(params=self.module.params)
self.have = ApiParameters()
self.changes = UsableChanges()
@ -478,16 +478,12 @@ def main():
supports_check_mode=spec.supports_check_mode,
)
client = F5RestClient(**module.params)
try:
mm = ModuleManager(module=module, client=client)
mm = ModuleManager(module=module)
results = mm.exec_module()
cleanup_tokens(client)
exit_json(module, results, client)
module.exit_json(**results)
except F5ModuleError as ex:
cleanup_tokens(client)
fail_json(module, ex, client)
module.fail_json(msg=str(ex))
if __name__ == '__main__':