3 #Script that install prerequisites
4 #author: Szilard Cserey (szilard.cserey@ericsson.com)
6 #Installs qemu-kvm, libvirt and prepares networking for Fuel VM
15 fuel_gw_ip='10.20.0.1/16'
19 ###check whether qemu-kvm is installed, otherwise install it
21 echo "${blue}Checking whether qemu-kvm is installed, otherwise install it${reset}"
22 if ! rpm -qa | grep -iE 'qemu-kvm'; then
23 echo "${blue}qemu-kvm is not installed, installing...${reset}"
24 yum -y install qemu-kvm
26 echo "${green}OK!${reset}"
30 ###check whether libvirt is installed, otherwise install it
32 echo "${blue}Checking whether libvirt is installed, otherwise install it${reset}"
33 if ! rpm -qa | grep -iE 'libvirt'; then
34 echo "${blue}libvirt is not installed, installing...${reset}"
35 yum -y install libvirt
37 echo "${green}OK!${reset}"
41 ###check whether kvm kernel module is loaded, otherwise load it
42 load_kvm_kernel_mod() {
43 echo "${blue}Checking whether kvm kernel module is loaded, otherwise load it${reset}"
44 if ! lsmod | grep -iE 'kvm'; then
45 if [[ `lscpu | grep 'Vendor ID' | awk 'BEGIN { FS = ":" } ; {print $2}' | tr -d ' '` == 'GenuineIntel' ]]; then
46 echo "${blue}Intel processor identified, loading kernel module kvm-intel${reset}"
47 kernel_mod='kvm-intel'
48 modprobe ${kernel_mod}
50 if [[ `lscpu | grep 'Vendor ID' | awk 'BEGIN { FS = ":" } ; {print $2}' | tr -d ' '` == 'AuthenticAMD' ]]; then
51 echo "${blue}AMD processor identified, loading kernel module kvm-amd${reset}"
53 modprobe ${kernel_mod}
55 if ! lsmod | grep -iE 'kvm'; then
56 echo "${red}Failed to load kernel module ${kernel_mod}!${reset}"
60 echo "${green}OK!${reset}"
64 ###check whether libvirtd service is running otherwise start it
65 start_libvirtd_service() {
66 echo "${blue}Checking whether libvirtd service is running otherwise start it${reset}"
67 if ! sudo systemctl status libvirtd | grep -iE 'active \(running\)'; then
68 echo "${blue}starting libvirtd service${reset}"
69 systemctl start libvirtd
70 if ! sudo systemctl status libvirtd | grep -iE 'active \(running\)'; then
71 echo "${red}Failed to start libvirtd service!${reset}"
75 echo "${green}OK!${reset}"
79 #Check whether interface is UP
82 echo "${red}Cannot bring UP, No interface specified${reset}"
86 echo "${blue}Checking whether interface ${interface} is UP${reset}"
87 link_state=$(ip link show ${interface} | grep -oP 'state \K[^ ]+')
88 if [[ ${link_state} != 'UP' ]]; then
89 echo "${blue}${interface} state is ${link_state}. Bringing it UP!${reset}"
90 ip link set dev ${interface} up
92 link_state=$(ip link show ${interface} | grep -oP 'state \K[^ ]+')
93 if [[ ${link_state} == 'DOWN' ]]; then
94 echo "${red}Could not bring UP interface ${interface} link state is ${link_state}${reset}"
98 echo "${green}OK!${reset}"
103 #Check whether base interface exists
104 echo "${blue}Checking whether base interface ${interface} exists${reset}"
105 if ! ip link show ${interface}; then
106 echo "${red}Base interface ${interface} does not exists!${reset}"
109 echo "${green}OK!${reset}"
112 #Check whether base interface is UP
113 check_interface ${interface}
116 pxe_interface="${interface}.${pxe_vid}"
118 #Check whether VLAN 0 (PXE) interface exists
119 echo "${blue}Checking whether VLAN 0 (PXE) interface ${pxe_interface} exists${reset}"
120 if ! ip link show ${pxe_interface}; then
121 echo "${blue}Creating VLAN 0 (PXE) interface ${pxe_interface}${reset}"
122 ip link add link ${interface} name ${pxe_interface} type vlan id ${pxe_vid}
124 echo "${green}OK!${reset}"
127 #Check whether VLAN 0 (PXE) interface is UP
128 check_interface ${pxe_interface}
130 #Check whether PXE bridge exists
131 echo "${blue}Checking whether PXE bridge ${pxe_bridge} exists${reset}"
132 if brctl show ${pxe_bridge} 2>&1 | grep 'No such device'; then
133 echo "${blue}Creating PXE bridge ${pxe_bridge}${reset}"
134 brctl addbr ${pxe_bridge}
136 echo "${green}OK!${reset}"
139 #Add VLAN 0 (PXE) interface to PXE bridge
140 echo "${blue}Checking whether VLAN 0 (PXE) interface ${pxe_interface} is added to PXE bridge ${pxe_bridge} exists${reset}"
141 if ! brctl show ${pxe_bridge} 2>&1 | grep ${pxe_interface}; then
142 echo "${blue}Adding VLAN 0 (PXE) interface ${pxe_interface} to PXE bridge ${pxe_bridge}${reset}"
143 brctl addif ${pxe_bridge} ${pxe_interface}
144 if ! brctl show ${pxe_bridge} 2>&1 | grep ${pxe_interface}; then
145 echo "${red}Could not add VLAN 0 (PXE) interface ${pxe_interface} to PXE bridge ${pxe_bridge}${reset}"
149 echo "${green}OK!${reset}"
152 #Check whether PXE bridge is UP
153 check_interface ${pxe_bridge}
155 #Add Fuel Gateway IP Address to PXE bridge
156 echo "${blue}Checking whether Fuel Gateway IP Address ${fuel_gw_ip} is assigned to PXE bridge ${pxe_bridge}${reset}"
157 if ! ip addr show ${pxe_bridge} | grep ${fuel_gw_ip}; then
158 echo "${blue}Adding Fuel Gateway IP Address ${fuel_gw_ip} to PXE bridge ${pxe_bridge}${reset}"
159 sudo ip addr add ${fuel_gw_ip} dev ${pxe_bridge}
160 if ! ip addr show ${pxe_bridge} | grep ${fuel_gw_ip}; then
161 echo "${red}Could not add Fuel Gateway IP Address ${fuel_gw_ip} to PXE bridge ${pxe_bridge}${reset}"
165 echo "${green}OK!${reset}"
174 start_libvirtd_service