Add Congress datasource create to post-install script
[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
23 fi
24
25 # launch eth on computer nodes and remove default gw route
26 launch_eth() {
27     computer_list=$(juju status --format short | grep -Eo 'nova-compute/[0-9]')
28     for node in $computer_list; do
29         echo "node name is ${node}"
30         juju ssh $node "sudo ifconfig $EXTNET_PORT up"
31         juju ssh $node "sudo route del default gw $EXTNET_GW"
32     done
33 }
34
35 # Update gateway mac to onos for l3 function
36 update_gw_mac() {
37     ## get gateway mac
38     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})'")
39     ## set external gateway mac in onos
40     juju set onos-controller gateway-mac=$EXTNET_GW_MAC
41 }
42
43 unitAddress() {
44         juju status | python -c "import yaml; import sys; print yaml.load(sys.stdin)[\"services\"][\"$1\"][\"units\"][\"$1/$2\"][\"public-address\"]" 2> /dev/null
45 }
46
47 unitMachine() {
48         juju status | python -c "import yaml; import sys; print yaml.load(sys.stdin)[\"services\"][\"$1\"][\"units\"][\"$1/$2\"][\"machine\"]" 2> /dev/null
49 }
50
51 # create external network and subnet in openstack
52 create_openrc() {
53     mkdir -m 0700 -p cloud
54     keystoneIp=$(unitAddress keystone 0)
55     adminPasswd=$(juju get keystone | grep admin-password -A 5 | grep value | awk '{print $2}')
56     configOpenrc admin $adminPasswd admin http://$keystoneIp:5000/v2.0 Canonical > cloud/admin-openrc
57     chmod 0600 cloud/admin-openrc
58 }
59
60 configOpenrc() {
61         cat <<-EOF
62                 export OS_USERNAME=$1
63                 export OS_PASSWORD=$2
64                 export OS_TENANT_NAME=$3
65                 export OS_AUTH_URL=$4
66                 export OS_REGION_NAME=$5
67                 EOF
68 }
69
70 create_openrc
71
72 . ./cloud/admin-openrc
73
74 wget -P /tmp/images http://download.cirros-cloud.net/0.3.3/cirros-0.3.3-x86_64-disk.img
75 glance image-create --name "cirros-0.3.3-x86_64" --file /tmp/images/cirros-0.3.3-x86_64-disk.img --disk-format qcow2 --container-format bare --progress
76
77 #wget -P /tmp/images http://cloud-images.ubuntu.com/trusty/current/trusty-server-cloudimg-amd64-disk1.img
78 #glance image-create --name "ubuntu-trusty-daily" --file /tmp/images/trusty-server-cloudimg-amd64-disk1.img --disk-format qcow2 --container-format bare --progress
79 rm -rf /tmp/images
80
81 # adjust tiny image
82 nova flavor-delete m1.tiny
83 nova flavor-create m1.tiny 1 512 8 1
84
85 # configure security groups
86 neutron security-group-rule-create --direction ingress --ethertype IPv4 --protocol icmp --remote-ip-prefix 0.0.0.0/0 default
87 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
88
89 # import key pair
90 keystone tenant-create --name demo --description "Demo Tenant"
91 keystone user-create --name demo --tenant demo --pass demo --email demo@demo.demo
92
93 nova keypair-add --pub-key ~/.ssh/id_rsa.pub ubuntu-keypair
94
95 # configure external network
96
97 ##
98 ## Create external subnet Network
99 ##
100 if [ "onos" == "$1" ]; then
101     launch_eth
102     neutron net-create ext-net --shared --router:external=True
103     neutron subnet-create ext-net --name ext-subnet $EXTNET_NET
104     update_gw_mac
105 else
106     neutron net-create ext-net --shared --router:external --provider:physical_network external --provider:network_type flat
107     neutron subnet-create ext-net --name ext-subnet \
108        --allocation-pool start=$EXTNET_FIP,end=$EXTNET_LIP \
109           --disable-dhcp --gateway $EXTNET_GW $EXTNET_NET
110 fi
111
112 # create vm network
113 neutron net-create demo-net
114 neutron subnet-create --name demo-subnet --gateway 10.20.5.1 demo-net 10.20.5.0/24
115
116 neutron router-create demo-router
117
118 neutron router-interface-add demo-router demo-subnet
119
120 neutron router-gateway-set demo-router ext-net
121
122 # create pool of floating ips
123 i=0
124 while [ $i -ne 3 ]; do
125         neutron floatingip-create ext-net
126         i=$((i + 1))
127 done
128
129 #http://docs.openstack.org/juno/install-guide/install/apt/content/launch-instance-neutron.html
130 # 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
131 # nova floating-ip-associate demo-instance1 10.5.8.35
132
133 # Create Congress datasources
134 sudo apt-get install -y python-congressclient
135 openstack congress datasource create nova "nova" \
136   --config username=$OS_USERNAME \
137   --config tenant_name=$OS_TENANT_NAME \
138   --config password=$OS_PASSWORD \
139   --config auth_url=http://$keystoneIp:5000/v2.0
140 openstack congress datasource create neutronv2 "neutronv2" \
141   --config username=$OS_USERNAME \
142   --config tenant_name=$OS_TENANT_NAME \
143   --config password=$OS_PASSWORD \
144   --config auth_url=http://$keystoneIp:5000/v2.0
145 openstack congress datasource create ceilometer "ceilometer" \
146   --config username=$OS_USERNAME \
147   --config tenant_name=$OS_TENANT_NAME \
148   --config password=$OS_PASSWORD \
149   --config auth_url=http://$keystoneIp:5000/v2.0
150 openstack congress datasource create cinder "cinder" \
151   --config username=$OS_USERNAME \
152   --config tenant_name=$OS_TENANT_NAME \
153   --config password=$OS_PASSWORD \
154   --config auth_url=http://$keystoneIp:5000/v2.0
155 openstack congress datasource create glancev2 "glancev2" \
156   --config username=$OS_USERNAME \
157   --config tenant_name=$OS_TENANT_NAME \
158   --config password=$OS_PASSWORD \
159   --config auth_url=http://$keystoneIp:5000/v2.0
160 openstack congress datasource create keystone "keystone" \
161   --config username=$OS_USERNAME \
162   --config tenant_name=$OS_TENANT_NAME \
163   --config password=$OS_PASSWORD \
164   --config auth_url=http://$keystoneIp:5000/v2.0