Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Exports all domains for a Rackspace Cloud account in BIND9 format
#!/usr/bin/env python
import json
import os
import time
import clouddns
USERNAME = ''
APIKEY = ''
DIRECTORY = ''
dns = clouddns.connection.Connection(USERNAME, APIKEY)
domains = dns.get_domains()
DIRECTORY = os.path.expanduser(DIRECTORY)
if not os.path.exists(DIRECTORY):
os.makedirs(DIRECTORY)
for domain in domains:
finished = False
response = json.loads(dns.make_request('GET', ["domains", domain.id, "export"]).read())
try:
status = response['callbackUrl'].split('/')[-2:]
except KeyError as e:
print response
# Prevent rate-limiting
time.sleep(5)
while not finished:
try:
records = json.loads(dns.make_request('GET', status, parms = {'showDetails': "true"}).read())['response']['contents']
filename = os.path.join(DIRECTORY, "%s.bind9" % domain.name)
print "Creating %s" % filename
with open(filename, 'w') as f:
f.write(records)
except KeyError as e:
print "Request is still running for %s, retrying..." % domain.name
time.sleep(5)
else:
finished = True
@fxer

This comment has been minimized.

Show comment
Hide comment
@fxer

fxer Dec 16, 2013

Have you thought about tweaking this to use the new 'pyrax' module which replaced cloudnds? Thanks for this gist DW!

https://github.com/rackspace/pyrax/blob/master/docs/cloud_dns.md

fxer commented Dec 16, 2013

Have you thought about tweaking this to use the new 'pyrax' module which replaced cloudnds? Thanks for this gist DW!

https://github.com/rackspace/pyrax/blob/master/docs/cloud_dns.md

@goldencut

This comment has been minimized.

Show comment
Hide comment
@goldencut

goldencut Jul 24, 2017

Hmm, probably my bad but on py2.7 I get:
File "get_RS_DNS.py", line 13, in <module> dns = clouddns.connection.Connection(USERNAME, APIKEY) File "/usr/local/lib/python2.7/dist-packages/clouddns/connection.py", line 73, in __init__ self._authenticate() File "/usr/local/lib/python2.7/dist-packages/clouddns/connection.py", line 85, in _authenticate (url, self.token) = self.auth.authenticate() File "/usr/local/lib/python2.7/dist-packages/clouddns/authentication.py", line 109, in authenticate return ("".join(dns_management_url), auth_token) UnboundLocalError: local variable 'dns_management_url' referenced before assignment
On py3.4 I get other stuff as it needs to be ported to py3 properly.

G.

Hmm, probably my bad but on py2.7 I get:
File "get_RS_DNS.py", line 13, in <module> dns = clouddns.connection.Connection(USERNAME, APIKEY) File "/usr/local/lib/python2.7/dist-packages/clouddns/connection.py", line 73, in __init__ self._authenticate() File "/usr/local/lib/python2.7/dist-packages/clouddns/connection.py", line 85, in _authenticate (url, self.token) = self.auth.authenticate() File "/usr/local/lib/python2.7/dist-packages/clouddns/authentication.py", line 109, in authenticate return ("".join(dns_management_url), auth_token) UnboundLocalError: local variable 'dns_management_url' referenced before assignment
On py3.4 I get other stuff as it needs to be ported to py3 properly.

G.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment