Revision a582b70e docs/developers/clients-api.rst
b/docs/developers/clients-api.rst | ||
---|---|---|
215 | 215 |
|
216 | 216 |
.. code-block:: python |
217 | 217 |
|
218 |
#/usr/bin/python |
|
218 |
#! /usr/bin/python
|
|
219 | 219 |
|
220 | 220 |
from kamaki.clients.astakos import AstakosClient |
221 | 221 |
from kamaki.clients.cyclades import CycladesClient |
... | ... | |
245 | 245 |
|
246 | 246 |
.. code-block:: python |
247 | 247 |
|
248 |
#/usr/bin/python |
|
248 |
#! /usr/bin/python
|
|
249 | 249 |
|
250 | 250 |
from kamaki.clients.astakos import AstakosClient |
251 | 251 |
from kamaki.clients.cyclades import CycladesClient |
... | ... | |
262 | 262 |
for i in range(4): |
263 | 263 |
name, flavor_id, image_id = 'Server %s' % (i + 1), 3, 'some-image-id' |
264 | 264 |
cyclades.create_server(name, flavor_id, image_id) |
265 |
|
|
266 |
Register a banch of pre-uploaded images |
|
267 |
''''''''''''''''''''''''''''''''''''''' |
|
268 |
|
|
269 |
.. code-block:: python |
|
270 |
|
|
271 |
#! /usr/bin/python |
|
272 |
|
|
273 |
from kamaki.clients import ClientError |
|
274 |
from kamaki.clients.astakos import AstakosClient |
|
275 |
from kamaki.clients.pithos import PithosClient |
|
276 |
from kamaki.clients.image import ImageClient |
|
277 |
|
|
278 |
AUTHENTICATION_URL = 'https://accounts.example.com/identity/v2.0' |
|
279 |
TOKEN = 'replace this with your token' |
|
280 |
IMAGE_CONTAINER = 'images' |
|
281 |
|
|
282 |
astakos = AstakosClient(AUTHENTICATION_URL, TOKEN) |
|
283 |
USER_UUID = astakos.user_term('uuid') |
|
284 |
|
|
285 |
PITHOS_URL = astakos.get_endpoints('object-store')['publicURL'] |
|
286 |
pithos = PithosClient(PITHOS_URL, TOKEN, USER_UUID, IMAGE_CONTAINER) |
|
287 |
|
|
288 |
IMAGE_URL = astakos.get_endpoints('image')['publicURL'] |
|
289 |
plankton = ImageClient(IMAGE_URL, TOKEN) |
|
290 |
|
|
291 |
for img in pithos.list_objects(): |
|
292 |
IMAGE_PATH = img['name'] |
|
293 |
try: |
|
294 |
r = plankton.register( |
|
295 |
name='Image %s' % img, |
|
296 |
location=(USER_UUID, IMAGE_CONTAINER, IMAGE_PATH)) |
|
297 |
print 'Image %s registered with id %s' % (r['name'], r['id']) |
|
298 |
except ClientError: |
|
299 |
print 'Failed to register image %s' % IMAGE_PATH |
Also available in: Unified diff