4 # POC Script to build/install/deploy/orchestrate Tacker on an OPNFV Brhamaputra Fuel cluster
5 # Script assuming it runs on the openstack primary controller (where is opendaylight
6 # present) and there is a fuel master on 10.20.0.2 and can be reached with default
9 # author: Ferenc Cserepkei <ferenc.cserepkei@ericsson.com>
11 # (c) 2016 Telefonaktiebolaget L. M. ERICSSON
13 # All rights reserved. This program and the accompanying materials are made available
14 # under the terms of the Apache License, Version 2.0 which accompanies this distribution,
15 # and is available at http://www.apache.org/licenses/LICENSE-2.0
19 SSH_OPTIONS=(-o StrictHostKeyChecking=no -o GlobalKnownHostsFile=/dev/null -o UserKnownHostsFile=/dev/null -o LogLevel=error)
21 MYDIR=$(dirname $(readlink -f "$0"))
22 MYREPO="tacker-server"
23 CLIREPO="tacker-client"
26 CLIENT=$(echo python-python-tackerclient_*_all.deb)
27 JSONRPC=$(echo python-jsonrpclib_*_all.deb)
28 SERVER=$(echo python-tacker_*_all.deb)
33 # Function checks whether crudini is available, if not - installs
34 function chkCrudini () {
35 if [[ ! -f '/usr/bin/crudini' ]]; then
36 wget -N http://mirrors.kernel.org/ubuntu/pool/universe/p/python-iniparse/python-iniparse_0.4-2.1build1_all.deb
37 wget -N http://archive.ubuntu.com/ubuntu/pool/universe/c/crudini/crudini_0.3-1_amd64.deb
38 dpkg -i python-iniparse_0.4-2.1build1_all.deb crudini_0.3-1_amd64.deb
42 # Function checks whether a python egg is available, if not, installs
45 IPPACK=$(python - <<'____EOF'
47 from os.path import join
48 for package in pip.get_installed_distributions():
49 print(package.location)
50 print(join(package.location, *package._get_metadata("top_level.txt")))
53 echo "$IPPACK" | grep -q "$PKG"
59 # Function setting up the build/deploy environment
60 function envSetup () {
62 apt-get install -y git python-pip python-all debhelper
67 # Function installs jsonrpclib from github
68 function deployJsonrpclib () {
69 if [[ -e "${MYDIR}/${JSONRPC}" ]]; then
70 echo "$JSONRPC exists."
75 git clone https://github.com/joshmarshall/jsonrpclib.git $DEPREPO
77 dpkg --purge python-jsonrpclib
78 python setup.py --command-packages=stdeb.command bdist_deb
80 JSONRPC=$(echo python-jsonrpclib_*_all.deb)
85 # Function builds Tacker server from github
86 function buildTackerServer () {
87 if [[ -e "${MYDIR}/${SERVER}" ]]; then
88 echo "$SERVER exists."
93 git clone -b 'SFC_colorado' https://github.com/trozet/tacker.git $MYREPO
96 diff -ruN a/setup.cfg b/setup.cfg
97 --- a/setup.cfg 2016-02-08 10:54:37.416525934 +0100
98 +++ b/setup.cfg 2016-02-08 10:55:29.293428896 +0100
105 etc/tacker/api-paste.ini
106 etc/tacker/policy.json
107 etc/tacker/tacker.conf
108 etc/tacker/rootwrap.conf
111 etc/tacker/rootwrap.d/servicevm.filters
112 - etc/init.d = etc/init.d/tacker-server
113 + /etc/init.d = etc/init.d/tacker-server
118 dpkg --purge python-tacker
119 python setup.py --command-packages=stdeb.command bdist_deb
122 # Function corrects and installs the Tacker-server debian package
123 function blessPackage () {
124 pushd "${MYDIR}/${MYREPO}/deb_dist"
125 SERVER=$(echo python-tacker_*_all.deb)
127 DEBFILE="${MYDIR}/${MYREPO}/deb_dist/${SERVER}"
128 TMPDIR=$(mktemp -d /tmp/deb.XXXXXX) || exit 1
129 OUTPUT=$(basename "$DEBFILE")
130 if [[ -e "${MYDIR}/${OUTPUT}" ]]; then
131 echo "$OUTPUT exists."
135 dpkg-deb -x "$DEBFILE" "$TMPDIR"
136 dpkg-deb --control "$DEBFILE" "${TMPDIR}/DEBIAN"
139 diff -ruN a/DEBIAN/control b/DEBIAN/control
140 --- a/DEBIAN/control 2016-02-08 10:06:18.000000000 +0000
141 +++ b/DEBIAN/control 2016-02-08 10:45:09.501373675 +0000
144 Maintainer: OpenStack <openstack-dev@lists.openstack.org>
146 -Depends: python (>= 2.7), python (<< 2.8), python:any (>= 2.7.1-0ubuntu2), python-pbr, python-paste, python-pastedeploy, python-routes, python-anyjson, python-babel, python-eventlet, python-greenlet, python-httplib2, python-requests, python-iso8601, python-jsonrpclib, python-jinja2, python-kombu, python-netaddr, python-sqlalchemy (>= 1.0~), python-sqlalchemy (<< 1.1), python-webob, python-heatclient, python-keystoneclient, alembic, python-six, python-stevedore, python-oslo.config, python-oslo.messaging-, python-oslo.rootwrap, python-novaclient
147 +Depends: python (>= 2.7), python (<< 2.8), python:any (>= 2.7.1-0ubuntu2), python-pbr, python-paste, python-pastedeploy, python-routes, python-anyjson, python-babel, python-eventlet, python-greenlet, python-httplib2, python-requests, python-iso8601, python-jsonrpclib, python-jinja2, python-kombu, python-netaddr, python-sqlalchemy (>= 1.0~), python-sqlalchemy (<< 1.1), python-webob, python-heatclient, python-keystoneclient, alembic, python-six, python-stevedore, python-oslo.config, python-oslo.messaging, python-oslo.rootwrap, python-novaclient
150 Description: OpenStack servicevm/device manager
153 echo "Patching deb..."
154 dpkg -b "$TMPDIR" "${MYDIR}/${SERVER}"
156 dpkg -i "${MYDIR}/${SERVER}"
159 # Function deploys Tacker-server (installs missing mandatory files: upstart, default)
160 function deployTackerServer () {
161 rm -rf /etc/default/tacker-server
162 cat > /etc/default/tacker-server <<EOFTD
164 PIDFILE=/var/run/tacker/tacker-server.pid
165 LOGFILE=/var/log/tacker/tacker-server.log
166 PATH="\${PATH:+\$PATH:}/usr/sbin:/sbin"
167 TMPDIR=/var/lib/tacker/tmp
169 rm -rf /etc/init/tacker.conf
170 cat > /etc/init/tacker.conf <<EOFSC
171 # tacker-server - Provides the Tacker servicevm/device manager service
172 description "Openstack Tacker Server"
173 author "Ferenc Cserepkei <ferenc.cserepkei@ericsson.com>"
175 start on runlevel [2345]
176 stop on runlevel [!2345]
180 limit nofile 65535 65535
185 # stop job from continuing if no config file found for daemon
186 [ ! -f /etc/default/tacker-server ] && { stop; exit 0; }
187 [ ! -f /etc/tacker/tacker.conf ] && { stop; exit 0; }
189 # source the config file
190 . /etc/default/tacker-server
192 # stop job from continuing if admin has not enabled service in
194 [ -z "\$ENABLED" ] && { stop; exit 0; }
196 mkdir -p /var/run/tacker
197 mkdir -p /var/log/tacker
198 echo "Starting tacker server"
202 echo "Stopping tacker server"
205 exec /usr/bin/python /usr/bin/tacker-server --log-file=/var/log/tacker/tacker-server.log -v -d --config-file=/etc/tacker/tacker.conf
209 # Function installs python-tackerclient from github
210 function deployTackerClient() {
211 if [[ -e "${MYDIR}/${CLIENT}" ]]; then
212 echo "$CLIENT exists."
217 dpkg --purge python-tackerclient
218 git clone -b 'SFC_refactor' https://github.com/trozet/python-tackerclient.git $CLIREPO
220 python setup.py --command-packages=stdeb.command bdist_deb
222 CLIENT=$(echo python-python-tackerclient_*_all.deb)
224 dpkg -i "${MYDIR}/${CLIENT}"
227 # Function removes the cloned git repositories
228 function remove_repo () {
229 if [[ -d "${MYDIR}/${1}" ]]; then
234 # Funcion copies and installs built artifact on all remaining cluster nodes
235 function populate_client() {
236 wget -O deb http://archive.ubuntu.com/ubuntu/pool/universe/s/sshpass/sshpass_1.05-1_amd64.deb &&\
240 clusternodes=$(sshpass -p "r00tme" ssh ${SSH_OPTIONS[@]} root@10.20.0.2 fuel node | cut -d '|' -f 5 | grep -E -o "([0-9]{1,3}[\.]){3}[0-9]{1,3}" )
241 myaddr=$(ifconfig br-fw-admin | sed -n '/inet addr/s/.*addr.\([^ ]*\) .*/\1/p')
242 for anode in $clusternodes ; do
243 if [ "$anode" != "$myaddr" ] ; then
244 echo "Installing $CLIENT on $anode"
245 scp ${SSH_OPTIONS[@]} -i "${MYDIR}/.ssh/id_rsa" ${CLIENT} ${fadm}@${anode}:${CLIENT}
246 ssh ${SSH_OPTIONS[@]} -i "${MYDIR}/.ssh/id_rsa" ${fadm}@${anode} sudo dpkg -i ${CLIENT}
247 ssh ${SSH_OPTIONS[@]} -i "${MYDIR}/.ssh/id_rsa" ${fadm}@${anode} rm ${CLIENT}
253 # Function orchestrate the Tacker service
254 function orchestarte () {
255 rm -rf /etc/puppet/modules/tacker
256 pushd /etc/puppet/modules
257 git clone https://github.com/trozet/puppet-tacker.git tacker
258 rm -rf /etc/puppet/modules/tacker/.git
263 # Port(s) Protocol ServiceDetails Source
264 # 8805-8872 tcp,udp Unassigned IANA
267 auth_uri=$(crudini --get '/etc/heat/heat.conf' 'keystone_authtoken' 'auth_uri')
268 identity_uri=$(crudini --get '/etc/heat/heat.conf' 'keystone_authtoken' 'identity_uri')
269 int_addr=$(ifconfig br-mesh | sed -n '/inet addr/s/.*addr.\([^ ]*\) .*/\1/p')
270 mgmt_addr=$(ifconfig br-mgmt | sed -n '/inet addr/s/.*addr.\([^ ]*\) .*/\1/p')
271 pub_addr=$(ifconfig br-ex-lnx | sed -n '/inet addr/s/.*addr.\([^ ]*\) .*/\1/p')
272 rabbit_host=$(crudini --get '/etc/heat/heat.conf' 'oslo_messaging_rabbit' 'rabbit_hosts'| cut -d ':' -f 1)
273 rabbit_password=$(crudini --get '/etc/heat/heat.conf' 'oslo_messaging_rabbit' 'rabbit_password')
274 sql_host=$(hiera database_vip)
275 database_connection="mysql://tacker:tacker@${sql_host}/tacker"
276 internal_url="http://${int_addr}:${bind_port}"
277 admin_url="http://${mgmt_addr}:${bind_port}"
278 public_url="http://${pub_addr}:${bind_port}"
279 heat_api_vip=$(crudini --get '/etc/heat/heat.conf' 'heat_api' 'bind_host')
280 allowed_hosts="[ '${sql_host}', '${HOSTNAME%%.domain.tld}', 'localhost', '127.0.0.1', '%' ]"
281 heat_uri="http://${heat_api_vip}:8004/v1"
283 service_tenant='services'
287 cat > configure_tacker.pp << EOF
288 class mysql::config {}
289 include mysql::config
290 class mysql::server {}
291 include mysql::server
294 package_ensure => 'absent',
295 client_package_ensure => 'absent',
296 bind_port => '${bind_port}',
297 keystone_password => '${myPassword}',
298 keystone_tenant => '${service_tenant}',
299 auth_uri => '${auth_uri}',
300 identity_uri => '${identity_uri}',
301 database_connection => '${database_connection}',
302 rabbit_host => '${rabbit_host}',
303 rabbit_password => '${rabbit_password}',
304 heat_uri => '${heat_uri}',
305 opendaylight_host => '${mgmt_addr}',
306 opendaylight_port => '${odl_port}',
309 class { 'tacker::db::mysql':
310 password => '${myPassword}',
311 allowed_hosts => ${allowed_hosts},
314 class { 'tacker::keystone::auth':
315 password => '${myPassword}',
316 tenant => '${service_tenant}',
317 admin_url => '${admin_url}',
318 internal_url => '${internal_url}',
319 public_url => '${public_url}',
320 region => '${myRegion}',
324 apt-get install -y mysql-client-5.5
325 cat > /usr/bin/tacker-manage <<EOFAKEMANAGE
328 chmod +x /usr/bin/tacker-manage
329 puppet apply configure_tacker.pp
331 cat > tackerc <<EOFRC
334 export OS_NO_CACHE='true'
335 export OS_TENANT_NAME='${service_tenant}'
336 export OS_PROJECT_NAME='${service_tenant}'
337 export OS_USERNAME='tacker'
338 export OS_PASSWORD='${myPassword}'
339 export OS_AUTH_URL='${auth_uri}'
340 export OS_DEFAULT_DOMAIN='default'
341 export OS_AUTH_STRATEGY='keystone'
342 export OS_REGION_NAME='${myRegion}'
343 export TACKER_ENDPOINT_TYPE='internalURL'
348 # Funcion copies and installs built environment settings on all remaining cluster nodes
349 function populate_rc() {
350 wget -O deb http://archive.ubuntu.com/ubuntu/pool/universe/s/sshpass/sshpass_1.05-1_amd64.deb &&\
354 clusternodes=$(sshpass -p "r00tme" ssh ${SSH_OPTIONS[@]} root@10.20.0.2 fuel node | cut -d '|' -f 5 | grep -E -o "([0-9]{1,3}[\.]){3}[0-9]{1,3}" )
355 myaddr=$(ifconfig br-fw-admin | sed -n '/inet addr/s/.*addr.\([^ ]*\) .*/\1/p')
356 for anode in $clusternodes ; do
357 if [ "$anode" != "$myaddr" ] ; then
358 echo "Populating settings to $anode"
359 scp ${SSH_OPTIONS[@]} -i "${MYDIR}/.ssh/id_rsa" tackerc ${fadm}@${anode}:tackerc
374 remove_repo "$MYREPO"
375 remove_repo "$DEPREPO"
376 remove_repo "$CLIREPO"
378 echo "Built: ${MYDIR}/${OUTPUT}"
379 echo "Built: ${MYDIR}/${CLIENT}"
380 echo "Built: ${MYDIR}/${JSONRPC}"
381 echo "tackerc - mandatory environmental parameters file created"