def _run(self, parsed_args, parsed_globals): path = parsed_args.paths rule_id = parsed_args.id bucket, key = split_bucket_key(path) self._warning_prompt('Are you sure to delete bucket life circle?') if rule_id is None: # delete all lifecycles resp = self.client.deleteBucketLifecycle(bucket) check_resp(resp) self._outprint("delete all lifecycle complete.") else: # delete one lifecycle rule_str = self._check_lifecycle(bucket, rule_id) if rule_str is not None and rule_str != 'NOTIN': resp = self.client.deleteBucketLifecycle(bucket) check_resp(resp) lifecycle = json.loads(rule_str) resp = self.client.setBucketLifecycle(bucket, lifecycle) check_resp(resp) self._outprint("delete lifecycle " + rule_id + " complete.") elif rule_str is None: resp = self.client.deleteBucketLifecycle(bucket) check_resp(resp) self._outprint("delete lifecycle " + rule_id + " complete.") elif rule_str == 'NOTIN': self._outprint("there is no lifecycle named: " + rule_id)
def __init__(self, bucket, objkey, src_obspath, partsize, tasknum, enable_checkpoint, checkpoint_file, checksum, metadata, obsclient): super(UploadOperation, self).__init__(bucket, objkey, src_obspath, partsize, tasknum, enable_checkpoint, checkpoint_file, obsclient) self.checksum = checksum self.metadata = metadata self.cmdtype = 'copy' self.copy_source = self.filename.replace('obs://', '') srcb, srck = split_bucket_key(src_obspath) metedata_resp = self.obscmdutil.get_object_metadata_nocheck(srcb, srck) if metedata_resp.status < 300: self.lastModified = metedata_resp.body.lastModified self.size = metedata_resp.body.contentLength else: logger.warning( 'touch the objetc {0} error. ErrorCode:{1}, ErrorMessage:{2}'.format( self.objkey, metedata_resp.errorCode, metedata_resp.errorMessage)) self._delete_record() raise Exception( 'touch the objetc {0} error. ErrorCode:{1}, ErrorMessage:{2}'.format( self.objkey, metedata_resp.status, metedata_resp.errorMessage)) resp_for_check_bucket = self.obscmdutil.head_bucket_nocheck(self.bucket) check_resp(resp_for_check_bucket) self._lock = compat.Lock() self._exception = [] self._record = None
def _run(self, parsed_args, parsed_globals): path = parsed_args.paths bucket, key = split_bucket_key(path) self._warning_prompt('Are you sure to delete bucket website?') resp = self.client.deleteBucketWebsite(bucket) check_resp(resp) self._outprint("delete bucket website complete.")
def _run(self, parsed_args, parsed_globals): path = parsed_args.paths policy = parsed_args.policy bucket, key = split_bucket_key(path) resp = self.client.setBucketPolicy(bucket, policy) check_resp(resp) self._outprint("create policy complete: %s\n" % path)
def _run(self, parsed_args, parsed_globals): path = parsed_args.paths rule_str = parsed_args.lifecycle bucket, key = split_bucket_key(path) rule = self._check_lifecycle(bucket, rule_str) lifecycle = json.loads(rule) resp = self.client.setBucketLifecycle(bucket, lifecycle) check_resp(resp) self._outprint("create bucket lifecycle complete.")
def _run(self, parsed_args, parsed_globals): path = parsed_args.paths log_str = parsed_args.log bucket, key = split_bucket_key(path) logstatus = None if log_str is not None: logstatus = self._build_log(log_str=log_str) resp = self.client.setBucketLogging(bucket, logstatus=logstatus) check_resp(resp) self._outprint("set bucket log complete.")
def _run(self, parsed_args, parsed_globals): path = parsed_args.paths acl_control = parsed_args.acl_control acl_str = parsed_args.acl bucket, key = split_bucket_key(path) acl = None if not acl_control and acl_str: acl = self._build_acl(acl_str) resp = self.client.setBucketAcl(bucket, acl=acl, aclControl=acl_control) # resp = self.client.setBucketAcl(bucket, acl=acl, aclControl=HeadPermission.PUBLIC_READ_WRITE_DELIVERED) check_resp(resp) self._outprint("create acl complete.")
def _run(self, parsed_args, parsed_globals): path = parsed_args.paths force = parsed_args.force bucket, key = split_bucket_key(path) self._warning_prompt('Are you sure to delete bucket %s?' % bucket) obs_cmd_util = ObsCmdUtil(self.client) if force: keys = obs_cmd_util.force_remove_bucket(bucket) self.print_results(bucket, keys) else: obs_cmd_util.remove_bucket(bucket) self._outprint('remove bucket complete: %s' % path) return 0
def _run(self, parsed_args, parsed_globals): path = parsed_args.paths acl_control = parsed_args.acl_control storage = parsed_args.storage location = parsed_args.location bucket, key = split_bucket_key(path) obs_cmd_util = ObsCmdUtil(self.client) if obs_cmd_util.head_bucket(bucket): self._outprint("bucket already exists: %s\n" % path) return 0 obs_cmd_util.create_bucket(bucket, acl_control, storage, location) self._outprint("make bucket complete: %s\n" % path) return 0
def _run(self, parsed_args, parsed_globals): path = parsed_args.paths outfile = parsed_args.outfile if outfile: with open(outfile, 'w'): pass recursive = parsed_args.recursive limit = int(parsed_args.limit) if parsed_args.limit else parsed_args.limit bucket, key = split_bucket_key(path) self._outprint('start to find list ...') if not bucket: self._list_all_buckets() elif recursive: self._list_all_objects(bucket, key, limit, outfile) else: self._list_dirs_objects(bucket, key, limit, outfile)
def _run(self, parsed_args, parsed_globals): path = parsed_args.paths recursive = parsed_args.recursive versionid = parsed_args.versionid bucket, key = split_bucket_key(path) self._warning_prompt('Are you sure to delete bucket objects?') self.now = time.strftime('%Y.%m.%d_%H.%M.%S', time.localtime(time.time())) self.obs_cmd_util = ObsCmdUtil(self.client) self._outprint('start delete objects ...') if recursive: self.delete_dir(bucket, key) else: self.delete_object(bucket, key, versionid)
def _run(self, parsed_args, parsed_globals): path = parsed_args.paths website_str = parsed_args.website website_obj = json.loads(website_str) bucket, key = split_bucket_key(path) index_suff = website_obj['indexDocument']['suffix'] error_page = None if website_obj.get('errorDocument') is not None: error_page = website_obj['errorDocument']['key'] if self._check_index_page(index_suff): if self._check_error_page(error_page): resp = self.client.setBucketWebsite(bucket, website=website_obj) check_resp(resp) self._outprint("create bucket website complete.") else: self._outprint( "input error, errorDocument[key] must be html/jpg/png/bmp/webp file in the root directory, and filename can be only consist of English letter, number and '-'." ) else: self._outprint( "input error, indexDocument[suffix] must be html file in the root directory, and filename can be only consist of English letter, number and '-'." )
def test_split_bucket_key(self): path = 'obs://bucket/keys' self.assertEqual(split_bucket_key(path), ('bucket', 'keys')) path = 'obs://bucket' self.assertEqual(split_bucket_key(path), ('bucket', ''))