Created
July 21, 2011 22:23
-
-
Save tarkatronic/1098382 to your computer and use it in GitHub Desktop.
Transferring DNS records from Slicehost to 6sync via API calls
This file contains 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
from pyactiveresource.activeresource import ActiveResource | |
from biscuit.api import APIHandler | |
ip_translations = {'aaa.bbb.ccc.ddd': 'xxx.yyy.zzz.qqq', | |
'eee.fff.ggg.hhh': 'ppp.qqq.rrr.sss'} | |
slice_api_key = 'xxxxx_YOUR_SLICEHOST_API_KEY_HERE_xxxxx' | |
slice_api_url = 'https://%[email protected]/' % slice_api_key | |
biscuit_api_key = 'XXX_YOUR_6SYNC_API_KEY_XXX' | |
biscuit_api_secret = 'XXX_YOUR_6SYNC_API_SECRET_XXX' | |
biscuit_api = APIHandler(biscuit_api_key, biscuit_api_secret) | |
class Zone(ActiveResource): | |
_site = slice_api_url | |
class Record(ActiveResource): | |
_site = slice_api_url | |
slice_domains = Zone.find() | |
slice_origins = map(lambda x: x.origin, slice_domains) | |
biscuit_domains = biscuit_api.domain_list() | |
biscuit_origins = map(lambda x: x['origin'], biscuit_domains) | |
transfer_domains = filter(lambda x: x not in biscuit_origins, slice_origins) | |
print 'Found', len(transfer_domains), 'to transfer.' | |
for domain in transfer_domains: | |
print 'Transferring', domain, '\n' | |
old_zone = Zone.find(origin=domain)[0] | |
new_zone = biscuit_api.domain_create(domain) | |
old_records = Record.find(zone_id=old_zone.id) | |
for record in old_records: | |
if record.record_type != 'NS': # We're changing NS servers; ignore these records. | |
if record.data in ip_translations: | |
data = ip_translations[record.data] | |
else: | |
data = record.data | |
new_record = biscuit_api.domain_resource_create(new_zone['id'], record.name, record.record_type, data, record.aux) | |
print 'Done!' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment