Saturday 30 March 2013

Automated OpenStack Folsom with Quantum install using Ansible/Vagrant/VirtualBox


This script (folsom branch) installs OpenStack Folsom with Quantum networking fully configured in about 10 minutes - once the prereqs are in place. The readme has the usage. It is written in Ansible which is easy to learn and quick to work with. It uses the OpenStack packages from the Ubuntu cloud archive and sets up this configuration:



The web dashboard has only limited support for Quantum networking in Folsom. You can create/delete regular networks/subnets and boot to them, but you will need to use the CLIs for routers, floating ips and configuring external access. The CLI are already installed on the controller node.

Here is a sample admin session that creates a virtual network, gives it a subnet and boots a VM to it. Then the external access is configured and a floating ip is mapped to the vm.
These commands are scripted in /vagrant/run-sample-session.sh which can be run on the controller.


laptop$ cd vms
laptop$ vagrant ssh controller

# load admin credentials into the environment - the installer left them here

vagrant@controller:~$ cat /vagrant/openrc 
export OS_USERNAME=admin
export OS_TENANT_NAME=demo
export OS_PASSWORD=secrete
export OS_AUTH_URL=http://10.0.10.10:5000/v2.0/
export OS_REGION_NAME=RegionOne

vagrant@controller:~$ source /vagrant/openrc 

# The cirros image only needs 50MB of RAM to run. 

vagrant@controller:~$ nova flavor-create micro 6 50 0 1
vagrant@controller:~$ nova secgroup-add-rule default tcp 22 22 0.0.0.0/0
vagrant@controller:~$ nova secgroup-add-rule default icmp -1 -1 0.0.0.0/0


Note: opening the security groups here was not necessary as Quantum in Folsom does not support them with overlapping IPs.


vagrant@controller:~$ quantum net-create net1
Created a new network:
+---------------------------+--------------------------------------+
| Field                     | Value                                |
+---------------------------+--------------------------------------+
| admin_state_up            | True                                 |
| id                        | cf46fc34-62b8-4866-9af2-a35b13a0fd7a |
| name                      | net1                                 |
| provider:network_type     | gre                                  |
| provider:physical_network |                                      |
| provider:segmentation_id  | 1                                    |
| router:external           | False                                |
| shared                    | False                                |
| status                    | ACTIVE                               |
| subnets                   |                                      |
| tenant_id                 | 33c295b9099e4a5c829e6aaa335dfc31     |
+---------------------------+--------------------------------------+

Note: the provider attributes are not visible to non-admin users.


vagrant@controller:~$ quantum subnet-create net1 10.0.33.0/24 --name=sub1
Created a new subnet:
+------------------+----------------------------------------------+
| Field            | Value                                        |
+------------------+----------------------------------------------+
| allocation_pools | {"start": "10.0.33.2", "end": "10.0.33.254"} |
| cidr             | 10.0.33.0/24                                 |
| dns_nameservers  |                                              |
| enable_dhcp      | True                                         |
| gateway_ip       | 10.0.33.1                                    |
| host_routes      |                                              |
| id               | c220885d-01a2-4e27-9e4c-c5910d0fc6d0         |
| ip_version       | 4                                            |
| name             | sub1                                         |
| network_id       | cf46fc34-62b8-4866-9af2-a35b13a0fd7a         |
| tenant_id        | 33c295b9099e4a5c829e6aaa335dfc31             |
+------------------+----------------------------------------------+




