Example #1
0
 def __call__(self, env, start_response):
     if env['REQUEST_METHOD'] == 'GET':
         if self.status == 200:
             start_response(Response().status)
             start_response({'Content-Type': 'text/xml'})
             json_pattern = [
                 '"name":%s', '"last_modified":%s', '"hash":%s',
                 '"bytes":%s'
             ]
             json_pattern = '{' + ','.join(json_pattern) + '}'
             json_out = []
             for b in self.objects:
                 name = simplejson.dumps(b[0])
                 time = simplejson.dumps(b[1])
                 json_out.append(json_pattern % (name, time, b[2], b[3]))
             account_list = '[' + ','.join(json_out) + ']'
             return account_list
         elif self.status == 401:
             start_response(HTTPUnauthorized().status)
             start_response({})
         elif self.status == 404:
             start_response(HTTPNotFound().status)
             start_response({})
         else:
             start_response(HTTPBadRequest().status)
             start_response({})
     elif env['REQUEST_METHOD'] == 'PUT':
         if self.status == 201:
             start_response(HTTPCreated().status)
             start_response({})
         elif self.status == 401:
             start_response(HTTPUnauthorized().status)
             start_response({})
         elif self.status == 202:
             start_response(HTTPAccepted().status)
             start_response({})
         else:
             start_response(HTTPBadRequest().status)
             start_response({})
     elif env['REQUEST_METHOD'] == 'DELETE':
         if self.status == 204:
             start_response(HTTPNoContent().status)
             start_response({})
         elif self.status == 401:
             start_response(HTTPUnauthorized().status)
             start_response({})
         elif self.status == 404:
             start_response(HTTPNotFound().status)
             start_response({})
         elif self.status == 409:
             start_response(HTTPConflict().status)
             start_response({})
         else:
             start_response(HTTPBadRequest().status)
             start_response({})
Example #2
0
 def __call__(self, env, start_response):
     if env['REQUEST_METHOD'] == 'GET' or env['REQUEST_METHOD'] == 'HEAD':
         if self.status == 200:
             start_response(Response().status)
             start_response(self.response_headers)
             if env['REQUEST_METHOD'] == 'GET':
                 return self.object_body
         elif self.status == 401:
             start_response(HTTPUnauthorized().status)
             start_response({})
         elif self.status == 404:
             start_response(HTTPNotFound().status)
             start_response({})
         else:
             start_response(HTTPBadRequest().status)
             start_response({})
     elif env['REQUEST_METHOD'] == 'PUT':
         if self.status == 201:
             start_response(HTTPCreated().status)
             start_response({'etag': self.response_headers['etag']})
         elif self.status == 401:
             start_response(HTTPUnauthorized().status)
             start_response({})
         elif self.status == 404:
             start_response(HTTPNotFound().status)
             start_response({})
         else:
             start_response(HTTPBadRequest().status)
             start_response({})
     elif env['REQUEST_METHOD'] == 'DELETE':
         if self.status == 204:
             start_response(HTTPNoContent().status)
             start_response({})
         elif self.status == 401:
             start_response(HTTPUnauthorized().status)
             start_response({})
         elif self.status == 404:
             start_response(HTTPNotFound().status)
             start_response({})
         else:
             start_response(HTTPBadRequest().status)
             start_response({})
Example #3
0
 def PUT(self, req):
     print 'here is put'
     conn = HTTPConnection('localhost', '9000')
     conn.path=req.path
     conn.putrequest('PUT', req.path)
     headers = req.headers
     if headers:
         for header, value in headers.iteritems():
             conn.putheader(header, value)
     conn.endheaders()
     response = conn.getresponse()
     status = response.status
     reason = response.reason
     body = response.read()
     resp = Response(request=req)
     resp.status = status
     resp.body = body
     resp.content_type = 'text/plain'
     return resp
     return HTTPCreated(request=req)
     return 'finished'
