summaryrefslogtreecommitdiff
path: root/lib/ansible/modules/network/f5/bigip_vcmp_guest.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/ansible/modules/network/f5/bigip_vcmp_guest.py')
-rw-r--r--lib/ansible/modules/network/f5/bigip_vcmp_guest.py156
1 files changed, 67 insertions, 89 deletions
diff --git a/lib/ansible/modules/network/f5/bigip_vcmp_guest.py b/lib/ansible/modules/network/f5/bigip_vcmp_guest.py
index edc6ca7c01..59033c6963 100644
--- a/lib/ansible/modules/network/f5/bigip_vcmp_guest.py
+++ b/lib/ansible/modules/network/f5/bigip_vcmp_guest.py
@@ -112,9 +112,11 @@ options:
- The number you can specify depends on the type of hardware you have.
- In the event of a reboot, the system persists the guest to the same slot on
which it ran prior to the reboot.
+ partition:
+ description:
+ - Device partition to manage resources on.
+ default: Common
notes:
- - Requires the f5-sdk Python package on the host. This is as easy as pip
- install f5-sdk.
- This module can take a lot of time to deploy vCMP guests. This is an intrinsic
limitation of the vCMP system because it is booting real VMs on the BIG-IP
device. This boot time is very similar in length to the time it takes to
@@ -123,8 +125,6 @@ notes:
means that it is not unusual for a vCMP host with many guests to take a
long time (60+ minutes) to reboot and bring all the guests online. The
BIG-IP chassis will be available before all vCMP guests are online.
-requirements:
- - f5-sdk >= 3.0.3
- netaddr
extends_documentation_fragment: f5
author:
@@ -173,16 +173,41 @@ vlans:
sample: ['/Common/vlan1', '/Common/vlan2']
'''
+import time
-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.six import iteritems
-from collections import defaultdict
+from ansible.module_utils.basic import AnsibleModule
+from ansible.module_utils.basic import env_fallback
from collections import namedtuple
-import time
+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:
from netaddr import IPAddress, AddrFormatError, IPNetwork
@@ -192,7 +217,6 @@ except ImportError:
try:
from f5.utils.responses.handlers import Stats
- from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError
except ImportError:
HAS_F5SDK = False
@@ -222,37 +246,6 @@ class Parameters(AnsibleF5Parameters):
'state'
]
- def __init__(self, params=None, client=None):
- self._values = defaultdict(lambda: None)
- self._values['__warnings'] = []
- if params:
- self.update(params=params)
- self.client = client
-
- def update(self, params=None):
- if params:
- for k, v in iteritems(params):
- if self.api_map is not None and k in self.api_map:
- map_key = self.api_map[k]
- else:
- map_key = k
-
- # Handle weird API parameters like `dns.proxy.__iter__` by
- # using a map provided by the module developer
- class_attr = getattr(type(self), map_key, None)
- if isinstance(class_attr, property):
- # There is a mapped value for the api_map key
- if class_attr.fset is None:
- # If the mapped value does not have
- # an associated setter
- self._values[map_key] = v
- else:
- # The mapped value has a setter
- setattr(self, map_key, v)
- else:
- # If the mapped value is not a @property
- self._values[map_key] = v
-
def _fqdn_name(self, value):
if value is not None and not value.startswith('/'):
return '/{0}/{1}'.format(self.partition, value)
@@ -268,16 +261,6 @@ class Parameters(AnsibleF5Parameters):
pass
return result
- def api_params(self):
- result = {}
- for api_attribute in self.api_attributes:
- if self.api_map is not None and 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
-
@property
def mgmt_route(self):
if self._values['mgmt_route'] is None:
@@ -394,9 +377,10 @@ class Difference(object):
class ModuleManager(object):
- def __init__(self, client):
- self.client = client
- self.want = Parameters(client=client, params=self.client.module.params)
+ def __init__(self, *args, **kwargs):
+ self.module = kwargs.get('module', None)
+ self.client = kwargs.get('client', None)
+ self.want = Parameters(client=self.client, params=self.module.params)
self.changes = Changes()
def _set_changed_options(self):
@@ -405,7 +389,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)
@@ -418,7 +402,7 @@ class ModuleManager(object):
else:
changed[k] = change
if changed:
- self.changes = Parameters(changed)
+ self.changes = Parameters(params=changed)
return True
return False
@@ -450,7 +434,7 @@ class ModuleManager(object):
def _announce_deprecations(self, result):
warnings = result.pop('__warnings', [])
for warning in warnings:
- self.client.module.deprecate(
+ self.module.deprecate(
msg=warning['msg'],
version=warning['version']
)
@@ -476,7 +460,7 @@ class ModuleManager(object):
self.have = self.read_current_from_device()
if not self.should_update():
return False
- if self.client.check_mode:
+ if self.module.check_mode:
return True
self.update_on_device()
if self.want.state == 'provisioned':
@@ -488,7 +472,7 @@ class ModuleManager(object):
return True
def remove(self):
- if self.client.check_mode:
+ if self.module.check_mode:
return True
if self.want.delete_virtual_disk:
self.have = self.read_current_from_device()
@@ -501,7 +485,7 @@ class ModuleManager(object):
def create(self):
self._set_changed_options()
- if self.client.check_mode:
+ if self.module.check_mode:
return True
if self.want.mgmt_tuple.subnet is None:
self.want.update(dict(
@@ -547,7 +531,7 @@ class ModuleManager(object):
name=self.want.name
)
result = resource.attrs
- return Parameters(result)
+ return Parameters(params=result)
def remove_virtual_disk(self):
if self.virtual_disk_exists():
@@ -666,7 +650,7 @@ class ModuleManager(object):
class ArgumentSpec(object):
def __init__(self):
self.supports_check_mode = True
- self.argument_spec = dict(
+ argument_spec = dict(
name=dict(required=True),
vlans=dict(type='list'),
mgmt_network=dict(choices=['bridged', 'isolated', 'host only']),
@@ -680,47 +664,41 @@ class ArgumentSpec(object):
delete_virtual_disk=dict(
type='bool', default='no'
),
- cores_per_slot=dict(type='int')
+ cores_per_slot=dict(type='int'),
+ 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)
self.required_if = [
['mgmt_network', 'bridged', ['mgmt_address']]
]
-def cleanup_tokens(client):
- try:
- resource = client.api.shared.authz.tokens_s.token.load(
- name=client.api.icrs.token
- )
- resource.delete()
- except Exception:
- pass
-
-
def main():
- if not HAS_F5SDK:
- raise F5ModuleError("The python f5-sdk module is required")
-
- if not HAS_NETADDR:
- raise F5ModuleError("The python netaddr 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()
cleanup_tokens(client)
- client.module.exit_json(**results)
- except F5ModuleError as e:
+ module.exit_json(**results)
+ except F5ModuleError as ex:
cleanup_tokens(client)
- client.module.fail_json(msg=str(e))
+ module.fail_json(msg=str(ex))
if __name__ == '__main__':