當前位置: 首頁>>代碼示例>>Python>>正文


Python oss2.Bucket方法代碼示例

本文整理匯總了Python中oss2.Bucket方法的典型用法代碼示例。如果您正苦於以下問題:Python oss2.Bucket方法的具體用法?Python oss2.Bucket怎麽用?Python oss2.Bucket使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在oss2的用法示例。


在下文中一共展示了oss2.Bucket方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: print_inventory_configuration

# 需要導入模塊: import oss2 [as 別名]
# 或者: from oss2 import Bucket [as 別名]
def print_inventory_configuration(configuration):
    print('======inventory configuration======')
    print('inventory_id', configuration.inventory_id)
    print('is_enabled', configuration.is_enabled)
    print('frequency', configuration.inventory_schedule.frequency)
    print('included_object_versions', configuration.included_object_versions)
    print('inventory_filter prefix', configuration.inventory_filter.prefix)
    print('fields', configuration.optional_fields)
    bucket_destin = configuration.inventory_destination.bucket_destination
    print('===bucket destination===')
    print('account_id', bucket_destin.account_id)
    print('role_arn', bucket_destin.role_arn)
    print('bucket', bucket_destin.bucket)
    print('format', bucket_destin.inventory_format)
    print('destination prefix', bucket_destin.prefix)
    if bucket_destin.sse_kms_encryption is not None:
        print('server side encryption by kms, key id:', bucket_destin.sse_kms_encryption.key_id)
    elif bucket_destin.sse_oss_encryption is not None:
        print('server side encryption by oss.')

# 創建Bucket對象,所有Object相關的接口都可以通過Bucket對象來進行 
開發者ID:aliyun,項目名稱:aliyun-oss-python-sdk,代碼行數:23,代碼來源:bucket_inventory.py

示例2: oss_check

# 需要導入模塊: import oss2 [as 別名]
# 或者: from oss2 import Bucket [as 別名]
def oss_check(self, bucket_name, default_endpoint, access_key_id, access_key_secret):
        if bucket_name in self.bucket_endpoints:
            endpoint = self.bucket_endpoints[bucket_name]
            try:
                bucket = oss2.Bucket(oss2.Auth(access_key_id, access_key_secret), endpoint, bucket_name, connect_timeout=5.0, app_name=defaults.app_name)
                res = bucket.get_bucket_acl()
            except oss2.exceptions.OssError as e:
                raise AuthenticationFailed("access bucket:%s using specified \
                        endpoint:%s failed. request_id:%s, status:%s, code:%s, message:%s" % (bucket_name, endpoint, e.request_id, unicode(e.status), e.code, e.message))
            return endpoint 
        try:
            service = oss2.Service(oss2.Auth(access_key_id, access_key_secret), default_endpoint, app_name=defaults.app_name)
            res = service.list_buckets(prefix=bucket_name)
        except oss2.exceptions.AccessDenied as e:
            raise AuthenticationFailed("can't list buckets, check your access_key.request_id:%s, status:%s, code:%s, message:%s"% (e.request_id, unicode(e.status), e.code, e.message))
        except oss2.exceptions.OssError as e:
            raise AuthenticationFailed("list buckets error. request_id:%s, status:%s, code:%s, message:%s" % (e.request_id, unicode(e.status), e.code, e.message))

        bucket_list = res.buckets
        for bucket in bucket_list:
            if bucket.name == bucket_name:
                endpoint = self.get_endpoint(bucket_name, bucket.location.decode('utf-8'), access_key_id, access_key_secret)
                return endpoint
        raise AuthenticationFailed("can't find the bucket %s when list buckets." % bucket_name) 
開發者ID:aliyun,項目名稱:oss-ftp,代碼行數:26,代碼來源:oss_authorizers.py

示例3: upload_oss