Example #4
0
 def __call__(self, env, start_response):
     if env['REQUEST_METHOD'] == 'GET' or env['REQUEST_METHOD'] == 'HEAD':
         if self.status == 200:
             if 'HTTP_RANGE' in env:
                 resp = Response(body=self.object_body,
                                 conditional_response=True)
                 return resp(env, start_response)
             start_response(Response().status,
                            self.response_headers.items())
             if env['REQUEST_METHOD'] == 'GET':
                 return self.object_body
         elif self.status == 401:
             start_response(HTTPUnauthorized().status, [])
         elif self.status == 404:
             start_response(HTTPNotFound().status, [])
         else:
             start_response(HTTPBadRequest().status, [])
     elif env['REQUEST_METHOD'] == 'PUT':
         if self.status == 201:
             start_response(HTTPCreated().status,
                            [('etag', self.response_headers['etag'])])
         elif self.status == 401:
             start_response(HTTPUnauthorized().status, [])
         elif self.status == 404:
             start_response(HTTPNotFound().status, [])
         else:
             start_response(HTTPBadRequest().status, [])
     elif env['REQUEST_METHOD'] == 'DELETE':
         if self.status == 204:
             start_response(HTTPNoContent().status, [])
         elif self.status == 401:
             start_response(HTTPUnauthorized().status, [])
         elif self.status == 404:
             start_response(HTTPNotFound().status, [])
         else:
             start_response(HTTPBadRequest().status, [])
     return []
Example #5
0
                if old_delete_at:
                    self.delete_at_update('DELETE', old_delete_at, account,
                        container, obj, request.headers, device)
            file.put(fd, tmppath, metadata)
        file.unlinkold(metadata['X-Timestamp'])
        if not orig_timestamp or \
                orig_timestamp < request.headers['x-timestamp']:
            self.container_update('PUT', account, container, obj,
                request.headers,
                {'x-size': file.metadata['Content-Length'],
                 'x-content-type': file.metadata['Content-Type'],
                 'x-timestamp': file.metadata['X-Timestamp'],
                 'x-etag': file.metadata['ETag'],
                 'x-trans-id': request.headers.get('x-trans-id', '-')},
                device)
        resp = HTTPCreated(request=request, etag=etag)
        return resp

    def GET(self, request):
        """Handle HTTP GET requests for the Swift Object Server."""
        try:
            device, partition, account, container, obj = \
                split_path(unquote(request.path), 5, 5, True)
        except ValueError, err:
            return HTTPBadRequest(body=str(err), request=request,
                        content_type='text/plain')
        if self.mount_check and not check_mount(self.devices, device):
            return HTTPInsufficientStorage(drive=device, request=request)
        file = DiskFile(self.devices, device, partition, account, container,
                        obj, self.logger, keep_data_fp=True,
                        disk_chunk_size=self.disk_chunk_size)
