2 ##############################################################################
3 # Copyright (c) 2015 Tim Rozet (Red Hat), Dan Radez (Red Hat) and others.
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 ##############################################################################
11 ##download dependencies if missing and configure host
13 function configure_deps {
14 if ! verify_internet; then
15 echo "${red}Will not download dependencies${reset}"
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"
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
32 # ensure networks are configured
33 systemctl status libvirtd || systemctl start libvirtd
34 systemctl status openvswitch || systemctl start openvswitch
36 # For baremetal we only need to create/attach Undercloud to admin and external
37 if [ "$virtual" == "FALSE" ]; then
38 virsh_enabled_networks="admin external"
40 virsh_enabled_networks=$enabled_network_list
43 # ensure default network is configured correctly
44 libvirt_dir="/usr/share/libvirt/networks"
45 virsh net-list --all | grep default || virsh net-define ${libvirt_dir}/default.xml
46 virsh net-list --all | grep -E "default\s+active" > /dev/null || virsh net-start default
47 virsh net-list --all | grep -E "default\s+active\s+yes" > /dev/null || virsh net-autostart --network default
49 if [[ -z "$virtual" || "$virtual" == "FALSE" ]]; then
50 for network in ${enabled_network_list}; do
51 echo "${blue}INFO: Creating Virsh Network: $network & OVS Bridge: ${NET_MAP[$network]}${reset}"
52 ovs-vsctl list-br | grep "^${NET_MAP[$network]}$" > /dev/null || ovs-vsctl add-br ${NET_MAP[$network]}
53 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
56 <forward mode='bridge'/>
57 <bridge name='${NET_MAP[$network]}'/>
58 <virtualport type='openvswitch'/>
61 if ! (virsh net-list --all | grep " $network " > /dev/null); then
62 echo "${red}ERROR: unable to create network: ${network}${reset}"
65 rm -f ${libvirt_dir}/apex-virsh-net.xml &> /dev/null;
66 virsh net-list | grep -E "$network\s+active" > /dev/null || virsh net-start $network
67 virsh net-list | grep -E "$network\s+active\s+yes" > /dev/null || virsh net-autostart --network $network
70 echo -e "${blue}INFO: Bridges set: ${reset}"
73 # bridge interfaces to correct OVS instances for baremetal deployment
74 for network in ${enabled_network_list}; do
75 if [[ "$network" != "admin" && "$network" != "external" ]]; then
78 this_interface=$(eval echo \${${network}_installer_vm_members})
79 # check if this a bridged interface for this network
80 if [[ ! -z "$this_interface" || "$this_interface" != "none" ]]; then
81 if ! attach_interface_to_ovs ${NET_MAP[$network]} ${this_interface} ${network}; then
82 echo -e "${red}ERROR: Unable to bridge interface ${this_interface} to bridge ${NET_MAP[$network]} for enabled network: ${network}${reset}"
85 echo -e "${blue}INFO: Interface ${this_interface} bridged to bridge ${NET_MAP[$network]} for enabled network: ${network}${reset}"
88 echo "${red}ERROR: Unable to determine interface to bridge to for enabled network: ${network}${reset}"
93 for network in ${OPNFV_NETWORK_TYPES}; do
94 if ! ovs-vsctl --may-exist add-br ${NET_MAP[$network]}; then
95 echo -e "${red}ERROR: Failed to create ovs bridge ${NET_MAP[$network]}{$reset}"
98 echo "${blue}INFO: Creating Virsh Network: $network${reset}"
99 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
101 <name>$network</name>
102 <forward mode='bridge'/>
103 <bridge name='${NET_MAP[$network]}'/>
104 <virtualport type='openvswitch'/>
107 if ! (virsh net-list --all | grep $network > /dev/null); then
108 echo "${red}ERROR: unable to create network: ${network}${reset}"
111 rm -f ${libvirt_dir}/apex-virsh-net.xml &> /dev/null;
112 virsh net-list | grep -E "$network\s+active" > /dev/null || virsh net-start $network
113 virsh net-list | grep -E "$network\s+active\s+yes" > /dev/null || virsh net-autostart --network $network
116 echo -e "${blue}INFO: Bridges set: ${reset}"
120 echo -e "${blue}INFO: virsh networks set: ${reset}"
123 # ensure storage pool exists and is started
124 virsh pool-list --all | grep default > /dev/null || virsh pool-define-as --name default dir --target /var/lib/libvirt/images
125 virsh pool-list | grep -Eo "default\s+active" > /dev/null || (virsh pool-autostart default; virsh pool-start default)
127 if ! egrep '^flags.*(vmx|svm)' /proc/cpuinfo > /dev/null; then
128 echo "${red}virtualization extensions not found, kvm kernel module insertion may fail.\n \
129 Are you sure you have enabled vmx in your bios or hypervisor?${reset}"
132 if ! lsmod | grep kvm > /dev/null; then modprobe kvm; fi
133 if ! lsmod | grep kvm_intel > /dev/null; then modprobe kvm_intel; fi
135 if ! lsmod | grep kvm > /dev/null; then
136 echo "${red}kvm kernel modules not loaded!${reset}"
140 # try to enabled nested kvm
141 if [ "$virtual" == "TRUE" ]; then
142 nested_kvm=`cat /sys/module/kvm_intel/parameters/nested`
143 if [ "$nested_kvm" != "Y" ]; then
144 # try to enable nested kvm
145 echo 'options kvm-intel nested=1' > /etc/modprobe.d/kvm_intel.conf
146 if rmmod kvm_intel; then
149 nested_kvm=`cat /sys/module/kvm_intel/parameters/nested`
151 if [ "$nested_kvm" != "Y" ]; then
152 echo "${red}Cannot enable nested kvm, falling back to qemu for deployment${reset}"
153 DEPLOY_OPTIONS+=" --libvirt-type qemu"
155 echo "${blue}Nested kvm enabled, deploying with kvm acceleration${reset}"
160 if [ ! -e ~/.ssh/id_rsa.pub ]; then
161 ssh-keygen -t rsa -N "" -f ~/.ssh/id_rsa
164 echo "${blue}All dependencies installed and running${reset}"