vagrant@controller:~$ nova boot --flavor micro --image cirros-0.3.0-x86_64 vm1
+-------------------------------------+--------------------------------------+
| Property                            | Value                                |
+-------------------------------------+--------------------------------------+
| OS-DCF:diskConfig                   | MANUAL                               |
| OS-EXT-SRV-ATTR:host                | None                                 |
| OS-EXT-SRV-ATTR:hypervisor_hostname | None                                 |
| OS-EXT-SRV-ATTR:instance_name       | instance-00000001                    |
| OS-EXT-STS:power_state              | 0                                    |
| OS-EXT-STS:task_state               | scheduling                           |
| OS-EXT-STS:vm_state                 | building                             |
| accessIPv4                          |                                      |
| accessIPv6                          |                                      |
| adminPass                           | f4w3uELbjye5                         |
| config_drive                        |                                      |
| created                             | 2013-03-29T12:47:35Z                 |
| flavor                              | micro                                |
| hostId                              |                                      |
| id                                  | eaccc9da-17e9-4e53-8faa-ac0e8cd94674 |
| image                               | cirros-0.3.0-x86_64                  |
| key_name                            | None                                 |
| metadata                            | {}                                   |
| name                                | vm1                                  |
| progress                            | 0                                    |
| security_groups                     | [{u'name': u'default'}]              |
| status                              | BUILD                                |
| tenant_id                           | 33c295b9099e4a5c829e6aaa335dfc31     |
| updated                             | 2013-03-29T12:47:35Z                 |
| user_id                             | eb0a969df6d647da87b0b3a1b6b2d3d8     |
+-------------------------------------+--------------------------------------+


Booting a vm without --nic parameters causes an interface to be created on the vm for each network the tenant has.

The next couple of steps are not very intuitive - there seems to be overloading of the network/subnet concepts for configuring external access. You have to create a special network that Quantum uses to represent the external network. There can only be one of these per l3-agent and it knows to use bridge br-ex for the gateway.

vagrant@controller:~$ quantum net-create ext-net --provider:network_type local \
>                     --router:external true
Created a new network:
+---------------------------+--------------------------------------+
| Field                     | Value                                |
+---------------------------+--------------------------------------+
| admin_state_up            | True                                 |
| id                        | 1af055b7-20e9-42b1-9b47-9db9e40d1625 |
| name                      | ext-net                              |
| provider:network_type     | local                                |
| provider:physical_network |                                      |
| provider:segmentation_id  |                                      |
| router:external           | True                                 |
| shared                    | False                                |
| status                    | ACTIVE                               |
| subnets                   |                                      |
| tenant_id                 | 33c295b9099e4a5c829e6aaa335dfc31     |
+---------------------------+--------------------------------------+


Now create a subnet on this network. Because this subnet is associated with the external network, it will be used as the CIDR block for floating IP allocation. I have used the same range as the external subnet in the diagram.

vagrant@controller:~$ quantum subnet-create ext-net 192.168.101.0/24
Created a new subnet:
+------------------+------------------------------------------------------+
| Field            | Value                                                |
+------------------+------------------------------------------------------+
| allocation_pools | {"start": "192.168.101.2", "end": "192.168.101.254"} |
| cidr             | 192.168.101.0/24                                     |
| dns_nameservers  |                                                      |
| enable_dhcp      | True                                                 |
| gateway_ip       | 192.168.101.1                                        |
| host_routes      |                                                      |
| id               | fcb5d670-405e-4f70-9de1-ca24733af5b2                 |
| ip_version       | 4                                                    |
| name             |                                                      |
| network_id       | 1af055b7-20e9-42b1-9b47-9db9e40d1625                 |
| tenant_id        | 33c295b9099e4a5c829e6aaa335dfc31                     |
+------------------+------------------------------------------------------+

Note: I should have not have enabled dhcp on this range (--enable_dhcp False).


vagrant@controller:~$ quantum net-list   
+--------------------------------------+---------+--------------------------------------+
| id                                   | name    | subnets                              |
+--------------------------------------+---------+--------------------------------------+
| 1af055b7-20e9-42b1-9b47-9db9e40d1625 | ext-net | fcb5d670-405e-4f70-9de1-ca24733af5b2 |
| cf46fc34-62b8-4866-9af2-a35b13a0fd7a | net1    | c220885d-01a2-4e27-9e4c-c5910d0fc6d0 |
+--------------------------------------+---------+--------------------------------------+


