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). 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 " --in --iface-name: creates bridge interfaces on this interface, needed for openvim overlay networks"
58 function _interface_cfg_generator
(){
59 #$1 interface name | $2 MTU | $3 type
66 " >> ${interfaced_path}${1}.
"cfg"
70 function _interface_cfg_generator
(){
71 #$1 interface name | $2 vlan | $3 virbrMan | $4 MTU
75 iface ${1}.${2} inet manual
77 post-up vconfig add ${1} ${2}
78 post-down vconfig rem ${1}.${2}
81 iface ${3} inet manual
82 bridge_ports ${1}.${2}
85 " >> ${interfaced_path}${1}.${2}.
"cfg"
88 function _install_user
() {
89 # create user given by the user and add to groups need it.
92 groupadd
-f libvirt
#for other operating systems may be libvirtd
94 # Adds user, default password same as name
95 if grep -q "^${option_user}:" /etc
/passwd
97 #user exist, add to group
98 echo "adding user ${option_user} to groups libvirt,admin"
99 usermod
-a -G libvirt
,admin
-g admin
${option_user}
101 #create user if it does not exist
102 [ -z "$FORCE" ] && read -p "user '${option_user}' does not exist, create (Y/n)" kk
103 if ! [ -z "$kk" -o "$kk"="y" -o "$kk"="Y" ]
107 echo "creating and configuring user ${option_user}"
108 useradd
-m -G libvirt
,admin
-g admin
${option_user}
112 echo "Provide a password for ${option_user}"
113 passwd
${option_user}
115 echo -e "$option_user\n$option_user" | passwd
--stdin ${option_user}
121 function _openmano_img_2_libvirt_img
(){
122 # Links the OpenMANO required folder /opt/VNF/images to /var/lib/libvirt/images.
123 # The OS installation
124 # should have only a / partition with all possible space available
126 echo " link /opt/VNF/images to /var/lib/libvirt/images"
127 if [ "$option_user" != "" ]
129 # The orchestator needs to link the images folder
130 rm -f /opt
/VNF
/images
132 ln -s /var
/lib
/libvirt
/images
/opt
/VNF
/images
133 chown
-R ${option_user}:admin
/opt
/VNF
134 chown
-R root
:admin
/var
/lib
/libvirt
/images
135 chmod g
+rwx
/var
/lib
/libvirt
/images
137 mkdir
-p /opt
/VNF
/images
138 chmod o
+rx
/opt
/VNF
/images
142 function _install_pacckags_dependences
()
144 # Required packages by openvim
146 apt-get
-y install grub-common screen virt-manager ethtool build-essential \
147 x11-common x11-utils libguestfs-tools hwloc libguestfs-tools \
148 numactl vlan nfs-common nfs-kernel-server
149 echo "Remove unneeded packages....."
150 apt-get
-y autoremove
153 function _network_configuration
(){
154 # adding vlan support
155 grep -q '8021q' '/etc/modules'; [ $?
-eq 1 ] && sudo su
-c 'echo "8021q" >> /etc/modules'
157 #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'
159 # Network interfaces static configuration
160 echo "Interface ==> $interface"
161 if [ -n "$interface" ]
163 # For management and data interfaces
164 rm -f /etc
/udev
/rules.d
/pci_config.rules
# it will be created to define VFs
165 # Set ONBOOT=on and MTU=9000 on the interface used for the bridges
166 echo "configuring iface $interface"
168 # Static network interface configuration and MTU
170 virbrMan_interface_number
=20
172 #Create bridge interfaces
173 echo "Creating bridge ifaces: "
174 for ((i
=1; i
<= ${virbrMan_interface_number}; i
++))
177 [ ${i} -lt 10 ] && i2digits
="0${i}"
178 echo " ${interface} ${VLAN_INDEX}${i2digits}"
179 echo " virbrMan${i} vlan ${VLAN_INDEX}${i2digits}"
181 #$1 interface name | $2 vlan | $3 MTU | $3 virbrMan | $4 bridge_ports
182 _interface_cfg_generator
${interface} ${VLAN_INDEX}${i2digits} 'virbrMan'${i} ${MTU}
188 function _disable_aaparmor
(){
189 #Deactivating apparmor while looking for a better solution
190 /etc
/init.d
/apparmor stop
191 update-rc.d
-f apparmor remove
194 function _check_interface
(){
195 #check if interface given as an argument exits
196 if [ -n "$1" ] && ! ifconfig
$1 &> /dev
/null
198 echo "Error: interface '$1' is not present in the system"\n
203 function _user_remainder_pront
()
206 echo "Do not forget to create a shared (NFS, Samba, ...) where original virtual machine images are allocated"
208 echo "Do not forget to copy the public ssh key into /home/${option_user}/.ssh/authorized_keys for authomatic login from openvim controller"
210 echo "Reboot the system to make the changes effective"
213 function _libvirt_configuration
(){
214 # Libvirt options for openvim
215 echo "configure Libvirt options"
216 sed -i 's/#unix_sock_group = "libvirt"/unix_sock_group = "libvirt"/' /etc
/libvirt
/libvirtd.conf
217 sed -i 's/#unix_sock_rw_perms = "0770"/unix_sock_rw_perms = "0770"/' /etc
/libvirt
/libvirtd.conf
218 sed -i 's/#unix_sock_dir = "\/var\/run\/libvirt"/unix_sock_dir = "\/var\/run\/libvirt"/' /etc
/libvirt
/libvirtd.conf
219 sed -i 's/#auth_unix_rw = "none"/auth_unix_rw = "none"/' /etc
/libvirt
/libvirtd.conf
221 chmod a
+rwx
/var
/lib
/libvirt
/images
224 ln -s /usr
/bin
/qemu-system-x86_64 qemu-kvm
228 function _hostinfo_config
()
231 echo "#By default openvim assumes control plane interface naming as em1,em2,em3,em4 " > /opt
/VNF
/images
/hostinfo.yaml
232 echo "creating local information /opt/VNF/images/hostinfo.yaml"
233 echo "#and bridge ifaces as virbrMan1, virbrMan2, ..." >> /opt
/VNF
/images
/hostinfo.yaml
234 echo "#if compute node contain a different name it must be indicated in this file" >> /opt
/VNF
/images
/hostinfo.yaml
235 echo "#with the format extandard-name: compute-name" >> /opt
/VNF
/images
/hostinfo.yaml
236 chmod o
+r
/opt
/VNF
/images
/hostinfo.yaml
247 for option_group
in $options
249 _name
=${option_group%%:*}
252 eval option_
${_name}='""'
259 if [[ -n $get_argument ]]
261 [[ ${argument:0:1} == "-" ]] && echo "option '-$option' requires an argument" >&2 && return 1
262 eval ${get_argument}='"$argument"'
263 #echo option $get_argument with argument
270 if [[ ${argument:0:1} == "-" ]] && [[ ${argument:1:1} != "-" ]] && [[ ${#argument} -ge 2 ]]
273 while index
=$
((index
+1)) && [[ $index -lt ${#argument} ]]
275 option
=${argument:$index:1}
277 for option_group
in $options
280 for o
in $
(echo $option_group |
tr ":=" " ")
282 [[ -z "$_name" ]] && _name
=${o//-/_}
283 #echo option $option versus $o
284 if [[ "$option" == "${o}" ]]
286 eval option_
${_name}='${option_'${_name}'}-'
288 if [[ ${option_group:${#option_group}-1} != "=" ]]
292 if [[ ${#argument} -gt $((index+1)) ]]
294 eval option_${_name}='"${argument:$((index+1))}"'
297 get_argument=option_${_name}
298 #echo next should be argument $argument
305 [[ $bad_option == y ]] && echo "invalid argument '-$option'? Type -h for help" >&2 && return 1
307 elif [[ ${argument:0:2} == "--" ]] && [[ ${#argument} -ge 3 ]]
310 option_argument=${option#*=}
311 option_name=${option%%=*}
312 [[ "$option_name" == "$option" ]] && option_argument=""
314 for option_group in $options
317 for o in $(echo $option_group | tr ":=" " ")
319 [[ -z "$_name" ]] && _name=${o//-/_}
320 #echo option $option versus $o
321 if [[ "$option_name" == "${o}" ]]
324 if [[ ${option_group:${#option_group}-1} != "=" ]]
325 then #not an argument
326 [[ -n "${option_argument}" ]] && echo "option '--${option%%=*}' do not accept an argument " >&2 && return 1
327 eval option_${_name}='"${option_'${_name}'}-"'
328 elif [[ -n "${option_argument}" ]]
330 eval option_
${_name}='"${option_argument}"'
332 get_argument
=option_
${_name}
333 #echo next should be argument $argument
339 [[ $bad_option == y
]] && echo "invalid argument '-$option'? Type -h for help" >&2 && return 1
340 elif [[ ${argument:0:2} == "--" ]]
346 if [[ "$o" == "--" ]]
353 [[ $bad_option == y
]] && echo "invalid argument '--'? Type -h for help" >&2 && return 1
356 params
="$params ${argument}"
361 [[ -n "$get_argument" ]] && echo "option '-$option' requires an argument" >&2 && return 1
365 function _parse_opts
()
367 [ -n "$option_help" ] && _usage
&& exit 0
370 [ -n "$option_force" ] && FORCE
="yes"
372 [ -z "$option_user" ] && echo -e "ERROR: User argument is mandatory, --user=<user>\n" >&2 && _usage
373 #echo "user_name = "$option_user
375 [ -z "$option_iface_name" ] && echo -e "ERROR: iface-name argument is mandatory, --iface-name=<interface>\n" && _usage
376 interface
=$option_iface_name
381 _get_opts
"help:h force:f user:u= iface-name:in= " $
* ||
exit 1
384 #check root privileges
385 [ "${USER}" != "root" ] && echo "Needed root privileges" >&2 && exit 2
387 echo "checking interface "$interface
389 _check_interface
$interface
392 #################################################################
393 ##### INSTALL USER #####
394 #################################################################'
398 #################################################################
399 ##### INSTALL NEEDED PACKETS #####
400 #################################################################'
401 _install_pacckags_dependences
404 #################################################################
405 ##### OTHER CONFIGURATION #####
406 #################################################################'
407 _openmano_img_2_libvirt_img
409 _libvirt_configuration
412 #################################################################
413 ##### NETWORK CONFIGURATION #####
414 #################################################################'
415 _network_configuration
417 _user_remainder_pront