Example #1
0
    def wait_for_instance_build(self):
        debug("wait_for_instance_build start")

        wait = WaitingForTask(self.check_db_instance, [self.db_instance_name])
        if wait.wait_for_tasks() == False:
            self.db_instance.delete()
            sys.exit()
Example #2
0
    def run(self):
        debug("run start")
        ChallengeBase.run(self)
        
        if self.check() is False:
            self.usage()
            sys.exit(-1)

        log("--------------------------------------------")
        log("Container %s info before enabling CDN:" % self.container_name )
        self.show(self.container_name)

        if self.enable_cdn(self.container_name) :
            log("--------------------------------------------")
            log("Container info after enabling CDN:")
            self.container=self.show(self.container_name)

        log("--------------------------------------------")
        log("Example files from the container %s" % self.container.name)
        
        objects=self.container.get_objects()
        if objects : 
            # print example 2 files from the container 
            for index in [ i for i in range(0, len(objects)) if i < 2 ] :
                cf_file=objects[index]

                log("============================================")
                self.show_file_info(cf_file)

        else: 
            log("there are not files in the container")
Example #3
0
    def create_users(self):
        debug("create_users start")
        password = "******"

        for user in self.db_users:
            self.db_instance.create_user(user, password, self.dbs)
            log("Created user %s pass %s in db %s" % (user, password, self.dbs))
Example #4
0
    def create_domain(self, domain_name):
        debug("create_domain start")
        
        try:
            dom = self.dns.find(name=domain_name)
            if self.opt_delete_domain :
                debug("deleting domain %s" % domain_name)
                dom.delete()
            else:
                log("Domain %s exists, please specify other domain name or use -d option" % domain_name)
                return False

        except exc.NotFound:
            pass

        try:
            dom = self.dns.create(name=domain_name, emailAddress="*****@*****.**",
                    ttl=900, comment="challenge4 domain")
        except exc.DomainCreationFailed as e:
            log("Domain creation failed: %s" % e)
            return False

        self.domain = dom
        log("Domain created: %s" % domain_name)

        return True
Example #5
0
    def run(self):
        debug("run start")
        ChallengeBase.run(self)
        
        if self.check() is False:
            self.usage()
            sys.exit(-1)

        log("Creating new DNS zone %s" % self.domain_name)
        self.domain=self.dns.create(name=self.domain_name, emailAddress="*****@*****.**", ttl=300, comment="challenge9 domain")

        log("Creating cloud server ...(please wait the build can take a while)")
        self.server=self.cs.servers.create(name=self.fqdn_name, flavor=self.flavor_id, image=self.image_id)

        wait = WaitingForTask(self.check_cs_build, self.server)
        if wait.wait_for_tasks() == False: 
            log("Cloud server build failed, deleting created objects")
            self.server.delete()
            self.domain.delete()
            sys.exit(-1)

        # get all public IPs
        net = [ i["addr"] for i in self.server.addresses["public"] ] 
        self.net = utils.get_ipv4net(net)

        cname_rec = {"type": "A",
                    "name": self.fqdn_name,
                    "data": self.net,
                    "ttl": 300,
                    "comment": "challenge9 rec"}

        self.recs = self.domain.add_record(cname_rec)

        log("DNS zone %s has been udpated and a new A record created" % (self.domain_name))
        log("rec A: %s -> %s" % (self.fqdn_name, self.net))
    def build_lb(self):
        debug("build_lb start")

        for s in self.servers :
            net = [ i["addr"] for i in s.addresses["private"] ] 
            net = utils.get_ipv4net(net)

            node = self.clb.Node(address=net, port=80, condition="ENABLED")
            self.nodes.append(node)

        self.vip = self.clb.VirtualIP(type="PUBLIC")
        self.lb = self.clb.create(self.lb_name, port=80, protocol="HTTP", nodes=self.nodes, virtual_ips=[self.vip])
        self.wait_for_lb_change()

        debug("key")
        debug(self.cert_key)

        debug("crt")
        debug(self.cert)

        self.lb.add_ssl_termination(
            securePort=443,
            enabled=True,
            secureTrafficOnly=False,
            certificate=self.cert,
            privatekey=self.cert_key )

        self.wait_for_lb_change()
    def check(self):
        debug("check start")
        ret = True

        if self.check_cert() :
            log("Checked your cert/key pair %s/%s, ok" % (self.cert_name, self.cert_key_name))
        else :
            ret=False
        
        if self.check_fqdn_and_dns() : 
            log("Checked your FQDN %s, ok" % self.fqdn_name )
            log("Checked your DNS domains %s, there is none, ok" % self.domain_name )
        else :
            ret=False


        if self.check_cloud_servers():
            log("Checked your existing cloud server %s-*, ok" % self.server_prefix )

        if self.check_blocks() :
            log("Checked your block images %s, there is none, ok" % self.storage_name )
        else :
            ret=False

        if self.check_existing_lb() :
            log("Checked your lb %s, there is none, ok" % self.lb_name )
        else :
            ret=False

        try:
            self.image=self.cs.images.find(id=self.image_id)
            log("Checked your image id %s, ok" % self.image_id )
        except exc.NotFound, e:
            log("The image id is incorrect")
            ret=False