# 需要導入模塊: import oss2 [as 別名]
# 或者: from oss2 import Bucket [as 別名]
def upload_oss(kw, local_file, oss_path):
    """
    help function to upload a model to oss
    :param kw: OSS parameter
    :param local_file: local place of model
    :param oss_path: remote place of OSS
    :return: True if the procedure is success
    """
    if oss_path[-1] == '/':
        oss_path = '%s%s' % (oss_path, os.path.basename(local_file))

    auth = oss2.Auth(kw['access_id'], kw['access_key'])
    bucket = kw['access_bucket']
    bkt = oss2.Bucket(auth=auth, endpoint=kw['endpoint'], bucket_name=bucket)

    try:
        bkt.put_object_from_file(key=oss_path, filename=local_file)
        logger.info("upload %s to %s successfully!" %
                    (os.path.abspath(local_file), oss_path))
    except Exception():
        raise ValueError('upload %s to %s failed' %
                         (os.path.abspath(local_file), oss_path)) 
開發者ID:kubeflow,項目名稱:xgboost-operator,代碼行數:24,代碼來源:utils.py

示例4: read_model_from_oss

# 需要導入模塊: import oss2 [as 別名]
# 或者: from oss2 import Bucket [as 別名]
def read_model_from_oss(kw):
    """
    helper function to read a model from oss
    :param kw: OSS parameter
    :return: XGBoost booster model
    """
    auth = oss2.Auth(kw['access_id'], kw['access_key'])
    bucket = kw['access_bucket']
    bkt = oss2.Bucket(auth=auth, endpoint=kw['endpoint'], bucket_name=bucket)
    oss_path = kw["path"]

    temp_model_fname = os.path.join(tempfile.mkdtemp(), 'local_model')
    try:
        bkt.get_object_to_file(key=oss_path, filename=temp_model_fname)
        logger.info("success to load model from oss %s", oss_path)
    except Exception as e:
        logging.error("fail to load model: " + e)
        raise Exception("fail to load model from oss %s", oss_path)

    bst = xgb.Booster({'nthread': 2})  # init model

    bst.load_model(temp_model_fname)

    return bst 
開發者ID:kubeflow,項目名稱:xgboost-operator,代碼行數:26,代碼來源:utils.py

示例5: __init__

# 需要導入模塊: import oss2 [as 別名]
# 或者: from oss2 import Bucket [as 別名]
def __init__(self, data):
        """
        COS發布
        :param data: 前端傳來的配置信息
        """
        self.repository = data.get('repository')  # 代碼倉庫
        self.repo_name = self.repository.split('/')[-1].replace('.git', '')  # 倉庫名字
        self.access_id = data.get('SecretID')
        self.access_key = data.get('SecretKey')
        self.region = data.get('region')  # Bucket區域
        self.bucket_name = data.get('bucket_name')  # Bucket名字
        self.bucket_path = data.get('bucket_path')  # 目錄路徑
        self.clone_dir = '/opt'  # 代碼拉取地址
        self.local_dir = '/tmp/{}/'.format(self.repo_name)  # 處理後的臨時存放代碼路徑
        self.ENDPOINT = 'http://oss-{}.aliyuncs.com'.format(self.region)  # 節點信息
        self.bucket = oss2.Bucket(oss2.Auth(self.access_id, self.access_key), self.ENDPOINT, self.bucket_name) 
開發者ID:opendevops-cn,項目名稱:codo-publish,代碼行數:18,代碼來源:upload_oss.py

示例6: test_failed_state

# 需要導入模塊: import oss2 [as 別名]
# 或者: from oss2 import Bucket [as 別名]
def test_failed_state(self):
        auth = oss2.Auth(OSS_ID, OSS_SECRET)
        bucket_name = OSS_BUCKET + "-test-async-fetch-task-callback"
        bucket = oss2.Bucket(auth, self.endpoint, bucket_name)
        bucket.create_bucket()

        object_name = self.fetch_object_name+'-destination'
       
        task_config = AsyncFetchTaskConfiguration('http://invalidUrl.com', object_name=object_name)

        result = bucket.put_async_fetch_task(task_config)
        task_id = result.task_id
        time.sleep(5)

        result = bucket.get_async_fetch_task(task_id)

        self.assertEqual(task_id, result.task_id)
        self.assertEqual(ASYNC_FETCH_TASK_STATE_FAILED, result.task_state)
        self.assertNotEqual('', result.error_msg)

        bucket.delete_bucket() 
開發者ID:aliyun,項目名稱:aliyun-oss-python-sdk,代碼行數:23,代碼來源:test_async_fetch_task.py

示例7: test_ignore_same_key

