Revision cb69a058
b/kamaki/clients/image.py | ||
---|---|---|
30 | 30 |
# documentation are those of the authors and should not be |
31 | 31 |
# interpreted as representing official policies, either expressed |
32 | 32 |
# or implied, of GRNET S.A. |
33 |
from kamaki.clients import Client |
|
33 |
|
|
34 |
from kamaki.clients import Client, ClientError |
|
34 | 35 |
from kamaki.clients.utils import path4url |
35 | 36 |
|
36 | 37 |
|
... | ... | |
46 | 47 |
|
47 | 48 |
:param filters: (dict) request filters |
48 | 49 |
|
49 |
:param order: (str) sort_dir|desc |
|
50 |
:param order: (str) order listing by field (default is ascending, - for |
|
51 |
descending) |
|
50 | 52 |
|
51 | 53 |
:returns: (list) id,name + full image info if detail |
52 | 54 |
""" |
... | ... | |
65 | 67 |
return r.json |
66 | 68 |
|
67 | 69 |
def get_meta(self, image_id): |
70 |
""" |
|
71 |
:param image_id: (string) |
|
72 |
|
|
73 |
:returns: (list) image metadata (key:val) |
|
74 |
""" |
|
68 | 75 |
path = path4url('images', image_id) |
69 | 76 |
r = self.head(path, success=200) |
70 | 77 |
|
... | ... | |
87 | 94 |
return reply |
88 | 95 |
|
89 | 96 |
def register(self, name, location, params={}, properties={}): |
97 |
"""Register image put at location |
|
98 |
|
|
99 |
:param name: (str) |
|
100 |
|
|
101 |
:param location: (str) pithos://<account>/<container>/<path> |
|
102 |
|
|
103 |
:param params: (dict) image metadata (X-Image-Meta) can be id, store, |
|
104 |
disc_format, container_format, size, checksum, is_public, owner |
|
105 |
|
|
106 |
:param properties: (dict) image properties (X-Image-Meta-Property) |
|
107 |
""" |
|
90 | 108 |
path = path4url('images/') |
91 | 109 |
self.set_header('X-Image-Meta-Name', name) |
92 | 110 |
self.set_header('X-Image-Meta-Location', location) |
... | ... | |
104 | 122 |
r.release() |
105 | 123 |
|
106 | 124 |
def reregister(self, location, name=None, params={}, properties={}): |
125 |
"""Update existing image (key: location) |
|
126 |
|
|
127 |
:param location: (str) pithos://<account>/<container>/<path> |
|
128 |
|
|
129 |
:param name: (str) |
|
130 |
|
|
131 |
:param params: (dict) image metadata (X-Image-Meta) can be id, store, |
|
132 |
disc_format, container_format, size, checksum, is_public, owner |
|
133 |
|
|
134 |
:param properties: (dict) image properties (X-Image-Meta-Property) |
|
135 |
""" |
|
107 | 136 |
path = path4url('images', 'detail') |
108 | 137 |
r = self.get(path, success=200) |
109 | 138 |
imgs = [img for img in r.json if img['location'] == location] |
... | ... | |
116 | 145 |
r.release() |
117 | 146 |
|
118 | 147 |
def list_members(self, image_id): |
148 |
""" |
|
149 |
:param image_id: (str) |
|
150 |
|
|
151 |
:returns: (list) users who can use current user's images |
|
152 |
""" |
|
119 | 153 |
path = path4url('images', image_id, 'members') |
120 | 154 |
r = self.get(path, success=200) |
121 | 155 |
return r.json['members'] |
122 | 156 |
|
123 | 157 |
def list_shared(self, member): |
158 |
""" |
|
159 |
:param member: (str) sharers account |
|
160 |
|
|
161 |
:returns: (list) images shared by member |
|
162 |
""" |
|
124 | 163 |
path = path4url('shared-images', member) |
125 | 164 |
#self.set_param('format', 'json') |
126 | 165 |
r = self.get(path, success=200) |
127 | 166 |
return r.json['shared_images'] |
128 | 167 |
|
129 | 168 |
def add_member(self, image_id, member): |
169 |
""" |
|
170 |
:param image_id: (str) |
|
171 |
|
|
172 |
:param member: (str) user to allow access to current user's images |
|
173 |
""" |
|
130 | 174 |
path = path4url('images', image_id, 'members', member) |
131 | 175 |
r = self.put(path, success=204) |
132 | 176 |
r.release() |
133 | 177 |
|
134 | 178 |
def remove_member(self, image_id, member): |
179 |
""" |
|
180 |
:param image_id: (str) |
|
181 |
|
|
182 |
:param member: (str) user to deprive from current user's images |
|
183 |
""" |
|
135 | 184 |
path = path4url('images', image_id, 'members', member) |
136 | 185 |
r = self.delete(path, success=204) |
137 | 186 |
r.release() |
138 | 187 |
|
139 | 188 |
def set_members(self, image_id, members): |
189 |
""" |
|
190 |
:param image_id: (str) |
|
191 |
|
|
192 |
:param members: (list) user to deprive from current user's images |
|
193 |
""" |
|
140 | 194 |
path = path4url('images', image_id, 'members') |
141 | 195 |
req = {'memberships': [{'member_id': member} for member in members]} |
142 | 196 |
r = self.put(path, json=req, success=204) |
Also available in: Unified diff