diff --git a/lib/ansible/module_utils/f5.py b/lib/ansible/module_utils/f5_utils.py
similarity index 63%
rename from lib/ansible/module_utils/f5.py
rename to lib/ansible/module_utils/f5_utils.py
index 74e8b34937..0945b69f64 100644
--- a/lib/ansible/module_utils/f5.py
+++ b/lib/ansible/module_utils/f5_utils.py
@@ -1,32 +1,23 @@
-# -*- coding: utf-8 -*-
+#
+# Copyright 2016 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 .
-# This code is part of Ansible, but is an independent component.
-# This particular file snippet, and this file snippet only, is BSD licensed.
-# Modules you write using this snippet, which is embedded dynamically by Ansible
-# still belong to the author of the module, and may assign their own license
-# to the complete work.
-#
-# Copyright (c), Etienne Carrière ,2015
-# All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without modification,
-# are permitted provided that the following conditions are met:
-#
-# * Redistributions of source code must retain the above copyright
-# notice, this list of conditions and the following disclaimer.
-# * Redistributions in binary form must reproduce the above copyright notice,
-# this list of conditions and the following disclaimer in the documentation
-# and/or other materials provided with the distribution.
-#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-# IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
-# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
-# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+# Legacy
try:
import bigsuds
@@ -35,16 +26,6 @@ except ImportError:
bigsuds_found = False
-try:
- from f5.bigip import ManagementRoot as BigIpMgmt
- from f5.bigiq import ManagementRoot as BigIqMgmt
- from f5.iworkflow import ManagementRoot as iWorkflowMgmt
- from icontrol.session import iControlUnexpectedHTTPError
- HAS_F5SDK = True
-except ImportError:
- HAS_F5SDK = False
-
-
from ansible.module_utils.basic import env_fallback
@@ -98,9 +79,19 @@ def f5_parse_arguments(module):
if module.params['validate_certs']:
import ssl
if not hasattr(ssl, 'SSLContext'):
- module.fail_json(msg='bigsuds does not support verifying certificates with python < 2.7.9. Either update python or set validate_certs=False on the task')
+ module.fail_json(
+ msg="bigsuds does not support verifying certificates with python < 2.7.9." \
+ "Either update python or set validate_certs=False on the task'")
- return (module.params['server'],module.params['user'],module.params['password'],module.params['state'],module.params['partition'],module.params['validate_certs'],module.params['server_port'])
+ return (
+ module.params['server'],
+ module.params['user'],
+ module.params['password'],
+ module.params['state'],
+ module.params['partition'],
+ module.params['validate_certs'],
+ module.params['server_port']
+ )
def bigip_api(bigip, user, password, validate_certs, port=443):
@@ -144,14 +135,74 @@ def fq_list_names(partition,list_names):
return map(lambda x: fq_name(partition,x),list_names)
+
+
+
+# New style
+
+try:
+ from f5.bigip import ManagementRoot as BigIpMgmt
+ from f5.bigiq import ManagementRoot as BigIqMgmt
+ from f5.iworkflow import ManagementRoot as iWorkflowMgmt
+ from icontrol.session import iControlUnexpectedHTTPError
+ HAS_F5SDK = True
+except ImportError:
+ HAS_F5SDK = False
+
+
+from ansible.module_utils.basic import *
+from ansible.module_utils.six import iteritems
+
+
+F5_COMMON_ARGS = dict(
+ server=dict(
+ type='str',
+ required=True,
+ fallback=(env_fallback, ['F5_SERVER'])
+ ),
+ user=dict(
+ type='str',
+ required=True,
+ fallback=(env_fallback, ['F5_USER'])
+ ),
+ password=dict(
+ type='str',
+ aliases=['pass', 'pwd'],
+ required=True,
+ no_log=True,
+ fallback=(env_fallback, ['F5_PASSWORD'])
+ ),
+ validate_certs=dict(
+ default='yes',
+ type='bool',
+ fallback=(env_fallback, ['F5_VALIDATE_CERTS'])
+ ),
+ server_port=dict(
+ type='int',
+ default=443,
+ required=False,
+ fallback=(env_fallback, ['F5_SERVER_PORT'])
+ ),
+ state=dict(
+ type='str',
+ default='present',
+ choices=['present', 'absent']
+ ),
+ partition=dict(
+ type='str',
+ default='Common',
+ fallback=(env_fallback, ['F5_PARTITION'])
+ )
+)
+
+
class AnsibleF5Client(object):
def __init__(self, argument_spec=None, supports_check_mode=False,
mutually_exclusive=None, required_together=None,
required_if=None, f5_product_name='bigip'):
merged_arg_spec = dict()
- common_args = f5_argument_spec()
- merged_arg_spec.update(common_args)
+ merged_arg_spec.update(F5_COMMON_ARGS)
if argument_spec:
merged_arg_spec.update(argument_spec)
self.arg_spec = merged_arg_spec
@@ -222,5 +273,54 @@ class AnsibleF5Client(object):
)
+class AnsibleF5Parameters(object):
+ def __init__(self, params=None):
+ self._partition = None
+ if params is None:
+ return
+ for key, value in iteritems(params):
+ setattr(self, key, value)
+
+ @property
+ def partition(self):
+ if self._partition is None:
+ return 'Common'
+ return self._partition.strip('/')
+
+ @partition.setter
+ def partition(self, value):
+ self._partition = value
+
+ @classmethod
+ def from_api(cls, params):
+ for key,value in iteritems(cls._api_param_map):
+ params[key] = params.pop(value, None)
+ p = cls(params)
+ return p
+
+ def __getattr__(self, item):
+ return None
+
+ def api_params(self):
+ result = self._api_params_from_map()
+ return self._filter_none(result)
+
+ def _filter_none(self, params):
+ result = dict()
+ for k, v in iteritems(params):
+ if v is None:
+ continue
+ result[k] = v
+ return result
+
+ def _api_params_from_map(self):
+ result = dict()
+ pmap = self.__class__._api_param_map
+ for k,v in iteritems(pmap):
+ value = getattr(self, k)
+ result[v] = value
+ return result
+
+
class F5ModuleError(Exception):
pass
diff --git a/lib/ansible/modules/network/f5/bigip_device_dns.py b/lib/ansible/modules/network/f5/bigip_device_dns.py
index a6c1e8e30d..73b4d1ea20 100644
--- a/lib/ansible/modules/network/f5/bigip_device_dns.py
+++ b/lib/ansible/modules/network/f5/bigip_device_dns.py
@@ -397,7 +397,7 @@ def main():
from ansible.module_utils.basic import *
from ansible.module_utils.ec2 import camel_dict_to_snake_dict
-from ansible.module_utils.f5 import *
+from ansible.module_utils.f5_utils import *
if __name__ == '__main__':
main()
diff --git a/lib/ansible/modules/network/f5/bigip_device_ntp.py b/lib/ansible/modules/network/f5/bigip_device_ntp.py
index 8856689139..2f5ac70a3e 100644
--- a/lib/ansible/modules/network/f5/bigip_device_ntp.py
+++ b/lib/ansible/modules/network/f5/bigip_device_ntp.py
@@ -257,7 +257,7 @@ def main():
from ansible.module_utils.basic import *
from ansible.module_utils.ec2 import camel_dict_to_snake_dict
-from ansible.module_utils.f5 import *
+from ansible.module_utils.f5_utils import *
if __name__ == '__main__':
main()
diff --git a/lib/ansible/modules/network/f5/bigip_device_sshd.py b/lib/ansible/modules/network/f5/bigip_device_sshd.py
index a1b3699826..96df331a55 100644
--- a/lib/ansible/modules/network/f5/bigip_device_sshd.py
+++ b/lib/ansible/modules/network/f5/bigip_device_sshd.py
@@ -344,7 +344,7 @@ def main():
from ansible.module_utils.basic import *
from ansible.module_utils.ec2 import camel_dict_to_snake_dict
-from ansible.module_utils.f5 import *
+from ansible.module_utils.f5_utils import *
if __name__ == '__main__':
main()
diff --git a/lib/ansible/modules/network/f5/bigip_facts.py b/lib/ansible/modules/network/f5/bigip_facts.py
index 33d5e1937e..10ff24b47d 100644
--- a/lib/ansible/modules/network/f5/bigip_facts.py
+++ b/lib/ansible/modules/network/f5/bigip_facts.py
@@ -1722,7 +1722,7 @@ def main():
# include magic from lib/ansible/module_common.py
from ansible.module_utils.basic import *
-from ansible.module_utils.f5 import *
+from ansible.module_utils.f5_utils import *
if __name__ == '__main__':
main()
diff --git a/lib/ansible/modules/network/f5/bigip_gtm_datacenter.py b/lib/ansible/modules/network/f5/bigip_gtm_datacenter.py
index 440dd7cbaf..d8be7247ab 100644
--- a/lib/ansible/modules/network/f5/bigip_gtm_datacenter.py
+++ b/lib/ansible/modules/network/f5/bigip_gtm_datacenter.py
@@ -366,7 +366,7 @@ def main():
from ansible.module_utils.basic import *
from ansible.module_utils.ec2 import camel_dict_to_snake_dict
-from ansible.module_utils.f5 import *
+from ansible.module_utils.f5_utils import *
if __name__ == '__main__':
main()
diff --git a/lib/ansible/modules/network/f5/bigip_gtm_facts.py b/lib/ansible/modules/network/f5/bigip_gtm_facts.py
index 039fec5d58..a2f803d4c6 100644
--- a/lib/ansible/modules/network/f5/bigip_gtm_facts.py
+++ b/lib/ansible/modules/network/f5/bigip_gtm_facts.py
@@ -489,7 +489,7 @@ def main():
from ansible.module_utils.basic import *
from ansible.module_utils.ec2 import camel_dict_to_snake_dict
-from ansible.module_utils.f5 import *
+from ansible.module_utils.f5_utils import *
if __name__ == '__main__':
main()
diff --git a/lib/ansible/modules/network/f5/bigip_gtm_virtual_server.py b/lib/ansible/modules/network/f5/bigip_gtm_virtual_server.py
index 03be3a9df6..e81df76c74 100644
--- a/lib/ansible/modules/network/f5/bigip_gtm_virtual_server.py
+++ b/lib/ansible/modules/network/f5/bigip_gtm_virtual_server.py
@@ -92,7 +92,7 @@ else:
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.pycompat24 import get_exception
-from ansible.module_utils.f5 import bigip_api, f5_argument_spec
+from ansible.module_utils.f5_utils import bigip_api, f5_argument_spec
def server_exists(api, server):
diff --git a/lib/ansible/modules/network/f5/bigip_gtm_wide_ip.py b/lib/ansible/modules/network/f5/bigip_gtm_wide_ip.py
index c1712902f4..fd0732e215 100644
--- a/lib/ansible/modules/network/f5/bigip_gtm_wide_ip.py
+++ b/lib/ansible/modules/network/f5/bigip_gtm_wide_ip.py
@@ -77,7 +77,7 @@ else:
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.pycompat24 import get_exception
-from ansible.module_utils.f5 import bigip_api, f5_argument_spec
+from ansible.module_utils.f5_utils import bigip_api, f5_argument_spec
def get_wide_ip_lb_method(api, wide_ip):
diff --git a/lib/ansible/modules/network/f5/bigip_hostname.py b/lib/ansible/modules/network/f5/bigip_hostname.py
index 9dc9d085c5..28fc8eef89 100644
--- a/lib/ansible/modules/network/f5/bigip_hostname.py
+++ b/lib/ansible/modules/network/f5/bigip_hostname.py
@@ -182,7 +182,7 @@ def main():
module.fail_json(msg=str(e))
from ansible.module_utils.basic import *
-from ansible.module_utils.f5 import *
+from ansible.module_utils.f5_utils import *
if __name__ == '__main__':
main()
diff --git a/lib/ansible/modules/network/f5/bigip_irule.py b/lib/ansible/modules/network/f5/bigip_irule.py
index 52b8f30fb5..7b7890c0ab 100644
--- a/lib/ansible/modules/network/f5/bigip_irule.py
+++ b/lib/ansible/modules/network/f5/bigip_irule.py
@@ -382,7 +382,7 @@ def main():
from ansible.module_utils.basic import *
from ansible.module_utils.ec2 import camel_dict_to_snake_dict
-from ansible.module_utils.f5 import *
+from ansible.module_utils.f5_utils import *
if __name__ == '__main__':
main()
diff --git a/lib/ansible/modules/network/f5/bigip_monitor_http.py b/lib/ansible/modules/network/f5/bigip_monitor_http.py
index 02017569c8..d9f04c93ff 100644
--- a/lib/ansible/modules/network/f5/bigip_monitor_http.py
+++ b/lib/ansible/modules/network/f5/bigip_monitor_http.py
@@ -441,7 +441,7 @@ def main():
# import module snippets
from ansible.module_utils.basic import *
-from ansible.module_utils.f5 import *
+from ansible.module_utils.f5_utils import *
if __name__ == '__main__':
main()
diff --git a/lib/ansible/modules/network/f5/bigip_monitor_tcp.py b/lib/ansible/modules/network/f5/bigip_monitor_tcp.py
index aedc71f642..bdd555ceae 100644
--- a/lib/ansible/modules/network/f5/bigip_monitor_tcp.py
+++ b/lib/ansible/modules/network/f5/bigip_monitor_tcp.py
@@ -483,7 +483,7 @@ def main():
# import module snippets
from ansible.module_utils.basic import *
-from ansible.module_utils.f5 import *
+from ansible.module_utils.f5_utils import *
if __name__ == '__main__':
main()
diff --git a/lib/ansible/modules/network/f5/bigip_node.py b/lib/ansible/modules/network/f5/bigip_node.py
index a40b545529..284b61df59 100644
--- a/lib/ansible/modules/network/f5/bigip_node.py
+++ b/lib/ansible/modules/network/f5/bigip_node.py
@@ -461,7 +461,7 @@ def main():
module.exit_json(**result)
from ansible.module_utils.basic import *
-from ansible.module_utils.f5 import *
+from ansible.module_utils.f5_utils import *
if __name__ == '__main__':
main()
diff --git a/lib/ansible/modules/network/f5/bigip_pool.py b/lib/ansible/modules/network/f5/bigip_pool.py
index 7c6b626563..5892564063 100644
--- a/lib/ansible/modules/network/f5/bigip_pool.py
+++ b/lib/ansible/modules/network/f5/bigip_pool.py
@@ -582,7 +582,7 @@ def main():
module.exit_json(**result)
from ansible.module_utils.basic import *
-from ansible.module_utils.f5 import *
+from ansible.module_utils.f5_utils import *
if __name__ == '__main__':
main()
diff --git a/lib/ansible/modules/network/f5/bigip_pool_member.py b/lib/ansible/modules/network/f5/bigip_pool_member.py
index ec16ce08a3..dcdf548df2 100644
--- a/lib/ansible/modules/network/f5/bigip_pool_member.py
+++ b/lib/ansible/modules/network/f5/bigip_pool_member.py
@@ -503,7 +503,7 @@ def main():
module.exit_json(**result)
from ansible.module_utils.basic import *
-from ansible.module_utils.f5 import *
+from ansible.module_utils.f5_utils import *
if __name__ == '__main__':
main()
diff --git a/lib/ansible/modules/network/f5/bigip_routedomain.py b/lib/ansible/modules/network/f5/bigip_routedomain.py
index 7abe77abac..cb5d868bcb 100644
--- a/lib/ansible/modules/network/f5/bigip_routedomain.py
+++ b/lib/ansible/modules/network/f5/bigip_routedomain.py
@@ -524,7 +524,7 @@ def main():
from ansible.module_utils.basic import *
from ansible.module_utils.ec2 import camel_dict_to_snake_dict
-from ansible.module_utils.f5 import *
+from ansible.module_utils.f5_utils import *
if __name__ == '__main__':
main()
diff --git a/lib/ansible/modules/network/f5/bigip_selfip.py b/lib/ansible/modules/network/f5/bigip_selfip.py
index 2a9465f625..7d88aae5b8 100644
--- a/lib/ansible/modules/network/f5/bigip_selfip.py
+++ b/lib/ansible/modules/network/f5/bigip_selfip.py
@@ -698,7 +698,7 @@ def main():
from ansible.module_utils.basic import *
from ansible.module_utils.ec2 import camel_dict_to_snake_dict
-from ansible.module_utils.f5 import *
+from ansible.module_utils.f5_utils import *
if __name__ == '__main__':
main()
diff --git a/lib/ansible/modules/network/f5/bigip_snat_pool.py b/lib/ansible/modules/network/f5/bigip_snat_pool.py
index 52341e4dfe..31fc80e39d 100644
--- a/lib/ansible/modules/network/f5/bigip_snat_pool.py
+++ b/lib/ansible/modules/network/f5/bigip_snat_pool.py
@@ -411,7 +411,7 @@ def main():
from ansible.module_utils.basic import *
from ansible.module_utils.ec2 import camel_dict_to_snake_dict
-from ansible.module_utils.f5 import *
+from ansible.module_utils.f5_utils import *
if __name__ == '__main__':
main()
diff --git a/lib/ansible/modules/network/f5/bigip_ssl_certificate.py b/lib/ansible/modules/network/f5/bigip_ssl_certificate.py
index fe0a753e83..0b1d092e74 100644
--- a/lib/ansible/modules/network/f5/bigip_ssl_certificate.py
+++ b/lib/ansible/modules/network/f5/bigip_ssl_certificate.py
@@ -514,7 +514,7 @@ def main():
module.fail_json(msg=str(e))
from ansible.module_utils.basic import *
-from ansible.module_utils.f5 import *
+from ansible.module_utils.f5_utils import *
if __name__ == '__main__':
main()
diff --git a/lib/ansible/modules/network/f5/bigip_sys_db.py b/lib/ansible/modules/network/f5/bigip_sys_db.py
index b451461b9c..66d2a06af4 100644
--- a/lib/ansible/modules/network/f5/bigip_sys_db.py
+++ b/lib/ansible/modules/network/f5/bigip_sys_db.py
@@ -221,7 +221,7 @@ def main():
module.fail_json(msg=str(e))
from ansible.module_utils.basic import *
-from ansible.module_utils.f5 import *
+from ansible.module_utils.f5_utils import *
if __name__ == '__main__':
main()
diff --git a/lib/ansible/modules/network/f5/bigip_sys_global.py b/lib/ansible/modules/network/f5/bigip_sys_global.py
index 7e6cfd7806..72bce3e67e 100644
--- a/lib/ansible/modules/network/f5/bigip_sys_global.py
+++ b/lib/ansible/modules/network/f5/bigip_sys_global.py
@@ -424,7 +424,7 @@ def main():
from ansible.module_utils.basic import *
from ansible.module_utils.ec2 import camel_dict_to_snake_dict
-from ansible.module_utils.f5 import *
+from ansible.module_utils.f5_utils import *
if __name__ == '__main__':
main()
diff --git a/lib/ansible/modules/network/f5/bigip_virtual_server.py b/lib/ansible/modules/network/f5/bigip_virtual_server.py
index a2aae5dad6..9c0979b70f 100644
--- a/lib/ansible/modules/network/f5/bigip_virtual_server.py
+++ b/lib/ansible/modules/network/f5/bigip_virtual_server.py
@@ -799,7 +799,7 @@ def main():
module.exit_json(**result)
# import module snippets
from ansible.module_utils.basic import *
-from ansible.module_utils.f5 import *
+from ansible.module_utils.f5_utils import *
if __name__ == '__main__':
main()
diff --git a/lib/ansible/modules/network/f5/bigip_vlan.py b/lib/ansible/modules/network/f5/bigip_vlan.py
index 40df948f6c..ad2675ca71 100644
--- a/lib/ansible/modules/network/f5/bigip_vlan.py
+++ b/lib/ansible/modules/network/f5/bigip_vlan.py
@@ -445,7 +445,7 @@ def main():
from ansible.module_utils.basic import *
from ansible.module_utils.ec2 import camel_dict_to_snake_dict
-from ansible.module_utils.f5 import *
+from ansible.module_utils.f5_utils import *
if __name__ == '__main__':
main()
diff --git a/test/compile/python2.4-skip.txt b/test/compile/python2.4-skip.txt
index 66682e68f1..2b806b5d95 100644
--- a/test/compile/python2.4-skip.txt
+++ b/test/compile/python2.4-skip.txt
@@ -46,7 +46,8 @@
/lib/ansible/module_utils/vmware.py
/lib/ansible/module_utils/netconf.py
/lib/ansible/module_utils/junos.py
-/lib/ansible/module_utils/f5.py
+/lib/ansible/module_utils/f5_utils.py
+/lib/ansible/module_utils/f5_cli.py
/lib/ansible/parsing/
/lib/ansible/playbook/
/lib/ansible/plugins/
diff --git a/test/sanity/pep8/legacy-files.txt b/test/sanity/pep8/legacy-files.txt
index 538adbbd4c..3ccb4d0c6a 100644
--- a/test/sanity/pep8/legacy-files.txt
+++ b/test/sanity/pep8/legacy-files.txt
@@ -12,7 +12,6 @@ lib/ansible/inventory/dir.py
lib/ansible/inventory/script.py
lib/ansible/module_utils/basic.py
lib/ansible/module_utils/ec2.py
-lib/ansible/module_utils/f5.py
lib/ansible/module_utils/facts.py
lib/ansible/module_utils/known_hosts.py
lib/ansible/module_utils/mysql.py