Remove update_gw_mac for ONOS.
[joid.git] / ci / openstack.sh
1 #!/bin/bash -ex
2
3 ##############################################################################
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
9
10 if [ -f ./deployconfig.yaml ];then
11     EXTERNAL_NETWORK=`grep floating-ip-range deployconfig.yaml | cut -d ' ' -f 4 `
12
13     # split EXTERNAL_NETWORK=first ip;last ip; gateway;network
14
15     EXTNET=(${EXTERNAL_NETWORK//,/ })
16
17     EXTNET_FIP=${EXTNET[0]}
18     EXTNET_LIP=${EXTNET[1]}
19     EXTNET_GW=${EXTNET[2]}
20     EXTNET_NET=${EXTNET[3]}
21     EXTNET_PORT=`grep "ext-port" deployconfig.yaml | cut -d ' ' -f 4 | sed -e 's/ //' | tr ',' ' '`
22     ADMNET_GW=`grep "admNetgway" deployconfig.yaml | cut -d ' ' -f 4 | sed -e 's/ //' | tr ',' ' '`
23
24 fi
25
26 # launch eth on computer nodes and remove default gw route
27 launch_eth() {
28     computer_list=$(juju status --format short | grep -Eo 'nova-compute/[0-9]')
29     for node in $computer_list; do
30         echo "node name is ${node}"
31         juju ssh $node "sudo ifconfig $EXTNET_PORT up"
32         #juju ssh $node "sudo route del default gw $ADMNET_GW"
33     done
34 }
35
36 # Update gateway mac to onos for l3 function
37 update_gw_mac() {
38     ## get gateway mac
39     EXTNET_GW_MAC=$(juju ssh nova-compute/0 "arp -a ${EXTNET_GW} | grep -Eo '([0-9a-fA-F]{2})(([/\s:-][0-9a-fA-F]{2}){5})'")
40     ## set external gateway mac in onos
41     juju set onos-controller gateway-mac=$EXTNET_GW_MAC
42 }
43
44 unitAddress() {
45         juju status | python -c "import yaml; import sys; print yaml.load(sys.stdin)[\"services\"][\"$1\"][\"units\"][\"$1/$2\"][\"public-address\"]" 2> /dev/null
46 }
47
48 unitMachine() {
49         juju status | python -c "import yaml; import sys; print yaml.load(sys.stdin)[\"services\"][\"$1\"][\"units\"][\"$1/$2\"][\"machine\"]" 2> /dev/null
50 }
51
52 # create external network and subnet in openstack
53 create_openrc() {
54     mkdir -m 0700 -p cloud
55     keystoneIp=$(juju get keystone | grep vip: -A 7 | grep value | awk '{print $2}')
56     if [ -z "$keystoneIp" ]; then
57         keystoneIp=$(unitAddress keystone 0)
58     fi
59     adminPasswd=$(juju get keystone | grep admin-password -A 5 | grep value | awk '{print $2}')
60     configOpenrc admin $adminPasswd admin http://$keystoneIp:5000/v2.0 Canonical > cloud/admin-openrc
61     chmod 0600 cloud/admin-openrc
62 }
63
64 configOpenrc() {
65         cat <<-EOF
66                 export OS_USERNAME=$1
67                 export OS_PASSWORD=$2
68                 export OS_TENANT_NAME=$3
69                 export OS_AUTH_URL=$4
70                 export OS_REGION_NAME=$5
71                 EOF
72 }
73
74 create_openrc
75
76 . ./cloud/admin-openrc
77
78 wget -P /tmp/images http://download.cirros-cloud.net/0.3.3/cirros-0.3.3-x86_64-disk.img
79 openstack image create --file /tmp/images/cirros-0.3.3-x86_64-disk.img --disk-format qcow2 --container-format bare "cirros-0.3.3-x86_64"
80
81 #wget -P /tmp/images http://cloud-images.ubuntu.com/trusty/current/trusty-server-cloudimg-amd64-disk1.img
82 #openstack image create --file /tmp/images/trusty-server-cloudimg-amd64-disk1.img --disk-format qcow2 --container-format bare "ubuntu-trusty-daily"
83 #wget -P /tmp/images http://cloud-images.ubuntu.com/trusty/current/xenial-server-cloudimg-amd64.tar.gz
84 #openstack image create --file /tmp/images/xenial-server-cloudimg-amd64.tar.gz --container-format bare --disk-format raw "xenial-server-cloudimg-amd64"
85
86 rm -rf /tmp/images
87
88 # adjust tiny image
89 #nova flavor-delete m1.tiny
90 #nova flavor-create m1.tiny 1 512 8 1
91
92
93 # import key pair
94 openstack project create --description "Demo Tenant" demo
95 openstack user create --project demo --password demo --email demo@demo.demo demo
96
97 openstack keypair create --public-key ~/.ssh/id_rsa.pub ubuntu-keypair
98
99 # configure external network
100
101 ##
102 ## Create external subnet Network
103 ##
104 if [ "onos" == "$1" ]; then
105     launch_eth
106     neutron net-create ext-net --shared --router:external=True
107     neutron subnet-create ext-net --name ext-subnet $EXTNET_NET
108     #update_gw_mac
109 elif [ "nosdn" == "$1" ]; then
110     neutron net-create ext-net --shared --router:external --provider:physical_network external --provider:network_type flat
111     neutron subnet-create ext-net --name ext-subnet \
112        --allocation-pool start=$EXTNET_FIP,end=$EXTNET_LIP \
113           --disable-dhcp --gateway $EXTNET_GW $EXTNET_NET
114     # configure security groups
115     neutron security-group-rule-create --direction ingress --ethertype IPv4 --protocol icmp --remote-ip-prefix 0.0.0.0/0 default
116     neutron security-group-rule-create --direction ingress --ethertype IPv4 --protocol tcp --port-range-min 22 --port-range-max 22 --remote-ip-prefix 0.0.0.0/0 default
117 else
118     neutron net-create ext-net --shared --router:external --provider:physical_network external --provider:network_type flat
119     neutron subnet-create ext-net --name ext-subnet \
120        --allocation-pool start=$EXTNET_FIP,end=$EXTNET_LIP \
121           --disable-dhcp --gateway $EXTNET_GW $EXTNET_NET
122     # configure security groups
123     #neutron security-group-rule-create --direction ingress --ethertype IPv4 --protocol icmp --remote-ip-prefix 0.0.0.0/0 default
124     #neutron security-group-rule-create --direction ingress --ethertype IPv4 --protocol tcp --port-range-min 22 --port-range-max 22 --remote-ip-prefix 0.0.0.0/0 default
125 fi
126
127
128 # create vm network
129 neutron net-create demo-net
130 neutron subnet-create --name demo-subnet --gateway 10.20.5.1 demo-net 10.20.5.0/24
131
132 neutron router-create demo-router
133
134 neutron router-interface-add demo-router demo-subnet
135
136 neutron router-gateway-set demo-router ext-net
137
138 # create pool of floating ips
139 i=0
140 while [ $i -ne 3 ]; do
141         neutron floatingip-create ext-net
142         i=$((i + 1))
143 done
144
145 #http://docs.openstack.org/juno/install-guide/install/apt/content/launch-instance-neutron.html
146 # nova boot --flavor m1.small --image cirros-0.3.3-x86_64 --nic net-id=b65479a4-3638-4595-9245-6e41ccd8bfd8 --security-group default --key-name ubuntu-keypair demo-instance1
147 # nova floating-ip-associate demo-instance1 10.5.8.35
148
149 # Create Congress datasources
150 sudo apt-get install -y python-congressclient
151 openstack congress datasource create nova "nova" \
152   --config username=$OS_USERNAME \
153   --config tenant_name=$OS_TENANT_NAME \
154   --config password=$OS_PASSWORD \
155   --config auth_url=http://$keystoneIp:5000/v2.0
156 openstack congress datasource create neutronv2 "neutronv2" \
157   --config username=$OS_USERNAME \
158   --config tenant_name=$OS_TENANT_NAME \
159   --config password=$OS_PASSWORD \
160   --config auth_url=http://$keystoneIp:5000/v2.0
161 openstack congress datasource create ceilometer "ceilometer" \
162   --config username=$OS_USERNAME \
163   --config tenant_name=$OS_TENANT_NAME \
164   --config password=$OS_PASSWORD \
165   --config auth_url=http://$keystoneIp:5000/v2.0
166 openstack congress datasource create cinder "cinder" \
167   --config username=$OS_USERNAME \
168   --config tenant_name=$OS_TENANT_NAME \
169   --config password=$OS_PASSWORD \
170   --config auth_url=http://$keystoneIp:5000/v2.0
171 openstack congress datasource create glancev2 "glancev2" \
172   --config username=$OS_USERNAME \
173   --config tenant_name=$OS_TENANT_NAME \
174   --config password=$OS_PASSWORD \
175   --config auth_url=http://$keystoneIp:5000/v2.0
176 openstack congress datasource create keystone "keystone" \
177   --config username=$OS_USERNAME \
178   --config tenant_name=$OS_TENANT_NAME \
179   --config password=$OS_PASSWORD \
180   --config auth_url=http://$keystoneIp:5000/v2.0