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, Leonardo Mirabal
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 [-f] --user=<user-name> --overlay=ovs --iface-name=<iface-name>"
50 echo -e " Configure compute host for VIM usage. (version 0.4). OPTIONS:"
51 echo -e " -h --help this help"
52 echo -e " -f --force: do not prompt for confirmation. If a new user is created, the user name is set as password"
53 echo -e " -u --user: Create if not exist and configure this user for openvim to connect"
54 echo -e " -o --overlay: ovs, bridge and bridge-and-ovs. Specify the networking overlay used by openvim, by default ovs is used"
55 echo -e " -in --iface-name: creates bridge interfaces on this interface, needed for openvim overlay networks"
60 function _interface_cfg_generator
(){
61 #$1 interface name | $2 vlan | $3 virbrMan | $4 MTU
65 iface ${1}.${2} inet manual
67 post-up ip link set mtu $MTU dev ${1}.${2}
70 iface ${3} inet manual
71 bridge_ports ${1}.${2}
72 post-up ip link set dev ${3} && ip link set mtu $MTU dev ${3}
74 " >> ${interfaced_path}${1}.${2}.
"cfg"
77 function _install_user
() {
78 # create user given by the user and add to groups need it.
81 groupadd
-f libvirtd
#for other operating systems may be libvirtd
83 # Adds user, default password same as name
84 if grep -q "^${option_user}:" /etc
/passwd
86 #user exist, add to group
87 echo "adding user ${option_user} to groups libvirt,admin"
88 usermod
-a -G libvirtd
,admin
-g admin
${option_user}
90 #create user if it does not exist
91 [ -z "$FORCE" ] && read -p "user '${option_user}' does not exist, create (Y/n)" kk
92 if ! [ -z "$kk" -o "$kk"="y" -o "$kk"="Y" ]
96 echo "creating and configuring user ${option_user}"
97 useradd
-m -G libvirtd
,admin
-g admin
${option_user}
101 echo "Provide a password for ${option_user}"
102 passwd
${option_user}
104 echo -e "$option_user\n$option_user" | passwd
--stdin ${option_user}
110 function _openmano_img_2_libvirt_img
(){
111 # Links the OpenMANO required folder /opt/VNF/images to /var/lib/libvirt/images.
112 # The OS installation
113 # should have only a / partition with all possible space available
115 echo " link /opt/VNF/images to /var/lib/libvirt/images"
116 if [ "$option_user" != "" ]
118 # The orchestator needs to link the images folder
119 rm -f /opt
/VNF
/images
121 ln -s /var
/lib
/libvirt
/images
/opt
/VNF
/images
122 chown
-R ${option_user}:admin
/opt
/VNF
123 chown
-R root
:admin
/var
/lib
/libvirt
/images
124 chmod g
+rwx
/var
/lib
/libvirt
/images
126 mkdir
-p /opt
/VNF
/images
127 chmod o
+rx
/opt
/VNF
/images
131 function _install_packages_dependencies
()
133 # Required packages by openvim
135 apt-get
-y install grub-common screen virt-manager ethtool build-essential \
136 x11-common x11-utils libguestfs-tools hwloc libguestfs-tools \
137 numactl vlan nfs-common nfs-kernel-server openvswitch-switch
138 echo "Remove unneeded packages....."
139 apt-get
-y autoremove
142 function _network_configuration
(){
143 # adding vlan support
144 grep -q '8021q' '/etc/modules'; [ $?
-eq 1 ] && sudo su
-c 'echo "8021q" >> /etc/modules'
146 # Network interfaces static configuration
147 echo "Interface ==> $interface"
148 if [ -n "$interface" ]
150 # For management and data interfaces
151 rm -f /etc
/udev
/rules.d
/pci_config.rules
# it will be created to define VFs
152 # Set ONBOOT=on and MTU=9000 on the interface used for the bridges
153 echo "configuring iface $interface"
154 if [ "$option_overlay" == "bridge" ] ||
[ "$option_overlay" == "bridge-and-ovs" ]
156 # Static network interface configuration and MTU
158 virbrMan_interface_number
=20
160 #Create bridge interfaces
161 echo "Creating bridge ifaces: "
162 for ((i
=1; i
<= ${virbrMan_interface_number}; i
++))
165 [ ${i} -lt 10 ] && i2digits
="0${i}"
166 echo " ${interface} ${VLAN_INDEX}${i2digits}"
167 echo " virbrMan${i} vlan ${VLAN_INDEX}${i2digits}"
169 #$1 interface name | $2 vlan | $3 MTU | $3 virbrMan | $4 bridge_ports
170 _interface_cfg_generator
${interface} ${VLAN_INDEX}${i2digits} 'virbrMan'${i} ${MTU}
176 function _disable_aaparmor
(){
177 #Deactivating apparmor while looking for a better solution
178 /etc
/init.d
/apparmor stop
179 update-rc.d
-f apparmor remove
182 function _check_interface
(){
183 #check if interface given as an argument exits
184 if [ -n "$1" ] && ! ifconfig
$1 &> /dev
/null
186 echo "Error: interface '$1' is not present in the system"\n
191 function _user_remainder_pront
()
194 echo "Do not forget to create a shared (NFS, Samba, ...) where original virtual machine images are allocated"
196 echo "Do not forget to copy the public ssh key into /home/${option_user}/.ssh/authorized_keys for authomatic login from openvim controller"
198 echo "Reboot the system to make the changes effective"
201 function _libvirt_configuration
(){
202 # Libvirt options for openvim
203 echo "configure Libvirt options"
204 sed -i 's/#unix_sock_group = "libvirt"/unix_sock_group = "libvirt"/' /etc
/libvirt
/libvirtd.conf
205 sed -i 's/#unix_sock_rw_perms = "0770"/unix_sock_rw_perms = "0770"/' /etc
/libvirt
/libvirtd.conf
206 sed -i 's/#unix_sock_dir = "\/var\/run\/libvirt"/unix_sock_dir = "\/var\/run\/libvirt"/' /etc
/libvirt
/libvirtd.conf
207 sed -i 's/#auth_unix_rw = "none"/auth_unix_rw = "none"/' /etc
/libvirt
/libvirtd.conf
209 chmod a
+rwx
/var
/lib
/libvirt
/images
212 ln -s /usr
/bin
/qemu-system-x86_64 qemu-kvm
216 function _hostinfo_config
()
219 echo "#By default openvim assumes control plane interface naming as em1,em2,em3,em4 " > /opt
/VNF
/images
/hostinfo.yaml
220 echo "creating local information /opt/VNF/images/hostinfo.yaml"
221 echo "#and bridge ifaces as virbrMan1, virbrMan2, ..." >> /opt
/VNF
/images
/hostinfo.yaml
222 echo "#if compute node contain a different name it must be indicated in this file" >> /opt
/VNF
/images
/hostinfo.yaml
223 echo "#with the format extandard-name: compute-name" >> /opt
/VNF
/images
/hostinfo.yaml
224 chmod o
+r
/opt
/VNF
/images
/hostinfo.yaml
225 if [ "$interface" != "" -a "$interface" != "em1" ]
227 echo "iface_names:" >> /opt
/VNF
/images
/hostinfo.yaml
228 echo " em1: ${interface}" >> /opt
/VNF
/images
/hostinfo.yaml
232 function _add_user_to_visudo
()
234 # Allow admin users to access without password
235 if ! grep -q "#openmano" /etc
/sudoers
237 cat >> /home
/${option_user}/script_visudo.sh
<< EOL
239 echo "#openmano allow to group admin to grant root privileges without password" >> \$1
240 echo "${option_user} ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
242 chmod +x
/home
/${option_user}/script_visudo.sh
243 echo "allowing admin user to get root privileges withut password"
244 export EDITOR
=/home
/${option_user}/script_visudo.sh
&& sudo
-E visudo
245 rm -f /home
/${option_user}/script_visudo.sh
257 for option_group
in $options
259 _name
=${option_group%%:*}
262 eval option_
${_name}='""'
269 if [[ -n $get_argument ]]
271 [[ ${argument:0:1} == "-" ]] && echo "option '-$option' requires an argument" >&2 && return 1
272 eval ${get_argument}='"$argument"'
273 #echo option $get_argument with argument
280 if [[ ${argument:0:1} == "-" ]] && [[ ${argument:1:1} != "-" ]] && [[ ${#argument} -ge 2 ]]
283 while index
=$
((index
+1)) && [[ $index -lt ${#argument} ]]
285 option
=${argument:$index:1}
287 for option_group
in $options
290 for o
in $
(echo $option_group |
tr ":=" " ")
292 [[ -z "$_name" ]] && _name
=${o//-/_}
293 #echo option $option versus $o
294 if [[ "$option" == "${o}" ]]
296 eval option_
${_name}='${option_'${_name}'}-'
298 if [[ ${option_group:${#option_group}-1} != "=" ]]
302 if [[ ${#argument} -gt $((index+1)) ]]
304 eval option_${_name}='"${argument:$((index+1))}"'
307 get_argument=option_${_name}
308 #echo next should be argument $argument
315 [[ $bad_option == y ]] && echo "invalid argument '-$option'? Type -h for help" >&2 && return 1
317 elif [[ ${argument:0:2} == "--" ]] && [[ ${#argument} -ge 3 ]]
320 option_argument=${option#*=}
321 option_name=${option%%=*}
322 [[ "$option_name" == "$option" ]] && option_argument=""
324 for option_group in $options
327 for o in $(echo $option_group | tr ":=" " ")
329 [[ -z "$_name" ]] && _name=${o//-/_}
330 #echo option $option versus $o
331 if [[ "$option_name" == "${o}" ]]
334 if [[ ${option_group:${#option_group}-1} != "=" ]]
335 then #not an argument
336 [[ -n "${option_argument}" ]] && echo "option '--${option%%=*}' do not accept an argument " >&2 && return 1
337 eval option_${_name}='"${option_'${_name}'}-"'
338 elif [[ -n "${option_argument}" ]]
340 eval option_
${_name}='"${option_argument}"'
342 get_argument
=option_
${_name}
343 #echo next should be argument $argument
349 [[ $bad_option == y
]] && echo "invalid argument '-$option'? Type -h for help" >&2 && return 1
350 elif [[ ${argument:0:2} == "--" ]]
356 if [[ "$o" == "--" ]]
363 [[ $bad_option == y
]] && echo "invalid argument '--'? Type -h for help" >&2 && return 1
366 params
="$params ${argument}"
371 [[ -n "$get_argument" ]] && echo "option '-$option' requires an argument" >&2 && return 1
375 function _parse_opts
()
377 [ -n "$option_help" ] && _usage
&& exit 0
380 [ -n "$option_force" ] && FORCE
="yes"
382 [ -z "$option_user" ] && echo -e "ERROR: User argument is mandatory, --user=<user>\n" >&2 && _usage
384 [ -z "$option_iface_name" ] && echo -e "ERROR: iface-name argument is mandatory, --iface-name=<interface>\n" && _usage
385 interface
=$option_iface_name
387 if [ "$option_overlay" != "bridge" ] && [ "$option_overlay" != "ovs" ] && [ "$option_overlay" != "bridge-and-ovs" ];
390 echo 'ERROR: overlay argument must be "ovs", "bridge", "bridge-and-ovs"' && _usage
395 _get_opts
"help:h force:f user:u= overlay:o= iface-name:in= " $
* ||
exit 1
398 #check root privileges
399 [ "${USER}" != "root" ] && echo "Needed root privileges" >&2 && exit 2
401 echo "checking interface "$interface
403 _check_interface
$interface
406 #################################################################
407 ##### INSTALL USER #####
408 #################################################################'
412 #################################################################
413 ##### INSTALL NEEDED PACKETS #####
414 #################################################################'
415 _install_packages_dependencies
418 #################################################################
419 ##### OTHER CONFIGURATION #####
420 #################################################################'
421 _openmano_img_2_libvirt_img
423 _libvirt_configuration
426 #################################################################
427 ##### NETWORK CONFIGURATION #####
428 #################################################################'
430 _network_configuration
434 _user_remainder_pront