def __init__ (self, MAX_IMAGES=None, debug=0, args=[], optlist=[]):
        ChallengeBase.__init__(self, debug)

        self.message ="""
    usage: %s [-h] [-v] [-d] FQDN ip-add
        -h - usage help 
        -v - verbose / debug output 
        -d - if a domain exists it will be deleted first 

        FQDN - Fully Qualified Domain Name; exaple www.wikipedia.org
        ip-add - ip address
    """ % (PROGRAM_NAME)

        self.optlist = optlist
        self.args = args
        
        self.opt_delete_domain = False

        if "-d" in map(lambda x: x[0], optlist) :
            self.opt_delete_domain = True

        try:
            self.domain_record = self.args[0]
            self.domain_name =  ".".join( self.domain_record.split('.')[1:] )
            self.domain = None

            self.ip_str = self.args[1]

        except Exception, e:
            log("missing params")
            self.usage()
            sys.exit(-1)
    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")
    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 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()
    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()
    def __init__ (self, MAX_IMAGES=None, debug=0):
        ChallengeBase.__init__(self,debug)

        self.message ="""
    usage: %s [-h] [-v] dir-name container-name
        -h - usage help 
        -v - verbose / debug output 
        dir-name - a path to a directory
        container-name - upload the dir-name to this cloud container
    """ % (PROGRAM_NAME)

        self.optlist, self.args = None, None
    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()
    def __init__(self, debug_level=0, args=[], optlist=[]):
        ChallengeBase.__init__(self, debug_level)

        self.message = """
    usage: %s [-h] [-v] [ -i | -d ] [ -u db-user ] [ instance-name ] [ db-name1 [db-name2] ] 
        -h - usage help 
        -v - verbose / debug output 
        -i - if instance exists delete it and all its databases before proceeding 
        -d - delete database(s) from under the instance

        instance-name - create instance with this name 
        db-nameX - name of the database
        db-user - create user that can access the database; by default a user name is equal to db-name
    """ % (
            PROGRAM_NAME
        )

        self.optlist = optlist
        self.args = args

        self.db_users = None
        self.dbs = []

        self.db_instance_name = None
        self.db_instance = None

        self.opt_delete_instance = False
        self.opt_delete_db = False

        for o, val in optlist:
            if o == "-i":
                self.opt_delete_instance = True
            elif o == "-d":
                self.opt_delete_db = True
            elif o == "-u":
                self.db_users = [val]

        try:
            self.db_instance_name = self.args[0]
            self.dbs = self.args[1:]

        except Exception, e:
            pass
    def __init__ (self, debug_level=0, args=[], optlist=[]) :
        ChallengeBase.__init__(self, debug_level)

        self.message ="""
    usage: %s [-h] [-v] 
        -h - usage help 
        -v - verbose / debug output 
    """ % (PROGRAM_NAME)

        self.optlist = optlist
        self.args = args

        self.cs_count = 2
        self.servers = []

        self.nodes=[]
        self.lb=None
        self.lb_name="challenge7-vip"
        self.vip=None
    def run(self):
        debug("run start")
        ChallengeBase.run(self)
        
        if self.check() is False:
            self.usage()
            sys.exit(-1)

        self.check()

        log("Building %d cloud servers" % self.cs_count)
        self.build_cs()

        log("Building and configuring lb ...")
        self.build_lb()

        log("Building and configuring dns domain ...")
        self.build_dns()

        self.show()
    def run(self):
        debug("run start")
        ChallengeBase.run(self)

        if self.check() is False:
            self.usage()
            sys.exit(-1)

        log("Creating instance %s" % self.db_instance_name)
        self.create_db_instance(self.db_instance_name)

        log("Waiting for the instance to be built ...")
        self.wait_for_instance_build()
        log("Instance is created on host %s" % self.db_instance.hostname)

        log("Creating databases %s under the instance %s" % (self.dbs, self.db_instance_name))
        self.create_dbs()

        log("Creating users %s" % (self.db_users))
        self.create_users()
    def __init__ (self, debug_level=0, args=[], optlist=[]) :
        ChallengeBase.__init__(self, debug_level)

        self.message ="""
    usage: %s [-h] [-v] container-name
        -h - usage help 
        -v - verbose / debug output 
        
        container-name - name of the container
    """ % (PROGRAM_NAME)

        self.optlist = optlist
        self.args = args

        try:
            self.container = None
            self.container_name = self.args[0]

        except Exception, e:
            self.container_name = None
    def run(self):
        debug("run start")
        ChallengeBase.run(self)
        
        if self.check() is False:
            self.usage()
            sys.exit(-1)

        log("Building %d cloud servers" % self.cs_count)
        
        mycs=CloudServers(self.cs_count, "challenge7")
        self.servers = mycs.get_servers()

        log("Building and configuring lb ...")
        self.build_lb()

        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; created lb and cloud servers will be deleted")
            self.delete_all()
            sys.exit(-1)

        self.show()
    def __init__ (self, debug_level=0, args=[], optlist=[]) :
        ChallengeBase.__init__(self, debug_level)

        self.message ="""
    usage: %s [-h] [-v] 
        -h - usage help 
        -v - verbose / debug output 
    """ % (PROGRAM_NAME)

        self.optlist = optlist
        self.args = args

        self.container_name = "challenge8"
        self.container = None
        self.index_name = "index.html"
        self.index_file_data = "Hello challenge8, it works!\n"

        self.domain_name = "rado-challenge.org"
        self.domain = None
        self.recs = None

        self.rec_CNAME = None
        self.rec_CNAME_data = None
    def __init__ (self, debug_level=0, args=[], optlist=[]) :
        ChallengeBase.__init__(self, debug_level)

        self.message ="""
    usage: %s [-h] [-v] -n FQDN-name -i image-id -f flavor-id
        -h - usage help 
        -v - verbose / debug output 
        -n - FQDN name
        -i - proper image id
        -f - flavor id 
    """ % (PROGRAM_NAME)

        self.optlist = optlist
        self.args = args

        self.server = None
        self.image = None
        self.flavor = None

        (self.fqdn_name, self.image_id, self.flavor_id)  = (None, None, None)

        for o, val in optlist:
            if o == "-n":
                self.fqdn_name = val
                self.domain_name =  ".".join( self.fqdn_name.split('.')[1:] )
                self.domain=None
                self.recs = None
                self.net=None

            elif o == "-i":
                self.image_id = val
            elif o == "-f":
                self.flavor_id = val

        if not ( self.fqdn_name and self.image_id and self.flavor_id) :
            self.usage()
            sys.exit(-1)
    def run(self):
        debug("run start")
        ChallengeBase.run(self)
        
        if self.check() is False:
            self.usage()
            sys.exit(-1)

        log("Building %d cloud servers" % self.cs_count)
        files={'/root/.ssh/authorized_keys': self.ssh_public_key }
        mycs=CloudServers(self.cs_count, self.server_prefix, image=self.image_id, flavor=self.flavor_id, 
                files=files )
        self.servers = mycs.get_servers()

        log("Building and configuring lb ...")
        self.build_lb()

        log("Building and configuring dns domain ...")
        self.build_dns()

        log("Backuping files to cloud files ...")
        self.backup_to_cloud_files()

        self.show()
    def __init__ (self, debug_level=0, args=[], optlist=[]) :
        ChallengeBase.__init__(self, debug_level)

        self.message ="""
    usage: %s [-h] [-v] [-d] [ -k key-key  ] [ -c cert ] [ -i image-id ]\
[ -f flavor-id ] -n FQDN-name  

    image-id -f flavor-id
        -h - usage help 
        -v - verbose / debug output 
        -d - delete objects if they existed in cloud before creating new one
        -k - certificate pritate key (see -c below)
        -c - public certificate ( see -k above)
        -n - FQDN name like www.myexample.com
        -i - specify image-id or use the default for Ubuntu 10.04
        -f - specify flavor-id or use the default for the smallest cloud server
    """ % (PROGRAM_NAME) 

        self.cert_use_default = False
        self.cert_key_name = None
        self.cert_key = None
        self.cert_name = None
        self.cert = None

        self.opt_delete = False

        self.fqdn_name = None
        self.domain_name = None
        self.domain = None
        self.recs = None

        self.lb=None
        self.lb_name = None
        self.vip=None
        self.vip_address = None
        self.nodes=[]

        self.image = None
        self.image_id = None

        self.flavor = None
        self.flavor_id = None

        self.server_prefix=None
        self.cs_count=3
        self.server_passord = "SecretP@ss1"
        self.servers = []

        self.storage_name = None
        self.volumes=[]

        self.network_name = None
        self.network_range = "192.168.100.0/24"
        self.network = None
        self.network_id = None


        for o, val in optlist:
            if o == "-n":
                self.fqdn_name = val
                self.domain_name =  ".".join( self.fqdn_name.split('.')[1:] )
                self.domain=None
                self.recs = None
            elif o == "-d":
                self.opt_delete = True
            elif o == "-i":
                self.image_id = val
            elif o == "-f":
                self.flavor_id = val
            elif o == "-k":
                self.cert_key_name = val
            elif o == "-c":
                self.cert_name = val
            elif o == "-i":
                self.image_id = val
            elif o == "-f":
                self.flavor_id = val

        if not self.fqdn_name :
            self.usage()
            sys.exit(-1)

        #default values for some variables 

        self.image = None
        if not self.image_id :
            self.image_id = utils.get_image(self.cs)
        
        self.flavor= None
        if not self.flavor_id :
            self.flavor_id = utils.get_flavor(self.cs)

        self.lb_name = self.fqdn_name
        self.storage_name = self.fqdn_name
        self.server_prefix = self.fqdn_name
        self.network_name = self.fqdn_name

        if not self.cert_key_name and not self.cert_name :
            self.cert_use_default = True
            self.cert_key_name = self.fqdn_name + ".key"
            self.cert_key="""-----BEGIN RSA PRIVATE KEY-----
MIICXAIBAAKBgQCypZq3lUHWhBjDxV6hOtOQFI3WvcGlp9RP+ZHVTcwDb/buaGIL
99xCUabM5TIjzfSMthddEb+43RIdZeaXSnqV0Ut+xF9fPIHiky+DrOS2i77ltu67
RGTerezjM36D4TW5N3vQOR+qIezp1yko1qJr5hROp2ykqcgIL5GzR4980QIDAQAB
AoGBAKIZyKDqa3pGFN6XWf18jnn/XJDNUEiLWAhVkfF2DTfVQcAksUrg1ljLFEp5
chyxBkUj+WE2+Lu6xXQtgaYoK7/+mRRpKEZ6aHEsd5KqoVgxp2igyRZOGyVWaAJ3
loi+GmMiRkjC6o6xxNGG7UNfXSACfbB8eEBaGw61ZhbZJ28NAkEA5rVk/mqQFYzO
WynHT1DUz4YeIpj1ZAnhjn/957knU61VoAjeruLANOmN5bQ2gCKJm7MsPJ11iAdp
Cfltaprq7wJBAMY7Jp0hQBWOp3J1VNTkeG23At/ZQv5QzkUih2hcHjXy54RYqFe/
pIH9qrLC01BjhG2PePrJwaKMmhl7TvQ7FD8CQHmG7848n+1aIJFQ7pZPQ+qVAWbE
H+80bUY9EahwldC0K7iDM5n4A7tbk81+In9Yshf8R78eSnz/Oktwwjw3oq0CQEyZ
3PEJQUdTSdeMCYz/AJ59AwpXXXEC7sJ+dk7YkgAM7nQRAnRuJPbqfET5zkiZPDpO
H9ThlAbpSD8ijD8KeWcCQBxun2xWhCH19BulbUufsocKrwaxAijJ4pc5fX+cabEU
Na05oMyXQxN2tR4gWlbyVrGuZPVRDH39oRej5z2/JUA=
-----END RSA PRIVATE KEY-----
"""
        self.cert_name = self.fqdn_name + ".crt"
        self.cert = """-----BEGIN CERTIFICATE-----
    def __init__ (self, debug_level=0, args=[], optlist=[]) :
        ChallengeBase.__init__(self, debug_level)

        self.message ="""
    usage: %s [-h] [-v] [-d] [ -s ssh-key ] [ -e error-page ] [ -c container-name ] [ -i image-id ] [ -f flavor-id ] -n FQDN-name  

    image-id -f flavor-id
        -h - usage help 
        -v - verbose / debug output 
        -d - delete objects if they existed in cloud before creating new one
        -n - FQDN name like www.myexample.com
        -s - path to your ssh public key (not priv!)
        -e - path to a html file that will be served from the LB when all pool members are down
        -c - name of cloud files container-name to store the backup data
        -i - specify image-id or use the default for Ubuntu 10.04
        -f - specify flavor-id or use the default for the smallest cloud server
    """ % (PROGRAM_NAME)

        self.optlist = optlist
        self.args = args

        self.opt_delete = False

        self.fqdn_name = None
        self.domain_name = None
        self.domain = None
        self.recs = None

        self.ssh_public_key_name = None
        self.ssh_public_key = None

        self.error_page_name = None
        self.error_page_path = None
        self.error_page = None

        self.container_name = None
        self.container = None

        self.image = None
        self.image_id = None

        self.flavor = None
        self.flavor_id = None

        self.server_prefix=None
        self.cs_count=2
        self.servers = []
        
        self.lb=None
        self.lb_name =None
        self.vip=None
        self.vip_address = None
        self.nodes=[]

        for o, val in optlist:
            if o == "-n":
                self.fqdn_name = val
                self.domain_name =  ".".join( self.fqdn_name.split('.')[1:] )
                self.domain=None
                self.recs = None
            elif o == "-s":
                self.ssh_public_key_name = val
            elif o == "-e":
                self.error_page_path = val
            elif o == "-d":
                self.opt_delete = True
            elif o == "-c":
                self.container_name = val
            elif o == "-i":
                self.image_id = val
            elif o == "-f":
                self.flavor_id = val

        if not self.fqdn_name :
            self.usage()
            sys.exit(-1)

        #default values for some variables 

        if not self.container_name :
            self.container_name = self.fqdn_name 

        self.image = None
        if not self.image_id :
            self.image_id = utils.get_image(self.cs)
        
        self.flavor= None
        if not self.flavor_id :
            self.flavor_id = utils.get_flavor(self.cs)

        self.lb_name = self.fqdn_name

        self.server_prefix = self.fqdn_name