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

Adds variable types to docs
Refactors unit tests to remove deprecated parameters
Adds missing Return values to documentation
Removes deprecated modules unit tests
This commit is contained in:
Wojciech Wypior 2019-03-19 15:59:14 +01:00 committed by John R Barker
parent dcf40d43ea
commit e13cb29e23
34 changed files with 478 additions and 1118 deletions

View file

@ -89,19 +89,13 @@ try:
from library.module_utils.network.f5.bigip import F5RestClient
from library.module_utils.network.f5.common import F5ModuleError
from library.module_utils.network.f5.common import AnsibleF5Parameters
from library.module_utils.network.f5.common import cleanup_tokens
from library.module_utils.network.f5.common import f5_argument_spec
from library.module_utils.network.f5.common import exit_json
from library.module_utils.network.f5.common import fail_json
from library.module_utils.network.f5.common import transform_name
except ImportError:
from ansible.module_utils.network.f5.bigip import F5RestClient
from ansible.module_utils.network.f5.common import F5ModuleError
from ansible.module_utils.network.f5.common import AnsibleF5Parameters
from ansible.module_utils.network.f5.common import cleanup_tokens
from ansible.module_utils.network.f5.common import f5_argument_spec
from ansible.module_utils.network.f5.common import exit_json
from ansible.module_utils.network.f5.common import fail_json
from ansible.module_utils.network.f5.common import transform_name
@ -186,7 +180,7 @@ class Difference(object):
class ModuleManager(object):
def __init__(self, *args, **kwargs):
self.module = kwargs.get('module', None)
self.client = kwargs.get('client', None)
self.client = F5RestClient(**self.module.params)
self.want = ModuleParameters(params=self.module.params)
self.have = ApiParameters()
self.changes = UsableChanges()
@ -405,16 +399,12 @@ def main():
supports_check_mode=spec.supports_check_mode,
)
client = F5RestClient(**module.params)
try:
mm = ModuleManager(module=module, client=client)
mm = ModuleManager(module=module)
results = mm.exec_module()
cleanup_tokens(client)
exit_json(module, results, client)
module.exit_json(**results)
except F5ModuleError as ex:
cleanup_tokens(client)
fail_json(module, ex, client)
module.fail_json(msg=str(ex))
if __name__ == '__main__':

View file

@ -94,19 +94,13 @@ try:
from library.module_utils.network.f5.bigip import F5RestClient
from library.module_utils.network.f5.common import F5ModuleError
from library.module_utils.network.f5.common import AnsibleF5Parameters
from library.module_utils.network.f5.common import cleanup_tokens
from library.module_utils.network.f5.common import f5_argument_spec
from library.module_utils.network.f5.common import exit_json
from library.module_utils.network.f5.common import fail_json
from library.module_utils.network.f5.common import transform_name
except ImportError:
from ansible.module_utils.network.f5.bigip import F5RestClient
from ansible.module_utils.network.f5.common import F5ModuleError
from ansible.module_utils.network.f5.common import AnsibleF5Parameters
from ansible.module_utils.network.f5.common import cleanup_tokens
from ansible.module_utils.network.f5.common import f5_argument_spec
from ansible.module_utils.network.f5.common import exit_json
from ansible.module_utils.network.f5.common import fail_json
from ansible.module_utils.network.f5.common import transform_name
@ -225,7 +219,7 @@ class Difference(object):
class ModuleManager(object):
def __init__(self, *args, **kwargs):
self.module = kwargs.get('module', None)
self.client = kwargs.get('client', None)
self.client = F5RestClient(**self.module.params)
self.want = ModuleParameters(params=self.module.params)
self.have = ApiParameters()
self.changes = UsableChanges()
@ -448,16 +442,12 @@ def main():
supports_check_mode=spec.supports_check_mode,
)
client = F5RestClient(**module.params)
try:
mm = ModuleManager(module=module, client=client)
mm = ModuleManager(module=module)
results = mm.exec_module()
cleanup_tokens(client)
exit_json(module, results, client)
module.exit_json(**results)
except F5ModuleError as ex:
cleanup_tokens(client)
fail_json(module, ex, client)
module.fail_json(msg=str(ex))
if __name__ == '__main__':

View file

@ -213,24 +213,17 @@ try:
from library.module_utils.network.f5.bigip import F5RestClient
from library.module_utils.network.f5.common import F5ModuleError
from library.module_utils.network.f5.common import AnsibleF5Parameters
from library.module_utils.network.f5.common import cleanup_tokens
from library.module_utils.network.f5.common import fq_name
from library.module_utils.network.f5.common import f5_argument_spec
from library.module_utils.network.f5.common import transform_name
from library.module_utils.network.f5.common import exit_json
from library.module_utils.network.f5.common import fail_json
from library.module_utils.network.f5.common import is_cli
except ImportError:
from ansible.module_utils.network.f5.bigip import F5RestClient
from ansible.module_utils.network.f5.common import F5ModuleError
from ansible.module_utils.network.f5.common import AnsibleF5Parameters
from ansible.module_utils.network.f5.common import cleanup_tokens
from ansible.module_utils.network.f5.common import fq_name
from ansible.module_utils.network.f5.common import f5_argument_spec
from ansible.module_utils.network.f5.common import transform_name
from ansible.module_utils.network.f5.common import compare_dictionary
from ansible.module_utils.network.f5.common import exit_json
from ansible.module_utils.network.f5.common import fail_json
from ansible.module_utils.network.f5.common import is_cli
try:
@ -414,7 +407,7 @@ class Parameters(AnsibleF5Parameters):
class BaseManager(object):
def __init__(self, *args, **kwargs):
self.module = kwargs.get('module', None)
self.client = kwargs.get('client', None)
self.client = F5RestClient(**self.module.params)
self.want = Parameters(params=self.module.params)
self.want.update({'module': self.module})
self.changes = Parameters(module=self.module)
@ -715,18 +708,12 @@ def main():
supports_check_mode=spec.supports_check_mode
)
client = F5RestClient(**module.params)
try:
mm = ModuleManager(module=module, client=client)
mm = ModuleManager(module=module)
results = mm.exec_module()
if not is_cli(module):
cleanup_tokens(client)
module.exit_json(**results)
except F5ModuleError as e:
if not is_cli(module):
cleanup_tokens(client)
module.fail_json(msg=str(e))
except F5ModuleError as ex:
module.fail_json(msg=str(ex))
if __name__ == '__main__':

View file

@ -121,21 +121,15 @@ try:
from library.module_utils.network.f5.bigip import F5RestClient
from library.module_utils.network.f5.common import F5ModuleError
from library.module_utils.network.f5.common import AnsibleF5Parameters
from library.module_utils.network.f5.common import cleanup_tokens
from library.module_utils.network.f5.common import fq_name
from library.module_utils.network.f5.common import f5_argument_spec
from library.module_utils.network.f5.common import exit_json
from library.module_utils.network.f5.common import fail_json
from library.module_utils.network.f5.icontrol import upload_file
except ImportError:
from ansible.module_utils.network.f5.bigip import F5RestClient
from ansible.module_utils.network.f5.common import F5ModuleError
from ansible.module_utils.network.f5.common import AnsibleF5Parameters
from ansible.module_utils.network.f5.common import cleanup_tokens
from ansible.module_utils.network.f5.common import fq_name
from ansible.module_utils.network.f5.common import f5_argument_spec
from ansible.module_utils.network.f5.common import exit_json
from ansible.module_utils.network.f5.common import fail_json
from ansible.module_utils.network.f5.icontrol import upload_file
@ -153,7 +147,7 @@ class Parameters(AnsibleF5Parameters):
class ModuleManager(object):
def __init__(self, *args, **kwargs):
self.module = kwargs.get('module', None)
self.client = kwargs.get('client', None)
self.client = F5RestClient(**self.module.params)
self.want = Parameters(params=self.module.params)
self.changes = Parameters()
@ -420,15 +414,11 @@ def main():
supports_check_mode=spec.supports_check_mode
)
client = F5RestClient(**module.params)
try:
mm = ModuleManager(module=module, client=client)
mm = ModuleManager(module=module)
results = mm.exec_module()
cleanup_tokens(client)
module.exit_json(**results)
except F5ModuleError as ex:
cleanup_tokens(client)
module.fail_json(msg=str(ex))

View file

@ -25,6 +25,7 @@ options:
device_group:
description:
- The device group that you want to perform config-sync actions on.
type: str
required: True
sync_device_to_group:
description:
@ -44,8 +45,8 @@ options:
description:
- Indicates that the sync operation overwrites the configuration on
the target.
default: no
type: bool
default: no
notes:
- Requires the objectpath Python package on the host. This is as easy as
C(pip install objectpath).
@ -101,18 +102,12 @@ try:
from library.module_utils.network.f5.bigip import F5RestClient
from library.module_utils.network.f5.common import F5ModuleError
from library.module_utils.network.f5.common import AnsibleF5Parameters
from library.module_utils.network.f5.common import cleanup_tokens
from library.module_utils.network.f5.common import f5_argument_spec
from library.module_utils.network.f5.common import exit_json
from library.module_utils.network.f5.common import fail_json
except ImportError:
from ansible.module_utils.network.f5.bigip import F5RestClient
from ansible.module_utils.network.f5.common import F5ModuleError
from ansible.module_utils.network.f5.common import AnsibleF5Parameters
from ansible.module_utils.network.f5.common import cleanup_tokens
from ansible.module_utils.network.f5.common import f5_argument_spec
from ansible.module_utils.network.f5.common import exit_json
from ansible.module_utils.network.f5.common import fail_json
try:
from objectpath import Tree
@ -196,7 +191,7 @@ class Difference(object):
class ModuleManager(object):
def __init__(self, *args, **kwargs):
self.module = kwargs.get('module', None)
self.client = kwargs.get('client', None)
self.client = F5RestClient(**self.module.params)
self.want = ModuleParameters(params=self.module.params)
self.changes = UsableChanges()
@ -408,9 +403,6 @@ class ArgumentSpec(object):
self.mutually_exclusive = [
['sync_device_to_group', 'sync_most_recent_to_device']
]
self.required_one_of = [
['sync_device_to_group', 'sync_most_recent_to_device']
]
def main():
@ -423,16 +415,12 @@ def main():
required_one_of=spec.required_one_of
)
client = F5RestClient(**module.params)
try:
mm = ModuleManager(module=module, client=client)
mm = ModuleManager(module=module)
results = mm.exec_module()
cleanup_tokens(client)
exit_json(module, results, client)
module.exit_json(**results)
except F5ModuleError as ex:
cleanup_tokens(client)
fail_json(module, ex, client)
module.fail_json(msg=str(ex))
if __name__ == '__main__':

View file

