Last active
July 12, 2018 13:30
-
-
Save kymair/5193783 to your computer and use it in GitHub Desktop.
Python script to update Linode DNS
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
# Get Linode API python bindings from https://github.com/tjfontaine/linode-python | |
#!/usr/bin/python | |
from linode import api | |
instance = api.Api(key='abcdefg') | |
for domain in instance.domain_list(): | |
if domain['TYPE'] == 'master': | |
print "Updating %s (%i)..." % (domain['DOMAIN'], domain['DOMAINID']) | |
for resource in instance.domain_resource_list( | |
domainid=domain['DOMAINID']): | |
if resource['TYPE'] == 'A' and \ | |
resource['TARGET'] == '1.1.1.1': | |
print 'Old A Record Found: %s.%s (%i)' % \ | |
(resource['NAME'], domain['DOMAIN'], | |
resource['RESOURCEID']) | |
newresid = instance.domain_resource_create( | |
domainid=domain['DOMAINID'], | |
type='A', | |
name=resource['NAME'], | |
target='2.2.2.2') | |
print ' Created resource %i' % newresid['ResourceID'] | |
oldresid = instance.domain_resource_delete( | |
domainid=domain['DOMAINID'], | |
resourceid=resource['RESOURCEID']) | |
print ' Deleted resource %i' % oldresid['ResourceID'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment