def _make_block(self, offset): url, size = self._mlk_url(offset) url = https_check(url) headers = self.__generate_headers() try: mkblk_retries = int(self.cfg.mkblk_retries) except ValueError as e: warning( 'parameter mkblk_retries is invalid, so use default value 3') mkblk_retries = 3 with open(self.path, 'rb') as f: bput = readfile(f, offset, self.bput_size) blkcode, blktext, _ = _post(url=url, headers=headers, data=bput) while mkblk_retries and self.__need_retry(blkcode): blkcode, blktext, _ = _post(url=url, headers=headers, data=bput) mkblk_retries -= 1 if blkcode != 200: result = [offset, blkcode, blktext['message']] debug('make block fail,code :{0},message :{1}'.format( blkcode, blktext)) else: result = self._make_bput(f, blktext['ctx'], offset) self._record_upload_progress(result, size) return blkcode
def move(self, srcbucket, srckey, dstbucket, dstkey): url = self._make_move_url(srcbucket, srckey, dstbucket, dstkey) debug('Move object %s from %s to %s:%s' % (srckey, srcbucket, dstbucket, dstkey)) return _post(url=url, headers=super(BucketManager, self)._gernerate_headers(url))
def _make_file(self, ctx_string): try: mkfile_retries = int(self.cfg.mkfile_retries) except ValueError as e: warning( u"parameter mkfile_retries is invalid, so use default value 3") mkfile_retries = 3 url = https_check(self.__file_url()) body = ctx_string #','.join(blkstatus) headers = self.__generate_headers() code, text, logid = _post(url=url, headers=headers, data=body) while mkfile_retries and self.__need_retry(code): debug('make file fail.retry upload') code, text, logid = _post(url=url, headers=headers, data=body) mkfile_retries -= 1 return code, text, logid
def _make_file(self): try: mkfile_retries = int(self.cfg.mkfile_retries) except ValueError as e: warning( u"parameter mkfile_retries is invalid, so use default value 3") mkfile_retries = 3 blkstatus = self._get_blkstatus() url = https_check(self.__file_url()) body = ','.join(blkstatus) headers = self.__generate_headers() code, text, logid = _post(url=url, headers=headers, data=body) while mkfile_retries and self.__need_retry(code): code, text, logid = _post(url=url, headers=headers, data=body) mkfile_retries -= 1 self.recorder.delete_upload_record() return code, text, logid
def _fmgr_commons(self, reqdata, method): url = https_check('{0}/fmgr/{1}'.format(self.mgr_host, method)) debug('Request body is: %s' % (reqdata)) debug('Start to execute opration: %s' % method) return _post(url=url, data=reqdata, headers=super(Fmgr, self)._gernerate_headers(url, body=reqdata))
def image_detect(self, image, dtype, bucket): url = https_check('{0}/imageDetect'.format(self.mgr_host)) param = {'image': urlsafe_base64_encode(image)} param['type'] = dtype param['bucket'] = bucket body = super(BucketManager, self)._params_parse(param) debug('image detect for %s to %s' % (image, dtype)) return _post(url=url, data=body, headers=super(BucketManager, self)._gernerate_headers(url, body))
def setdeadline(self, bucket, key, deadline): url = https_check('{0}/setdeadline'.format(self.mgr_host)) param = {'bucket': urlsafe_base64_encode(bucket)} param['key'] = urlsafe_base64_encode(key) param['deadline'] = deadline body = super(BucketManager, self)._params_parse(param) debug('Set deadline of %s to %s' % (key, deadline)) return _post(url=url, data=body, headers=super(BucketManager, self)._gernerate_headers(url, body))
def execute(self, fops, bucket, key, force=0, separate=0, notifyurl=None): data = { 'bucket': urlsafe_base64_encode(bucket), 'key': urlsafe_base64_encode(key), 'fops': urlsafe_base64_encode(fops) } if notifyurl is not None: data['notifyURL'] = urlsafe_base64_encode(notifyurl) if force == 1: data['force'] = 1 if separate == 1: data['separate'] = 1 url = https_check('{0}/fops'.format(self.mgr_host)) headers, reqdata = self._gernerate_headers(url, data) debug('PersistentFops is %s' % fops) debug('Start to post persistentFops') return _post(url=url, data=reqdata, headers=headers)
def delete(self, bucket, key): url = https_check(self._make_delete_url(bucket, key)) debug('Start to post request of delete %s:%s' % (bucket, key)) return _post(url=url, headers=super(BucketManager, self)._gernerate_headers(url))
def _make_bput_post(self, ctx, bputnum, bput_next): url = https_check(self.__bput_url(ctx, bputnum * self.bput_size)) headers = self.__generate_headers() return _post(url=url, headers=headers, data=bput_next)