-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathquickstart-v5.0.2.sh
executable file
·151 lines (130 loc) · 4.39 KB
/
quickstart-v5.0.2.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/bin/bash
#
# Midonet Ansible Quickstart
# Copyright (C) 2015 Midokura SARL
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# This script must be run as root and is intended for CentOS 7 or
# Ubuntu 14.04 LTS
# This script sets up the environment for, and runs, an Ansible playbook
# which installs Midonet 5.0.2 with OpenStack Liberty on a single node.
set -e
if [ -n "$DEBUG" ]; then
set -x
fi
MIDONET_VERSION=5.0.2
WORK_PATH=/opt/quickstart-midonet
LOG_FILE=$WORK_PATH/quickstart-midonet.log
TARBALL_URL=https://www.midonet.org/quickstart-v${MIDONET_VERSION}.tgz
DEB_PKGS="python-all python-dev curl autoconf g++ python2.7-dev wget software-properties-common"
RPM_PKGS="curl autoconf gcc-c++ python2-devel wget redhat-lsb-core redhat-lsb epel-release"
DEFAULT_NIC=$(ip r | grep default | grep -o "dev [a-z0-9]*" | awk '{ print $2 }')
ETH0_IP=$(ip -4 -o a show dev $DEFAULT_NIC | awk '{ ADDR=$4; gsub("/.+", "", ADDR); print ADDR; }')
if [ -n "$OVERRIDE_URL" ]; then
TARBALL_URL=$OVERRIDE_URL
fi
# Functions
function check_root {
if [ "$(id -u)" != "0" ]; then
echo "This script must be run as root."
exit 1
fi
}
function distro_fail {
echo ""
echo "Unsupported distribution/version. Only Ubuntu 14.04 (Trusty) or CentOS 7 (Core) is supported."
echo ""
exit 1
}
function check_distro {
echo -n "* Checking distribution/version... "
. /etc/os-release
echo $NAME >>$LOG_FILE 2>&1
echo $VERSION >>$LOG_FILE 2>&1
HORIZON_URL="http://$ETH0_IP/horizon"
if [[ "$NAME" =~ "Ubuntu" && "$VERSION" =~ "Trusty" ]]; then
DISTRO="ubuntu14"
elif [[ "$NAME" =~ "CentOS" && "$VERSION_ID" =~ "7" ]]; then
DISTRO="centos7"
else
distro_fail
fi
echo "ok."
}
# Install dependencies
function install_deps {
echo -n "* Installing basic dependencies... "
if [[ "$DISTRO" == "ubuntu14" ]]; then
apt-get update >>$LOG_FILE 2>&1
apt-get -y install $DEB_PKGS >>$LOG_FILE 2>&1
elif [[ "$DISTRO" == "centos7" ]]; then
yum -y install $RPM_PKGS >>$LOG_FILE 2>&1
else
distro_fail
fi
echo "ok."
}
function install_ansible {
echo -n "* Installing ansible... "
if [[ "$DISTRO" == "ubuntu14" ]]; then
apt-add-repository -y ppa:ansible/ansible >>$LOG_FILE 2>&1
apt-get update >>$LOG_FILE 2>&1
apt-get install -y ansible >>$LOG_FILE 2>&1
elif [[ "$DISTRO" == "centos7" ]]; then
#TODO Remove --enablerepo=epel-testing once Ansible 2.0 is available in EPEL
yum install -y ansible --enablerepo=epel-testing >>$LOG_FILE 2>&1
else
distro_fail
fi
echo "ok."
}
function get_tarball {
wget $TARBALL_URL -O /tmp/quickstart-v${MIDONET_VERSION}.tgz >>$LOG_FILE 2>&1
echo -n "* Untarring the installer at $WORK_PATH "
tar xzf /tmp/quickstart-v${MIDONET_VERSION}.tgz -C $WORK_PATH >>$LOG_FILE 2>&1
echo "ok."
}
function run_ansible {
echo "* Running ansible... "
cd $WORK_PATH/quickstart
if [ -n "$DEBUG" ]; then
EXTRA_FLAGS="-vvvv"
fi
ansible-playbook $EXTRA_FLAGS -i hosts_localhost_allinone -e deploy=$DISTRO -e os_virt_type=qemu local-allinone.yml >>$LOG_FILE 2>&1
}
function ip_forward {
echo -n "* Enabling IP forwarding on host... "
sysctl -w net.ipv4.ip_forward=1 >>$LOG_FILE 2>&1
iptables -t nat -I POSTROUTING -o $DEFAULT_NIC -s 200.200.200.0/24 -j MASQUERADE >>$LOG_FILE 2>&1
iptables -I FORWARD -s 200.200.200.0/24 -j ACCEPT >>$LOG_FILE 2>&1
iptables -I FORWARD -d 200.200.200.0/24 -j ACCEPT >>$LOG_FILE 2>&1
}
export LC_ALL=C
echo "Logging to $LOG_FILE"
check_root
mkdir -p $WORK_PATH
check_distro
install_deps
install_ansible
get_tarball
run_ansible
ip_forward
cat <<-EOF
OpenStack Liberty with MidoNet $MIDONET_VERSION available in $HORIZON_URL
To access through Horizon, use one of the following user/passwords:
* demo/midonet (Demo tenant, demo user)
* admin/midonet (Admin tenant, admin user)
Thanks for trying MidoNet!
EOF