From c4005983329d92f34af3cad427ea7a748836de80 Mon Sep 17 00:00:00 2001 From: Tim Rupp Date: Tue, 3 May 2016 22:50:45 -0700 Subject: [PATCH] Reverse the unpack list operation Instead of doing an unpack, deliberately specify which parameters you want to use. This allows us to flexibly add more parameters to the f5_argument_spec without having to rewrite all the modules that use it. Functionally this commit changes nothing, it just provides for a different way of accessing the parameters to the module --- network/f5/bigip_monitor_http.py | 15 ++++++++++++++- network/f5/bigip_monitor_tcp.py | 17 +++++++++++++++-- network/f5/bigip_node.py | 17 +++++++++++++++-- network/f5/bigip_pool.py | 15 ++++++++++++++- network/f5/bigip_pool_member.py | 18 ++++++++++++++++-- network/f5/bigip_virtual_server.py | 16 +++++++++++++++- 6 files changed, 89 insertions(+), 9 deletions(-) diff --git a/network/f5/bigip_monitor_http.py b/network/f5/bigip_monitor_http.py index 166b7ae32e0..dcdaf4b65b6 100644 --- a/network/f5/bigip_monitor_http.py +++ b/network/f5/bigip_monitor_http.py @@ -317,7 +317,20 @@ def main(): supports_check_mode=True ) - (server,user,password,state,partition,validate_certs) = f5_parse_arguments(module) + if not bigsuds_found: + module.fail_json(msg="the python bigsuds module is required") + + 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') + + server = module.params['server'] + user = module.params['user'] + password = module.params['password'] + state = module.params['state'] + partition = module.params['partition'] + validate_certs = module.params['validate_certs'] parent_partition = module.params['parent_partition'] name = module.params['name'] diff --git a/network/f5/bigip_monitor_tcp.py b/network/f5/bigip_monitor_tcp.py index b06c8978106..0ef6a9add26 100644 --- a/network/f5/bigip_monitor_tcp.py +++ b/network/f5/bigip_monitor_tcp.py @@ -315,7 +315,7 @@ def set_ipport(api, monitor, ipport): def main(): # begin monitor specific stuff - argument_spec=f5_argument_spec(); + argument_spec=f5_argument_spec() argument_spec.update(dict( name = dict(required=True), type = dict(default=DEFAULT_TEMPLATE_TYPE_CHOICE, choices=TEMPLATE_TYPE_CHOICES), @@ -336,7 +336,20 @@ def main(): supports_check_mode=True ) - (server,user,password,state,partition,validate_certs) = f5_parse_arguments(module) + if not bigsuds_found: + module.fail_json(msg="the python bigsuds module is required") + + 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') + + server = module.params['server'] + user = module.params['user'] + password = module.params['password'] + state = module.params['state'] + partition = module.params['partition'] + validate_certs = module.params['validate_certs'] parent_partition = module.params['parent_partition'] name = module.params['name'] diff --git a/network/f5/bigip_node.py b/network/f5/bigip_node.py index c6c32a38858..bc209af6ae6 100644 --- a/network/f5/bigip_node.py +++ b/network/f5/bigip_node.py @@ -263,7 +263,7 @@ def get_node_monitor_status(api, name): def main(): - argument_spec=f5_argument_spec(); + argument_spec=f5_argument_spec() argument_spec.update(dict( session_state = dict(type='str', choices=['enabled', 'disabled']), monitor_state = dict(type='str', choices=['enabled', 'disabled']), @@ -278,7 +278,20 @@ def main(): supports_check_mode=True ) - (server,user,password,state,partition,validate_certs) = f5_parse_arguments(module) + if not bigsuds_found: + module.fail_json(msg="the python bigsuds module is required") + + 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') + + server = module.params['server'] + user = module.params['user'] + password = module.params['password'] + state = module.params['state'] + partition = module.params['partition'] + validate_certs = module.params['validate_certs'] session_state = module.params['session_state'] monitor_state = module.params['monitor_state'] diff --git a/network/f5/bigip_pool.py b/network/f5/bigip_pool.py index 85fbc5b9c0d..a8dafb3bbef 100644 --- a/network/f5/bigip_pool.py +++ b/network/f5/bigip_pool.py @@ -367,7 +367,20 @@ def main(): supports_check_mode=True ) - (server,user,password,state,partition,validate_certs) = f5_parse_arguments(module) + if not bigsuds_found: + module.fail_json(msg="the python bigsuds module is required") + + 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') + + server = module.params['server'] + user = module.params['user'] + password = module.params['password'] + state = module.params['state'] + partition = module.params['partition'] + validate_certs = module.params['validate_certs'] name = module.params['name'] pool = fq_name(partition,name) diff --git a/network/f5/bigip_pool_member.py b/network/f5/bigip_pool_member.py index 50abef420e7..9f0965cbd84 100644 --- a/network/f5/bigip_pool_member.py +++ b/network/f5/bigip_pool_member.py @@ -314,7 +314,7 @@ def get_member_monitor_status(api, pool, address, port): return result def main(): - argument_spec = f5_argument_spec(); + argument_spec = f5_argument_spec() argument_spec.update(dict( session_state = dict(type='str', choices=['enabled', 'disabled']), monitor_state = dict(type='str', choices=['enabled', 'disabled']), @@ -334,7 +334,21 @@ def main(): supports_check_mode=True ) - (server,user,password,state,partition,validate_certs) = f5_parse_arguments(module) + if not bigsuds_found: + module.fail_json(msg="the python bigsuds module is required") + + 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') + + server = module.params['server'] + user = module.params['user'] + password = module.params['password'] + state = module.params['state'] + partition = module.params['partition'] + validate_certs = module.params['validate_certs'] + session_state = module.params['session_state'] monitor_state = module.params['monitor_state'] pool = fq_name(partition, module.params['pool']) diff --git a/network/f5/bigip_virtual_server.py b/network/f5/bigip_virtual_server.py index b654e5f84f8..891ff5ecd34 100644 --- a/network/f5/bigip_virtual_server.py +++ b/network/f5/bigip_virtual_server.py @@ -378,7 +378,21 @@ def main(): supports_check_mode=True ) - (server,user,password,state,partition,validate_certs) = f5_parse_arguments(module) + if not bigsuds_found: + module.fail_json(msg="the python bigsuds module is required") + + 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') + + server = module.params['server'] + user = module.params['user'] + password = module.params['password'] + state = module.params['state'] + partition = module.params['partition'] + validate_certs = module.params['validate_certs'] + name = fq_name(partition,module.params['name']) destination=module.params['destination'] port=module.params['port']