Skip to content

Instantly share code, notes, and snippets.

@gokmen
Created September 29, 2012 18:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gokmen/3804853 to your computer and use it in GitHub Desktop.
Save gokmen/3804853 to your computer and use it in GitHub Desktop.
Webfaction Google Apps record creator
#!/usr/bin/env python2.5
import sys
import getpass
import xmlrpclib
server = xmlrpclib.Server('https://api.webfaction.com/')
username = raw_input("Username : ")
password = getpass.getpass("Password : ")
print "Trying to connect webfaction..."
print
try:
session_id, account = server.login(username, password)
except:
sys.exit("Connection failed, did u mispelled something?")
print "Ok, connected."
print
domain = raw_input("Please enter your domain name (no www, etc): ")
services = ('mail', 'cal', 'docs', 'start')
print
print "Here are the default subdomains for your google apps domain:"
for service in services:
print "\t - %s.%s" % (service, domain)
print
state = raw_input("If you want to create these aliases write yes: ")
if state == 'yes':
# mx info
mx_info = (
('ASPMX.L.GOOGLE.COM','10'),
('ALT1.ASPMX.L.GOOGLE.COM','20'),
('ALT2.ASPMX.L.GOOGLE.COM','20'),
('ASPMX2.GOOGLEMAIL.COM','30'),
('ASPMX3.GOOGLEMAIL.COM','30'),
('ASPMX4.GOOGLEMAIL.COM','30'),
('ASPMX5.GOOGLEMAIL.COM','30'),
)
print " Creating MX records for %s ..." % domain
try:
# create mx records
for mx in mx_info:
server.create_dns_override(session_id,
domain,
'',
'',
mx[0],
mx[1],
'')
except:
sys.exit(" MX record failed, exiting...")
else:
print " MX records created successfully."
for service in services:
print " Creating CNAME records for: %s.%s ..." % (service, domain)
# create CNAME record
try:
server.create_domain(session_id, domain, service)
server.create_dns_override(session_id,
"%s.%s" % (service, domain),
'',
'ghs.google.com',
'',
'',
'')
except:
print " Failed to create CNAME record for: %s.%s ..." % (service, domain)
else:
print " CNAME record created for: %s.%s ..." % (service, domain)
print "All records created, failed or not I have no idea, follow the messages above."
else:
print "Ok then, c ya!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment