~ggouzi/obinstall/obinstall

« back to all changes in this revision

Viewing changes to demos/bin/orange-box-configure-openstack

  • Committer: MMorana
  • Date: 2016-03-24 01:18:40 UTC
  • Revision ID: mass@ubuntu.com-20160324011840-blxydmf7ca4ggle0
Splitting out demos from install

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/bin/bash
2
 
#
3
 
#    orange-box-configure-openstack
4
 
#    Copyright (C) 2014 Canonical Ltd.
5
 
#
6
 
#    Authors: Darryl Weaver <darryl.weaver@canonical.com>
7
 
#
8
 
#    This program is free software: you can redistribute it and/or modify
9
 
#    it under the terms of the GNU General Public License as published by
10
 
#    the Free Software Foundation, version 3 of the License.
11
 
#
12
 
#    This program is distributed in the hope that it will be useful,
13
 
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 
#    GNU General Public License for more details.
16
 
#
17
 
#    You should have received a copy of the GNU General Public License
18
 
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
 
 
20
 
set -e
21
 
 
22
 
echo "This command is run to configure an Orange-Box Openstack deployment"
23
 
 
24
 
obnum=`hostname | cut -c 10- -`
25
 
external_net=`expr ${obnum} + 1`
26
 
 
27
 
QUANTUM_EXT_NET_GW="172.27.${external_net}.254"
28
 
QUANTUM_EXT_NET_CIDR="172.27.${obnum}.0/23"
29
 
QUANTUM_EXT_NET_NAME="ext_net"
30
 
QUANTUM_DNS="172.27.${external_net}.254"
31
 
QUANTUM_FLOAT_RANGE_START="172.27.${external_net}.200"
32
 
QUANTUM_FLOAT_RANGE_END="172.27.${external_net}.253"
33
 
 
34
 
QUANTUM_FIXED_NET_CIDR="192.168.14.0/24"
35
 
QUANTUM_FIXED_NET_NAME="admin_net"
36
 
 
37
 
keystone=$(juju status keystone | grep public-address | head -1 | awk '{print $2}')
38
 
 
39
 
echo "export SERVICE_ENDPOINT=http://$keystone:35357/v2.0/
40
 
export SERVICE_TOKEN=admin
41
 
export OS_AUTH_URL=http://$keystone:35357/v2.0/
42
 
export OS_USERNAME=admin
43
 
export OS_PASSWORD=admin
44
 
export OS_TENANT_NAME=admin
45
 
export OS_REGION_NAME=RegionOne
46
 
" > ~/nova.rc
47
 
 
48
 
source ~/nova.rc
49
 
 
50
 
# Determine the tenant id for the configured tenant name.
51
 
export TENANT_ID="$(keystone tenant-list | grep $OS_TENANT_NAME | awk '{ print $2 }')"
52
 
 
53
 
if [ "$TENANT_ID" = "" ]; then
54
 
        echo "Unable to find tenant ID, keystone auth problem"
55
 
        exit
56
 
fi
57
 
 
58
 
echo "Configuring Openstack Neutron Networking"
59
 
 
60
 
#create ext network with neutron for floating IPs
61
 
neutron net-show ext_net > /dev/null 2>&1 || neutron net-create ext_net --tenant-id $TENANT_ID -- --router:external=True
62
 
EXTERNAL_NETWORK_ID=$(neutron net-show ext_net | grep " id" | awk '{print $4}')
63
 
neutron subnet-show ext_net_subnet > /dev/null 2>&1 || neutron subnet-create ext_net $QUANTUM_EXT_NET_CIDR --name ext_net_subnet --tenant-id $TENANT_ID \
64
 
--allocation-pool start=$QUANTUM_FLOAT_RANGE_START,end=$QUANTUM_FLOAT_RANGE_END \
65
 
--gateway $QUANTUM_EXT_NET_GW --disable-dhcp --dns_nameservers $QUANTUM_DNS list=true
66
 
 
67
 
#Create private network for neutron for tenant VMs
68
 
neutron net-show private > /dev/null 2>&1 || neutron net-create private
69
 
neutron subnet-show private_subnet > /dev/null 2>&1 || neutron subnet-create private $QUANTUM_FIXED_NET_CIDR -- --name private_subnet --dns_nameservers list=true $QUANTUM_DNS
70
 
SUBNET_ID=$(neutron subnet-show private_subnet | grep " id" | awk '{print $4}')
71
 
 
72
 
#Create router for external network and private network
73
 
neutron router-show provider-router > /dev/null 2>&1 || neutron router-create --tenant-id $TENANT_ID provider-router
74
 
