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


Python swiftclient.ClientException方法代碼示例

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


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

示例1: _get_object

# 需要導入模塊: import swiftclient [as 別名]
# 或者: from swiftclient import ClientException [as 別名]
def _get_object(self, location, manager, start=None):
        headers = {}
        if start is not None:
            bytes_range = 'bytes=%d-' % start
            headers = {'Range': bytes_range}

        try:
            resp_headers, resp_body = manager.get_connection().get_object(
                location.container, location.obj,
                resp_chunk_size=self.CHUNKSIZE, headers=headers)
        except swiftclient.ClientException as e:
            if e.http_status == http_client.NOT_FOUND:
                msg = _("Swift could not find object %s.") % location.obj
                LOG.warning(msg)
                raise exceptions.NotFound(message=msg)
            else:
                raise

        return (resp_headers, resp_body) 
開發者ID:openstack,項目名稱:glance_store,代碼行數:21,代碼來源:store.py

示例2: setup

# 需要導入模塊: import swiftclient [as 別名]
# 或者: from swiftclient import ClientException [as 別名]
def setup(self):
        self.conn = swiftclient.Connection(
            user=USER,
            key=KEY,
            authurl=AUTHURL,
        )
        self.container = 'test'

        self.config = Config({
            'user': USER,
            'key': KEY,
            'authurl': AUTHURL,
        })
        self.backend = SwiftBackend(self.container, self.config)

        yield

        try:
            headers, items = self.conn.get_container(self.backend.name)
            for i in items:
                self.conn.delete_object(self.backend.name, i['name'])

            self.conn.delete_container(self.backend.name)
        except swiftclient.ClientException as e:
            assert False, "Failed to delete container ->" + str(e) 
開發者ID:noirbizarre,項目名稱:flask-fs,代碼行數:27,代碼來源:test_swift_backend.py

示例3: put_object

# 需要導入模塊: import swiftclient [as 別名]
# 或者: from swiftclient import ClientException [as 別名]
def put_object(self, container, obj, contents, headers=None):
        container_dir = self.swiftdir + "/" + container
        obj_file = container_dir + "/" + obj
        obj_dir = obj_file[0:obj_file.rfind("/")]
        if os.path.exists(container_dir) is True:
            if os.path.exists(obj_dir) is False:
                os.makedirs(obj_dir)
            with open(obj_file, "w") as f:
                f.write(contents)

            self.object_headers[obj_file] = {}
            for key, value in headers.items():
                self.object_headers[obj_file][str(key)] = str(value)
            return
        else:
            raise ClientException("error_container") 
開發者ID:openstack,項目名稱:karbor,代碼行數:18,代碼來源:fake_swift_client.py

示例4: create

# 需要導入模塊: import swiftclient [as 別名]
# 或者: from swiftclient import ClientException [as 別名]
def create(self, name, location=None):
        OpenStackBucket.assert_valid_resource_name(name)
        location = location or self.provider.region_name
        try:
            self.provider.swift.head_container(name)
            raise DuplicateResourceException(
                'Bucket already exists with name {0}'.format(name))
        except SwiftClientException:
            self.provider.swift.put_container(name)
            return self.get(name) 
開發者ID:CloudVE,項目名稱:cloudbridge,代碼行數:12,代碼來源:services.py

示例5: set_acls

# 需要導入模塊: import swiftclient [as 別名]
# 或者: from swiftclient import ClientException [as 別名]
def set_acls(self, location, public=False, read_tenants=None,
                 write_tenants=None, connection=None, context=None):
        location = location.store_location
        if not connection:
            connection = self.get_connection(location, context=context)

        if read_tenants is None:
            read_tenants = []
        if write_tenants is None:
            write_tenants = []

        headers = {}
        if public:
            headers['X-Container-Read'] = "*:*"
        elif read_tenants:
            headers['X-Container-Read'] = ','.join('%s:*' % i
                                                   for i in read_tenants)
        else:
            headers['X-Container-Read'] = ''

        write_tenants.extend(self.admin_tenants)
        if write_tenants:
            headers['X-Container-Write'] = ','.join('%s:*' % i
                                                    for i in write_tenants)
        else:
            headers['X-Container-Write'] = ''

        try:
            connection.post_container(location.container, headers=headers)
        except swiftclient.ClientException as e:
            if e.http_status == http_client.NOT_FOUND:
                msg = _("Swift could not find image at URI.")
                raise exceptions.NotFound(message=msg)
            else:
                raise 
開發者ID:openstack,項目名稱:glance_store,代碼行數:37,代碼來源:store.py

示例6: exists

# 需要導入模塊: import swiftclient [as 別名]
# 或者: from swiftclient import ClientException [as 別名]
def exists(self, filename):
        try:
            self.conn.head_object(self.name, filename)
            return True
        except swiftclient.ClientException:
            return False 
