4 # Copyright 2015 Telefónica Investigación y Desarrollo, S.A.U.
5 # This file is part of openvim
8 # Licensed under the Apache License, Version 2.0 (the "License"); you may
9 # not use this file except in compliance with the License. You may obtain
10 # a copy of the License at
12 # http://www.apache.org/licenses/LICENSE-2.0
14 # Unless required by applicable law or agreed to in writing, software
15 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
17 # License for the specific language governing permissions and limitations
20 # For those usages not covered by the Apache License, Version 2.0 please
21 # contact with: nfvlabs@tid.es
24 # Authors: Antonio Lopez, Pablo Montes, Alfonso Tierno
27 # Personalize RHEL7.1 on compute nodes
28 # Prepared to work with the following network card drivers:
29 # tg3, igb drivers for management interfaces
30 # ixgbe (Intel Niantic) and i40e (Intel Fortville) drivers for data plane interfaces
33 # wget https://raw.githubusercontent.com/nfvlabs/openmano/master/scripts/configure-compute-node-develope-UBUNTU16.04.sh
35 # chmod +x ./configure-compute-node-RHEL7.1.sh
36 # sudo ./configure-compute-node-RHEL7.1.sh <user> <iface>
39 # All virtualization options activated on BIOS (vt-d, vt-x, SR-IOV, no power savings...)
40 # RHEL7.1 installed without /home partition and with the following packages selection:
41 # @base, @core, @development, @network-file-system-client, @virtualization-hypervisor, @virtualization-platform, @virtualization-tools
43 interfaced_path
='/etc/network/interfaces.d/'
44 #interfaced_path='/home/ubuntu/openvim_install/openvim/test-inter/'
49 echo -e "Usage: sudo $0 [-y] <user-name> <iface-name>"
50 echo -e " Configure compute host for VIM usage. (version 0.4). Params:"
51 echo -e " -y do not prompt for confirmation. If a new user is created, the user name is set as password"
52 echo -e " <user-name> Create if not exist and configure this user for openvim to connect"
53 echo -e " <iface-name> if suplied creates bridge interfaces on this interface, needed for openvim"
56 function _interface_cfg_generator
(){
57 #$1 interface name | $2 MTU | $3 type
64 " >> ${interfaced_path}${1}.
"cfg"
68 function _interface_cfg_generator
(){
69 #$1 interface name | $2 vlan | $3 virbrMan | $4 MTU
73 iface ${1}.${2} inet manual
75 post-up vconfig add ${1} ${2}
76 post-down vconfig rem ${1}.${2}
79 iface ${3} inet manual
80 bridge_ports ${1}.${2}
83 " >> ${interfaced_path}${1}.${2}.
"cfg"
86 function _install_user
() {
87 # create user given by the user and add to groups need it.
90 groupadd
-f libvirt
#for other operating systems may be libvirtd
92 # Adds user, default password same as name
93 if grep -q "^${user_name}:" /etc
/passwd
95 #user exist, add to group
96 echo "adding user ${user_name} to groups libvirt,admin"
97 usermod
-a -G libvirt
,admin
-g admin
${user_name}
99 #create user if it does not exist
100 [ -z "$FORCE" ] && read -p "user '${user_name}' does not exist, create (Y/n)" kk
101 if ! [ -z "$kk" -o "$kk"="y" -o "$kk"="Y" ]
105 echo "creating and configuring user ${user_name}"
106 useradd
-m -G libvirt
,admin
-g admin
${user_name}
110 echo "Provide a password for ${user_name}"
113 echo -e "$user_name\n$user_name" | passwd
--stdin ${user_name}
119 function _openmano_img_2_libvirt_img
(){
120 # Links the OpenMANO required folder /opt/VNF/images to /var/lib/libvirt/images.
121 # The OS installation
122 # should have only a / partition with all possible space available
124 echo " link /opt/VNF/images to /var/lib/libvirt/images"
125 if [ "$user_name" != "" ]
127 # The orchestator needs to link the images folder
128 rm -f /opt
/VNF
/images
130 ln -s /var
/lib
/libvirt
/images
/opt
/VNF
/images
131 chown
-R ${user_name}:admin
/opt
/VNF
132 chown
-R root
:admin
/var
/lib
/libvirt
/images
133 chmod g
+rwx
/var
/lib
/libvirt
/images
135 mkdir
-p /opt
/VNF
/images
136 chmod o
+rx
/opt
/VNF
/images
140 function _install_pacckags_dependences
()
142 # Required packages by openvim
144 apt-get
-y install grub-common screen virt-manager ethtool build-essential \
145 x11-common x11-utils libguestfs-tools hwloc libguestfs-tools \
146 numactl vlan nfs-common nfs-kernel-server
147 echo "Remove unneeded packages....."
148 apt-get
-y autoremove
151 function _network_configuration
(){
152 # adding vlan support
153 grep -q '8021q' '/etc/modules'; [ $?
-eq 1 ] && sudo su
-c 'echo "8021q" >> /etc/modules'
155 #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'
157 # Network interfaces static configuration
158 echo "Interface ==> $interface"
159 if [ -n "$interface" ]
161 # For management and data interfaces
162 rm -f /etc
/udev
/rules.d
/pci_config.rules
# it will be created to define VFs
163 # Set ONBOOT=on and MTU=9000 on the interface used for the bridges
164 echo "configuring iface $interface"
166 # Static network interface configuration and MTU
168 virbrMan_interface_number
=20
170 #Create bridge interfaces
171 echo "Creating bridge ifaces: "
172 for ((i
=1; i
<= ${virbrMan_interface_number}; i
++))
175 [ ${i} -lt 10 ] && i2digits
="0${i}"
176 echo " ${interface} ${VLAN_INDEX}${i2digits}"
177 echo " virbrMan${i} vlan ${VLAN_INDEX}${i2digits}"
179 #$1 interface name | $2 vlan | $3 MTU | $3 virbrMan | $4 bridge_ports
180 _interface_cfg_generator
${interface} ${VLAN_INDEX}${i2digits} 'virbrMan'${i} ${MTU}
186 function _disable_aaparmor
(){
187 #Deactivating apparmor while looking for a better solution
188 /etc
/init.d
/apparmor stop
189 update-rc.d
-f apparmor remove
192 function _check_interface
(){
193 #check if interface given as an argument exits
194 if [ -n "$1" ] && ! ifconfig
$1 &> /dev
/null
196 echo "Error: interface '$1' is not present in the system"\n
202 function _user_remainder_pront
()
205 echo "Do not forget to create a shared (NFS, Samba, ...) where original virtual machine images are allocated"
207 echo "Do not forget to copy the public ssh key into /home/${user_name}/.ssh/authorized_keys for authomatic login from openvim controller"
209 echo "Reboot the system to make the changes effective"
212 function _libvirt_configuration
(){
213 # Libvirt options for openvim
214 echo "configure Libvirt options"
215 sed -i 's/#unix_sock_group = "libvirt"/unix_sock_group = "libvirt"/' /etc
/libvirt
/libvirtd.conf
216 sed -i 's/#unix_sock_rw_perms = "0770"/unix_sock_rw_perms = "0770"/' /etc
/libvirt
/libvirtd.conf
217 sed -i 's/#unix_sock_dir = "\/var\/run\/libvirt"/unix_sock_dir = "\/var\/run\/libvirt"/' /etc
/libvirt
/libvirtd.conf
218 sed -i 's/#auth_unix_rw = "none"/auth_unix_rw = "none"/' /etc
/libvirt
/libvirtd.conf
220 chmod a
+rwx
/var
/lib
/libvirt
/images
223 ln -s /usr
/bin
/qemu-system-x86_64 qemu-kvm
227 function _hostinfo_config
()
230 echo "#By default openvim assumes control plane interface naming as em1,em2,em3,em4 " > /opt
/VNF
/images
/hostinfo.yaml
231 echo "creating local information /opt/VNF/images/hostinfo.yaml"
232 echo "#and bridge ifaces as virbrMan1, virbrMan2, ..." >> /opt
/VNF
/images
/hostinfo.yaml
233 echo "#if compute node contain a different name it must be indicated in this file" >> /opt
/VNF
/images
/hostinfo.yaml
234 echo "#with the format extandard-name: compute-name" >> /opt
/VNF
/images
/hostinfo.yaml
235 chmod o
+r
/opt
/VNF
/images
/hostinfo.yaml
240 [[ ${BASH_SOURCE[0]} != $0 ]] && ___exit
="return" || ___exit
="exit"
248 for option_group
in $options
250 _name
=${option_group%%:*}
253 eval option_
${_name}='""'
260 if [[ -n $get_argument ]]
262 [[ ${argument:0:1} == "-" ]] && echo "option '-$option' requires an argument" >&2 && $___exit 1
263 eval ${get_argument}='"$argument"'
264 #echo option $get_argument with argument
271 if [[ ${argument:0:1} == "-" ]] && [[ ${argument:1:1} != "-" ]] && [[ ${#argument} -ge 2 ]]
274 while index
=$
((index
+1)) && [[ $index -lt ${#argument} ]]
276 option
=${argument:$index:1}
278 for option_group
in $options
281 for o
in $
(echo $option_group |
tr ":=" " ")
283 [[ -z "$_name" ]] && _name
=${o//-/_}
284 #echo option $option versus $o
285 if [[ "$option" == "${o}" ]]
287 eval option_
${_name}='${option_'${_name}'}-'
289 if [[ ${option_group:${#option_group}-1} != "=" ]]
293 if [[ ${#argument} -gt $((index+1)) ]]
295 eval option_${_name}='"${argument:$((index+1))}"'
298 get_argument=option_${_name}
299 #echo next should be argument $argument
306 [[ $bad_option == y ]] && echo "invalid argument '-$option'? Type -h for help" >&2 && $___exit 1
308 elif [[ ${argument:0:2} == "--" ]] && [[ ${#argument} -ge 3 ]]
311 option_argument=${option#*=}
312 option_name=${option%%=*}
313 [[ "$option_name" == "$option" ]] && option_argument=""
315 for option_group in $options
318 for o in $(echo $option_group | tr ":=" " ")
320 [[ -z "$_name" ]] && _name=${o//-/_}
321 #echo option $option versus $o
322 if [[ "$option_name" == "${o}" ]]
325 if [[ ${option_group:${#option_group}-1} != "=" ]]
326 then #not an argument
327 [[ -n "${option_argument}" ]] && echo "option '--${option%%=*}' do not accept an argument " >&2 && $___exit 1
328 eval option_${_name}='"${option_'${_name}'}-"'
329 elif [[ -n "${option_argument}" ]]
331 eval option_
${_name}='"${option_argument}"'
333 get_argument
=option_
${_name}
334 #echo next should be argument $argument
340 [[ $bad_option == y
]] && echo "invalid argument '-$option'? Type -h for help" >&2 && $___exit 1
341 elif [[ ${argument:0:2} == "--" ]]
347 if [[ "$o" == "--" ]]
354 [[ $bad_option == y
]] && echo "invalid argument '--'? Type -h for help" >&2 && $___exit 1
357 params
="$params ${argument}"
362 [[ -n "$get_argument" ]] && echo "option '-$option' requires an argument" >&2 && $___exit 1
367 function _parse_opts
()
370 if [ -n "$option_help" ];
376 if [ -n "$option_force" ];
382 [ -z "$option_user" ] && echo -e "ERROR: User argument is mandatory, --user=<user>\n" && usage
384 echo "user_name = "$option_user
386 [ -z "$option_iface_name" ] && echo -e "ERROR: User argument is mandatory, --user=<user>\n" && usage
387 interface
=$option_iface_name
390 #1 CHECK input parameters
392 [ "${USER}" != "root" ] && echo "Needed root privileges" && _usage
&& exit -1
396 _get_opts
"help:h force:f user:u= iface-name:in= " $
*
399 echo "checking interface "$interface
401 _check_interface
$interface
404 #################################################################
405 ##### INSTALL USER #####
406 #################################################################'
410 #################################################################
411 ##### INSTALL NEEDED PACKETS #####
412 #################################################################'
413 _install_pacckags_dependences
416 #################################################################
417 ##### OTHER CONFIGURATION #####
418 #################################################################'
419 _openmano_img_2_libvirt_img
421 _libvirt_configuration
424 #################################################################
425 ##### NETWORK CONFIGURATION #####
426 #################################################################'
427 _network_configuration
429 _user_remainder_pront