141 lines
5.0 KiB
Plaintext
Raw Normal View History

#!/bin/bash
#
# functions - networking-vpp driver devstack utility functions
function install_vpp {
if is_fedora; then
sudo tee /etc/yum.repos.d/fdio.repo <<EOF
[fdio-master]
name=fd.io master branch latest merge
baseurl=https://nexus.fd.io/content/repositories/fd.io.$VPP_BRANCH.centos7/
enabled=1
gpgcheck=0
EOF
sudo yum --enablerepo=fdio-master clean metadata
elif is_ubuntu; then
echo "deb [trusted=yes] https://nexus.fd.io/content/repositories/fd.io.$VPP_BRANCH.ubuntu.$os_CODENAME.main/ ./" | sudo tee /etc/apt/sources.list.d/99fd.io.list
# installing to prevent failure with https hosts on fd.io source
install_package apt-transport-https
else
die $LINENO "Can't install VPP on unsupported os: $os_VENDOR"
fi
# stack fails without this package, ensuring it's installed
install_package bridge-utils
install_package vpp
# if vpp service is started while installing it will not have correct
# startup conf yet, stop the service it will be started later
stop_service vpp || true
# python api package name was renamed in 17.04, try to install both
install_package vpp-python-api || install_package vpp-api-python
# plugins are required to support security groups
install_package vpp-plugins
if is_set VPP_STARTUP_CONFIG; then
if [[ -f "$VPP_STARTUP_CONFIG" && -r "$VPP_STARTUP_CONFIG" ]]; then
sudo cp -f /etc/vpp/startup.conf /etc/vpp/startup.conf.devstack_bak
sudo cp -f $VPP_STARTUP_CONFIG /etc/vpp/startup.conf
else
die $LINENO "VPP config file $VPP_STARTUP_CONFIG not a file or unreadable"
fi
elif is_set VPP_INT_PCI_DEV; then
# keep a copy of un-modified initial config file
sudo cp -f /etc/vpp/startup.conf /etc/vpp/startup.conf.devstack_bak
have_dpdk_config=`sed -n '/'^$'dpdk/p' /etc/vpp/startup.conf | wc -l`
if [[ $have_dpdk_config -eq 0 ]]; then
# we do not have dpdk section, append it to startup.conf
echo "dpdk {" | sudo tee -a /etc/vpp/startup.conf
echo "}" | sudo tee -a /etc/vpp/startup.conf
fi
# We have some very poor skills hacking this file - we add but don't substitute
# and we don't make any attempt to parse the file, so this works with default
# configs and not generally otherwise
sudo sed -i "/"^$"dpdk *{/a\ \ dev $VPP_INT_PCI_DEV" /etc/vpp/startup.conf
else
die $LINENO "VPP_STARTUP_CONFIG or VPP_INT_PCI_DEV must be set"
fi
user="$(id -un)"
sudo sed -i "/api-segment *{/a\ \ uid $user" /etc/vpp/startup.conf
}
function start_vpp {
is_package_installed vpp || install_vpp
start_service vpp
}
function set_hugepages {
if is_set NR_HUGEPAGES; then
system_hugepages="$(cat /proc/meminfo | grep HugePages_Total | awk '{print $2}')"
die_if_not_set $LINENO system_hugepages "Couldn't determine current system huge page count"
if [ "$system_hugepages" -lt "$NR_HUGEPAGES" ]; then
sudo sysctl -w vm.nr_hugepages="$NR_HUGEPAGES"
system_hugepages=$(cat /proc/meminfo | grep HugePages_Total | awk '{print $2}')
if [ "$system_hugepages" -ne "$NR_HUGEPAGES" ]; then
die $LINENO "Failed to set system huge page count to $NR_HUGEPAGES"
fi
fi
fi
}
function setup_host_env {
if is_service_enabled etcd3; then
# We don't need to run it for ourselves, it's a devstack service
RUN_ETCD=no
if [ "$CLEAN_ETCD" = "yes" ] ; then
# Need to trap the etcd3 startup
eval "$(echo -n _vpp_orig_; declare -f start_etcd3)"
start_etcd3() {
_vpp_orig_start_etcd3
clean_etcd_vpp_area
}
fi
fi
if [ "$RUN_ETCD" = "yes" ] ; then
# TODO(ijw): in fact, we may not need to run it at all (it might be
# remote) - should add an option...
is_package_installed etcd || install_package etcd
restart_service etcd
if [ "$CLEAN_ETCD" = "yes" ] ; then
clean_etcd_vpp_area
fi
fi
set_hugepages
systemctl is-active vpp || start_vpp
}
function clean_etcd_vpp_area() {
# This relies on a bunch of etcd state, and if you're stacking and unstacking
# stale cruft builds up.
# This is not a good idea if you're running multiple controllers, but it's
# fine for a single controller system.
# etcd_host may be complex, so we do our best with it
if [ ! -z "$ETCD_CA_CERT" ] ; then
proto=https
args="--ca-file $ETCD_CA_CERT"
else
proto=http
args=""
fi
if [[ ! "$ETCD_HOST" =~ "://" ]] ; then
hostarg=""
for f in $(echo "$ETCD_HOST" | tr "," "\n"); do
hostarg="$hostarg,$proto://$f:$ETCD_PORT/"
done
# Strip that leading comma
hostarg="${hostarg:1}"
else
hostarg="$ETCD_HOST"
fi
args="$args --endpoints $hostarg"
# TODO(ijw): deal with username and password
sleep 2 # settle time for the daemon
etcdctl $args rm --recursive /networking-vpp 2>/dev/null ||:
}