Created
May 7, 2013 11:11
-
-
Save tomellis/5531886 to your computer and use it in GitHub Desktop.
Add DNS with pyrax to Rackspace Cloud
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
import os | |
import logging | |
import sys | |
import pyrax | |
import pyrax.exceptions as exc | |
logging.basicConfig(level=logging.DEBUG) | |
## Authenticate to London Rackspace Cloud | |
conf = os.path.expanduser("creds") | |
pyrax.set_credential_file(conf, "LON") | |
dns = pyrax.cloud_dns | |
def create_subdomain(subdomain_name): | |
try: | |
print "Creating subdomain: ", subdomain_name | |
dom = dns.create(name=subdomain_name, emailAddress="bill@microsoft.com", ttl=900, comment="Chef demo subdomain") | |
except exc.DomainCreationFailed: | |
print "DomainCreationFailed!" | |
print "Trying to get existing domain record..." | |
try: | |
dom = dns.find(name=subdomain_name) | |
print dom | |
except exc.NotFound: | |
print "Subdomain not found" | |
pass | |
def create_record(subdomain_name, fqdn_name, ip_addr): | |
dom = dns.find(name=subdomain_name) | |
a_rec = { | |
"type": "A", | |
"name": fqdn_name, | |
"data": ip_addr, | |
"ttl": 6000, | |
} | |
recs = dom.add_records([a_rec]) | |
def delete_subdomain(subdomain_name): | |
dom = dns.find(name=subdomain_name) | |
dom.delete() | |
subdomain_name = "test.co.uk" | |
fqdn_name = "demo.test.bigcloudsolutions.co.uk" | |
ip_addr = "162.13.2.143" | |
create_subdomain(subdomain_name) | |
create_record(subdomain_name, fqdn_name, ip_addr) | |
#delete_subdomain(subdomain_name) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment