diff --git a/lib/ansible/module_common.py b/lib/ansible/module_common.py index 37d617812a..8beff78d07 100644 --- a/lib/ansible/module_common.py +++ b/lib/ansible/module_common.py @@ -33,7 +33,6 @@ REPLACER_COMPLEX = "\"<>\"" REPLACER_WINDOWS = "# POWERSHELL_COMMON" REPLACER_VERSION = "\"<>\"" - class ModuleReplacer(object): """ diff --git a/lib/ansible/module_utils/rax.py b/lib/ansible/module_utils/rax.py index 3eada0268e..db8b6c4f3a 100644 --- a/lib/ansible/module_utils/rax.py +++ b/lib/ansible/module_utils/rax.py @@ -170,6 +170,29 @@ def rax_find_server(module, rax_module, server): return server +def rax_find_loadbalancer(module, rax_module, loadbalancer): + clb = rax_module.cloud_loadbalancers + try: + UUID(loadbalancer) + found = clb.get(loadbalancer) + except: + for lb in clb.list(): + if loadbalancer == lb.name: + found.append(lb) + + if not found: + module.fail_json(msg='No loadbalancer was matched') + + if len(found) > 1: + module.fail_json(msg='Multiple loadbalancers matched') + + # We made it this far, grab the first and hopefully only item + # in the list + found = found[0] + + return found + + def rax_argument_spec(): return dict( api_key=dict(type='str', aliases=['password'], no_log=True), diff --git a/library/cloud/rax b/library/cloud/rax index 35156a01db..d7db2c63d7 100644 --- a/library/cloud/rax +++ b/library/cloud/rax @@ -219,7 +219,7 @@ def create(module, names=[], flavor=None, image=None, meta={}, key_name=None, except Exception, e: module.fail_json(msg='Failed to load %s' % user_data) - # Handle the file contents + # Handle the file contents for rpath in files.keys(): lpath = os.path.expanduser(files[rpath]) try: @@ -707,5 +707,5 @@ def main(): from ansible.module_utils.basic import * from ansible.module_utils.rax import * -### invoke the module +# invoke the module main() diff --git a/library/cloud/rax_dns_record b/library/cloud/rax_dns_record index 05c7a8fc05..561758f4fd 100644 --- a/library/cloud/rax_dns_record +++ b/library/cloud/rax_dns_record @@ -120,43 +120,23 @@ except ImportError: HAS_PYRAX = False -def rax_dns_record(module, data=None, comment=None, loadbalancer=None, - name=None, server=None, state='present', ttl=7200): +def rax_dns_record_ptr(module, data=None, comment=None, loadbalancer=None, + name=None, server=None, state='present', ttl=7200): changed = False results = [] - cs = pyrax.cloudservers - clb = pyrax.cloud_loadbalancers dns = pyrax.cloud_dns - if not cs or not clb or not dns: + if not dns: module.fail_json(msg='Failed to instantiate client. This ' 'typically indicates an invalid region or an ' 'incorrectly capitalized region name.') if loadbalancer: - try: - UUID(loadbalancer) - found = [clb.get(loadbalancer)] - except: - for lb in clb.list(): - if loadbalancer == lb.name: - found.append(lb) - - if len(found) != 1: - module.fail_json(msg='Could not match a loadbalancer with %s' % - loadbalancer) + item = rax_find_loadbalancer(module, pyrax, loadbalancer) elif server: - try: - UUID(server) - found = [cs.servers.get(server)] - except: - found = cs.servers.list(search_opts=dict(name='^%s$' % server)) - if len(found) != 1: - module.fail_json(msg='Could not match a server with %s' % - server) + item = rax_find_server(module, pyrax, server) - item = found[0] if state == 'present': current = dns.list_ptr_records(item) for record in current: @@ -169,10 +149,10 @@ def rax_dns_record(module, data=None, comment=None, loadbalancer=None, module.fail_json(msg='%s' % e.message) record.ttl = ttl record.name = name - results.append(to_dict(record)) + results.append(rax_to_dict(record)) break else: - results.append(to_dict(record)) + results.append(rax_to_dict(record)) break if not results: @@ -190,7 +170,7 @@ def rax_dns_record(module, data=None, comment=None, loadbalancer=None, current = dns.list_ptr_records(item) for record in current: if record.data == data: - results.append(to_dict(record)) + results.append(rax_to_dict(record)) break if results: