Dedupe PTR record related code in rax_dns_record

reviewable/pr18780/r1
Matt Martz 10 years ago
parent a96fb6fab9
commit 050b2e5386

@ -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()

@ -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 = found[0]
item = rax_find_server(module, pyrax, server)
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:

Loading…
Cancel
Save