開發者ID:noirbizarre,項目名稱:flask-fs,代碼行數:8,代碼來源:swift.py

示例7: file_exists

# 需要導入模塊: import swiftclient [as 別名]
# 或者: from swiftclient import ClientException [as 別名]
def file_exists(self, filename):
        try:
            self.conn.head_object(self.container, filename)
            return True
        except swiftclient.ClientException:
            return False 
開發者ID:noirbizarre,項目名稱:flask-fs,代碼行數:8,代碼來源:test_swift_backend.py

示例8: _put_object

# 需要導入模塊: import swiftclient [as 別名]
# 或者: from swiftclient import ClientException [as 別名]
def _put_object(self, container, obj, contents, headers=None):
        try:
            self.connection.put_object(container=container,
                                       obj=obj,
                                       contents=contents,
                                       headers=headers)
        except ClientException as err:
            raise SwiftConnectionFailed(reason=err) 
開發者ID:openstack,項目名稱:karbor,代碼行數:10,代碼來源:swift_bank_plugin.py

示例9: _get_object

# 需要導入模塊: import swiftclient [as 別名]
# 或者: from swiftclient import ClientException [as 別名]
def _get_object(self, container, obj):
        try:
            (_resp, body) = self.connection.get_object(container=container,
                                                       obj=obj)
            if _resp.get("x-object-meta-serialized").lower() == "true":
                body = jsonutils.loads(body)
            return body
        except ClientException as err:
            raise SwiftConnectionFailed(reason=err) 
開發者ID:openstack,項目名稱:karbor,代碼行數:11,代碼來源:swift_bank_plugin.py

示例10: _post_object

# 需要導入模塊: import swiftclient [as 別名]
# 或者: from swiftclient import ClientException [as 別名]
def _post_object(self, container, obj, headers):
        try:
            self.connection.post_object(container=container,
                                        obj=obj,
                                        headers=headers)
        except ClientException as err:
            raise SwiftConnectionFailed(reason=err) 
開發者ID:openstack,項目名稱:karbor,代碼行數:9,代碼來源:swift_bank_plugin.py

示例11: _delete_object

# 需要導入模塊: import swiftclient [as 別名]
# 或者: from swiftclient import ClientException [as 別名]
def _delete_object(self, container, obj):
        try:
            self.connection.delete_object(container=container,
                                          obj=obj)
        except ClientException as err:
            raise SwiftConnectionFailed(reason=err) 
開發者ID:openstack,項目名稱:karbor,代碼行數:8,代碼來源:swift_bank_plugin.py

示例12: _put_container

# 需要導入模塊: import swiftclient [as 別名]
# 或者: from swiftclient import ClientException [as 別名]
def _put_container(self, container):
        try:
            self.connection.put_container(container=container)
        except ClientException as err:
            raise SwiftConnectionFailed(reason=err) 
開發者ID:openstack,項目名稱:karbor,代碼行數:7,代碼來源:swift_bank_plugin.py

示例13: get_object

# 需要導入模塊: import swiftclient [as 別名]
# 或者: from swiftclient import ClientException [as 別名]
def get_object(self, container, obj):
        container_dir = self.swiftdir + "/" + container
        obj_file = container_dir + "/" + obj
        if os.path.exists(container_dir) is True:
            if os.path.exists(obj_file) is True:
                with open(obj_file, "r") as f:
                    return self.object_headers[obj_file], f.read()
            else:
                raise ClientException("error_obj")
        else:
            raise ClientException("error_container") 
開發者ID:openstack,項目名稱:karbor,代碼行數:13,代碼來源:fake_swift_client.py

示例14: delete_object

# 需要導入模塊: import swiftclient [as 別名]
# 或者: from swiftclient import ClientException [as 別名]
def delete_object(self, container, obj):
        container_dir = self.swiftdir + "/" + container
        obj_file = container_dir + "/" + obj
        if os.path.exists(container_dir) is True:
            if os.path.exists(obj_file) is True:
                os.remove(obj_file)
                self.object_headers.pop(obj_file)
            else:
                raise ClientException("error_obj")
        else:
            raise ClientException("error_container") 
開發者ID:openstack,項目名稱:karbor,代碼行數:13,代碼來源:fake_swift_client.py

示例15: test_storlet_acl_get_fail

# 需要導入模塊: import swiftclient [as 別名]
# 或者: from swiftclient import ClientException [as 別名]
def test_storlet_acl_get_fail(self):
        headers = {'X-Run-Storlet': self.storlet_name}
        headers.update(self.additional_headers)
        exc_pattern = '^.*403 Forbidden.*$'
        with self.assertRaisesRegexp(ClientException, exc_pattern):
            swift_client.get_object(self.member_url, self.member_token,
                                    self.container, 'test_object',
                                    headers=headers) 
開發者ID:openstack,項目名稱:storlets,代碼行數:10,代碼來源:test_test_storlet.py


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