Example #6
0
 broker = self._get_account_broker(drive, part, account)
 if container:  # put account container
     if 'x-cf-trans-id' in req.headers:
         broker.pending_timeout = 3
     if req.headers.get('x-account-override-deleted', 'no').lower() != \
             'yes' and broker.is_deleted():
         return HTTPNotFound(request=req)
     broker.put_container(container, req.headers['x-put-timestamp'],
                          req.headers['x-delete-timestamp'],
                          req.headers['x-object-count'],
                          req.headers['x-bytes-used'])
     if req.headers['x-delete-timestamp'] > \
             req.headers['x-put-timestamp']:
         return HTTPNoContent(request=req)
     else:
         return HTTPCreated(request=req)
 else:  # put account
     timestamp = normalize_timestamp(req.headers['x-timestamp'])
     if not os.path.exists(broker.db_file):
         broker.initialize(timestamp)
         created = True
     elif broker.is_status_deleted():
         return HTTPForbidden(request=req, body='Recently deleted')
     else:
         created = broker.is_deleted()
         broker.update_put_timestamp(timestamp)
         if broker.is_deleted():
             return HTTPConflict(request=req)
     metadata = {}
     metadata.update((key, (value, timestamp))
                     for key, value in req.headers.iteritems()
Example #7
0
                    self.delete_at_update('DELETE', old_delete_at, account,
                                          container, obj, request.headers,
                                          device)
            file.put(fd, tmppath, metadata)
        file.unlinkold(metadata['X-Timestamp'])
        if not orig_timestamp or \
                orig_timestamp < request.headers['x-timestamp']:
            self.container_update(
                'PUT', account, container, obj, request.headers, {
                    'x-size': file.metadata['Content-Length'],
                    'x-content-type': file.metadata['Content-Type'],
                    'x-timestamp': file.metadata['X-Timestamp'],
                    'x-etag': file.metadata['ETag'],
                    'x-trans-id': request.headers.get('x-trans-id', '-')
                }, device)
        resp = HTTPCreated(request=request, etag=etag)
        return resp

    def GET(self, request):
        """Handle HTTP GET requests for the Chase Object Server."""
        try:
            device, partition, account, container, obj = \
                split_path(unquote(request.path), 5, 5, True)
        except ValueError, err:
            return HTTPBadRequest(body=str(err),
                                  request=request,
                                  content_type='text/plain')
        if self.mount_check and not check_mount(self.devices, device):
            return Response(status='507 %s is not mounted' % device)
        file = DiskFile(self.devices,
                        device,
Example #8
0
            if request.headers['content-type'].lower() == DIR_TYPE:
                metadata.update({X_OBJECT_TYPE: MARKER_DIR})

            metadata.update(val for val in request.headers.iteritems()
                    if val[0].lower().startswith('x-object-meta-') and
                    len(val[0]) > 14)
            for header_key in self.allowed_headers:
                if header_key in request.headers:
                    header_caps = header_key.title()
                    metadata[header_caps] = request.headers[header_key]
            if not file_obj.put(fd, tmppath, metadata):
                logging.error('Object put failed %s %s %s' % (account, container, obj))
                return HTTPUnprocessableEntity(request=request)

        resp = HTTPCreated(request=request, etag=etag)
        return resp

    def GET(self, request):
        """Handle HTTP GET requests for the Swift Object Server."""
        try:
            device, partition, account, container, obj = \
                split_path(unquote(request.path), 5, 5, True)
        except ValueError, err:
            return HTTPBadRequest(body=str(err), request=request,
                        content_type='text/plain')
        if self.mount_check and not check_mount(self.devices, device):
            if not check_valid_account(account, self.fs_object):
                return Response(status='507 %s is not mounted' % device)
        file_obj = DiskFile(self.devices, device, partition, account, container,
                        obj, self.logger, keep_data_fp=True,
Example #9
0
 def PUTS(self, req):
     print 'here is put'
     return HTTPCreated(request=req)
     return 'finished'
Example #10
0
 def PUT(self, req):
     etag = 'etag'
     resp = HTTPCreated(request=req, etag=etag)
     return resp
Example #11
0
            self.container_update(
                "PUT",
                account,
                container,
                obj,
                request.headers,
                {
                    "x-size": file.metadata["Content-Length"],
                    "x-content-type": file.metadata["Content-Type"],
                    "x-timestamp": file.metadata["X-Timestamp"],
                    "x-etag": file.metadata["ETag"],
                    "x-trans-id": request.headers.get("x-trans-id", "-"),
                },
                device,
            )
        resp = HTTPCreated(request=request, etag=etag)
        self.logger.timing_since("PUT.timing", start_time)
        return resp

    @public
    def GET(self, request):
        """Handle HTTP GET requests for the Swift Object Server."""
        start_time = time.time()
        try:
            device, partition, account, container, obj = split_path(unquote(request.path), 5, 5, True)
            validate_device_partition(device, partition)
        except ValueError, err:
            self.logger.increment("GET.errors")
            return HTTPBadRequest(body=str(err), request=request, content_type="text/plain")
        if self.mount_check and not check_mount(self.devices, device):
            self.logger.increment("GET.errors")