# 需要導入模塊: import oss2 [as 別名]
# 或者: from oss2 import Bucket [as 別名]
def test_ignore_same_key(self):
        auth = oss2.Auth(OSS_ID, OSS_SECRET)
        bucket_name = OSS_BUCKET + "-test-async-fetch-task"
        bucket = oss2.Bucket(auth, self.endpoint, bucket_name)
        bucket.create_bucket()

        object_name = self.fetch_object_name+'-destination'
        bucket.put_object(object_name, 'test-content')

        task_config = AsyncFetchTaskConfiguration(self.fetch_url, object_name=object_name, ignore_same_key=False)
        result = bucket.put_async_fetch_task(task_config)
        task_id = result.task_id
        self.assertNotEqual('', task_id)

        task_config = AsyncFetchTaskConfiguration(self.fetch_url, object_name=object_name, ignore_same_key=True)
        self.assertRaises(oss2.exceptions.ObjectAlreadyExists, bucket.put_async_fetch_task, task_config)

        task_config = AsyncFetchTaskConfiguration(self.fetch_url, object_name=object_name)
        self.assertRaises(oss2.exceptions.ObjectAlreadyExists, bucket.put_async_fetch_task, task_config)

        bucket.delete_object(object_name) 
開發者ID:aliyun,項目名稱:aliyun-oss-python-sdk,代碼行數:23,代碼來源:test_async_fetch_task.py

示例8: setUp

# 需要導入模塊: import oss2 [as 別名]
# 或者: from oss2 import Bucket [as 別名]
def setUp(self):
        OssTestCase.setUp(self)
        policy_text = ''
        policy_text += '{'
        policy_text += '"Version":"1",'
        policy_text += '"Statement":[{'
        policy_text += '"Action":["oss:*"],'
        policy_text += '"Effect":"Allow",'
        policy_text += '"Principal":["{0}"],'.format(OSS_PAYER_UID)
        policy_text += '"Resource": ["acs:oss:*:*:{0}","acs:oss:*:*:{0}/*"]'.format(OSS_BUCKET)
        policy_text += '}]}'
        self.bucket.put_bucket_policy(policy_text)

        # Enable bucket request payment
        result = self.bucket.put_bucket_request_payment(PAYER_REQUESTER)
        self.assertEqual(result.status, 200)

        self.payer_bucket = oss2.Bucket(oss2.Auth(OSS_PAYER_ID, OSS_PAYER_SECRET), OSS_ENDPOINT, OSS_BUCKET) 
開發者ID:aliyun,項目名稱:aliyun-oss-python-sdk,代碼行數:20,代碼來源:test_object_request_payment.py

示例9: test_resumable_incomplete_download

# 需要導入模塊: import oss2 [as 別名]
# 或者: from oss2 import Bucket [as 別名]
def test_resumable_incomplete_download(self):
        # """One of the part is incomplete, while there's no exception raised."""

        oss2.defaults.multiget_threshold = 1
        oss2.defaults.multiget_part_size = 100
        oss2.defaults.multiget_num_threads = 5
        oss2.defaults.min_part_size = 100

        file_size = 123 * 3 + 1
        key, filename, content = self.__prepare(self.bucket, file_size)

        with patch.object(oss2.Bucket, 'get_object',
                          side_effect=partial(mock_get_object, content_length=file_size),
                          autospec=True):
            try:
                oss2.resumable_download(self.bucket, key, filename)
            except oss2.exceptions.InconsistentError as e:
                self.assertTrue(e.request_id)
                self.assertEqual(e.body, 'InconsistentError: IncompleteRead from source')
            except:
                self.assertTrue(False) 
開發者ID:aliyun,項目名稱:aliyun-oss-python-sdk,代碼行數:23,代碼來源:test_download.py

示例10: __init__

