-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_ulibcloud.py
124 lines (88 loc) · 3.14 KB
/
test_ulibcloud.py
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
from ulibcloud.udriver import uDriver as Driver
from ulibcloud.uprovider import get_driver
from ulibcloud.ext.ext_provider import extProvider
from ulibcloud.types import *
from libcloud.storage.types import Provider
S3_eu_west = get_driver(Provider.S3_EU_WEST)
driver_s3_eu_west = S3_eu_west('your_key', 'your_secret')
Cloud_files_us = get_driver(Provider.CLOUDFILES_US)
driver_cloud_files_us = Cloud_files_us('your_key', 'your_secret')
k = 1
m = 2
driver = Driver([driver_s3_eu_west, driver_cloud_files_us], k, m)
def test_container_create(c_name):
try :
print 'create container %s' % (c_name)
container = driver.create_container(c_name)
return container
except uLibcloudError ,e :
print e
def test_container_get(c_name):
try :
print 'get container %s' % (c_name)
container = driver.get_container(c_name)
return container
except uLibcloudError ,e :
print e
def test_container_delete(container):
try :
print 'delete container %s' % (container.name)
return driver.delete_container(container)
except uLibcloudError ,e :
print e
def test_container_list():
try :
print 'list container '
return driver.list_container()
except uLibcloudError ,e :
print e
def test_upload_object(file_path, container, object_name, extra):
driver.upload_object(file_path, container, object_name, extra)
def test_list_container_objects(container):
return driver.list_container_objects(container)
##################
def test_get_object(container_name, object_name):
return driver.get_object(container_name, object_name)
def test_get_meta(container_name, object_name, file_dir):
return driver.get_meta(container_name, object_name, file_dir)
def test_download_object(obj, destination_path):
return driver.download_object(obj, destination_path)
def test_delete_object(obj):
return driver.delete_object(obj)
def main() :
c_name = 'iwanttofuckyou'
f_path = '/home/zork/Dev-place/ulibcloud-0.1/lamport'
d_path = '/home/zork/Desktop/'
o_name = 'lamportx'
extra = {'content_type' : 'ulib'}
# container = test_container_create(c_name)
# print container
print '=== get container ==='
container = test_container_get(c_name)
print container
# ret = test_container_delete(container)
# print ret
# container = test_container_create(c_name)
# print container
# c_list = test_container_list()
# print c_list
# print '=== list container ==='
# container = test_container_get(c_name)
# print container
# print '=== upload object ==='
# test_upload_object(f_path, container, o_name, extra)
# print '=== list container object ==='
# objects_list = test_list_container_objects(container)
# for i in objects_list :
# print i.name
print '=== get object === '
obj = test_get_object(c_name, o_name)
# for i in obj.objects :
# print i.name
print '=== get meta ==='
umeta = test_get_meta(c_name, o_name, d_path)
print umeta
print '=== download object ==='
test_download_object(obj, d_path)
if __name__ == '__main__' :
main()