本文整理汇总了Python中swiftclient.Connection.delete_container方法的典型用法代码示例。如果您正苦于以下问题:Python Connection.delete_container方法的具体用法?Python Connection.delete_container怎么用?Python Connection.delete_container使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类swiftclient.Connection
的用法示例。
在下文中一共展示了Connection.delete_container方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from swiftclient import Connection [as 别名]
# 或者: from swiftclient.Connection import delete_container [as 别名]
#.........这里部分代码省略.........
self.swift_client.delete_object(
self.container['name'], self.object)
self.logger.warning("Object %s Deleted", self.object)
except Exception as e:
self.success, self.overall_success = False, False
self.failure = e
self.logger.error(
"Object Deletion Failed %s", sys.exc_info()[1])
@monitoring.timeit
def create_cdn_enabled_container(self):
"""
Create a CDN enabled container. We use Swift client to do this except
we use a CDN endpoint
"""
try:
self.success = True
self.container_name = 'cdncheck' + str(time.time())
self.cdn_client.put_container(self.container_name)
self.logger.warning(
"Created New Container %s", self.container_name)
except Exception as e:
self.success, self.overall_success = False, False
self.failure = e
self.logger.error(
"Create CDN Container Failed %s", sys.exc_info()[1])
@monitoring.timeit
def delete_container(self):
"""
Delete the container we created
"""
try:
self.success = True
self.cdn_containers[self.enabled_container]['cdn_enabled'] = False
# This would take some time to be propagated
# We will keep checking until it's disabled.
self.timer = 0
while self.cdn_containers[
self.enabled_container]['cdn_enabled'] is True:
if self.timer > 90:
break
sleep(1)
self.timer = self.timer + 1
continue
self.logger.warning("Deleting Container: %s", self.container['name'])
self.swift_client.delete_container(self.container_name)
self.cdn_client.delete_container(self.container_name)
except Exception as e:
self.success, self.overall_success = False, False
self.failure = e
self.logger.error(
"Delete CDN Container Failed %s", sys.exc_info()[1])
@monitoring.timeit
def update_metadata(self):
示例2: __init__
# 需要导入模块: from swiftclient import Connection [as 别名]
# 或者: from swiftclient.Connection import delete_container [as 别名]
class Swift:
def __init__(self, username, password, tenant, auth_url, region):
self.swift_client = Connection(
user=username,
key=password,
tenant_name=tenant,
authurl=auth_url,
auth_version="2.0",
os_options={'region_name': region}
)
# Setup logging
self.logger = logging.getLogger()
self.logger.setLevel(logging.WARNING)
# Allow the logger to write all output to stdout too
self.logger.addHandler(logging.StreamHandler())
def list_containers(self):
try:
self.containers = self.swift_client.get_account()[1]
self.logger.warning("Listing Containers")
for container in self.containers:
self.logger.warning(container['name'])
except Exception:
self.logger.error("Listing Containers Failed")
self.exit(1)
def list_objects(self):
try:
self.logger.warning("Listing Objects")
for container in self.containers:
for swift_container in self.swift_client.get_container(container['name'])[1]:
self.logger.warning(container['name'] + " " + swift_container['name'])
except Exception as e:
self.logger.error('Listing Objects Failed, Got exception: %s' % e)
self.exit(1)
def create_container(self, name):
try:
self.container = name
self.swift_client.put_container(self.container)
self.logger.warning("Created Container %s", self.container)
except Exception:
self.logger.error("Creating Container Failed")
self.exit(1)
def create_object(self, name, contents):
try:
self.object = name
self.swift_client.put_object(self.container, self.object, contents)
self.logger.warning("Created Object %s", self.object)
except Exception:
self.logger.error("Creating Object Failed")
self.exit(1)
def get_container(self):
try:
self.containers = self.swift_client.get_account()[1]
for container in self.containers:
if container['name'] == self.container:
self.logger.warning("Getting Container Succeeded")
return True
self.logger.error("Getting Container Failed")
self.exit(1)
except Exception as e:
self.logger.error('Getting Container Failed: Got exception: ' % e)
self.exit(1)
def get_object(self):
try:
object = self.swift_client.get_object(self.container, self.object)
self.logger.warning("Object Get: %s", object)
except Exception as e:
self.logger.error('Object Get Failed, Got exception: %s' % e)
self.exit(1)
def delete_object(self):
try:
self.swift_client.delete_object(self.container, self.object)
self.logger.warning("Object Deleted")
except Exception as e:
self.logger.error('Object Deletion Failed: Got exception: ' % e)
def delete_container(self):
try:
self.swift_client.delete_container(self.container)
self.logger.warning("Container Deleted")
#.........这里部分代码省略.........
示例3: __init__
# 需要导入模块: from swiftclient import Connection [as 别名]
# 或者: from swiftclient.Connection import delete_container [as 别名]
#.........这里部分代码省略.........
def update_metadata_container(self):
"""
Update the metadata of the container
"""
try:
self.success = True
headers = {"X-Container-Meta-Temp-User": "testuser"}
self.swift_client.post_container(self.container, headers)
self.logger.warning(
"Posting Metadata to Container succeeded: %s", headers)
except Exception as e:
self.success, self.overall_success = False, False
self.failure = e
self.logger.error(
"Posting Metadata to Container failed %s", sys.exc_info()[1])
@monitoring.timeit
def update_metadata_object(self):
"""
Update the metadata of the object
"""
try:
self.success = True
headers = {"X-Object-Meta-Temp-User": "testuser"}
self.swift_client.post_object(self.container, self.object, headers)
self.logger.warning(
"Posting Metadata to Object succeeded: %s", headers)
except Exception as e:
self.success, self.overall_success = False, False
self.failure = e
self.logger.error(
"Posting Metadata to Object failed %s", sys.exc_info()[1])
@monitoring.timeit
def delete_object(self):
"""
Delete the object created earlier in the process flow
"""
try:
self.swift_client.delete_object(self.container, self.object)
self.logger.warning("Object Deleted")
except Exception as e:
self.success, self.overall_success = False, False
self.failure = e
self.logger.error(
"Object Delete failed %s", sys.exc_info()[1])
@monitoring.timeit
def delete_container(self):
"""
Delete the container that was created earlier in the process flow
"""
try:
self.swift_client.delete_container(self.container)
self.logger.warning("Container %s Deleted", self.container)
except Exception as e:
self.success, self.overall_success = False, False
self.failure = e
self.logger.error(
"Container Delete Failed %s", sys.exc_info()[1])
def run(self):
"""
The driver method that runs all the steps in the process flow
"""
self.list_containers()
self.list_objects()
self.update_metadata_account()
self.retrieve_metadata_account()
self.create_container()
self.get_container()
self.update_metadata_container()
self.retrieve_metadata_container()
self.create_object()
self.get_object()
self.update_metadata_object()
self.retrieve_metadata_object()
if hasattr(self, 'object'):
self.delete_object()
if hasattr(self, 'container'):
self.delete_container()
if self.overall_success is True:
exit(0)
else:
exit(1)
示例4: __init__
# 需要导入模块: from swiftclient import Connection [as 别名]
# 或者: from swiftclient.Connection import delete_container [as 别名]
#.........这里部分代码省略.........
def delete_cdn_containers(self):
"""
Description - Delete all containers where name starts with
'cdncheck' and all objects in that container
"""
try:
self.success = True
self.cdn_containers = self.cdn_client.get_account()[1]
if len(self.cdn_containers) == 0:
self.logger.warning(
'No CDN containers to clean up')
return
self.cdn_container_names = []
for i in self.cdn_containers:
if str(i['name']).startswith('cdncheck'):
self.cdn_container_names.append(str(i['name']))
if len(self.cdn_container_names) == 0:
self.logger.warning(
'No CDN containers (cdncheck string) to delete')
return
for self.container_name in self.cdn_container_names:
try:
self.objects = self.swift_client.get_container(
self.container_name)[1]
except Exception:
self.logger.warning(
"Couldn't retrieve objects for %s", self.container_name)
self.logger.warning("Deleting the container directly")
self.cdn_client.delete_container(self.container_name)
continue
if len(self.objects) == 0:
self.logger.warning(
'No objects found for %s', self.container_name)
self.logger.warning(
'Deleting CDN container %s', self.container_name)
self.swift_client.delete_container(self.container_name)
self.cdn_client.delete_container(self.container_name)
continue
self.object_names = []
for i in self.swift_client.get_container(self.container_name)[1]:
self.object_names.append(str(i['name']))
self.logger.warning(
'Deleting objects for %s', self.container_name)
for i in self.object_names:
self.logger.warning(' Deleting object %s', i)
self.swift_client.delete_object(self.container_name, i)
self.logger.warning(
'Deleting CDN container %s', self.container_name)
self.swift_client.delete_container(self.container_name)
self.cdn_client.delete_container(self.container_name)
except Exception as e:
self.success, self.overall_success = False, False
self.failure = e
self.logger.error("<*>delete_cdn_containers Failed %s", e)