modified cengn pod1 as per details provided.
[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 unitAddress()
11 {
12         juju status | python -c "import yaml; import sys; print yaml.load(sys.stdin)[\"services\"][\"$1\"][\"units\"][\"$1/$2\"][\"public-address\"]" 2> /dev/null
13 }
14
15 unitMachine()
16 {
17         juju status | python -c "import yaml; import sys; print yaml.load(sys.stdin)[\"services\"][\"$1\"][\"units\"][\"$1/$2\"][\"machine\"]" 2> /dev/null
18 }
19
20 # create external network and subnet in openstack
21 create_openrc() {
22   mkdir -m 0700 -p cloud
23   keystoneIp=$(unitAddress keystone 0)
24   adminPasswd=$(juju get keystone | grep admin-password -A 5 | grep value | awk '{print $2}')
25   configOpenrc admin $adminPasswd admin http://$keystoneIp:5000/v2.0 Canonical > cloud/admin-openrc
26   chmod 0600 cloud/admin-openrc
27 }
28
29 configOpenrc()
30 {
31         cat <<-EOF
32                 export OS_USERNAME=$1
33                 export OS_PASSWORD=$2
34                 export OS_TENANT_NAME=$3
35                 export OS_AUTH_URL=$4
36                 export OS_REGION_NAME=$5
37                 EOF
38 }
39
40 create_openrc
41
42 . ./cloud/admin-openrc
43
44 wget -P /tmp/images http://download.cirros-cloud.net/0.3.3/cirros-0.3.3-x86_64-disk.img
45 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
46
47 #wget -P /tmp/images http://cloud-images.ubuntu.com/trusty/current/trusty-server-cloudimg-amd64-disk1.img
48 #glance image-create --name "ubuntu-trusty-daily" --file /tmp/images/trusty-server-cloudimg-amd64-disk1.img --disk-format qcow2 --container-format bare --progress
49 rm -rf /tmp/images
50
51 # adjust tiny image
52 nova flavor-delete m1.tiny
53 nova flavor-create m1.tiny 1 512 8 1
54
55 # configure security groups
56 #neutron security-group-rule-create --direction ingress --ethertype IPv4 --protocol icmp --remote-ip-prefix 0.0.0.0/0 default
57 #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
58
59 # import key pair
60 keystone tenant-create --name demo --description "Demo Tenant"
61 keystone user-create --name demo --tenant demo --pass demo --email demo@demo.demo
62
63 nova keypair-add --pub-key ~/.ssh/id_rsa.pub ubuntu-keypair
64
65 # configure external network
66 neutron net-create ext-net --shared --router:external --provider:physical_network external --provider:network_type flat
67
68 ##
69 ## Parse Network config
70 ##
71
72 if [ -f ./deployconfig.yaml ];then
73     EXTERNAL_NETWORK=`grep floating-ip-range deployconfig.yaml | cut -d ' ' -f 4 `
74
75     # split EXTERNAL_NETWORK=first ip;last ip; gateway;network
76
77     EXTNET=(${EXTERNAL_NETWORK//,/ })
78
79     EXTNET_FIP=${EXTNET[0]}
80     EXTNET_LIP=${EXTNET[1]}
81     EXTNET_GW=${EXTNET[2]}
82     EXTNET_NET=${EXTNET[3]}
83
84     neutron subnet-create ext-net --name ext-subnet \
85        --allocation-pool start=$EXTNET_FIP,end=$EXTNET_LIP \
86           --disable-dhcp --gateway $EXTNET_GW $EXTNET_NET
87 fi
88
89 # create vm network
90 neutron net-create demo-net
91 neutron subnet-create --name demo-subnet --gateway 10.20.5.1 demo-net 10.20.5.0/24
92
93 neutron router-create demo-router
94
95 neutron router-interface-add demo-router demo-subnet
96
97 neutron router-gateway-set demo-router ext-net
98
99 # create pool of floating ips
100 i=0
101 while [ $i -ne 5 ]; do
102         neutron floatingip-create ext-net
103         i=$((i + 1))
104 done
105
106 #http://docs.openstack.org/juno/install-guide/install/apt/content/launch-instance-neutron.html
107 # 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
108 # nova floating-ip-associate demo-instance1 10.5.8.35