-
Notifications
You must be signed in to change notification settings - Fork 0
/
openstack.py
39 lines (28 loc) · 1.08 KB
/
openstack.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
35
36
37
38
39
import openstack
SERVER_NAME = 'web-tier-instance'
IMAGE_NAME = 'web-tier-image'
FLAVOR_NAME = 'm1.small'
NETWORK_NAME = 'private'
KEYPAIR_NAME = 'web-tier-key'
PRIVATE_KEYPAIR_FILE = 'id_web'
def create_server(conn):
print("Create Server:")
image = conn.compute.find_image(IMAGE_NAME)
flavor = conn.compute.find_flavor(FLAVOR_NAME)
network = conn.network.find_network(NETWORK_NAME)
keypair = conn.compute.find_keypair(KEYPAIR_NAME)
server = conn.compute.create_server(
name=SERVER_NAME, image_id=image.id, flavor_id=flavor.id,
networks=[{"uuid": network.id}], key_name=keypair.name)
server = conn.compute.wait_for_server(server, wait=360)
print("ssh -i {key} ubuntu@{ip}".format(
key=PRIVATE_KEYPAIR_FILE,
ip=server.access_ipv4))
def delete_server(conn):
print("Delete Server:")
server = conn.compute.find_server(SERVER_NAME)
print(server)
conn.compute.delete_server(server)
with openstack.connect(cloud='openstack') as conn:
create_server(conn)
# delete_server(conn)