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