Skip to content

Instantly share code, notes, and snippets.

@mario
Forked from tarkatronic/transfer_slicehost.py
Created June 1, 2012 21:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mario/2855396 to your computer and use it in GitHub Desktop.
Save mario/2855396 to your computer and use it in GitHub Desktop.
Transferring DNS records from Slicehost to 6sync via API calls
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://%s@api.slicehost.com/' % 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