mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-22 21:00:22 -07:00
Refactors and deprecation removals (#34830)
This patch is primarily a refactor to make the validate-modules arg-spec no longer generate a traceback. It additionally includes removal of deprecated code in the virtual server module.
This commit is contained in:
parent
a10aee0fc3
commit
c548ab0f18
26 changed files with 1612 additions and 2099 deletions
|
@ -100,14 +100,11 @@ options:
|
|||
- Specifies whether the system uses route advertisement for this
|
||||
virtual address. When disabled, the system does not advertise
|
||||
routes for this virtual address.
|
||||
choices:
|
||||
- yes
|
||||
- no
|
||||
type: bool
|
||||
partition:
|
||||
description:
|
||||
- Device partition to manage resources on.
|
||||
required: False
|
||||
default: 'Common'
|
||||
default: Common
|
||||
version_added: 2.5
|
||||
traffic_group:
|
||||
description:
|
||||
|
@ -116,13 +113,10 @@ options:
|
|||
will be used.
|
||||
version_added: 2.5
|
||||
notes:
|
||||
- Requires the f5-sdk Python package on the host. This is as easy as pip
|
||||
install f5-sdk.
|
||||
- Requires the netaddr Python package on the host. This is as easy as pip
|
||||
install netaddr.
|
||||
extends_documentation_fragment: f5
|
||||
requirements:
|
||||
- f5-sdk
|
||||
- netaddr
|
||||
author:
|
||||
- Tim Rupp (@caphrim007)
|
||||
|
@ -193,24 +187,47 @@ state:
|
|||
sample: disabled
|
||||
'''
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.basic import env_fallback
|
||||
from ansible.module_utils.parsing.convert_bool import BOOLEANS_TRUE
|
||||
from ansible.module_utils.parsing.convert_bool import BOOLEANS_FALSE
|
||||
|
||||
HAS_DEVEL_IMPORTS = False
|
||||
|
||||
try:
|
||||
# Sideband repository used for dev
|
||||
from library.module_utils.network.f5.bigip import HAS_F5SDK
|
||||
from library.module_utils.network.f5.bigip import F5Client
|
||||
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 fqdn_name
|
||||
from library.module_utils.network.f5.common import f5_argument_spec
|
||||
try:
|
||||
from library.module_utils.network.f5.common import iControlUnexpectedHTTPError
|
||||
except ImportError:
|
||||
HAS_F5SDK = False
|
||||
HAS_DEVEL_IMPORTS = True
|
||||
except ImportError:
|
||||
# Upstream Ansible
|
||||
from ansible.module_utils.network.f5.bigip import HAS_F5SDK
|
||||
from ansible.module_utils.network.f5.bigip import F5Client
|
||||
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 fqdn_name
|
||||
from ansible.module_utils.network.f5.common import f5_argument_spec
|
||||
try:
|
||||
from ansible.module_utils.network.f5.common import iControlUnexpectedHTTPError
|
||||
except ImportError:
|
||||
HAS_F5SDK = False
|
||||
|
||||
try:
|
||||
import netaddr
|
||||
HAS_NETADDR = True
|
||||
except ImportError:
|
||||
HAS_NETADDR = False
|
||||
|
||||
from ansible.module_utils.f5_utils import AnsibleF5Client
|
||||
from ansible.module_utils.f5_utils import AnsibleF5Parameters
|
||||
from ansible.module_utils.f5_utils import HAS_F5SDK
|
||||
from ansible.module_utils.f5_utils import F5ModuleError
|
||||
from ansible.module_utils.parsing.convert_bool import BOOLEANS_TRUE
|
||||
from ansible.module_utils.parsing.convert_bool import BOOLEANS_FALSE
|
||||
|
||||
try:
|
||||
from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError
|
||||
except ImportError:
|
||||
HAS_F5SDK = False
|
||||
|
||||
|
||||
class Parameters(AnsibleF5Parameters):
|
||||
api_map = {
|
||||
|
@ -349,17 +366,6 @@ class Parameters(AnsibleF5Parameters):
|
|||
result = self._filter_params(result)
|
||||
return result
|
||||
|
||||
def api_params(self):
|
||||
result = {}
|
||||
for api_attribute in self.api_attributes:
|
||||
if api_attribute in self.api_map:
|
||||
result[api_attribute] = getattr(
|
||||
self, self.api_map[api_attribute])
|
||||
else:
|
||||
result[api_attribute] = getattr(self, api_attribute)
|
||||
result = self._filter_params(result)
|
||||
return result
|
||||
|
||||
|
||||
class Changes(Parameters):
|
||||
pass
|
||||
|
@ -393,10 +399,11 @@ class Difference(object):
|
|||
|
||||
|
||||
class ModuleManager(object):
|
||||
def __init__(self, client):
|
||||
self.client = client
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.module = kwargs.get('module', None)
|
||||
self.client = kwargs.get('client', None)
|
||||
self.have = None
|
||||
self.want = Parameters(self.client.module.params)
|
||||
self.want = Parameters(client=self.client, params=self.module.params)
|
||||
self.changes = Changes()
|
||||
|
||||
def _set_changed_options(self):
|
||||
|
@ -405,7 +412,7 @@ class ModuleManager(object):
|
|||
if getattr(self.want, key) is not None:
|
||||
changed[key] = getattr(self.want, key)
|
||||
if changed:
|
||||
self.changes = Changes(changed)
|
||||
self.changes = Changes(params=changed)
|
||||
|
||||
def _update_changed_options(self):
|
||||
diff = Difference(self.want, self.have)
|
||||
|
@ -421,7 +428,7 @@ class ModuleManager(object):
|
|||
else:
|
||||
changed[k] = change
|
||||
if changed:
|
||||
self.changes = Changes(changed)
|
||||
self.changes = Changes(params=changed)
|
||||
return True
|
||||
return False
|
||||
|
||||
|
@ -467,7 +474,7 @@ class ModuleManager(object):
|
|||
partition=self.want.partition
|
||||
)
|
||||
result = resource.attrs
|
||||
return Parameters(result)
|
||||
return Parameters(params=result)
|
||||
|
||||
def exists(self):
|
||||
result = self.client.api.tm.ltm.virtual_address_s.virtual_address.exists(
|
||||
|
@ -481,18 +488,18 @@ class ModuleManager(object):
|
|||
if self.want.netmask is not None:
|
||||
if self.have.netmask != self.want.netmask:
|
||||
raise F5ModuleError(
|
||||
"The netmask cannot be changed. Delete and recreate"
|
||||
"The netmask cannot be changed. Delete and recreate "
|
||||
"the virtual address if you need to do this."
|
||||
)
|
||||
if self.want.address is not None:
|
||||
if self.have.address != self.want.address:
|
||||
raise F5ModuleError(
|
||||
"The address cannot be changed. Delete and recreate"
|
||||
"The address cannot be changed. Delete and recreate "
|
||||
"the virtual address if you need to do this."
|
||||
)
|
||||
if not self.should_update():
|
||||
return False
|
||||
if self.client.check_mode:
|
||||
if self.module.check_mode:
|
||||
return True
|
||||
self.update_on_device()
|
||||
return True
|
||||
|
@ -509,7 +516,7 @@ class ModuleManager(object):
|
|||
self._set_changed_options()
|
||||
if self.want.traffic_group is None:
|
||||
self.want.update({'traffic_group': '/Common/traffic-group-1'})
|
||||
if self.client.check_mode:
|
||||
if self.module.check_mode:
|
||||
return True
|
||||
self.create_on_device()
|
||||
if self.exists():
|
||||
|
@ -527,7 +534,7 @@ class ModuleManager(object):
|
|||
)
|
||||
|
||||
def remove(self):
|
||||
if self.client.check_mode:
|
||||
if self.module.check_mode:
|
||||
return True
|
||||
self.remove_from_device()
|
||||
if self.exists():
|
||||
|
@ -545,7 +552,7 @@ class ModuleManager(object):
|
|||
class ArgumentSpec(object):
|
||||
def __init__(self):
|
||||
self.supports_check_mode = True
|
||||
self.argument_spec = dict(
|
||||
argument_spec = dict(
|
||||
state=dict(
|
||||
default='present',
|
||||
choices=['present', 'absent', 'disabled', 'enabled']
|
||||
|
@ -577,29 +584,38 @@ class ArgumentSpec(object):
|
|||
use_route_advertisement=dict(
|
||||
type='bool'
|
||||
),
|
||||
traffic_group=dict()
|
||||
traffic_group=dict(),
|
||||
partition=dict(
|
||||
default='Common',
|
||||
fallback=(env_fallback, ['F5_PARTITION'])
|
||||
)
|
||||
)
|
||||
self.f5_product_name = 'bigip'
|
||||
self.argument_spec = {}
|
||||
self.argument_spec.update(f5_argument_spec)
|
||||
self.argument_spec.update(argument_spec)
|
||||
|
||||
|
||||
def main():
|
||||
if not HAS_F5SDK:
|
||||
raise F5ModuleError("The python f5-sdk module is required")
|
||||
|
||||
spec = ArgumentSpec()
|
||||
|
||||
client = AnsibleF5Client(
|
||||
module = AnsibleModule(
|
||||
argument_spec=spec.argument_spec,
|
||||
supports_check_mode=spec.supports_check_mode,
|
||||
f5_product_name=spec.f5_product_name
|
||||
supports_check_mode=spec.supports_check_mode
|
||||
)
|
||||
if not HAS_F5SDK:
|
||||
module.fail_json(msg="The python f5-sdk module is required")
|
||||
if not HAS_NETADDR:
|
||||
module.fail_json(msg="The python netaddr module is required")
|
||||
|
||||
try:
|
||||
mm = ModuleManager(client)
|
||||
client = F5Client(**module.params)
|
||||
mm = ModuleManager(module=module, client=client)
|
||||
results = mm.exec_module()
|
||||
client.module.exit_json(**results)
|
||||
except F5ModuleError as e:
|
||||
client.module.fail_json(msg=str(e))
|
||||
cleanup_tokens(client)
|
||||
module.exit_json(**results)
|
||||
except F5ModuleError as ex:
|
||||
cleanup_tokens(client)
|
||||
module.fail_json(msg=str(ex))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue