本文整理汇总了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)
示例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)
示例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")
示例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)
示例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
示例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
示例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
示例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)
示例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)
示例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)
示例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)
示例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)
示例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")
示例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")
示例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)