Updates release notes for Colorado 3.0
[apex.git] / lib / configure-deps-functions.sh
1 #!/usr/bin/env bash
2 ##############################################################################
3 # Copyright (c) 2015 Tim Rozet (Red Hat), Dan Radez (Red Hat) and others.
4 #
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
10
11 ##download dependencies if missing and configure host
12 #params: none
13 function configure_deps {
14   if ! verify_internet; then
15     echo "${red}Will not download dependencies${reset}"
16     internet=false
17   fi
18
19   # verify ip forwarding
20   if sysctl net.ipv4.ip_forward | grep 0; then
21     sudo sysctl -w net.ipv4.ip_forward=1
22     sudo sh -c "echo 'net.ipv4.ip_forward = 1' >> /etc/sysctl.conf"
23   fi
24
25   # ensure no dhcp server is running on jumphost
26   if ! sudo systemctl status dhcpd | grep dead; then
27     echo "${red}WARN: DHCP Server detected on jumphost, disabling...${reset}"
28     sudo systemctl stop dhcpd
29     sudo systemctl disable dhcpd
30   fi
31
32   # ensure networks are configured
33   systemctl status libvirtd || systemctl start libvirtd
34   systemctl status openvswitch || systemctl start openvswitch
35
36   # If flat we only use admin network
37   if [[ "$net_isolation_enabled" == "FALSE" ]]; then
38     virsh_enabled_networks="admin_network"
39     enabled_network_list="admin_network"
40   # For baremetal we only need to create/attach Undercloud to admin and public
41   elif [ "$virtual" == "FALSE" ]; then
42     virsh_enabled_networks="admin_network public_network"
43   else
44     virsh_enabled_networks=$enabled_network_list
45   fi
46
47   # ensure default network is configured correctly
48   libvirt_dir="/usr/share/libvirt/networks"
49   virsh net-list --all | grep default || virsh net-define ${libvirt_dir}/default.xml
50   virsh net-list --all | grep -E "default\s+active" > /dev/null || virsh net-start default
51   virsh net-list --all | grep -E "default\s+active\s+yes" > /dev/null || virsh net-autostart --network default
52
53   if [[ -z "$virtual" || "$virtual" == "FALSE" ]]; then
54     for network in ${enabled_network_list}; do
55       echo "${blue}INFO: Creating Virsh Network: $network & OVS Bridge: ${NET_MAP[$network]}${reset}"
56       ovs-vsctl list-br | grep "^${NET_MAP[$network]}$" > /dev/null || ovs-vsctl add-br ${NET_MAP[$network]}
57       virsh net-list --all | grep $network > /dev/null || (cat > ${libvirt_dir}/apex-virsh-net.xml && virsh net-define ${libvirt_dir}/apex-virsh-net.xml) << EOF
58 <network>
59   <name>$network</name>
60   <forward mode='bridge'/>
61   <bridge name='${NET_MAP[$network]}'/>
62   <virtualport type='openvswitch'/>
63 </network>
64 EOF
65       if ! (virsh net-list --all | grep $network > /dev/null); then
66           echo "${red}ERROR: unable to create network: ${network}${reset}"
67           exit 1;
68       fi
69       rm -f ${libvirt_dir}/apex-virsh-net.xml &> /dev/null;
70       virsh net-list | grep -E "$network\s+active" > /dev/null || virsh net-start $network
71       virsh net-list | grep -E "$network\s+active\s+yes" > /dev/null || virsh net-autostart --network $network
72     done
73
74     echo -e "${blue}INFO: Bridges set: ${reset}"
75     ovs-vsctl list-br
76
77     # bridge interfaces to correct OVS instances for baremetal deployment
78     for network in ${enabled_network_list}; do
79       if [[ "$network" != "admin_network" && "$network" != "public_network" ]]; then
80         continue
81       fi
82       this_interface=$(eval echo \${${network}_bridged_interface})
83       # check if this a bridged interface for this network
84       if [[ ! -z "$this_interface" || "$this_interface" != "none" ]]; then
85         if ! attach_interface_to_ovs ${NET_MAP[$network]} ${this_interface} ${network}; then
86           echo -e "${red}ERROR: Unable to bridge interface ${this_interface} to bridge ${NET_MAP[$network]} for enabled network: ${network}${reset}"
87           exit 1
88         else
89           echo -e "${blue}INFO: Interface ${this_interface} bridged to bridge ${NET_MAP[$network]} for enabled network: ${network}${reset}"
90         fi
91       else
92         echo "${red}ERROR: Unable to determine interface to bridge to for enabled network: ${network}${reset}"
93         exit 1
94       fi
95     done
96   else
97     for network in ${OPNFV_NETWORK_TYPES}; do
98       if ! ovs-vsctl --may-exist add-br ${NET_MAP[$network]}; then
99        echo -e "${red}ERROR: Failed to create ovs bridge ${NET_MAP[$network]}{$reset}"
100        exit 1
101       fi
102       echo "${blue}INFO: Creating Virsh Network: $network${reset}"
103       virsh net-list --all | grep $network > /dev/null || (cat > ${libvirt_dir}/apex-virsh-net.xml && virsh net-define ${libvirt_dir}/apex-virsh-net.xml) << EOF
104 <network ipv6='yes'>
105 <name>$network</name>
106 <forward mode='bridge'/>
107 <bridge name='${NET_MAP[$network]}'/>
108 <virtualport type='openvswitch'/>
109 </network>
110 EOF
111       if ! (virsh net-list --all | grep $network > /dev/null); then
112           echo "${red}ERROR: unable to create network: ${network}${reset}"
113           exit 1;
114       fi
115       rm -f ${libvirt_dir}/apex-virsh-net.xml &> /dev/null;
116       virsh net-list | grep -E "$network\s+active" > /dev/null || virsh net-start $network
117       virsh net-list | grep -E "$network\s+active\s+yes" > /dev/null || virsh net-autostart --network $network
118     done
119
120     echo -e "${blue}INFO: Bridges set: ${reset}"
121     ovs-vsctl list-br
122   fi
123
124   echo -e "${blue}INFO: virsh networks set: ${reset}"
125   virsh net-list
126
127   # ensure storage pool exists and is started
128   virsh pool-list --all | grep default > /dev/null || virsh pool-define-as --name default dir --target /var/lib/libvirt/images
129   virsh pool-list | grep -Eo "default\s+active" > /dev/null || (virsh pool-autostart default; virsh pool-start default)
130
131   if ! egrep '^flags.*(vmx|svm)' /proc/cpuinfo > /dev/null; then
132     echo "${red}virtualization extensions not found, kvm kernel module insertion may fail.\n  \
133 Are you sure you have enabled vmx in your bios or hypervisor?${reset}"
134   fi
135
136   if ! lsmod | grep kvm > /dev/null; then modprobe kvm; fi
137   if ! lsmod | grep kvm_intel > /dev/null; then modprobe kvm_intel; fi
138
139   if ! lsmod | grep kvm > /dev/null; then
140     echo "${red}kvm kernel modules not loaded!${reset}"
141     return 1
142   fi
143
144   # try to enabled nested kvm
145   if [ "$virtual" == "TRUE" ]; then
146     nested_kvm=`cat /sys/module/kvm_intel/parameters/nested`
147     if [ "$nested_kvm" != "Y" ]; then
148       # try to enable nested kvm
149       echo 'options kvm-intel nested=1' > /etc/modprobe.d/kvm_intel.conf
150       if rmmod kvm_intel; then
151         modprobe kvm_intel
152       fi
153       nested_kvm=`cat /sys/module/kvm_intel/parameters/nested`
154     fi
155     if [ "$nested_kvm" != "Y" ]; then
156       echo "${red}Cannot enable nested kvm, falling back to qemu for deployment${reset}"
157       DEPLOY_OPTIONS+=" --libvirt-type qemu"
158     else
159       echo "${blue}Nested kvm enabled, deploying with kvm acceleration${reset}"
160     fi
161   fi
162
163   ##sshkeygen for root
164   if [ ! -e ~/.ssh/id_rsa.pub ]; then
165     ssh-keygen -t rsa -N "" -f ~/.ssh/id_rsa
166   fi
167
168   echo "${blue}All dependencies installed and running${reset}"
169 }