vagrant@controller:~$ quantum router-create router1
Created a new router:
+-----------------------+--------------------------------------+
| Field                 | Value                                |
+-----------------------+--------------------------------------+
| admin_state_up        | True                                 |
| external_gateway_info |                                      |
| id                    | b6ea6b1a-7a1d-415b-90e4-fc8b7cc34d1d |
| name                  | router1                              |
| status                | ACTIVE                               |
| tenant_id             | 33c295b9099e4a5c829e6aaa335dfc31     |
+-----------------------+--------------------------------------+

vagrant@controller:~$ quantum router-gateway-set router1 ext-net
Set gateway for router router1


vagrant@controller:~$ quantum router-interface-add router1 sub1
Added interface to router router1


vagrant@controller:~$ quantum floatingip-create ext-net
Created a new floatingip:
+---------------------+--------------------------------------+
| Field               | Value                                |
+---------------------+--------------------------------------+
| fixed_ip_address    |                                      |
| floating_ip_address | 192.168.101.4                        |
| floating_network_id | 1af055b7-20e9-42b1-9b47-9db9e40d1625 |
| id                  | f59aaaa4-5789-4473-bc24-e0f3bcc479f4 |
| port_id             |                                      |
| router_id           |                                      |
| tenant_id           | 33c295b9099e4a5c829e6aaa335dfc31     |
+---------------------+--------------------------------------+


Now find the Quantum port id that the vm's interface is plugged into

vagrant@controller:~$ quantum port-list --fields id \
>                     -- --device_id eaccc9da-17e9-4e53-8faa-ac0e8cd94674
+--------------------------------------+
| id                                   |
+--------------------------------------+
| e61cbaa9-7911-467d-a69f-fc6332263f36 |
+--------------------------------------+


vagrant@controller:~$ quantum floatingip-associate \
>                     f59aaaa4-5789-4473-bc24-e0f3bcc479f4 \
>                     e61cbaa9-7911-467d-a69f-fc6332263f36

Associated floatingip f59aaaa4-5789-4473-bc24-e0f3bcc479f4


vagrant@controller:~$ quantum floatingip-show \
>                     f59aaaa4-5789-4473-bc24-e0f3bcc479f4
+---------------------+--------------------------------------+
| Field               | Value                                |
+---------------------+--------------------------------------+
| fixed_ip_address    | 10.0.33.3                            |
| floating_ip_address | 192.168.101.4                        |
| floating_network_id | 1af055b7-20e9-42b1-9b47-9db9e40d1625 |
| id                  | f59aaaa4-5789-4473-bc24-e0f3bcc479f4 |
| port_id             | e61cbaa9-7911-467d-a69f-fc6332263f36 |
| router_id           | b6ea6b1a-7a1d-415b-90e4-fc8b7cc34d1d |
| tenant_id           | 33c295b9099e4a5c829e6aaa335dfc31     |
+---------------------+--------------------------------------+


Now the vm can be reached from the laptop (192.168.101.1 - vboxnet7 in this case) using 192.168.101.4. The password for the cirros user is "cubswin:)"

laptop$ ping -c1 192.168.101.4
PING 192.168.101.4 (192.168.101.4) 56(84) bytes of data.
64 bytes from 192.168.101.4: icmp_req=1 ttl=63 time=115 ms


laptop$ ssh cirros@192.168.101.4
The authenticity of host '192.168.101.4 (192.168.101.4)' can't be established.
RSA key fingerprint is d2:27:2b:44:d7:db:6e:a5:6a:1c:92:5d:f6:9e:b9:32.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.101.4' (RSA) to the list of known hosts.
cirros@192.168.101.4's password: 


$ uname -a
Linux cirros 3.0.0-12-virtual #20-Ubuntu SMP Fri Oct 7 18:19:02 UTC 2011 x86_64 GNU/Linux
$ free
             total         used         free       shared      buffers
Mem:         37180        15036        22144            0          400
-/+ buffers:              14636        22544
Swap:            0            0            0


$ ip addr show dev eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether fa:16:3e:0c:e5:70 brd ff:ff:ff:ff:ff:ff
    inet 10.0.33.3/24 brd 10.0.33.255 scope global eth0
    inet6 fe80::f816:3eff:fe0c:e570/64 scope link 
       valid_lft forever preferred_lft forever