@ -28,6 +28,7 @@ options:
- Take special note that the parameters supported by this module will vary depending
on the C(type) that you are configuring.
- This module only supports a subset, at this time, of the total available auth types.
type: str
choices:
- tacacs
- local
@ -40,6 +41,7 @@ options:
by specifying the C(port) key.
- If no port number is specified, the default port C(49163) is used.
- This parameter is supported by the C(tacacs) type.
type: raw
suboptions:
address:
description:
@ -57,6 +59,7 @@ options:
server.
- B(Do not) use the pound/hash sign in the secret for TACACS+ servers.
- When configuring TACACS+ auth for the first time, this value is required.
type: str
service_name:
description:
- Specifies the name of the service that the user is requesting to be
@ -67,6 +70,7 @@ options:
- When configuring this form of system authentication, this setting is required.
- Note that the majority of TACACS+ implementations are of service type C(ppp),
so try that first.
type: str
choices:
- slip
- ppp
@ -83,6 +87,7 @@ options:
or system accounting.
- Note that the majority of TACACS+ implementations are of protocol type C(ip),
so try that first.
type: str
choices:
- lcp
- ip
@ -110,6 +115,7 @@ options:
request to each server until authentication succeeds, or until the system has
sent a request to all servers in the list.
- This parameter is supported by the C(tacacs) type.
type: str
choices:
- use-first-server
- use-all-servers
@ -122,19 +128,21 @@ options:
- The state of the authentication configuration on the system.
- When C(present), guarantees that the system is configured for the specified C(type).
- When C(absent), sets the system auth source back to C(local).
default: present
type: str
choices:
- absent
- present
default: present
update_secret:
description:
- C(always) will allow to update secrets if the user chooses to do so.
- C(on_create) will only set the secret when a C(use_auth_source) is C(yes)
and TACACS+ is not currently the auth source.
default: always
type: str
choices:
- always
- on_create
default: always
extends_documentation_fragment: f5
author:
- Tim Rupp (@caphrim007)
@ -209,18 +217,12 @@ try:
from library.module_utils.network.f5.bigip import F5RestClient
from library.module_utils.network.f5.common import F5ModuleError
from library.module_utils.network.f5.common import AnsibleF5Parameters
from library.module_utils.network.f5.common import cleanup_tokens
from library.module_utils.network.f5.common import f5_argument_spec
from library.module_utils.network.f5.common import exit_json
from library.module_utils.network.f5.common import fail_json
except ImportError:
from ansible.module_utils.network.f5.bigip import F5RestClient
from ansible.module_utils.network.f5.common import F5ModuleError
from ansible.module_utils.network.f5.common import AnsibleF5Parameters
from ansible.module_utils.network.f5.common import cleanup_tokens
from ansible.module_utils.network.f5.common import f5_argument_spec
from ansible.module_utils.network.f5.common import exit_json
from ansible.module_utils.network.f5.common import fail_json
class BaseParameters(AnsibleF5Parameters):
@ -506,7 +508,7 @@ class BaseManager(object):
class LocalManager(BaseManager):
def __init__(self, *args, **kwargs):
self.module = kwargs.get('module', None)
self.client = kwargs.get('client', None)
self.client = F5RestClient(**self.module.params)
self.want = self.get_module_parameters(params=self.module.params)
self.have = self.get_api_parameters()
self.changes = self.get_usable_changes()
@ -574,7 +576,7 @@ class LocalManager(BaseManager):
class TacacsManager(BaseManager):
def __init__(self, *args, **kwargs):
self.module = kwargs.get('module', None)
self.client = kwargs.get('client', None)
self.client = F5RestClient(**self.module.params)
self.want = self.get_module_parameters(params=self.module.params)
self.have = self.get_api_parameters()
self.changes = self.get_usable_changes()
@ -719,7 +721,6 @@ class TacacsManager(BaseManager):
class ModuleManager(object):
def __init__(self, *args, **kwargs):
self.module = kwargs.get('module', None)
self.client = kwargs.get('client', None)
self.kwargs = kwargs
def exec_module(self):
@ -790,16 +791,12 @@ def main():
supports_check_mode=spec.supports_check_mode,
)
client = F5RestClient(**module.params)
try:
mm = ModuleManager(module=module, client=client)
mm = ModuleManager(module=module)
results = mm.exec_module()
cleanup_tokens(client)
exit_json(module, results, client)
module.exit_json(**results)
except F5ModuleError as ex:
cleanup_tokens(client)
fail_json(module, ex, client)
module.fail_json(msg=str(ex))
if __name__ == '__main__':

View file

@ -25,19 +25,23 @@ options:
- Specifies the LDAP servers that the system must use to obtain
authentication information. You must specify a server when you
create an LDAP configuration object.
type: list
port:
description:
- Specifies the port that the system uses for access to the remote host server.
- When configuring LDAP device authentication for the first time, if this parameter
is not specified, the default port is C(389).
type: int
remote_directory_tree:
description:
- Specifies the file location (tree) of the user authentication database on the
server.
type: str
scope:
description:
- Specifies the level of the remote Active Directory or LDAP directory that the
system should search for the user authentication.
type: str
choices:
- sub
- one
@ -52,9 +56,11 @@ options:
- Therefore, if you plan to use Active Directory or LDAP as your authentication
source and want to use referred accounts, make sure your servers perform bind
referral.
type: str
bind_password:
description:
- Specifies a password for the Active Directory or LDAP server user ID.
type: str
user_template:
description:
- Specifies the distinguished name of the user who is logging on.
@ -68,6 +74,7 @@ options:
- The system passes the associated password as the password for the bind operation.
- This field can contain only one C(%s) and cannot contain any other format
specifiers.
type: str
check_member_attr:
description:
- Checks the user's member attribute in the remote LDAP or AD group.
@ -75,6 +82,7 @@ options:
ssl:
description:
- Specifies whether the system uses an SSL port to communicate with the LDAP server.
type: str
choices:
- "yes"
- "no"
@ -83,14 +91,17 @@ options:
description:
- Specifies the name of an SSL certificate from a certificate authority (CA).
- To remove this value, use the reserved value C(none).
type: str
ssl_client_key:
description:
- Specifies the name of an SSL client key.
- To remove this value, use the reserved value C(none).
type: str
ssl_client_cert:
description:
- Specifies the name of an SSL client certificate.
- To remove this value, use the reserved value C(none).
type: str
ssl_check_peer:
description:
- Specifies whether the system checks an SSL peer, as a result of which the
@ -102,6 +113,7 @@ options:
associated with the selected directory entry.
- When configuring LDAP device authentication for the first time, if this parameter
is not specified, the default port is C(samaccountname).
type: str
fallback_to_local:
description:
- Specifies that the system uses the Local authentication method if the remote
@ -111,22 +123,25 @@ options:
description:
- When C(present), ensures the device authentication method exists.
- When C(absent), ensures the device authentication method does not exist.
default: present
type: str
choices:
- present
- absent
default: present
update_password:
description:
- C(always) will always update the C(bind_password).
- C(on_create) will only set the C(bind_password) for newly created authentication
mechanisms.
default: always
type: str
choices:
- always
- on_create
default: always
extends_documentation_fragment: f5
author:
- Tim Rupp (@caphrim007)
- Wojciech Wypior (@wojtek0806)
'''
EXAMPLES = r'''
@ -141,16 +156,76 @@ EXAMPLES = r'''
'''
RETURN = r'''
param1:
description: The new param1 value of the resource.
servers:
description: LDAP servers used by the system to obtain authentication information.
returned: changed
type: bool
sample: true
param2:
description: The new param2 value of the resource.
type: list
sample: ['192.168.1.1', '192.168.1.2']
port:
description: The port that the system uses for access to the remote LDAP server.
returned: changed
type: int
sample: 389
remote_directory_tree:
description: File location (tree) of the user authentication database on the server.
returned: changed
type: str
sample: Foo is bar
sample: "CN=Users,DC=FOOBAR,DC=LOCAL"
scope:
description: The level of the remote Active Directory or LDAP directory searched for user authentication.
returned: changed
type: str
sample: base
bind_dn:
description: The distinguished name for the Active Directory or LDAP server user ID.
returned: changed
type: str
sample: "user@foobar.local"
user_template:
description: The distinguished name of the user who is logging on.
returned: changed
type: str
sample: "uid=%s,ou=people,dc=foobar,dc=local"
check_member_attr:
description: The user's member attribute in the remote LDAP or AD group.
returned: changed
type: bool
sample: yes
ssl:
description: Specifies whether the system uses an SSL port to communicate with the LDAP server.
returned: changed
type: str
sample: start-tls
ssl_ca_cert:
description: The name of an SSL certificate from a certificate authority.
returned: changed
type: str
sample: My-Trusted-CA-Bundle.crt
ssl_client_key:
description: The name of an SSL client key.
returned: changed
type: str
sample: MyKey.key
ssl_client_cert:
description: The name of an SSL client certificate.
returned: changed
type: str
sample: MyCert.crt
ssl_check_peer:
description: Indicates if the system checks an SSL peer.
returned: changed
type: bool
sample: yes
login_ldap_attr:
description: The LDAP directory attribute containing the local user name associated with the selected directory entry.
returned: changed
type: str
sample: samaccountname
fallback_to_local:
description: Specifies that the system uses the Local authentication method as fallback
returned: changed
type: bool
sample: yes
'''
from ansible.module_utils.basic import AnsibleModule
@ -159,24 +234,18 @@ try:
from library.module_utils.network.f5.bigip import F5RestClient
from library.module_utils.network.f5.common import F5ModuleError
from library.module_utils.network.f5.common import AnsibleF5Parameters
from library.module_utils.network.f5.common import cleanup_tokens
from library.module_utils.network.f5.common import fq_name
from library.module_utils.network.f5.common import transform_name
from library.module_utils.network.f5.common import f5_argument_spec
from library.module_utils.network.f5.common import exit_json
from library.module_utils.network.f5.common import fail_json
from library.module_utils.network.f5.common import flatten_boolean
from library.module_utils.network.f5.compare import cmp_str_with_none
except ImportError:
from ansible.module_utils.network.f5.bigip import F5RestClient
from ansible.module_utils.network.f5.common import F5ModuleError
from ansible.module_utils.network.f5.common import AnsibleF5Parameters
from ansible.module_utils.network.f5.common import cleanup_tokens
from ansible.module_utils.network.f5.common import fq_name
from ansible.module_utils.network.f5.common import transform_name
from ansible.module_utils.network.f5.common import f5_argument_spec
from ansible.module_utils.network.f5.common import exit_json
from ansible.module_utils.network.f5.common import fail_json
from ansible.module_utils.network.f5.common import flatten_boolean
from ansible.module_utils.network.f5.compare import cmp_str_with_none
@ -438,7 +507,7 @@ class Difference(object):
class ModuleManager(object):
def __init__(self, *args, **kwargs):
self.module = kwargs.get('module', None)
self.client = kwargs.get('client', None)
self.client = F5RestClient(**self.module.params)
self.want = ModuleParameters(params=self.module.params)
self.have = ApiParameters()
self.changes = UsableChanges()
@ -759,16 +828,12 @@ def main():
supports_check_mode=spec.supports_check_mode,
)
client = F5RestClient(**module.params)
try:
mm = ModuleManager(module=module, client=client)
mm = ModuleManager(module=module)
results = mm.exec_module()
cleanup_tokens(client)
exit_json(module, results, client)
module.exit_json(**results)
except F5ModuleError as ex:
cleanup_tokens(client)
fail_json(module, ex, client)
module.fail_json(msg=str(ex))
if __name__ == '__main__':

View file

