import common as helper import pyrax # preliminary creds_file = os.path.expanduser("~/.rackspace_cloud_credentials") pyrax.set_credential_file(creds_file) cdns = pyrax.cloud_dns # take three parameters: 1: your hosted domain 2: a valid hostname (e.g.: www), 3: a valid IPv4 address if len(sys.argv) < 3: print "{0}: <domain> <host> <ipv4address>".format(sys.argv[0]) sys.exit(1) valid_fqdn = helper.validate_fqdn(sys.argv[1]) valid_host = helper.validate_fqdn(sys.argv[2]) valid_ipv4 = helper.validate_ipv4(sys.argv[3]) # use helper function to ensure that the specified domain is valid if valid_fqdn: valid_fqdn = sys.argv[1] print valid_fqdn, "seems valid, but I have not verified this on remote server yet.." else: print "ERROR: invalid characters in your FQDN" sys.exit(1) # use helper function to ensure that the specified hostname is valid if valid_host: valid_host = sys.argv[2] print "validated host:", valid_host, "successfully" else: print "ERROR: invalid hostname"
print 'checking server until LB is active...', disp_time lb = helper.act_loop(clb.get, lb.id) if lb.status == 'ACTIVE': helper.act_loop(lb.add_health_monitor, type="CONNECT", delay=10, timeout=10, attemptsBeforeDeactivation=3) html_error_page = '<html><body><h1>stuff is messed up</h1><iframe width="420" height="315" src="http://www.youtube.com/embed/XYYo3T6nCw8?list=FLaE5b9q2s2yO77ZIXwqbHog&autoplay=1" frameborder="0" allowfullscreen></iframe></body></html>' while True: print 'updating health montor..' lb = helper.act_loop(clb.get, lb.id) if lb.status == 'ACTIVE': break helper.act_loop(lb.set_error_page, html_error_page) site_cont_name = '{0}-backup'.format(lb_name) cont = helper.act_loop(cf.get_container, site_cont_name) obj = helper.act_loop(cf.store_object, site_cont_name, "index.htm", html_error_page) for ip in lb.virtual_ips: if helper.validate_ipv4(lb.virtual_ips[0].address): get_vip = lb.virtual_ips[0].address else: get_vip = lb.virtual_ips[1].address domains = helper.act_loop(cdns.list, limit=1) for domain in domains: dom = domain dom_name = dom.name # create a cname for the container we created subdomain = '{0}.{1}'.format(lb_name, dom_name) recs = [{"type": "A", "name": subdomain, "data": get_vip, "ttl": 300}] # add our A record helper.act_loop(cdns.add_records, dom, recs) print 'created dns record: {0} -> {1} on domain: {2}'.format(subdomain, get_vip, dom_name) print "-------------------------------------" print "Load Balancer:", lb.name
import common as helper import pyrax # preliminary creds_file = os.path.expanduser("~/.rackspace_cloud_credentials") pyrax.set_credential_file(creds_file) cdns = pyrax.cloud_dns # take three parameters: 1: your hosted domain 2: a valid hostname (e.g.: www), 3: a valid IPv4 address if len(sys.argv) < 3: print '{0}: <domain> <host> <ipv4address>'.format(sys.argv[0]) sys.exit(1) valid_fqdn = helper.validate_fqdn(sys.argv[1]) valid_host = helper.validate_fqdn(sys.argv[2]) valid_ipv4 = helper.validate_ipv4(sys.argv[3]) # use helper function to ensure that the specified domain is valid if valid_fqdn: valid_fqdn = sys.argv[1] print valid_fqdn, 'seems valid, but I have not verified this on remote server yet..' else: print 'ERROR: invalid characters in your FQDN' sys.exit(1) # use helper function to ensure that the specified hostname is valid if valid_host: valid_host = sys.argv[2] print 'validated host:', valid_host, 'successfully' else: print 'ERROR: invalid hostname'