blob: 19c39d4f3c7003d5ea92b740103b75403169b5dd [file] [log] [blame]
tiernof7aa8c42016-09-06 16:43:04 +02001#!/bin/bash
2
3##
4# Copyright 2015 Telefónica Investigación y Desarrollo, S.A.U.
tierno9a61c6b2016-09-08 10:57:02 +02005# This file is part of openvim
tiernof7aa8c42016-09-06 16:43:04 +02006# All Rights Reserved.
7#
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
11#
12# http://www.apache.org/licenses/LICENSE-2.0
13#
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
18# under the License.
19#
20# For those usages not covered by the Apache License, Version 2.0 please
21# contact with: nfvlabs@tid.es
22##
23
24# v1.0: 2015 June
25# Authors: Antonio Lopez, Pablo Montes, Alfonso Tierno
26
27# Personalize RHEL7/CENTOS compute nodes for using openvim in 'development' mode:
28# not using huge pages neither isolcpus
29
30# To download:
31# wget https://raw.githubusercontent.com/nfvlabs/openmano/master/scripts/configure-compute-node-develop.sh
32# To execute:
33# chmod +x ./configure-compute-node-develop.sh
34# sudo ./configure-compute-node-develop.sh <user> <iface>
35
36function usage(){
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' "
43}
44
45#1 CHECK input parameters
46#1.1 root privileges
47[ "$USER" != "root" ] && echo "Needed root privileges" && usage && exit -1
48
49#1.2 input parameters
50FORCE=""
51while getopts "y" o; do
52 case "${o}" in
53 y)
54 FORCE="yes"
55 ;;
56 *)
57 usage
58 exit -1
59 ;;
60 esac
61done
62shift $((OPTIND-1))
63
64
65if [ $# -lt 1 ]
66then
67 usage
68 exit
69fi
70
71user_name=$1
72interface=$2
73ip_iface=$3
74
75if [ -n "$interface" ] && ! ifconfig $interface &> /dev/null
76then
77 echo "Error: interface '$interface' is not present in the system"
78 usage
79 exit 1
80fi
81
82echo '
83#################################################################
84##### INSTALL NEEDED PACKETS #####
85#################################################################'
86
87# Required packages
88yum repolist
89yum check-update
90yum update -y
91yum 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
92# Selinux management
93yum install -y policycoreutils-python
94
95echo '
96#################################################################
97##### INSTALL USER #####
98#################################################################'
99
100# Add required groups
101groupadd -f admin
102groupadd -f libvirt #for other operating systems may be libvirtd
103
104# Adds user, default password same as name
105if grep -q "^${user_name}:" /etc/passwd
106then
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
110else
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" ]
114 then
115 exit
116 fi
117 echo "creating and configuring user ${user_name}"
118 useradd -m -G libvirt,admin -g admin $user_name
119 #Password
120 if [ -z "$FORCE" ]
121 then
122 echo "Provide a password for $user_name"
123 passwd $user_name
124 else
125 echo -e "$user_name\n$user_name" | passwd --stdin $user_name
126 fi
127fi
128
129# Allow admin users to access without password
130if ! grep -q "#openmano" /etc/sudoers
131then
132 cat >> /home/${user_name}/script_visudo.sh << EOL
133#!/bin/bash
134cat \$1 | awk '(\$0~"requiretty"){print "#"\$0}(\$0!~"requiretty"){print \$0}' > tmp
135cat tmp > \$1
136rm tmp
137echo "" >> \$1
138echo "#openmano allow to group admin to grant root privileges without password" >> \$1
139echo "%admin ALL=(ALL) NOPASSWD: ALL" >> \$1
140EOL
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
145fi
146
147echo '
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
153echo "creating compute node folder for local images /opt/VNF/images"
154if [ "$user_name" != "" ]
155then
156 mkdir -p /home/VNF_images
157 chown -R ${user_name}:admin /home/VNF_images
158 chmod go+x /home/VNF_images
159
160 # The orchestator needs to link the images folder
161 rm -f /opt/VNF/images
162 mkdir -p /opt/VNF/
163 ln -s /home/VNF_images /opt/VNF/images
164 chown -R ${user_name}:admin /opt/VNF
165
166else
167 mkdir -p /opt/VNF/images
168 chmod o+rx /opt/VNF/images
169fi
170
171echo "creating local information /opt/VNF/images/hostinfo.yaml"
172echo "#By default openvim assumes control plane interface naming as em1,em2,em3,em4 " > /opt/VNF/images/hostinfo.yaml
173echo "#and bridge ifaces as virbrMan1, virbrMan2, ..." >> /opt/VNF/images/hostinfo.yaml
174echo "#if compute node contain a different name it must be indicated in this file" >> /opt/VNF/images/hostinfo.yaml
175echo "#with the format extandard-name: compute-name" >> /opt/VNF/images/hostinfo.yaml
176if [ "$interface" != "" -a "$interface" != "em1" ]
177then
178 echo "iface_names:" >> /opt/VNF/images/hostinfo.yaml
179 echo " em1: ${interface}" >> /opt/VNF/images/hostinfo.yaml
180fi
181chmod o+r /opt/VNF/images/hostinfo.yaml
182
183# deactivate memory overcommit
184echo "deactivate memory overcommit"
185service ksmtuned stop
186service ksm stop
187chkconfig ksmtuned off
188chkconfig ksm off
189
190# Libvirt options (uncomment the following)
191echo "configure Libvirt options"
192sed -i 's/#unix_sock_group = "libvirt"/unix_sock_group = "libvirt"/' /etc/libvirt/libvirtd.conf
193sed -i 's/#unix_sock_rw_perms = "0770"/unix_sock_rw_perms = "0770"/' /etc/libvirt/libvirtd.conf
194sed -i 's/#unix_sock_dir = "\/var\/run\/libvirt"/unix_sock_dir = "\/var\/run\/libvirt"/' /etc/libvirt/libvirtd.conf
195sed -i 's/#auth_unix_rw = "none"/auth_unix_rw = "none"/' /etc/libvirt/libvirtd.conf
196
197echo '
198#################################################################
199##### NETWORK CONFIGURATION #####
200#################################################################'
201# Network config (if the second parameter is net)
202if [ -n "$interface" ]
203then
204
205 # Deactivate network manager
206 #systemctl stop NetworkManager
207 #systemctl disable NetworkManager
208
209 pushd /etc/sysconfig/network-scripts/
210
211 #Create infrastructure bridge
212 echo "DEVICE=virbrInf
213TYPE=Bridge
214ONBOOT=yes
215DELAY=0
216NM_CONTROLLED=no
217IPADDR=10.10.0.1
218NETMASK=255.255.255.0
219USERCTL=no" > ifcfg-virbrInf
220
221 #Create bridge interfaces
222 echo "Creating bridge ifaces: "
223 for ((i=1;i<=20;i++))
224 do
225 i2digits=$i
226 [ $i -lt 10 ] && i2digits="0$i"
227 echo " virbrMan$i"
228 echo "DEVICE=virbrMan$i
229TYPE=Bridge
230ONBOOT=yes
231DELAY=0
232NM_CONTROLLED=no
233USERCTL=no" > ifcfg-virbrMan$i
234
235 done
236
237 popd
238fi
239
240echo
241echo "Do not forget to create a folder where original virtual machine images are allocated (ex. $HOME/static_storage)"
242echo
243echo "Do not forget to allow openvim machine accessing directly to the host with ssh. Can be done by:"
244echo " 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"
245echo " Or running on openvim machine 'ssh-keygen' (generate ssh keys) and 'ssh-copy-id <user>@<compute host>'"
246echo
247echo "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"
248echo
249
250echo "Reboot the system to make the changes effective"
251
252