Example #8
0
    def show(self):
        debug("show start")

        log("Static site details: (make sure you point your DNS to Rackspace Cloud DNS servers):")
        log("ping %s" % self.rec_CNAME)
        log("curl -v http://%s/%s" % (self.rec_CNAME, self.index_name) )
        log("curl -v http://%s" % (self.rec_CNAME_data) )
Example #9
0
    def show(self):
        debug("show start")

        dom = self.dns.find(name=self.domain_name)

        log("domain name: %s created at %s" % (dom.name, dom.created) )
        for r in dom.list_records() : 
            log("record %3s %s -> %s" % (r.type, r.name, r.data) )
Example #10
0
    def check_network_objects(self):
        debug("check_network_objects start")

        for net in self.cnw.list() :
            if net.name == self.network_name :
                log("Deleted existing network obj %s" % self.network_name)
                net.delete()

        return True
Example #11
0
 def check(self):
     debug("check start")
     ret = True
 
     try:
         self.image=self.cs.images.find(id=self.image_id)
     except exc.NotFound, e:
         log("The image id is incorrect")
         ret=False
Example #12
0
    def check(self):
        debug("check start")

        try:
            self.clb.find(name=self.lb_name) 
            log("found lb %s, please remove it before reruning the script" % self.lb_name )
            ret = False
        except exc.NotFound, e:
            ret = True
Example #13
0
    def show(self):
        debug("show start")

        lb_properties = [ "name", "status", "created", "virtual_ips", "port", "protocol", "algorithm", "nodeCount" ]
        
        for prop in lb_properties : 
            log("lb %s : %s " % (prop, getattr(self.lb, prop)) )

        for n in self.nodes:
            log("Node: %s" % n.to_dict() )
Example #14
0
    def check_ssh_pub_key(self):
        debug("check_ssh_pub_key start")
        ret = True

        if self.ssh_public_key_name == None:
            try:
                self.ssh_public_key_name = "%s/.ssh/id_rsa.pub" % os.environ["HOME"]
            except Exception, e:
                ret=False
                log("Please specify a path to ssh public key")
                sys.exit(-1)
Example #15
0
 def run(self):
     debug("run start")
     ChallengeBase.run(self)
     
     if self.check(args) is False:
         self.usage()
         sys.exit(-1)
     
     log("Uploading directory %s to container %s" % (self.path, self.container))
     self.upload_dir(self.path) 
     self.wait_for_upload()
Example #16
0
    def set_container(self):
        debug("set_container start")

        fname = self.index_name

        c=self.cf.create_container(self.container_name)
        c.store_object(fname, self.index_file_data)
        c.make_public(ttl=300)
        c.set_web_index_page(fname)

        self.container=c
Example #17
0
    def upload_dir(self, path):
        debug("upload_dir start")

        try:
            cont = self.cf.get_container(self.container)
            log("container %s exists, all newly uploaded files will overwrite existing cloud files" %
                self.container)

        except exc.NoSuchContainer, e:
            log("container %s don't exists, create a new one ..." % (self.container,) )
            cont = self.cf.create_container(self.container)
Example #18
0
    def show(self, container_name):
        debug("show start")

        cont=self.get_container(container_name)
        log("cdn_enabled %s" % cont.cdn_enabled)
        log("cdn_ttl %s" % cont.cdn_ttl)
        log("cdn_uri %s" % cont.cdn_uri)
        log("cdn_ssl_uri %s" % cont.cdn_ssl_uri)
        log("cdn_streaming_uri %s" % cont.cdn_streaming_uri)
        log("cdn_ios_uri %s" % cont.cdn_ios_uri)

        return cont
Example #19
0
    def build_lb(self):
        debug("build_lb start")

        for s in self.servers :
            net = [ i["addr"] for i in s.addresses["private"] ] 
            net = utils.get_ipv4net(net)

            node = self.clb.Node(address=net, port=80, condition="ENABLED")
            self.nodes.append(node)

        self.vip = self.clb.VirtualIP(type="PUBLIC")
        self.lb = self.clb.create(self.lb_name, port=80, protocol="HTTP", nodes=self.nodes, virtual_ips=[self.vip])
Example #20
0
    def run(self):
        debug("run start")
        ChallengeBase.run(self)
        
        if self.check() is False:
            self.usage()
            sys.exit(-1)

        log("Creating container %s and uploading small %s file." %  (self.container_name, self.index_name) )
        self.set_container()
        self.set_dns()
        self.show()
Example #21
0
    def enable_cdn(self, container_name):
        debug("enable_cdn start")
        ret=True

        container = self.get_container(container_name)
        if container.cdn_enabled == False:
            container.make_public(ttl=1200)
        else:
            log("container %s is alrady CDN enabled")
            ret = False
        
        return ret
