-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquick_delete_container.py
More file actions
executable file
·42 lines (33 loc) · 1.15 KB
/
quick_delete_container.py
File metadata and controls
executable file
·42 lines (33 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/python
import cloudfiles
import ConfigParser
# get our config from the config file
config = ConfigParser.ConfigParser()
config.read("./cf.ini")
USERNAME = config.get("auth", "username")
AUTH_URL = config.get("auth", "url")
API_KEY = config.get("auth", "key")
# create the connection object
conn = cloudfiles.get_connection(USERNAME, API_KEY, authurl = AUTH_URL)
def getandprint_all_containers():
""" will get a list of containers
and print them out to stdout"""
containers = conn.get_all_containers()
# print them all out
print "These are all your containers..."
for container in containers:
print container.name
# container to delete
getandprint_all_containers()
print "\n"
CONTAINER = raw_input("enter the container name to delete: ")
# delete a container
try:
conn.delete_container(CONTAINER)
except(cloudfiles.errors.NoSuchContainer):
print "Sorry - there is no container called \'%s\'" % CONTAINER
except(cloudfiles.errors.ContainerNotEmpty):
print "Sorry - container \'%s\' is not empty" % CONTAINER
else:
print "Container \'%s\' deleted successfully\n" % CONTAINER
getandprint_all_containers()