@ -26,14 +26,17 @@ options:
config_sync_ip:
description:
- Local IP address that the system uses for ConfigSync operations.
type: str
mirror_primary_address:
description:
- Specifies the primary IP address for the system to use to mirror
connections.
type: str
mirror_secondary_address:
description:
- Specifies the secondary IP address for the system to use to mirror
connections.
type: str
unicast_failover:
description:
- Desired addresses to use for failover operations. Options C(address)
@ -43,6 +46,7 @@ options:
is not specified, the default value C(1026) will be used. If you are
specifying the (recommended) management IP address, use 'management-ip' in
the address field.
type: list
failover_multicast:
description:
- When C(yes), ensures that the Failover Multicast configuration is enabled
@ -56,23 +60,27 @@ options:
- Interface over which the system sends multicast messages associated
with failover. When C(failover_multicast) is C(yes) and this option is
not provided, a default of C(eth0) will be used.
type: str
multicast_address:
description:
- IP address for the system to send multicast messages associated with
failover. When C(failover_multicast) is C(yes) and this option is not
provided, a default of C(224.0.0.245) will be used.
type: str
multicast_port:
description:
- Port for the system to send multicast messages associated with
failover. When C(failover_multicast) is C(yes) and this option is not
provided, a default of C(62960) will be used. This value must be between
0 and 65535.
type: int
cluster_mirroring:
description:
- Specifies whether mirroring occurs within the same cluster or between
different clusters on a multi-bladed system.
- This parameter is only supported on platforms that have multiple blades,
such as Viprion hardware. It is not supported on VE.
type: str
choices:
- between-clusters
- within-cluster
@ -144,7 +152,7 @@ multicast_address:
multicast_port:
description: The new value of the C(multicast_port) setting.
returned: changed
type: str
type: int
sample: 1026
cluster_mirroring:
description: The current cluster-mirroring setting.
@ -160,21 +168,15 @@ try:
from library.module_utils.network.f5.bigip import F5RestClient
from library.module_utils.network.f5.common import F5ModuleError
from library.module_utils.network.f5.common import AnsibleF5Parameters
from library.module_utils.network.f5.common import cleanup_tokens
from library.module_utils.network.f5.common import transform_name
from library.module_utils.network.f5.common import f5_argument_spec
from library.module_utils.network.f5.common import exit_json
from library.module_utils.network.f5.common import fail_json
from library.module_utils.network.f5.ipaddress import is_valid_ip
except ImportError:
from ansible.module_utils.network.f5.bigip import F5RestClient
from ansible.module_utils.network.f5.common import F5ModuleError
from ansible.module_utils.network.f5.common import AnsibleF5Parameters
from ansible.module_utils.network.f5.common import cleanup_tokens
from ansible.module_utils.network.f5.common import transform_name
from ansible.module_utils.network.f5.common import f5_argument_spec
from ansible.module_utils.network.f5.common import exit_json
from ansible.module_utils.network.f5.common import fail_json
from ansible.module_utils.network.f5.ipaddress import is_valid_ip
@ -489,7 +491,7 @@ class Difference(object):
class ModuleManager(object):
def __init__(self, *args, **kwargs):
self.module = kwargs.get('module', None)
self.client = kwargs.get('client', None)
self.client = F5RestClient(**self.module.params)
self.want = ModuleParameters(params=self.module.params)
self.have = ApiParameters()
self.changes = UsableChanges()
@ -704,16 +706,12 @@ def main():
required_together=spec.required_together
)
client = F5RestClient(**module.params)
try:
mm = ModuleManager(module=module, client=client)
mm = ModuleManager(module=module)
results = mm.exec_module()
cleanup_tokens(client)
exit_json(module, results, client)
module.exit_json(**results)
except F5ModuleError as ex:
cleanup_tokens(client)
fail_json(module, ex, client)
module.fail_json(msg=str(ex))
if __name__ == '__main__':

View file

@ -26,6 +26,7 @@ options:
operation each time a lookup is needed. Please note that this applies
only to Access Policy Manager features, such as ACLs, web application
rewrites, and authentication.
type: str
choices:
- enabled
- disabled
@ -34,10 +35,12 @@ options:
name_servers:
description:
- A list of name servers that the system uses to validate DNS lookups
type: list
search:
description:
- A list of domains that the system searches for local domain lookups,
to resolve local host names.
type: list
ip_version:
description:
- Specifies whether the DNS specifies IP addresses using IPv4 or IPv6.
@ -48,10 +51,11 @@ options:
description:
- The state of the variable on the system. When C(present), guarantees
that an existing variable is set to C(value).
default: present
type: str
choices:
- absent
- present
default: present
extends_documentation_fragment: f5
author:
- Tim Rupp (@caphrim007)
@ -108,21 +112,15 @@ try:
from library.module_utils.network.f5.bigip import F5RestClient
from library.module_utils.network.f5.common import F5ModuleError
from library.module_utils.network.f5.common import AnsibleF5Parameters
from library.module_utils.network.f5.common import cleanup_tokens
from library.module_utils.network.f5.common import fq_name
from library.module_utils.network.f5.common import f5_argument_spec
from library.module_utils.network.f5.common import exit_json
from library.module_utils.network.f5.common import fail_json
from library.module_utils.network.f5.common import is_empty_list
except ImportError:
from ansible.module_utils.network.f5.bigip import F5RestClient
from ansible.module_utils.network.f5.common import F5ModuleError
from ansible.module_utils.network.f5.common import AnsibleF5Parameters
from ansible.module_utils.network.f5.common import cleanup_tokens
from ansible.module_utils.network.f5.common import fq_name
from ansible.module_utils.network.f5.common import f5_argument_spec
from ansible.module_utils.network.f5.common import exit_json
from ansible.module_utils.network.f5.common import fail_json
from ansible.module_utils.network.f5.common import is_empty_list
@ -311,7 +309,7 @@ class Difference(object):
class ModuleManager(object):
def __init__(self, *args, **kwargs):
self.module = kwargs.pop('module', None)
self.client = kwargs.pop('client', None)
self.client = F5RestClient(**self.module.params)
self.want = ModuleParameters(params=self.module.params)
self.have = ApiParameters()
self.changes = UsableChanges()
@ -542,16 +540,12 @@ def main():
required_one_of=spec.required_one_of
)
client = F5RestClient(**module.params)
try:
mm = ModuleManager(module=module, client=client)
mm = ModuleManager(module=module)
results = mm.exec_module()
cleanup_tokens(client)
exit_json(module, results, client)
module.exit_json(**results)
except F5ModuleError as ex:
cleanup_tokens(client)
fail_json(module, ex, client)
module.fail_json(msg=str(ex))
if __name__ == '__main__':

View file

@ -26,6 +26,7 @@ options:
name:
description:
- Specifies the name of the device group.
type: str
required: True
type:
description:
@ -36,12 +37,14 @@ options:
- A C(sync-only) device group has no such failover. When creating a new
device group, this option will default to C(sync-only).
- This setting cannot be changed once it has been set.
type: str
choices:
- sync-failover
- sync-only
description:
description:
- Description of the device group.
type: str
auto_sync:
description:
- Indicates whether configuration synchronization occurs manually or
@ -78,10 +81,12 @@ options:
- Using incremental synchronization operations can reduce the per-device sync/load
time for configuration changes.
- This setting is relevant only when C(full_sync) is C(no).
type: int
state:
description:
- When C(state) is C(present), ensures the device group exists.
- When C(state) is C(absent), ensures that the device group is removed.
type: str
choices:
- present
- absent
@ -168,18 +173,12 @@ try:
from library.module_utils.network.f5.bigip import F5RestClient
from library.module_utils.network.f5.common import F5ModuleError
from library.module_utils.network.f5.common import AnsibleF5Parameters
from library.module_utils.network.f5.common import cleanup_tokens
from library.module_utils.network.f5.common import f5_argument_spec
from library.module_utils.network.f5.common import exit_json
from library.module_utils.network.f5.common import fail_json
except ImportError:
from ansible.module_utils.network.f5.bigip import F5RestClient
from ansible.module_utils.network.f5.common import F5ModuleError
from ansible.module_utils.network.f5.common import AnsibleF5Parameters
from ansible.module_utils.network.f5.common import cleanup_tokens
from ansible.module_utils.network.f5.common import f5_argument_spec
from ansible.module_utils.network.f5.common import exit_json
from ansible.module_utils.network.f5.common import fail_json
class Parameters(AnsibleF5Parameters):
@ -364,7 +363,7 @@ class ReportableChanges(Changes):
class ModuleManager(object):
def __init__(self, *args, **kwargs):
self.module = kwargs.get('module', None)
self.client = kwargs.get('client', None)
self.client = F5RestClient(**self.module.params)
self.want = ModuleParameters(params=self.module.params)
self.have = ApiParameters()
self.changes = UsableChanges()
@ -593,7 +592,9 @@ class ArgumentSpec(object):
name=dict(
required=True
),
max_incremental_sync_size=dict(),
max_incremental_sync_size=dict(
type='int'
),
state=dict(
default='present',
choices=['absent', 'present']
@ -613,16 +614,12 @@ def main():
supports_check_mode=spec.supports_check_mode
)
client = F5RestClient(**module.params)
try:
mm = ModuleManager(module=module, client=client)
mm = ModuleManager(module=module)
results = mm.exec_module()
cleanup_tokens(client)
exit_json(module, results, client)
module.exit_json(**results)
except F5ModuleError as ex:
cleanup_tokens(client)
fail_json(module, ex, client)
module.fail_json(msg=str(ex))
if __name__ == '__main__':

View file

@ -30,19 +30,22 @@ options:
This member must be trusted by the device already. Trusting
can be done with the C(bigip_device_trust) module and the
C(peer_hostname) option to that module.
type: str
required: True
device_group:
description:
- The device group that you want to add the member to.
type: str
required: True
state:
description:
- When C(present), ensures that the device group member exists.
- When C(absent), ensures the device group member is removed.
default: present
type: str
choices:
- present
- absent
default: present
extends_documentation_fragment: f5
author:
- Tim Rupp (@caphrim007)
@ -83,18 +86,12 @@ try:
from library.module_utils.network.f5.bigip import F5RestClient
from library.module_utils.network.f5.common import F5ModuleError
from library.module_utils.network.f5.common import AnsibleF5Parameters
from library.module_utils.network.f5.common import cleanup_tokens
from library.module_utils.network.f5.common import f5_argument_spec
from library.module_utils.network.f5.common import exit_json
from library.module_utils.network.f5.common import fail_json
except ImportError:
from ansible.module_utils.network.f5.bigip import F5RestClient
from ansible.module_utils.network.f5.common import F5ModuleError
from ansible.module_utils.network.f5.common import AnsibleF5Parameters
from ansible.module_utils.network.f5.common import cleanup_tokens
from ansible.module_utils.network.f5.common import f5_argument_spec
from ansible.module_utils.network.f5.common import exit_json
from ansible.module_utils.network.f5.common import fail_json
class Parameters(AnsibleF5Parameters):
@ -146,7 +143,7 @@ class Difference(object):
class ModuleManager(object):
def __init__(self, *args, **kwargs):
self.module = kwargs.get('module', None)
self.client = kwargs.get('client', None)
self.client = F5RestClient(**self.module.params)
self.want = Parameters(params=self.module.params)
self.have = None
self.changes = Changes()
@ -284,16 +281,12 @@ def main():
supports_check_mode=spec.supports_check_mode
)
client = F5RestClient(**module.params)
try:
mm = ModuleManager(module=module, client=client)
mm = ModuleManager(module=module)
results = mm.exec_module()
cleanup_tokens(client)
exit_json(module, results, client)
module.exit_json(**results)
except F5ModuleError as ex:
cleanup_tokens(client)
fail_json(module, ex, client)
module.fail_json(msg=str(ex))
if __name__ == '__main__':

View file