ROUTER_ID=$(neutron router-show provider-router | grep " id" | awk '{print $4}')
75
 
 
76
 
PORT_ID=$(neutron port-list | grep $SUBNET_ID | awk '{print $2}')
77
 
if [ "$PORT_ID" != "" ]; then
78
 
        neutron router-interface-delete $ROUTER_ID port=$PORT_ID
79
 
fi
80
 
neutron router-interface-add $ROUTER_ID $SUBNET_ID
81
 
 
82
 
neutron router-gateway-clear provider-router
83
 
neutron router-gateway-set $ROUTER_ID $EXTERNAL_NETWORK_ID
84
 
 
85
 
echo "Configuring security groups for access to ICMP, SSH and RDP by default"
86
 
 
87
 
#Configure the default security group to allow ICMP and SSH
88
 
nova secgroup-list-rules default | grep icmp  > /dev/null 2>&1 || nova secgroup-add-rule default icmp -1 -1 0.0.0.0/0 > /dev/null 2>&1
89
 
nova secgroup-list-rules default | grep 22  > /dev/null 2>&1 || nova secgroup-add-rule default tcp 22 22 0.0.0.0/0 > /dev/null 2>&1
90
 
#for rdp
91
 
nova secgroup-list-rules default | grep 3389  > /dev/null 2>&1 || nova secgroup-add-rule default tcp 3389 3389 0.0.0.0/0 > /dev/null 2>&1
92
 
 
93
 
echo "Uploading default SSH key"
94
 
 
95
 
#Upload a default SSH key
96
 
nova keypair-list | grep default  > /dev/null 2>&1 || nova  keypair-add --pub-key ~/.ssh/id_rsa.pub default > /dev/null 2>&1
97
 
 
98
 
echo "Modifying the flavors to be better sized for the Orange Box"
99
 
 
100
 
#Modify the flavours to fit better on the OB
101
 
#nova flavor-create FLAVOR_NAME FLAVOR_ID RAM_IN_MB ROOT_DISK_IN_GB NUMBER_OF_VCPUS
102
 
nova flavor-delete m1.tiny > /dev/null 2>&1
103
 
nova flavor-delete m1.small > /dev/null 2>&1
104
 
nova flavor-delete m1.medium > /dev/null 2>&1
105
 
nova flavor-delete m1.large > /dev/null 2>&1
106
 
nova flavor-delete m1.xlarge > /dev/null 2>&1
107
 
nova flavor-create --is-public true m1.tiny auto 512 5 1 > /dev/null 2>&1
108
 
nova flavor-create --is-public true m1.small auto 1024 10 1 > /dev/null 2>&1
109
 
nova flavor-create --is-public true m1.medium auto 2048 10 2 > /dev/null 2>&1
110
 
nova flavor-create --is-public true m1.large auto 3072 10 2 > /dev/null 2>&1
111
 
nova flavor-create --is-public true m1.xlarge auto 4096 10 2 > /dev/null 2>&1
112
 
 
113
 
echo "modifying default quotas for admin user"
114
 
 
115
 
#Modify quotas for the tenant to allow large deployments
116
 
nova quota-update --instances 100 $TENANT_ID
117
 
nova quota-update --cores 200 $TENANT_ID
118
 
nova quota-update --ram 204800 $TENANT_ID
119
 
nova quota-update --security-groups 200 $TENANT_ID
120
 
 
121
 
echo "Uploading images to glance"
122
 
 
123
 
#Upload images to glance
124
 
glance image-show "Precise x86_64" > /dev/null 2>&1 || glance add name="Precise x86_64" is_public=true container_format=ovf disk_format=qcow2 <  /srv/data/precise-server-cloudimg-amd64-disk1.img 
125
 
glance image-show "Trusty x86_64" > /dev/null 2>&1 || glance add name="Trusty x86_64" is_public=true container_format=ovf disk_format=qcow2 <  /srv/data/trusty-server-cloudimg-amd64-disk1.img
126
 
glance image-show "CentOS 6.4" > /dev/null 2>&1 || glance add name="CentOS 6.4" is_public=true container_format=bare disk_format=qcow2 < /srv/data/centos6.4-x86_64-gold-master.img
127
 
glance image-show "Cirros 0.3" > /dev/null 2>&1 || glance add name="Cirros 0.3" is_public=true container_format=bare disk_format=qcow2 < /srv/data/cirros-0.3.2-x86_64-disk.img
128
 
glance image-show "Windows Server 2012" > /dev/null 2>&1 || glance add name="Windows Server 2012" is_public=true container_format=bare disk_format=qcow2 < /srv/data/windows_server_2012_r2_standard_eval_kvm_20131117.qcow2 &
129
 
 
130
 
exit