echo -e " If openvim_version is not provided it tries to get from openvimd.py using relative path"
echo -e " OPTIONS"
echo -e " -u USER database user. '$DBUSER' by default. Prompts if DB access fails"
- echo -e " -p PASS database password. 'No password' by default. Prompts if DB access fails"
+ echo -e " -p PASS database password. 'No password' or 'vimpw' by default. Prompts if DB access fails"
echo -e " -P PORT database port. '$DBPORT' by default"
echo -e " -h HOST database host. '$DBHOST' by default"
echo -e " -d NAME database name. '$DBNAME' by default. Prompts if DB access fails"
done
shift $((OPTIND-1))
-#check and ask for database user password
-DBUSER_="-u$DBUSER"
-DBPASS_=""
-[ -n "$DBPASS" ] && DBPASS_="-p$DBPASS"
+#Creating temporary file
+TEMPFILE="$(mktemp -q --tmpdir "initmanodb.XXXXXX")"
+trap 'rm -f "$TEMPFILE"' EXIT
+chmod 0600 "$TEMPFILE"
+
+#if password is missing, before prompting for it try without password and with "manopw"
DBHOST_="-h$DBHOST"
DBPORT_="-P$DBPORT"
-while ! echo ";" | mysql $DBHOST_ $DBPORT_ $DBUSER_ $DBPASS_ $DBNAME >/dev/null 2>&1
+DEF_EXTRA_FILE_PARAM="--defaults-extra-file=$TEMPFILE"
+if [ -z "${DBPASS}" ]
+then
+ password_ok=""
+ 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=""
+fi
+echo -e "[client]\nuser='${DBUSER}'\npassword='${DBPASS}'" > "$TEMPFILE"
+
+#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)"
[ -z "$logintry" ] && echo -e "\nProvide database name and credentials"
read -e -p "mysql database name($DBNAME): " KK
[ -n "$KK" ] && DBNAME="$KK"
read -e -p "mysql user($DBUSER): " KK
- [ -n "$KK" ] && DBUSER="$KK" && DBUSER_="-u$DBUSER"
+ [ -n "$KK" ] && DBUSER="$KK"
read -e -s -p "mysql password: " DBPASS
- [ -n "$DBPASS" ] && DBPASS_="-p$DBPASS"
- [ -z "$DBPASS" ] && DBPASS_=""
- logintry="yes":
+ echo -e "[client]\nuser='${DBUSER}'\npassword='${DBPASS}'" > "$TEMPFILE"
+ logintry="yes"
echo
done
+DBCMD="mysql $DEF_EXTRA_FILE_PARAM $DBHOST_ $DBPORT_ $DBNAME"
+DBUSER_="-u$DBUSER"
+DBPASS_="-p$DBPASS"
+
+
echo " loading ${DIRNAME}/vim_db_structure.sql"
-sed -e "s/vim_db/$DBNAME/" ${DIRNAME}/vim_db_structure.sql | mysql $DBHOST_ $DBPORT_ $DBUSER_ $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
echo " loading ${DIRNAME}/host_ranking.sql"
-mysql $DBHOST_ $DBPORT_ $DBUSER_ $DBPASS_ $DBNAME < ${DIRNAME}/host_ranking.sql
+mysql $DEF_EXTRA_FILE_PARAM $DBHOST_ $DBPORT_ $DBNAME < ${DIRNAME}/host_ranking.sql
echo " loading ${DIRNAME}/of_ports_pci_correspondence.sql"
-mysql $DBHOST_ $DBPORT_ $DBUSER_ $DBPASS_ $DBNAME < ${DIRNAME}/of_ports_pci_correspondence.sql
+mysql $DEF_EXTRA_FILE_PARAM $DBHOST_ $DBPORT_ $DBNAME < ${DIRNAME}/of_ports_pci_correspondence.sql
#mysql -h $HOST -P $PORT -u $MUSER -p$MPASS $MDB < ${DIRNAME}/of_ports_pci_correspondence_centos.sql
echo " loading ${DIRNAME}/nets.sql"
-mysql $DBHOST_ $DBPORT_ $DBUSER_ $DBPASS_ $DBNAME < ${DIRNAME}/nets.sql
+mysql $DEF_EXTRA_FILE_PARAM $DBHOST_ $DBPORT_ $DBNAME < ${DIRNAME}/nets.sql
echo -e " if openvim_version is not provided it tries to get from openvimd.py using relative path"
echo -e " OPTIONS"
echo -e " -u USER database user. '$DBUSER' by default. Prompts if DB access fails"
- echo -e " -p PASS database password. 'No password' by default. Prompts if DB access fails"
+ echo -e " -p PASS database password. 'No password' or 'vimpw' by default. Prompts if DB access fails"
echo -e " -P PORT database port. '$DBPORT' by default"
echo -e " -h HOST database host. '$DBHOST' by default"
echo -e " -d NAME database name. '$DBNAME' by default. Prompts if DB access fails"
fi
OPENVIM_VER_NUM=`printf "%d%03d%03d" ${VERSION_1} ${VERSION_2} ${VERSION_3}`
-#check and ask for database user password
-DBUSER_="-u$DBUSER"
-[ -n "$DBPASS" ] && DBPASS_="-p$DBPASS"
+#Creating temporary file
+TEMPFILE="$(mktemp -q --tmpdir "migratemanodb.XXXXXX")"
+trap 'rm -f "$TEMPFILE"' EXIT
+chmod 0600 "$TEMPFILE"
+
+#if password is missing, before prompting for it try without password and with "manopw"
DBHOST_="-h$DBHOST"
DBPORT_="-P$DBPORT"
-while ! echo ";" | mysql $DBHOST_ $DBPORT_ $DBUSER_ $DBPASS_ $DBNAME >/dev/null 2>&1
+DEF_EXTRA_FILE_PARAM="--defaults-extra-file=$TEMPFILE"
+if [ -z "${DBPASS}" ]
+then
+ password_ok=""
+ 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=""
+fi
+echo -e "[client]\nuser='${DBUSER}'\npassword='${DBPASS}'" > "$TEMPFILE"
+
+#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)"
[ -z "$logintry" ] && echo -e "\nProvide database name and credentials"
read -e -p "mysql database name($DBNAME): " KK
[ -n "$KK" ] && DBNAME="$KK"
read -e -p "mysql user($DBUSER): " KK
- [ -n "$KK" ] && DBUSER="$KK" && DBUSER_="-u$DBUSER"
+ [ -n "$KK" ] && DBUSER="$KK"
read -e -s -p "mysql password: " DBPASS
- [ -n "$DBPASS" ] && DBPASS_="-p$DBPASS"
- [ -z "$DBPASS" ] && DBPASS_=""
+ echo -e "[client]\nuser='${DBUSER}'\npassword='${DBPASS}'" > "$TEMPFILE"
logintry="yes"
echo
done
-DBCMD="mysql $DBHOST_ $DBPORT_ $DBUSER_ $DBPASS_ $DBNAME"
+DBCMD="mysql $DEF_EXTRA_FILE_PARAM $DBHOST_ $DBPORT_ $DBNAME"
#echo DBCMD $DBCMD
#GET DATABASE VERSION
self.ssh_conn.set_missing_host_key_policy(paramiko.AutoAddPolicy())
self.ssh_conn.load_system_host_keys()
self.ssh_conn.connect(self.dhcp_params["host"], port=self.dhcp_params.get("port",22),
- username=self.dhcp_params["user"], password=self.dhcp_params.get("password"), pkey=self.dhcp_params.get("key"),
+ username=self.dhcp_params["user"], password=self.dhcp_params.get("password"), key_filename=self.dhcp_params.get("key"),
timeout=2)
except paramiko.ssh_exception.SSHException as e:
text = e.args[0]
__date__ ="$10-jul-2014 12:07:15$"
import bottle
+import urlparse
import yaml
import json
import threading
except js_e.ValidationError:
return False
+
+def is_url(url):
+ '''
+ Check if string value is a well-wormed url
+ :param url: string url
+ :return: True if is a valid url, False if is not well-formed
+ '''
+
+ parsed_url = urlparse.urlparse(url)
+ return parsed_url
+
+
@bottle.error(400)
@bottle.error(401)
@bottle.error(404)
sriov['source_name'] = index
index += 1
interfaces.append ({'pci':str(port_k), 'Mbps': port_v['speed']/1000000, 'sriovs': new_sriovs, 'mac':port_v['mac'], 'source_name':port_v['source_name']})
- #@TODO LA memoria devuelta por el RAD es incorrecta, almenos para IVY1, NFV100
memory=node['memory']['node_size'] / (1024*1024*1024)
#memory=get_next_2pow(node['memory']['hugepage_nr'])
host['numas'].append( {'numa_socket': node['id'], 'hugepages': node['memory']['hugepage_nr'], 'memory':memory, 'interfaces': interfaces, 'cores': cores } )
image_file = http_content['image'].get('path',None)
if os.path.exists(image_file):
http_content['image']['checksum'] = md5(image_file)
+ elif is_url(image_file):
+ pass
else:
if not host_test_mode:
content = "Image file not found"
http_admin_port: 9085 # Admin port where openvim is listening (when missing, no administration server is launched)
#database parameters
-db_host: localhost # by default localhost
+db_host: 0.0.0.0 # by default localhost
db_user: vim # DB user
db_passwd: vimpw # DB password
db_name: vim_db # Name of the VIM DB
#In case some of the previous 'bridge_ifaces' are connected to an EXTERNAL dhcp server, provide
# the server parameters to allow openvim getting the allocated IP addresses of virtual machines
# connected to the indicated 'bridge_ifaces' and or 'nets'. Openvim will connect to the dhcp server by ssh.
-#DHCP server must contain a shell script "./get_dhcp_lease.sh" that accept a mac address as parameter
-# and return empty or the allocated IP address. See an example at the end of the file ./openvim/dhcp_thread.py
+#DHCP server must contain a shell script "get_dhcp_lease.sh" included in the path, that accepts a mac address as
+# parameter and return empty or the allocated IP address. See an example at the end of the file
+# ./openvim/dhcp_thread.py
#COMMENT all lines in case you do not have a DHCP server in 'normal', 'development' or 'host only' modes.
# For 'test' or 'OF only' modes you can leave then uncommented, because in these modes fake IP
# address are generated instead of connecting with a real DHCP server.
--- /dev/null
+#!/bin/bash
+
+##
+# Copyright 2015 Telefónica Investigación y Desarrollo, S.A.U.
+# This file is part of openvim
+# All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+#
+# For those usages not covered by the Apache License, Version 2.0 please
+# contact with: nfvlabs@tid.es
+##
+
+# Authors: Antonio Lopez, Pablo Montes, Alfonso Tierno
+# June 2015
+
+# Personalize RHEL7.1 on compute nodes
+# Prepared to work with the following network card drivers:
+# tg3, igb drivers for management interfaces
+# ixgbe (Intel Niantic) and i40e (Intel Fortville) drivers for data plane interfaces
+
+# To download:
+# wget https://raw.githubusercontent.com/nfvlabs/openmano/master/scripts/configure-compute-node-develope-UBUNTU16.04.sh
+# To execute:
+# chmod +x ./configure-compute-node-RHEL7.1.sh
+# sudo ./configure-compute-node-RHEL7.1.sh <user> <iface>
+
+# Assumptions:
+# All virtualization options activated on BIOS (vt-d, vt-x, SR-IOV, no power savings...)
+# RHEL7.1 installed without /home partition and with the following packages selection:
+# @base, @core, @development, @network-file-system-client, @virtualization-hypervisor, @virtualization-platform, @virtualization-tools
+
+interfaced_path='/etc/network/interfaces.d/'
+#interfaced_path='/home/ubuntu/openvim_install/openvim/test-inter/'
+set_mtu_path='/etc/'
+VLAN_INDEX=20
+
+function _usage(){
+ echo -e "Usage: sudo $0 [-y] <user-name> <iface-name>"
+ echo -e " Configure compute host for VIM usage. (version 0.4). OPTIONS:"
+ echo -e " -h --help this help"
+ echo -e " -f --force: do not prompt for confirmation. If a new user is created, the user name is set as password"
+ echo -e " -u --user: Create if not exist and configure this user for openvim to connect"
+ echo -e " --in --iface-name: creates bridge interfaces on this interface, needed for openvim overlay networks"
+ exit 1
+}
+
+function _interface_cfg_generator(){
+ #$1 interface name | $2 MTU | $3 type
+
+echo "
+auto ${1}
+iface ${1} inet ${3}
+ mtu ${2}
+ ${bridge_ports}
+" >> ${interfaced_path}${1}."cfg"
+}
+
+
+function _interface_cfg_generator(){
+ #$1 interface name | $2 vlan | $3 virbrMan | $4 MTU
+
+echo "
+auto ${1}.${2}
+iface ${1}.${2} inet manual
+ mtu ${4}
+ post-up vconfig add ${1} ${2}
+ post-down vconfig rem ${1}.${2}
+
+auto ${3}
+iface ${3} inet manual
+ bridge_ports ${1}.${2}
+ mtu ${4}
+ vlan-raw-device $1
+" >> ${interfaced_path}${1}.${2}."cfg"
+}
+
+function _install_user() {
+ # create user given by the user and add to groups need it.
+ # Add required groups
+ groupadd -f admin
+ groupadd -f libvirt #for other operating systems may be libvirtd
+
+ # Adds user, default password same as name
+ if grep -q "^${option_user}:" /etc/passwd
+ then
+ #user exist, add to group
+ echo "adding user ${option_user} to groups libvirt,admin"
+ usermod -a -G libvirt,admin -g admin ${option_user}
+ else
+ #create user if it does not exist
+ [ -z "$FORCE" ] && read -p "user '${option_user}' does not exist, create (Y/n)" kk
+ if ! [ -z "$kk" -o "$kk"="y" -o "$kk"="Y" ]
+ then
+ exit
+ fi
+ echo "creating and configuring user ${option_user}"
+ useradd -m -G libvirt,admin -g admin ${option_user}
+ #Password
+ if [ -z "$FORCE" ]
+ then
+ echo "Provide a password for ${option_user}"
+ passwd ${option_user}
+ else
+ echo -e "$option_user\n$option_user" | passwd --stdin ${option_user}
+ fi
+ fi
+
+}
+
+function _openmano_img_2_libvirt_img(){
+ # Links the OpenMANO required folder /opt/VNF/images to /var/lib/libvirt/images.
+ # The OS installation
+ # should have only a / partition with all possible space available
+
+ echo " link /opt/VNF/images to /var/lib/libvirt/images"
+ if [ "$option_user" != "" ]
+ then
+ # The orchestator needs to link the images folder
+ rm -f /opt/VNF/images
+ mkdir -p /opt/VNF/
+ ln -s /var/lib/libvirt/images /opt/VNF/images
+ chown -R ${option_user}:admin /opt/VNF
+ chown -R root:admin /var/lib/libvirt/images
+ chmod g+rwx /var/lib/libvirt/images
+ else
+ mkdir -p /opt/VNF/images
+ chmod o+rx /opt/VNF/images
+ fi
+}
+
+function _install_pacckags_dependences()
+{
+ # Required packages by openvim
+ apt-get -y update
+ apt-get -y install grub-common screen virt-manager ethtool build-essential \
+ x11-common x11-utils libguestfs-tools hwloc libguestfs-tools \
+ numactl vlan nfs-common nfs-kernel-server
+ echo "Remove unneeded packages....."
+ apt-get -y autoremove
+}
+
+function _network_configuration(){
+ # adding vlan support
+ grep -q '8021q' '/etc/modules'; [ $? -eq 1 ] && sudo su -c 'echo "8021q" >> /etc/modules'
+
+ #grep -q ${interface} '/etc/network/interfaces.d/50-cloud-init.cfg'; [ $? -eq 0 ] && sed -e '/'${interface}'/ s/^#*/#/' -i '/etc/network/interfaces.d/50-cloud-init.cfg'
+
+ # Network interfaces static configuration
+ echo "Interface ==> $interface"
+ if [ -n "$interface" ]
+ then
+ # For management and data interfaces
+ rm -f /etc/udev/rules.d/pci_config.rules # it will be created to define VFs
+ # Set ONBOOT=on and MTU=9000 on the interface used for the bridges
+ echo "configuring iface $interface"
+
+ # Static network interface configuration and MTU
+ MTU=9000
+ virbrMan_interface_number=20
+
+ #Create bridge interfaces
+ echo "Creating bridge ifaces: "
+ for ((i =1; i <= ${virbrMan_interface_number}; i++))
+ do
+ i2digits=${i}
+ [ ${i} -lt 10 ] && i2digits="0${i}"
+ echo " ${interface} ${VLAN_INDEX}${i2digits}"
+ echo " virbrMan${i} vlan ${VLAN_INDEX}${i2digits}"
+ j=${i}
+ #$1 interface name | $2 vlan | $3 MTU | $3 virbrMan | $4 bridge_ports
+ _interface_cfg_generator ${interface} ${VLAN_INDEX}${i2digits} 'virbrMan'${i} ${MTU}
+ done
+
+ fi
+}
+
+function _disable_aaparmor(){
+ #Deactivating apparmor while looking for a better solution
+ /etc/init.d/apparmor stop
+ update-rc.d -f apparmor remove
+}
+
+function _check_interface(){
+ #check if interface given as an argument exits
+ if [ -n "$1" ] && ! ifconfig $1 &> /dev/null
+ then
+ echo "Error: interface '$1' is not present in the system"\n
+ exit 1
+ fi
+}
+
+function _user_remainder_pront()
+{
+ echo
+ echo "Do not forget to create a shared (NFS, Samba, ...) where original virtual machine images are allocated"
+ echo
+ echo "Do not forget to copy the public ssh key into /home/${option_user}/.ssh/authorized_keys for authomatic login from openvim controller"
+ echo
+ echo "Reboot the system to make the changes effective"
+}
+
+function _libvirt_configuration(){
+ # Libvirt options for openvim
+ echo "configure Libvirt options"
+ sed -i 's/#unix_sock_group = "libvirt"/unix_sock_group = "libvirt"/' /etc/libvirt/libvirtd.conf
+ sed -i 's/#unix_sock_rw_perms = "0770"/unix_sock_rw_perms = "0770"/' /etc/libvirt/libvirtd.conf
+ sed -i 's/#unix_sock_dir = "\/var\/run\/libvirt"/unix_sock_dir = "\/var\/run\/libvirt"/' /etc/libvirt/libvirtd.conf
+ sed -i 's/#auth_unix_rw = "none"/auth_unix_rw = "none"/' /etc/libvirt/libvirtd.conf
+
+ chmod a+rwx /var/lib/libvirt/images
+ mkdir /usr/libexec/
+ pushd /usr/libexec/
+ ln -s /usr/bin/qemu-system-x86_64 qemu-kvm
+ popd
+}
+
+function _hostinfo_config()
+{
+
+ echo "#By default openvim assumes control plane interface naming as em1,em2,em3,em4 " > /opt/VNF/images/hostinfo.yaml
+ echo "creating local information /opt/VNF/images/hostinfo.yaml"
+ echo "#and bridge ifaces as virbrMan1, virbrMan2, ..." >> /opt/VNF/images/hostinfo.yaml
+ echo "#if compute node contain a different name it must be indicated in this file" >> /opt/VNF/images/hostinfo.yaml
+ echo "#with the format extandard-name: compute-name" >> /opt/VNF/images/hostinfo.yaml
+ chmod o+r /opt/VNF/images/hostinfo.yaml
+}
+
+function _get_opts()
+{
+ options="$1"
+ shift
+
+ get_argument=""
+ #reset variables
+ params=""
+ for option_group in $options
+ do
+ _name=${option_group%%:*}
+ _name=${_name%=}
+ _name=${_name//-/_}
+ eval option_${_name}='""'
+ done
+
+ while [[ $# -gt 0 ]]
+ do
+ argument="$1"
+ shift
+ if [[ -n $get_argument ]]
+ then
+ [[ ${argument:0:1} == "-" ]] && echo "option '-$option' requires an argument" >&2 && return 1
+ eval ${get_argument}='"$argument"'
+ #echo option $get_argument with argument
+ get_argument=""
+ continue
+ fi
+
+
+ #short options
+ if [[ ${argument:0:1} == "-" ]] && [[ ${argument:1:1} != "-" ]] && [[ ${#argument} -ge 2 ]]
+ then
+ index=0
+ while index=$((index+1)) && [[ $index -lt ${#argument} ]]
+ do
+ option=${argument:$index:1}
+ bad_option=y
+ for option_group in $options
+ do
+ _name=""
+ for o in $(echo $option_group | tr ":=" " ")
+ do
+ [[ -z "$_name" ]] && _name=${o//-/_}
+ #echo option $option versus $o
+ if [[ "$option" == "${o}" ]]
+ then
+ eval option_${_name}='${option_'${_name}'}-'
+ bad_option=n
+ if [[ ${option_group:${#option_group}-1} != "=" ]]
+ then
+ continue
+ fi
+ if [[ ${#argument} -gt $((index+1)) ]]
+ then
+ eval option_${_name}='"${argument:$((index+1))}"'
+ index=${#argument}
+ else
+ get_argument=option_${_name}
+ #echo next should be argument $argument
+ fi
+
+ break
+ fi
+ done
+ done
+ [[ $bad_option == y ]] && echo "invalid argument '-$option'? Type -h for help" >&2 && return 1
+ done
+ elif [[ ${argument:0:2} == "--" ]] && [[ ${#argument} -ge 3 ]]
+ then
+ option=${argument:2}
+ option_argument=${option#*=}
+ option_name=${option%%=*}
+ [[ "$option_name" == "$option" ]] && option_argument=""
+ bad_option=y
+ for option_group in $options
+ do
+ _name=""
+ for o in $(echo $option_group | tr ":=" " ")
+ do
+ [[ -z "$_name" ]] && _name=${o//-/_}
+ #echo option $option versus $o
+ if [[ "$option_name" == "${o}" ]]
+ then
+ bad_option=n
+ if [[ ${option_group:${#option_group}-1} != "=" ]]
+ then #not an argument
+ [[ -n "${option_argument}" ]] && echo "option '--${option%%=*}' do not accept an argument " >&2 && return 1
+ eval option_${_name}='"${option_'${_name}'}-"'
+ elif [[ -n "${option_argument}" ]]
+ then
+ eval option_${_name}='"${option_argument}"'
+ else
+ get_argument=option_${_name}
+ #echo next should be argument $argument
+ fi
+ break
+ fi
+ done
+ done
+ [[ $bad_option == y ]] && echo "invalid argument '-$option'? Type -h for help" >&2 && return 1
+ elif [[ ${argument:0:2} == "--" ]]
+ then
+ option__="$*"
+ bad_option=y
+ for o in $options
+ do
+ if [[ "$o" == "--" ]]
+ then
+ bad_option=n
+ option__=" $*"
+ break
+ fi
+ done
+ [[ $bad_option == y ]] && echo "invalid argument '--'? Type -h for help" >&2 && return 1
+ break
+ else
+ params="$params ${argument}"
+ fi
+
+ done
+
+ [[ -n "$get_argument" ]] && echo "option '-$option' requires an argument" >&2 && return 1
+ return 0
+}
+
+function _parse_opts()
+{
+ [ -n "$option_help" ] && _usage && exit 0
+
+ FORCE=""
+ [ -n "$option_force" ] && FORCE="yes"
+
+ [ -z "$option_user" ] && echo -e "ERROR: User argument is mandatory, --user=<user>\n" >&2 && _usage
+ #echo "user_name = "$option_user
+
+ [ -z "$option_iface_name" ] && echo -e "ERROR: iface-name argument is mandatory, --iface-name=<interface>\n" && _usage
+ interface=$option_iface_name
+
+}
+
+#Parse opts
+_get_opts "help:h force:f user:u= iface-name:in= " $* || exit 1
+_parse_opts
+
+#check root privileges
+[ "${USER}" != "root" ] && echo "Needed root privileges" >&2 && exit 2
+
+echo "checking interface "$interface
+
+_check_interface $interface
+
+echo '
+#################################################################
+##### INSTALL USER #####
+#################################################################'
+_install_user
+
+echo '
+#################################################################
+##### INSTALL NEEDED PACKETS #####
+#################################################################'
+_install_pacckags_dependences
+
+echo '
+#################################################################
+##### OTHER CONFIGURATION #####
+#################################################################'
+_openmano_img_2_libvirt_img
+_hostinfo_config
+_libvirt_configuration
+
+echo '
+#################################################################
+##### NETWORK CONFIGURATION #####
+#################################################################'
+_network_configuration
+_disable_aaparmor
+_user_remainder_pront
+
+
+
# For those usages not covered by the Apache License, Version 2.0 please
# contact with: nfvlabs@tid.es
##
-awk '
-($1=="lease" && $3=="{"){ lease=$2; active="no"; found="no" }
-($1=="binding" && $2=="state" && $3=="active;"){ active="yes" }
-($1=="hardware" && $2=="ethernet" && $3==tolower("'$1';")){ found="yes" }
-($1=="client-hostname"){ name=$2 }
-($1=="}"){ if (active=="yes" && found=="yes"){ target_lease=lease; target_name=name}}
-END{printf("%s", target_lease)} #print target_name
-' /var/lib/dhcp/dhcpd.leases
+if [ -e /var/lib/dhcp/dhcpd.leases ]
+then
+ awk '
+ ($1=="lease" && $3=="{"){ lease=$2; active="no"; found="no" }
+ ($1=="binding" && $2=="state" && $3=="active;"){ active="yes" }
+ ($1=="hardware" && $2=="ethernet" && $3==tolower("'$1';")){ found="yes" }
+ ($1=="client-hostname"){ name=$2 }
+ ($1=="}"){ if (active=="yes" && found=="yes"){ target_lease=lease; target_name=name}}
+ END{printf("%s", target_lease)} #print target_name
+ ' /var/lib/dhcp/dhcpd.leases
+elif [ -e /var/lib/lxd-bridge/dnsmasq.lxdbr0.leases ]
+then
+ awk '
+ ($2=="'$1'"){ lease=$3; name=$4}
+ END{printf("%s", lease)}
+ ' /var/lib/lxd-bridge/dnsmasq.lxdbr0.leases
+fi
#Get configuration of a host for using it as a compute node
function usage(){
- echo -e "usage: $0 user ip_name nb_cores GiB_memory nb_10GB_interfaces [hostname] [>> host.yaml]\n Get host parameters and generated a yaml file to be used for openvim host-add"
- echo -e " - In case hostname is not specified it will be used the name of the machine where the script is run"
- echo -e " - nb_cores must be an odd number and bigger or equal to 4."
- echo -e " - GiB_memory must be an odd number and bigger or equal to 16. 4GiB of memory will be reserved for the host OS, the rest will be used by VM."
- echo -e " - nb_10GB_interfaces must be an odd number and bigger or equal to 4."
- echo -e " - The output will be a server descriptor with two numas and resources (memory, cores and interfaces) equally distributed between them."
- echo -e " - Each interface (physical funtion) will have defined 8 SR-IOV (virtual functions)."
+
+ echo -e "\nUsage: $0 --user-name <user> --ip=<X.X.X.X> --cores=<core_number> --huge-pages-1G=<huga_pages_number> --nb-10GB-interfaces==<interface_number>"
+ echo -e "Generate a develop host yaml to be used for openvim host-add\n"
+ echo -e " --user-name -u <user>* Server OAM Ip"
+ echo -e " --ip -i <ip>* Server hostname"
+ echo -e " --cores -c <cores> Numa Cores available must be an odd number and bigger or equal to 4."
+ echo -e " --huge-pages-1G -hp <huge_pages_number> Must be an odd number and bigger or equal to 16. 4GiB of memory will be reserved for the host OS, the rest will be used by VM."
+ echo -e " --nb-10GB-interfaces -ni <nb-10GB-interfaces> Dataplane interfaces must be an odd number and bigger or equal to 4."
+ echo -e " * Mandatory arguments"
+ echo -e "\n"
+ echo -e "The output will be a server descriptor with two numas and resources (memory, cores and interfaces) equally distributed between them."
+ echo -e "Each interface (physical funtion) will have defined 8 SR-IOV (virtual functions)."
+
exit 1
}
-function get_hash_value() { echo `eval echo $\{\`echo $1[$2]\`\}`; }
+function get_hash_value() { echo `eval echo $\{\`echo $USER[$IP]\`\}`; }
function get_mac(){
seed=$1
echo $mac
}
+function _parse_opts(){
-#check root privileges and non a root user behind
+ #help argument
+ if [ -n "$option_help" ];
+ then
+ usage
+ fi
-[ "$#" -lt "5" ] && echo "Missing parameters" && usage
-[ "$#" -gt "6" ] && echo "Too many parameters" && usage
-HOST_NAME=`cat /etc/hostname`
-[ "$#" -eq "6" ] && HOST_NAME=$6
-FEATURES_LIST="lps,dioc,hwsv,tlbps,ht,lps,64b,iommu"
-NUMAS=2
-CORES=$3
-MEMORY=$4
-INTERFACES=$5
-
-#Ensure the user input is big enough
-([ $((CORES%2)) -ne 0 ] || [ $CORES -lt 4 ] ) && echo -e "ERROR: Wrong number of cores\n" && usage
-([ $((MEMORY%2)) -ne 0 ] || [ $MEMORY -lt 16 ] ) && echo -e "ERROR: Wrong number of memory\n" && usage
-([ $((INTERFACES%2)) -ne 0 ] || [ $INTERFACES -lt 4 ] ) && echo -e "ERROR: Wrong number of interfaces\n" && usage
-
-#Generate a cpu topology for 4 numas with hyperthreading
-CPUS=`pairs_gap=$((CORES/NUMAS));numa=0;inc=0;sibling=0;for((thread=0;thread<=$((pairs_gap-1));thread++)); do printf " ${numa}-${sibling}-${thread} ${numa}-${sibling}-$((thread+pairs_gap))";numa=$(((numa+1)%$NUMAS)); sibling=$((sibling+inc)); inc=$(((inc+1)%2)); done`
-
-#in this developing/fake server all cores can be used
-
-echo "#This file was created by $0"
-echo "#for adding this compute node to openvim"
-echo "#copy this file to openvim controller and run"
-echo "#openvim host-add <this>"
-echo
-echo "host:"
-echo " name: $HOST_NAME"
-echo " user: $1"
-echo " ip_name: $2"
-echo "host-data:"
-echo " name: $HOST_NAME"
-echo " user: $1"
-echo " ip_name: $2"
-echo " ranking: 100"
-echo " description: $HOST_NAME"
-echo " features: $FEATURES_LIST"
-echo " numas:"
-
-numa=0
-last_iface=0
-iface_counter=0
-while [ $numa -lt $NUMAS ]
-do
- echo " - numa_socket: $numa"
-#MEMORY
- echo " hugepages: $((MEMORY/2-2))"
- echo " memory: $((MEMORY/2))"
-
-#CORES
- echo " cores:"
- for cpu in $CPUS
- do
- PHYSICAL=`echo $cpu | cut -f 1 -d"-"`
- CORE=`echo $cpu | cut -f 2 -d"-"`
- THREAD=`echo $cpu | cut -f 3 -d"-"`
- [ $PHYSICAL != $numa ] && continue #skip non physical
- echo " - core_id: $CORE"
- echo " thread_id: $THREAD"
- [ $CORE -eq 0 ] && echo " status: noteligible"
- done
-
-
- #GENERATE INTERFACES INFORMATION AND PRINT IT
- seed=$RANDOM
- echo " interfaces:"
- for ((iface=0;iface<$INTERFACES;iface+=2))
- do
- name="iface$iface_counter"
- bus=$((iface+last_iface))
- pci=`printf "0000:%02X:00.0" $bus`
- mac=`get_mac $seed`
- seed=$((seed+1))
-
- echo " - source_name: $name"
- echo " Mbps: 10000"
- echo " pci: \"$pci\""
- echo " mac: \"$mac\""
- echo " switch_dpid: \"01:02:03:04:05:06\""
- echo " switch_port: fake0/$iface_counter"
- echo " sriovs:"
-
- for((nb_sriov=0;nb_sriov<8;nb_sriov++))
+ #User argument
+ [ -z "$option_user_name" ] && echo -e "ERROR: User argument is mandatory, --user-name=<user>\n" && usage
+ USER_NAME=${option_user_name}
+
+ [ -z "$option_ip" ] && echo -e "ERROR: OAM IP argument is mandatory, --ip=<X.X.X.X>\n" && usage
+ IP=${option_ip}
+
+ #TODO to be checl diference between real cores an numa cores
+ #cores argument
+ REAL_CORES=$(grep -c "^processor" "/proc/cpuinfo")
+ if [ -z "$option_cores" ] ; then
+ CORES=REAL_CORES
+ else
+ CORES=${option_cores}
+ fi
+
+ #Ensure the core user input is big enough
+ ([ $((CORES%2)) -ne 0 ]) && echo -e "ERROR: Wrong number of cores\n" && usage
+
+ MEMORY=$(($(grep MemTotal /proc/meminfo | awk '{print $2}') /1024/1024))
+ if [ -z "$option_huge_pages_1G" ] ; then
+ HUGE_PAGES_MEMORY=0
+ else
+ HUGE_PAGES_MEMORY=${option_huge_pages_1G}
+ fi
+ #Ensure the memory user input is big enough
+ #([ $((MEMORY%2)) -ne 0 ] || [ $MEMORY -lt 16 ] ) && echo -e "ERROR: Wrong number of memory\n" && usage
+
+ #nb_10GB_interfaces argument
+ if [ -z "$nb_10GB_interfaces" ] ; then
+ INTERFACES=8
+ else
+ INTERFACES=${nb_10GB_interfaces}
+ fi
+ ([ $((INTERFACES%2)) -ne 0 ] || [ $INTERFACES -lt 4 ] ) && echo -e "ERROR: Wrong number of interfaces\n" && usage
+
+ # Parameter by default
+ NUMAS=1
+ ([ $((NUMAS%2)) -ne 0 ]) && NUMAS=1
+}
+
+function _generate_compute_develope_yaml(){
+
+ _yaml_init
+
+ FEATURES_LIST="lps,dioc,hwsv,tlbps,ht,lps,64b,iommu"
+
+ #Generate a cpu topology for 4 numas with hyperthreading
+ #in this developing/fake server all cores can be used
+ #TODO check if this calculation is correct
+ echo2file "#This file was created by $0"
+ echo2file "#for adding this compute node to openvim"
+ echo2file "#copy this file to openvim controller and run"
+ echo2file "#openvim host-add <this>"
+ echo2file
+ echo2file "host:"
+ echo2file " name: $HOST_NAME"
+ echo2file " user: $USER_NAME"
+ echo2file " ip_name: $IP"
+ echo2file "host-data:"
+ echo2file " name: $HOST_NAME"
+ echo2file " user: $USER_NAME"
+ echo2file " ip_name: $IP"
+ echo2file " ranking: 100"
+ echo2file " description: $HOST_NAME"
+ echo2file " features: $FEATURES_LIST"
+ echo2file " numas:"
+
+ numa=0
+ last_iface=0
+ iface_counter=0
+
+ while [ $numa -lt $NUMAS ]
+ do
+
+ HUGE_PAGES=$((HUGE_PAGES_MEMORY/2-2))
+ ([ ${HUGE_PAGES} -lt -1 ]) && HUGE_PAGES=0
+
+ echo2file " - numa_socket: $numa"
+ #MEMORY
+ echo2file " hugepages: $((HUGE_PAGES))"
+ echo2file " memory: $((MEMORY/$NUMAS))"
+ #CORES
+ echo2file " cores:"
+
+ for((n_core=0;n_core<$REAL_CORES;n_core++))
+ do
+ THREAD_ID=$(($n_core+1))
+ CORE_ID=$(($((${n_core}+${numa}))/2))
+ echo2file " - core_id: ${CORE_ID}"
+ echo2file " thread_id: ${THREAD_ID}"
+ [ $CORE_ID -eq 0 ] && echo2file " status: noteligible"
+
+ thread_counter=$((thread_counter+1))
+ done
+ # GENERATE INTERFACES INFORMATION AND PRINT IT
+ seed=$RANDOM
+ echo2file " interfaces:"
+ for ((iface=0;iface<$INTERFACES;iface+=2))
+ do
+ name="iface$iface_counter"
+ bus=$((iface+last_iface))
+ bus=$((iface))
+ pci=`printf "0000:%02X:00.0" $bus`
+ mac=`get_mac $seed`
+ seed=$((seed+1))
+
+ echo2file " - source_name: $name"
+ echo2file " Mbps: 10000"
+ echo2file " pci: \"$pci\""
+ echo2file " mac: \"$mac\""
+ echo2file " sriovs:"
+
+ PCI_COUNTER=0
+ for((nb_sriov=0;nb_sriov<8;nb_sriov++))
+ do
+ #PCI_COUNTER=$((PCI_COUNTER+2))
+ #echo2file "nb_sriov "$nb_sriov
+ #echo2file "PCI_COUNTER "$PCI_COUNTER
+
+ pci=`printf "0000:%02X:10.%i" $bus $nb_sriov`
+ mac=`get_mac $seed`
+ seed=$((seed+1))
+ echo2file " - source_name: eth$nb_sriov"
+ echo2file " mac: \"$mac\""
+ echo2file " pci: \"$pci\""
+ done
+ iface_counter=$((iface_counter+1))
+ done
+ last_iface=$(((numa+1)*127/NUMAS+5)) #made-up formula for more realistic pci numbers
+ numa=$((numa+1))
+ done
+}
+
+function _yaml_init(){
+ echo -n > host-develope.yaml
+}
+
+function echo2file(){
+ echo "${1}"
+ echo "${1}" >> host-develope.yaml
+}
+
+function _get_opts()
+{
+ options="$1"
+ shift
+
+ get_argument=""
+ #reset variables
+ params=""
+ for option_group in $options
do
- pci=`printf "0000:%02X:10.%i" $bus $nb_sriov`
- mac=`get_mac $seed`
- seed=$((seed+1))
- echo " - mac: \"$mac\""
- echo " pci: \"$pci\""
- echo " source_name: $nb_sriov"
+ _name=${option_group%%:*}
+ _name=${_name%=}
+ _name=${_name//-/_}
+ eval option_${_name}='""'
done
-
- iface_counter=$((iface_counter+1))
- done
- last_iface=$(((numa+1)*127/NUMAS+5)) #made-up formula for more realistic pci numbers
-
-
- numa=$((numa+1))
-done
+
+ while [[ $# -gt 0 ]]
+ do
+ argument="$1"
+ shift
+ if [[ -n $get_argument ]]
+ then
+ [[ ${argument:0:1} == "-" ]] && echo "option '-$option' requires an argument" >&2 && return 1
+ eval ${get_argument}='"$argument"'
+ #echo option $get_argument with argument
+ get_argument=""
+ continue
+ fi
+
+
+ #short options
+ if [[ ${argument:0:1} == "-" ]] && [[ ${argument:1:1} != "-" ]] && [[ ${#argument} -ge 2 ]]
+ then
+ index=0
+ while index=$((index+1)) && [[ $index -lt ${#argument} ]]
+ do
+ option=${argument:$index:1}
+ bad_option=y
+ for option_group in $options
+ do
+ _name=""
+ for o in $(echo $option_group | tr ":=" " ")
+ do
+ [[ -z "$_name" ]] && _name=${o//-/_}
+ #echo option $option versus $o
+ if [[ "$option" == "${o}" ]]
+ then
+ eval option_${_name}='${option_'${_name}'}-'
+ bad_option=n
+ if [[ ${option_group:${#option_group}-1} != "=" ]]
+ then
+ continue
+ fi
+ if [[ ${#argument} -gt $((index+1)) ]]
+ then
+ eval option_${_name}='"${argument:$((index+1))}"'
+ index=${#argument}
+ else
+ get_argument=option_${_name}
+ #echo next should be argument $argument
+ fi
+
+ break
+ fi
+ done
+ done
+ [[ $bad_option == y ]] && echo "invalid argument '-$option'? Type -h for help" >&2 && return 1
+ done
+ elif [[ ${argument:0:2} == "--" ]] && [[ ${#argument} -ge 3 ]]
+ then
+ option=${argument:2}
+ option_argument=${option#*=}
+ option_name=${option%%=*}
+ [[ "$option_name" == "$option" ]] && option_argument=""
+ bad_option=y
+ for option_group in $options
+ do
+ _name=""
+ for o in $(echo $option_group | tr ":=" " ")
+ do
+ [[ -z "$_name" ]] && _name=${o//-/_}
+ #echo option $option versus $o
+ if [[ "$option_name" == "${o}" ]]
+ then
+ bad_option=n
+ if [[ ${option_group:${#option_group}-1} != "=" ]]
+ then #not an argument
+ [[ -n "${option_argument}" ]] && echo "option '--${option%%=*}' do not accept an argument " >&2 && return 1
+ eval option_${_name}='"${option_'${_name}'}-"'
+ elif [[ -n "${option_argument}" ]]
+ then
+ eval option_${_name}='"${option_argument}"'
+ else
+ get_argument=option_${_name}
+ #echo next should be argument $argument
+ fi
+ break
+ fi
+ done
+ done
+ [[ $bad_option == y ]] && echo "invalid argument '-$option'? Type -h for help" >&2 && return 1
+ elif [[ ${argument:0:2} == "--" ]]
+ then
+ option__="$*"
+ bad_option=y
+ for o in $options
+ do
+ if [[ "$o" == "--" ]]
+ then
+ bad_option=n
+ option__=" $*"
+ break
+ fi
+ done
+ [[ $bad_option == y ]] && echo "invalid argument '--'? Type -h for help" >&2 && return 1
+ break
+ else
+ params="$params ${argument}"
+ fi
+
+ done
+
+ [[ -n "$get_argument" ]] && echo "option '-$option' requires an argument" >&2 && return 1
+ return 0
+}
+
+#process options
+DIRNAME=$(readlink -f ${BASH_SOURCE[0]})
+DIRNAME=$(dirname $DIRNAME)
+
+#source ${DIRNAME}/get-options.sh "help:h user:u= ip:i= cores:c= huge-pages-1G:hp= nb-10GB-interfaces:ni=" $*
+_get_opts "help:h user-name:u= ip:i= cores:c= huge-pages-1G:hp= nb-10GB-interfaces:ni=" $* || exit 1
+_parse_opts
+
+#check root privileges
+[ "${USER}" != "root" ] && echo "Needed root privileges" >&2 && exit 2
+#check root privileges and non a root user behind
+
+
+HOST_NAME=`cat /etc/hostname`
+
+_generate_compute_develope_yaml
if [[ -n $QUIET_MODE ]]
then
echo -e "\nCheking database connection and ask for credentials"
- while ! mysqladmin -s -u$DBUSER $DBPASSWD_PARAM ping
+ while ! mysqladmin -s -u$DBUSER $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"
##### DOWNLOAD SOURCE #####
#################################################################'
su $SUDO_USER -c 'git clone '"${GIT_URL}"' openvim'
-[[ -z $DEVELOP ]] && su $SUDO_USER -c 'cd openvim; git checkout tags/v1.0; cd ..'
+[[ -z $DEVELOP ]] && su $SUDO_USER -c 'git -C openvim checkout tags/v1.0.1'
#Unncoment to use a concrete branch, if not main branch
#pushd openvim
function usage(){
echo -e "Usage: $0 start|stop|restart|status"
echo -e " Launch|Removes|Restart|Getstatus opendaylight on a screen"
- echo -e " Shell variable OPENDAYDLIGHT_PATH must indicate opendaylight installation path"
+ echo -e " Shell variable OPENDAYLIGHT_PATH must indicate opendaylight installation path"
}
function kill_pid(){
#start
if [ "$om_action" == "start" -o "$om_action" == "restart" ]
then
- [[ -z $OPENDAYDLIGHT_PATH ]] && echo "OPENDAYDLIGHT_PATH shell variable must indicate opendaylight installation path" >&2 && exit -1
+ [[ -z $OPENDAYLIGHT_PATH ]] && echo "OPENDAYLIGHT_PATH shell variable must indicate opendaylight installation path" >&2 && exit -1
#calculates log file name
logfile=""
mkdir -p $DIR_OM/logs && logfile=$DIR_OM/logs/openflow.log && logfile_console=$DIR_OM/logs/openflow_console.log || echo "can not create logs directory $DIR_OM/logs"
echo -n " starting $om_name ... "
if ! screen -wipe | grep -Fq .flow
then
- pushd ${OPENDAYDLIGHT_PATH}/bin > /dev/null
+ pushd ${OPENDAYLIGHT_PATH}/bin > /dev/null
screen -dmS flow bash
sleep 1
popd > /dev/null
else
echo -n " using existing screen 'flow' ... "
screen -S flow -p 0 -X log off
- screen -S flow -p 0 -X stuff "cd ${OPENDAYDLIGHT_PATH}/bin\n"
+ screen -S flow -p 0 -X stuff "cd ${OPENDAYLIGHT_PATH}/bin\n"
sleep 1
fi
#move old log file index one number up and log again in index 0
for index in .9 .8 .7 .6 .5 .4 .3 .2 .1 ""
do
rm -f ${logfile}${index}
- ln -s ${OPENDAYDLIGHT_PATH}/data/log/karaf.log${index} ${logfile}${index}
+ ln -s ${OPENDAYLIGHT_PATH}/data/log/karaf.log${index} ${logfile}${index}
done
rm -rf ${logfile_console}
screen -S flow -p 0 -X logfile ${logfile_console}
"type": "object",
"properties":{
"admin_state_up":{"type":"boolean"},
- "hugepages":integer1_schema,
+ "hugepages":integer0_schema,
"cores":{
"type": "array",
"minItems":2,
"memory":integer1_schema
},
"additionalProperties": False,
- "required": ["hugepages","cores","numa_socket"]
+ "required": ["cores","numa_socket"]
}
}
},