@ -28,12 +28,15 @@ options:
- To specify all addresses, use the value C(all).
- IP address can be specified, such as 172.27.1.10.
- IP rangees can be specified, such as 172.27.*.* or 172.27.0.0/255.255.0.0.
type: list
auth_name:
description:
- Sets the BIG-IP authentication realm name.
type: str
auth_pam_idle_timeout:
description:
- Sets the GUI timeout for automatic logout, in seconds.
type: int
auth_pam_validate_ip:
description:
- Sets the authPamValidateIp setting.
@ -45,6 +48,7 @@ options:
fast_cgi_timeout:
description:
- Sets the timeout of FastCGI.
type: int
hostname_lookup:
description:
- Sets whether or not to display the hostname, if possible.
@ -52,10 +56,20 @@ options:
log_level:
description:
- Sets the minimum httpd log level.
choices: ['alert', 'crit', 'debug', 'emerg', 'error', 'info', 'notice', 'warn']
type: str
choices:
- alert
- crit
- debug
- emerg
- error
- info
- notice
- warn
max_clients:
description:
- Sets the maximum number of clients that can connect to the GUI at once.
type: int
redirect_http_to_https:
description:
- Whether or not to redirect http requests to the GUI to https.
@ -63,6 +77,7 @@ options:
ssl_port:
description:
- The HTTPS port to listen on.
type: int
ssl_cipher_suite:
description:
- Specifies the ciphers that the system uses.
@ -77,6 +92,7 @@ options:
ECDHE-ECDSA-AES128-SHA256,ECDHE-ECDSA-AES256-SHA384,AES128-GCM-SHA256,
AES256-GCM-SHA384,AES128-SHA,AES256-SHA,AES128-SHA256,AES256-SHA256,
ECDHE-RSA-DES-CBC3-SHA,ECDHE-ECDSA-DES-CBC3-SHA,DES-CBC3-SHA).
type: raw
version_added: 2.6
ssl_protocols:
description:
@ -87,6 +103,7 @@ options:
recommended way to provide the cipher suite. See examples for usage.
- Use the value C(default) to set the SSL protocols to the system default.
This value is equivalent to specifying a list of C(all,-SSLv2,-SSLv3).
type: raw
version_added: 2.6
notes:
- Requires the requests Python package on the host. This is as easy as
@ -248,18 +265,12 @@ try:
from library.module_utils.network.f5.bigip import F5RestClient
from library.module_utils.network.f5.common import F5ModuleError
from library.module_utils.network.f5.common import AnsibleF5Parameters
from library.module_utils.network.f5.common import cleanup_tokens
from library.module_utils.network.f5.common import f5_argument_spec
from library.module_utils.network.f5.common import exit_json
from library.module_utils.network.f5.common import fail_json
except ImportError:
from ansible.module_utils.network.f5.bigip import F5RestClient
from ansible.module_utils.network.f5.common import F5ModuleError
from ansible.module_utils.network.f5.common import AnsibleF5Parameters
from ansible.module_utils.network.f5.common import cleanup_tokens
from ansible.module_utils.network.f5.common import f5_argument_spec
from ansible.module_utils.network.f5.common import exit_json
from ansible.module_utils.network.f5.common import fail_json
class Parameters(AnsibleF5Parameters):
@ -525,7 +536,7 @@ class Difference(object):
class ModuleManager(object):
def __init__(self, *args, **kwargs):
self.module = kwargs.get('module', None)
self.client = kwargs.get('client', None)
self.client = F5RestClient(**self.module.params)
self.want = ModuleParameters(params=self.module.params)
self.have = ApiParameters()
self.changes = UsableChanges()
@ -700,16 +711,12 @@ def main():
supports_check_mode=spec.supports_check_mode,
)
client = F5RestClient(**module.params)
try:
mm = ModuleManager(module=module, client=client)
mm = ModuleManager(module=module)
results = mm.exec_module()
cleanup_tokens(client)
exit_json(module, results, client)
module.exit_json(**results)
except F5ModuleError as ex:
cleanup_tokens(client)
fail_json(module, ex, client)
module.fail_json(msg=str(ex))
if __name__ == '__main__':

View file

@ -26,12 +26,14 @@ options:
- This parameter is required if the C(state) is equal to C(present).
- This parameter is not required when C(state) is C(absent) and will be
ignored if it is provided.
type: str
license_server:
description:
- The F5 license server to use when getting a license and validating a dossier.
- This parameter is required if the C(state) is equal to C(present).
- This parameter is not required when C(state) is C(absent) and will be
ignored if it is provided.
type: str
default: activate.f5.com
state:
description:
@ -41,11 +43,12 @@ options:
- When C(absent), removes the license on the system.
- When C(revoked), removes the license on the system and revokes its future usage
on the F5 license servers.
default: present
type: str
choices:
- absent
- present
- revoked
default: present
accept_eula:
description:
- Declares whether you accept the BIG-IP EULA or not. By default, this
@ -56,6 +59,7 @@ options:
- This parameter is not required when C(state) is C(absent) and will be
ignored if it is provided.
type: bool
default: no
extends_documentation_fragment: f5
author:
- Tim Rupp (@caphrim007)
@ -96,21 +100,15 @@ try:
from library.module_utils.network.f5.bigip import F5RestClient
from library.module_utils.network.f5.common import F5ModuleError
from library.module_utils.network.f5.common import AnsibleF5Parameters
from library.module_utils.network.f5.common import cleanup_tokens
from library.module_utils.network.f5.common import fq_name
from library.module_utils.network.f5.common import f5_argument_spec
from library.module_utils.network.f5.common import exit_json
from library.module_utils.network.f5.common import fail_json
from library.module_utils.network.f5.icontrol import iControlRestSession
except ImportError:
from ansible.module_utils.network.f5.bigip import F5RestClient
from ansible.module_utils.network.f5.common import F5ModuleError
from ansible.module_utils.network.f5.common import AnsibleF5Parameters
from ansible.module_utils.network.f5.common import cleanup_tokens
from ansible.module_utils.network.f5.common import fq_name
from ansible.module_utils.network.f5.common import f5_argument_spec
from ansible.module_utils.network.f5.common import exit_json
from ansible.module_utils.network.f5.common import fail_json
from ansible.module_utils.network.f5.icontrol import iControlRestSession
@ -341,7 +339,7 @@ class Difference(object):
class ModuleManager(object):
def __init__(self, *args, **kwargs):
self.module = kwargs.get('module', None)
self.client = kwargs.get('client', None)
self.client = F5RestClient(**self.module.params)
self.want = ModuleParameters(params=self.module.params, client=self.client)
self.have = ApiParameters(client=self.client)
self.changes = UsableChanges()
@ -875,19 +873,16 @@ def main():
module = AnsibleModule(
argument_spec=spec.argument_spec,
supports_check_mode=spec.supports_check_mode
supports_check_mode=spec.supports_check_mode,
required_if=spec.required_if
)
client = F5RestClient(**module.params)
try:
mm = ModuleManager(module=module, client=client)
mm = ModuleManager(module=module)
results = mm.exec_module()
cleanup_tokens(client)
exit_json(module, results, client)
module.exit_json(**results)
except F5ModuleError as ex:
cleanup_tokens(client)
fail_json(module, ex, client)
module.fail_json(msg=str(ex))
if __name__ == '__main__':

View file

@ -24,19 +24,22 @@ options:
description:
- A list of NTP servers to set on the device. At least one of C(ntp_servers)
or C(timezone) is required.
type: list
state:
description:
- The state of the NTP servers on the system. When C(present), guarantees
that the NTP servers are set on the system. When C(absent), removes the
specified NTP servers from the device configuration.
default: present
type: str
choices:
- absent
- present
default: present
timezone:
description:
- The timezone to set for NTP lookups. At least one of C(ntp_servers) or
C(timezone) is required.
type: str
extends_documentation_fragment: f5
author:
- Tim Rupp (@caphrim007)
@ -83,21 +86,15 @@ try:
from library.module_utils.network.f5.bigip import F5RestClient
from library.module_utils.network.f5.common import F5ModuleError
from library.module_utils.network.f5.common import AnsibleF5Parameters
from library.module_utils.network.f5.common import cleanup_tokens
from library.module_utils.network.f5.common import fq_name
from library.module_utils.network.f5.common import f5_argument_spec
from library.module_utils.network.f5.common import exit_json
from library.module_utils.network.f5.common import fail_json
from library.module_utils.network.f5.common import is_empty_list
except ImportError:
from ansible.module_utils.network.f5.bigip import F5RestClient
from ansible.module_utils.network.f5.common import F5ModuleError
from ansible.module_utils.network.f5.common import AnsibleF5Parameters
from ansible.module_utils.network.f5.common import cleanup_tokens
from ansible.module_utils.network.f5.common import fq_name
from ansible.module_utils.network.f5.common import f5_argument_spec
from ansible.module_utils.network.f5.common import exit_json
from ansible.module_utils.network.f5.common import fail_json
from ansible.module_utils.network.f5.common import is_empty_list
@ -209,7 +206,7 @@ class Difference(object):
class ModuleManager(object):
def __init__(self, *args, **kwargs):
self.module = kwargs.pop('module', None)
self.client = kwargs.pop('client', None)
self.client = F5RestClient(**self.module.params)
self.want = ModuleParameters(params=self.module.params)
self.have = ApiParameters()
self.changes = UsableChanges()
@ -391,16 +388,12 @@ def main():
required_one_of=spec.required_one_of
)
client = F5RestClient(**module.params)
try:
mm = ModuleManager(module=module, client=client)
mm = ModuleManager(module=module)
results = mm.exec_module()
cleanup_tokens(client)
exit_json(module, results, client)
module.exit_json(**results)
except F5ModuleError as ex:
cleanup_tokens(client)
fail_json(module, ex, client)
module.fail_json(msg=str(ex))
if __name__ == '__main__':

View file

@ -33,6 +33,7 @@ options:
banner:
description:
- Whether to enable the banner or not.
type: str
choices:
- enabled
- disabled
@ -40,13 +41,16 @@ options:
description:
- Specifies the text to include on the pre-login banner that displays
when a user attempts to login to the system using SSH.
type: str
inactivity_timeout:
description:
- Specifies the number of seconds before inactivity causes an SSH
session to log out.
type: int
log_level:
description:
- Specifies the minimum SSHD message level to include in the system log.
type: str
choices:
- debug
- debug1
@ -61,12 +65,14 @@ options:
description:
- Specifies, when checked C(enabled), that the system accepts SSH
communications.
type: str
choices:
- enabled
- disabled
port:
description:
- Port that you want the SSH daemon to run on.
type: int
notes:
- Requires BIG-IP version 12.0.0 or greater
extends_documentation_fragment: f5
@ -157,21 +163,15 @@ try:
from library.module_utils.network.f5.bigip import F5RestClient
from library.module_utils.network.f5.common import F5ModuleError
from library.module_utils.network.f5.common import AnsibleF5Parameters
from library.module_utils.network.f5.common import cleanup_tokens
from library.module_utils.network.f5.common import fq_name
from library.module_utils.network.f5.common import f5_argument_spec
from library.module_utils.network.f5.common import exit_json
from library.module_utils.network.f5.common import fail_json
from library.module_utils.network.f5.common import is_empty_list
except ImportError:
from ansible.module_utils.network.f5.bigip import F5RestClient
from ansible.module_utils.network.f5.common import F5ModuleError
from ansible.module_utils.network.f5.common import AnsibleF5Parameters
from ansible.module_utils.network.f5.common import cleanup_tokens
from ansible.module_utils.network.f5.common import fq_name
from ansible.module_utils.network.f5.common import f5_argument_spec
from ansible.module_utils.network.f5.common import exit_json
from ansible.module_utils.network.f5.common import fail_json
from ansible.module_utils.network.f5.common import is_empty_list
@ -288,7 +288,7 @@ class Difference(object):
class ModuleManager(object):
def __init__(self, *args, **kwargs):
self.module = kwargs.get('module', None)
self.client = kwargs.get('client', None)
self.client = F5RestClient(**self.module.params)
self.want = ModuleParameters(params=self.module.params)
self.have = ApiParameters()
self.changes = UsableChanges()
@ -428,16 +428,12 @@ def main():
supports_check_mode=spec.supports_check_mode
)
client = F5RestClient(**module.params)
try:
mm = ModuleManager(module=module, client=client)
mm = ModuleManager(module=module)
results = mm.exec_module()
cleanup_tokens(client)
exit_json(module, results, client)
module.exit_json(**results)
except F5ModuleError as ex:
cleanup_tokens(client)
fail_json(module, ex, client)
module.fail_json(msg=str(ex))
if __name__ == '__main__':

