StarlingX NFVI Orchestration
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

489 lines
17 KiB

#!/bin/bash
#
# SPDX-License-Identifier: Apache-2.0
#
# Copyright (C) 2019 Intel Corporation
#
# Copyright (c) 2019 Wind River Systems, Inc.
#
# lib/nfv
_XTRACE_STX_NFV=$(set +o | grep xtrace)
set -o xtrace
# Defaults
# --------
STXNFV_DIR=${GITDIR[$STX_NFV_NAME]}
STXNFV_SYSCONFDIR=/etc
STXNFV_OCF_ROOT=/usr/lib/ocf
NFV_DIR=$STXNFV_DIR/nfv
NFV_CONF_DIR=$STXNFV_SYSCONFDIR/nfv
NFV_OCF_DIR=$STXNFV_OCF_ROOT/resource.d/nfv
NFV_CLIENT_DIR=$NFV_DIR/nfv-client
NFV_COMMON_DIR=$NFV_DIR/nfv-common
NFV_PLUGINS_DIR=$NFV_DIR/nfv-plugins
NFV_TOOLS_DIR=$NFV_DIR/nfv-tools
NFV_VIM_DIR=$NFV_DIR/nfv-vim
# nova-api-proxy
NOVA_API_PROXY_CONF=$STXNFV_SYSCONFDIR/proxy
NOVA_API_PROXY_DIR=$STXNFV_DIR/nova-api-proxy/nova-api-proxy
# mtce-guest
MTCE_GUEST_DIR=$STXNFV_DIR/mtce-guest
MTCE_GUEST_CONF=$STXNFV_SYSCONFDIR/mtc
MTCE_GUEST_OCF_DIR=$STXNFV_OCF_ROOT/resource.d/platform
# STX_INST_DIR should be a non-root-writable place to install build artifacts
STX_INST_DIR=${STX_INST_DIR:-/usr/local}
STX_BIN_DIR=$STX_INST_DIR/bin
# Set up so we don't use sudo for installs when not necessary
STX_SUDO="sudo"
[[ -w $STX_INST_DIR ]] && STX_SUDO="env"
PYTHON_SITE_DIR=$(python -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())")
# Functions
# ---------
function cleanup_guest_agent {
sudo rm -rf $MTCE_GUEST_OCF_DIR/guestAgent
sudo rm -rf $MTCE_GUEST_CONF/guestAgent.ini
$STX_SUDO rm -rf $STX_INST_DIR/bin/guestAgent
sudo rm -rf $STXNFV_SYSCONFDIR/init.d/guestAgent
sudo rm -rf $STXNFV_SYSCONFDIR/logrotate.d/guestAgent.logrotate
}
function cleanup_guest_server {
sudo rm -rf $MTCE_GUEST_CONF/guestServer.ini
$STX_SUDO rm -rf $STX_INST_DIR/bin/guestServer
sudo rm -rf $STXNFV_SYSCONFDIR/init.d/guestServer
sudo rm -rf $STXNFV_SYSCONFDIR/pmon.d/guestServer.conf
sudo rm -rf $STXNFV_SYSCONFDIR/logrotate.d/guestServer.logrotate
}
function cleanup_nfv {
if is_service_enabled nfv-vim || is_service_enabled nfv-vim-api || is_service_enabled nfv-vim-webserver; then
sudo rm -rf $NFV_CONF_DIR
sudo rm -rf $NFV_OCF_DIR
sudo rm -rf $STXNFV_SYSCONFDIR/bash_completion.d/sw-manager
cleanup_nfv_vim
cleanup_nfv_common
cleanup_nfv_plugins
cleanup_nfv_tools
cleanup_nfv_client
fi
if is_service_enabled nfv-vim; then
sudo rm -rf $STXNFV_SYSCONFDIR/systemd/system/devstack@nfv-vim.service
fi
if is_service_enabled nfv-vim-api; then
sudo rm -rf $STXNFV_SYSCONFDIR/systemd/system/devstack@nfv-vim-api.service
fi
if is_service_enabled nfv-vim-webserver; then
sudo rm -rf $STXNFV_SYSCONFDIR/systemd/system/devstack@nfv-vim-webserver.service
fi
if is_service_enabled nova-api-proxy; then
cleanup_nova_api_proxy
fi
if is_service_enabled guest-agent || is_service_enabled guest-server; then
pushd $MTCE_GUEST_DIR/src
make clean
popd
fi
if is_service_enabled guest-agent; then
cleanup_guest_agent
fi
if is_service_enabled guest-server; then
cleanup_guest_server
fi
}
function cleanup_nfv_client {
pip_uninstall nfv-client
}
function cleanup_nfv_common {
pip_uninstall windriver-nfv-common-plugins
}
function cleanup_nfv_plugins {
pip_uninstall windriver-nfv-plugins
}
function cleanup_nfv_tools {
pip_uninstall nfv-tools
}
function cleanup_nfv_vim {
pip_uninstall nfv-vim
}
function cleanup_nova_api_proxy {
pip_uninstall api-proxy
}
function configure_guest_agent {
sudo sed -i "s%DAEMON=\"/usr/local/bin/\${DAEMON_NAME}\"%DAEMON=\"$STX_INST_DIR/bin/\${DAEMON_NAME}\"%" $STXNFV_SYSCONFDIR/init.d/guestAgent
iniset -sudo $STXNFV_SYSCONFDIR/systemd/system/devstack@guest-agent.service "Service" "Type" "forking"
iniset -sudo $STXNFV_SYSCONFDIR/systemd/system/devstack@guest-agent.service "Service" "PIDFile" "/var/run/guestAgent.pid"
if [ $DISTRO == "bionic" ]; then
iniset -sudo $STXNFV_SYSCONFDIR/systemd/system/devstack@guest-agent.service "Service" "Environment" "UBUNTU_BIONIC=yes"
fi
}
function configure_guest_server {
sudo sed -i "s%DAEMON=\"/usr/local/bin/\${DAEMON_NAME}\"%DAEMON=\"$STX_INST_DIR/bin/\${DAEMON_NAME}\"%" $STXNFV_SYSCONFDIR/init.d/guestServer
iniset -sudo $STXNFV_SYSCONFDIR/systemd/system/devstack@guest-server.service "Service" "Type" "forking"
iniset -sudo $STXNFV_SYSCONFDIR/systemd/system/devstack@guest-server.service "Service" "PIDFile" "/var/run/guestServer.pid"
}
function configure_mtce_guest_common {
# the content related to "controller" in /etc/hosts is generated by metal
# devstack plugin. for the time being, there are no entries about oamcontroller,
# pxecontroller, ipv6, etc. so here we use a simple regular expression.
if grep -q "^[0-9]\{1,3\}.*\s\+controller$" /etc/hosts; then
sudo sed -i "s%^[0-9]\{1,3\}.*\s\+controller$%$HOST_IP controller%" /etc/hosts
else
echo "$HOST_IP controller" | sudo tee -a "/etc/hosts"
fi
if grep -q "^[0-9]\{1,3\}.*\s\+.*controller-0$" /etc/hosts; then
sudo sed -i "s%^[0-9]\{1,3\}.*\s\+controller-0$%$HOST_IP controller-0%" /etc/hosts
else
echo "$HOST_IP controller-0" | sudo tee -a "/etc/hosts"
fi
if [ -f "/etc/platform/.initial_config_complete" ]; then
sudo touch /etc/platform/.initial_config_complete
fi
if [ -f "/var/run/.goenabled" ]; then
sudo touch /var/run/.goenabled
fi
}
function configure_nfv {
if is_service_enabled nfv-vim || is_service_enabled nfv-vim-api || is_service_enabled nfv-vim-webserver; then
configure_nfv_common
fi
if is_service_enabled nfv-vim; then
configure_nfv_vim
fi
if is_service_enabled nfv-vim-api; then
configure_nfv_vim_api
fi
if is_service_enabled nfv-vim-webserver; then
configure_nfv_vim_webserver
fi
if is_service_enabled nova-api-proxy; then
configure_nova_api_proxy
fi
if is_service_enabled guest-agent || is_service_enabled guest-server; then
configure_mtce_guest_common
fi
if is_service_enabled guest-agent; then
configure_guest_agent
fi
if is_service_enabled guest-server; then
configure_guest_server
fi
}
function configure_nfv_common {
iniset -sudo $NFV_CONF_DIR/nfv_plugins/nfvi_plugins/config.ini "platform" "authorization_ip" "$HOST_IP"
iniset -sudo $NFV_CONF_DIR/nfv_plugins/nfvi_plugins/config.ini "openstack" "authorization_ip" "$HOST_IP"
iniset -sudo $NFV_CONF_DIR/nfv_plugins/nfvi_plugins/config.ini "amqp" "host" "$RABBIT_HOST"
iniset -sudo $NFV_CONF_DIR/nfv_plugins/nfvi_plugins/config.ini "amqp" "user_id" "$RABBIT_USERID"
iniset -sudo $NFV_CONF_DIR/nfv_plugins/nfvi_plugins/config.ini "amqp" "password" "$RABBIT_PASSWORD"
if [[ "${CELLSV2_SETUP}" == "singleconductor" ]]; then
iniset -sudo $NFV_CONF_DIR/nfv_plugins/nfvi_plugins/config.ini "amqp" "virt_host" "/"
else
iniset -sudo $NFV_CONF_DIR/nfv_plugins/nfvi_plugins/config.ini "amqp" "virt_host" "nova_cell1"
fi
iniset -sudo $NFV_CONF_DIR/nfv_plugins/nfvi_plugins/config.ini "host-listener" "host" "$HOST_IP"
sudo sed -i -e "s|@SYSCONFDIR@|${STXNFV_SYSCONFDIR}|g" $NFV_CONF_DIR/vim/config.ini
sudo sed -i -e "s|@PYTHONROOT@|${PYTHON_SITE_DIR}|g" $NFV_CONF_DIR/vim/config.ini
iniset -sudo $NFV_CONF_DIR/vim/config.ini "sw-mgmt-configuration" "single_controller" "True"
iniset -sudo $NFV_CONF_DIR/vim/config.ini "vim-webserver" "host" "$HOST_IP"
}
function configure_nfv_vim {
sudo sed -i -e "s|@SYSCONFDIR@|${STXNFV_SYSCONFDIR}|g" $NFV_OCF_DIR/vim
sudo sed -i -e 's|${OCF_ROOT}|@OCF_ROOT@|g' $NFV_OCF_DIR/vim
sudo sed -i -e "s|@OCF_ROOT@|${STXNFV_OCF_ROOT}|g" $NFV_OCF_DIR/vim
iniset -sudo $STXNFV_SYSCONFDIR/systemd/system/devstack@nfv-vim.service "Service" "Type" "forking"
iniset -sudo $STXNFV_SYSCONFDIR/systemd/system/devstack@nfv-vim.service "Service" "PIDFile" "/var/run/nfv-vim.pid"
}
function configure_nfv_vim_api {
sudo sed -i -e "s|@SYSCONFDIR@|${STXNFV_SYSCONFDIR}|g" $NFV_OCF_DIR/vim-api
sudo sed -i -e 's|${OCF_ROOT}|@OCF_ROOT@|g' $NFV_OCF_DIR/vim-api
sudo sed -i -e "s|@OCF_ROOT@|${STXNFV_OCF_ROOT}|g" $NFV_OCF_DIR/vim-api
iniset -sudo $STXNFV_SYSCONFDIR/systemd/system/devstack@nfv-vim-api.service "Service" "Type" "forking"
iniset -sudo $STXNFV_SYSCONFDIR/systemd/system/devstack@nfv-vim-api.service "Service" "PIDFile" "/var/run/nfv-vim-api.pid"
}
function configure_nfv_vim_webserver {
sudo sed -i -e "s|@SYSCONFDIR@|${STXNFV_SYSCONFDIR}|g" $NFV_OCF_DIR/vim-webserver
sudo sed -i -e 's|${OCF_ROOT}|@OCF_ROOT@|g' $NFV_OCF_DIR/vim-webserver
sudo sed -i -e "s|@OCF_ROOT@|${STXNFV_OCF_ROOT}|g" $NFV_OCF_DIR/vim-webserver
iniset -sudo $STXNFV_SYSCONFDIR/systemd/system/devstack@nfv-vim-webserver.service "Service" "Type" "forking"
iniset -sudo $STXNFV_SYSCONFDIR/systemd/system/devstack@nfv-vim-webserver.service "Service" "PIDFile" "/var/run/nfv-vim-webserver.pid"
}
function configure_nova_api_proxy {
iniset -sudo $NOVA_API_PROXY_CONF/nova-api-proxy.conf "DEFAULT" "pool_size" "256"
iniset -sudo $NOVA_API_PROXY_CONF/nova-api-proxy.conf "DEFAULT" "nfvi_compute_listen_port" "30003"
iniset -sudo $NOVA_API_PROXY_CONF/nova-api-proxy.conf "DEFAULT" "nfvi_compute_listen" "127.0.0.1"
iniset -sudo $NOVA_API_PROXY_CONF/nova-api-proxy.conf "keystone_authtoken" "auth_type" "password"
iniset -sudo $NOVA_API_PROXY_CONF/nova-api-proxy.conf "keystone_authtoken" "auth_url" "$KEYSTONE_SERVICE_URI"
iniset -sudo $NOVA_API_PROXY_CONF/nova-api-proxy.conf "keystone_authtoken" "user_domain_name" "$SERVICE_DOMAIN_NAME"
iniset -sudo $NOVA_API_PROXY_CONF/nova-api-proxy.conf "keystone_authtoken" "username" "nova"
iniset -sudo $NOVA_API_PROXY_CONF/nova-api-proxy.conf "keystone_authtoken" "password" "$SERVICE_PASSWORD"
iniset -sudo $NOVA_API_PROXY_CONF/nova-api-proxy.conf "keystone_authtoken" "project_domain_name" "$SERVICE_DOMAIN_NAME"
iniset -sudo $NOVA_API_PROXY_CONF/nova-api-proxy.conf "keystone_authtoken" "project_name" "$SERVICE_PROJECT_NAME"
iniset -sudo $NOVA_API_PROXY_CONF/nova-api-proxy.conf "keystone_authtoken" "admin_user" "nova"
iniset -sudo $NOVA_API_PROXY_CONF/nova-api-proxy.conf "keystone_authtoken" "admin_tenant_name" "$SERVICE_PROJECT_NAME"
iniset -sudo $STXNFV_SYSCONFDIR/systemd/system/devstack@nova-api-proxy.service "Service" "Type" "simple"
iniset -sudo $STXNFV_SYSCONFDIR/systemd/system/devstack@nova-api-proxy.service "Service" "PIDFile" "/var/run/nova-api-proxy.pid"
}
function install_guest_agent {
pushd $MTCE_GUEST_DIR/src
sudo install -m 755 -d $MTCE_GUEST_OCF_DIR
sudo install -m 755 -p -D scripts/guestAgent.ocf $MTCE_GUEST_OCF_DIR/guestAgent
sudo install -m 644 -p -D scripts/guest.ini $MTCE_GUEST_CONF/guestAgent.ini
$STX_SUDO install -m 755 -p -D guestAgent $STX_INST_DIR/bin/guestAgent
sudo install -m 755 -p -D scripts/guestAgent $STXNFV_SYSCONFDIR/init.d/guestAgent
sudo install -m 644 -p -D scripts/guestAgent.logrotate $STXNFV_SYSCONFDIR/logrotate.d/guestAgent.logrotate
popd
}
function install_guest_server {
pushd $MTCE_GUEST_DIR/src
sudo install -m 644 -p -D scripts/guest.ini $MTCE_GUEST_CONF/guestServer.ini
$STX_SUDO install -m 755 -p -D guestServer $STX_INST_DIR/bin/guestServer
sudo install -m 755 -p -D scripts/guestServer $STXNFV_SYSCONFDIR/init.d/guestServer
sudo install -m 755 -d $STXNFV_SYSCONFDIR/pmon.d
sudo install -m 644 -p -D scripts/guestServer.pmon $STXNFV_SYSCONFDIR/pmon.d/guestServer.conf
sudo install -m 644 -p -D scripts/guestServer.logrotate $STXNFV_SYSCONFDIR/logrotate.d/guestServer.logrotate
popd
}
function install_mtce_guest_common {
pushd $MTCE_GUEST_DIR/src
make EXTRALDFLAGS="-L$STX_INST_DIR"/lib64 build
popd
sudo install -m 755 -d $(STXNFV_SYSCONFDIR)/logrotate.d
}
function install_nfv {
if is_service_enabled nfv-vim || is_service_enabled nfv-vim-api || is_service_enabled nfv-vim-webserver; then
install_nfv_vim
install_nfv_common
install_nfv_plugins
install_nfv_tools
install_nfv_client
fi
if is_service_enabled nova-api-proxy; then
install_nova_api_proxy
fi
if is_service_enabled guest-agent || is_service_enabled guest-server; then
install_mtce_guest_common
fi
if is_service_enabled guest-agent; then
install_guest_agent
fi
if is_service_enabled guest-server; then
install_guest_server
fi
}
function install_nfv_client {
pushd $NFV_CLIENT_DIR
python setup.py build
sudo python setup.py install --root=/ --install-lib=${PYTHON_SITE_DIR} --single-version-externally-managed
popd
sudo install -d -m 755 $STXNFV_SYSCONFDIR/bash_completion.d
sudo install -m 444 $NFV_CLIENT_DIR/scripts/sw-manager.completion $STXNFV_SYSCONFDIR/bash_completion.d/sw-manager
}
function install_nfv_common {
pushd $NFV_COMMON_DIR
python setup.py build
sudo python setup.py install --root=/ --install-lib=${PYTHON_SITE_DIR} --single-version-externally-managed
popd
}
function install_nfv_plugins {
pushd $NFV_PLUGINS_DIR
python setup.py build
sudo python setup.py install --root=/ --install-lib=${PYTHON_SITE_DIR} --single-version-externally-managed
popd
sudo install -d -m 755 $NFV_CONF_DIR/nfv_plugins/
sudo install -d -m 755 $NFV_CONF_DIR/nfv_plugins/alarm_handlers/
sudo install -p -D -m 644 $NFV_PLUGINS_DIR/nfv_plugins/alarm_handlers/config.ini $NFV_CONF_DIR/nfv_plugins/alarm_handlers/config.ini
sudo install -d -m 755 $NFV_CONF_DIR/nfv_plugins/event_log_handlers/
sudo install -p -D -m 644 $NFV_PLUGINS_DIR/nfv_plugins/event_log_handlers/config.ini $NFV_CONF_DIR/nfv_plugins/event_log_handlers/config.ini
sudo install -d -m 755 $NFV_CONF_DIR/nfv_plugins/nfvi_plugins/
sudo install -p -D -m 644 $NFV_PLUGINS_DIR/nfv_plugins/nfvi_plugins/config.ini $NFV_CONF_DIR/nfv_plugins/nfvi_plugins/config.ini
sudo install -p -D -m 644 $NFV_PLUGINS_DIR/scripts/nfvi-plugins.logrotate $STXNFV_SYSCONFDIR/logrotate.d/nfvi-plugins.logrotate
}
function install_nfv_tools {
pushd $NFV_TOOLS_DIR
python setup.py build
sudo python setup.py install --root=/ --install-lib=${PYTHON_SITE_DIR} --single-version-externally-managed
popd
}
function install_nfv_vim {
pushd $NFV_VIM_DIR
python setup.py build
sudo python setup.py install --root=/ --install-lib=${PYTHON_SITE_DIR} --single-version-externally-managed
popd
sudo install -d -m 755 $NFV_CONF_DIR
sudo install -d -m 755 $NFV_OCF_DIR
sudo install -p -D -m 755 $NFV_VIM_DIR/scripts/vim $NFV_OCF_DIR/vim
sudo install -p -D -m 755 $NFV_VIM_DIR/scripts/vim-api $NFV_OCF_DIR/vim-api
sudo install -p -D -m 755 $NFV_VIM_DIR/scripts/vim-webserver $NFV_OCF_DIR/vim-webserver
sudo install -d -m 755 $NFV_CONF_DIR/vim/
sudo install -p -D -m 644 $NFV_VIM_DIR/nfv_vim/config.ini $NFV_CONF_DIR/vim/config.ini
sudo install -p -D -m 644 $NFV_VIM_DIR/nfv_vim/debug.ini $NFV_CONF_DIR/vim/debug.ini
}
function install_nova_api_proxy {
pushd $NOVA_API_PROXY_DIR
python setup.py build
sudo python setup.py install --root=/ --install-lib=${PYTHON_SITE_DIR} --single-version-externally-managed
popd
sudo install -d -m 755 $NOVA_API_PROXY_CONF
sudo install -p -D -m 744 $NOVA_API_PROXY_DIR/nova_api_proxy/nova-api-proxy.conf $NOVA_API_PROXY_CONF/nova-api-proxy.conf
sudo install -p -D -m 744 $NOVA_API_PROXY_DIR/nova_api_proxy/api-proxy-paste.ini $NOVA_API_PROXY_CONF/api-proxy-paste.ini
}
function start_guest_agent {
run_process guest-agent "$STXNFV_SYSCONFDIR/init.d/guestAgent start" root root
}
function start_guest_server {
run_process guest-server "$STXNFV_SYSCONFDIR/init.d/guestServer start" root root
}
function start_nfv {
if is_service_enabled nfv-vim; then
start_nfv_vim
fi
if is_service_enabled nfv-vim-api; then
start_nfv_vim_api
fi
if is_service_enabled nfv-vim-webserver; then
start_nfv_vim_webserver
fi
if is_service_enabled nova-api-proxy; then
start_nova_api_proxy
fi
if is_service_enabled guest-agent; then
start_guest_agent
fi
if is_service_enabled guest-server; then
start_guest_server
fi
}
function start_nfv_vim {
run_process nfv-vim "$NFV_OCF_DIR/vim start" root root
}
function start_nfv_vim_api {
run_process nfv-vim-api "$NFV_OCF_DIR/vim-api start" root root
}
function start_nfv_vim_webserver {
run_process nfv-vim-webserver "$NFV_OCF_DIR/vim-webserver start" root root
}
function start_nova_api_proxy {
local daemon
daemon=$(which nova-api-proxy)
run_process nova-api-proxy "$daemon --config-file=$NOVA_API_PROXY_CONF/nova-api-proxy.conf" root root
}
function stop_guest_agent {
stop_process guest-agent
}
function stop_guest_server {
stop_process guest-server
}
function stop_nfv {
if is_service_enabled nfv-vim; then
stop_nfv_vim
fi
if is_service_enabled nfv-vim-api; then
stop_nfv_vim_api
fi
if is_service_enabled nfv-vim-webserver; then
stop_nfv_vim_webserver
fi
if is_service_enabled nova-api-proxy; then
stop_nova_api_proxy
fi
if is_service_enabled guest-agent; then
stop_guest_agent
fi
if is_service_enabled guest-server; then
stop_guest_server
fi
}
function stop_nfv_vim {
stop_process nfv-vim
}
function stop_nfv_vim_api {
stop_process nfv-vim-api
}
function stop_nfv_vim_webserver {
stop_process nfv-vim-webserver
}
function stop_nova_api_proxy {
stop_process nova-api-proxy
}
$_XTRACE_STX_NFV