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