Revision b3b32add kamaki/clients/compute.py
b/kamaki/clients/compute.py | ||
---|---|---|
33 | 33 |
|
34 | 34 |
import json |
35 | 35 |
|
36 |
from . import ClientError |
|
36 | 37 |
from .http import HTTPClient |
37 | 38 |
|
38 | 39 |
|
... | ... | |
146 | 147 |
path = '/images/detail' if detail else '/images' |
147 | 148 |
reply = self.http_get(path) |
148 | 149 |
return reply['images']['values'] |
149 |
|
|
150 |
|
|
150 | 151 |
def get_image_details(self, image_id): |
151 |
path = '/images/%d' % image_id
|
|
152 |
path = '/images/%s' % image_id
|
|
152 | 153 |
reply = self.http_get(path) |
153 | 154 |
return reply['image'] |
154 |
|
|
155 |
def create_image(self, server_id, name): |
|
156 |
req = {'name': name, 'serverRef': server_id} |
|
157 |
body = json.dumps({'image': req}) |
|
158 |
reply = self.http_post('/images', body) |
|
159 |
return reply['image'] |
|
160 |
|
|
155 |
|
|
161 | 156 |
def delete_image(self, image_id): |
162 |
path = '/images/%d' % image_id
|
|
157 |
path = '/images/%s' % image_id
|
|
163 | 158 |
self.http_delete(path) |
164 | 159 |
|
165 | 160 |
def get_image_metadata(self, image_id, key=None): |
166 |
path = '/images/%d/meta' % image_id
|
|
161 |
path = '/images/%s/meta' % image_id
|
|
167 | 162 |
if key: |
168 | 163 |
path += '/%s' % key |
169 | 164 |
reply = self.http_get(path) |
170 | 165 |
return reply['meta'] if key else reply['metadata']['values'] |
171 | 166 |
|
172 | 167 |
def create_image_metadata(self, image_id, key, val): |
173 |
path = '/images/%d/meta/%s' % (image_id, key)
|
|
168 |
path = '/images/%s/meta/%s' % (image_id, key)
|
|
174 | 169 |
body = json.dumps({'meta': {key: val}}) |
175 | 170 |
reply = self.http_put(path, body, success=201) |
176 |
reply['meta'] |
|
171 |
return reply['meta']
|
|
177 | 172 |
|
178 | 173 |
def update_image_metadata(self, image_id, **metadata): |
179 |
path = '/images/%d/meta' % image_id
|
|
174 |
path = '/images/%s/meta' % image_id
|
|
180 | 175 |
body = json.dumps({'metadata': metadata}) |
181 | 176 |
reply = self.http_post(path, body, success=201) |
182 | 177 |
return reply['metadata'] |
183 | 178 |
|
184 | 179 |
def delete_image_metadata(self, image_id, key): |
185 |
path = '/images/%d/meta/%s' % (image_id, key) |
|
186 |
reply = self.http_delete(path) |
|
180 |
path = '/images/%s/meta/%s' % (image_id, key) |
|
181 |
self.http_delete(path) |
Also available in: Unified diff