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 # 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"
44 virsh_enabled_networks=$enabled_network_list
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
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
60 <forward mode='bridge'/>
61 <bridge name='${NET_MAP[$network]}'/>
62 <virtualport type='openvswitch'/>
65 if ! (virsh net-list --all | grep $network > /dev/null); then
66 echo "${red}ERROR: unable to create network: ${network}${reset}"
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
74 echo -e "${blue}INFO: Bridges set: ${reset}"
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
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}"
89 echo -e "${blue}INFO: Interface ${this_interface} bridged to bridge ${NET_MAP[$network]} for enabled network: ${network}${reset}"
92 echo "${red}ERROR: Unable to determine interface to bridge to for enabled network: ${network}${reset}"
97 for network in ${OPNFV_NETWORK_TYPES}; do
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 <bridge name='${NET_MAP[$network]}'/>
105 if ! (virsh net-list --all | grep $network > /dev/null); then
106 echo "${red}ERROR: unable to create network: ${network}${reset}"
109 rm -f ${libvirt_dir}/apex-virsh-net.xml &> /dev/null;
110 virsh net-list | grep -E "$network\s+active" > /dev/null || virsh net-start $network
111 virsh net-list | grep -E "$network\s+active\s+yes" > /dev/null || virsh net-autostart --network $network
114 echo -e "${blue}INFO: Bridges set: ${reset}"
118 echo -e "${blue}INFO: virsh networks set: ${reset}"
121 # ensure storage pool exists and is started
122 virsh pool-list --all | grep default > /dev/null || virsh pool-define-as --name default dir --target /var/lib/libvirt/images
123 virsh pool-list | grep -Eo "default\s+active" > /dev/null || (virsh pool-autostart default; virsh pool-start default)
125 if ! egrep '^flags.*(vmx|svm)' /proc/cpuinfo > /dev/null; then
126 echo "${red}virtualization extensions not found, kvm kernel module insertion may fail.\n \
127 Are you sure you have enabled vmx in your bios or hypervisor?${reset}"
130 if ! lsmod | grep kvm > /dev/null; then modprobe kvm; fi
131 if ! lsmod | grep kvm_intel > /dev/null; then modprobe kvm_intel; fi
133 if ! lsmod | grep kvm > /dev/null; then
134 echo "${red}kvm kernel modules not loaded!${reset}"
138 # try to enabled nested kvm
139 if [ "$virtual" == "TRUE" ]; then
140 nested_kvm=`cat /sys/module/kvm_intel/parameters/nested`
141 if [ "$nested_kvm" != "Y" ]; then
142 # try to enable nested kvm
143 echo 'options kvm-intel nested=1' > /etc/modprobe.d/kvm_intel.conf
144 if rmmod kvm_intel; then
147 nested_kvm=`cat /sys/module/kvm_intel/parameters/nested`
149 if [ "$nested_kvm" != "Y" ]; then
150 echo "${red}Cannot enable nested kvm, falling back to qemu for deployment${reset}"
151 DEPLOY_OPTIONS+=" --libvirt-type qemu"
153 echo "${blue}Nested kvm enabled, deploying with kvm acceleration${reset}"
158 if [ ! -e ~/.ssh/id_rsa.pub ]; then
159 ssh-keygen -t rsa -N "" -f ~/.ssh/id_rsa
162 echo "${blue}All dependencies installed and running${reset}"