예제 #1
0
 def _delete_object(self, id, etag, resource):
     uri = '/%s/%s/%s' % (self.Version, resource, id)
     response = self.make_request('DELETE', uri, {'If-Match': etag})
     body = response.read()
     fcu_boto.log.debug(body)
     if response.status != 204:
         raise CloudFrontServerError(response.status, response.reason, body)
예제 #2
0
 def _get_config(self, id, resource, config_class):
     uri = '/%s/%s/%s/config' % (self.Version, resource, id)
     response = self.make_request('GET', uri)
     body = response.read()
     fcu_boto.log.debug(body)
     if response.status >= 300:
         raise CloudFrontServerError(response.status, response.reason, body)
     d = config_class(connection=self)
     d.etag = self.get_etag(response)
     h = handler.XmlHandler(d, self)
     xml.sax.parseString(body, h)
     return d
예제 #3
0
 def _set_config(self, distribution_id, etag, config):
     if isinstance(config, StreamingDistributionConfig):
         resource = 'streaming-distribution'
     else:
         resource = 'distribution'
     uri = '/%s/%s/%s/config' % (self.Version, resource, distribution_id)
     headers = {'If-Match': etag, 'Content-Type': 'text/xml'}
     response = self.make_request('PUT', uri, headers, config.to_xml())
     body = response.read()
     fcu_boto.log.debug(body)
     if response.status != 200:
         raise CloudFrontServerError(response.status, response.reason, body)
     return self.get_etag(response)
예제 #4
0
 def invalidation_request_status(self,
                                 distribution_id,
                                 request_id,
                                 caller_reference=None):
     uri = '/%s/distribution/%s/invalidation/%s' % (
         self.Version, distribution_id, request_id)
     response = self.make_request('GET', uri, {'Content-Type': 'text/xml'})
     body = response.read()
     if response.status == 200:
         paths = InvalidationBatch([])
         h = handler.XmlHandler(paths, self)
         xml.sax.parseString(body, h)
         return paths
     else:
         raise CloudFrontServerError(response.status, response.reason, body)
예제 #5
0
 def _create_object(self, config, resource, dist_class):
     response = self.make_request('POST',
                                  '/%s/%s' % (self.Version, resource),
                                  {'Content-Type': 'text/xml'},
                                  data=config.to_xml())
     body = response.read()
     fcu_boto.log.debug(body)
     if response.status == 201:
         d = dist_class(connection=self)
         h = handler.XmlHandler(d, self)
         xml.sax.parseString(body, h)
         d.etag = self.get_etag(response)
         return d
     else:
         raise CloudFrontServerError(response.status, response.reason, body)
예제 #6
0
 def _get_info(self, id, resource, dist_class):
     uri = '/%s/%s/%s' % (self.Version, resource, id)
     response = self.make_request('GET', uri)
     body = response.read()
     fcu_boto.log.debug(body)
     if response.status >= 300:
         raise CloudFrontServerError(response.status, response.reason, body)
     d = dist_class(connection=self)
     response_headers = response.msg
     for key in response_headers.keys():
         if key.lower() == 'etag':
             d.etag = response_headers[key]
     h = handler.XmlHandler(d, self)
     xml.sax.parseString(body, h)
     return d
예제 #7
0
 def _get_all_objects(self,
                      resource,
                      tags,
                      result_set_class=None,
                      result_set_kwargs=None):
     if not tags:
         tags = [('DistributionSummary', DistributionSummary)]
     response = self.make_request('GET',
                                  '/%s/%s' % (self.Version, resource))
     body = response.read()
     fcu_boto.log.debug(body)
     if response.status >= 300:
         raise CloudFrontServerError(response.status, response.reason, body)
     rs_class = result_set_class or ResultSet
     rs_kwargs = result_set_kwargs or dict()
     rs = rs_class(tags, **rs_kwargs)
     h = handler.XmlHandler(rs, self)
     xml.sax.parseString(body, h)
     return rs
예제 #8
0
 def create_invalidation_request(self,
                                 distribution_id,
                                 paths,
                                 caller_reference=None):
     """Creates a new invalidation request
         :see: http://goo.gl/8vECq
     """
     # We allow you to pass in either an array or
     # an InvalidationBatch object
     if not isinstance(paths, InvalidationBatch):
         paths = InvalidationBatch(paths)
     paths.connection = self
     uri = '/%s/distribution/%s/invalidation' % (self.Version,
                                                 distribution_id)
     response = self.make_request('POST',
                                  uri, {'Content-Type': 'text/xml'},
                                  data=paths.to_xml())
     body = response.read()
     if response.status == 201:
         h = handler.XmlHandler(paths, self)
         xml.sax.parseString(body, h)
         return paths
     else:
         raise CloudFrontServerError(response.status, response.reason, body)