View file

@ -24,6 +24,7 @@ options:
description:
- Specifies the lowest level of messages about user authentication
to include in the system log.
type: str
choices:
- alert
- crit
@ -37,6 +38,7 @@ options:
description:
- Specifies the highest level of messages about user authentication
to include in the system log.
type: str
choices:
- alert
- crit
@ -55,6 +57,7 @@ options:
description:
- Specifies the lowest level of messages about time-based scheduling
to include in the system log.
type: str
choices:
- alert
- crit
@ -68,6 +71,7 @@ options:
description:
- Specifies the highest level of messages about time-based
scheduling to include in the system log.
type: str
choices:
- alert
- crit
@ -81,6 +85,7 @@ options:
description:
- Specifies the lowest level of messages about daemon performance to
include in the system log.
type: str
choices:
- alert
- crit
@ -94,6 +99,7 @@ options:
description:
- Specifies the highest level of messages about daemon performance
to include in the system log.
type: str
choices:
- alert
- crit
@ -106,6 +112,7 @@ options:
include:
description:
- Syslog-NG configuration to include in the device syslog config.
type: str
iso_date:
description:
- Enables or disables the ISO date format for messages in the log
@ -115,6 +122,7 @@ options:
description:
- Specifies the lowest level of kernel messages to include in the
system log.
type: str
choices:
- alert
- crit
@ -128,6 +136,7 @@ options:
description:
- Specifies the highest level of kernel messages to include in the
system log.
type: str
choices:
- alert
- crit
@ -141,6 +150,7 @@ options:
description:
- Specifies the lowest error level for messages from the local6
facility to include in the log.
type: str
choices:
- alert
- crit
@ -154,6 +164,7 @@ options:
description:
- Specifies the highest error level for messages from the local6
facility to include in the log.
type: str
choices:
- alert
- crit
@ -167,6 +178,7 @@ options:
description:
- Specifies the lowest level of mail log messages to include in the
system log.
type: str
choices:
- alert
- crit
@ -180,6 +192,7 @@ options:
description:
- Specifies the highest level of mail log messages to include in the
system log.
type: str
choices:
- alert
- crit
@ -193,6 +206,7 @@ options:
description:
- Specifies the lowest level of system messages to include in the
system log.
type: str
choices:
- alert
- crit
@ -206,6 +220,7 @@ options:
description:
- Specifies the highest level of system messages to include in the
system log.
type: str
choices:
- alert
- crit
@ -219,6 +234,7 @@ options:
description:
- Specifies the lowest level of user account messages to include in
the system log.
type: str
choices:
- alert
- crit
@ -232,6 +248,7 @@ options:
description:
- Specifies the highest level of user account messages to include in
the system log.
type: str
choices:
- alert
- crit
@ -361,22 +378,16 @@ try:
from library.module_utils.network.f5.bigip import F5RestClient
from library.module_utils.network.f5.common import F5ModuleError
from library.module_utils.network.f5.common import AnsibleF5Parameters
from library.module_utils.network.f5.common import cleanup_tokens
from library.module_utils.network.f5.common import fq_name
from library.module_utils.network.f5.common import f5_argument_spec
from library.module_utils.network.f5.common import exit_json
from library.module_utils.network.f5.common import fail_json
from library.module_utils.network.f5.common import flatten_boolean
from library.module_utils.network.f5.compare import cmp_str_with_none
except ImportError:
from ansible.module_utils.network.f5.bigip import F5RestClient
from ansible.module_utils.network.f5.common import F5ModuleError
from ansible.module_utils.network.f5.common import AnsibleF5Parameters
from ansible.module_utils.network.f5.common import cleanup_tokens
from ansible.module_utils.network.f5.common import fq_name
from ansible.module_utils.network.f5.common import f5_argument_spec
from ansible.module_utils.network.f5.common import exit_json
from ansible.module_utils.network.f5.common import fail_json
from ansible.module_utils.network.f5.common import flatten_boolean
from ansible.module_utils.network.f5.compare import cmp_str_with_none
@ -565,7 +576,7 @@ class Difference(object):
class ModuleManager(object):
def __init__(self, *args, **kwargs):
self.module = kwargs.get('module', None)
self.client = kwargs.get('client', None)
self.client = F5RestClient(**self.module.params)
self.want = ModuleParameters(params=self.module.params)
self.have = ApiParameters()
self.changes = UsableChanges()
@ -712,16 +723,12 @@ def main():
supports_check_mode=spec.supports_check_mode,
)
client = F5RestClient(**module.params)
try:
mm = ModuleManager(module=module, client=client)
mm = ModuleManager(module=module)
results = mm.exec_module()
cleanup_tokens(client)
exit_json(module, results, client)
module.exit_json(**results)
except F5ModuleError as ex:
cleanup_tokens(client)
fail_json(module, ex, client)
module.fail_json(msg=str(ex))
if __name__ == '__main__':

View file

@ -27,6 +27,7 @@ options:
- The peer address to connect to and trust for synchronizing configuration.
This is typically the management address of the remote device, but may
also be a Self IP.
type: str
required: True
peer_hostname:
description:
@ -34,17 +35,20 @@ options:
be used to easily distinguish this device in BIG-IP configuration.
- When trusting a new device, if this parameter is not specified, the value
of C(peer_server) will be used as a default.
type: str
peer_user:
description:
- The API username of the remote peer device that you are trusting. Note
that the CLI user cannot be used unless it too has an API account. If this
value is not specified, then the value of C(user), or the environment
variable C(F5_USER) will be used.
type: str
peer_password:
description:
- The password of the API username of the remote peer device that you are
trusting. If this value is not specified, then the value of C(password),
or the environment variable C(F5_PASSWORD) will be used.
type: str
type:
description:
- Specifies whether the device you are adding is a Peer or a Subordinate.
@ -58,6 +62,7 @@ options:
- Designating devices as subordinate devices is recommended for device
groups with a large number of member devices, where the risk of compromise
is high.
type: str
choices:
- peer
- subordinate
@ -66,10 +71,11 @@ options:
description:
- When C(present), ensures the specified devices are trusted.
- When C(absent), removes the device trusts.
default: present
type: str
choices:
- absent
- present
default: present
extends_documentation_fragment: f5
author:
- Tim Rupp (@caphrim007)
@ -112,14 +118,12 @@ try:
from library.module_utils.network.f5.bigip import F5RestClient
from library.module_utils.network.f5.common import F5ModuleError
from library.module_utils.network.f5.common import AnsibleF5Parameters
from library.module_utils.network.f5.common import cleanup_tokens
from library.module_utils.network.f5.common import f5_argument_spec
from library.module_utils.network.f5.ipaddress import is_valid_ip
except ImportError:
from ansible.module_utils.network.f5.bigip import F5RestClient
from ansible.module_utils.network.f5.common import F5ModuleError
from ansible.module_utils.network.f5.common import AnsibleF5Parameters
from ansible.module_utils.network.f5.common import cleanup_tokens
from ansible.module_utils.network.f5.common import f5_argument_spec
from ansible.module_utils.network.f5.ipaddress import is_valid_ip
@ -186,7 +190,7 @@ class Parameters(AnsibleF5Parameters):
class ModuleManager(object):
def __init__(self, *args, **kwargs):
self.module = kwargs.get('module', None)
self.client = kwargs.get('client', None)
self.client = F5RestClient(**self.module.params)
self.have = None
self.want = Parameters(params=self.module.params)
self.changes = Parameters()
@ -364,15 +368,11 @@ def main():
supports_check_mode=spec.supports_check_mode
)
client = F5RestClient(**module.params)
try:
mm = ModuleManager(module=module, client=client)
mm = ModuleManager(module=module)
results = mm.exec_module()
cleanup_tokens(client)
module.exit_json(**results)
except F5ModuleError as ex:
cleanup_tokens(client)
module.fail_json(msg=str(ex))

View file