# 需要導入模塊: import oss2 [as 別名]
# 或者: from oss2 import Bucket [as 別名]
def __init__(self, access_key_id=None, access_key_secret=None, end_point=None, bucket_name=None, expire_time=None):
        self.access_key_id = access_key_id if access_key_id else _get_config('OSS_ACCESS_KEY_ID')
        self.access_key_secret = access_key_secret if access_key_secret else _get_config('OSS_ACCESS_KEY_SECRET')
        self.end_point = _normalize_endpoint(end_point if end_point else _get_config('OSS_ENDPOINT'))
        self.bucket_name = bucket_name if bucket_name else _get_config('OSS_BUCKET_NAME')
        self.expire_time = expire_time if expire_time else int(_get_config('OSS_EXPIRE_TIME', default=60*60*24*30))

        self.auth = Auth(self.access_key_id, self.access_key_secret)
        self.service = Service(self.auth, self.end_point)
        self.bucket = Bucket(self.auth, self.end_point, self.bucket_name)

        # try to get bucket acl to check bucket exist or not
        try:
            self.bucket_acl = self.bucket.get_bucket_acl().acl
        except oss2.exceptions.NoSuchBucket:
            raise SuspiciousOperation("Bucket '%s' does not exist." % self.bucket_name) 
開發者ID:aliyun,項目名稱:django-oss-storage,代碼行數:18,代碼來源:backends.py

示例11: _get_bucket

# 需要導入模塊: import oss2 [as 別名]
# 或者: from oss2 import Bucket [as 別名]
def _get_bucket(self, auth):
        if self.cname:
            return Bucket(auth, self.cname, self.bucket_name, is_cname=True)
        else:
            return Bucket(auth, self.end_point, self.bucket_name) 
開發者ID:007gzs,項目名稱:dingtalk-django-example,代碼行數:7,代碼來源:storage.py

示例12: from_crawler

# 需要導入模塊: import oss2 [as 別名]
# 或者: from oss2 import Bucket [as 別名]
def from_crawler(cls, crawler):
        s = cls()
        import oss2
        aid = 'kkkkkkkkkkkkkkkkkkkkkkkk'
        ack = 'vvvvvvvvvvvvvvvvvvvvvvvvvvvvvv'
        enp = 'http://oss-cn-hangzhou.aliyuncs.com'
        _bucket = '<bucket name>'
        VOssPipeline.BUCKET_STORE = oss2.Bucket(oss2.Auth(aid,ack), enp, _bucket)
        return s 
開發者ID:cilame,項目名稱:vrequest,代碼行數:11,代碼來源:pipelines.py

示例13: __init__

# 需要導入模塊: import oss2 [as 別名]
# 或者: from oss2 import Bucket [as 別名]
def __init__(self, bucket_name, endpoint, access_id, access_key):
        self.bucket_name = bucket_name
        self.endpoint = endpoint
        self.access_id = access_id
        self.access_key = access_key

        self.bucket = oss2.Bucket(oss2.Auth(self.access_id, self.access_key), self.endpoint, self.bucket_name, app_name=defaults.app_name)
        self.size_cache = {}
        self.dir_cache = {} 
開發者ID:aliyun,項目名稱:oss-ftp,代碼行數:11,代碼來源:oss_fs_impl.py

示例14: get_bucket

# 需要導入模塊: import oss2 [as 別名]
# 或者: from oss2 import Bucket [as 別名]
def get_bucket(self, path):
        path = self.normalize_separate_char(path)
        bucket_name = self.get_oss_bucket_name(path)
        bucket = oss2.Bucket(oss2.Auth(self.access_id, self.access_key), self.endpoint, bucket_name, app_name=defaults.app_name)
        return bucket 
開發者ID:aliyun,項目名稱:oss-ftp,代碼行數:7,代碼來源:oss_fs_impl.py

示例15: get_endpoint

# 需要導入模塊: import oss2 [as 別名]
# 或者: from oss2 import Bucket [as 別名]
def get_endpoint(self, bucket_name, location, access_key_id, access_key_secret):
        #try if can connect through internal domain
        internal_endpoint = location + "-internal" + ".aliyuncs.com"
        public_endpoint = location + ".aliyuncs.com"
        if self.internal is True:
            return internal_endpoint
        elif self.internal is False:
            return public_endpoint

        try:
            bucket = oss2.Bucket(oss2.Auth(access_key_id, access_key_secret), internal_endpoint, bucket_name, connect_timeout=1.0, app_name=defaults.app_name)
            res = bucket.get_bucket_acl()
        except oss2.exceptions.OssError as e:
            return public_endpoint
        return internal_endpoint 
開發者ID:aliyun,項目名稱:oss-ftp,代碼行數:17,代碼來源:oss_authorizers.py


注:本文中的oss2.Bucket方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。