146 |
146 |
Print objects in default container
|
147 |
147 |
|
148 |
148 |
srv = cyclades.get_server_info(server_id)
|
149 |
|
print("Server Name: %s (with OS %s" % (srv['name'], srv['os']))
|
|
149 |
print("Server Name: %s (OS: %s)" % (srv['name'], srv['metadata']['os']))
|
150 |
150 |
|
151 |
151 |
obj_list = pithos.list_objects()
|
152 |
152 |
print("Objects in container '%s':" % pithos.container)
|
... | ... | |
160 |
160 |
|
161 |
161 |
|
162 |
162 |
$ python test_script.py
|
163 |
|
Server Name: A Debian Server (with OS Debian Base)
|
|
163 |
Server Name: A Debian Server (OS: debian)
|
164 |
164 |
Objects in container 'pithos':
|
165 |
165 |
lala.txt of 34 bytes
|
166 |
166 |
test.txt of 1232 bytes
|
... | ... | |
196 |
196 |
astakos = AstakosClient(AUTHENTICATION_URL, TOKEN)
|
197 |
197 |
except ClientError:
|
198 |
198 |
print('Failed to authenticate user token')
|
199 |
|
return 1
|
|
199 |
raise
|
200 |
200 |
|
201 |
201 |
try:
|
202 |
202 |
cyclades_endpoints = astakos.get_service_endpoints('compute')
|
203 |
|
cyclades_publicURL = cyclades_endpoints['publicURL']
|
|
203 |
CYCLADES_URL = cyclades_endpoints['publicURL']
|
204 |
204 |
except ClientError:
|
205 |
205 |
print('Failed to get endpoints for cyclades')
|
206 |
206 |
|
207 |
207 |
try:
|
208 |
|
cyclades = CycladesClient(cyclades_publicURL, token)
|
|
208 |
cyclades = CycladesClient(CYCLADES_URL, TOKEN)
|
209 |
209 |
except ClientError:
|
210 |
210 |
print('Failed to initialize Cyclades client')
|
211 |
211 |
|
212 |
212 |
try:
|
213 |
213 |
pithos_endpoints = astakos.get_service_endpoints('object-store')
|
214 |
|
pithos_publicURL = pithos_endpoints['publicURL']
|
|
214 |
PITHOS_URL = pithos_endpoints['publicURL']
|
215 |
215 |
except ClientError:
|
216 |
216 |
print('Failed to get endpoints for pithos')
|
217 |
217 |
|
218 |
218 |
try:
|
219 |
|
pithos = PithosClient(pithos_publicURL, token, account, container)
|
|
219 |
account, container = astakos.user_info['id'], 'pithos'
|
|
220 |
pithos = PithosClient(PITHOS_URL, TOKEN, account, container)
|
220 |
221 |
except ClientError:
|
221 |
222 |
print('Failed to initialize Pithos+ client')
|
222 |
223 |
|
223 |
224 |
try:
|
|
225 |
server_id = SERVER_ID
|
224 |
226 |
srv = cyclades.get_server_info(server_id)
|
225 |
|
print("Server Name: %s (with OS %s" % (srv['name'], srv['os']))
|
|
227 |
print("Server Name: %s (OS: %s)" % (srv['name'], srv['metadata']['os']))
|
226 |
228 |
|
227 |
229 |
obj_list = pithos.list_objects()
|
|
230 |
print('Objects in container %s:' % pithos.container)
|
228 |
231 |
for obj in obj_list:
|
229 |
232 |
print(' %s of %s bytes' % (obj['name'], obj['bytes']))
|
230 |
233 |
except ClientError as e:
|
... | ... | |
264 |
267 |
('My Ubuntu Server', 3, 'my-ubuntu-12-image-id'),
|
265 |
268 |
]
|
266 |
269 |
|
|
270 |
created = []
|
267 |
271 |
for name, flavor_id, image_id in servers:
|
268 |
|
cyclades.create_server(name, flavor_id, image_id)
|
|
272 |
new_vm = cyclades.create_server(name, flavor_id, image_id, networks=[])
|
|
273 |
created.append(new_vm)
|
269 |
274 |
|
|
275 |
for vm in created:
|
|
276 |
print 'Wait while vm "%s" (%s) is being build' % (vm['name'], vm['id'])
|
|
277 |
cyclades.wait_server(vm['id'])
|
270 |
278 |
|
271 |
|
Batch-create 4 servers of the same kind
|
272 |
|
'''''''''''''''''''''''''''''''''''''''
|
273 |
|
|
274 |
|
.. code-block:: python
|
275 |
|
|
276 |
|
#! /usr/bin/python
|
277 |
|
|
278 |
|
from kamaki.clients.astakos import AstakosClient
|
279 |
|
from kamaki.clients.cyclades import CycladesClient
|
280 |
|
|
281 |
|
AUTHENTICATION_URL = 'https://accounts.example.com/identity/v2.0'
|
282 |
|
TOKEN = 'replace this with your token'
|
283 |
|
|
284 |
|
astakos = AstakosClient(AUTHENTICATION_URL, TOKEN)
|
285 |
|
|
286 |
|
CYCLADES_URL = astakos.get_service_endpoints('compute')['publicURL']
|
287 |
|
cyclades = CycladesClient(CYCLADES_URL, TOKEN)
|
288 |
|
|
289 |
|
for i in range(4):
|
290 |
|
name, flavor_id, image_id = 'Server %s' % (i + 1), 3, 'some-image-id'
|
291 |
|
cyclades.create_server(name, flavor_id, image_id)
|
|
279 |
.. note:: The `networks=[]` argument explicitly instructs `cyclades` to create
|
|
280 |
a virtual server without any network connections. If not used, `cyclades`
|
|
281 |
will apply the default policy (e.g., assign a public IP to the new virtual
|
|
282 |
server).
|
292 |
283 |
|
293 |
284 |
Register a banch of pre-uploaded images
|
294 |
285 |
'''''''''''''''''''''''''''''''''''''''
|
... | ... | |
310 |
301 |
USER_UUID = astakos.user_info['id']
|
311 |
302 |
|
312 |
303 |
PITHOS_URL = astakos.get_service_endpoints('object-store')['publicURL']
|
313 |
|
pithos = PithosClient(PITHOS_URL, TOKEN, USER_UUID, IMAGE_CONTAINER)
|
|
304 |
pithos = PithosClient(
|
|
305 |
PITHOS_URL, TOKEN, account=USER_UUID, container=IMAGE_CONTAINER)
|
314 |
306 |
|
315 |
307 |
IMAGE_URL = astakos.get_service_endpoints('image')['publicURL']
|
316 |
308 |
plankton = ImageClient(IMAGE_URL, TOKEN)
|
... | ... | |
325 |
317 |
except ClientError:
|
326 |
318 |
print 'Failed to register image %s' % IMAGE_PATH
|
327 |
319 |
|
328 |
|
.. note::
|
329 |
|
|
330 |
|
In `plankton.register`, the `location` argument can be either `a triplet`,
|
331 |
|
as shown above, or `a qualified URL` of the form
|
|
320 |
.. note:: In `plankton.register`, the `location` argument can be either
|
|
321 |
`a triplet`, as shown above, or `a qualified URL` of the form
|
332 |
322 |
``pithos://USER_UUID/IMAGE_CONTAINER/IMAGE_PATH``.
|
333 |
323 |
|
334 |
324 |
Two servers and a private network
|