Created
August 25, 2010 21:17
-
-
Save tarkatronic/550312 to your computer and use it in GitHub Desktop.
Shift A records to a new IP for any number of domains at a time using Slicehost's API. Requires http://code.google.com/p/pyactiveresource/
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 pyactiveresource.connection import UnauthorizedAccess | |
#### CONFIGURATION #### | |
from_ip = 'xxx.xxx.xxx.xxx' | |
to_ip = 'xxx.xxx.xxx.xxx' | |
update_domains = ('domain1.com.','domain2.net.','otherdomain.org.') | |
api_key = 'xxxxx_YOUR_API_KEY_HERE_xxxxx' | |
api_url = 'https://%[email protected]/' % api_key | |
#### Resource classes #### | |
class Zone(ActiveResource): | |
_site = api_url | |
class Record(ActiveResource): | |
_site = api_url | |
#### Processing #### | |
zones_found = [] | |
zones_not_found = [] | |
records_found = [] | |
try: | |
for domain in update_domains: | |
z = Zone.find(origin=domain) | |
if z: | |
z = z[0] # 'find' returns a list; extract this item to ease of use | |
zones_found.append(z.origin) | |
records = Record.find(zone_id=z.id, record_type='A', data=from_ip) | |
for record in records: | |
records_found.append(record.name) | |
record.data = to_ip | |
record.save() | |
else: | |
zones_not_found.append(domain) | |
except UnauthorizedAccess: | |
print 'Access denied. Please confirm your API key is correct.' | |
except: | |
print 'An unknown error has occurred.' | |
else: | |
print 'Found %d zones.' % len(zones_found) | |
print 'Found %d A records.' % len(records_found) | |
if zones_not_found: | |
print '\nFailed to find the following zones:\n\t%s' % '\n\t'.join(zones_not_found) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment