--- /dev/null
+include openvimd.cfg
+recursive-include database_utils *
+recursive-include scripts *
+
--- /dev/null
+#!/usr/bin/env bash
+SHELL := /bin/bash
+
+all: clean build pip install
+lite: clean build pip install_lite
+
+prepare:
+ mkdir -p build
+ cp *.py build/
+ cp MANIFEST.in build/
+ cp openvimd.py build/openvimd
+ cp ovim.py build/ovim
+ cp openvim build/
+ cp openflow build/
+ cp openvimd.cfg build/
+ cp -r scripts build/
+ #cd build/scripts; mv service-openvim.sh service-openvim; mv openvim-report.sh openvim-report; mv initopenvim.sh initopenvim
+ cp -r database_utils build/
+
+build: prepare
+ python -m py_compile build/*.py
+
+clean:
+ rm -rf build
+
+pip:
+ cd build; ./setup.py sdist
+
+install:
+ cd build; python setup.py install
+
+install_lite:
+ cd build; python setup.py install --lite
+
+
+
if [ -z "${DBPASS}" ]
then
password_ok=""
- echo -e "[client]\nuser='${DBUSER}'\npassword='vimpw'" > "$TEMPFILE"
+ echo -e "[client]\nuser='${DBUSER}'\npassword=vimpw" > "$TEMPFILE"
mysql --defaults-extra-file="$TEMPFILE" $DBHOST_ $DBPORT_ $DBNAME -e "quit" >/dev/null 2>&1 && DBPASS="vimpw"
echo -e "[client]\nuser='${DBUSER}'\npassword=''" > "$TEMPFILE"
mysql --defaults-extra-file="$TEMPFILE" $DBHOST_ $DBPORT_ $DBNAME -e "quit" >/dev/null 2>&1 && DBPASS=""
sed -e "s/vim_db/$DBNAME/" ${DIRNAME}/vim_db_structure.sql | mysql $DEF_EXTRA_FILE_PARAM $DBHOST_ $DBPORT_
echo " migrage database version"
+#${DIRNAME}/migrate_vim_db.sh $DBHOST_ $DBPORT_ $DBUSER_ $DBPASS_ -d$DBNAME $1
+DIRNAME=$(dirname $(readlink -f ${BASH_SOURCE[0]}))
+echo "${DIRNAME}/migrate_vim_db.sh $DBHOST_ $DBPORT_ $DBUSER_ $DBPASS_ -d$DBNAME $1"
${DIRNAME}/migrate_vim_db.sh $DBHOST_ $DBPORT_ $DBUSER_ $DBPASS_ -d$DBNAME $1
echo " loading ${DIRNAME}/host_ranking.sql"
--- /dev/null
+#!/usr/bin/env bash
+
+function usage(){
+ echo -e "usage: sudo $0 [OPTIONS]"
+ echo -e "Install openvim database server"
+ echo -e " OPTIONS"
+ echo -e " -U USER: database admin user. 'root' by default. Prompts if needed"
+ echo -e " -P PASS: database admin password to be used or installed. Prompts if needed"
+ echo -e " -d: d database name, default name vim_db"
+ echo -e " -u: database user, default name vim"
+ echo -e " -p: database pass, default name vimpw"
+ echo -e " -q --quiet: install in unattended mode"
+ echo -e " -h --help: show this help"
+ echo -e " --forcedb: reinstall vim_db DB, deleting previous database if exists and creating a new one"
+ echo -e " --no-install-packages: <deprecate> use this option to skip updating and installing the requires packages. This avoid wasting time if you are sure requires packages are present e.g. because of a previous installation"
+
+
+}
+
+function _create_db(){
+ echo '
+ #################################################################
+ ##### CREATE DATABASE #####
+ #################################################################'
+ echo -e "\nCreating temporary file form MYSQL installation and initialization"
+ TEMPFILE="$(mktemp -q --tmpdir "installopenvim.XXXXXX")"
+ trap 'rm -f "$TEMPFILE"' EXIT
+ chmod 0600 "$TEMPFILE"
+ echo -e "[client]\n user='${DB_ADMIN_USER}'\n password='$DB_ADMIN_PASSWD'">"$TEMPFILE"
+
+ if db_exists $DB_NAME $TEMPFILE ; then
+ if [[ -n $FORCEDB ]]; then
+ DBDELETEPARAM=""
+ [[ -n $QUIET_MODE ]] && DBDELETEPARAM="-f"
+ mysqladmin --defaults-extra-file=$TEMPFILE -s drop ${DB_NAME} $DBDELETEPARAM || ! echo "Could not delete ${DB_NAME} database" || exit 1
+ mysqladmin --defaults-extra-file=$TEMPFILE -s create ${DB_NAME} || ! echo "1 Error creating ${DB_NAME} database" || exit 1
+ echo "CREATE USER $DB_USER@'localhost' IDENTIFIED BY '$DB_PASS';" | mysql --defaults-extra-file=$TEMPFILE -s || ! echo "2 Failed while creating user vim at database"
+ echo "GRANT ALL PRIVILEGES ON ${DB_NAME}.* TO $DB_USER@'localhost';" | mysql --defaults-extra-file=$TEMPFILE -s || ! echo "3 Failed while creating user vim at database" || exit 1
+ echo " Database '${DB_NAME}' created, user $DB_USER password '$DB_PASS'"
+ else
+ echo "Database exists. Use option '--forcedb' to force the deletion of the existing one" && exit 1
+ fi
+ else
+ echo "mysqladmin -u$DB_ADMIN_USER $DBPASSWD_PARAM -s create ${DB_NAME}"
+
+ mysqladmin -u$DB_ADMIN_USER $DBPASSWD_PARAM -s create ${DB_NAME} || ! echo "4 Error creating ${DB_NAME} database" || exit 1
+ echo "CREATE USER $DB_USER@'localhost' IDENTIFIED BY '$DB_PASS';" | mysql --defaults-extra-file=$TEMPFILE -s || ! echo "Failed while creating user vim at database"
+ echo "GRANT ALL PRIVILEGES ON ${DB_NAME}.* TO $DB_USER@'localhost';" | mysql --defaults-extra-file=$TEMPFILE -s || ! echo "Failed giving creating user vim at database" || exit 1
+ echo " Database '${DB_NAME}' created, user $DB_USER password '$DB_PASS'"
+ fi
+}
+
+function _init_db(){
+ echo '
+ #################################################################
+ ##### INIT DATABASE #####
+ #################################################################'
+ DIRNAME=$(dirname $(readlink -f ${BASH_SOURCE[0]}))
+ su $SUDO_USER -c "${DIRNAME}/init_vim_db.sh -u $DB_USER -p $DB_PASS -d ${DB_NAME}" || ! echo "Failed while initializing database" || exit 1
+}
+
+function db_exists() {
+ RESULT=`mysqlshow --defaults-extra-file="$2" | grep -v Wildcard | grep -o $1`
+ if [ "$RESULT" == "$1" ]; then
+ echo " DB $1 exists"
+ return 0
+ fi
+ echo " DB $1 does not exist"
+ return 1
+}
+DB_NAME='vim_db'
+DB_ADMIN_USER="root"
+DB_USER="vim"
+DB_PASS="vimpw"
+DB_ADMIN_PASSWD=""
+DBPASSWD_PARAM=""
+QUIET_MODE=""
+FORCEDB=""
+NO_PACKAGES=""
+while getopts ":U:P:d:u:p:hiq-:" o; do
+ case "${o}" in
+ U)
+ export DB_ADMIN_USER="$OPTARG"
+ ;;
+ P)
+ export DB_ADMIN_PASSWD="$OPTARG"
+ export DBPASSWD_PARAM="-p$OPTARG"
+ ;;
+ d)
+ export DB_NAME="$OPTARG"
+ ;;
+ u)
+ export DB_USER="$OPTARG"
+ ;;
+ p)
+ export DB_PASS="$OPTARG"
+ ;;
+ q)
+ export QUIET_MODE=yes
+ export DEBIAN_FRONTEND=noninteractive
+ ;;
+ h)
+ usage && exit 0
+ ;;
+ -)
+ [ "${OPTARG}" == "help" ] && usage && exit 0
+ [ "${OPTARG}" == "forcedb" ] && FORCEDB="y" && continue
+ [ "${OPTARG}" == "quiet" ] && export QUIET_MODE=yes && export DEBIAN_FRONTEND=noninteractive && continue
+ [ "${OPTARG}" == "no-install-packages" ] && export NO_PACKAGES=yes && continue
+ echo -e "Invalid option: '--$OPTARG'\nTry $0 --help for more information" >&2
+ exit 1
+ ;;
+ \?)
+ echo -e "Invalid option: '-$OPTARG'\nTry $0 --help for more information" >&2
+ exit 1
+ ;;
+ :)
+ echo -e "Option '-$OPTARG' requires an argument\nTry $0 --help for more information" >&2
+ exit 1
+ ;;
+ *)
+ usage >&2
+ exit 1
+ ;;
+ esac
+done
+
+HERE=$(realpath $(dirname $0))
+OPENVIM_BASEFOLDER=$(dirname $HERE)
+[ "$USER" != "root" ] && echo "Needed root privileges" >&2 && exit -1
+
+if [[ -z "$SUDO_USER" ]] || [[ "$SUDO_USER" = "root" ]]
+then
+ export SUDO_USER='root'
+fi
+
+#Discover Linux distribution
+#try redhat type
+[ -f /etc/redhat-release ] && _DISTRO=$(cat /etc/redhat-release 2>/dev/null | cut -d" " -f1)
+#if not assuming ubuntu type
+[ -f /etc/redhat-release ] || _DISTRO=$(lsb_release -is 2>/dev/null)
+
+#check and ask for database user password. Must be done after database installation
+if [[ -n $QUIET_MODE ]]
+then
+ echo -e "\nCheking database connection and ask for credentials"
+ echo "mysqladmin -s -u$DB_ADMIN_USER $DBPASSWD_PARAM status >/dev/null"
+ while ! mysqladmin -s -u$DB_ADMIN_USER $DBPASSWD_PARAM status >/dev/null
+ do
+ [ -n "$logintry" ] && echo -e "\nInvalid database credentials!!!. Try again (Ctrl+c to abort)"
+ [ -z "$logintry" ] && echo -e "\nProvide database credentials"
+ read -e -p "database user? ($DB_ADMIN_USER) " DBUSER_
+ [ -n "$DBUSER_" ] && DB_ADMIN_USER=$DBUSER_
+ read -e -s -p "database password? (Enter for not using password) " DBPASSWD_
+ [ -n "$DBPASSWD_" ] && DB_ADMIN_PASSWD="$DBPASSWD_" && DBPASSWD_PARAM="-p$DBPASSWD_"
+ [ -z "$DBPASSWD_" ] && DB_ADMIN_PASSWD="" && DBPASSWD_PARAM=""
+ logintry="yes"
+ done
+fi
+
+if [[ -z "$NO_PACKAGES" ]]
+then
+ _create_db
+ _init_db
+fi
+
OPENVIM_VER="$1"
if [ -z "$OPENVIM_VER" ]
then
- OPENVIM_VER=`${DIRNAME}/../openvimd.py -v`
+ OPENVIM_VER=`ovim -v`
OPENVIM_VER=${OPENVIM_VER%%-r*}
OPENVIM_VER=${OPENVIM_VER##*version }
echo " Detected openvim version $OPENVIM_VER"
#check and ask for database user password
while ! mysql "$DEF_EXTRA_FILE_PARAM" $DBHOST_ $DBPORT_ $DBNAME -e "quit" >/dev/null 2>&1
do
- [ -n "$logintry" ] && echo -e "\nInvalid database credentials!!!. Try again (Ctrl+c to abort)"
+ [ -n "$logintry" ] && echo -e "\nInvalid database credentials!!!. Try again (Ctrl+c to abort)"
[ -z "$logintry" ] && echo -e "\nProvide database name and credentials"
read -e -p "mysql database name($DBNAME): " KK
[ -n "$KK" ] && DBNAME="$KK"
+#!/usr/bin/env python
# -*- coding: utf-8 -*-
##
import threading
import vim_db
import logging
-import threading
import imp
import host_thread as ht
import dhcp_thread as dt
from netaddr import IPNetwork
from jsonschema import validate as js_v, exceptions as js_e
import openflow_conn
+import argparse
HTTP_Bad_Request = 400
HTTP_Unauthorized = 401
controller_host.create_dhcp_interfaces(vlan, first_ip, dhcp_netmask)
controller_host.launch_dhcp_server(vlan, ip_range, dhcp_netmask, dhcp_path, gateway)
+if __name__ == "__main__":
+
+ parser = argparse.ArgumentParser()
+ parser.add_argument("-v","--version", help="increase output verbosity", action="store_true")
+ args = parser.parse_args()
+ if args.version:
+ print ('openvimd version {} {}'.format(ovim.get_version(), ovim.get_version_date()))
+ print ('(c) Copyright Telefonica')
echo -e " -q --quiet: install in an unattended mode"
echo -e " -h --help: show this help"
echo -e " --develop: install last version for developers, and do not configure as a service"
- echo -e " --forcedb: reinstall vim_db DB, deleting previous database if exists and creating a new one"
echo -e " --force: makes idenpotent, delete previous installations folders if needed"
echo -e " --noclone: assumes that openvim was cloned previously and that this script is run from the local repo"
echo -e " --no-install-packages: use this option to skip updating and installing the requires packages. This avoid wasting time if you are sure requires packages are present e.g. because of a previous installation"
+ echo -e " --no-db: do not insall mysql server"
}
function install_packages(){
DBPASSWD_PARAM=""
QUIET_MODE=""
DEVELOP=""
-FORCEDB=""
FORCE=""
NOCLONE=""
NO_PACKAGES=""
+NO_DB=""
+
while getopts ":u:p:hiq-:" o; do
case "${o}" in
u)
-)
[ "${OPTARG}" == "help" ] && usage && exit 0
[ "${OPTARG}" == "develop" ] && DEVELOP="y" && continue
- [ "${OPTARG}" == "forcedb" ] && FORCEDB="y" && continue
- [ "${OPTARG}" == "force" ] && FORCEDB="y" && FORCE="y" && continue
+ [ "${OPTARG}" == "force" ] && FORCE="y" && continue
[ "${OPTARG}" == "noclone" ] && NOCLONE="y" && continue
[ "${OPTARG}" == "quiet" ] && export QUIET_MODE=yes && export DEBIAN_FRONTEND=noninteractive && continue
[ "${OPTARG}" == "no-install-packages" ] && export NO_PACKAGES=yes && continue
+ [ "${OPTARG}" == "no-db" ] && NO_DB="y" && continue
echo -e "Invalid option: '--$OPTARG'\nTry $0 --help for more information" >&2
exit 1
;;
done
fi
+
+if [ -z "$NO_DB" ]; then
+ if [ -n "$QUIET_MODE" ]; then
+ DB_QUIET='-q'
+ fi
+
+ echo "!!!! install-db-server.sh: ${OPENVIM_BASEFOLDER}/scripts/install-db-server.sh -u $DBUSER $DBPASSWD_PARAM -n vim_db $DB_QUIET"
+ ${OPENVIM_BASEFOLDER}/scripts/install-db-server.sh -u $DBUSER $DBPASSWD_PARAM $DB_QUIET || exit 1
+fi
+
+
if [[ -z "$NO_PACKAGES" ]]
then
+
echo '
#################################################################
##### INSTALL PYTHON PACKAGES #####
[[ -z $DEVELOP ]] && su $SUDO_USER -c "git -C ${OPENVIM_BASEFOLDER} checkout tags/v1.0.2"
fi
-echo '
-#################################################################
-##### CREATE DATABASE #####
-#################################################################'
-echo -e "\nCreating temporary file form MYSQL installation and initialization"
-TEMPFILE="$(mktemp -q --tmpdir "installopenvim.XXXXXX")"
-trap 'rm -f "$TEMPFILE"' EXIT
-chmod 0600 "$TEMPFILE"
-echo -e "[client]\n user='$DBUSER'\n password='$DBPASSWD'">"$TEMPFILE"
-
-if db_exists "vim_db" $TEMPFILE ; then
- if [[ -n $FORCEDB ]]; then
- echo " Deleting previous database vim_db"
- DBDELETEPARAM=""
- [[ -n $QUIET_MODE ]] && DBDELETEPARAM="-f"
- mysqladmin --defaults-extra-file=$TEMPFILE -s drop vim_db $DBDELETEPARAM || ! echo "Could not delete vim_db database" || exit 1
- #echo "REVOKE ALL PRIVILEGES ON vim_db.* FROM 'vim'@'localhost';" | mysql --defaults-extra-file=$TEMPFILE -s || ! echo "Failed while creating user vim at database" || exit 1
- #echo "DELETE USER 'vim'@'localhost';" | mysql --defaults-extra-file=$TEMPFILE -s || ! echo "Failed while creating user vim at database" || exit 1
- mysqladmin --defaults-extra-file=$TEMPFILE -s create vim_db || ! echo "Error creating vim_db database" || exit 1
- echo "DROP USER 'vim'@'localhost';" | mysql --defaults-extra-file=$TEMPFILE -s || ! echo "Failed while creating user vim at database" || exit 1
- echo "CREATE USER 'vim'@'localhost' identified by 'vimpw';" | mysql --defaults-extra-file=$TEMPFILE -s || ! echo "Failed while creating user vim at database" || exit 1
- echo "GRANT ALL PRIVILEGES ON vim_db.* TO 'vim'@'localhost';" | mysql --defaults-extra-file=$TEMPFILE -s || ! echo "Failed while creating user vim at database" || exit 1
- echo " Database 'vim_db' created, user 'vim' password 'vimpw'"
- else
- echo "Database exists. Use option '--forcedb' to force the deletion of the existing one" && exit 1
- fi
-else
- mysqladmin -u$DBUSER $DBPASSWD_PARAM -s create vim_db || ! echo "Error creating vim_db database" || exit 1
- echo "CREATE USER 'vim'@'localhost' identified by 'vimpw';" | mysql --defaults-extra-file=$TEMPFILE -s || ! echo "Failed while creating user vim at database" || exit 1
- echo "GRANT ALL PRIVILEGES ON vim_db.* TO 'vim'@'localhost';" | mysql --defaults-extra-file=$TEMPFILE -s || ! echo "Failed while creating user vim at database" || exit 1
- echo " Database 'vim_db' created, user 'vim' password 'vimpw'"
-fi
-
-echo '
-#################################################################
-##### INIT DATABASE #####
-#################################################################'
-su $SUDO_USER -c "${OPENVIM_BASEFOLDER}/database_utils/init_vim_db.sh -u vim -p vimpw -d vim_db" || ! echo "Failed while initializing database" || exit 1
if [ "$_DISTRO" == "CentOS" -o "$_DISTRO" == "Red" ]
--- /dev/null
+#!/usr/bin/env python
+
+from setuptools import setup, find_packages
+from setuptools.command.install import install
+from os import system
+from setuptools import setup
+
+__name__ = 'lib-osm-openvim'
+__version__ = '1.0.0'
+__description__ = 'OSM Openvim library'
+__author__ = 'ETSI OSM'
+__author_email__ = 'alfonso.tiernosepulveda@telefonica.com'
+__maintainer__ = 'mirabal'
+__maintainer_email__ = 'leonardo.mirabal@altran.com'
+__license__ = 'Apache 2.0'
+__url__ = 'https://osm.etsi.org/gitweb/?p=osm/openvim.git;a=summary'
+
+
+__data_files__ = [('osm/openvim/', ['openvimd.cfg']),
+ ('osm/openvim/database_utils/', ['database_utils/vim_db_structure.sql',
+ 'database_utils/nets.sql',
+ 'database_utils/of_ports_pci_correspondence.sql',
+ 'database_utils/host_ranking.sql',
+ 'database_utils/dump_db.sh',
+ 'database_utils/init_vim_db.sh',
+ 'database_utils/migrate_vim_db.sh',
+ 'database_utils/install-db-server.sh'
+ ]),
+ ('osm/openvim/scripts/', ['scripts/service-openvim.sh',
+ 'scripts/openvim-report.sh',
+ 'scripts/service-floodlight.sh',
+ 'scripts/service-opendaylight.sh',
+ 'scripts/initopenvim.sh'
+ ]),
+ ]
+
+
+_req = [
+ "asn1crypto",
+ "cffi",
+ "enum34",
+ "functools32",
+ "idna",
+ "ipaddress",
+ "packaging",
+ "pbr",
+ "pkgconfig",
+ "pyasn1",
+ "pycparser",
+ "pycrypto",
+ "pyparsing",
+ "six",
+ "jsonschema",
+ "argcomplete",
+ "requests",
+ "PyYAML",
+ "requestsexceptions",
+ "netaddr",
+ "bottle",
+ "MySQL-python",
+ "paramiko",
+ "libvirt-python"
+]
+
+__scripts__ = ['openflow', 'ovim']
+
+
+class LibOpenvimInstaller(install):
+ lite = None
+ user_options = install.user_options + [('lite', None, "Don't install without Machine Learning modules.")]
+
+ def initialize_options(self):
+ self.lite = None
+ install.initialize_options(self)
+
+ def finalize_options(self):
+ install.finalize_options(self)
+
+ def run(self):
+
+ cmd = 'ln -sf -v /usr/local/osm/openvim/openvimd.cfg /etc/default/openvimd.cfg '
+ system(cmd)
+ cmd = 'ln -sf -v /usr/local/osm/openvim/openflow /usr/bin/openflow'
+ system(cmd)
+ cmd = 'ln -sf -v /usr/local/osm/openvim/ovim.py /usr/bin/ovim'
+ system(cmd)
+ if not self.lite:
+ __scripts__.append('openvim')
+ __scripts__.append('openvimd')
+
+ cmd = 'ln -sf -v /usr/local/osm/openvim/openvimd /usr/bin/openvimd'
+ system(cmd)
+ cmd = 'ln -sf -v /usr/local/osm/openvim/openvim /usr/bin/openvim'
+ system(cmd)
+ cmd = 'ln -sf -v /usr/local/osm/openvim/scripts/service-openvim.sh /usr/sbin/service-openvim'
+ system(cmd)
+ cmd = 'ln -sf -v /usr/local/osm/openvim/scripts/openvim-report.sh /usr/sbin/service-report'
+ system(cmd)
+ cmd = 'ln -sf -v /usr/local/osm/openvim/scripts/service-floodlight.sh /usr/sbin/service-floodlight'
+ system(cmd)
+ cmd = 'ln -sf -v /usr/local/osm/openvim/scripts/service-opendaylight.sh /usr/sbin/service-opendaylight'
+ system(cmd)
+ cmd = 'ln -sf -v /usr/local/osm/openvim/scripts/initopenvim.sh /usr/sbin/initopenvim'
+ system(cmd)
+
+ install.run(self)
+
+
+setup(name=__name__,
+ version=__version__,
+ description=__description__,
+ long_description=__description__,
+ author=__author__,
+ author_email=__author_email__,
+ license=__license__,
+ maintainer=__maintainer__,
+ maintainer_email=__maintainer_email__,
+ url=__url__,
+ py_modules=['ovim',
+ 'openvimd',
+ 'vim_db',
+ 'httpserver',
+ 'RADclass',
+ 'auxiliary_functions',
+ 'dhcp_thread',
+ 'definitionsClass',
+ 'host_thread',
+ 'vim_schema',
+ 'ovim',
+ 'openflow_thread',
+ 'onos',
+ 'ODL',
+ 'floodlight',
+ ],
+ packages=find_packages() + ['database_utils'] + ['scripts'],
+ package_dir={__name__: __name__},
+ package_data={'database_utils': ['*'], 'scripts': ['*']},
+ scripts=__scripts__,
+ data_files=__data_files__,
+ include_package_data=True,
+ cmdclass={'install': LibOpenvimInstaller},
+ install_requires=_req
+ )
+
+