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
25 # Authors: Antonio Lopez, Pablo Montes, Alfonso Tierno
27 # Personalize RHEL7/CENTOS compute nodes for using openvim in 'development' mode:
28 # not using huge pages neither isolcpus
31 # wget https://raw.githubusercontent.com/nfvlabs/openmano/master/scripts/configure-compute-node-develop.sh
33 # chmod +x ./configure-compute-node-develop.sh
34 # sudo ./configure-compute-node-develop.sh <user> <iface>
37 echo -e "Usage: sudo $0 [-y] <user-name> [ <iface-name> [<ip-address>|dhcp] ]"
38 echo -e " Configure compute host for VIM usage in mode 'development'. Params:"
39 echo -e " -y do not prompt for confirmation. If a new user is created, the user name is set as password"
40 echo -e " <user-name> Create if not exist and configure this user for openvim to connect"
41 echo -e " <iface-name> if supplied creates bridge interfaces on this interface, needed for openvim"
42 echo -e " ip or dhcp if supplied, configure the interface with this ip address (/24) or 'dhcp' "
45 #1 CHECK input parameters
47 [ "$USER" != "root" ] && echo "Needed root privileges" && usage
&& exit -1
51 while getopts "y" o
; do
75 if [ -n "$interface" ] && ! ifconfig
$interface &> /dev
/null
77 echo "Error: interface '$interface' is not present in the system"
83 #################################################################
84 ##### INSTALL NEEDED PACKETS #####
85 #################################################################'
91 yum
install -y screen virt-manager ethtool gcc gcc-c
++ xorg-x11-xauth xorg-x11-xinit xorg-x11-deprecated-libs libXtst guestfish hwloc libhugetlbfs-utils libguestfs-tools
93 yum
install -y policycoreutils-python
96 #################################################################
97 ##### INSTALL USER #####
98 #################################################################'
100 # Add required groups
102 groupadd
-f libvirt
#for other operating systems may be libvirtd
104 # Adds user, default password same as name
105 if grep -q "^${user_name}:" /etc
/passwd
107 #user exist, add to group
108 echo "adding user ${user_name} to groups libvirt,admin"
109 usermod
-a -G libvirt
,admin
-g admin
$user_name
111 #create user if it does not exist
112 [ -z "$FORCE" ] && read -p "user '${user_name}' does not exist, create (Y/n)" kk
113 if ! [ -z "$kk" -o "$kk"="y" -o "$kk"="Y" ]
117 echo "creating and configuring user ${user_name}"
118 useradd
-m -G libvirt
,admin
-g admin
$user_name
122 echo "Provide a password for $user_name"
125 echo -e "$user_name\n$user_name" | passwd
--stdin $user_name
129 # Allow admin users to access without password
130 if ! grep -q "#openmano" /etc
/sudoers
132 cat >> /home
/${user_name}/script_visudo.sh
<< EOL
134 cat \$1 | awk '(\$0~"requiretty"){print "#"\$0}(\$0!~"requiretty"){print \$0}' > tmp
138 echo "#openmano allow to group admin to grant root privileges without password" >> \$1
139 echo "%admin ALL=(ALL) NOPASSWD: ALL" >> \$1
141 chmod +x
/home
/${user_name}/script_visudo.sh
142 echo "allowing admin user to get root privileges withut password"
143 export EDITOR
=/home
/${user_name}/script_visudo.sh
&& sudo
-E visudo
144 rm -f /home
/${user_name}/script_visudo.sh
148 #################################################################
149 ##### OTHER CONFIGURATION #####
150 #################################################################'
151 # Creates a folder to store images in the user home
152 #Creates a link to the /home folder because in RHEL this folder is larger
153 echo "creating compute node folder for local images /opt/VNF/images"
154 if [ "$user_name" != "" ]
156 mkdir
-p /home
/VNF_images
157 chown
-R ${user_name}:admin
/home
/VNF_images
158 chmod go
+x
/home
/VNF_images
160 # The orchestator needs to link the images folder
161 rm -f /opt
/VNF
/images
163 ln -s /home
/VNF_images
/opt
/VNF
/images
164 chown
-R ${user_name}:admin
/opt
/VNF
167 mkdir
-p /opt
/VNF
/images
168 chmod o
+rx
/opt
/VNF
/images
171 echo "creating local information /opt/VNF/images/hostinfo.yaml"
172 echo "#By default openvim assumes control plane interface naming as em1,em2,em3,em4 " > /opt
/VNF
/images
/hostinfo.yaml
173 echo "#and bridge ifaces as virbrMan1, virbrMan2, ..." >> /opt
/VNF
/images
/hostinfo.yaml
174 echo "#if compute node contain a different name it must be indicated in this file" >> /opt
/VNF
/images
/hostinfo.yaml
175 echo "#with the format extandard-name: compute-name" >> /opt
/VNF
/images
/hostinfo.yaml
176 if [ "$interface" != "" -a "$interface" != "em1" ]
178 echo "iface_names:" >> /opt
/VNF
/images
/hostinfo.yaml
179 echo " em1: ${interface}" >> /opt
/VNF
/images
/hostinfo.yaml
181 chmod o
+r
/opt
/VNF
/images
/hostinfo.yaml
183 # deactivate memory overcommit
184 echo "deactivate memory overcommit"
185 service ksmtuned stop
187 chkconfig ksmtuned off
190 # Libvirt options (uncomment the following)
191 echo "configure Libvirt options"
192 sed -i 's/#unix_sock_group = "libvirt"/unix_sock_group = "libvirt"/' /etc
/libvirt
/libvirtd.conf
193 sed -i 's/#unix_sock_rw_perms = "0770"/unix_sock_rw_perms = "0770"/' /etc
/libvirt
/libvirtd.conf
194 sed -i 's/#unix_sock_dir = "\/var\/run\/libvirt"/unix_sock_dir = "\/var\/run\/libvirt"/' /etc
/libvirt
/libvirtd.conf
195 sed -i 's/#auth_unix_rw = "none"/auth_unix_rw = "none"/' /etc
/libvirt
/libvirtd.conf
198 #################################################################
199 ##### NETWORK CONFIGURATION #####
200 #################################################################'
201 # Network config (if the second parameter is net)
202 if [ -n "$interface" ]
205 # Deactivate network manager
206 #systemctl stop NetworkManager
207 #systemctl disable NetworkManager
209 pushd /etc
/sysconfig
/network-scripts
/
211 #Create infrastructure bridge
212 echo "DEVICE=virbrInf
218 NETMASK=255.255.255.0
219 USERCTL=no" > ifcfg-virbrInf
221 #Create bridge interfaces
222 echo "Creating bridge ifaces: "
223 for ((i
=1;i
<=20;i
++))
226 [ $i -lt 10 ] && i2digits
="0$i"
228 echo "DEVICE=virbrMan$i
233 USERCTL=no" > ifcfg-virbrMan
$i
241 echo "Do not forget to create a folder where original virtual machine images are allocated (ex. $HOME/static_storage)"
243 echo "Do not forget to allow openvim machine accessing directly to the host with ssh. Can be done by:"
244 echo " Copy the public ssh key of the openvim user from $HOME/.ssh/id_dsa.pub (in openvim) into /home/${user_name}/.ssh/authorized_keys (in the host) for automatic login from openvim controller"
245 echo " Or running on openvim machine 'ssh-keygen' (generate ssh keys) and 'ssh-copy-id <user>@<compute host>'"
247 echo "Do not forget to perform an initial ssh login from openmano VM into the host so the openmano ssh host key is added to /home/${user_name}/.ssh/known_hosts"
250 echo "Reboot the system to make the changes effective"