mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Various fixes (#34815)
This patch was primarily an effort to reduce traceback errors for work that sivel was doing. Part of (and in some cases in addition to) that, the following was done. * Removed re-def of cleanup_tokens. * Changed parameter args to be keywords. * Changed imports to include new module_util locations. * Imports also include developing (sideband) module_util locations. * Changed to using F5Client and plain AnsibleModule to prevent tracebacks caused by missing libraries. * Removed init and update methods from most Parameter classes (optimization) as its now included in module_utils. * Changed module and module param references to take into account the new self.module arg. * Minor bug fixes made during this refactor.
This commit is contained in:
parent
18d33eeb89
commit
44a5b3abb4
22 changed files with 838 additions and 998 deletions
|
@ -98,8 +98,6 @@ options:
|
||||||
- Device partition to manage resources on.
|
- Device partition to manage resources on.
|
||||||
default: Common
|
default: Common
|
||||||
extends_documentation_fragment: f5
|
extends_documentation_fragment: f5
|
||||||
requirements:
|
|
||||||
- f5-sdk >= 3.0.4
|
|
||||||
author:
|
author:
|
||||||
- Wojciech Wypior (@wojtek0806)
|
- Wojciech Wypior (@wojtek0806)
|
||||||
- Tim Rupp (@caphrim007)
|
- Tim Rupp (@caphrim007)
|
||||||
|
@ -219,50 +217,42 @@ name:
|
||||||
import os
|
import os
|
||||||
import time
|
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 distutils.version import LooseVersion
|
from distutils.version import LooseVersion
|
||||||
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
|
from ansible.module_utils.basic import env_fallback
|
||||||
|
|
||||||
|
HAS_DEVEL_IMPORTS = False
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError
|
# 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:
|
except ImportError:
|
||||||
HAS_F5SDK = False
|
HAS_F5SDK = False
|
||||||
|
|
||||||
|
|
||||||
class Parameters(AnsibleF5Parameters):
|
class Parameters(AnsibleF5Parameters):
|
||||||
def __init__(self, params=None):
|
|
||||||
self._values = defaultdict(lambda: None)
|
|
||||||
if params:
|
|
||||||
self.update(params=params)
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
updatables = [
|
updatables = [
|
||||||
'active'
|
'active'
|
||||||
]
|
]
|
||||||
|
@ -290,17 +280,12 @@ class Parameters(AnsibleF5Parameters):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def full_path(self):
|
def full_path(self):
|
||||||
return self._fqdn_name(self.name)
|
return fqdn_name(self.name)
|
||||||
|
|
||||||
def _templates_from_device(self):
|
def _templates_from_device(self):
|
||||||
collection = self.client.api.tm.asm.policy_templates_s.get_collection()
|
collection = self.client.api.tm.asm.policy_templates_s.get_collection()
|
||||||
return collection
|
return collection
|
||||||
|
|
||||||
def _fqdn_name(self, value):
|
|
||||||
if value is not None and not value.startswith('/'):
|
|
||||||
return '/{0}/{1}'.format(self.partition, value)
|
|
||||||
return value
|
|
||||||
|
|
||||||
def to_return(self):
|
def to_return(self):
|
||||||
result = {}
|
result = {}
|
||||||
for returnable in self.returnables:
|
for returnable in self.returnables:
|
||||||
|
@ -308,16 +293,6 @@ class Parameters(AnsibleF5Parameters):
|
||||||
result = self._filter_params(result)
|
result = self._filter_params(result)
|
||||||
return result
|
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
|
|
||||||
|
|
||||||
|
|
||||||
class V1Parameters(Parameters):
|
class V1Parameters(Parameters):
|
||||||
@property
|
@property
|
||||||
|
@ -483,8 +458,9 @@ class Difference(object):
|
||||||
|
|
||||||
|
|
||||||
class BaseManager(object):
|
class BaseManager(object):
|
||||||
def __init__(self, client):
|
def __init__(self, *args, **kwargs):
|
||||||
self.client = client
|
self.client = kwargs.get('client', None)
|
||||||
|
self.module = kwargs.get('module', None)
|
||||||
self.have = None
|
self.have = None
|
||||||
self.changes = Changes()
|
self.changes = Changes()
|
||||||
|
|
||||||
|
@ -512,7 +488,7 @@ class BaseManager(object):
|
||||||
if getattr(self.want, key) is not None:
|
if getattr(self.want, key) is not None:
|
||||||
changed[key] = getattr(self.want, key)
|
changed[key] = getattr(self.want, key)
|
||||||
if changed:
|
if changed:
|
||||||
self.changes = Changes(changed)
|
self.changes = Changes(params=changed)
|
||||||
|
|
||||||
def should_update(self):
|
def should_update(self):
|
||||||
result = self._update_changed_options()
|
result = self._update_changed_options()
|
||||||
|
@ -534,7 +510,7 @@ class BaseManager(object):
|
||||||
else:
|
else:
|
||||||
changed[k] = change
|
changed[k] = change
|
||||||
if changed:
|
if changed:
|
||||||
self.changes = Changes(changed)
|
self.changes = Changes(params=changed)
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -554,9 +530,12 @@ class BaseManager(object):
|
||||||
policies = self.client.api.tm.asm.policies_s.get_collection()
|
policies = self.client.api.tm.asm.policies_s.get_collection()
|
||||||
if any(p.name == self.want.name and p.partition == self.want.partition for p in policies):
|
if any(p.name == self.want.name and p.partition == self.want.partition for p in policies):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def _file_is_missing(self):
|
def _file_is_missing(self):
|
||||||
|
if self.want.template and self.want.file is None:
|
||||||
|
return False
|
||||||
if not os.path.exists(self.want.file):
|
if not os.path.exists(self.want.file):
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
@ -570,7 +549,7 @@ class BaseManager(object):
|
||||||
"The specified ASM policy file does not exist"
|
"The specified ASM policy file does not exist"
|
||||||
)
|
)
|
||||||
self._set_changed_options()
|
self._set_changed_options()
|
||||||
if self.client.check_mode:
|
if self.module.check_mode:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
if self.want.template is None and self.want.file is None:
|
if self.want.template is None and self.want.file is None:
|
||||||
|
@ -595,7 +574,7 @@ class BaseManager(object):
|
||||||
self.have = self.read_current_from_device()
|
self.have = self.read_current_from_device()
|
||||||
if not self.should_update():
|
if not self.should_update():
|
||||||
return False
|
return False
|
||||||
if self.client.check_mode:
|
if self.module.check_mode:
|
||||||
return True
|
return True
|
||||||
self.update_on_device()
|
self.update_on_device()
|
||||||
if self.changes.active:
|
if self.changes.active:
|
||||||
|
@ -641,7 +620,7 @@ class BaseManager(object):
|
||||||
)
|
)
|
||||||
|
|
||||||
def remove(self):
|
def remove(self):
|
||||||
if self.client.check_mode:
|
if self.module.check_mode:
|
||||||
return True
|
return True
|
||||||
self.remove_from_device()
|
self.remove_from_device()
|
||||||
if self.exists():
|
if self.exists():
|
||||||
|
@ -662,7 +641,7 @@ class BaseManager(object):
|
||||||
if policy.name == self.want.name and policy.partition == self.want.partition:
|
if policy.name == self.want.name and policy.partition == self.want.partition:
|
||||||
params = policy.attrs
|
params = policy.attrs
|
||||||
params.update(dict(self_link=policy.selfLink))
|
params.update(dict(self_link=policy.selfLink))
|
||||||
return Parameters(params)
|
return Parameters(params=params)
|
||||||
raise F5ModuleError("The policy was not found")
|
raise F5ModuleError("The policy was not found")
|
||||||
|
|
||||||
def import_to_device(self):
|
def import_to_device(self):
|
||||||
|
@ -710,8 +689,9 @@ class BaseManager(object):
|
||||||
|
|
||||||
|
|
||||||
class ModuleManager(object):
|
class ModuleManager(object):
|
||||||
def __init__(self, client):
|
def __init__(self, *args, **kwargs):
|
||||||
self.client = client
|
self.client = kwargs.get('client', None)
|
||||||
|
self.kwargs = kwargs
|
||||||
|
|
||||||
def exec_module(self):
|
def exec_module(self):
|
||||||
if self.version_is_less_than_13():
|
if self.version_is_less_than_13():
|
||||||
|
@ -722,9 +702,9 @@ class ModuleManager(object):
|
||||||
|
|
||||||
def get_manager(self, type):
|
def get_manager(self, type):
|
||||||
if type == 'v1':
|
if type == 'v1':
|
||||||
return V1Manager(self.client)
|
return V1Manager(**self.kwargs)
|
||||||
elif type == 'v2':
|
elif type == 'v2':
|
||||||
return V2Manager(self.client)
|
return V2Manager(**self.kwargs)
|
||||||
|
|
||||||
def version_is_less_than_13(self):
|
def version_is_less_than_13(self):
|
||||||
version = self.client.api.tmos_version
|
version = self.client.api.tmos_version
|
||||||
|
@ -735,19 +715,19 @@ class ModuleManager(object):
|
||||||
|
|
||||||
|
|
||||||
class V1Manager(BaseManager):
|
class V1Manager(BaseManager):
|
||||||
def __init__(self, client):
|
def __init__(self, *args, **kwargs):
|
||||||
super(V1Manager, self).__init__(client)
|
client = kwargs.get('client', None)
|
||||||
self.want = V1Parameters()
|
module = kwargs.get('module', None)
|
||||||
self.want.client = self.client
|
super(V1Manager, self).__init__(client=client, module=module)
|
||||||
self.want.update(self.client.module.params)
|
self.want = V1Parameters(params=module.params, client=client)
|
||||||
|
|
||||||
|
|
||||||
class V2Manager(BaseManager):
|
class V2Manager(BaseManager):
|
||||||
def __init__(self, client):
|
def __init__(self, *args, **kwargs):
|
||||||
super(V2Manager, self).__init__(client)
|
client = kwargs.get('client', None)
|
||||||
self.want = V2Parameters()
|
module = kwargs.get('module', None)
|
||||||
self.want.client = self.client
|
super(V2Manager, self).__init__(client=client, module=module)
|
||||||
self.want.update(self.client.module.params)
|
self.want = V2Parameters(params=module.params, client=client)
|
||||||
|
|
||||||
|
|
||||||
class ArgumentSpec(object):
|
class ArgumentSpec(object):
|
||||||
|
@ -790,7 +770,7 @@ class ArgumentSpec(object):
|
||||||
'Wordpress',
|
'Wordpress',
|
||||||
]
|
]
|
||||||
self.supports_check_mode = True
|
self.supports_check_mode = True
|
||||||
self.argument_spec = dict(
|
argument_spec = dict(
|
||||||
name=dict(
|
name=dict(
|
||||||
required=True,
|
required=True,
|
||||||
),
|
),
|
||||||
|
@ -800,44 +780,43 @@ class ArgumentSpec(object):
|
||||||
),
|
),
|
||||||
active=dict(
|
active=dict(
|
||||||
type='bool'
|
type='bool'
|
||||||
|
),
|
||||||
|
state=dict(
|
||||||
|
default='present',
|
||||||
|
choices=['present', 'absent']
|
||||||
|
),
|
||||||
|
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 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():
|
def main():
|
||||||
if not HAS_F5SDK:
|
|
||||||
raise F5ModuleError("The python f5-sdk module is required")
|
|
||||||
|
|
||||||
spec = ArgumentSpec()
|
spec = ArgumentSpec()
|
||||||
|
|
||||||
client = AnsibleF5Client(
|
module = AnsibleModule(
|
||||||
argument_spec=spec.argument_spec,
|
argument_spec=spec.argument_spec,
|
||||||
supports_check_mode=spec.supports_check_mode,
|
supports_check_mode=spec.supports_check_mode,
|
||||||
f5_product_name=spec.f5_product_name,
|
|
||||||
mutually_exclusive=[
|
mutually_exclusive=[
|
||||||
['file', 'template']
|
['file', 'template']
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
if not HAS_F5SDK:
|
||||||
|
module.fail_json(msg="The python f5-sdk module is required")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
mm = ModuleManager(client)
|
client = F5Client(**module.params)
|
||||||
|
mm = ModuleManager(module=module, client=client)
|
||||||
results = mm.exec_module()
|
results = mm.exec_module()
|
||||||
cleanup_tokens(client)
|
cleanup_tokens(client)
|
||||||
client.module.exit_json(**results)
|
module.exit_json(**results)
|
||||||
except F5ModuleError as e:
|
except F5ModuleError as e:
|
||||||
cleanup_tokens(client)
|
cleanup_tokens(client)
|
||||||
client.module.fail_json(msg=str(e))
|
module.fail_json(msg=str(e))
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|
|
@ -162,29 +162,48 @@ failed_conditions:
|
||||||
import re
|
import re
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from ansible.module_utils.basic import env_fallback
|
|
||||||
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
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from ansible.module_utils.f5_utils import run_commands
|
from ansible.module_utils.f5_utils import run_commands
|
||||||
HAS_CLI_TRANSPORT = True
|
HAS_CLI_TRANSPORT = True
|
||||||
except ImportError:
|
except ImportError:
|
||||||
HAS_CLI_TRANSPORT = False
|
HAS_CLI_TRANSPORT = False
|
||||||
|
|
||||||
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
|
from ansible.module_utils.basic import env_fallback
|
||||||
from ansible.module_utils.six import string_types
|
from ansible.module_utils.six import string_types
|
||||||
from ansible.module_utils.network.common.parsing import FailedConditionsError
|
from ansible.module_utils.network.common.parsing import FailedConditionsError
|
||||||
from ansible.module_utils.network.common.parsing import Conditional
|
from ansible.module_utils.network.common.parsing import Conditional
|
||||||
from ansible.module_utils.network.common.utils import ComplexList
|
from ansible.module_utils.network.common.utils import ComplexList
|
||||||
from ansible.module_utils.network.common.utils import to_list
|
from ansible.module_utils.network.common.utils import to_list
|
||||||
from ansible.module_utils.six import iteritems
|
|
||||||
from collections import defaultdict
|
|
||||||
from collections import deque
|
from collections import deque
|
||||||
|
|
||||||
|
HAS_DEVEL_IMPORTS = False
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError
|
# 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:
|
except ImportError:
|
||||||
HAS_F5SDK = False
|
HAS_F5SDK = False
|
||||||
|
|
||||||
|
@ -192,36 +211,6 @@ except ImportError:
|
||||||
class Parameters(AnsibleF5Parameters):
|
class Parameters(AnsibleF5Parameters):
|
||||||
returnables = ['stdout', 'stdout_lines', 'warnings']
|
returnables = ['stdout', 'stdout_lines', 'warnings']
|
||||||
|
|
||||||
def __init__(self, params=None):
|
|
||||||
self._values = defaultdict(lambda: None)
|
|
||||||
self._values['__warnings'] = []
|
|
||||||
if params:
|
|
||||||
self.update(params=params)
|
|
||||||
|
|
||||||
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 to_return(self):
|
def to_return(self):
|
||||||
result = {}
|
result = {}
|
||||||
for returnable in self.returnables:
|
for returnable in self.returnables:
|
||||||
|
@ -260,9 +249,10 @@ class Parameters(AnsibleF5Parameters):
|
||||||
|
|
||||||
|
|
||||||
class ModuleManager(object):
|
class ModuleManager(object):
|
||||||
def __init__(self, client):
|
def __init__(self, *args, **kwargs):
|
||||||
self.client = client
|
self.module = kwargs.get('module', None)
|
||||||
self.want = Parameters(self.client.module.params)
|
self.client = kwargs.get('client', None)
|
||||||
|
self.want = Parameters(params=self.module.params)
|
||||||
self.changes = Parameters()
|
self.changes = Parameters()
|
||||||
|
|
||||||
def _to_lines(self, stdout):
|
def _to_lines(self, stdout):
|
||||||
|
@ -278,7 +268,7 @@ class ModuleManager(object):
|
||||||
'list', 'show',
|
'list', 'show',
|
||||||
'modify cli preference pager disabled'
|
'modify cli preference pager disabled'
|
||||||
]
|
]
|
||||||
if self.client.module.params['transport'] != 'cli':
|
if self.module.params['transport'] != 'cli':
|
||||||
valid_configs = list(map(self.want._ensure_tmsh_prefix, valid_configs))
|
valid_configs = list(map(self.want._ensure_tmsh_prefix, valid_configs))
|
||||||
if any(cmd.startswith(x) for x in valid_configs):
|
if any(cmd.startswith(x) for x in valid_configs):
|
||||||
return True
|
return True
|
||||||
|
@ -308,12 +298,12 @@ class ModuleManager(object):
|
||||||
|
|
||||||
conditionals = [Conditional(c) for c in wait_for]
|
conditionals = [Conditional(c) for c in wait_for]
|
||||||
|
|
||||||
if self.client.check_mode:
|
if self.module.check_mode:
|
||||||
return
|
return
|
||||||
|
|
||||||
while retries > 0:
|
while retries > 0:
|
||||||
if self.client.module.params['transport'] == 'cli' and HAS_CLI_TRANSPORT:
|
if self.module.params['transport'] == 'cli' and HAS_CLI_TRANSPORT:
|
||||||
responses = self._run_commands(self.client.module, commands)
|
responses = self._run_commands(self.module, commands)
|
||||||
else:
|
else:
|
||||||
responses = self.execute_on_device(commands)
|
responses = self.execute_on_device(commands)
|
||||||
|
|
||||||
|
@ -334,11 +324,12 @@ class ModuleManager(object):
|
||||||
errmsg = 'One or more conditional statements have not been satisfied'
|
errmsg = 'One or more conditional statements have not been satisfied'
|
||||||
raise FailedConditionsError(errmsg, failed_conditions)
|
raise FailedConditionsError(errmsg, failed_conditions)
|
||||||
|
|
||||||
self.changes = Parameters({
|
changes = {
|
||||||
'stdout': responses,
|
'stdout': responses,
|
||||||
'stdout_lines': self._to_lines(responses),
|
'stdout_lines': self._to_lines(responses),
|
||||||
'warnings': warnings
|
'warnings': warnings
|
||||||
})
|
}
|
||||||
|
self.changes = Parameters(params=changes)
|
||||||
if any(x for x in self.want.user_commands if x.startswith(changed)):
|
if any(x for x in self.want.user_commands if x.startswith(changed)):
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
@ -354,11 +345,11 @@ class ModuleManager(object):
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
transform = ComplexList(spec, self.client.module)
|
transform = ComplexList(spec, self.module)
|
||||||
commands = transform(commands)
|
commands = transform(commands)
|
||||||
|
|
||||||
for index, item in enumerate(commands):
|
for index, item in enumerate(commands):
|
||||||
if not self._is_valid_mode(item['command']) and self.client.module.params['transport'] != 'cli':
|
if not self._is_valid_mode(item['command']) and self.module.params['transport'] != 'cli':
|
||||||
warnings.append(
|
warnings.append(
|
||||||
'Using "write" commands is not idempotent. You should use '
|
'Using "write" commands is not idempotent. You should use '
|
||||||
'a module that is specifically made for that. If such a '
|
'a module that is specifically made for that. If such a '
|
||||||
|
@ -394,7 +385,7 @@ class ModuleManager(object):
|
||||||
class ArgumentSpec(object):
|
class ArgumentSpec(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.supports_check_mode = True
|
self.supports_check_mode = True
|
||||||
self.argument_spec = dict(
|
argument_spec = dict(
|
||||||
commands=dict(
|
commands=dict(
|
||||||
type='raw',
|
type='raw',
|
||||||
required=True
|
required=True
|
||||||
|
@ -421,44 +412,38 @@ class ArgumentSpec(object):
|
||||||
choices=['cli', 'rest']
|
choices=['cli', 'rest']
|
||||||
),
|
),
|
||||||
password=dict(
|
password=dict(
|
||||||
required=False,
|
|
||||||
fallback=(env_fallback, ['F5_PASSWORD']),
|
fallback=(env_fallback, ['F5_PASSWORD']),
|
||||||
no_log=True
|
no_log=True
|
||||||
|
),
|
||||||
|
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 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():
|
def main():
|
||||||
spec = ArgumentSpec()
|
spec = ArgumentSpec()
|
||||||
|
|
||||||
client = AnsibleF5Client(
|
module = AnsibleModule(
|
||||||
argument_spec=spec.argument_spec,
|
argument_spec=spec.argument_spec,
|
||||||
supports_check_mode=spec.supports_check_mode,
|
supports_check_mode=spec.supports_check_mode
|
||||||
f5_product_name=spec.f5_product_name
|
|
||||||
)
|
)
|
||||||
|
if module.params['transport'] != 'cli' and not HAS_F5SDK:
|
||||||
if client.module.params['transport'] != 'cli' and not HAS_F5SDK:
|
module.fail_json(msg="The python f5-sdk module is required to use the rest api")
|
||||||
raise F5ModuleError("The python f5-sdk module is required to use the rest api")
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
mm = ModuleManager(client)
|
client = F5Client(**module.params)
|
||||||
|
mm = ModuleManager(module=module, client=client)
|
||||||
results = mm.exec_module()
|
results = mm.exec_module()
|
||||||
cleanup_tokens(client)
|
cleanup_tokens(client)
|
||||||
client.module.exit_json(**results)
|
module.exit_json(**results)
|
||||||
except F5ModuleError as e:
|
except F5ModuleError as e:
|
||||||
cleanup_tokens(client)
|
cleanup_tokens(client)
|
||||||
client.module.fail_json(msg=str(e))
|
module.fail_json(msg=str(e))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
|
@ -34,18 +34,14 @@ options:
|
||||||
no changes are made, the configuration is still saved to the
|
no changes are made, the configuration is still saved to the
|
||||||
startup config. This option will always cause the module to
|
startup config. This option will always cause the module to
|
||||||
return changed.
|
return changed.
|
||||||
choices:
|
type: bool
|
||||||
- yes
|
|
||||||
- no
|
|
||||||
default: no
|
default: no
|
||||||
reset:
|
reset:
|
||||||
description:
|
description:
|
||||||
- Loads the default configuration on the device. If this option
|
- Loads the default configuration on the device. If this option
|
||||||
is specified, the default configuration will be loaded before
|
is specified, the default configuration will be loaded before
|
||||||
any commands or other provided configuration is run.
|
any commands or other provided configuration is run.
|
||||||
choices:
|
type: bool
|
||||||
- yes
|
|
||||||
- no
|
|
||||||
default: no
|
default: no
|
||||||
merge_content:
|
merge_content:
|
||||||
description:
|
description:
|
||||||
|
@ -59,15 +55,8 @@ options:
|
||||||
- Validates the specified configuration to see whether they are
|
- Validates the specified configuration to see whether they are
|
||||||
valid to replace the running configuration. The running
|
valid to replace the running configuration. The running
|
||||||
configuration will not be changed.
|
configuration will not be changed.
|
||||||
choices:
|
type: bool
|
||||||
- yes
|
default: no
|
||||||
- no
|
|
||||||
default: yes
|
|
||||||
notes:
|
|
||||||
- Requires the f5-sdk Python package on the host. This is as easy as pip
|
|
||||||
install f5-sdk.
|
|
||||||
requirements:
|
|
||||||
- f5-sdk >= 2.2.3
|
|
||||||
extends_documentation_fragment: f5
|
extends_documentation_fragment: f5
|
||||||
author:
|
author:
|
||||||
- Tim Rupp (@caphrim007)
|
- Tim Rupp (@caphrim007)
|
||||||
|
@ -125,15 +114,35 @@ try:
|
||||||
except ImportError:
|
except ImportError:
|
||||||
from io import StringIO
|
from io import StringIO
|
||||||
|
|
||||||
from ansible.module_utils.f5_utils import AnsibleF5Client
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
from ansible.module_utils.f5_utils import AnsibleF5Parameters
|
|
||||||
from ansible.module_utils.f5_utils import HAS_F5SDK
|
HAS_DEVEL_IMPORTS = False
|
||||||
from ansible.module_utils.f5_utils import F5ModuleError
|
|
||||||
from ansible.module_utils.six import iteritems
|
|
||||||
from collections import defaultdict
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError
|
# 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:
|
except ImportError:
|
||||||
HAS_F5SDK = False
|
HAS_F5SDK = False
|
||||||
|
|
||||||
|
@ -141,11 +150,6 @@ except ImportError:
|
||||||
class Parameters(AnsibleF5Parameters):
|
class Parameters(AnsibleF5Parameters):
|
||||||
returnables = ['stdout', 'stdout_lines']
|
returnables = ['stdout', 'stdout_lines']
|
||||||
|
|
||||||
def __init__(self, params=None):
|
|
||||||
self._values = defaultdict(lambda: None)
|
|
||||||
if params:
|
|
||||||
self.update(params)
|
|
||||||
|
|
||||||
def to_return(self):
|
def to_return(self):
|
||||||
result = {}
|
result = {}
|
||||||
for returnable in self.returnables:
|
for returnable in self.returnables:
|
||||||
|
@ -153,34 +157,12 @@ class Parameters(AnsibleF5Parameters):
|
||||||
result = self._filter_params(result)
|
result = self._filter_params(result)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
|
|
||||||
class ModuleManager(object):
|
class ModuleManager(object):
|
||||||
def __init__(self, client):
|
def __init__(self, *args, **kwargs):
|
||||||
self.client = client
|
self.module = kwargs.get('module', None)
|
||||||
self.want = Parameters(self.client.module.params)
|
self.client = kwargs.get('client', None)
|
||||||
|
self.want = Parameters(params=self.module.params)
|
||||||
self.changes = Parameters()
|
self.changes = Parameters()
|
||||||
|
|
||||||
def _set_changed_options(self):
|
def _set_changed_options(self):
|
||||||
|
@ -189,7 +171,7 @@ class ModuleManager(object):
|
||||||
if getattr(self.want, key) is not None:
|
if getattr(self.want, key) is not None:
|
||||||
changed[key] = getattr(self.want, key)
|
changed[key] = getattr(self.want, key)
|
||||||
if changed:
|
if changed:
|
||||||
self.changes = Parameters(changed)
|
self.changes = Parameters(params=changed)
|
||||||
|
|
||||||
def _to_lines(self, stdout):
|
def _to_lines(self, stdout):
|
||||||
lines = list()
|
lines = list()
|
||||||
|
@ -229,13 +211,14 @@ class ModuleManager(object):
|
||||||
response = self.save()
|
response = self.save()
|
||||||
responses.append(response)
|
responses.append(response)
|
||||||
|
|
||||||
self.changes = Parameters({
|
changes = {
|
||||||
'stdout': responses,
|
'stdout': responses,
|
||||||
'stdout_lines': self._to_lines(responses)
|
'stdout_lines': self._to_lines(responses)
|
||||||
})
|
}
|
||||||
|
self.changes = Parameters(params=changes)
|
||||||
|
|
||||||
def reset(self):
|
def reset(self):
|
||||||
if self.client.check_mode:
|
if self.module.check_mode:
|
||||||
return True
|
return True
|
||||||
return self.reset_device()
|
return self.reset_device()
|
||||||
|
|
||||||
|
@ -254,7 +237,7 @@ class ModuleManager(object):
|
||||||
remote_path = "/var/config/rest/downloads/{0}".format(temp_name)
|
remote_path = "/var/config/rest/downloads/{0}".format(temp_name)
|
||||||
temp_path = '/tmp/' + temp_name
|
temp_path = '/tmp/' + temp_name
|
||||||
|
|
||||||
if self.client.check_mode:
|
if self.module.check_mode:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
self.upload_to_device(temp_name)
|
self.upload_to_device(temp_name)
|
||||||
|
@ -302,7 +285,7 @@ class ModuleManager(object):
|
||||||
upload.upload_stringio(template, temp_name)
|
upload.upload_stringio(template, temp_name)
|
||||||
|
|
||||||
def save(self):
|
def save(self):
|
||||||
if self.client.check_mode:
|
if self.module.check_mode:
|
||||||
return True
|
return True
|
||||||
return self.save_on_device()
|
return self.save_on_device()
|
||||||
|
|
||||||
|
@ -321,7 +304,7 @@ class ModuleManager(object):
|
||||||
class ArgumentSpec(object):
|
class ArgumentSpec(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.supports_check_mode = True
|
self.supports_check_mode = True
|
||||||
self.argument_spec = dict(
|
argument_spec = dict(
|
||||||
reset=dict(
|
reset=dict(
|
||||||
type='bool',
|
type='bool',
|
||||||
default=False
|
default=False
|
||||||
|
@ -329,46 +312,37 @@ class ArgumentSpec(object):
|
||||||
merge_content=dict(),
|
merge_content=dict(),
|
||||||
verify=dict(
|
verify=dict(
|
||||||
type='bool',
|
type='bool',
|
||||||
default=True
|
default=False
|
||||||
),
|
),
|
||||||
save=dict(
|
save=dict(
|
||||||
type='bool',
|
type='bool',
|
||||||
default=True
|
default=True
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
self.f5_product_name = 'bigip'
|
self.argument_spec = {}
|
||||||
|
self.argument_spec.update(f5_argument_spec)
|
||||||
|
self.argument_spec.update(argument_spec)
|
||||||
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():
|
def main():
|
||||||
if not HAS_F5SDK:
|
|
||||||
raise F5ModuleError("The python f5-sdk module is required")
|
|
||||||
|
|
||||||
spec = ArgumentSpec()
|
spec = ArgumentSpec()
|
||||||
|
|
||||||
client = AnsibleF5Client(
|
module = AnsibleModule(
|
||||||
argument_spec=spec.argument_spec,
|
argument_spec=spec.argument_spec,
|
||||||
supports_check_mode=spec.supports_check_mode,
|
supports_check_mode=spec.supports_check_mode
|
||||||
f5_product_name=spec.f5_product_name
|
|
||||||
)
|
)
|
||||||
|
if not HAS_F5SDK:
|
||||||
|
module.fail_json(msg="The python f5-sdk module is required")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
mm = ModuleManager(client)
|
client = F5Client(**module.params)
|
||||||
|
mm = ModuleManager(module=module, client=client)
|
||||||
results = mm.exec_module()
|
results = mm.exec_module()
|
||||||
cleanup_tokens(client)
|
cleanup_tokens(client)
|
||||||
client.module.exit_json(**results)
|
module.exit_json(**results)
|
||||||
except F5ModuleError as e:
|
except F5ModuleError as ex:
|
||||||
cleanup_tokens(client)
|
cleanup_tokens(client)
|
||||||
client.module.fail_json(msg=str(e))
|
module.fail_json(msg=str(ex))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
|
@ -53,12 +53,8 @@ options:
|
||||||
- yes
|
- yes
|
||||||
- no
|
- no
|
||||||
notes:
|
notes:
|
||||||
- Requires the f5-sdk Python package on the host. This is as easy as pip
|
- Requires the objectpath Python package on the host. This is as easy as
|
||||||
install f5-sdk.
|
C(pip install objectpath).
|
||||||
- Requires the objectpath Python package on the host. This is as easy as pip
|
|
||||||
install objectpath.
|
|
||||||
requirements:
|
|
||||||
- f5-sdk >= 2.2.3
|
|
||||||
extends_documentation_fragment: f5
|
extends_documentation_fragment: f5
|
||||||
author:
|
author:
|
||||||
- Tim Rupp (@caphrim007)
|
- Tim Rupp (@caphrim007)
|
||||||
|
@ -100,8 +96,8 @@ RETURN = r'''
|
||||||
# only common fields returned
|
# only common fields returned
|
||||||
'''
|
'''
|
||||||
|
|
||||||
import time
|
|
||||||
import re
|
import re
|
||||||
|
import time
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from objectpath import Tree
|
from objectpath import Tree
|
||||||
|
@ -109,14 +105,36 @@ try:
|
||||||
except ImportError:
|
except ImportError:
|
||||||
HAS_OBJPATH = False
|
HAS_OBJPATH = False
|
||||||
|
|
||||||
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
from ansible.module_utils.basic import BOOLEANS_TRUE
|
from ansible.module_utils.basic import BOOLEANS_TRUE
|
||||||
from ansible.module_utils.f5_utils import AnsibleF5Client
|
|
||||||
from ansible.module_utils.f5_utils import AnsibleF5Parameters
|
HAS_DEVEL_IMPORTS = False
|
||||||
from ansible.module_utils.f5_utils import HAS_F5SDK
|
|
||||||
from ansible.module_utils.f5_utils import F5ModuleError
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError
|
# 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:
|
except ImportError:
|
||||||
HAS_F5SDK = False
|
HAS_F5SDK = False
|
||||||
|
|
||||||
|
@ -184,9 +202,11 @@ class Parameters(AnsibleF5Parameters):
|
||||||
|
|
||||||
|
|
||||||
class ModuleManager(object):
|
class ModuleManager(object):
|
||||||
def __init__(self, client):
|
def __init__(self, *args, **kwargs):
|
||||||
self.client = client
|
self.module = kwargs.get('module', None)
|
||||||
self.want = Parameters(self.client.module.params)
|
self.client = kwargs.get('client', None)
|
||||||
|
self.want = Parameters(params=self.module.params)
|
||||||
|
self.changes = Parameters()
|
||||||
|
|
||||||
def exec_module(self):
|
def exec_module(self):
|
||||||
result = dict()
|
result = dict()
|
||||||
|
@ -319,8 +339,9 @@ class ModuleManager(object):
|
||||||
|
|
||||||
class ArgumentSpec(object):
|
class ArgumentSpec(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.supports_check_mode = True
|
self.supports_check_mode = False
|
||||||
self.argument_spec = dict(
|
|
||||||
|
argument_spec = dict(
|
||||||
sync_device_to_group=dict(
|
sync_device_to_group=dict(
|
||||||
type='bool'
|
type='bool'
|
||||||
),
|
),
|
||||||
|
@ -335,7 +356,10 @@ class ArgumentSpec(object):
|
||||||
required=True
|
required=True
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
self.f5_product_name = 'bigip'
|
self.argument_spec = {}
|
||||||
|
self.argument_spec.update(f5_argument_spec)
|
||||||
|
self.argument_spec.update(argument_spec)
|
||||||
|
|
||||||
self.required_one_of = [
|
self.required_one_of = [
|
||||||
['sync_device_to_group', 'sync_most_recent_to_device']
|
['sync_device_to_group', 'sync_most_recent_to_device']
|
||||||
]
|
]
|
||||||
|
@ -347,45 +371,27 @@ class ArgumentSpec(object):
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
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():
|
def main():
|
||||||
if not HAS_F5SDK:
|
|
||||||
raise F5ModuleError(
|
|
||||||
"The python 'f5-sdk' module is required. This can be done with 'pip install f5-sdk'"
|
|
||||||
)
|
|
||||||
|
|
||||||
if not HAS_OBJPATH:
|
|
||||||
raise F5ModuleError(
|
|
||||||
"The python 'objectpath' module is required. This can be done with 'pip install objectpath'"
|
|
||||||
)
|
|
||||||
|
|
||||||
spec = ArgumentSpec()
|
spec = ArgumentSpec()
|
||||||
|
|
||||||
client = AnsibleF5Client(
|
module = AnsibleModule(
|
||||||
argument_spec=spec.argument_spec,
|
argument_spec=spec.argument_spec,
|
||||||
supports_check_mode=spec.supports_check_mode,
|
supports_check_mode=spec.supports_check_mode,
|
||||||
mutually_exclusive=spec.mutually_exclusive,
|
mutually_exclusive=spec.mutually_exclusive,
|
||||||
required_one_of=spec.required_one_of,
|
required_one_of=spec.required_one_of
|
||||||
f5_product_name=spec.f5_product_name
|
|
||||||
)
|
)
|
||||||
|
if not HAS_F5SDK:
|
||||||
|
module.fail_json(msg="The python f5-sdk module is required")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
mm = ModuleManager(client)
|
client = F5Client(**module.params)
|
||||||
|
mm = ModuleManager(module=module, client=client)
|
||||||
results = mm.exec_module()
|
results = mm.exec_module()
|
||||||
cleanup_tokens(client)
|
cleanup_tokens(client)
|
||||||
client.module.exit_json(**results)
|
module.exit_json(**results)
|
||||||
except F5ModuleError as e:
|
except F5ModuleError as ex:
|
||||||
cleanup_tokens(client)
|
cleanup_tokens(client)
|
||||||
client.module.fail_json(msg=str(e))
|
module.fail_json(msg=str(ex))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
bigip_configsync_action.py
|
|
|
@ -70,13 +70,9 @@ options:
|
||||||
provided, a default of C(62960) will be used. This value must be between
|
provided, a default of C(62960) will be used. This value must be between
|
||||||
0 and 65535.
|
0 and 65535.
|
||||||
notes:
|
notes:
|
||||||
- Requires the f5-sdk Python package on the host. This is as easy as pip
|
|
||||||
install f5-sdk.
|
|
||||||
- This module is primarily used as a component of configuring HA pairs of
|
- This module is primarily used as a component of configuring HA pairs of
|
||||||
BIG-IP devices.
|
BIG-IP devices.
|
||||||
- Requires BIG-IP >= 12.0.0
|
- Requires BIG-IP >= 12.0.0
|
||||||
requirements:
|
|
||||||
- f5-sdk >= 2.2.3
|
|
||||||
extends_documentation_fragment: f5
|
extends_documentation_fragment: f5
|
||||||
author:
|
author:
|
||||||
- Tim Rupp (@caphrim007)
|
- Tim Rupp (@caphrim007)
|
||||||
|
@ -142,26 +138,49 @@ multicast_port:
|
||||||
sample: 1026
|
sample: 1026
|
||||||
'''
|
'''
|
||||||
|
|
||||||
from ansible.module_utils.f5_utils import AnsibleF5Client
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
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 ansible.module_utils.six import iteritems
|
||||||
|
|
||||||
|
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:
|
try:
|
||||||
from netaddr import IPAddress, AddrFormatError
|
from netaddr import IPAddress, AddrFormatError
|
||||||
HAS_NETADDR = True
|
HAS_NETADDR = True
|
||||||
except ImportError:
|
except ImportError:
|
||||||
HAS_NETADDR = False
|
HAS_NETADDR = False
|
||||||
|
|
||||||
try:
|
|
||||||
from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError
|
|
||||||
except ImportError:
|
|
||||||
HAS_F5SDK = False
|
|
||||||
|
|
||||||
|
|
||||||
class Parameters(AnsibleF5Parameters):
|
class Parameters(AnsibleF5Parameters):
|
||||||
api_map = {
|
api_map = {
|
||||||
|
'unicastAddress': 'unicast_failover',
|
||||||
'configsyncIp': 'config_sync_ip',
|
'configsyncIp': 'config_sync_ip',
|
||||||
'multicastInterface': 'multicast_interface',
|
'multicastInterface': 'multicast_interface',
|
||||||
'multicastIp': 'multicast_address',
|
'multicastIp': 'multicast_address',
|
||||||
|
@ -234,44 +253,6 @@ class Parameters(AnsibleF5Parameters):
|
||||||
result = self._get_validated_ip_address('config_sync_ip')
|
result = self._get_validated_ip_address('config_sync_ip')
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@property
|
|
||||||
def unicastAddress(self):
|
|
||||||
return self.unicast_failover
|
|
||||||
|
|
||||||
@unicastAddress.setter
|
|
||||||
def unicastAddress(self, value):
|
|
||||||
result = []
|
|
||||||
for item in value:
|
|
||||||
item['address'] = item.pop('ip')
|
|
||||||
result.append(item)
|
|
||||||
if result:
|
|
||||||
self._values['unicast_failover'] = result
|
|
||||||
|
|
||||||
@property
|
|
||||||
def unicast_failover(self):
|
|
||||||
if self._values['unicast_failover'] is None:
|
|
||||||
return None
|
|
||||||
if self._values['unicast_failover'] == ['none']:
|
|
||||||
return []
|
|
||||||
result = []
|
|
||||||
for item in self._values['unicast_failover']:
|
|
||||||
address = item.get('address', None)
|
|
||||||
port = item.get('port', None)
|
|
||||||
address = self._validate_unicast_failover_address(address)
|
|
||||||
port = self._validate_unicast_failover_port(port)
|
|
||||||
result.append(
|
|
||||||
dict(
|
|
||||||
effectiveIp=address,
|
|
||||||
effectivePort=port,
|
|
||||||
ip=address,
|
|
||||||
port=port
|
|
||||||
)
|
|
||||||
)
|
|
||||||
if result:
|
|
||||||
return result
|
|
||||||
else:
|
|
||||||
return None
|
|
||||||
|
|
||||||
def _validate_unicast_failover_port(self, port):
|
def _validate_unicast_failover_port(self, port):
|
||||||
try:
|
try:
|
||||||
result = int(port)
|
result = int(port)
|
||||||
|
@ -310,15 +291,36 @@ class Parameters(AnsibleF5Parameters):
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
def api_params(self):
|
|
||||||
result = {}
|
class ApiParameters(Parameters):
|
||||||
for api_attribute in self.api_attributes:
|
pass
|
||||||
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:
|
class ModuleParameters(Parameters):
|
||||||
result[api_attribute] = getattr(self, api_attribute)
|
@property
|
||||||
result = self._filter_params(result)
|
def unicast_failover(self):
|
||||||
|
if self._values['unicast_failover'] is None:
|
||||||
|
return None
|
||||||
|
if self._values['unicast_failover'] == ['none']:
|
||||||
|
return []
|
||||||
|
result = []
|
||||||
|
for item in self._values['unicast_failover']:
|
||||||
|
address = item.get('address', None)
|
||||||
|
port = item.get('port', None)
|
||||||
|
address = self._validate_unicast_failover_address(address)
|
||||||
|
port = self._validate_unicast_failover_port(port)
|
||||||
|
result.append(
|
||||||
|
dict(
|
||||||
|
effectiveIp=address,
|
||||||
|
effectivePort=port,
|
||||||
|
ip=address,
|
||||||
|
port=port
|
||||||
|
)
|
||||||
|
)
|
||||||
|
if result:
|
||||||
return result
|
return result
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
class Changes(Parameters):
|
class Changes(Parameters):
|
||||||
|
@ -459,9 +461,10 @@ class Difference(object):
|
||||||
|
|
||||||
|
|
||||||
class ModuleManager(object):
|
class ModuleManager(object):
|
||||||
def __init__(self, client):
|
def __init__(self, *args, **kwargs):
|
||||||
self.client = client
|
self.module = kwargs.get('module', None)
|
||||||
self.want = Parameters(self.client.module.params)
|
self.client = kwargs.get('client', None)
|
||||||
|
self.want = ModuleParameters(params=self.module.params)
|
||||||
self.changes = UsableChanges()
|
self.changes = UsableChanges()
|
||||||
|
|
||||||
def _update_changed_options(self):
|
def _update_changed_options(self):
|
||||||
|
@ -478,7 +481,7 @@ class ModuleManager(object):
|
||||||
else:
|
else:
|
||||||
changed[k] = change
|
changed[k] = change
|
||||||
if changed:
|
if changed:
|
||||||
self.changes = UsableChanges(changed)
|
self.changes = UsableChanges(params=changed)
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -499,7 +502,7 @@ class ModuleManager(object):
|
||||||
except iControlUnexpectedHTTPError as e:
|
except iControlUnexpectedHTTPError as e:
|
||||||
raise F5ModuleError(str(e))
|
raise F5ModuleError(str(e))
|
||||||
|
|
||||||
reportable = ReportableChanges(self.changes.to_return())
|
reportable = ReportableChanges(params=self.changes.to_return())
|
||||||
changes = reportable.to_return()
|
changes = reportable.to_return()
|
||||||
result.update(**changes)
|
result.update(**changes)
|
||||||
result.update(dict(changed=changed))
|
result.update(dict(changed=changed))
|
||||||
|
@ -509,7 +512,7 @@ class ModuleManager(object):
|
||||||
self.have = self.read_current_from_device()
|
self.have = self.read_current_from_device()
|
||||||
if not self.should_update():
|
if not self.should_update():
|
||||||
return False
|
return False
|
||||||
if self.client.check_mode:
|
if self.module.check_mode:
|
||||||
return True
|
return True
|
||||||
self.update_on_device()
|
self.update_on_device()
|
||||||
return True
|
return True
|
||||||
|
@ -530,7 +533,7 @@ class ModuleManager(object):
|
||||||
for resource in collection:
|
for resource in collection:
|
||||||
if resource.selfDevice == 'true':
|
if resource.selfDevice == 'true':
|
||||||
result = resource.attrs
|
result = resource.attrs
|
||||||
return Parameters(result)
|
return ApiParameters(params=result)
|
||||||
raise F5ModuleError(
|
raise F5ModuleError(
|
||||||
"The host device was not found."
|
"The host device was not found."
|
||||||
)
|
)
|
||||||
|
@ -539,7 +542,7 @@ class ModuleManager(object):
|
||||||
class ArgumentSpec(object):
|
class ArgumentSpec(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.supports_check_mode = True
|
self.supports_check_mode = True
|
||||||
self.argument_spec = dict(
|
argument_spec = dict(
|
||||||
multicast_port=dict(
|
multicast_port=dict(
|
||||||
type='int'
|
type='int'
|
||||||
),
|
),
|
||||||
|
@ -559,45 +562,37 @@ class ArgumentSpec(object):
|
||||||
choices=['present']
|
choices=['present']
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
self.f5_product_name = 'bigip'
|
self.argument_spec = {}
|
||||||
|
self.argument_spec.update(f5_argument_spec)
|
||||||
|
self.argument_spec.update(argument_spec)
|
||||||
self.required_together = [
|
self.required_together = [
|
||||||
['multicast_address', 'multicast_interface', 'multicast_port']
|
['multicast_address', 'multicast_interface', 'multicast_port']
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
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():
|
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()
|
spec = ArgumentSpec()
|
||||||
|
|
||||||
client = AnsibleF5Client(
|
module = AnsibleModule(
|
||||||
argument_spec=spec.argument_spec,
|
argument_spec=spec.argument_spec,
|
||||||
supports_check_mode=spec.supports_check_mode,
|
supports_check_mode=spec.supports_check_mode,
|
||||||
f5_product_name=spec.f5_product_name
|
required_together=spec.required_together
|
||||||
)
|
)
|
||||||
|
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:
|
try:
|
||||||
mm = ModuleManager(client)
|
client = F5Client(**module.params)
|
||||||
|
mm = ModuleManager(module=module, client=client)
|
||||||
results = mm.exec_module()
|
results = mm.exec_module()
|
||||||
cleanup_tokens(client)
|
cleanup_tokens(client)
|
||||||
client.module.exit_json(**results)
|
module.exit_json(**results)
|
||||||
except F5ModuleError as e:
|
except F5ModuleError as ex:
|
||||||
cleanup_tokens(client)
|
cleanup_tokens(client)
|
||||||
client.module.fail_json(msg=str(e))
|
module.fail_json(msg=str(ex))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
|
@ -55,12 +55,7 @@ options:
|
||||||
choices:
|
choices:
|
||||||
- absent
|
- absent
|
||||||
- present
|
- present
|
||||||
notes:
|
|
||||||
- Requires the f5-sdk Python package on the host. This is as easy as pip
|
|
||||||
install f5-sdk.
|
|
||||||
extends_documentation_fragment: f5
|
extends_documentation_fragment: f5
|
||||||
requirements:
|
|
||||||
- f5-sdk
|
|
||||||
author:
|
author:
|
||||||
- Tim Rupp (@caphrim007)
|
- Tim Rupp (@caphrim007)
|
||||||
'''
|
'''
|
||||||
|
@ -109,13 +104,35 @@ warnings:
|
||||||
sample: ['...', '...']
|
sample: ['...', '...']
|
||||||
'''
|
'''
|
||||||
|
|
||||||
from ansible.module_utils.f5_utils import AnsibleF5Client
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
from ansible.module_utils.f5_utils import AnsibleF5Parameters
|
|
||||||
from ansible.module_utils.f5_utils import HAS_F5SDK
|
HAS_DEVEL_IMPORTS = False
|
||||||
from ansible.module_utils.f5_utils import F5ModuleError
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError
|
# 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:
|
except ImportError:
|
||||||
HAS_F5SDK = False
|
HAS_F5SDK = False
|
||||||
|
|
||||||
|
@ -151,16 +168,6 @@ class Parameters(AnsibleF5Parameters):
|
||||||
result = self._filter_params(result)
|
result = self._filter_params(result)
|
||||||
return result
|
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
|
@property
|
||||||
def search(self):
|
def search(self):
|
||||||
result = []
|
result = []
|
||||||
|
@ -211,10 +218,11 @@ class Parameters(AnsibleF5Parameters):
|
||||||
|
|
||||||
|
|
||||||
class ModuleManager(object):
|
class ModuleManager(object):
|
||||||
def __init__(self, client):
|
def __init__(self, *args, **kwargs):
|
||||||
self.client = client
|
self.module = kwargs.get('module', None)
|
||||||
|
self.client = kwargs.get('client', None)
|
||||||
|
self.want = Parameters(params=self.module.params)
|
||||||
self.have = None
|
self.have = None
|
||||||
self.want = Parameters(self.client.module.params)
|
|
||||||
self.changes = Parameters()
|
self.changes = Parameters()
|
||||||
|
|
||||||
def _update_changed_options(self):
|
def _update_changed_options(self):
|
||||||
|
@ -226,7 +234,7 @@ class ModuleManager(object):
|
||||||
if attr1 != attr2:
|
if attr1 != attr2:
|
||||||
changed[key] = attr1
|
changed[key] = attr1
|
||||||
if changed:
|
if changed:
|
||||||
self.changes = Parameters(changed)
|
self.changes = Parameters(params=changed)
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -260,13 +268,13 @@ class ModuleManager(object):
|
||||||
if 'include' not in attrs:
|
if 'include' not in attrs:
|
||||||
attrs['include'] = 4
|
attrs['include'] = 4
|
||||||
result.update(attrs)
|
result.update(attrs)
|
||||||
return Parameters(result)
|
return Parameters(params=result)
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
self.have = self.read_current_from_device()
|
self.have = self.read_current_from_device()
|
||||||
if not self.should_update():
|
if not self.should_update():
|
||||||
return False
|
return False
|
||||||
if self.client.check_mode:
|
if self.module.check_mode:
|
||||||
return True
|
return True
|
||||||
self.update_on_device()
|
self.update_on_device()
|
||||||
return True
|
return True
|
||||||
|
@ -299,7 +307,7 @@ class ModuleManager(object):
|
||||||
if set_new != set_have:
|
if set_new != set_have:
|
||||||
changed[key] = list(set_new)
|
changed[key] = list(set_new)
|
||||||
if changed:
|
if changed:
|
||||||
self.changes = Parameters(changed)
|
self.changes = Parameters(params=changed)
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -313,7 +321,7 @@ class ModuleManager(object):
|
||||||
self.have = self.read_current_from_device()
|
self.have = self.read_current_from_device()
|
||||||
if not self.should_absent():
|
if not self.should_absent():
|
||||||
return False
|
return False
|
||||||
if self.client.check_mode:
|
if self.module.check_mode:
|
||||||
return True
|
return True
|
||||||
self.absent_on_device()
|
self.absent_on_device()
|
||||||
return True
|
return True
|
||||||
|
@ -327,11 +335,9 @@ class ModuleManager(object):
|
||||||
class ArgumentSpec(object):
|
class ArgumentSpec(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.supports_check_mode = True
|
self.supports_check_mode = True
|
||||||
self.argument_spec = dict(
|
argument_spec = dict(
|
||||||
cache=dict(
|
cache=dict(
|
||||||
required=False,
|
choices=['disabled', 'enabled', 'disable', 'enable']
|
||||||
choices=['disabled', 'enabled', 'disable', 'enable'],
|
|
||||||
default=None
|
|
||||||
),
|
),
|
||||||
name_servers=dict(
|
name_servers=dict(
|
||||||
required=False,
|
required=False,
|
||||||
|
@ -355,48 +361,38 @@ class ArgumentSpec(object):
|
||||||
type='int'
|
type='int'
|
||||||
),
|
),
|
||||||
state=dict(
|
state=dict(
|
||||||
required=False,
|
|
||||||
default='present',
|
default='present',
|
||||||
choices=['absent', 'present']
|
choices=['absent', 'present']
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
self.argument_spec = {}
|
||||||
|
self.argument_spec.update(f5_argument_spec)
|
||||||
|
self.argument_spec.update(argument_spec)
|
||||||
self.required_one_of = [
|
self.required_one_of = [
|
||||||
['name_servers', 'search', 'forwarders', 'ip_version', 'cache']
|
['name_servers', 'search', 'forwarders', 'ip_version', 'cache']
|
||||||
]
|
]
|
||||||
self.f5_product_name = 'bigip'
|
|
||||||
|
|
||||||
|
|
||||||
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():
|
def main():
|
||||||
if not HAS_F5SDK:
|
|
||||||
raise F5ModuleError("The python f5-sdk module is required")
|
|
||||||
|
|
||||||
spec = ArgumentSpec()
|
spec = ArgumentSpec()
|
||||||
|
|
||||||
client = AnsibleF5Client(
|
module = AnsibleModule(
|
||||||
argument_spec=spec.argument_spec,
|
argument_spec=spec.argument_spec,
|
||||||
supports_check_mode=spec.supports_check_mode,
|
supports_check_mode=spec.supports_check_mode,
|
||||||
f5_product_name=spec.f5_product_name,
|
|
||||||
required_one_of=spec.required_one_of
|
required_one_of=spec.required_one_of
|
||||||
)
|
)
|
||||||
|
if not HAS_F5SDK:
|
||||||
|
module.fail_json(msg="The python f5-sdk module is required")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
mm = ModuleManager(client)
|
client = F5Client(**module.params)
|
||||||
|
mm = ModuleManager(module=module, client=client)
|
||||||
results = mm.exec_module()
|
results = mm.exec_module()
|
||||||
cleanup_tokens(client)
|
cleanup_tokens(client)
|
||||||
client.module.exit_json(**results)
|
module.exit_json(**results)
|
||||||
except F5ModuleError as e:
|
except F5ModuleError as ex:
|
||||||
cleanup_tokens(client)
|
cleanup_tokens(client)
|
||||||
client.module.fail_json(msg=str(e))
|
module.fail_json(msg=str(ex))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
|
@ -38,18 +38,18 @@ options:
|
||||||
auth_pam_validate_ip:
|
auth_pam_validate_ip:
|
||||||
description:
|
description:
|
||||||
- Sets the authPamValidateIp setting.
|
- Sets the authPamValidateIp setting.
|
||||||
choices: ['on', 'off']
|
type: bool
|
||||||
auth_pam_dashboard_timeout:
|
auth_pam_dashboard_timeout:
|
||||||
description:
|
description:
|
||||||
- Sets whether or not the BIG-IP dashboard will timeout.
|
- Sets whether or not the BIG-IP dashboard will timeout.
|
||||||
choices: ['on', 'off']
|
type: bool
|
||||||
fast_cgi_timeout:
|
fast_cgi_timeout:
|
||||||
description:
|
description:
|
||||||
- Sets the timeout of FastCGI.
|
- Sets the timeout of FastCGI.
|
||||||
hostname_lookup:
|
hostname_lookup:
|
||||||
description:
|
description:
|
||||||
- Sets whether or not to display the hostname, if possible.
|
- Sets whether or not to display the hostname, if possible.
|
||||||
choices: ['on', 'off']
|
type: bool
|
||||||
log_level:
|
log_level:
|
||||||
description:
|
description:
|
||||||
- Sets the minimum httpd log level.
|
- Sets the minimum httpd log level.
|
||||||
|
@ -60,17 +60,14 @@ options:
|
||||||
redirect_http_to_https:
|
redirect_http_to_https:
|
||||||
description:
|
description:
|
||||||
- Whether or not to redirect http requests to the GUI to https.
|
- Whether or not to redirect http requests to the GUI to https.
|
||||||
choices: ['yes', 'no']
|
type: bool
|
||||||
ssl_port:
|
ssl_port:
|
||||||
description:
|
description:
|
||||||
- The HTTPS port to listen on.
|
- The HTTPS port to listen on.
|
||||||
notes:
|
notes:
|
||||||
- Requires the f5-sdk Python package on the host. This is as easy as pip
|
|
||||||
install f5-sdk.
|
|
||||||
- Requires the requests Python package on the host. This is as easy as
|
- Requires the requests Python package on the host. This is as easy as
|
||||||
pip install requests.
|
C(pip install requests).
|
||||||
requirements:
|
requirements:
|
||||||
- f5-sdk >= 3.0.4
|
|
||||||
- requests
|
- requests
|
||||||
extends_documentation_fragment: f5
|
extends_documentation_fragment: f5
|
||||||
author:
|
author:
|
||||||
|
@ -159,15 +156,35 @@ ssl_port:
|
||||||
|
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from ansible.module_utils.f5_utils import AnsibleF5Client
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
from ansible.module_utils.f5_utils import AnsibleF5Parameters
|
|
||||||
from ansible.module_utils.f5_utils import HAS_F5SDK
|
HAS_DEVEL_IMPORTS = False
|
||||||
from ansible.module_utils.f5_utils import F5ModuleError
|
|
||||||
from ansible.module_utils.six import iteritems
|
|
||||||
from collections import defaultdict
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError
|
# 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:
|
except ImportError:
|
||||||
HAS_F5SDK = False
|
HAS_F5SDK = False
|
||||||
|
|
||||||
|
@ -212,46 +229,6 @@ class Parameters(AnsibleF5Parameters):
|
||||||
'allow'
|
'allow'
|
||||||
]
|
]
|
||||||
|
|
||||||
def __init__(self, params=None):
|
|
||||||
self._values = defaultdict(lambda: None)
|
|
||||||
self._values['__warnings'] = []
|
|
||||||
if params:
|
|
||||||
self.update(params=params)
|
|
||||||
|
|
||||||
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 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
|
@property
|
||||||
def auth_pam_idle_timeout(self):
|
def auth_pam_idle_timeout(self):
|
||||||
if self._values['auth_pam_idle_timeout'] is None:
|
if self._values['auth_pam_idle_timeout'] is None:
|
||||||
|
@ -395,9 +372,10 @@ class Difference(object):
|
||||||
|
|
||||||
|
|
||||||
class ModuleManager(object):
|
class ModuleManager(object):
|
||||||
def __init__(self, client):
|
def __init__(self, *args, **kwargs):
|
||||||
self.client = client
|
self.module = kwargs.get('module', None)
|
||||||
self.want = ModuleParameters(params=self.client.module.params)
|
self.client = kwargs.get('client', None)
|
||||||
|
self.want = ModuleParameters(params=self.module.params)
|
||||||
self.have = ApiParameters()
|
self.have = ApiParameters()
|
||||||
self.changes = UsableChanges()
|
self.changes = UsableChanges()
|
||||||
|
|
||||||
|
@ -407,7 +385,7 @@ class ModuleManager(object):
|
||||||
if getattr(self.want, key) is not None:
|
if getattr(self.want, key) is not None:
|
||||||
changed[key] = getattr(self.want, key)
|
changed[key] = getattr(self.want, key)
|
||||||
if changed:
|
if changed:
|
||||||
self.changes = Changes(changed)
|
self.changes = Changes(params=changed)
|
||||||
|
|
||||||
def _update_changed_options(self):
|
def _update_changed_options(self):
|
||||||
diff = Difference(self.want, self.have)
|
diff = Difference(self.want, self.have)
|
||||||
|
@ -423,7 +401,7 @@ class ModuleManager(object):
|
||||||
else:
|
else:
|
||||||
changed[k] = change
|
changed[k] = change
|
||||||
if changed:
|
if changed:
|
||||||
self.changes = UsableChanges(changed)
|
self.changes = UsableChanges(params=changed)
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -441,7 +419,7 @@ class ModuleManager(object):
|
||||||
except iControlUnexpectedHTTPError as e:
|
except iControlUnexpectedHTTPError as e:
|
||||||
raise F5ModuleError(str(e))
|
raise F5ModuleError(str(e))
|
||||||
|
|
||||||
reportable = ReportableChanges(self.changes.to_return())
|
reportable = ReportableChanges(params=self.changes.to_return())
|
||||||
changes = reportable.to_return()
|
changes = reportable.to_return()
|
||||||
result.update(**changes)
|
result.update(**changes)
|
||||||
result.update(dict(changed=changed))
|
result.update(dict(changed=changed))
|
||||||
|
@ -451,7 +429,7 @@ class ModuleManager(object):
|
||||||
def _announce_deprecations(self, result):
|
def _announce_deprecations(self, result):
|
||||||
warnings = result.pop('__warnings', [])
|
warnings = result.pop('__warnings', [])
|
||||||
for warning in warnings:
|
for warning in warnings:
|
||||||
self.client.module.deprecate(
|
self.module.deprecate(
|
||||||
msg=warning['msg'],
|
msg=warning['msg'],
|
||||||
version=warning['version']
|
version=warning['version']
|
||||||
)
|
)
|
||||||
|
@ -463,7 +441,7 @@ class ModuleManager(object):
|
||||||
self.have = self.read_current_from_device()
|
self.have = self.read_current_from_device()
|
||||||
if not self.should_update():
|
if not self.should_update():
|
||||||
return False
|
return False
|
||||||
if self.client.check_mode:
|
if self.module.check_mode:
|
||||||
return True
|
return True
|
||||||
self.update_on_device()
|
self.update_on_device()
|
||||||
return True
|
return True
|
||||||
|
@ -494,7 +472,7 @@ class ModuleManager(object):
|
||||||
class ArgumentSpec(object):
|
class ArgumentSpec(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.supports_check_mode = True
|
self.supports_check_mode = True
|
||||||
self.argument_spec = dict(
|
argument_spec = dict(
|
||||||
allow=dict(
|
allow=dict(
|
||||||
type='list'
|
type='list'
|
||||||
),
|
),
|
||||||
|
@ -530,42 +508,32 @@ class ArgumentSpec(object):
|
||||||
type='bool'
|
type='bool'
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
self.f5_product_name = 'bigip'
|
self.argument_spec = {}
|
||||||
|
self.argument_spec.update(f5_argument_spec)
|
||||||
|
self.argument_spec.update(argument_spec)
|
||||||
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():
|
def main():
|
||||||
if not HAS_F5SDK:
|
|
||||||
raise F5ModuleError("The python f5-sdk module is required")
|
|
||||||
|
|
||||||
if not HAS_REQUESTS:
|
|
||||||
raise F5ModuleError("The python requests module is required")
|
|
||||||
|
|
||||||
spec = ArgumentSpec()
|
spec = ArgumentSpec()
|
||||||
|
|
||||||
client = AnsibleF5Client(
|
module = AnsibleModule(
|
||||||
argument_spec=spec.argument_spec,
|
argument_spec=spec.argument_spec,
|
||||||
supports_check_mode=spec.supports_check_mode,
|
supports_check_mode=spec.supports_check_mode
|
||||||
f5_product_name=spec.f5_product_name
|
|
||||||
)
|
)
|
||||||
|
if not HAS_F5SDK:
|
||||||
|
module.fail_json(msg="The python f5-sdk module is required")
|
||||||
|
if not HAS_REQUESTS:
|
||||||
|
module.fail_json(msg="The python requests module is required")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
mm = ModuleManager(client)
|
client = F5Client(**module.params)
|
||||||
|
mm = ModuleManager(module=module, client=client)
|
||||||
results = mm.exec_module()
|
results = mm.exec_module()
|
||||||
cleanup_tokens(client)
|
cleanup_tokens(client)
|
||||||
client.module.exit_json(**results)
|
module.exit_json(**results)
|
||||||
except F5ModuleError as e:
|
except F5ModuleError as ex:
|
||||||
cleanup_tokens(client)
|
cleanup_tokens(client)
|
||||||
client.module.fail_json(msg=str(e))
|
module.fail_json(msg=str(ex))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
|
@ -37,12 +37,7 @@ options:
|
||||||
- The timezone to set for NTP lookups. At least one of C(ntp_servers) or
|
- The timezone to set for NTP lookups. At least one of C(ntp_servers) or
|
||||||
C(timezone) is required.
|
C(timezone) is required.
|
||||||
default: UTC
|
default: UTC
|
||||||
notes:
|
|
||||||
- Requires the f5-sdk Python package on the host. This is as easy as pip
|
|
||||||
install f5-sdk.
|
|
||||||
extends_documentation_fragment: f5
|
extends_documentation_fragment: f5
|
||||||
requirements:
|
|
||||||
- f5-sdk
|
|
||||||
author:
|
author:
|
||||||
- Tim Rupp (@caphrim007)
|
- Tim Rupp (@caphrim007)
|
||||||
- Wojciech Wypior (@wojtek0806)
|
- Wojciech Wypior (@wojtek0806)
|
||||||
|
@ -82,14 +77,35 @@ timezone:
|
||||||
sample: true
|
sample: true
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
|
|
||||||
from ansible.module_utils.f5_utils import AnsibleF5Client
|
HAS_DEVEL_IMPORTS = False
|
||||||
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
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError
|
# 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:
|
except ImportError:
|
||||||
HAS_F5SDK = False
|
HAS_F5SDK = False
|
||||||
|
|
||||||
|
@ -122,23 +138,13 @@ class Parameters(AnsibleF5Parameters):
|
||||||
result = self._filter_params(result)
|
result = self._filter_params(result)
|
||||||
return result
|
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
|
|
||||||
|
|
||||||
|
|
||||||
class ModuleManager(object):
|
class ModuleManager(object):
|
||||||
def __init__(self, client):
|
def __init__(self, *args, **kwargs):
|
||||||
self.client = client
|
self.module = kwargs.get('module', None)
|
||||||
|
self.client = kwargs.get('client', None)
|
||||||
self.have = None
|
self.have = None
|
||||||
self.want = Parameters(self.client.module.params)
|
self.want = Parameters(params=self.module.params)
|
||||||
self.changes = Parameters()
|
self.changes = Parameters()
|
||||||
|
|
||||||
def _update_changed_options(self):
|
def _update_changed_options(self):
|
||||||
|
@ -150,7 +156,7 @@ class ModuleManager(object):
|
||||||
if attr1 != attr2:
|
if attr1 != attr2:
|
||||||
changed[key] = attr1
|
changed[key] = attr1
|
||||||
if changed:
|
if changed:
|
||||||
self.changes = Parameters(changed)
|
self.changes = Parameters(params=changed)
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -163,7 +169,7 @@ class ModuleManager(object):
|
||||||
if set_want != set_have:
|
if set_want != set_have:
|
||||||
changed[key] = list(set_want)
|
changed[key] = list(set_want)
|
||||||
if changed:
|
if changed:
|
||||||
self.changes = Parameters(changed)
|
self.changes = Parameters(params=changed)
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -189,7 +195,7 @@ class ModuleManager(object):
|
||||||
self.have = self.read_current_from_device()
|
self.have = self.read_current_from_device()
|
||||||
if not self.should_update():
|
if not self.should_update():
|
||||||
return False
|
return False
|
||||||
if self.client.check_mode:
|
if self.module.check_mode:
|
||||||
return True
|
return True
|
||||||
self.update_on_device()
|
self.update_on_device()
|
||||||
return True
|
return True
|
||||||
|
@ -210,7 +216,7 @@ class ModuleManager(object):
|
||||||
self.have = self.read_current_from_device()
|
self.have = self.read_current_from_device()
|
||||||
if not self.should_absent():
|
if not self.should_absent():
|
||||||
return False
|
return False
|
||||||
if self.client.check_mode:
|
if self.module.check_mode:
|
||||||
return True
|
return True
|
||||||
self.absent_on_device()
|
self.absent_on_device()
|
||||||
return True
|
return True
|
||||||
|
@ -223,7 +229,7 @@ class ModuleManager(object):
|
||||||
def read_current_from_device(self):
|
def read_current_from_device(self):
|
||||||
resource = self.client.api.tm.sys.ntp.load()
|
resource = self.client.api.tm.sys.ntp.load()
|
||||||
result = resource.attrs
|
result = resource.attrs
|
||||||
return Parameters(result)
|
return Parameters(params=result)
|
||||||
|
|
||||||
def absent_on_device(self):
|
def absent_on_device(self):
|
||||||
params = self.changes.api_params()
|
params = self.changes.api_params()
|
||||||
|
@ -234,54 +240,45 @@ class ModuleManager(object):
|
||||||
class ArgumentSpec(object):
|
class ArgumentSpec(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.supports_check_mode = True
|
self.supports_check_mode = True
|
||||||
self.argument_spec = dict(
|
argument_spec = dict(
|
||||||
ntp_servers=dict(
|
ntp_servers=dict(
|
||||||
required=False,
|
|
||||||
default=None,
|
|
||||||
type='list',
|
type='list',
|
||||||
),
|
),
|
||||||
timezone=dict(
|
timezone=dict(),
|
||||||
required=False,
|
state=dict(
|
||||||
default=None,
|
default='present',
|
||||||
)
|
choices=['present', 'absent']
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
self.argument_spec = {}
|
||||||
|
self.argument_spec.update(f5_argument_spec)
|
||||||
|
self.argument_spec.update(argument_spec)
|
||||||
|
|
||||||
self.required_one_of = [
|
self.required_one_of = [
|
||||||
['ntp_servers', 'timezone']
|
['ntp_servers', 'timezone']
|
||||||
]
|
]
|
||||||
self.f5_product_name = 'bigip'
|
|
||||||
|
|
||||||
|
|
||||||
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():
|
def main():
|
||||||
if not HAS_F5SDK:
|
|
||||||
raise F5ModuleError("The python f5-sdk module is required")
|
|
||||||
|
|
||||||
spec = ArgumentSpec()
|
spec = ArgumentSpec()
|
||||||
|
|
||||||
client = AnsibleF5Client(
|
module = AnsibleModule(
|
||||||
argument_spec=spec.argument_spec,
|
argument_spec=spec.argument_spec,
|
||||||
supports_check_mode=spec.supports_check_mode,
|
supports_check_mode=spec.supports_check_mode,
|
||||||
f5_product_name=spec.f5_product_name,
|
|
||||||
required_one_of=spec.required_one_of
|
required_one_of=spec.required_one_of
|
||||||
)
|
)
|
||||||
|
if not HAS_F5SDK:
|
||||||
|
module.fail_json(msg="The python f5-sdk module is required")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
mm = ModuleManager(client)
|
client = F5Client(**module.params)
|
||||||
|
mm = ModuleManager(module=module, client=client)
|
||||||
results = mm.exec_module()
|
results = mm.exec_module()
|
||||||
cleanup_tokens(client)
|
cleanup_tokens(client)
|
||||||
client.module.exit_json(**results)
|
module.exit_json(**results)
|
||||||
except F5ModuleError as e:
|
except F5ModuleError as ex:
|
||||||
cleanup_tokens(client)
|
cleanup_tokens(client)
|
||||||
client.module.fail_json(msg=str(e))
|
module.fail_json(msg=str(ex))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
|
@ -66,12 +66,8 @@ options:
|
||||||
description:
|
description:
|
||||||
- Port that you want the SSH daemon to run on.
|
- Port that you want the SSH daemon to run on.
|
||||||
notes:
|
notes:
|
||||||
- Requires the f5-sdk Python package on the host This is as easy as pip
|
|
||||||
install f5-sdk.
|
|
||||||
- Requires BIG-IP version 12.0.0 or greater
|
- Requires BIG-IP version 12.0.0 or greater
|
||||||
extends_documentation_fragment: f5
|
extends_documentation_fragment: f5
|
||||||
requirements:
|
|
||||||
- f5-sdk
|
|
||||||
author:
|
author:
|
||||||
- Tim Rupp (@caphrim007)
|
- Tim Rupp (@caphrim007)
|
||||||
'''
|
'''
|
||||||
|
@ -149,14 +145,35 @@ port:
|
||||||
sample: 22
|
sample: 22
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
|
|
||||||
from ansible.module_utils.f5_utils import AnsibleF5Client
|
HAS_DEVEL_IMPORTS = False
|
||||||
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
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError
|
# 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:
|
except ImportError:
|
||||||
HAS_F5SDK = False
|
HAS_F5SDK = False
|
||||||
|
|
||||||
|
@ -190,16 +207,6 @@ class Parameters(AnsibleF5Parameters):
|
||||||
result = self._filter_params(result)
|
result = self._filter_params(result)
|
||||||
return result
|
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
|
@property
|
||||||
def inactivity_timeout(self):
|
def inactivity_timeout(self):
|
||||||
if self._values['inactivity_timeout'] is None:
|
if self._values['inactivity_timeout'] is None:
|
||||||
|
@ -223,10 +230,11 @@ class Parameters(AnsibleF5Parameters):
|
||||||
|
|
||||||
|
|
||||||
class ModuleManager(object):
|
class ModuleManager(object):
|
||||||
def __init__(self, client):
|
def __init__(self, *args, **kwargs):
|
||||||
self.client = client
|
self.module = kwargs.get('module', None)
|
||||||
|
self.client = kwargs.get('client', None)
|
||||||
self.have = None
|
self.have = None
|
||||||
self.want = Parameters(self.client.module.params)
|
self.want = Parameters(params=self.module.params)
|
||||||
self.changes = Parameters()
|
self.changes = Parameters()
|
||||||
|
|
||||||
def _update_changed_options(self):
|
def _update_changed_options(self):
|
||||||
|
@ -238,7 +246,7 @@ class ModuleManager(object):
|
||||||
if attr1 != attr2:
|
if attr1 != attr2:
|
||||||
changed[key] = attr1
|
changed[key] = attr1
|
||||||
if changed:
|
if changed:
|
||||||
self.changes = Parameters(changed)
|
self.changes = Parameters(params=changed)
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -258,13 +266,13 @@ class ModuleManager(object):
|
||||||
def read_current_from_device(self):
|
def read_current_from_device(self):
|
||||||
resource = self.client.api.tm.sys.sshd.load()
|
resource = self.client.api.tm.sys.sshd.load()
|
||||||
result = resource.attrs
|
result = resource.attrs
|
||||||
return Parameters(result)
|
return Parameters(params=result)
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
self.have = self.read_current_from_device()
|
self.have = self.read_current_from_device()
|
||||||
if not self.should_update():
|
if not self.should_update():
|
||||||
return False
|
return False
|
||||||
if self.client.check_mode:
|
if self.module.check_mode:
|
||||||
return True
|
return True
|
||||||
self.update_on_device()
|
self.update_on_device()
|
||||||
return True
|
return True
|
||||||
|
@ -289,7 +297,7 @@ class ArgumentSpec(object):
|
||||||
'quiet', 'verbose'
|
'quiet', 'verbose'
|
||||||
]
|
]
|
||||||
self.supports_check_mode = True
|
self.supports_check_mode = True
|
||||||
self.argument_spec = dict(
|
argument_spec = dict(
|
||||||
allow=dict(
|
allow=dict(
|
||||||
type='list'
|
type='list'
|
||||||
),
|
),
|
||||||
|
@ -308,45 +316,32 @@ class ArgumentSpec(object):
|
||||||
),
|
),
|
||||||
port=dict(
|
port=dict(
|
||||||
type='int'
|
type='int'
|
||||||
),
|
|
||||||
state=dict(
|
|
||||||
default='present',
|
|
||||||
choices=['present']
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
self.f5_product_name = 'bigip'
|
self.argument_spec = {}
|
||||||
|
self.argument_spec.update(f5_argument_spec)
|
||||||
|
self.argument_spec.update(argument_spec)
|
||||||
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():
|
def main():
|
||||||
if not HAS_F5SDK:
|
|
||||||
raise F5ModuleError("The python f5-sdk module is required")
|
|
||||||
|
|
||||||
spec = ArgumentSpec()
|
spec = ArgumentSpec()
|
||||||
|
|
||||||
client = AnsibleF5Client(
|
module = AnsibleModule(
|
||||||
argument_spec=spec.argument_spec,
|
argument_spec=spec.argument_spec,
|
||||||
supports_check_mode=spec.supports_check_mode,
|
supports_check_mode=spec.supports_check_mode
|
||||||
f5_product_name=spec.f5_product_name
|
|
||||||
)
|
)
|
||||||
|
if not HAS_F5SDK:
|
||||||
|
module.fail_json(msg="The python f5-sdk module is required")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
mm = ModuleManager(client)
|
client = F5Client(**module.params)
|
||||||
|
mm = ModuleManager(module=module, client=client)
|
||||||
results = mm.exec_module()
|
results = mm.exec_module()
|
||||||
cleanup_tokens(client)
|
cleanup_tokens(client)
|
||||||
client.module.exit_json(**results)
|
module.exit_json(**results)
|
||||||
except F5ModuleError as e:
|
except F5ModuleError as ex:
|
||||||
cleanup_tokens(client)
|
cleanup_tokens(client)
|
||||||
client.module.fail_json(msg=str(e))
|
module.fail_json(msg=str(ex))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
|
@ -60,11 +60,15 @@ options:
|
||||||
- peer
|
- peer
|
||||||
- subordinate
|
- subordinate
|
||||||
default: peer
|
default: peer
|
||||||
notes:
|
state:
|
||||||
- Requires the f5-sdk Python package on the host. This is as easy as
|
description:
|
||||||
pip install f5-sdk.
|
- When C(present), ensures the specified devices are trusted.
|
||||||
|
- When C(absent), removes the device trusts.
|
||||||
|
default: present
|
||||||
|
choices:
|
||||||
|
- absent
|
||||||
|
- present
|
||||||
requirements:
|
requirements:
|
||||||
- f5-sdk
|
|
||||||
- netaddr
|
- netaddr
|
||||||
extends_documentation_fragment: f5
|
extends_documentation_fragment: f5
|
||||||
author:
|
author:
|
||||||
|
@ -101,22 +105,44 @@ peer_hostname:
|
||||||
|
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
|
|
||||||
|
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:
|
try:
|
||||||
import netaddr
|
import netaddr
|
||||||
HAS_NETADDR = True
|
HAS_NETADDR = True
|
||||||
except ImportError:
|
except ImportError:
|
||||||
HAS_NETADDR = False
|
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
|
|
||||||
|
|
||||||
try:
|
|
||||||
from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError
|
|
||||||
except ImportError:
|
|
||||||
HAS_F5SDK = False
|
|
||||||
|
|
||||||
|
|
||||||
class Parameters(AnsibleF5Parameters):
|
class Parameters(AnsibleF5Parameters):
|
||||||
api_map = {
|
api_map = {
|
||||||
|
@ -147,16 +173,6 @@ class Parameters(AnsibleF5Parameters):
|
||||||
except Exception:
|
except Exception:
|
||||||
return result
|
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
|
@property
|
||||||
def peer_server(self):
|
def peer_server(self):
|
||||||
if self._values['peer_server'] is None:
|
if self._values['peer_server'] is None:
|
||||||
|
@ -177,12 +193,6 @@ class Parameters(AnsibleF5Parameters):
|
||||||
result = regex.sub('_', self._values['peer_hostname'])
|
result = regex.sub('_', self._values['peer_hostname'])
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@property
|
|
||||||
def partition(self):
|
|
||||||
# Partitions are not supported when making peers.
|
|
||||||
# Everybody goes in Common.
|
|
||||||
return None
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def type(self):
|
def type(self):
|
||||||
if self._values['type'] == 'peer':
|
if self._values['type'] == 'peer':
|
||||||
|
@ -191,10 +201,11 @@ class Parameters(AnsibleF5Parameters):
|
||||||
|
|
||||||
|
|
||||||
class ModuleManager(object):
|
class ModuleManager(object):
|
||||||
def __init__(self, client):
|
def __init__(self, *args, **kwargs):
|
||||||
self.client = client
|
self.module = kwargs.get('module', None)
|
||||||
|
self.client = kwargs.get('client', None)
|
||||||
self.have = None
|
self.have = None
|
||||||
self.want = Parameters(self.client.module.params)
|
self.want = Parameters(params=self.module.params)
|
||||||
self.changes = Parameters()
|
self.changes = Parameters()
|
||||||
|
|
||||||
def _set_changed_options(self):
|
def _set_changed_options(self):
|
||||||
|
@ -203,7 +214,7 @@ class ModuleManager(object):
|
||||||
if getattr(self.want, key) is not None:
|
if getattr(self.want, key) is not None:
|
||||||
changed[key] = getattr(self.want, key)
|
changed[key] = getattr(self.want, key)
|
||||||
if changed:
|
if changed:
|
||||||
self.changes = Parameters(changed)
|
self.changes = Parameters(params=changed)
|
||||||
|
|
||||||
def exec_module(self):
|
def exec_module(self):
|
||||||
changed = False
|
changed = False
|
||||||
|
@ -237,8 +248,9 @@ class ModuleManager(object):
|
||||||
self.want.update({'peer_password': self.want.password})
|
self.want.update({'peer_password': self.want.password})
|
||||||
if self.want.peer_hostname is None:
|
if self.want.peer_hostname is None:
|
||||||
self.want.update({'peer_hostname': self.want.server})
|
self.want.update({'peer_hostname': self.want.server})
|
||||||
if self.client.check_mode:
|
if self.module.check_mode:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
self.create_on_device()
|
self.create_on_device()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@ -248,7 +260,7 @@ class ModuleManager(object):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def remove(self):
|
def remove(self):
|
||||||
if self.client.check_mode:
|
if self.module.check_mode:
|
||||||
return True
|
return True
|
||||||
self.remove_from_device()
|
self.remove_from_device()
|
||||||
if self.exists():
|
if self.exists():
|
||||||
|
@ -284,7 +296,7 @@ class ModuleManager(object):
|
||||||
class ArgumentSpec(object):
|
class ArgumentSpec(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.supports_check_mode = True
|
self.supports_check_mode = True
|
||||||
self.argument_spec = dict(
|
argument_spec = dict(
|
||||||
peer_server=dict(required=True),
|
peer_server=dict(required=True),
|
||||||
peer_hostname=dict(),
|
peer_hostname=dict(),
|
||||||
peer_user=dict(),
|
peer_user=dict(),
|
||||||
|
@ -292,44 +304,38 @@ class ArgumentSpec(object):
|
||||||
type=dict(
|
type=dict(
|
||||||
choices=['peer', 'subordinate'],
|
choices=['peer', 'subordinate'],
|
||||||
default='peer'
|
default='peer'
|
||||||
|
),
|
||||||
|
state=dict(
|
||||||
|
default='present',
|
||||||
|
choices=['present', 'absent']
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
self.f5_product_name = 'bigip'
|
self.argument_spec = {}
|
||||||
|
self.argument_spec.update(f5_argument_spec)
|
||||||
|
self.argument_spec.update(argument_spec)
|
||||||
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():
|
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()
|
spec = ArgumentSpec()
|
||||||
|
|
||||||
client = AnsibleF5Client(
|
module = AnsibleModule(
|
||||||
argument_spec=spec.argument_spec,
|
argument_spec=spec.argument_spec,
|
||||||
supports_check_mode=spec.supports_check_mode,
|
supports_check_mode=spec.supports_check_mode
|
||||||
f5_product_name=spec.f5_product_name
|
|
||||||
)
|
)
|
||||||
|
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:
|
try:
|
||||||
mm = ModuleManager(client)
|
client = F5Client(**module.params)
|
||||||
|
mm = ModuleManager(module=module, client=client)
|
||||||
results = mm.exec_module()
|
results = mm.exec_module()
|
||||||
cleanup_tokens(client)
|
cleanup_tokens(client)
|
||||||
client.module.exit_json(**results)
|
module.exit_json(**results)
|
||||||
except F5ModuleError as e:
|
except F5ModuleError as ex:
|
||||||
cleanup_tokens(client)
|
cleanup_tokens(client)
|
||||||
client.module.fail_json(msg=str(e))
|
module.fail_json(msg=str(ex))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
|
@ -41,16 +41,6 @@ lib/ansible/modules/net_tools/cloudflare_dns.py E317
|
||||||
lib/ansible/modules/net_tools/haproxy.py E317
|
lib/ansible/modules/net_tools/haproxy.py E317
|
||||||
lib/ansible/modules/net_tools/omapi_host.py E317
|
lib/ansible/modules/net_tools/omapi_host.py E317
|
||||||
lib/ansible/modules/network/cloudengine/ce_reboot.py E317
|
lib/ansible/modules/network/cloudengine/ce_reboot.py E317
|
||||||
lib/ansible/modules/network/f5/bigip_asm_policy.py E321
|
|
||||||
lib/ansible/modules/network/f5/bigip_config.py E321
|
|
||||||
lib/ansible/modules/network/f5/bigip_configsync_action.py E321
|
|
||||||
lib/ansible/modules/network/f5/bigip_configsync_actions.py E321
|
|
||||||
lib/ansible/modules/network/f5/bigip_device_connectivity.py E321
|
|
||||||
lib/ansible/modules/network/f5/bigip_device_dns.py E321
|
|
||||||
lib/ansible/modules/network/f5/bigip_device_httpd.py E321
|
|
||||||
lib/ansible/modules/network/f5/bigip_device_ntp.py E321
|
|
||||||
lib/ansible/modules/network/f5/bigip_device_sshd.py E321
|
|
||||||
lib/ansible/modules/network/f5/bigip_device_trust.py E321
|
|
||||||
lib/ansible/modules/network/f5/bigip_gtm_datacenter.py E321
|
lib/ansible/modules/network/f5/bigip_gtm_datacenter.py E321
|
||||||
lib/ansible/modules/network/f5/bigip_gtm_facts.py E321
|
lib/ansible/modules/network/f5/bigip_gtm_facts.py E321
|
||||||
lib/ansible/modules/network/f5/bigip_gtm_pool.py E321
|
lib/ansible/modules/network/f5/bigip_gtm_pool.py E321
|
||||||
|
|
|
@ -18,8 +18,7 @@ if sys.version_info < (2, 7):
|
||||||
from ansible.compat.tests import unittest
|
from ansible.compat.tests import unittest
|
||||||
from ansible.compat.tests.mock import Mock
|
from ansible.compat.tests.mock import Mock
|
||||||
from ansible.compat.tests.mock import patch
|
from ansible.compat.tests.mock import patch
|
||||||
from ansible.module_utils.f5_utils import AnsibleF5Client
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
from ansible.module_utils.f5_utils import F5ModuleError
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from library.bigip_asm_policy import V1Parameters
|
from library.bigip_asm_policy import V1Parameters
|
||||||
|
@ -28,7 +27,8 @@ try:
|
||||||
from library.bigip_asm_policy import V1Manager
|
from library.bigip_asm_policy import V1Manager
|
||||||
from library.bigip_asm_policy import V2Manager
|
from library.bigip_asm_policy import V2Manager
|
||||||
from library.bigip_asm_policy import ArgumentSpec
|
from library.bigip_asm_policy import ArgumentSpec
|
||||||
from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError
|
from library.module_utils.network.f5.common import F5ModuleError
|
||||||
|
from library.module_utils.network.f5.common import iControlUnexpectedHTTPError
|
||||||
from test.unit.modules.utils import set_module_args
|
from test.unit.modules.utils import set_module_args
|
||||||
except ImportError:
|
except ImportError:
|
||||||
try:
|
try:
|
||||||
|
@ -38,7 +38,8 @@ except ImportError:
|
||||||
from ansible.modules.network.f5.bigip_asm_policy import V1Manager
|
from ansible.modules.network.f5.bigip_asm_policy import V1Manager
|
||||||
from ansible.modules.network.f5.bigip_asm_policy import V2Manager
|
from ansible.modules.network.f5.bigip_asm_policy import V2Manager
|
||||||
from ansible.modules.network.f5.bigip_asm_policy import ArgumentSpec
|
from ansible.modules.network.f5.bigip_asm_policy import ArgumentSpec
|
||||||
from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError
|
from ansible.module_utils.network.f5.common import F5ModuleError
|
||||||
|
from ansible.module_utils.network.f5.common import iControlUnexpectedHTTPError
|
||||||
from units.modules.utils import set_module_args
|
from units.modules.utils import set_module_args
|
||||||
except ImportError:
|
except ImportError:
|
||||||
raise SkipTest("F5 Ansible modules require the f5-sdk Python library")
|
raise SkipTest("F5 Ansible modules require the f5-sdk Python library")
|
||||||
|
@ -66,7 +67,7 @@ class TestParameters(unittest.TestCase):
|
||||||
file='/var/fake/fake.xml'
|
file='/var/fake/fake.xml'
|
||||||
)
|
)
|
||||||
|
|
||||||
p = V1Parameters(args)
|
p = V1Parameters(params=args)
|
||||||
assert p.name == 'fake_policy'
|
assert p.name == 'fake_policy'
|
||||||
assert p.state == 'present'
|
assert p.state == 'present'
|
||||||
assert p.file == '/var/fake/fake.xml'
|
assert p.file == '/var/fake/fake.xml'
|
||||||
|
@ -78,14 +79,12 @@ class TestParameters(unittest.TestCase):
|
||||||
template='LotusDomino 6.5 (http)'
|
template='LotusDomino 6.5 (http)'
|
||||||
)
|
)
|
||||||
|
|
||||||
p = V1Parameters(args)
|
p = V1Parameters(params=args)
|
||||||
assert p.name == 'fake_policy'
|
assert p.name == 'fake_policy'
|
||||||
assert p.state == 'present'
|
assert p.state == 'present'
|
||||||
assert p.template == 'POLICY_TEMPLATE_LOTUSDOMINO_6_5_HTTP'
|
assert p.template == 'POLICY_TEMPLATE_LOTUSDOMINO_6_5_HTTP'
|
||||||
|
|
||||||
|
|
||||||
@patch('ansible.module_utils.f5_utils.AnsibleF5Client._get_mgmt_root',
|
|
||||||
return_value=True)
|
|
||||||
class TestManager(unittest.TestCase):
|
class TestManager(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.spec = ArgumentSpec()
|
self.spec = ArgumentSpec()
|
||||||
|
@ -102,14 +101,13 @@ class TestManager(unittest.TestCase):
|
||||||
user='admin',
|
user='admin',
|
||||||
))
|
))
|
||||||
|
|
||||||
current = V1Parameters(load_fixture('load_asm_policy_inactive.json'))
|
current = V1Parameters(params=load_fixture('load_asm_policy_inactive.json'))
|
||||||
client = AnsibleF5Client(
|
module = AnsibleModule(
|
||||||
argument_spec=self.spec.argument_spec,
|
argument_spec=self.spec.argument_spec,
|
||||||
supports_check_mode=self.spec.supports_check_mode,
|
supports_check_mode=self.spec.supports_check_mode,
|
||||||
f5_product_name=self.spec.f5_product_name
|
|
||||||
)
|
)
|
||||||
|
|
||||||
v1 = V1Manager(client)
|
v1 = V1Manager(module=module)
|
||||||
v1.exists = Mock(return_value=False)
|
v1.exists = Mock(return_value=False)
|
||||||
v1.import_to_device = Mock(return_value=True)
|
v1.import_to_device = Mock(return_value=True)
|
||||||
v1.wait_for_task = Mock(side_effect=[True, True])
|
v1.wait_for_task = Mock(side_effect=[True, True])
|
||||||
|
@ -117,7 +115,7 @@ class TestManager(unittest.TestCase):
|
||||||
v1.apply_on_device = Mock(return_value=True)
|
v1.apply_on_device = Mock(return_value=True)
|
||||||
|
|
||||||
# Override methods to force specific logic in the module to happen
|
# Override methods to force specific logic in the module to happen
|
||||||
mm = ModuleManager(client)
|
mm = ModuleManager(module=module)
|
||||||
mm.version_is_less_than_13 = Mock(return_value=False)
|
mm.version_is_less_than_13 = Mock(return_value=False)
|
||||||
mm.get_manager = Mock(return_value=v1)
|
mm.get_manager = Mock(return_value=v1)
|
||||||
|
|
||||||
|
@ -139,14 +137,13 @@ class TestManager(unittest.TestCase):
|
||||||
user='admin',
|
user='admin',
|
||||||
))
|
))
|
||||||
|
|
||||||
current = V1Parameters(load_fixture('load_asm_policy_inactive.json'))
|
current = V1Parameters(params=load_fixture('load_asm_policy_inactive.json'))
|
||||||
client = AnsibleF5Client(
|
module = AnsibleModule(
|
||||||
argument_spec=self.spec.argument_spec,
|
argument_spec=self.spec.argument_spec,
|
||||||
supports_check_mode=self.spec.supports_check_mode,
|
supports_check_mode=self.spec.supports_check_mode
|
||||||
f5_product_name=self.spec.f5_product_name
|
|
||||||
)
|
)
|
||||||
|
|
||||||
v1 = V1Manager(client)
|
v1 = V1Manager(module=module)
|
||||||
v1.exists = Mock(return_value=False)
|
v1.exists = Mock(return_value=False)
|
||||||
v1.import_to_device = Mock(return_value=True)
|
v1.import_to_device = Mock(return_value=True)
|
||||||
v1.wait_for_task = Mock(side_effect=[True, True])
|
v1.wait_for_task = Mock(side_effect=[True, True])
|
||||||
|
@ -156,7 +153,7 @@ class TestManager(unittest.TestCase):
|
||||||
v1._file_is_missing = Mock(return_value=False)
|
v1._file_is_missing = Mock(return_value=False)
|
||||||
|
|
||||||
# Override methods to force specific logic in the module to happen
|
# Override methods to force specific logic in the module to happen
|
||||||
mm = ModuleManager(client)
|
mm = ModuleManager(module=module)
|
||||||
mm.version_is_less_than_13 = Mock(return_value=False)
|
mm.version_is_less_than_13 = Mock(return_value=False)
|
||||||
mm.get_manager = Mock(return_value=v1)
|
mm.get_manager = Mock(return_value=v1)
|
||||||
|
|
||||||
|
@ -177,14 +174,13 @@ class TestManager(unittest.TestCase):
|
||||||
user='admin',
|
user='admin',
|
||||||
))
|
))
|
||||||
|
|
||||||
current = V1Parameters(load_fixture('load_asm_policy_inactive.json'))
|
current = V1Parameters(params=load_fixture('load_asm_policy_inactive.json'))
|
||||||
client = AnsibleF5Client(
|
module = AnsibleModule(
|
||||||
argument_spec=self.spec.argument_spec,
|
argument_spec=self.spec.argument_spec,
|
||||||
supports_check_mode=self.spec.supports_check_mode,
|
supports_check_mode=self.spec.supports_check_mode
|
||||||
f5_product_name=self.spec.f5_product_name
|
|
||||||
)
|
)
|
||||||
|
|
||||||
v1 = V1Manager(client)
|
v1 = V1Manager(module=module)
|
||||||
v1.exists = Mock(return_value=False)
|
v1.exists = Mock(return_value=False)
|
||||||
v1.import_to_device = Mock(return_value=True)
|
v1.import_to_device = Mock(return_value=True)
|
||||||
v1.wait_for_task = Mock(side_effect=[True, True])
|
v1.wait_for_task = Mock(side_effect=[True, True])
|
||||||
|
@ -195,7 +191,7 @@ class TestManager(unittest.TestCase):
|
||||||
v1._file_is_missing = Mock(return_value=False)
|
v1._file_is_missing = Mock(return_value=False)
|
||||||
|
|
||||||
# Override methods to force specific logic in the module to happen
|
# Override methods to force specific logic in the module to happen
|
||||||
mm = ModuleManager(client)
|
mm = ModuleManager(module=module)
|
||||||
mm.version_is_less_than_13 = Mock(return_value=False)
|
mm.version_is_less_than_13 = Mock(return_value=False)
|
||||||
mm.get_manager = Mock(return_value=v1)
|
mm.get_manager = Mock(return_value=v1)
|
||||||
|
|
||||||
|
@ -215,14 +211,13 @@ class TestManager(unittest.TestCase):
|
||||||
user='admin',
|
user='admin',
|
||||||
))
|
))
|
||||||
|
|
||||||
current = V1Parameters(load_fixture('load_asm_policy_inactive.json'))
|
current = V1Parameters(params=load_fixture('load_asm_policy_inactive.json'))
|
||||||
client = AnsibleF5Client(
|
module = AnsibleModule(
|
||||||
argument_spec=self.spec.argument_spec,
|
argument_spec=self.spec.argument_spec,
|
||||||
supports_check_mode=self.spec.supports_check_mode,
|
supports_check_mode=self.spec.supports_check_mode
|
||||||
f5_product_name=self.spec.f5_product_name
|
|
||||||
)
|
)
|
||||||
|
|
||||||
v1 = V1Manager(client)
|
v1 = V1Manager(module=module)
|
||||||
v1.exists = Mock(return_value=True)
|
v1.exists = Mock(return_value=True)
|
||||||
v1.update_on_device = Mock(return_value=True)
|
v1.update_on_device = Mock(return_value=True)
|
||||||
v1.wait_for_task = Mock(side_effect=[True, True])
|
v1.wait_for_task = Mock(side_effect=[True, True])
|
||||||
|
@ -230,7 +225,7 @@ class TestManager(unittest.TestCase):
|
||||||
v1.apply_on_device = Mock(return_value=True)
|
v1.apply_on_device = Mock(return_value=True)
|
||||||
|
|
||||||
# Override methods to force specific logic in the module to happen
|
# Override methods to force specific logic in the module to happen
|
||||||
mm = ModuleManager(client)
|
mm = ModuleManager(module=module)
|
||||||
mm.version_is_less_than_13 = Mock(return_value=False)
|
mm.version_is_less_than_13 = Mock(return_value=False)
|
||||||
mm.get_manager = Mock(return_value=v1)
|
mm.get_manager = Mock(return_value=v1)
|
||||||
|
|
||||||
|
@ -249,20 +244,19 @@ class TestManager(unittest.TestCase):
|
||||||
user='admin',
|
user='admin',
|
||||||
))
|
))
|
||||||
|
|
||||||
current = V1Parameters(load_fixture('load_asm_policy_active.json'))
|
current = V1Parameters(params=load_fixture('load_asm_policy_active.json'))
|
||||||
client = AnsibleF5Client(
|
module = AnsibleModule(
|
||||||
argument_spec=self.spec.argument_spec,
|
argument_spec=self.spec.argument_spec,
|
||||||
supports_check_mode=self.spec.supports_check_mode,
|
supports_check_mode=self.spec.supports_check_mode
|
||||||
f5_product_name=self.spec.f5_product_name
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# Override methods to force specific logic in the module to happen
|
# Override methods to force specific logic in the module to happen
|
||||||
v1 = V1Manager(client)
|
v1 = V1Manager(module=module)
|
||||||
v1.exists = Mock(return_value=True)
|
v1.exists = Mock(return_value=True)
|
||||||
v1.read_current_from_device = Mock(return_value=current)
|
v1.read_current_from_device = Mock(return_value=current)
|
||||||
|
|
||||||
# Override methods to force specific logic in the module to happen
|
# Override methods to force specific logic in the module to happen
|
||||||
mm = ModuleManager(client)
|
mm = ModuleManager(module=module)
|
||||||
mm.version_is_less_than_13 = Mock(return_value=False)
|
mm.version_is_less_than_13 = Mock(return_value=False)
|
||||||
mm.get_manager = Mock(return_value=v1)
|
mm.get_manager = Mock(return_value=v1)
|
||||||
|
|
||||||
|
@ -280,21 +274,20 @@ class TestManager(unittest.TestCase):
|
||||||
active='no'
|
active='no'
|
||||||
))
|
))
|
||||||
|
|
||||||
current = V1Parameters(load_fixture('load_asm_policy_active.json'))
|
current = V1Parameters(params=load_fixture('load_asm_policy_active.json'))
|
||||||
client = AnsibleF5Client(
|
module = AnsibleModule(
|
||||||
argument_spec=self.spec.argument_spec,
|
argument_spec=self.spec.argument_spec,
|
||||||
supports_check_mode=self.spec.supports_check_mode,
|
supports_check_mode=self.spec.supports_check_mode
|
||||||
f5_product_name=self.spec.f5_product_name
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# Override methods to force specific logic in the module to happen
|
# Override methods to force specific logic in the module to happen
|
||||||
v1 = V1Manager(client)
|
v1 = V1Manager(module=module)
|
||||||
v1.exists = Mock(return_value=True)
|
v1.exists = Mock(return_value=True)
|
||||||
v1.read_current_from_device = Mock(return_value=current)
|
v1.read_current_from_device = Mock(return_value=current)
|
||||||
v1.update_on_device = Mock(return_value=True)
|
v1.update_on_device = Mock(return_value=True)
|
||||||
|
|
||||||
# Override methods to force specific logic in the module to happen
|
# Override methods to force specific logic in the module to happen
|
||||||
mm = ModuleManager(client)
|
mm = ModuleManager(module=module)
|
||||||
mm.version_is_less_than_13 = Mock(return_value=False)
|
mm.version_is_less_than_13 = Mock(return_value=False)
|
||||||
mm.get_manager = Mock(return_value=v1)
|
mm.get_manager = Mock(return_value=v1)
|
||||||
|
|
||||||
|
@ -313,20 +306,19 @@ class TestManager(unittest.TestCase):
|
||||||
active='no'
|
active='no'
|
||||||
))
|
))
|
||||||
|
|
||||||
current = V1Parameters(load_fixture('load_asm_policy_inactive.json'))
|
current = V1Parameters(params=load_fixture('load_asm_policy_inactive.json'))
|
||||||
client = AnsibleF5Client(
|
module = AnsibleModule(
|
||||||
argument_spec=self.spec.argument_spec,
|
argument_spec=self.spec.argument_spec,
|
||||||
supports_check_mode=self.spec.supports_check_mode,
|
supports_check_mode=self.spec.supports_check_mode
|
||||||
f5_product_name=self.spec.f5_product_name
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# Override methods to force specific logic in the module to happen
|
# Override methods to force specific logic in the module to happen
|
||||||
v1 = V1Manager(client)
|
v1 = V1Manager(module=module)
|
||||||
v1.exists = Mock(return_value=True)
|
v1.exists = Mock(return_value=True)
|
||||||
v1.read_current_from_device = Mock(return_value=current)
|
v1.read_current_from_device = Mock(return_value=current)
|
||||||
|
|
||||||
# Override methods to force specific logic in the module to happen
|
# Override methods to force specific logic in the module to happen
|
||||||
mm = ModuleManager(client)
|
mm = ModuleManager(module=module)
|
||||||
mm.version_is_less_than_13 = Mock(return_value=False)
|
mm.version_is_less_than_13 = Mock(return_value=False)
|
||||||
mm.get_manager = Mock(return_value=v1)
|
mm.get_manager = Mock(return_value=v1)
|
||||||
|
|
||||||
|
@ -344,22 +336,21 @@ class TestManager(unittest.TestCase):
|
||||||
user='admin',
|
user='admin',
|
||||||
))
|
))
|
||||||
|
|
||||||
current = V1Parameters(load_fixture('load_asm_policy_inactive.json'))
|
current = V1Parameters(params=load_fixture('load_asm_policy_inactive.json'))
|
||||||
client = AnsibleF5Client(
|
module = AnsibleModule(
|
||||||
argument_spec=self.spec.argument_spec,
|
argument_spec=self.spec.argument_spec,
|
||||||
supports_check_mode=self.spec.supports_check_mode,
|
supports_check_mode=self.spec.supports_check_mode
|
||||||
f5_product_name=self.spec.f5_product_name
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# Override methods to force specific logic in the module to happen
|
# Override methods to force specific logic in the module to happen
|
||||||
v1 = V1Manager(client)
|
v1 = V1Manager(module=module)
|
||||||
v1.exists = Mock(return_value=False)
|
v1.exists = Mock(return_value=False)
|
||||||
v1.import_to_device = Mock(return_value=True)
|
v1.import_to_device = Mock(return_value=True)
|
||||||
v1.wait_for_task = Mock(side_effect=[True, True])
|
v1.wait_for_task = Mock(side_effect=[True, True])
|
||||||
v1.read_current_from_device = Mock(return_value=current)
|
v1.read_current_from_device = Mock(return_value=current)
|
||||||
|
|
||||||
# Override methods to force specific logic in the module to happen
|
# Override methods to force specific logic in the module to happen
|
||||||
mm = ModuleManager(client)
|
mm = ModuleManager(module=module)
|
||||||
mm.version_is_less_than_13 = Mock(return_value=False)
|
mm.version_is_less_than_13 = Mock(return_value=False)
|
||||||
mm.get_manager = Mock(return_value=v1)
|
mm.get_manager = Mock(return_value=v1)
|
||||||
|
|
||||||
|
@ -380,15 +371,14 @@ class TestManager(unittest.TestCase):
|
||||||
user='admin',
|
user='admin',
|
||||||
))
|
))
|
||||||
|
|
||||||
current = V1Parameters(load_fixture('load_asm_policy_inactive.json'))
|
current = V1Parameters(params=load_fixture('load_asm_policy_inactive.json'))
|
||||||
client = AnsibleF5Client(
|
module = AnsibleModule(
|
||||||
argument_spec=self.spec.argument_spec,
|
argument_spec=self.spec.argument_spec,
|
||||||
supports_check_mode=self.spec.supports_check_mode,
|
supports_check_mode=self.spec.supports_check_mode
|
||||||
f5_product_name=self.spec.f5_product_name
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# Override methods to force specific logic in the module to happen
|
# Override methods to force specific logic in the module to happen
|
||||||
v1 = V1Manager(client)
|
v1 = V1Manager(module=module)
|
||||||
v1.exists = Mock(return_value=False)
|
v1.exists = Mock(return_value=False)
|
||||||
v1.create_from_template_on_device = Mock(return_value=True)
|
v1.create_from_template_on_device = Mock(return_value=True)
|
||||||
v1.wait_for_task = Mock(side_effect=[True, True])
|
v1.wait_for_task = Mock(side_effect=[True, True])
|
||||||
|
@ -396,7 +386,7 @@ class TestManager(unittest.TestCase):
|
||||||
v1._file_is_missing = Mock(return_value=False)
|
v1._file_is_missing = Mock(return_value=False)
|
||||||
|
|
||||||
# Override methods to force specific logic in the module to happen
|
# Override methods to force specific logic in the module to happen
|
||||||
mm = ModuleManager(client)
|
mm = ModuleManager(module=module)
|
||||||
mm.version_is_less_than_13 = Mock(return_value=False)
|
mm.version_is_less_than_13 = Mock(return_value=False)
|
||||||
mm.get_manager = Mock(return_value=v1)
|
mm.get_manager = Mock(return_value=v1)
|
||||||
|
|
||||||
|
@ -416,14 +406,13 @@ class TestManager(unittest.TestCase):
|
||||||
user='admin',
|
user='admin',
|
||||||
))
|
))
|
||||||
|
|
||||||
current = V1Parameters(load_fixture('load_asm_policy_inactive.json'))
|
current = V1Parameters(params=load_fixture('load_asm_policy_inactive.json'))
|
||||||
client = AnsibleF5Client(
|
module = AnsibleModule(
|
||||||
argument_spec=self.spec.argument_spec,
|
argument_spec=self.spec.argument_spec,
|
||||||
supports_check_mode=self.spec.supports_check_mode,
|
supports_check_mode=self.spec.supports_check_mode
|
||||||
f5_product_name=self.spec.f5_product_name
|
|
||||||
)
|
)
|
||||||
|
|
||||||
v1 = V1Manager(client)
|
v1 = V1Manager(module=module)
|
||||||
v1.exists = Mock(return_value=False)
|
v1.exists = Mock(return_value=False)
|
||||||
v1.import_to_device = Mock(return_value=True)
|
v1.import_to_device = Mock(return_value=True)
|
||||||
v1.wait_for_task = Mock(side_effect=[True, True])
|
v1.wait_for_task = Mock(side_effect=[True, True])
|
||||||
|
@ -434,7 +423,7 @@ class TestManager(unittest.TestCase):
|
||||||
v1._file_is_missing = Mock(return_value=False)
|
v1._file_is_missing = Mock(return_value=False)
|
||||||
|
|
||||||
# Override methods to force specific logic in the module to happen
|
# Override methods to force specific logic in the module to happen
|
||||||
mm = ModuleManager(client)
|
mm = ModuleManager(module=module)
|
||||||
mm.version_is_less_than_13 = Mock(return_value=False)
|
mm.version_is_less_than_13 = Mock(return_value=False)
|
||||||
mm.get_manager = Mock(return_value=v1)
|
mm.get_manager = Mock(return_value=v1)
|
||||||
|
|
||||||
|
@ -453,19 +442,18 @@ class TestManager(unittest.TestCase):
|
||||||
user='admin',
|
user='admin',
|
||||||
))
|
))
|
||||||
|
|
||||||
client = AnsibleF5Client(
|
module = AnsibleModule(
|
||||||
argument_spec=self.spec.argument_spec,
|
argument_spec=self.spec.argument_spec,
|
||||||
supports_check_mode=self.spec.supports_check_mode,
|
supports_check_mode=self.spec.supports_check_mode
|
||||||
f5_product_name=self.spec.f5_product_name
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# Override methods to force specific logic in the module to happen
|
# Override methods to force specific logic in the module to happen
|
||||||
v1 = V1Manager(client)
|
v1 = V1Manager(module=module)
|
||||||
v1.exists = Mock(side_effect=[True, False])
|
v1.exists = Mock(side_effect=[True, False])
|
||||||
v1.remove_from_device = Mock(return_value=True)
|
v1.remove_from_device = Mock(return_value=True)
|
||||||
|
|
||||||
# Override methods to force specific logic in the module to happen
|
# Override methods to force specific logic in the module to happen
|
||||||
mm = ModuleManager(client)
|
mm = ModuleManager(module=module)
|
||||||
mm.version_is_less_than_13 = Mock(return_value=False)
|
mm.version_is_less_than_13 = Mock(return_value=False)
|
||||||
mm.get_manager = Mock(return_value=v1)
|
mm.get_manager = Mock(return_value=v1)
|
||||||
|
|
||||||
|
@ -483,21 +471,20 @@ class TestManager(unittest.TestCase):
|
||||||
user='admin',
|
user='admin',
|
||||||
))
|
))
|
||||||
|
|
||||||
client = AnsibleF5Client(
|
module = AnsibleModule(
|
||||||
argument_spec=self.spec.argument_spec,
|
argument_spec=self.spec.argument_spec,
|
||||||
supports_check_mode=self.spec.supports_check_mode,
|
supports_check_mode=self.spec.supports_check_mode
|
||||||
f5_product_name=self.spec.f5_product_name
|
|
||||||
)
|
)
|
||||||
|
|
||||||
msg = 'Import policy task failed.'
|
msg = 'Import policy task failed.'
|
||||||
# Override methods to force specific logic in the module to happen
|
# Override methods to force specific logic in the module to happen
|
||||||
v1 = V1Manager(client)
|
v1 = V1Manager(module=module)
|
||||||
v1.exists = Mock(return_value=False)
|
v1.exists = Mock(return_value=False)
|
||||||
v1.import_to_device = Mock(return_value=True)
|
v1.import_to_device = Mock(return_value=True)
|
||||||
v1.wait_for_task = Mock(return_value=False)
|
v1.wait_for_task = Mock(return_value=False)
|
||||||
|
|
||||||
# Override methods to force specific logic in the module to happen
|
# Override methods to force specific logic in the module to happen
|
||||||
mm = ModuleManager(client)
|
mm = ModuleManager(module=module)
|
||||||
mm.version_is_less_than_13 = Mock(return_value=False)
|
mm.version_is_less_than_13 = Mock(return_value=False)
|
||||||
mm.get_manager = Mock(return_value=v1)
|
mm.get_manager = Mock(return_value=v1)
|
||||||
|
|
||||||
|
@ -515,16 +502,15 @@ class TestManager(unittest.TestCase):
|
||||||
user='admin',
|
user='admin',
|
||||||
))
|
))
|
||||||
|
|
||||||
current = V1Parameters(load_fixture('load_asm_policy_inactive.json'))
|
current = V1Parameters(params=load_fixture('load_asm_policy_inactive.json'))
|
||||||
client = AnsibleF5Client(
|
module = AnsibleModule(
|
||||||
argument_spec=self.spec.argument_spec,
|
argument_spec=self.spec.argument_spec,
|
||||||
supports_check_mode=self.spec.supports_check_mode,
|
supports_check_mode=self.spec.supports_check_mode
|
||||||
f5_product_name=self.spec.f5_product_name
|
|
||||||
)
|
)
|
||||||
|
|
||||||
msg = 'Apply policy task failed.'
|
msg = 'Apply policy task failed.'
|
||||||
# Override methods to force specific logic in the module to happen
|
# Override methods to force specific logic in the module to happen
|
||||||
v1 = V1Manager(client)
|
v1 = V1Manager(module=module)
|
||||||
v1.exists = Mock(return_value=True)
|
v1.exists = Mock(return_value=True)
|
||||||
v1.wait_for_task = Mock(return_value=False)
|
v1.wait_for_task = Mock(return_value=False)
|
||||||
v1.update_on_device = Mock(return_value=True)
|
v1.update_on_device = Mock(return_value=True)
|
||||||
|
@ -532,7 +518,7 @@ class TestManager(unittest.TestCase):
|
||||||
v1.apply_on_device = Mock(return_value=True)
|
v1.apply_on_device = Mock(return_value=True)
|
||||||
|
|
||||||
# Override methods to force specific logic in the module to happen
|
# Override methods to force specific logic in the module to happen
|
||||||
mm = ModuleManager(client)
|
mm = ModuleManager(module=module)
|
||||||
mm.version_is_less_than_13 = Mock(return_value=False)
|
mm.version_is_less_than_13 = Mock(return_value=False)
|
||||||
mm.get_manager = Mock(return_value=v1)
|
mm.get_manager = Mock(return_value=v1)
|
||||||
|
|
||||||
|
@ -549,21 +535,20 @@ class TestManager(unittest.TestCase):
|
||||||
user='admin',
|
user='admin',
|
||||||
))
|
))
|
||||||
|
|
||||||
client = AnsibleF5Client(
|
module = AnsibleModule(
|
||||||
argument_spec=self.spec.argument_spec,
|
argument_spec=self.spec.argument_spec,
|
||||||
supports_check_mode=self.spec.supports_check_mode,
|
supports_check_mode=self.spec.supports_check_mode
|
||||||
f5_product_name=self.spec.f5_product_name
|
|
||||||
)
|
)
|
||||||
|
|
||||||
msg = 'Failed to create ASM policy: fake_policy'
|
msg = 'Failed to create ASM policy: fake_policy'
|
||||||
# Override methods to force specific logic in the module to happen
|
# Override methods to force specific logic in the module to happen
|
||||||
v1 = V1Manager(client)
|
v1 = V1Manager(module=module)
|
||||||
v1.exists = Mock(return_value=False)
|
v1.exists = Mock(return_value=False)
|
||||||
v1.create_on_device = Mock(return_value=False)
|
v1.create_on_device = Mock(return_value=False)
|
||||||
v1._file_is_missing = Mock(return_value=False)
|
v1._file_is_missing = Mock(return_value=False)
|
||||||
|
|
||||||
# Override methods to force specific logic in the module to happen
|
# Override methods to force specific logic in the module to happen
|
||||||
mm = ModuleManager(client)
|
mm = ModuleManager(module=module)
|
||||||
mm.version_is_less_than_13 = Mock(return_value=False)
|
mm.version_is_less_than_13 = Mock(return_value=False)
|
||||||
mm.get_manager = Mock(return_value=v1)
|
mm.get_manager = Mock(return_value=v1)
|
||||||
|
|
||||||
|
@ -580,19 +565,18 @@ class TestManager(unittest.TestCase):
|
||||||
user='admin',
|
user='admin',
|
||||||
))
|
))
|
||||||
|
|
||||||
client = AnsibleF5Client(
|
module = AnsibleModule(
|
||||||
argument_spec=self.spec.argument_spec,
|
argument_spec=self.spec.argument_spec,
|
||||||
supports_check_mode=self.spec.supports_check_mode,
|
supports_check_mode=self.spec.supports_check_mode
|
||||||
f5_product_name=self.spec.f5_product_name
|
|
||||||
)
|
)
|
||||||
msg = 'Failed to delete ASM policy: fake_policy'
|
msg = 'Failed to delete ASM policy: fake_policy'
|
||||||
# Override methods to force specific logic in the module to happen
|
# Override methods to force specific logic in the module to happen
|
||||||
v1 = V1Manager(client)
|
v1 = V1Manager(module=module)
|
||||||
v1.exists = Mock(side_effect=[True, True])
|
v1.exists = Mock(side_effect=[True, True])
|
||||||
v1.remove_from_device = Mock(return_value=True)
|
v1.remove_from_device = Mock(return_value=True)
|
||||||
|
|
||||||
# Override methods to force specific logic in the module to happen
|
# Override methods to force specific logic in the module to happen
|
||||||
mm = ModuleManager(client)
|
mm = ModuleManager(module=module)
|
||||||
mm.version_is_less_than_13 = Mock(return_value=False)
|
mm.version_is_less_than_13 = Mock(return_value=False)
|
||||||
mm.get_manager = Mock(return_value=v1)
|
mm.get_manager = Mock(return_value=v1)
|
||||||
|
|
||||||
|
|
|
@ -17,20 +17,22 @@ if sys.version_info < (2, 7):
|
||||||
from ansible.compat.tests import unittest
|
from ansible.compat.tests import unittest
|
||||||
from ansible.compat.tests.mock import patch
|
from ansible.compat.tests.mock import patch
|
||||||
from ansible.compat.tests.mock import Mock
|
from ansible.compat.tests.mock import Mock
|
||||||
from ansible.module_utils.f5_utils import AnsibleF5Client
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from library.bigip_command import Parameters
|
from library.bigip_command import Parameters
|
||||||
from library.bigip_command import ModuleManager
|
from library.bigip_command import ModuleManager
|
||||||
from library.bigip_command import ArgumentSpec
|
from library.bigip_command import ArgumentSpec
|
||||||
from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError
|
from library.module_utils.network.f5.common import F5ModuleError
|
||||||
|
from library.module_utils.network.f5.common import iControlUnexpectedHTTPError
|
||||||
from test.unit.modules.utils import set_module_args
|
from test.unit.modules.utils import set_module_args
|
||||||
except ImportError:
|
except ImportError:
|
||||||
try:
|
try:
|
||||||
from ansible.modules.network.f5.bigip_command import Parameters
|
from ansible.modules.network.f5.bigip_command import Parameters
|
||||||
from ansible.modules.network.f5.bigip_command import ModuleManager
|
from ansible.modules.network.f5.bigip_command import ModuleManager
|
||||||
from ansible.modules.network.f5.bigip_command import ArgumentSpec
|
from ansible.modules.network.f5.bigip_command import ArgumentSpec
|
||||||
from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError
|
from ansible.module_utils.network.f5.common import F5ModuleError
|
||||||
|
from ansible.module_utils.network.f5.common import iControlUnexpectedHTTPError
|
||||||
from units.modules.utils import set_module_args
|
from units.modules.utils import set_module_args
|
||||||
except ImportError:
|
except ImportError:
|
||||||
raise SkipTest("F5 Ansible modules require the f5-sdk Python library")
|
raise SkipTest("F5 Ansible modules require the f5-sdk Python library")
|
||||||
|
@ -61,12 +63,10 @@ class TestParameters(unittest.TestCase):
|
||||||
user='admin',
|
user='admin',
|
||||||
password='password'
|
password='password'
|
||||||
)
|
)
|
||||||
p = Parameters(args)
|
p = Parameters(params=args)
|
||||||
assert len(p.commands) == 2
|
assert len(p.commands) == 2
|
||||||
|
|
||||||
|
|
||||||
@patch('ansible.module_utils.f5_utils.AnsibleF5Client._get_mgmt_root',
|
|
||||||
return_value=True)
|
|
||||||
class TestManager(unittest.TestCase):
|
class TestManager(unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
@ -82,12 +82,12 @@ class TestManager(unittest.TestCase):
|
||||||
password='password'
|
password='password'
|
||||||
))
|
))
|
||||||
|
|
||||||
client = AnsibleF5Client(
|
module = AnsibleModule(
|
||||||
argument_spec=self.spec.argument_spec,
|
argument_spec=self.spec.argument_spec,
|
||||||
supports_check_mode=self.spec.supports_check_mode,
|
supports_check_mode=self.spec.supports_check_mode
|
||||||
f5_product_name=self.spec.f5_product_name
|
|
||||||
)
|
)
|
||||||
mm = ModuleManager(client)
|
|
||||||
|
mm = ModuleManager(module=module)
|
||||||
mm._run_commands = Mock(return_value=[])
|
mm._run_commands = Mock(return_value=[])
|
||||||
mm.execute_on_device = Mock(return_value=[])
|
mm.execute_on_device = Mock(return_value=[])
|
||||||
|
|
||||||
|
@ -107,12 +107,11 @@ class TestManager(unittest.TestCase):
|
||||||
password='password'
|
password='password'
|
||||||
))
|
))
|
||||||
|
|
||||||
client = AnsibleF5Client(
|
module = AnsibleModule(
|
||||||
argument_spec=self.spec.argument_spec,
|
argument_spec=self.spec.argument_spec,
|
||||||
supports_check_mode=self.spec.supports_check_mode,
|
supports_check_mode=self.spec.supports_check_mode
|
||||||
f5_product_name=self.spec.f5_product_name
|
|
||||||
)
|
)
|
||||||
mm = ModuleManager(client)
|
mm = ModuleManager(module=module)
|
||||||
mm._run_commands = Mock(return_value=[])
|
mm._run_commands = Mock(return_value=[])
|
||||||
mm.execute_on_device = Mock(return_value=[])
|
mm.execute_on_device = Mock(return_value=[])
|
||||||
|
|
||||||
|
@ -132,12 +131,12 @@ class TestManager(unittest.TestCase):
|
||||||
password='password',
|
password='password',
|
||||||
transport='cli'
|
transport='cli'
|
||||||
))
|
))
|
||||||
client = AnsibleF5Client(
|
|
||||||
|
module = AnsibleModule(
|
||||||
argument_spec=self.spec.argument_spec,
|
argument_spec=self.spec.argument_spec,
|
||||||
supports_check_mode=self.spec.supports_check_mode,
|
supports_check_mode=self.spec.supports_check_mode
|
||||||
f5_product_name=self.spec.f5_product_name
|
|
||||||
)
|
)
|
||||||
mm = ModuleManager(client)
|
mm = ModuleManager(module=module)
|
||||||
mm._run_commands = Mock(return_value=[])
|
mm._run_commands = Mock(return_value=[])
|
||||||
mm.execute_on_device = Mock(return_value=[])
|
mm.execute_on_device = Mock(return_value=[])
|
||||||
|
|
||||||
|
@ -159,12 +158,11 @@ class TestManager(unittest.TestCase):
|
||||||
user='admin',
|
user='admin',
|
||||||
password='password'
|
password='password'
|
||||||
))
|
))
|
||||||
client = AnsibleF5Client(
|
module = AnsibleModule(
|
||||||
argument_spec=self.spec.argument_spec,
|
argument_spec=self.spec.argument_spec,
|
||||||
supports_check_mode=self.spec.supports_check_mode,
|
supports_check_mode=self.spec.supports_check_mode
|
||||||
f5_product_name=self.spec.f5_product_name
|
|
||||||
)
|
)
|
||||||
mm = ModuleManager(client)
|
mm = ModuleManager(module=module)
|
||||||
mm._run_commands = Mock(return_value=[])
|
mm._run_commands = Mock(return_value=[])
|
||||||
mm.execute_on_device = Mock(return_value=[])
|
mm.execute_on_device = Mock(return_value=[])
|
||||||
|
|
||||||
|
|
|
@ -17,20 +17,22 @@ if sys.version_info < (2, 7):
|
||||||
from ansible.compat.tests import unittest
|
from ansible.compat.tests import unittest
|
||||||
from ansible.compat.tests.mock import Mock
|
from ansible.compat.tests.mock import Mock
|
||||||
from ansible.compat.tests.mock import patch
|
from ansible.compat.tests.mock import patch
|
||||||
from ansible.module_utils.f5_utils import AnsibleF5Client
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from library.bigip_config import Parameters
|
from library.bigip_config import Parameters
|
||||||
from library.bigip_config import ModuleManager
|
from library.bigip_config import ModuleManager
|
||||||
from library.bigip_config import ArgumentSpec
|
from library.bigip_config import ArgumentSpec
|
||||||
from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError
|
from library.module_utils.network.f5.common import F5ModuleError
|
||||||
|
from library.module_utils.network.f5.common import iControlUnexpectedHTTPError
|
||||||
from test.unit.modules.utils import set_module_args
|
from test.unit.modules.utils import set_module_args
|
||||||
except ImportError:
|
except ImportError:
|
||||||
try:
|
try:
|
||||||
from ansible.modules.network.f5.bigip_config import Parameters
|
from ansible.modules.network.f5.bigip_config import Parameters
|
||||||
from ansible.modules.network.f5.bigip_config import ModuleManager
|
from ansible.modules.network.f5.bigip_config import ModuleManager
|
||||||
from ansible.modules.network.f5.bigip_config import ArgumentSpec
|
from ansible.modules.network.f5.bigip_config import ArgumentSpec
|
||||||
from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError
|
from ansible.module_utils.network.f5.common import F5ModuleError
|
||||||
|
from ansible.module_utils.network.f5.common import iControlUnexpectedHTTPError
|
||||||
from units.modules.utils import set_module_args
|
from units.modules.utils import set_module_args
|
||||||
except ImportError:
|
except ImportError:
|
||||||
raise SkipTest("F5 Ansible modules require the f5-sdk Python library")
|
raise SkipTest("F5 Ansible modules require the f5-sdk Python library")
|
||||||
|
@ -68,14 +70,12 @@ class TestParameters(unittest.TestCase):
|
||||||
user='admin',
|
user='admin',
|
||||||
password='password'
|
password='password'
|
||||||
)
|
)
|
||||||
p = Parameters(args)
|
p = Parameters(params=args)
|
||||||
assert p.save == 'yes'
|
assert p.save == 'yes'
|
||||||
assert p.reset == 'yes'
|
assert p.reset == 'yes'
|
||||||
assert p.merge_content == 'asdasd'
|
assert p.merge_content == 'asdasd'
|
||||||
|
|
||||||
|
|
||||||
@patch('ansible.module_utils.f5_utils.AnsibleF5Client._get_mgmt_root',
|
|
||||||
return_value=True)
|
|
||||||
class TestManager(unittest.TestCase):
|
class TestManager(unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
@ -92,12 +92,11 @@ class TestManager(unittest.TestCase):
|
||||||
password='password'
|
password='password'
|
||||||
))
|
))
|
||||||
|
|
||||||
client = AnsibleF5Client(
|
module = AnsibleModule(
|
||||||
argument_spec=self.spec.argument_spec,
|
argument_spec=self.spec.argument_spec,
|
||||||
supports_check_mode=self.spec.supports_check_mode,
|
supports_check_mode=self.spec.supports_check_mode
|
||||||
f5_product_name=self.spec.f5_product_name
|
|
||||||
)
|
)
|
||||||
mm = ModuleManager(client)
|
mm = ModuleManager(module=module)
|
||||||
|
|
||||||
# Override methods to force specific logic in the module to happen
|
# Override methods to force specific logic in the module to happen
|
||||||
mm.exit_json = Mock(return_value=True)
|
mm.exit_json = Mock(return_value=True)
|
||||||
|
|
|
@ -17,20 +17,22 @@ if sys.version_info < (2, 7):
|
||||||
from ansible.compat.tests import unittest
|
from ansible.compat.tests import unittest
|
||||||
from ansible.compat.tests.mock import Mock
|
from ansible.compat.tests.mock import Mock
|
||||||
from ansible.compat.tests.mock import patch
|
from ansible.compat.tests.mock import patch
|
||||||
from ansible.module_utils.f5_utils import AnsibleF5Client
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from library.bigip_configsync_actions import Parameters
|
from library.bigip_configsync_actions import Parameters
|
||||||
from library.bigip_configsync_actions import ModuleManager
|
from library.bigip_configsync_actions import ModuleManager
|
||||||
from library.bigip_configsync_actions import ArgumentSpec
|
from library.bigip_configsync_actions import ArgumentSpec
|
||||||
from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError
|
from library.module_utils.network.f5.common import F5ModuleError
|
||||||
|
from library.module_utils.network.f5.common import iControlUnexpectedHTTPError
|
||||||
from test.unit.modules.utils import set_module_args
|
from test.unit.modules.utils import set_module_args
|
||||||
except ImportError:
|
except ImportError:
|
||||||
try:
|
try:
|
||||||
from ansible.modules.network.f5.bigip_configsync_actions import Parameters
|
from ansible.modules.network.f5.bigip_configsync_actions import Parameters
|
||||||
from ansible.modules.network.f5.bigip_configsync_actions import ModuleManager
|
from ansible.modules.network.f5.bigip_configsync_actions import ModuleManager
|
||||||
from ansible.modules.network.f5.bigip_configsync_actions import ArgumentSpec
|
from ansible.modules.network.f5.bigip_configsync_actions import ArgumentSpec
|
||||||
from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError
|
from ansible.module_utils.network.f5.common import F5ModuleError
|
||||||
|
from ansible.module_utils.network.f5.common import iControlUnexpectedHTTPError
|
||||||
from units.modules.utils import set_module_args
|
from units.modules.utils import set_module_args
|
||||||
except ImportError:
|
except ImportError:
|
||||||
raise SkipTest("F5 Ansible modules require the f5-sdk Python library")
|
raise SkipTest("F5 Ansible modules require the f5-sdk Python library")
|
||||||
|
@ -65,7 +67,7 @@ class TestParameters(unittest.TestCase):
|
||||||
overwrite_config=True,
|
overwrite_config=True,
|
||||||
device_group="foo"
|
device_group="foo"
|
||||||
)
|
)
|
||||||
p = Parameters(args)
|
p = Parameters(params=args)
|
||||||
assert p.sync_device_to_group is True
|
assert p.sync_device_to_group is True
|
||||||
assert p.sync_group_to_device is True
|
assert p.sync_group_to_device is True
|
||||||
assert p.overwrite_config is True
|
assert p.overwrite_config is True
|
||||||
|
@ -78,15 +80,13 @@ class TestParameters(unittest.TestCase):
|
||||||
overwrite_config='yes',
|
overwrite_config='yes',
|
||||||
device_group="foo"
|
device_group="foo"
|
||||||
)
|
)
|
||||||
p = Parameters(args)
|
p = Parameters(params=args)
|
||||||
assert p.sync_device_to_group is True
|
assert p.sync_device_to_group is True
|
||||||
assert p.sync_group_to_device is False
|
assert p.sync_group_to_device is False
|
||||||
assert p.overwrite_config is True
|
assert p.overwrite_config is True
|
||||||
assert p.device_group == 'foo'
|
assert p.device_group == 'foo'
|
||||||
|
|
||||||
|
|
||||||
@patch('ansible.module_utils.f5_utils.AnsibleF5Client._get_mgmt_root',
|
|
||||||
return_value=True)
|
|
||||||
class TestManager(unittest.TestCase):
|
class TestManager(unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
@ -101,12 +101,11 @@ class TestManager(unittest.TestCase):
|
||||||
user='admin'
|
user='admin'
|
||||||
))
|
))
|
||||||
|
|
||||||
client = AnsibleF5Client(
|
module = AnsibleModule(
|
||||||
argument_spec=self.spec.argument_spec,
|
argument_spec=self.spec.argument_spec,
|
||||||
supports_check_mode=self.spec.supports_check_mode,
|
supports_check_mode=self.spec.supports_check_mode
|
||||||
f5_product_name=self.spec.f5_product_name
|
|
||||||
)
|
)
|
||||||
mm = ModuleManager(client)
|
mm = ModuleManager(module=module)
|
||||||
|
|
||||||
# Override methods to force specific logic in the module to happen
|
# Override methods to force specific logic in the module to happen
|
||||||
mm._device_group_exists = Mock(return_value=True)
|
mm._device_group_exists = Mock(return_value=True)
|
||||||
|
|
|
@ -18,21 +18,24 @@ if sys.version_info < (2, 7):
|
||||||
from ansible.compat.tests import unittest
|
from ansible.compat.tests import unittest
|
||||||
from ansible.compat.tests.mock import Mock
|
from ansible.compat.tests.mock import Mock
|
||||||
from ansible.compat.tests.mock import patch
|
from ansible.compat.tests.mock import patch
|
||||||
from ansible.module_utils.f5_utils import AnsibleF5Client
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
from ansible.module_utils.f5_utils import F5ModuleError
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from library.bigip_device_connectivity import Parameters
|
from library.bigip_device_connectivity import ApiParameters
|
||||||
|
from library.bigip_device_connectivity import ModuleParameters
|
||||||
from library.bigip_device_connectivity import ModuleManager
|
from library.bigip_device_connectivity import ModuleManager
|
||||||
from library.bigip_device_connectivity import ArgumentSpec
|
from library.bigip_device_connectivity import ArgumentSpec
|
||||||
from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError
|
from library.module_utils.network.f5.common import F5ModuleError
|
||||||
|
from library.module_utils.network.f5.common import iControlUnexpectedHTTPError
|
||||||
from test.unit.modules.utils import set_module_args
|
from test.unit.modules.utils import set_module_args
|
||||||
except ImportError:
|
except ImportError:
|
||||||
try:
|
try:
|
||||||
from ansible.modules.network.f5.bigip_device_connectivity import Parameters
|
from ansible.modules.network.f5.bigip_device_connectivity import ApiParameters
|
||||||
|
from ansible.modules.network.f5.bigip_device_connectivity import ModuleParameters
|
||||||
from ansible.modules.network.f5.bigip_device_connectivity import ModuleManager
|
from ansible.modules.network.f5.bigip_device_connectivity import ModuleManager
|
||||||
from ansible.modules.network.f5.bigip_device_connectivity import ArgumentSpec
|
from ansible.modules.network.f5.bigip_device_connectivity import ArgumentSpec
|
||||||
from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError
|
from ansible.module_utils.network.f5.common import F5ModuleError
|
||||||
|
from ansible.module_utils.network.f5.common import iControlUnexpectedHTTPError
|
||||||
from units.modules.utils import set_module_args
|
from units.modules.utils import set_module_args
|
||||||
except ImportError:
|
except ImportError:
|
||||||
raise SkipTest("F5 Ansible modules require the f5-sdk Python library")
|
raise SkipTest("F5 Ansible modules require the f5-sdk Python library")
|
||||||
|
@ -80,7 +83,7 @@ class TestParameters(unittest.TestCase):
|
||||||
user='admin',
|
user='admin',
|
||||||
password='password'
|
password='password'
|
||||||
)
|
)
|
||||||
p = Parameters(args)
|
p = ModuleParameters(params=args)
|
||||||
assert p.multicast_port == 1010
|
assert p.multicast_port == 1010
|
||||||
assert p.multicast_address == '10.10.10.10'
|
assert p.multicast_address == '10.10.10.10'
|
||||||
assert p.multicast_interface == 'eth0'
|
assert p.multicast_interface == 'eth0'
|
||||||
|
@ -100,7 +103,7 @@ class TestParameters(unittest.TestCase):
|
||||||
|
|
||||||
def test_api_parameters(self):
|
def test_api_parameters(self):
|
||||||
params = load_fixture('load_tm_cm_device.json')
|
params = load_fixture('load_tm_cm_device.json')
|
||||||
p = Parameters(params)
|
p = ApiParameters(params=params)
|
||||||
assert p.multicast_port == 62960
|
assert p.multicast_port == 62960
|
||||||
assert p.multicast_address == '224.0.0.245'
|
assert p.multicast_address == '224.0.0.245'
|
||||||
assert p.multicast_interface == 'eth0'
|
assert p.multicast_interface == 'eth0'
|
||||||
|
@ -118,8 +121,6 @@ class TestParameters(unittest.TestCase):
|
||||||
assert p.unicast_failover[0]['effectivePort'] == 1026
|
assert p.unicast_failover[0]['effectivePort'] == 1026
|
||||||
|
|
||||||
|
|
||||||
@patch('ansible.module_utils.f5_utils.AnsibleF5Client._get_mgmt_root',
|
|
||||||
return_value=True)
|
|
||||||
class TestManager(unittest.TestCase):
|
class TestManager(unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
@ -141,14 +142,13 @@ class TestManager(unittest.TestCase):
|
||||||
|
|
||||||
# Configure the parameters that would be returned by querying the
|
# Configure the parameters that would be returned by querying the
|
||||||
# remote device
|
# remote device
|
||||||
current = Parameters(load_fixture('load_tm_cm_device_default.json'))
|
current = ApiParameters(params=load_fixture('load_tm_cm_device_default.json'))
|
||||||
|
|
||||||
client = AnsibleF5Client(
|
module = AnsibleModule(
|
||||||
argument_spec=self.spec.argument_spec,
|
argument_spec=self.spec.argument_spec,
|
||||||
supports_check_mode=self.spec.supports_check_mode,
|
supports_check_mode=self.spec.supports_check_mode
|
||||||
f5_product_name=self.spec.f5_product_name
|
|
||||||
)
|
)
|
||||||
mm = ModuleManager(client)
|
mm = ModuleManager(module=module)
|
||||||
|
|
||||||
# Override methods to force specific logic in the module to happen
|
# Override methods to force specific logic in the module to happen
|
||||||
mm.update_on_device = Mock(return_value=True)
|
mm.update_on_device = Mock(return_value=True)
|
||||||
|
@ -159,7 +159,7 @@ class TestManager(unittest.TestCase):
|
||||||
assert results['changed'] is True
|
assert results['changed'] is True
|
||||||
assert results['config_sync_ip'] == '10.1.30.1'
|
assert results['config_sync_ip'] == '10.1.30.1'
|
||||||
assert results['mirror_primary_address'] == '10.1.30.1'
|
assert results['mirror_primary_address'] == '10.1.30.1'
|
||||||
assert len(results.keys()) == 3
|
assert len(results.keys()) == 4
|
||||||
|
|
||||||
def test_set_primary_mirror_address_none(self, *args):
|
def test_set_primary_mirror_address_none(self, *args):
|
||||||
set_module_args(dict(
|
set_module_args(dict(
|
||||||
|
@ -171,14 +171,13 @@ class TestManager(unittest.TestCase):
|
||||||
|
|
||||||
# Configure the parameters that would be returned by querying the
|
# Configure the parameters that would be returned by querying the
|
||||||
# remote device
|
# remote device
|
||||||
current = Parameters(load_fixture('load_tm_cm_device.json'))
|
current = ApiParameters(params=load_fixture('load_tm_cm_device.json'))
|
||||||
|
|
||||||
client = AnsibleF5Client(
|
module = AnsibleModule(
|
||||||
argument_spec=self.spec.argument_spec,
|
argument_spec=self.spec.argument_spec,
|
||||||
supports_check_mode=self.spec.supports_check_mode,
|
supports_check_mode=self.spec.supports_check_mode
|
||||||
f5_product_name=self.spec.f5_product_name
|
|
||||||
)
|
)
|
||||||
mm = ModuleManager(client)
|
mm = ModuleManager(module=module)
|
||||||
|
|
||||||
# Override methods to force specific logic in the module to happen
|
# Override methods to force specific logic in the module to happen
|
||||||
mm.update_on_device = Mock(return_value=True)
|
mm.update_on_device = Mock(return_value=True)
|
||||||
|
@ -200,14 +199,13 @@ class TestManager(unittest.TestCase):
|
||||||
|
|
||||||
# Configure the parameters that would be returned by querying the
|
# Configure the parameters that would be returned by querying the
|
||||||
# remote device
|
# remote device
|
||||||
current = Parameters(load_fixture('load_tm_cm_device.json'))
|
current = ApiParameters(params=load_fixture('load_tm_cm_device.json'))
|
||||||
|
|
||||||
client = AnsibleF5Client(
|
module = AnsibleModule(
|
||||||
argument_spec=self.spec.argument_spec,
|
argument_spec=self.spec.argument_spec,
|
||||||
supports_check_mode=self.spec.supports_check_mode,
|
supports_check_mode=self.spec.supports_check_mode
|
||||||
f5_product_name=self.spec.f5_product_name
|
|
||||||
)
|
)
|
||||||
mm = ModuleManager(client)
|
mm = ModuleManager(module=module)
|
||||||
|
|
||||||
# Override methods to force specific logic in the module to happen
|
# Override methods to force specific logic in the module to happen
|
||||||
mm.update_on_device = Mock(return_value=True)
|
mm.update_on_device = Mock(return_value=True)
|
||||||
|
@ -229,14 +227,13 @@ class TestManager(unittest.TestCase):
|
||||||
|
|
||||||
# Configure the parameters that would be returned by querying the
|
# Configure the parameters that would be returned by querying the
|
||||||
# remote device
|
# remote device
|
||||||
current = Parameters(load_fixture('load_tm_cm_device.json'))
|
current = ApiParameters(params=load_fixture('load_tm_cm_device.json'))
|
||||||
|
|
||||||
client = AnsibleF5Client(
|
module = AnsibleModule(
|
||||||
argument_spec=self.spec.argument_spec,
|
argument_spec=self.spec.argument_spec,
|
||||||
supports_check_mode=self.spec.supports_check_mode,
|
supports_check_mode=self.spec.supports_check_mode
|
||||||
f5_product_name=self.spec.f5_product_name
|
|
||||||
)
|
)
|
||||||
mm = ModuleManager(client)
|
mm = ModuleManager(module=module)
|
||||||
|
|
||||||
# Override methods to force specific logic in the module to happen
|
# Override methods to force specific logic in the module to happen
|
||||||
mm.update_on_device = Mock(return_value=True)
|
mm.update_on_device = Mock(return_value=True)
|
||||||
|
@ -258,14 +255,13 @@ class TestManager(unittest.TestCase):
|
||||||
|
|
||||||
# Configure the parameters that would be returned by querying the
|
# Configure the parameters that would be returned by querying the
|
||||||
# remote device
|
# remote device
|
||||||
current = Parameters(load_fixture('load_tm_cm_device.json'))
|
current = ApiParameters(params=load_fixture('load_tm_cm_device.json'))
|
||||||
|
|
||||||
client = AnsibleF5Client(
|
module = AnsibleModule(
|
||||||
argument_spec=self.spec.argument_spec,
|
argument_spec=self.spec.argument_spec,
|
||||||
supports_check_mode=self.spec.supports_check_mode,
|
supports_check_mode=self.spec.supports_check_mode
|
||||||
f5_product_name=self.spec.f5_product_name
|
|
||||||
)
|
)
|
||||||
mm = ModuleManager(client)
|
mm = ModuleManager(module=module)
|
||||||
|
|
||||||
# Override methods to force specific logic in the module to happen
|
# Override methods to force specific logic in the module to happen
|
||||||
mm.update_on_device = Mock(return_value=True)
|
mm.update_on_device = Mock(return_value=True)
|
||||||
|
@ -286,14 +282,13 @@ class TestManager(unittest.TestCase):
|
||||||
|
|
||||||
# Configure the parameters that would be returned by querying the
|
# Configure the parameters that would be returned by querying the
|
||||||
# remote device
|
# remote device
|
||||||
current = Parameters(load_fixture('load_tm_cm_device.json'))
|
current = ApiParameters(params=load_fixture('load_tm_cm_device.json'))
|
||||||
|
|
||||||
client = AnsibleF5Client(
|
module = AnsibleModule(
|
||||||
argument_spec=self.spec.argument_spec,
|
argument_spec=self.spec.argument_spec,
|
||||||
supports_check_mode=self.spec.supports_check_mode,
|
supports_check_mode=self.spec.supports_check_mode
|
||||||
f5_product_name=self.spec.f5_product_name
|
|
||||||
)
|
)
|
||||||
mm = ModuleManager(client)
|
mm = ModuleManager(module=module)
|
||||||
|
|
||||||
# Override methods to force specific logic in the module to happen
|
# Override methods to force specific logic in the module to happen
|
||||||
mm.update_on_device = Mock(return_value=True)
|
mm.update_on_device = Mock(return_value=True)
|
||||||
|
@ -315,14 +310,13 @@ class TestManager(unittest.TestCase):
|
||||||
|
|
||||||
# Configure the parameters that would be returned by querying the
|
# Configure the parameters that would be returned by querying the
|
||||||
# remote device
|
# remote device
|
||||||
current = Parameters(load_fixture('load_tm_cm_device.json'))
|
current = ApiParameters(params=load_fixture('load_tm_cm_device.json'))
|
||||||
|
|
||||||
client = AnsibleF5Client(
|
module = AnsibleModule(
|
||||||
argument_spec=self.spec.argument_spec,
|
argument_spec=self.spec.argument_spec,
|
||||||
supports_check_mode=self.spec.supports_check_mode,
|
supports_check_mode=self.spec.supports_check_mode
|
||||||
f5_product_name=self.spec.f5_product_name
|
|
||||||
)
|
)
|
||||||
mm = ModuleManager(client)
|
mm = ModuleManager(module=module)
|
||||||
|
|
||||||
# Override methods to force specific logic in the module to happen
|
# Override methods to force specific logic in the module to happen
|
||||||
mm.update_on_device = Mock(return_value=True)
|
mm.update_on_device = Mock(return_value=True)
|
||||||
|
@ -344,14 +338,13 @@ class TestManager(unittest.TestCase):
|
||||||
|
|
||||||
# Configure the parameters that would be returned by querying the
|
# Configure the parameters that would be returned by querying the
|
||||||
# remote device
|
# remote device
|
||||||
current = Parameters(load_fixture('load_tm_cm_device.json'))
|
current = ApiParameters(params=load_fixture('load_tm_cm_device.json'))
|
||||||
|
|
||||||
client = AnsibleF5Client(
|
module = AnsibleModule(
|
||||||
argument_spec=self.spec.argument_spec,
|
argument_spec=self.spec.argument_spec,
|
||||||
supports_check_mode=self.spec.supports_check_mode,
|
supports_check_mode=self.spec.supports_check_mode
|
||||||
f5_product_name=self.spec.f5_product_name
|
|
||||||
)
|
)
|
||||||
mm = ModuleManager(client)
|
mm = ModuleManager(module=module)
|
||||||
|
|
||||||
# Override methods to force specific logic in the module to happen
|
# Override methods to force specific logic in the module to happen
|
||||||
mm.update_on_device = Mock(return_value=True)
|
mm.update_on_device = Mock(return_value=True)
|
||||||
|
|
|
@ -18,21 +18,22 @@ if sys.version_info < (2, 7):
|
||||||
from ansible.compat.tests import unittest
|
from ansible.compat.tests import unittest
|
||||||
from ansible.compat.tests.mock import Mock
|
from ansible.compat.tests.mock import Mock
|
||||||
from ansible.compat.tests.mock import patch
|
from ansible.compat.tests.mock import patch
|
||||||
from ansible.module_utils.f5_utils import AnsibleF5Client
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
from ansible.module_utils.f5_utils import F5ModuleError
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from library.bigip_device_dns import Parameters
|
from library.bigip_device_dns import Parameters
|
||||||
from library.bigip_device_dns import ModuleManager
|
from library.bigip_device_dns import ModuleManager
|
||||||
from library.bigip_device_dns import ArgumentSpec
|
from library.bigip_device_dns import ArgumentSpec
|
||||||
from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError
|
from library.module_utils.network.f5.common import F5ModuleError
|
||||||
|
from library.module_utils.network.f5.common import iControlUnexpectedHTTPError
|
||||||
from test.unit.modules.utils import set_module_args
|
from test.unit.modules.utils import set_module_args
|
||||||
except ImportError:
|
except ImportError:
|
||||||
try:
|
try:
|
||||||
from ansible.modules.network.f5.bigip_device_dns import Parameters
|
from ansible.modules.network.f5.bigip_device_dns import Parameters
|
||||||
from ansible.modules.network.f5.bigip_device_dns import ModuleManager
|
from ansible.modules.network.f5.bigip_device_dns import ModuleManager
|
||||||
from ansible.modules.network.f5.bigip_device_dns import ArgumentSpec
|
from ansible.modules.network.f5.bigip_device_dns import ArgumentSpec
|
||||||
from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError
|
from ansible.module_utils.network.f5.common import F5ModuleError
|
||||||
|
from ansible.module_utils.network.f5.common import iControlUnexpectedHTTPError
|
||||||
from units.modules.utils import set_module_args
|
from units.modules.utils import set_module_args
|
||||||
except ImportError:
|
except ImportError:
|
||||||
raise SkipTest("F5 Ansible modules require the f5-sdk Python library")
|
raise SkipTest("F5 Ansible modules require the f5-sdk Python library")
|
||||||
|
@ -71,7 +72,7 @@ class TestParameters(unittest.TestCase):
|
||||||
user='admin',
|
user='admin',
|
||||||
password='password'
|
password='password'
|
||||||
)
|
)
|
||||||
p = Parameters(args)
|
p = Parameters(params=args)
|
||||||
assert p.cache == 'disable'
|
assert p.cache == 'disable'
|
||||||
assert p.name_servers == ['10.10.10.10', '11.11.11.11']
|
assert p.name_servers == ['10.10.10.10', '11.11.11.11']
|
||||||
assert p.search == ['14.14.14.14', '15.15.15.15']
|
assert p.search == ['14.14.14.14', '15.15.15.15']
|
||||||
|
@ -83,16 +84,16 @@ class TestParameters(unittest.TestCase):
|
||||||
args = dict(
|
args = dict(
|
||||||
ip_version=6
|
ip_version=6
|
||||||
)
|
)
|
||||||
p = Parameters(args)
|
p = Parameters(params=args)
|
||||||
assert p.ip_version == 'options inet6'
|
assert p.ip_version == 'options inet6'
|
||||||
|
|
||||||
def test_ensure_forwards_raises_exception(self):
|
def test_ensure_forwards_raises_exception(self):
|
||||||
args = dict(
|
args = dict(
|
||||||
forwarders=['12.12.12.12', '13.13.13.13'],
|
forwarders=['12.12.12.12', '13.13.13.13'],
|
||||||
)
|
)
|
||||||
p = Parameters(args)
|
p = Parameters(params=args)
|
||||||
with pytest.raises(F5ModuleError) as ex:
|
with pytest.raises(F5ModuleError) as ex:
|
||||||
foo = p.forwarders
|
p.forwarders
|
||||||
assert 'The modifying of forwarders is not supported' in str(ex)
|
assert 'The modifying of forwarders is not supported' in str(ex)
|
||||||
|
|
||||||
|
|
||||||
|
@ -101,8 +102,6 @@ class TestManager(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.spec = ArgumentSpec()
|
self.spec = ArgumentSpec()
|
||||||
|
|
||||||
@patch('ansible.module_utils.f5_utils.AnsibleF5Client._get_mgmt_root',
|
|
||||||
return_value=True)
|
|
||||||
def test_update_settings(self, *args):
|
def test_update_settings(self, *args):
|
||||||
set_module_args(dict(
|
set_module_args(dict(
|
||||||
cache='disable',
|
cache='disable',
|
||||||
|
@ -123,12 +122,11 @@ class TestManager(unittest.TestCase):
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
client = AnsibleF5Client(
|
module = AnsibleModule(
|
||||||
argument_spec=self.spec.argument_spec,
|
argument_spec=self.spec.argument_spec,
|
||||||
supports_check_mode=self.spec.supports_check_mode,
|
supports_check_mode=self.spec.supports_check_mode
|
||||||
f5_product_name=self.spec.f5_product_name
|
|
||||||
)
|
)
|
||||||
mm = ModuleManager(client)
|
mm = ModuleManager(module=module)
|
||||||
|
|
||||||
# Override methods to force specific logic in the module to happen
|
# Override methods to force specific logic in the module to happen
|
||||||
mm.update_on_device = Mock(return_value=True)
|
mm.update_on_device = Mock(return_value=True)
|
||||||
|
|
|
@ -17,20 +17,22 @@ if sys.version_info < (2, 7):
|
||||||
from ansible.compat.tests import unittest
|
from ansible.compat.tests import unittest
|
||||||
from ansible.compat.tests.mock import Mock
|
from ansible.compat.tests.mock import Mock
|
||||||
from ansible.compat.tests.mock import patch
|
from ansible.compat.tests.mock import patch
|
||||||
from ansible.module_utils.f5_utils import AnsibleF5Client
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from library.bigip_device_httpd import Parameters
|
from library.bigip_device_httpd import Parameters
|
||||||
from library.bigip_device_httpd import ModuleManager
|
from library.bigip_device_httpd import ModuleManager
|
||||||
from library.bigip_device_httpd import ArgumentSpec
|
from library.bigip_device_httpd import ArgumentSpec
|
||||||
from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError
|
from library.module_utils.network.f5.common import F5ModuleError
|
||||||
|
from library.module_utils.network.f5.common import iControlUnexpectedHTTPError
|
||||||
from test.unit.modules.utils import set_module_args
|
from test.unit.modules.utils import set_module_args
|
||||||
except ImportError:
|
except ImportError:
|
||||||
try:
|
try:
|
||||||
from ansible.modules.network.f5.bigip_device_httpd import Parameters
|
from ansible.modules.network.f5.bigip_device_httpd import Parameters
|
||||||
from ansible.modules.network.f5.bigip_device_httpd import ModuleManager
|
from ansible.modules.network.f5.bigip_device_httpd import ModuleManager
|
||||||
from ansible.modules.network.f5.bigip_device_httpd import ArgumentSpec
|
from ansible.modules.network.f5.bigip_device_httpd import ArgumentSpec
|
||||||
from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError
|
from ansible.module_utils.network.f5.common import F5ModuleError
|
||||||
|
from ansible.module_utils.network.f5.common import iControlUnexpectedHTTPError
|
||||||
from units.modules.utils import set_module_args
|
from units.modules.utils import set_module_args
|
||||||
except ImportError:
|
except ImportError:
|
||||||
raise SkipTest("F5 Ansible modules require the f5-sdk Python library")
|
raise SkipTest("F5 Ansible modules require the f5-sdk Python library")
|
||||||
|
@ -65,20 +67,18 @@ class TestParameters(unittest.TestCase):
|
||||||
auth_pam_validate_ip='on'
|
auth_pam_validate_ip='on'
|
||||||
)
|
)
|
||||||
|
|
||||||
p = Parameters(args)
|
p = Parameters(params=args)
|
||||||
assert p.auth_name == 'BIG-IP'
|
assert p.auth_name == 'BIG-IP'
|
||||||
assert p.auth_pam_idle_timeout == 1200
|
assert p.auth_pam_idle_timeout == 1200
|
||||||
assert p.auth_pam_validate_ip == 'on'
|
assert p.auth_pam_validate_ip == 'on'
|
||||||
|
|
||||||
def test_api_parameters(self):
|
def test_api_parameters(self):
|
||||||
args = load_fixture('load_sys_httpd.json')
|
args = load_fixture('load_sys_httpd.json')
|
||||||
p = Parameters(args)
|
p = Parameters(params=args)
|
||||||
assert p.auth_name == 'BIG-IP'
|
assert p.auth_name == 'BIG-IP'
|
||||||
assert p.auth_pam_idle_timeout == 1200
|
assert p.auth_pam_idle_timeout == 1200
|
||||||
|
|
||||||
|
|
||||||
@patch('ansible.module_utils.f5_utils.AnsibleF5Client._get_mgmt_root',
|
|
||||||
return_value=True)
|
|
||||||
class TestModuleManager(unittest.TestCase):
|
class TestModuleManager(unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
@ -103,16 +103,13 @@ class TestModuleManager(unittest.TestCase):
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
current = Parameters(
|
current = Parameters(params=load_fixture('load_sys_httpd.json'))
|
||||||
load_fixture('load_sys_httpd.json')
|
|
||||||
)
|
|
||||||
|
|
||||||
client = AnsibleF5Client(
|
module = AnsibleModule(
|
||||||
argument_spec=self.spec.argument_spec,
|
argument_spec=self.spec.argument_spec,
|
||||||
supports_check_mode=self.spec.supports_check_mode,
|
supports_check_mode=self.spec.supports_check_mode
|
||||||
f5_product_name=self.spec.f5_product_name
|
|
||||||
)
|
)
|
||||||
mm = ModuleManager(client)
|
mm = ModuleManager(module=module)
|
||||||
|
|
||||||
# Override methods to force specific logic in the module to happen
|
# Override methods to force specific logic in the module to happen
|
||||||
mm.update_on_device = Mock(return_value=True)
|
mm.update_on_device = Mock(return_value=True)
|
||||||
|
|
|
@ -17,20 +17,22 @@ if sys.version_info < (2, 7):
|
||||||
from ansible.compat.tests import unittest
|
from ansible.compat.tests import unittest
|
||||||
from ansible.compat.tests.mock import Mock
|
from ansible.compat.tests.mock import Mock
|
||||||
from ansible.compat.tests.mock import patch
|
from ansible.compat.tests.mock import patch
|
||||||
from ansible.module_utils.f5_utils import AnsibleF5Client
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from library.bigip_device_ntp import Parameters
|
from library.bigip_device_ntp import Parameters
|
||||||
from library.bigip_device_ntp import ModuleManager
|
from library.bigip_device_ntp import ModuleManager
|
||||||
from library.bigip_device_ntp import ArgumentSpec
|
from library.bigip_device_ntp import ArgumentSpec
|
||||||
from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError
|
from library.module_utils.network.f5.common import F5ModuleError
|
||||||
|
from library.module_utils.network.f5.common import iControlUnexpectedHTTPError
|
||||||
from test.unit.modules.utils import set_module_args
|
from test.unit.modules.utils import set_module_args
|
||||||
except ImportError:
|
except ImportError:
|
||||||
try:
|
try:
|
||||||
from ansible.modules.network.f5.bigip_device_ntp import Parameters
|
from ansible.modules.network.f5.bigip_device_ntp import Parameters
|
||||||
from ansible.modules.network.f5.bigip_device_ntp import ModuleManager
|
from ansible.modules.network.f5.bigip_device_ntp import ModuleManager
|
||||||
from ansible.modules.network.f5.bigip_device_ntp import ArgumentSpec
|
from ansible.modules.network.f5.bigip_device_ntp import ArgumentSpec
|
||||||
from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError
|
from ansible.module_utils.network.f5.common import F5ModuleError
|
||||||
|
from ansible.module_utils.network.f5.common import iControlUnexpectedHTTPError
|
||||||
from units.modules.utils import set_module_args
|
from units.modules.utils import set_module_args
|
||||||
except ImportError:
|
except ImportError:
|
||||||
raise SkipTest("F5 Ansible modules require the f5-sdk Python library")
|
raise SkipTest("F5 Ansible modules require the f5-sdk Python library")
|
||||||
|
@ -65,7 +67,7 @@ class TestParameters(unittest.TestCase):
|
||||||
timezone='Arctic/Longyearbyen'
|
timezone='Arctic/Longyearbyen'
|
||||||
)
|
)
|
||||||
|
|
||||||
p = Parameters(args)
|
p = Parameters(params=args)
|
||||||
assert p.ntp_servers == ntp
|
assert p.ntp_servers == ntp
|
||||||
assert p.timezone == 'Arctic/Longyearbyen'
|
assert p.timezone == 'Arctic/Longyearbyen'
|
||||||
|
|
||||||
|
@ -76,13 +78,11 @@ class TestParameters(unittest.TestCase):
|
||||||
timezone='Arctic/Longyearbyen'
|
timezone='Arctic/Longyearbyen'
|
||||||
)
|
)
|
||||||
|
|
||||||
p = Parameters(args)
|
p = Parameters(params=args)
|
||||||
assert p.ntp_servers == ntp
|
assert p.ntp_servers == ntp
|
||||||
assert p.timezone == 'Arctic/Longyearbyen'
|
assert p.timezone == 'Arctic/Longyearbyen'
|
||||||
|
|
||||||
|
|
||||||
@patch('ansible.module_utils.f5_utils.AnsibleF5Client._get_mgmt_root',
|
|
||||||
return_value=True)
|
|
||||||
class TestModuleManager(unittest.TestCase):
|
class TestModuleManager(unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
@ -101,16 +101,13 @@ class TestModuleManager(unittest.TestCase):
|
||||||
|
|
||||||
# Configure the parameters that would be returned by querying the
|
# Configure the parameters that would be returned by querying the
|
||||||
# remote device
|
# remote device
|
||||||
current = Parameters(
|
current = Parameters(params=load_fixture('load_ntp.json'))
|
||||||
load_fixture('load_ntp.json')
|
|
||||||
)
|
|
||||||
|
|
||||||
client = AnsibleF5Client(
|
module = AnsibleModule(
|
||||||
argument_spec=self.spec.argument_spec,
|
argument_spec=self.spec.argument_spec,
|
||||||
supports_check_mode=self.spec.supports_check_mode,
|
supports_check_mode=self.spec.supports_check_mode
|
||||||
f5_product_name=self.spec.f5_product_name
|
|
||||||
)
|
)
|
||||||
mm = ModuleManager(client)
|
mm = ModuleManager(module=module)
|
||||||
|
|
||||||
# Override methods to force specific logic in the module to happen
|
# Override methods to force specific logic in the module to happen
|
||||||
mm.update_on_device = Mock(return_value=True)
|
mm.update_on_device = Mock(return_value=True)
|
||||||
|
@ -132,16 +129,13 @@ class TestModuleManager(unittest.TestCase):
|
||||||
|
|
||||||
# Configure the parameters that would be returned by querying the
|
# Configure the parameters that would be returned by querying the
|
||||||
# remote device
|
# remote device
|
||||||
current = Parameters(
|
current = Parameters(params=load_fixture('load_ntp.json'))
|
||||||
load_fixture('load_ntp.json')
|
|
||||||
)
|
|
||||||
|
|
||||||
client = AnsibleF5Client(
|
module = AnsibleModule(
|
||||||
argument_spec=self.spec.argument_spec,
|
argument_spec=self.spec.argument_spec,
|
||||||
supports_check_mode=self.spec.supports_check_mode,
|
supports_check_mode=self.spec.supports_check_mode
|
||||||
f5_product_name=self.spec.f5_product_name
|
|
||||||
)
|
)
|
||||||
mm = ModuleManager(client)
|
mm = ModuleManager(module=module)
|
||||||
|
|
||||||
# Override methods to force specific logic in the module to happen
|
# Override methods to force specific logic in the module to happen
|
||||||
mm.update_on_device = Mock(return_value=True)
|
mm.update_on_device = Mock(return_value=True)
|
||||||
|
@ -165,16 +159,13 @@ class TestModuleManager(unittest.TestCase):
|
||||||
|
|
||||||
# Configure the parameters that would be returned by querying the
|
# Configure the parameters that would be returned by querying the
|
||||||
# remote device
|
# remote device
|
||||||
current = Parameters(
|
current = Parameters(params=load_fixture('load_ntp.json'))
|
||||||
load_fixture('load_ntp.json')
|
|
||||||
)
|
|
||||||
|
|
||||||
client = AnsibleF5Client(
|
module = AnsibleModule(
|
||||||
argument_spec=self.spec.argument_spec,
|
argument_spec=self.spec.argument_spec,
|
||||||
supports_check_mode=self.spec.supports_check_mode,
|
supports_check_mode=self.spec.supports_check_mode
|
||||||
f5_product_name=self.spec.f5_product_name
|
|
||||||
)
|
)
|
||||||
mm = ModuleManager(client)
|
mm = ModuleManager(module=module)
|
||||||
|
|
||||||
# Override methods to force specific logic in the module to happen
|
# Override methods to force specific logic in the module to happen
|
||||||
mm.update_on_device = Mock(return_value=True)
|
mm.update_on_device = Mock(return_value=True)
|
||||||
|
@ -200,16 +191,13 @@ class TestModuleManager(unittest.TestCase):
|
||||||
|
|
||||||
# Configure the parameters that would be returned by querying the
|
# Configure the parameters that would be returned by querying the
|
||||||
# remote device
|
# remote device
|
||||||
current = Parameters(
|
current = Parameters(params=load_fixture('load_ntp.json'))
|
||||||
load_fixture('load_ntp.json')
|
|
||||||
)
|
|
||||||
|
|
||||||
client = AnsibleF5Client(
|
module = AnsibleModule(
|
||||||
argument_spec=self.spec.argument_spec,
|
argument_spec=self.spec.argument_spec,
|
||||||
supports_check_mode=self.spec.supports_check_mode,
|
supports_check_mode=self.spec.supports_check_mode
|
||||||
f5_product_name=self.spec.f5_product_name
|
|
||||||
)
|
)
|
||||||
mm = ModuleManager(client)
|
mm = ModuleManager(module=module)
|
||||||
|
|
||||||
# Override methods to force specific logic in the module to happen
|
# Override methods to force specific logic in the module to happen
|
||||||
mm.absent_on_device = Mock(return_value=True)
|
mm.absent_on_device = Mock(return_value=True)
|
||||||
|
@ -233,16 +221,13 @@ class TestModuleManager(unittest.TestCase):
|
||||||
|
|
||||||
# Configure the parameters that would be returned by querying the
|
# Configure the parameters that would be returned by querying the
|
||||||
# remote device
|
# remote device
|
||||||
current = Parameters(
|
current = Parameters(params=load_fixture('load_ntp.json'))
|
||||||
load_fixture('load_ntp.json')
|
|
||||||
)
|
|
||||||
|
|
||||||
client = AnsibleF5Client(
|
module = AnsibleModule(
|
||||||
argument_spec=self.spec.argument_spec,
|
argument_spec=self.spec.argument_spec,
|
||||||
supports_check_mode=self.spec.supports_check_mode,
|
supports_check_mode=self.spec.supports_check_mode
|
||||||
f5_product_name=self.spec.f5_product_name
|
|
||||||
)
|
)
|
||||||
mm = ModuleManager(client)
|
mm = ModuleManager(module=module)
|
||||||
|
|
||||||
# Override methods to force specific logic in the module to happen
|
# Override methods to force specific logic in the module to happen
|
||||||
mm.absent_on_device = Mock(return_value=True)
|
mm.absent_on_device = Mock(return_value=True)
|
||||||
|
|
|
@ -17,20 +17,22 @@ if sys.version_info < (2, 7):
|
||||||
from ansible.compat.tests import unittest
|
from ansible.compat.tests import unittest
|
||||||
from ansible.compat.tests.mock import Mock
|
from ansible.compat.tests.mock import Mock
|
||||||
from ansible.compat.tests.mock import patch
|
from ansible.compat.tests.mock import patch
|
||||||
from ansible.module_utils.f5_utils import AnsibleF5Client
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from library.bigip_device_sshd import Parameters
|
from library.bigip_device_sshd import Parameters
|
||||||
from library.bigip_device_sshd import ModuleManager
|
from library.bigip_device_sshd import ModuleManager
|
||||||
from library.bigip_device_sshd import ArgumentSpec
|
from library.bigip_device_sshd import ArgumentSpec
|
||||||
from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError
|
from library.module_utils.network.f5.common import F5ModuleError
|
||||||
|
from library.module_utils.network.f5.common import iControlUnexpectedHTTPError
|
||||||
from test.unit.modules.utils import set_module_args
|
from test.unit.modules.utils import set_module_args
|
||||||
except ImportError:
|
except ImportError:
|
||||||
try:
|
try:
|
||||||
from ansible.modules.network.f5.bigip_device_sshd import Parameters
|
from ansible.modules.network.f5.bigip_device_sshd import Parameters
|
||||||
from ansible.modules.network.f5.bigip_device_sshd import ModuleManager
|
from ansible.modules.network.f5.bigip_device_sshd import ModuleManager
|
||||||
from ansible.modules.network.f5.bigip_device_sshd import ArgumentSpec
|
from ansible.modules.network.f5.bigip_device_sshd import ArgumentSpec
|
||||||
from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError
|
from ansible.module_utils.network.f5.common import F5ModuleError
|
||||||
|
from ansible.module_utils.network.f5.common import iControlUnexpectedHTTPError
|
||||||
from units.modules.utils import set_module_args
|
from units.modules.utils import set_module_args
|
||||||
except ImportError:
|
except ImportError:
|
||||||
raise SkipTest("F5 Ansible modules require the f5-sdk Python library")
|
raise SkipTest("F5 Ansible modules require the f5-sdk Python library")
|
||||||
|
@ -71,7 +73,7 @@ class TestParameters(unittest.TestCase):
|
||||||
user='admin',
|
user='admin',
|
||||||
password='password'
|
password='password'
|
||||||
)
|
)
|
||||||
p = Parameters(args)
|
p = Parameters(params=args)
|
||||||
assert p.allow == ['all']
|
assert p.allow == ['all']
|
||||||
assert p.banner == 'enabled'
|
assert p.banner == 'enabled'
|
||||||
assert p.banner_text == 'asdf'
|
assert p.banner_text == 'asdf'
|
||||||
|
@ -86,8 +88,6 @@ class TestManager(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.spec = ArgumentSpec()
|
self.spec = ArgumentSpec()
|
||||||
|
|
||||||
@patch('ansible.module_utils.f5_utils.AnsibleF5Client._get_mgmt_root',
|
|
||||||
return_value=True)
|
|
||||||
def test_update_settings(self, *args):
|
def test_update_settings(self, *args):
|
||||||
set_module_args(dict(
|
set_module_args(dict(
|
||||||
allow=['all'],
|
allow=['all'],
|
||||||
|
@ -110,12 +110,11 @@ class TestManager(unittest.TestCase):
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
client = AnsibleF5Client(
|
module = AnsibleModule(
|
||||||
argument_spec=self.spec.argument_spec,
|
argument_spec=self.spec.argument_spec,
|
||||||
supports_check_mode=self.spec.supports_check_mode,
|
supports_check_mode=self.spec.supports_check_mode
|
||||||
f5_product_name=self.spec.f5_product_name
|
|
||||||
)
|
)
|
||||||
mm = ModuleManager(client)
|
mm = ModuleManager(module=module)
|
||||||
|
|
||||||
# Override methods to force specific logic in the module to happen
|
# Override methods to force specific logic in the module to happen
|
||||||
mm.update_on_device = Mock(return_value=True)
|
mm.update_on_device = Mock(return_value=True)
|
||||||
|
|
|
@ -17,7 +17,7 @@ if sys.version_info < (2, 7):
|
||||||
from ansible.compat.tests import unittest
|
from ansible.compat.tests import unittest
|
||||||
from ansible.compat.tests.mock import Mock
|
from ansible.compat.tests.mock import Mock
|
||||||
from ansible.compat.tests.mock import patch
|
from ansible.compat.tests.mock import patch
|
||||||
from ansible.module_utils.f5_utils import AnsibleF5Client
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from library.bigip_device_trust import Parameters
|
from library.bigip_device_trust import Parameters
|
||||||
|
@ -25,7 +25,8 @@ try:
|
||||||
from library.bigip_device_trust import ArgumentSpec
|
from library.bigip_device_trust import ArgumentSpec
|
||||||
from library.bigip_device_trust import HAS_F5SDK
|
from library.bigip_device_trust import HAS_F5SDK
|
||||||
from library.bigip_device_trust import HAS_NETADDR
|
from library.bigip_device_trust import HAS_NETADDR
|
||||||
from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError
|
from library.module_utils.network.f5.common import F5ModuleError
|
||||||
|
from library.module_utils.network.f5.common import iControlUnexpectedHTTPError
|
||||||
from test.unit.modules.utils import set_module_args
|
from test.unit.modules.utils import set_module_args
|
||||||
except ImportError:
|
except ImportError:
|
||||||
try:
|
try:
|
||||||
|
@ -34,7 +35,8 @@ except ImportError:
|
||||||
from ansible.modules.network.f5.bigip_device_trust import ArgumentSpec
|
from ansible.modules.network.f5.bigip_device_trust import ArgumentSpec
|
||||||
from ansible.modules.network.f5.bigip_device_trust import HAS_F5SDK
|
from ansible.modules.network.f5.bigip_device_trust import HAS_F5SDK
|
||||||
from ansible.modules.network.f5.bigip_device_trust import HAS_NETADDR
|
from ansible.modules.network.f5.bigip_device_trust import HAS_NETADDR
|
||||||
from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError
|
from ansible.module_utils.network.f5.common import F5ModuleError
|
||||||
|
from ansible.module_utils.network.f5.common import iControlUnexpectedHTTPError
|
||||||
from units.modules.utils import set_module_args
|
from units.modules.utils import set_module_args
|
||||||
except ImportError:
|
except ImportError:
|
||||||
raise SkipTest("F5 Ansible modules require the f5-sdk Python library")
|
raise SkipTest("F5 Ansible modules require the f5-sdk Python library")
|
||||||
|
@ -74,7 +76,7 @@ class TestParameters(unittest.TestCase):
|
||||||
peer_password='secret'
|
peer_password='secret'
|
||||||
)
|
)
|
||||||
|
|
||||||
p = Parameters(args)
|
p = Parameters(params=args)
|
||||||
assert p.peer_server == '10.10.10.10'
|
assert p.peer_server == '10.10.10.10'
|
||||||
assert p.peer_hostname == 'foo.bar.baz'
|
assert p.peer_hostname == 'foo.bar.baz'
|
||||||
assert p.peer_user == 'admin'
|
assert p.peer_user == 'admin'
|
||||||
|
@ -89,7 +91,7 @@ class TestParameters(unittest.TestCase):
|
||||||
type='peer'
|
type='peer'
|
||||||
)
|
)
|
||||||
|
|
||||||
p = Parameters(args)
|
p = Parameters(params=args)
|
||||||
assert p.peer_server == '10.10.10.10'
|
assert p.peer_server == '10.10.10.10'
|
||||||
assert p.peer_hostname == 'foo.bar.baz'
|
assert p.peer_hostname == 'foo.bar.baz'
|
||||||
assert p.peer_user == 'admin'
|
assert p.peer_user == 'admin'
|
||||||
|
@ -105,7 +107,7 @@ class TestParameters(unittest.TestCase):
|
||||||
type='subordinate'
|
type='subordinate'
|
||||||
)
|
)
|
||||||
|
|
||||||
p = Parameters(args)
|
p = Parameters(params=args)
|
||||||
assert p.peer_server == '10.10.10.10'
|
assert p.peer_server == '10.10.10.10'
|
||||||
assert p.peer_hostname == 'foo.bar.baz'
|
assert p.peer_hostname == 'foo.bar.baz'
|
||||||
assert p.peer_user == 'admin'
|
assert p.peer_user == 'admin'
|
||||||
|
@ -113,8 +115,6 @@ class TestParameters(unittest.TestCase):
|
||||||
assert p.type is False
|
assert p.type is False
|
||||||
|
|
||||||
|
|
||||||
@patch('ansible.module_utils.f5_utils.AnsibleF5Client._get_mgmt_root',
|
|
||||||
return_value=True)
|
|
||||||
class TestManager(unittest.TestCase):
|
class TestManager(unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
@ -131,15 +131,14 @@ class TestManager(unittest.TestCase):
|
||||||
user='admin'
|
user='admin'
|
||||||
))
|
))
|
||||||
|
|
||||||
client = AnsibleF5Client(
|
module = AnsibleModule(
|
||||||
argument_spec=self.spec.argument_spec,
|
argument_spec=self.spec.argument_spec,
|
||||||
supports_check_mode=self.spec.supports_check_mode,
|
supports_check_mode=self.spec.supports_check_mode
|
||||||
f5_product_name=self.spec.f5_product_name
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# Override methods in the specific type of manager
|
# Override methods in the specific type of manager
|
||||||
mm = ModuleManager(client)
|
mm = ModuleManager(module=module)
|
||||||
mm.exists = Mock(side_effect=[False, True])
|
mm.exists = Mock(return_value=False)
|
||||||
mm.create_on_device = Mock(return_value=True)
|
mm.create_on_device = Mock(return_value=True)
|
||||||
|
|
||||||
results = mm.exec_module()
|
results = mm.exec_module()
|
||||||
|
@ -157,14 +156,13 @@ class TestManager(unittest.TestCase):
|
||||||
user='admin'
|
user='admin'
|
||||||
))
|
))
|
||||||
|
|
||||||
client = AnsibleF5Client(
|
module = AnsibleModule(
|
||||||
argument_spec=self.spec.argument_spec,
|
argument_spec=self.spec.argument_spec,
|
||||||
supports_check_mode=self.spec.supports_check_mode,
|
supports_check_mode=self.spec.supports_check_mode
|
||||||
f5_product_name=self.spec.f5_product_name
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# Override methods in the specific type of manager
|
# Override methods in the specific type of manager
|
||||||
mm = ModuleManager(client)
|
mm = ModuleManager(module=module)
|
||||||
mm.exists = Mock(return_value=True)
|
mm.exists = Mock(return_value=True)
|
||||||
|
|
||||||
results = mm.exec_module()
|
results = mm.exec_module()
|
||||||
|
|
Loading…
Reference in a new issue