Last active
December 12, 2018 01:06
-
-
Save DavidWittman/4727690 to your computer and use it in GitHub Desktop.
Exports all domains for a Rackspace Cloud account in BIND9 format
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
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
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