@ -1,577 +0,0 @@
# -*- coding: utf-8 -*-
#
# Copyright (c) 2017 F5 Networks Inc.
# GNU General Public License v3.0 (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
import os
import json
import pytest
import sys
if sys.version_info < (2, 7):
pytestmark = pytest.mark.skip("F5 Ansible modules require Python >= 2.7")
from ansible.module_utils.basic import AnsibleModule
try:
from library.modules._bigip_asm_policy import V1Parameters
from library.modules._bigip_asm_policy import V2Parameters
from library.modules._bigip_asm_policy import ModuleManager
from library.modules._bigip_asm_policy import V1Manager
from library.modules._bigip_asm_policy import V2Manager
from library.modules._bigip_asm_policy import ArgumentSpec
from library.module_utils.network.f5.common import F5ModuleError
# In Ansible 2.8, Ansible changed import paths.
from test.units.compat import unittest
from test.units.compat.mock import Mock
from test.units.compat.mock import patch
from test.units.modules.utils import set_module_args
except ImportError:
from ansible.modules.network.f5._bigip_asm_policy import V1Parameters
from ansible.modules.network.f5._bigip_asm_policy import V2Parameters
from ansible.modules.network.f5._bigip_asm_policy import ModuleManager
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 ArgumentSpec
from ansible.module_utils.network.f5.common import F5ModuleError
# Ansible 2.8 imports
from units.compat import unittest
from units.compat.mock import Mock
from units.compat.mock import patch
from units.modules.utils import set_module_args
fixture_path = os.path.join(os.path.dirname(__file__), 'fixtures')
fixture_data = {}
def load_fixture(name):
path = os.path.join(fixture_path, name)
with open(path) as f:
data = f.read()
try:
data = json.loads(data)
except Exception:
pass
return data
class TestParameters(unittest.TestCase):
def test_module_parameters(self):
args = dict(
name='fake_policy',
state='present',
file='/var/fake/fake.xml'
)
p = V1Parameters(params=args)
assert p.name == 'fake_policy'
assert p.state == 'present'
assert p.file == '/var/fake/fake.xml'
def test_module_parameters_template(self):
args = dict(
name='fake_policy',
state='present',
template='LotusDomino 6.5 (http)'
)
p = V1Parameters(params=args)
assert p.name == 'fake_policy'
assert p.state == 'present'
assert p.template == 'POLICY_TEMPLATE_LOTUSDOMINO_6_5_HTTP'
class TestManager(unittest.TestCase):
def setUp(self):
self.spec = ArgumentSpec()
self.policy = os.path.join(fixture_path, 'fake_policy.xml')
self.patcher1 = patch('time.sleep')
self.patcher1.start()
try:
self.p1 = patch('library.modules._bigip_asm_policy.module_provisioned')
self.m1 = self.p1.start()
self.m1.return_value = True
except Exception:
self.p1 = patch('ansible.modules.network.f5._bigip_asm_policy.module_provisioned')
self.m1 = self.p1.start()
self.m1.return_value = True
def tearDown(self):
self.patcher1.stop()
self.p1.stop()
def test_activate_import_from_file(self, *args):
set_module_args(dict(
name='fake_policy',
file=self.policy,
state='present',
active='yes',
server='localhost',
password='password',
user='admin',
))
current = V1Parameters(params=load_fixture('load_asm_policy_inactive.json'))
module = AnsibleModule(
argument_spec=self.spec.argument_spec,
supports_check_mode=self.spec.supports_check_mode,
)
v1 = V1Manager(module=module)
v1.exists = Mock(return_value=False)
v1.import_to_device = Mock(return_value=True)
v1.wait_for_task = Mock(side_effect=[True, True])
v1.read_current_from_device = Mock(return_value=current)
v1.apply_on_device = Mock(return_value=True)
v1.remove_temp_policy_from_device = Mock(return_value=True)
# Override methods to force specific logic in the module to happen
mm = ModuleManager(module=module)
mm.version_is_less_than_13 = Mock(return_value=False)
mm.get_manager = Mock(return_value=v1)
results = mm.exec_module()
assert results['changed'] is True
assert results['name'] == 'fake_policy'
assert results['file'] == self.policy
assert results['active'] is True
def test_activate_import_from_template(self, *args):
set_module_args(dict(
name='fake_policy',
template='OWA Exchange 2007 (https)',
state='present',
active='yes',
server='localhost',
password='password',
user='admin',
))
current = V1Parameters(params=load_fixture('load_asm_policy_inactive.json'))
module = AnsibleModule(
argument_spec=self.spec.argument_spec,
supports_check_mode=self.spec.supports_check_mode
)
v1 = V1Manager(module=module)
v1.exists = Mock(return_value=False)
v1.import_to_device = Mock(return_value=True)
v1.wait_for_task = Mock(side_effect=[True, True])
v1.read_current_from_device = Mock(return_value=current)
v1.apply_on_device = Mock(return_value=True)
v1.create_from_template_on_device = Mock(return_value=True)
v1._file_is_missing = Mock(return_value=False)
# Override methods to force specific logic in the module to happen
mm = ModuleManager(module=module)
mm.version_is_less_than_13 = Mock(return_value=False)
mm.get_manager = Mock(return_value=v1)
results = mm.exec_module()
assert results['changed'] is True
assert results['name'] == 'fake_policy'
assert results['template'] == 'OWA Exchange 2007 (https)'
assert results['active'] is True
def test_activate_create_by_name(self, *args):
set_module_args(dict(
name='fake_policy',
state='present',
active='yes',
server='localhost',
password='password',
user='admin',
))
current = V1Parameters(params=load_fixture('load_asm_policy_inactive.json'))
module = AnsibleModule(
argument_spec=self.spec.argument_spec,
supports_check_mode=self.spec.supports_check_mode
)
v1 = V1Manager(module=module)
v1.exists = Mock(return_value=False)
v1.import_to_device = Mock(return_value=True)
v1.wait_for_task = Mock(side_effect=[True, True])
v1.create_on_device = Mock(return_value=True)
v1.create_blank = Mock(return_value=True)
v1.read_current_from_device = Mock(return_value=current)
v1.apply_on_device = Mock(return_value=True)
v1._file_is_missing = Mock(return_value=False)
# Override methods to force specific logic in the module to happen
mm = ModuleManager(module=module)
mm.version_is_less_than_13 = Mock(return_value=False)
mm.get_manager = Mock(return_value=v1)
results = mm.exec_module()
assert results['changed'] is True
assert results['name'] == 'fake_policy'
assert results['active'] is True
def test_activate_policy_exists_inactive(self, *args):
set_module_args(dict(
name='fake_policy',
state='present',
active='yes',
server='localhost',
password='password',
user='admin',
))
current = V1Parameters(params=load_fixture('load_asm_policy_inactive.json'))
module = AnsibleModule(
argument_spec=self.spec.argument_spec,
supports_check_mode=self.spec.supports_check_mode
)
v1 = V1Manager(module=module)
v1.exists = Mock(return_value=True)
v1.update_on_device = Mock(return_value=True)
v1.wait_for_task = Mock(side_effect=[True, True])
v1.read_current_from_device = Mock(return_value=current)
v1.apply_on_device = Mock(return_value=True)
# Override methods to force specific logic in the module to happen
mm = ModuleManager(module=module)
mm.version_is_less_than_13 = Mock(return_value=False)
mm.get_manager = Mock(return_value=v1)
results = mm.exec_module()
assert results['changed'] is True
assert results['active'] is True
def test_activate_policy_exists_active(self, *args):
set_module_args(dict(
name='fake_policy',
state='present',
active='yes',
server='localhost',
password='password',
user='admin',
))
current = V1Parameters(params=load_fixture('load_asm_policy_active.json'))
module = AnsibleModule(
argument_spec=self.spec.argument_spec,
supports_check_mode=self.spec.supports_check_mode
)
# Override methods to force specific logic in the module to happen
v1 = V1Manager(module=module)
v1.exists = Mock(return_value=True)
v1.read_current_from_device = Mock(return_value=current)
# Override methods to force specific logic in the module to happen
mm = ModuleManager(module=module)
mm.version_is_less_than_13 = Mock(return_value=False)
mm.get_manager = Mock(return_value=v1)
results = mm.exec_module()
assert results['changed'] is False
def test_deactivate_policy_exists_active(self, *args):
set_module_args(dict(
name='fake_policy',
state='present',
server='localhost',
password='password',
user='admin',
active='no'
))
current = V1Parameters(params=load_fixture('load_asm_policy_active.json'))
module = AnsibleModule(
argument_spec=self.spec.argument_spec,
supports_check_mode=self.spec.supports_check_mode
)
# Override methods to force specific logic in the module to happen
v1 = V1Manager(module=module)
v1.exists = Mock(return_value=True)
v1.read_current_from_device = Mock(return_value=current)
v1.update_on_device = Mock(return_value=True)
# Override methods to force specific logic in the module to happen
mm = ModuleManager(module=module)
mm.version_is_less_than_13 = Mock(return_value=False)
mm.get_manager = Mock(return_value=v1)
results = mm.exec_module()
assert results['changed'] is True
assert results['active'] is False
def test_deactivate_policy_exists_inactive(self, *args):
set_module_args(dict(
name='fake_policy',
state='present',
server='localhost',
password='password',
user='admin',
active='no'
))
current = V1Parameters(params=load_fixture('load_asm_policy_inactive.json'))
module = AnsibleModule(
argument_spec=self.spec.argument_spec,
supports_check_mode=self.spec.supports_check_mode
)
# Override methods to force specific logic in the module to happen
v1 = V1Manager(module=module)
v1.exists = Mock(return_value=True)
v1.read_current_from_device = Mock(return_value=current)
# Override methods to force specific logic in the module to happen
mm = ModuleManager(module=module)
mm.version_is_less_than_13 = Mock(return_value=False)
mm.get_manager = Mock(return_value=v1)
results = mm.exec_module()
assert results['changed'] is False
def test_import_from_file(self, *args):
set_module_args(dict(
name='fake_policy',
file=self.policy,
state='present',
server='localhost',
password='password',
user='admin',
))
current = V1Parameters(params=load_fixture('load_asm_policy_inactive.json'))
module = AnsibleModule(
argument_spec=self.spec.argument_spec,
supports_check_mode=self.spec.supports_check_mode
)
# Override methods to force specific logic in the module to happen
v1 = V1Manager(module=module)
v1.exists = Mock(return_value=False)
v1.import_to_device = Mock(return_value=True)
v1.wait_for_task = Mock(side_effect=[True, True])
v1.read_current_from_device = Mock(return_value=current)
v1.remove_temp_policy_from_device = Mock(return_value=True)
# Override methods to force specific logic in the module to happen
mm = ModuleManager(module=module)
mm.version_is_less_than_13 = Mock(return_value=False)
mm.get_manager = Mock(return_value=v1)
results = mm.exec_module()
assert results['changed'] is True
assert results['name'] == 'fake_policy'
assert results['file'] == self.policy
assert results['active'] is False
def test_import_from_template(self, *args):
set_module_args(dict(
name='fake_policy',
template='LotusDomino 6.5 (http)',
state='present',
server='localhost',
password='password',
user='admin',
))
current = V1Parameters(params=load_fixture('load_asm_policy_inactive.json'))
module = AnsibleModule(
argument_spec=self.spec.argument_spec,
supports_check_mode=self.spec.supports_check_mode
)
# Override methods to force specific logic in the module to happen
v1 = V1Manager(module=module)
v1.exists = Mock(return_value=False)
v1.create_from_template_on_device = Mock(return_value=True)
v1.wait_for_task = Mock(side_effect=[True, True])
v1.read_current_from_device = Mock(return_value=current)
v1._file_is_missing = Mock(return_value=False)
# Override methods to force specific logic in the module to happen
mm = ModuleManager(module=module)
mm.version_is_less_than_13 = Mock(return_value=False)
mm.get_manager = Mock(return_value=v1)
results = mm.exec_module()
assert results['changed'] is True
assert results['name'] == 'fake_policy'
assert results['template'] == 'LotusDomino 6.5 (http)'
assert results['active'] is False
def test_create_by_name(self, *args):
set_module_args(dict(
name='fake_policy',
state='present',
server='localhost',
password='password',
user='admin',
))
current = V1Parameters(params=load_fixture('load_asm_policy_inactive.json'))
module = AnsibleModule(
argument_spec=self.spec.argument_spec,
supports_check_mode=self.spec.supports_check_mode
)
v1 = V1Manager(module=module)
v1.exists = Mock(return_value=False)
v1.import_to_device = Mock(return_value=True)
v1.wait_for_task = Mock(side_effect=[True, True])
v1.create_on_device = Mock(return_value=True)
v1.create_blank = Mock(return_value=True)
v1.read_current_from_device = Mock(return_value=current)
v1.apply_on_device = Mock(return_value=True)
v1._file_is_missing = Mock(return_value=False)
# Override methods to force specific logic in the module to happen
mm = ModuleManager(module=module)
mm.version_is_less_than_13 = Mock(return_value=False)
mm.get_manager = Mock(return_value=v1)
results = mm.exec_module()
assert results['changed'] is True
assert results['name'] == 'fake_policy'
assert results['active'] is False
def test_delete_policy(self, *args):
set_module_args(dict(
name='fake_policy',
state='absent',
server='localhost',
password='password',
user='admin',
))
module = AnsibleModule(
argument_spec=self.spec.argument_spec,
supports_check_mode=self.spec.supports_check_mode
)
# Override methods to force specific logic in the module to happen
v1 = V1Manager(module=module)
v1.exists = Mock(side_effect=[True, False])
v1.remove_from_device = Mock(return_value=True)
# Override methods to force specific logic in the module to happen
mm = ModuleManager(module=module)
mm.version_is_less_than_13 = Mock(return_value=False)
mm.get_manager = Mock(return_value=v1)
results = mm.exec_module()
assert results['changed'] is True
def test_activate_policy_raises(self, *args):
set_module_args(dict(
name='fake_policy',
state='present',
active='yes',
server='localhost',
password='password',
user='admin',
))
current = V1Parameters(params=load_fixture('load_asm_policy_inactive.json'))
module = AnsibleModule(
argument_spec=self.spec.argument_spec,
supports_check_mode=self.spec.supports_check_mode
)
msg = 'Apply policy task failed.'
# Override methods to force specific logic in the module to happen
v1 = V1Manager(module=module)
v1.exists = Mock(return_value=True)
v1.wait_for_task = Mock(return_value=False)
v1.update_on_device = Mock(return_value=True)
v1.read_current_from_device = Mock(return_value=current)
v1.apply_on_device = Mock(return_value=True)
# Override methods to force specific logic in the module to happen
mm = ModuleManager(module=module)
mm.version_is_less_than_13 = Mock(return_value=False)
mm.get_manager = Mock(return_value=v1)
with pytest.raises(F5ModuleError) as err:
mm.exec_module()
assert str(err.value) == msg
def test_create_policy_raises(self, *args):
set_module_args(dict(
name='fake_policy',
state='present',
server='localhost',
password='password',
user='admin',
))
module = AnsibleModule(
argument_spec=self.spec.argument_spec,
supports_check_mode=self.spec.supports_check_mode
)
msg = 'Failed to create ASM policy: fake_policy'
# Override methods to force specific logic in the module to happen
v1 = V1Manager(module=module)
v1.exists = Mock(return_value=False)
v1.create_on_device = Mock(return_value=False)
v1._file_is_missing = Mock(return_value=False)
# Override methods to force specific logic in the module to happen
mm = ModuleManager(module=module)
mm.version_is_less_than_13 = Mock(return_value=False)
mm.get_manager = Mock(return_value=v1)
with pytest.raises(F5ModuleError) as err:
mm.exec_module()
assert str(err.value) == msg
def test_delete_policy_raises(self, *args):
set_module_args(dict(
name='fake_policy',
state='absent',
server='localhost',
password='password',
user='admin',
))
module = AnsibleModule(
argument_spec=self.spec.argument_spec,
supports_check_mode=self.spec.supports_check_mode
)
msg = 'Failed to delete ASM policy: fake_policy'
# Override methods to force specific logic in the module to happen
v1 = V1Manager(module=module)
v1.exists = Mock(side_effect=[True, True])
v1.remove_from_device = Mock(return_value=True)
# Override methods to force specific logic in the module to happen
mm = ModuleManager(module=module)
mm.version_is_less_than_13 = Mock(return_value=False)
mm.get_manager = Mock(return_value=v1)
with pytest.raises(F5ModuleError) as err:
mm.exec_module()
assert str(err.value) == msg

