-
Notifications
You must be signed in to change notification settings - Fork 0
/
exercise1.py
34 lines (29 loc) · 1.29 KB
/
exercise1.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
import keystoneclient.v2_0.client as keystone
import glanceclient as glance
import novaclient.v1_1.client as nova
import os
import time
from credentials import get_keystone_creds
from credentials import get_nova_creds
if __name__ == '__main__':
keystoneInfo = get_keystone_creds()
novaInfo = get_nova_creds()
keystoneclient = keystone.Client(**keystoneInfo)
novaclient = nova.Client(**novaInfo)
endPoint = keystoneclient.service_catalog.get_urls(service_type = 'image')[0]
glanceclient = glance.Client('1', endPoint, token = keystoneclient.auth_token)
images = glanceclient.images.list()
image_create = None
for image in images:
if image.name.find('ubuntu') > -1:
print image.id, '\t', image.name
flavor = novaclient.flavors.find(name="m1.micro")
instance = novaclient.servers.create(name=image.id, image=image, flavor=flavor)
# check whether the instance has been successfully started
status = instance.status
while status == 'BUILD':
time.sleep(5)
instance = novaclient.servers.get(instance.id)
print "status: %s" %instance.status
if status == 'ERROR' or 'ACTIVE':
break