Ejemplo n.º 1
0
 def CreateDistribution(self,
                        uri,
                        cnames_add=[],
                        comment=None,
                        logging=None,
                        default_root_object=None):
     dist_config = DistributionConfig()
     dist_config.info['Enabled'] = True
     dist_config.info['S3Origin']['DNSName'] = uri.host_name()
     dist_config.info['CallerReference'] = str(uri)
     dist_config.info['DefaultRootObject'] = default_root_object
     if comment == None:
         dist_config.info['Comment'] = uri.public_url()
     else:
         dist_config.info['Comment'] = comment
     for cname in cnames_add:
         if dist_config.info['CNAME'].count(cname) == 0:
             dist_config.info['CNAME'].append(cname)
     if logging:
         dist_config.info['Logging'] = S3UriS3(logging)
     request_body = str(dist_config)
     debug("CreateDistribution(): request_body: %s" % request_body)
     response = self.send_request("CreateDist", body=request_body)
     response['distribution'] = Distribution(response['data'])
     return response
Ejemplo n.º 2
0
 def ModifyDistribution(self,
                        cfuri,
                        cnames_add=[],
                        cnames_remove=[],
                        comment=None,
                        enabled=None,
                        logging=None,
                        default_root_object=None):
     if cfuri.type != "cf":
         raise ValueError("Expected CFUri instead of: %s" % cfuri)
     # Get current dist status (enabled/disabled) and Etag
     info("Checking current status of %s" % cfuri)
     response = self.GetDistConfig(cfuri)
     dc = response['dist_config']
     if enabled != None:
         dc.info['Enabled'] = enabled
     if comment != None:
         dc.info['Comment'] = comment
     if default_root_object != None:
         dc.info['DefaultRootObject'] = default_root_object
     for cname in cnames_add:
         if dc.info['CNAME'].count(cname) == 0:
             dc.info['CNAME'].append(cname)
     for cname in cnames_remove:
         while dc.info['CNAME'].count(cname) > 0:
             dc.info['CNAME'].remove(cname)
     if logging != None:
         if logging == False:
             dc.info['Logging'] = False
         else:
             dc.info['Logging'] = S3UriS3(logging)
     response = self.SetDistConfig(cfuri, dc, response['headers']['etag'])
     return response
Ejemplo n.º 3
0
 def parse(self, tree):
     self.info = getDictFromTree(tree)
     self.info['Enabled'] = (self.info['Enabled'].lower() == "true")
     if not self.info.has_key("CNAME"):
         self.info['CNAME'] = []
     if type(self.info['CNAME']) != list:
         self.info['CNAME'] = [self.info['CNAME']]
     self.info['CNAME'] = [cname.lower() for cname in self.info['CNAME']]
     if not self.info.has_key("Comment"):
         self.info['Comment'] = ""
     if not self.info.has_key("DefaultRootObject"):
         self.info['DefaultRootObject'] = ""
     ## Figure out logging - complex node not parsed by getDictFromTree()
     logging_nodes = tree.findall(".//Logging")
     if logging_nodes:
         logging_dict = getDictFromTree(logging_nodes[0])
         logging_dict['Bucket'], success = getBucketFromHostname(
             logging_dict['Bucket'])
         if not success:
             warning("Logging to unparsable bucket name: %s" %
                     logging_dict['Bucket'])
         self.info['Logging'] = S3UriS3(u"s3://%(Bucket)s/%(Prefix)s" %
                                        logging_dict)
     else:
         self.info['Logging'] = None