View file

@ -98,9 +98,11 @@ class TestManager(unittest.TestCase):
description='another description',
scope='shared',
state="present",
server='localhost',
user='admin',
password='password'
provider=dict(
server='localhost',
password='password',
user='admin'
)
)
)

View file

@ -94,9 +94,11 @@ class TestManager(unittest.TestCase):
set_module_args(dict(
name='foo',
content='asdasds',
server='localhost',
password='password',
user='admin'
provider=dict(
server='localhost',
password='password',
user='admin'
)
))
module = AnsibleModule(

View file

@ -66,9 +66,6 @@ class TestParameters(unittest.TestCase):
commands=[
"tmsh show sys version"
],
server='localhost',
user='admin',
password='password'
)
p = Parameters(params=args)
assert len(p.commands) == 1
@ -89,9 +86,11 @@ class TestManager(unittest.TestCase):
commands=[
"tmsh show sys version"
],
server='localhost',
user='admin',
password='password'
provider=dict(
server='localhost',
password='password',
user='admin'
)
))
module = AnsibleModule(
@ -117,9 +116,11 @@ class TestManager(unittest.TestCase):
commands=[
"tmsh create ltm virtual foo"
],
server='localhost',
user='admin',
password='password'
provider=dict(
server='localhost',
password='password',
user='admin'
)
))
module = AnsibleModule(
@ -145,10 +146,12 @@ class TestManager(unittest.TestCase):
commands=[
"show sys version"
],
server='localhost',
user='admin',
password='password',
transport='cli'
provider=dict(
server='localhost',
password='password',
user='admin',
transport='cli'
)
))
module = AnsibleModule(
@ -186,9 +189,11 @@ class TestManager(unittest.TestCase):
enabled search-base-dn cn=users,dc=domain,dc=com servers add {
ldap.server.com } }
""",
server='localhost',
user='admin',
password='password'
provider=dict(
server='localhost',
password='password',
user='admin'
)
))
module = AnsibleModule(
argument_spec=self.spec.argument_spec,

View file

@ -69,9 +69,6 @@ class TestParameters(unittest.TestCase):
reset='yes',
merge_content='asdasd',
verify='no',
server='localhost',
user='admin',
password='password'
)
p = Parameters(params=args)
assert p.save == 'yes'
@ -90,9 +87,11 @@ class TestManager(unittest.TestCase):
reset='yes',
merge_content='asdasd',
verify='no',
server='localhost',
user='admin',
password='password'
provider=dict(
server='localhost',
password='password',
user='admin'
)
))
module = AnsibleModule(

View file

@ -104,14 +104,18 @@ class TestManager(unittest.TestCase):
set_module_args(dict(
sync_device_to_group='yes',
device_group="foo",
password='password',
server='localhost',
user='admin'
provider=dict(
server='localhost',
password='password',
user='admin'
)
))
module = AnsibleModule(
argument_spec=self.spec.argument_spec,
supports_check_mode=self.spec.supports_check_mode
supports_check_mode=self.spec.supports_check_mode,
mutually_exclusive=self.spec.mutually_exclusive,
required_one_of=self.spec.required_one_of
)
mm = ModuleManager(module=module)

View file

@ -1,134 +0,0 @@
# -*- coding: utf-8 -*-
#
# Copyright 2017 F5 Networks Inc.
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
import os
import json
import sys
from nose.plugins.skip import SkipTest
if sys.version_info < (2, 7):
raise SkipTest("F5 Ansible modules require Python >= 2.7")
from units.compat import unittest
from units.compat.mock import patch, Mock
from ansible.module_utils.f5_utils import AnsibleF5Client
from units.modules.utils import set_module_args
try:
from library.bigip_configsync_actions import Parameters
from library.bigip_configsync_actions import ModuleManager
from library.bigip_configsync_actions import ArgumentSpec
except ImportError:
try:
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 ArgumentSpec
except ImportError:
raise SkipTest("F5 Ansible modules require the f5-sdk Python library")
fixture_path = os.path.join(os.path.dirname(__file__), 'fixtures')
fixture_data = {}
def load_fixture(name):
path = os.path.join(fixture_path, name)
if path in fixture_data:
return fixture_data[path]
with open(path) as f:
data = f.read()
try:
data = json.loads(data)
except Exception:
pass
fixture_data[path] = data
return data
class TestParameters(unittest.TestCase):
def test_module_parameters(self):
args = dict(
sync_device_to_group=True,
sync_group_to_device=True,
overwrite_config=True,
device_group="foo"
)
p = Parameters(args)
assert p.sync_device_to_group is True
assert p.sync_group_to_device is True
assert p.overwrite_config is True
assert p.device_group == 'foo'
def test_module_parameters_yes_no(self):
args = dict(
sync_device_to_group='yes',
sync_group_to_device='no',
overwrite_config='yes',
device_group="foo"
)
p = Parameters(args)
assert p.sync_device_to_group is True
assert p.sync_group_to_device is False
assert p.overwrite_config is True
assert p.device_group == 'foo'
@patch('ansible.module_utils.f5_utils.AnsibleF5Client._get_mgmt_root',
return_value=True)
class TestManager(unittest.TestCase):
def setUp(self):
self.spec = ArgumentSpec()
def test_update_agent_status_traps(self, *args):
set_module_args(dict(
sync_device_to_group='yes',
device_group="foo",
password='passsword',
server='localhost',
user='admin'
))
client = AnsibleF5Client(
argument_spec=self.spec.argument_spec,
supports_check_mode=self.spec.supports_check_mode,
f5_product_name=self.spec.f5_product_name
)
mm = ModuleManager(client)
# Override methods to force specific logic in the module to happen
mm._device_group_exists = Mock(return_value=True)
mm._sync_to_group_required = Mock(return_value=False)
mm.execute_on_device = Mock(return_value=True)
mm.read_current_from_device = Mock(return_value=None)
mm._get_status_from_resource = Mock()
mm._get_status_from_resource.side_effect = [
'Changes Pending', 'Awaiting Initial Sync', 'In Sync'
]
results = mm.exec_module()
assert results['changed'] is True

View file

@ -85,9 +85,6 @@ class TestParameters(unittest.TestCase):
mirror_secondary_address='5.6.7.8',
config_sync_ip='4.3.2.1',
state='present',
server='localhost',
user='admin',
password='password'
)
p = ModuleParameters(params=args)
assert p.multicast_port == 1010
@ -141,9 +138,11 @@ class TestManager(unittest.TestCase):
address="10.1.30.1"
)
],
server='localhost',
user='admin',
password='password'
provider=dict(
server='localhost',
password='password',
user='admin'
)
))
# Configure the parameters that would be returned by querying the
@ -152,7 +151,8 @@ class TestManager(unittest.TestCase):
module = AnsibleModule(
argument_spec=self.spec.argument_spec,
supports_check_mode=self.spec.supports_check_mode
supports_check_mode=self.spec.supports_check_mode,
required_together=self.spec.required_together
)
mm = ModuleManager(module=module)
@ -170,9 +170,11 @@ class TestManager(unittest.TestCase):
def test_set_primary_mirror_address_none(self, *args):
set_module_args(dict(
mirror_primary_address="none",
server='localhost',
user='admin',
password='password'
provider=dict(
server='localhost',
password='password',
user='admin'
)
))
# Configure the parameters that would be returned by querying the
@ -181,7 +183,8 @@ class TestManager(unittest.TestCase):
module = AnsibleModule(
argument_spec=self.spec.argument_spec,
supports_check_mode=self.spec.supports_check_mode
supports_check_mode=self.spec.supports_check_mode,
required_together=self.spec.required_together
)
mm = ModuleManager(module=module)
@ -198,9 +201,11 @@ class TestManager(unittest.TestCase):
def test_set_secondary_mirror_address_none(self, *args):
set_module_args(dict(
mirror_secondary_address="none",
server='localhost',
user='admin',
password='password'
provider=dict(
server='localhost',
password='password',
user='admin'
)
))
# Configure the parameters that would be returned by querying the
@ -209,7 +214,8 @@ class TestManager(unittest.TestCase):
module = AnsibleModule(
argument_spec=self.spec.argument_spec,
supports_check_mode=self.spec.supports_check_mode
supports_check_mode=self.spec.supports_check_mode,
required_together=self.spec.required_together
)
mm = ModuleManager(module=module)
@ -226,9 +232,13 @@ class TestManager(unittest.TestCase):
def test_set_multicast_address_none(self, *args):
set_module_args(dict(
multicast_address="none",
server='localhost',
user='admin',
password='password'
multicast_port=62960,
multicast_interface="eth0",
provider=dict(
server='localhost',
password='password',
user='admin'
)
))
# Configure the parameters that would be returned by querying the
@ -237,7 +247,8 @@ class TestManager(unittest.TestCase):
module = AnsibleModule(
argument_spec=self.spec.argument_spec,
supports_check_mode=self.spec.supports_check_mode
supports_check_mode=self.spec.supports_check_mode,
required_together=self.spec.required_together
)
mm = ModuleManager(module=module)
@ -254,9 +265,13 @@ class TestManager(unittest.TestCase):
def test_set_multicast_port_negative(self, *args):
set_module_args(dict(
multicast_port=-1,
server='localhost',
user='admin',
password='password'
multicast_address="224.0.0.245",
multicast_interface="eth0",
provider=dict(
server='localhost',
password='password',
user='admin'
)
))
# Configure the parameters that would be returned by querying the
@ -265,7 +280,8 @@ class TestManager(unittest.TestCase):
module = AnsibleModule(
argument_spec=self.spec.argument_spec,
supports_check_mode=self.spec.supports_check_mode
supports_check_mode=self.spec.supports_check_mode,
required_together=self.spec.required_together
)
mm = ModuleManager(module=module)
@ -281,9 +297,13 @@ class TestManager(unittest.TestCase):
def test_set_multicast_address(self, *args):
set_module_args(dict(
multicast_address="10.1.1.1",
server='localhost',
user='admin',
password='password'
multicast_port=62960,
multicast_interface="eth0",
provider=dict(
server='localhost',
password='password',
user='admin'
)
))
# Configure the parameters that would be returned by querying the
@ -292,7 +312,8 @@ class TestManager(unittest.TestCase):
module = AnsibleModule(
argument_spec=self.spec.argument_spec,
supports_check_mode=self.spec.supports_check_mode
supports_check_mode=self.spec.supports_check_mode,
required_together=self.spec.required_together
)
mm = ModuleManager(module=module)
@ -309,9 +330,11 @@ class TestManager(unittest.TestCase):
def test_unset_unicast_failover(self, *args):
set_module_args(dict(
unicast_failover="none",
server='localhost',
user='admin',
password='password'
provider=dict(
server='localhost',
password='password',
user='admin'
)
))
# Configure the parameters that would be returned by querying the
@ -320,7 +343,8 @@ class TestManager(unittest.TestCase):
module = AnsibleModule(
argument_spec=self.spec.argument_spec,
supports_check_mode=self.spec.supports_check_mode
supports_check_mode=self.spec.supports_check_mode,
required_together=self.spec.required_together
)
mm = ModuleManager(module=module)
@ -337,9 +361,11 @@ class TestManager(unittest.TestCase):
def test_unset_config_sync_ip(self, *args):
set_module_args(dict(
config_sync_ip="none",
server='localhost',
user='admin',
password='password'
provider=dict(
server='localhost',
password='password',
user='admin'
)
))
# Configure the parameters that would be returned by querying the
@ -348,7 +374,8 @@ class TestManager(unittest.TestCase):
module = AnsibleModule(
argument_spec=self.spec.argument_spec,
supports_check_mode=self.spec.supports_check_mode
supports_check_mode=self.spec.supports_check_mode,
required_together=self.spec.required_together
)
mm = ModuleManager(module=module)

View file

@ -69,9 +69,6 @@ class TestParameters(unittest.TestCase):
ip_version=4,
name_servers=['10.10.10.10', '11.11.11.11'],
search=['14.14.14.14', '15.15.15.15'],
server='localhost',
user='admin',
password='password'
)
p = Parameters(params=args)
assert p.cache == 'disable'
@ -100,9 +97,11 @@ class TestManager(unittest.TestCase):
ip_version=4,
name_servers=['10.10.10.10', '11.11.11.11'],
search=['14.14.14.14', '15.15.15.15'],
server='localhost',
user='admin',
password='password'
provider=dict(
server='localhost',
password='password',
user='admin'
)
))
# Configure the parameters that would be returned by querying the
@ -115,7 +114,8 @@ class TestManager(unittest.TestCase):
module = AnsibleModule(
argument_spec=self.spec.argument_spec,
supports_check_mode=self.spec.supports_check_mode
supports_check_mode=self.spec.supports_check_mode,
required_one_of=self.spec.required_one_of
)
mm = ModuleManager(module=module)

View file

@ -110,9 +110,11 @@ class TestModuleManager(unittest.TestCase):
dict(
name="foo-group",
state="present",
server='localhost',
user='admin',
password='password'
provider=dict(
server='localhost',
password='password',
user='admin'
)
)
)
@ -135,9 +137,11 @@ class TestModuleManager(unittest.TestCase):
full_sync=True,
name="foo-group",
state="present",
server='localhost',
user='admin',
password='password'
provider=dict(
server='localhost',
password='password',
user='admin'
)
)
)
@ -161,9 +165,11 @@ class TestModuleManager(unittest.TestCase):
dict(
name="foo-group",
state="absent",
server='localhost',
user='admin',
password='password'
provider=dict(
server='localhost',
password='password',
user='admin'
)
)
)

View file

@ -84,9 +84,11 @@ class TestManager(unittest.TestCase):
name="bigip1",
device_group="dg1",
state="present",
server='localhost',
user='admin',
password='password'
provider=dict(
server='localhost',
password='password',
user='admin'
)
)
)

View file

@ -105,9 +105,11 @@ class TestModuleManager(unittest.TestCase):
max_clients='20',
redirect_http_to_https='yes',
ssl_port=8443,
server='localhost',
user='admin',
password='password'
provider=dict(
server='localhost',
password='password',
user='admin'
)
)
)
@ -130,9 +132,11 @@ class TestModuleManager(unittest.TestCase):
set_module_args(
dict(
ssl_cipher_suite='ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384',
server='localhost',
user='admin',
password='password'
provider=dict(
server='localhost',
password='password',
user='admin'
)
)
)
@ -159,9 +163,11 @@ class TestModuleManager(unittest.TestCase):
'ECDHE-RSA-AES128-GCM-SHA256',
'ECDHE-RSA-AES256-GCM-SHA384'
],
server='localhost',
user='admin',
password='password'
provider=dict(
server='localhost',
password='password',
user='admin'
)
)
)
@ -185,9 +191,11 @@ class TestModuleManager(unittest.TestCase):
set_module_args(
dict(
ssl_cipher_suite='default',
server='localhost',
user='admin',
password='password'
provider=dict(
server='localhost',
password='password',
user='admin'
)
)
)
@ -211,9 +219,11 @@ class TestModuleManager(unittest.TestCase):
set_module_args(
dict(
ssl_protocols='all -SSLv2',
server='localhost',
user='admin',
password='password'
provider=dict(
server='localhost',
password='password',
user='admin'
)
)
)
@ -240,9 +250,11 @@ class TestModuleManager(unittest.TestCase):
'all',
'-SSLv2'
],
server='localhost',
user='admin',
password='password'
provider=dict(
server='localhost',
password='password',
user='admin'
)
)
)
@ -266,9 +278,11 @@ class TestModuleManager(unittest.TestCase):
set_module_args(
dict(
ssl_protocols='default',
server='localhost',
user='admin',
password='password'
provider=dict(
server='localhost',
password='password',
user='admin'
)
)
)

View file

@ -94,15 +94,18 @@ class TestModuleManager(unittest.TestCase):
license_key='xxxx-yyyy-zzzz',
license_server='foo-license.f5.com',
accept_eula=True,
server='localhost',
user='admin',
password='password'
provider=dict(
server='localhost',
password='password',
user='admin'
)
)
)
module = AnsibleModule(
argument_spec=self.spec.argument_spec,
supports_check_mode=self.spec.supports_check_mode
supports_check_mode=self.spec.supports_check_mode,
required_if=self.spec.required_if
)
mm = ModuleManager(module=module)

View file

@ -96,9 +96,11 @@ class TestModuleManager(unittest.TestCase):
set_module_args(
dict(
ntp_servers=ntp,
server='localhost',
user='admin',
password='password'
provider=dict(
server='localhost',
password='password',
user='admin'
)
)
)
@ -108,7 +110,8 @@ class TestModuleManager(unittest.TestCase):
module = AnsibleModule(
argument_spec=self.spec.argument_spec,
supports_check_mode=self.spec.supports_check_mode
supports_check_mode=self.spec.supports_check_mode,
required_one_of=self.spec.required_one_of
)
mm = ModuleManager(module=module)
@ -124,9 +127,11 @@ class TestModuleManager(unittest.TestCase):
set_module_args(
dict(
timezone='Arctic/Longyearbyen',
server='localhost',
user='admin',
password='password'
provider=dict(
server='localhost',
password='password',
user='admin'
)
)
)
@ -136,7 +141,8 @@ class TestModuleManager(unittest.TestCase):
module = AnsibleModule(
argument_spec=self.spec.argument_spec,
supports_check_mode=self.spec.supports_check_mode
supports_check_mode=self.spec.supports_check_mode,
required_one_of=self.spec.required_one_of
)
mm = ModuleManager(module=module)
@ -154,9 +160,11 @@ class TestModuleManager(unittest.TestCase):
dict(
ntp_servers=ntp,
timezone='Arctic/Longyearbyen',
server='localhost',
user='admin',
password='password'
provider=dict(
server='localhost',
password='password',
user='admin'
)
)
)
@ -166,7 +174,8 @@ class TestModuleManager(unittest.TestCase):
module = AnsibleModule(
argument_spec=self.spec.argument_spec,
supports_check_mode=self.spec.supports_check_mode
supports_check_mode=self.spec.supports_check_mode,
required_one_of=self.spec.required_one_of
)
mm = ModuleManager(module=module)
@ -185,10 +194,12 @@ class TestModuleManager(unittest.TestCase):
dict(
ntp_servers=ntp,
timezone='America/Los_Angeles',
server='localhost',
user='admin',
password='password',
state='absent'
state='absent',
provider=dict(
server='localhost',
password='password',
user='admin'
)
)
)
@ -198,7 +209,8 @@ class TestModuleManager(unittest.TestCase):
module = AnsibleModule(
argument_spec=self.spec.argument_spec,
supports_check_mode=self.spec.supports_check_mode
supports_check_mode=self.spec.supports_check_mode,
required_one_of=self.spec.required_one_of
)
mm = ModuleManager(module=module)
@ -215,10 +227,12 @@ class TestModuleManager(unittest.TestCase):
set_module_args(
dict(
timezone='',
server='localhost',
user='admin',
password='password',
state='absent'
state='absent',
provider=dict(
server='localhost',
password='password',
user='admin'
)
)
)
@ -228,7 +242,8 @@ class TestModuleManager(unittest.TestCase):
module = AnsibleModule(
argument_spec=self.spec.argument_spec,
supports_check_mode=self.spec.supports_check_mode
supports_check_mode=self.spec.supports_check_mode,
required_one_of=self.spec.required_one_of
)
mm = ModuleManager(module=module)

View file

@ -74,9 +74,6 @@ class TestParameters(unittest.TestCase):
log_level='debug',
login='enabled',
port=1010,
server='localhost',
user='admin',
password='password'
)
p = ModuleParameters(params=args)
assert p.allow == ['all']
@ -102,9 +99,11 @@ class TestManager(unittest.TestCase):
log_level='debug',
login='enabled',
port=1010,
server='localhost',
user='admin',
password='password'
provider=dict(
server='localhost',
password='password',
user='admin'
)
))
# Configure the parameters that would be returned by querying the

View file

@ -89,9 +89,11 @@ class TestUntypedManager(unittest.TestCase):
set_module_args(dict(
kern_from='emerg',
kern_to='debug',
password='password',
server='localhost',
user='admin'
provider=dict(
server='localhost',
password='password',
user='admin'
)
))
module = AnsibleModule(

View file

@ -137,9 +137,11 @@ class TestManager(unittest.TestCase):
peer_hostname='foo.bar.baz',
peer_user='admin',
peer_password='secret',
server='localhost',
password='password',
user='admin'
provider=dict(
server='localhost',
password='password',
user='admin'
)
))
module = AnsibleModule(
@ -162,9 +164,11 @@ class TestManager(unittest.TestCase):
peer_hostname='foo.bar.baz',
peer_user='admin',
peer_password='secret',
server='localhost',
password='password',
user='admin'
provider=dict(
server='localhost',
password='password',
user='admin'
)
))
module = AnsibleModule(