本文整理汇总了Python中trove.common.remote.create_swift_client函数的典型用法代码示例。如果您正苦于以下问题:Python create_swift_client函数的具体用法?Python create_swift_client怎么用?Python create_swift_client使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了create_swift_client函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_create_with_catalog_all_opts
def test_create_with_catalog_all_opts(self):
cfg.CONF.set_override('swift_service_type', 'object-storev3')
cfg.CONF.set_override('os_region_name', 'RegionTwo')
client = remote.create_swift_client(
TroveContext(service_catalog=self.service_catalog))
self.assertEqual(self.swiftv3_public_url_region_two,
client.url)
示例2: test_create_swift_client
def test_create_swift_client(self):
mock_resp = mock(dict)
when(swiftclient.client.Connection).get_container("bob").thenReturn(["text", mock_resp])
client = remote.create_swift_client(TroveContext(tenant="123"))
headers, container = client.get_container("bob")
self.assertIs(headers, "text")
self.assertIs(container, mock_resp)
示例3: __init__
def __init__(self, context, **kwargs):
self.process = None
self.pid = None
self.cmd = self.cmd % kwargs
self.container = kwargs.get('container')
self.filename = kwargs.get('filename')
self.original_backup_checksum = kwargs.get('backup_checksum', None)
self.swift_client = create_swift_client(context)
示例4: verify_swift_auth_token
def verify_swift_auth_token(cls, context):
try:
client = create_swift_client(context)
client.get_account()
except ClientException:
raise exception.SwiftAuthError(tenant_id=context.tenant)
except exception.NoServiceEndpoint:
raise exception.SwiftNotFound(tenant_id=context.tenant)
示例5: test_create_swift_client
def test_create_swift_client(self):
mock_resp = MagicMock()
swiftclient.client.Connection.get_container = MagicMock(
return_value=["text", mock_resp])
client = remote.create_swift_client(TroveContext(tenant='123'))
headers, container = client.get_container('bob')
self.assertIs(headers, "text")
self.assertIs(container, mock_resp)
示例6: test_create_with_conf_override
def test_create_with_conf_override(self):
swift_url_from_conf = 'http://example.com/AUTH_'
tenant_from_ctx = 'abc'
cfg.CONF.set_override('swift_url', swift_url_from_conf)
client = remote.create_swift_client(
TroveContext(tenant=tenant_from_ctx))
self.assertEqual('%s%s' % (swift_url_from_conf, tenant_from_ctx),
client.url)
示例7: test_create_swift_client
def test_create_swift_client(self):
mock_resp = MagicMock()
swiftclient.client.Connection.get_container = MagicMock(
return_value=["text", mock_resp])
service_catalog = [{'endpoints': [{'publicURL': 'example.com'}],
'type': 'object-store'}]
client = remote.create_swift_client(TroveContext(
tenant='123',
service_catalog=service_catalog))
headers, container = client.get_container('bob')
self.assertIs(headers, "text")
self.assertIs(container, mock_resp)
示例8: check_object_exist
def check_object_exist(cls, context, location):
try:
parts = location.split('/')
obj = parts[-1]
container = parts[-2]
client = create_swift_client(context)
client.head_object(container, obj)
return True
except ClientException as e:
if e.http_status == 404:
return False
else:
raise exception.SwiftAuthError(tenant_id=context.tenant)
示例9: test_create_swift_client
def test_create_swift_client(self):
mock_resp = MagicMock()
with patch.object(swiftclient.client.Connection, 'get_container',
MagicMock(return_value=["text", mock_resp])):
service_catalog = [{'endpoints': [{'region': 'RegionOne',
'publicURL': 'example.com'}],
'type': 'object-store'}]
client = remote.create_swift_client(TroveContext(
tenant=uuid.uuid4().hex,
service_catalog=service_catalog))
headers, container = client.get_container('bob')
self.assertIs(headers, "text")
self.assertIs(container, mock_resp)
示例10: delete_files_from_swift
def delete_files_from_swift(cls, context, filename):
client = remote.create_swift_client(context)
# Delete the manifest
if client.head_object(CONF.backup_swift_container, filename):
client.delete_object(CONF.backup_swift_container, filename)
# Delete the segments
if client.head_container(filename + "_segments"):
for obj in client.get_container(filename + "_segments")[1]:
client.delete_object(filename + "_segments", obj['name'])
# Delete the segments container
client.delete_container(filename + "_segments")
示例11: delete_files_from_swift
def delete_files_from_swift(cls, context, filename):
container = CONF.backup_swift_container
client = remote.create_swift_client(context)
obj = client.head_object(container, filename)
manifest = obj.get('x-object-manifest', '')
cont, prefix = cls._parse_manifest(manifest)
if all([cont, prefix]):
# This is a manifest file, first delete all segments.
LOG.info("Deleting files with prefix: %s/%s", cont, prefix)
# list files from container/prefix specified by manifest
headers, segments = client.get_container(cont, prefix=prefix)
LOG.debug(headers)
for segment in segments:
name = segment.get('name')
if name:
LOG.info("Deleting file: %s/%s", cont, name)
client.delete_object(cont, name)
# Delete the manifest file
LOG.info("Deleting file: %s/%s", container, filename)
client.delete_object(container, filename)
示例12: check_swift_object_exist
def check_swift_object_exist(self, context, verify_checksum=False):
try:
parts = self.location.split("/")
obj = parts[-1]
container = parts[-2]
client = create_swift_client(context)
LOG.info(_("Checking if backup exist in '%s'") % self.location)
resp = client.head_object(container, obj)
if verify_checksum:
LOG.info(_("Checking if backup checksum matches swift."))
# swift returns etag in double quotes
# e.g. '"dc3b0827f276d8d78312992cc60c2c3f"'
swift_checksum = resp["etag"].strip('"')
if self.checksum != swift_checksum:
raise exception.RestoreBackupIntegrityError(backup_id=self.id)
return True
except ClientException as e:
if e.http_status == 404:
return False
else:
raise exception.SwiftAuthError(tenant_id=context.tenant)
示例13: __init__
def __init__(self, *args, **kwargs):
super(SwiftStorage, self).__init__(*args, **kwargs)
self.connection = create_swift_client(self.context)
示例14: get_client
def get_client(cls, context):
return remote.create_swift_client(context)
示例15: swift_client
def swift_client(self):
if not self._cached_swift_client or (
self._cached_context != self.context):
self._cached_swift_client = create_swift_client(self.context)
self._cached_context = self.context
return self._cached_swift_client