Example #22
0
    def wait_for_upload(self):
        debug("wait_for_upload start")

        total_bytes = self.total_bytes
        upload_key = self.upload_key

        print "Total bytes to upload:", total_bytes
        uploaded = 0
        while uploaded < total_bytes:
            uploaded = self.cf.get_uploaded(upload_key)
            print "Progress: %4.2f%%" % ((uploaded * 100.0) / total_bytes)
            time.sleep(1)
Example #23
0
    def check_blocks(self) :
        debug("check_storage start")
        ret = True

        for i in xrange(0, self.cs_count) :
            name="%s-%d" % (self.storage_name, i)
            try:
                storage=self.cbs.find(name=name)
                storage.delete()
                log("Deleted existing block storage image  %s" % name )
            except Exception, e:
                debug("There is not block storage with name %s" % name )
Example #24
0
    def show(self):
        debug("show start")

        log("-" * 70)
        log("vip name %s and ip %s" % (self.lb_name, self.vip_address) )
        
        for i in xrange(0, self.cs_count) :
            name= "%s-%d" % (self.server_prefix, i)
            log("cloud server %s added to pool as %s" % (name, self.nodes[i].address) )

        log("Error page is stored in container %s under name %s" % (self.container_name, self.error_page_name) )
        log("to check if the config works try to: curl -v http://%s" % self.vip_address)
Example #25
0
    def wait_for_lb_change(self):
        debug("wait_for_lb_change start")

        wait = WaitingForTask(self.check_lb, [self.lb_name], sleep_time=5, max_timeout=1)
        if wait.wait_for_tasks() == False: 
            log("Aborting as the build of lb is taking too long; all created objects will be deleted")
            
            for s in self.servers :
                s.delete()
            self.lb.delete()

            sys.exit(-1)
Example #26
0
    def check_cloud_servers(self):
        debug("check_cloud_servers start")
        ret = True

        for i in xrange(0, self.cs_count) :
            name= "%s-%d" % (self.server_prefix, i)
            try:
                c=self.cs.servers.find(name=name)
                c.delete()
                log("Deleted existing cloud server %s" % name )
            except Exception, e:
                debug("There is not cs with name %s" % name )
Example #27
0
    def check_existing_lb(self):
        debug("check_existing_lb start")
        ret = True

        try:
            lb=self.clb.find(name=self.lb_name) 
            if self.opt_delete :
                lb.delete()
            else :
                log("found lb %s, please remove it before reruning the script" % self.lb_name )
                ret = False
        except exc.NotFound, e:
            pass
Example #28
0
    def create_record(self, domain_name, ip_str) :
        debug("create_record start")

        # Substitute your actual domain name and IP addresses here
        a_rec = {"type": "A",
                "name": self.domain_record,
                "data": ip_str,
                "ttl": 6000
                }

        log("Adding records to our domain ...")
        recs = self.domain.add_records([a_rec])

        return True
Example #29
0
    def run(self):
        debug("run start")
        ChallengeBase.run(self)
        
        if self.check() is False:
            self.usage()
            sys.exit(-1)
        
        if self.create_domain(self.domain_name) == False:
            self.usage()
            sys.exit(-1)    

        if self.create_record(self.domain_name, self.ip_str) :
            self.show()
Example #30
0
    def check(self):
        debug("check start")
        ret = True

        if self.db_instance_name is None:
            self.db_instance_name = "challenge5-inst1"

        elif self.check_str(self.db_instance_name) == False:
            log("instance name `%s` incorrect, please use only alphanumeric and `-_.` chars" % self.db_instance_name)
            ret = False

        # http://docs.rackspace.com/cdb/api/v1.0/cdb-devguide/content/POST_createInstance__version___accountId__instances_.html
        if len(self.db_instance_name) > 255:
            log("instance name `%s` is too long (max 255 chars) " % self.db_instance_name)
            ret = False

        if ret:
            ret = self.delete_db_instance(self.db_instance_name)

        if self.dbs:
            for db in self.dbs:
                if self.check_str(db) == False:
                    log("db name `%s` incorrect, please use only alphanumeric and `-_.` chars" % db)
                    ret = False
        else:
            self.dbs = ["challenge5-db1", "challenge5-db2"]

        # http://docs.rackspace.com/cdb/api/v1.0/cdb-devguide/content/POST_createDatabase__version___accountId__instances__instanceId__databases_.html
        for db in self.dbs:
            if len(db) > 64:
                log("db name `%s` is too long (max 64 chars) " % db)
                ret = False

        if self.db_users:
            for user in self.db_users:
                if self.check_str(user) == False:
                    log("user name `%s` incorrect, please use only alphanumeric and `-_.` chars" % user)
                    ret = False
        else:
            self.db_users = ["challenge5-user1", "challenge5-user2"]

        # http://docs.rackspace.com/cdb/api/v1.0/cdb-devguide/content/POST_createUser__version___accountId__instances__instanceId__users_.html
        for u in self.db_users:
            if len(u) > 16:
                log("user name `%s` is too long (max 16 chars) " % u)
                ret = False

        debug("instance %s dbs %s users %s" % (self.db_instance_name, self.dbs, self.db_users))
        return ret