Pass flavor metadata into heat template
[snaps.git] / examples / demo.py
1 import logging
2
3 from snaps.config.vm_inst import VmInstanceConfig
4
5 logging.basicConfig(level=logging.INFO)
6
7 # Credentials
8 from snaps.openstack.os_credentials import OSCreds, ProxySettings
9
10
11 proxy_settings = ProxySettings(
12     host='10.197.123.27', port='3128',
13     ssh_proxy_cmd='/usr/local/bin/corkscrew 10.197.123.27 3128 %h %p')
14
15 os_creds = OSCreds(
16     username='admin', password='cable123',
17     auth_url='http://192.168.67.10:5000/v2.0/', project_name='admin',
18     proxy_settings=proxy_settings)
19
20
21 # Images
22 from snaps.openstack.create_image import OpenStackImage
23 from snaps.config.image import ImageConfig
24
25 image_settings = ImageConfig(name='cirros-test', image_user='cirros', img_format='qcow2',
26                              url='http://download.cirros-cloud.net/0.3.4/cirros-0.3.4-x86_64-disk.img')
27
28 image = OpenStackImage(os_creds, image_settings)
29 image.create()
30 # See in Horizon
31
32
33 # Network
34 from snaps.config.network import NetworkConfig, SubnetConfig
35 from snaps.openstack.create_network import OpenStackNetwork
36
37 subnet_settings = SubnetConfig(name='test-subnet', cidr='10.0.0.1/24')
38 network_settings = NetworkConfig(
39     name='test-net', subnet_settings=[subnet_settings])
40 network = OpenStackNetwork(os_creds, network_settings)
41 network.create()
42
43
44 # Flavors
45 from snaps.config.flavor import FlavorConfig
46 from snaps.openstack.create_flavor import OpenStackFlavor
47
48 flavor_settings = FlavorConfig(name='test-flavor', ram=256, disk=10, vcpus=2)
49 flavor = OpenStackFlavor(os_creds, flavor_settings)
50 flavor.create()
51
52 # Instances
53 from snaps.config.network import PortConfig
54 from snaps.openstack.create_instance import OpenStackVmInstance
55
56 port_settings = PortConfig(
57     name='test-port', network_name=network_settings.name)
58 instance_settings = VmInstanceConfig(
59     name='test-inst', flavor=flavor_settings.name,
60     port_settings=[port_settings])
61
62 vm_inst = OpenStackVmInstance(os_creds, instance_settings, image_settings)
63 vm_inst.create(block=True)
64
65 # Cleanup
66 vm_inst.clean()
67 flavor.clean()
68 network.clean()
69 image.clean()