Skip to content

Instantly share code, notes, and snippets.

@okossuth
Created March 16, 2012 13:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save okossuth/2050056 to your computer and use it in GitHub Desktop.
Save okossuth/2050056 to your computer and use it in GitHub Desktop.
def delete_container(args):
"Deletes a container on Rackspace Cloud Files"
connection = cloudfiles.get_connection(
RACKSPACE_USERNAME,
RACKSPACE_API_KEY,
)
container = connection.get_container(args.container)
for obj in container.get_objects():
for w in range(1,10):
if w != 1:
# connection = cloudfiles.get_connection( RACKSPACE_USERNAME, RACKSPACE_API_KEY, )
try:
container.get_object(obj.name)
print 'Trying again to delete..'
container.delete_object(obj.name)
break
except NoSuchObject:
print 'Not existing anymore'
break
except ResponseError:
break
try:
print 'Object to delete "%s"' % obj.name
container.delete_object(obj.name)
print 'Object "%s" deleted!' % obj.name
break
except SSLError:
print "Rackspace SSL error.. retrying"
time.sleep(5)
if w > 10:
print "Giving up trying to delete file.. too many error attempts!"
raise SystemExit(1)
time.sleep(5)
getobj=container.list_objects()
if getobj:
print "Container not empty!... Deleting remaining files.."
for obj in container.get_objects():
container.delete_object(obj.name)
connection.delete_container(args.container)
print 'Container "%s" deleted' % args.container
else:
connection.delete_container(args.container)
print 'Container "%s" deleted' % args.container
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment