示例#1
0
 def get_slowdown_data(self):
     if time() - self.last_get > 10:
         try:
             self._slowdown_data = json.load(open(self.data_file))
         except (ValueError, IOError):
             self._slowdown_data = {}
         self.last_get = time()
     return self._slowdown_data
示例#2
0
 def REPLICATE(self, req):
     """
     Handle HTTP REPLICATE request (json-encoded RPC calls for replication.)
     """
     post_args = split_and_validate_path(req, 3)
     drive, partition, hash = post_args
     if self.mount_check and not check_mount(self.root, drive):
         return HTTPInsufficientStorage(drive=drive, request=req)
     try:
         args = json.load(req.environ['wsgi.input'])
     except ValueError, err:
         return HTTPBadRequest(body=str(err), content_type='text/plain')
示例#3
0
文件: server.py 项目: r0mik/swift
 def REPLICATE(self, req):
     """
     Handle HTTP REPLICATE request (json-encoded RPC calls for replication.)
     """
     post_args = split_and_validate_path(req, 3)
     drive, partition, hash = post_args
     if self.mount_check and not check_mount(self.root, drive):
         return HTTPInsufficientStorage(drive=drive, request=req)
     try:
         args = json.load(req.environ['wsgi.input'])
     except ValueError, err:
         return HTTPBadRequest(body=str(err), content_type='text/plain')
示例#4
0
 def REPLICATE(self, req):
     """
     Handle HTTP REPLICATE request.
     Handler for RPC calls for account replication.
     """
     post_args = split_and_validate_path(req, 3)
     drive, partition, hash = post_args
     if self.mount_check and not check_mount(self.root, drive):
         return HTTPInsufficientStorage(drive=drive, request=req)
     try:
         args = json.load(req.environ["wsgi.input"])
     except ValueError as err:
         return HTTPBadRequest(body=str(err), content_type="text/plain")
     ret = self.replicator_rpc.dispatch(post_args, args)
     ret.request = req
     return ret
示例#5
0
文件: server.py 项目: yinyalan/swift
 def REPLICATE(self, req):
     """
     Handle HTTP REPLICATE request.
     Handler for RPC calls for account replication.
     """
     post_args = split_and_validate_path(req, 3)
     drive, partition, hash = post_args
     if not check_drive(self.root, drive, self.mount_check):
         return HTTPInsufficientStorage(drive=drive, request=req)
     try:
         args = json.load(req.environ['wsgi.input'])
     except ValueError as err:
         return HTTPBadRequest(body=str(err), content_type='text/plain')
     ret = self.replicator_rpc.dispatch(post_args, args)
     ret.request = req
     return ret
示例#6
0
文件: recon.py 项目: zhanghua/swift
    def _from_recon_cache(self, cache_keys, cache_file, openr=open):
        """retrieve values from a recon cache file

        :params cache_keys: list of cache items to retrieve
        :params cache_file: cache file to retrieve items from.
        :params openr: open to use [for unittests]
        :return: dict of cache items and their value or none if not found
        """
        try:
            with openr(cache_file, 'r') as f:
                recondata = json.load(f)
                return dict((key, recondata.get(key)) for key in cache_keys)
        except IOError:
            self.logger.exception(_('Error reading recon cache file'))
        except ValueError:
            self.logger.exception(_('Error parsing recon cache file'))
        except Exception:
            self.logger.exception(_('Error retrieving recon data'))
        return dict((key, None) for key in cache_keys)
示例#7
0
文件: recon.py 项目: CiscoAS/swift
    def _from_recon_cache(self, cache_keys, cache_file, openr=open):
        """retrieve values from a recon cache file

        :params cache_keys: list of cache items to retrieve
        :params cache_file: cache file to retrieve items from.
        :params openr: open to use [for unittests]
        :return: dict of cache items and their value or none if not found
        """
        try:
            with openr(cache_file, 'r') as f:
                recondata = json.load(f)
                return dict((key, recondata.get(key)) for key in cache_keys)
        except IOError:
            self.logger.exception(_('Error reading recon cache file'))
        except ValueError:
            self.logger.exception(_('Error parsing recon cache file'))
        except Exception:
            self.logger.exception(_('Error retrieving recon data'))
        return dict((key, None) for key in cache_keys)
示例#8
0
文件: server.py 项目: waiterZen/swift
        Handler for RPC calls for account replication.
        """
        start_time = time.time()
        try:
            post_args = split_path(unquote(req.path), 3)
            drive, partition, hash = post_args
            validate_device_partition(drive, partition)
        except ValueError, err:
            self.logger.increment('REPLICATE.errors')
            return HTTPBadRequest(body=str(err), content_type='text/plain',
                                  request=req)
        if self.mount_check and not check_mount(self.root, drive):
            self.logger.increment('REPLICATE.errors')
            return HTTPInsufficientStorage(drive=drive, request=req)
        try:
            args = json.load(req.environ['wsgi.input'])
        except ValueError, err:
            self.logger.increment('REPLICATE.errors')
            return HTTPBadRequest(body=str(err), content_type='text/plain')
        ret = self.replicator_rpc.dispatch(post_args, args)
        ret.request = req
        self.logger.timing_since('REPLICATE.timing', start_time)
        return ret

    @public
    def POST(self, req):
        """Handle HTTP POST request."""
        start_time = time.time()
        try:
            drive, part, account = split_path(unquote(req.path), 3)
            validate_device_partition(drive, part)
示例#9
0
文件: server.py 项目: DylanYu/swift
    @public
    @timing_stats
    def REPLICATE(self, req):
        """
        Handle HTTP REPLICATE request (json-encoded RPC calls for replication.)
        """
        try:
            post_args = split_path(unquote(req.path), 3)
            drive, partition, hash = post_args
            validate_device_partition(drive, partition)
        except ValueError, err:
            return HTTPBadRequest(body=str(err), content_type="text/plain", request=req)
        if self.mount_check and not check_mount(self.root, drive):
            return HTTPInsufficientStorage(drive=drive, request=req)
        try:
            args = json.load(req.environ["wsgi.input"])
        except ValueError, err:
            return HTTPBadRequest(body=str(err), content_type="text/plain")
        ret = self.replicator_rpc.dispatch(post_args, args)
        ret.request = req
        return ret

    @public
    @timing_stats
    def POST(self, req):
        """Handle HTTP POST request."""
        try:
            drive, part, account, container = split_path(unquote(req.path), 4)
            validate_device_partition(drive, part)
        except ValueError, err:
            return HTTPBadRequest(body=str(err), content_type="text/plain", request=req)