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 # Deploy script to install provisioning server for OPNFV Apex
12 # author: Dan Radez (dradez@redhat.com)
13 # author: Tim Rozet (trozet@redhat.com)
15 # Based on RDO Manager http://www.rdoproject.org
20 reset=$(tput sgr0 || echo "")
21 blue=$(tput setaf 4 || echo "")
22 red=$(tput setaf 1 || echo "")
23 green=$(tput setaf 2 || echo "")
27 ntp_server="pool.ntp.org"
28 net_isolation_enabled="TRUE"
34 declare -A deploy_options_array
35 declare -a performance_options
38 SSH_OPTIONS=(-o StrictHostKeyChecking=no -o GlobalKnownHostsFile=/dev/null -o UserKnownHostsFile=/dev/null -o LogLevel=error)
40 CONFIG=${CONFIG:-'/var/opt/opnfv'}
41 RESOURCES=${RESOURCES:-"$CONFIG/images"}
42 LIB=${LIB:-"$CONFIG/lib"}
43 OPNFV_NETWORK_TYPES="admin_network private_network public_network storage_network api_network"
49 # Netmap used to map networks to OVS bridge names
50 NET_MAP['admin_network']="br-admin"
51 NET_MAP['private_network']="br-private"
52 NET_MAP['public_network']="br-public"
53 NET_MAP['storage_network']="br-storage"
54 NET_MAP['api_network']="br-api"
55 ext_net_type="interface"
60 $LIB/common-functions.sh
61 $LIB/configure-deps-functions.sh
62 $LIB/parse-functions.sh
63 $LIB/utility-functions.sh
64 $LIB/installer/onos/onos_gw_mac_update.sh
66 for lib_file in ${lib_files[@]}; do
67 if ! source $lib_file; then
68 echo -e "${red}ERROR: Failed to source $lib_file${reset}"
74 ##checks if prefix exists in string
75 ##params: string, prefix
76 ##usage: contains_prefix "deploy_setting_launcher=1" "deploy_setting"
80 if echo $mystr | grep -E "^$prefix.*$" > /dev/null; then
87 ##verify internet connectivity
89 function verify_internet {
90 if ping -c 2 $ping_site > /dev/null; then
91 if ping -c 2 www.google.com > /dev/null; then
92 echo "${blue}Internet connectivity detected${reset}"
95 echo "${red}Internet connectivity detected, but DNS lookup failed${reset}"
99 echo "${red}No internet connectivity detected${reset}"
104 ##verify vm exists, an has a dhcp lease assigned to it
106 function setup_undercloud_vm {
107 if ! virsh list --all | grep undercloud > /dev/null; then
108 undercloud_nets="default admin_network"
109 if [[ $enabled_network_list =~ "public_network" ]]; then
110 undercloud_nets+=" public_network"
112 define_vm undercloud hd 30 "$undercloud_nets" 4 12288
114 ### this doesn't work for some reason I was getting hangup events so using cp instead
115 #virsh vol-upload --pool default --vol undercloud.qcow2 --file $CONFIG/stack/undercloud.qcow2
116 #2015-12-05 12:57:20.569+0000: 8755: info : libvirt version: 1.2.8, package: 16.el7_1.5 (CentOS BuildSystem <http://bugs.centos.org>, 2015-11-03-13:56:46, worker1.bsys.centos.org)
117 #2015-12-05 12:57:20.569+0000: 8755: warning : virKeepAliveTimerInternal:143 : No response from client 0x7ff1e231e630 after 6 keepalive messages in 35 seconds
118 #2015-12-05 12:57:20.569+0000: 8756: warning : virKeepAliveTimerInternal:143 : No response from client 0x7ff1e231e630 after 6 keepalive messages in 35 seconds
119 #error: cannot close volume undercloud.qcow2
120 #error: internal error: received hangup / error event on socket
121 #error: Reconnected to the hypervisor
123 local undercloud_dst=/var/lib/libvirt/images/undercloud.qcow2
124 cp -f $RESOURCES/undercloud.qcow2 $undercloud_dst
126 # resize Undercloud machine
127 echo "Checking if Undercloud needs to be resized..."
128 undercloud_size=$(LIBGUESTFS_BACKEND=direct virt-filesystems --long -h --all -a $undercloud_dst |grep device | grep -Eo "[0-9\.]+G" | sed -n 's/\([0-9][0-9]*\).*/\1/p')
129 if [ "$undercloud_size" -lt 30 ]; then
130 qemu-img resize /var/lib/libvirt/images/undercloud.qcow2 +25G
131 LIBGUESTFS_BACKEND=direct virt-resize --expand /dev/sda1 $RESOURCES/undercloud.qcow2 $undercloud_dst
132 LIBGUESTFS_BACKEND=direct virt-customize -a $undercloud_dst --run-command 'xfs_growfs -d /dev/sda1 || true'
133 new_size=$(LIBGUESTFS_BACKEND=direct virt-filesystems --long -h --all -a $undercloud_dst |grep filesystem | grep -Eo "[0-9\.]+G" | sed -n 's/\([0-9][0-9]*\).*/\1/p')
134 if [ "$new_size" -lt 30 ]; then
135 echo "Error resizing Undercloud machine, disk size is ${new_size}"
138 echo "Undercloud successfully resized"
141 echo "Skipped Undercloud resize, upstream is large enough"
145 echo "Found Undercloud VM, using existing VM"
148 # if the VM is not running update the authkeys and start it
149 if ! virsh list | grep undercloud > /dev/null; then
150 echo "Injecting ssh key to Undercloud VM"
151 LIBGUESTFS_BACKEND=direct virt-customize -a $undercloud_dst --run-command "mkdir -p /root/.ssh/" \
152 --upload ~/.ssh/id_rsa.pub:/root/.ssh/authorized_keys \
153 --run-command "chmod 600 /root/.ssh/authorized_keys && restorecon /root/.ssh/authorized_keys" \
154 --run-command "cp /root/.ssh/authorized_keys /home/stack/.ssh/" \
155 --run-command "chown stack:stack /home/stack/.ssh/authorized_keys && chmod 600 /home/stack/.ssh/authorized_keys"
156 virsh start undercloud
159 sleep 10 # let undercloud get started up
161 # get the undercloud VM IP
163 echo -n "${blue}Waiting for Undercloud's dhcp address${reset}"
164 undercloud_mac=$(virsh domiflist undercloud | grep default | awk '{ print $5 }')
165 while ! $(arp -e | grep ${undercloud_mac} > /dev/null) && [ $CNT -gt 0 ]; do
170 UNDERCLOUD=$(arp -e | grep ${undercloud_mac} | awk {'print $1'})
172 if [ -z "$UNDERCLOUD" ]; then
173 echo "\n\nCan't get IP for Undercloud. Can Not Continue."
176 echo -e "${blue}\rUndercloud VM has IP $UNDERCLOUD${reset}"
180 echo -en "${blue}\rValidating Undercloud VM connectivity${reset}"
181 while ! ping -c 1 $UNDERCLOUD > /dev/null && [ $CNT -gt 0 ]; do
186 if [ "$CNT" -eq 0 ]; then
187 echo "Failed to contact Undercloud. Can Not Continue"
191 while ! ssh -T ${SSH_OPTIONS[@]} "root@$UNDERCLOUD" "echo ''" 2>&1> /dev/null && [ $CNT -gt 0 ]; do
196 if [ "$CNT" -eq 0 ]; then
197 echo "Failed to connect to Undercloud. Can Not Continue"
201 # extra space to overwrite the previous connectivity output
202 echo -e "${blue}\r ${reset}"
205 # ssh key fix for stack user
206 ssh -T ${SSH_OPTIONS[@]} "root@$UNDERCLOUD" "restorecon -r /home/stack"
209 ##Create virtual nodes in virsh
210 ##params: vcpus, ramsize
211 function setup_virtual_baremetal {
216 elif [ -z "$2" ]; then
223 #start by generating the opening json for instackenv.json
224 cat > $CONFIG/instackenv-virt.json << EOF
229 # next create the virtual machines and add their definitions to the file
230 if [ "$ha_enabled" == "False" ]; then
231 # 1 controller + computes
232 # zero based so just pass compute count
233 vm_index=$VM_COMPUTES
235 # 3 controller + computes
236 # zero based so add 2 to compute count
237 vm_index=$((2+$VM_COMPUTES))
240 for i in $(seq 0 $vm_index); do
241 if ! virsh list --all | grep baremetal${i} > /dev/null; then
242 define_vm baremetal${i} network 41 'admin_network' $vcpus $ramsize
243 for n in private_network public_network storage_network api_network; do
244 if [[ $enabled_network_list =~ $n ]]; then
246 virsh attach-interface --domain baremetal${i} --type network --source $n --model virtio --config
250 echo "Found Baremetal ${i} VM, using existing VM"
252 #virsh vol-list default | grep baremetal${i} 2>&1> /dev/null || virsh vol-create-as default baremetal${i}.qcow2 41G --format qcow2
253 mac=$(virsh domiflist baremetal${i} | grep admin_network | awk '{ print $5 }')
255 if [ "$VM_COMPUTES" -gt 0 ]; then
256 capability="profile:compute"
257 VM_COMPUTES=$((VM_COMPUTES - 1))
259 capability="profile:control"
262 cat >> $CONFIG/instackenv-virt.json << EOF
264 "pm_addr": "192.168.122.1",
266 "pm_password": "INSERT_STACK_USER_PRIV_KEY",
267 "pm_type": "pxe_ssh",
272 "memory": "$ramsize",
275 "capabilities": "$capability"
280 #truncate the last line to remove the comma behind the bracket
281 tail -n 1 $CONFIG/instackenv-virt.json | wc -c | xargs -I {} truncate $CONFIG/instackenv-virt.json -s -{}
283 #finally reclose the bracket and close the instackenv.json file
284 cat >> $CONFIG/instackenv-virt.json << EOF
288 "host-ip": "192.168.122.1",
289 "power_manager": "nova.virt.baremetal.virtual_power_driver.VirtualPowerManager",
291 "ssh-key": "INSERT_STACK_USER_PRIV_KEY",
295 #Overwrite the tripleo-inclubator domain.xml with our own, keeping a backup.
296 if [ ! -f /usr/share/tripleo/templates/domain.xml.bak ]; then
297 /usr/bin/mv -f /usr/share/tripleo/templates/domain.xml /usr/share/tripleo/templates/domain.xml.bak
300 /usr/bin/cp -f $LIB/installer/domain.xml /usr/share/tripleo/templates/domain.xml
303 ##Create virtual nodes in virsh
304 ##params: name - String: libvirt name for VM
305 ## bootdev - String: boot device for the VM
306 ## disksize - Number: size of the disk in GB
307 ## ovs_bridges: - List: list of ovs bridges
308 ## vcpus - Number of VCPUs to use (defaults to 4)
309 ## ramsize - Size of RAM for VM in MB (defaults to 8192)
310 function define_vm () {
316 elif [ -z "$6" ]; then
324 # Create the libvirt storage volume
325 if virsh vol-list default | grep ${1}.qcow2 2>&1> /dev/null; then
326 volume_path=$(virsh vol-path --pool default ${1}.qcow2 || echo "/var/lib/libvirt/images/${1}.qcow2")
327 echo "Volume ${1} exists. Deleting Existing Volume $volume_path"
328 virsh vol-dumpxml ${1}.qcow2 --pool default > /dev/null || echo '' #ok for this to fail
330 virsh vol-delete ${1}.qcow2 --pool default
332 virsh vol-create-as default ${1}.qcow2 ${3}G --format qcow2
333 volume_path=$(virsh vol-path --pool default ${1}.qcow2)
334 if [ ! -f $volume_path ]; then
335 echo "$volume_path Not created successfully... Aborting"
340 /usr/libexec/openstack-tripleo/configure-vm --name $1 \
342 --image "$volume_path" \
347 --libvirt-nic-driver virtio \
348 --baremetal-interface $4
351 ##Copy over the glance images and instackenv json file
353 function configure_undercloud {
354 local controller_nic_template compute_nic_template
356 echo "Copying configuration files to Undercloud"
357 if [[ "$net_isolation_enabled" == "TRUE" ]]; then
358 echo -e "${blue}Network Environment set for Deployment: ${reset}"
359 cat /tmp/network-environment.yaml
360 scp ${SSH_OPTIONS[@]} /tmp/network-environment.yaml "stack@$UNDERCLOUD":
362 # check for ODL L3/ONOS
363 if [ "${deploy_options_array['sdn_l3']}" == 'True' ]; then
367 if [ "${deploy_options_array['dataplane']}" == 'ovs_dpdk' ]; then
368 ovs_dpdk_bridge='br-phy'
373 if ! controller_nic_template=$(python3.4 -B $LIB/python/apex_python_utils.py nic-template -r controller -s $NETSETS -i $net_isolation_enabled -t $CONFIG/nics-template.yaml.jinja2 -n "$enabled_network_list" -e "br-ex" -af $ip_addr_family); then
374 echo -e "${red}ERROR: Failed to generate controller NIC heat template ${reset}"
378 if ! compute_nic_template=$(python3.4 -B $LIB/python/apex_python_utils.py nic-template -r compute -s $NETSETS -i $net_isolation_enabled -t $CONFIG/nics-template.yaml.jinja2 -n "$enabled_network_list" -e $ext_net_type -af $ip_addr_family -d "$ovs_dpdk_bridge"); then
379 echo -e "${red}ERROR: Failed to generate compute NIC heat template ${reset}"
382 ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" << EOI
384 cat > nics/controller.yaml << EOF
385 $controller_nic_template
387 cat > nics/compute.yaml << EOF
388 $compute_nic_template
393 # ensure stack user on Undercloud machine has an ssh key
394 ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" "if [ ! -e ~/.ssh/id_rsa.pub ]; then ssh-keygen -t rsa -N '' -f ~/.ssh/id_rsa; fi"
396 if [ "$virtual" == "TRUE" ]; then
398 # copy the Undercloud VM's stack user's pub key to
399 # root's auth keys so that Undercloud can control
400 # vm power on the hypervisor
401 ssh ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" "cat /home/stack/.ssh/id_rsa.pub" >> /root/.ssh/authorized_keys
403 DEPLOY_OPTIONS+=" --libvirt-type qemu"
404 INSTACKENV=$CONFIG/instackenv-virt.json
406 # upload instackenv file to Undercloud for virtual deployment
407 scp ${SSH_OPTIONS[@]} $INSTACKENV "stack@$UNDERCLOUD":instackenv.json
410 # allow stack to control power management on the hypervisor via sshkey
411 # only if this is a virtual deployment
412 if [ "$virtual" == "TRUE" ]; then
413 ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI
414 while read -r line; do
415 stack_key=\${stack_key}\\\\\\\\n\${line}
416 done < <(cat ~/.ssh/id_rsa)
417 stack_key=\$(echo \$stack_key | sed 's/\\\\\\\\n//')
418 sed -i 's~INSERT_STACK_USER_PRIV_KEY~'"\$stack_key"'~' instackenv.json
422 # copy stack's ssh key to this users authorized keys
423 ssh -T ${SSH_OPTIONS[@]} "root@$UNDERCLOUD" "cat /home/stack/.ssh/id_rsa.pub" >> ~/.ssh/authorized_keys
425 # disable requiretty for sudo
426 ssh -T ${SSH_OPTIONS[@]} "root@$UNDERCLOUD" "sed -i 's/Defaults\s*requiretty//'" /etc/sudoers
428 # configure undercloud on Undercloud VM
429 echo "Running undercloud configuration."
430 echo "Logging undercloud configuration to undercloud:/home/stack/apex-undercloud-install.log"
431 ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" << EOI
432 if [[ "$net_isolation_enabled" == "TRUE" ]]; then
433 sed -i 's/#local_ip/local_ip/' undercloud.conf
434 sed -i 's/#network_gateway/network_gateway/' undercloud.conf
435 sed -i 's/#network_cidr/network_cidr/' undercloud.conf
436 sed -i 's/#dhcp_start/dhcp_start/' undercloud.conf
437 sed -i 's/#dhcp_end/dhcp_end/' undercloud.conf
438 sed -i 's/#inspection_iprange/inspection_iprange/' undercloud.conf
439 sed -i 's/#undercloud_debug/undercloud_debug/' undercloud.conf
441 openstack-config --set undercloud.conf DEFAULT local_ip ${admin_network_provisioner_ip}/${admin_network_cidr##*/}
442 openstack-config --set undercloud.conf DEFAULT network_gateway ${admin_network_provisioner_ip}
443 openstack-config --set undercloud.conf DEFAULT network_cidr ${admin_network_cidr}
444 openstack-config --set undercloud.conf DEFAULT dhcp_start ${admin_network_dhcp_range%%,*}
445 openstack-config --set undercloud.conf DEFAULT dhcp_end ${admin_network_dhcp_range##*,}
446 openstack-config --set undercloud.conf DEFAULT inspection_iprange ${admin_network_introspection_range}
447 openstack-config --set undercloud.conf DEFAULT undercloud_debug false
451 sudo sed -i '/CephClusterFSID:/c\\ CephClusterFSID: \\x27$(cat /proc/sys/kernel/random/uuid)\\x27' /usr/share/openstack-tripleo-heat-templates/environments/storage-environment.yaml
452 sudo sed -i '/CephMonKey:/c\\ CephMonKey: \\x27'"\$(ceph-authtool --gen-print-key)"'\\x27' /usr/share/openstack-tripleo-heat-templates/environments/storage-environment.yaml
453 sudo sed -i '/CephAdminKey:/c\\ CephAdminKey: \\x27'"\$(ceph-authtool --gen-print-key)"'\\x27' /usr/share/openstack-tripleo-heat-templates/environments/storage-environment.yaml
455 # we assume that packages will not need to be updated with undercloud install
456 # and that it will be used only to configure the undercloud
457 # packages updates would need to be handled manually with yum update
458 sudo cp -f /usr/share/diskimage-builder/elements/yum/bin/install-packages /usr/share/diskimage-builder/elements/yum/bin/install-packages.bak
459 cat << 'EOF' | sudo tee /usr/share/diskimage-builder/elements/yum/bin/install-packages > /dev/null
464 openstack undercloud install &> apex-undercloud-install.log || {
465 # cat the undercloud install log incase it fails
466 echo "ERROR: openstack undercloud install has failed. Dumping Log:"
467 cat apex-undercloud-install.log
472 sudo systemctl restart openstack-glance-api
473 sudo systemctl restart openstack-nova-conductor
474 sudo systemctl restart openstack-nova-compute
476 sudo sed -i '/num_engine_workers/c\num_engine_workers = 2' /etc/heat/heat.conf
477 sudo sed -i '/#workers\s=/c\workers = 2' /etc/heat/heat.conf
478 sudo systemctl restart openstack-heat-engine
479 sudo systemctl restart openstack-heat-api
482 # configure external network
483 ssh -T ${SSH_OPTIONS[@]} "root@$UNDERCLOUD" << EOI
484 if [[ "$public_network_vlan" != "native" ]]; then
485 cat <<EOF > /etc/sysconfig/network-scripts/ifcfg-vlan${public_network_vlan}
486 DEVICE=vlan${public_network_vlan}
491 IPADDR=${public_network_provisioner_ip}
492 PREFIX=${public_network_cidr##*/}
493 OVS_BRIDGE=br-ctlplane
494 OVS_OPTIONS="tag=${public_network_vlan}"
496 ifup vlan${public_network_vlan}
498 if ! ip a s eth2 | grep ${public_network_provisioner_ip} > /dev/null; then
499 ip a a ${public_network_provisioner_ip}/${public_network_cidr##*/} dev eth2
500 ip link set up dev eth2
505 # WORKAROUND: must restart the above services to fix sync problem with nova compute manager
506 # TODO: revisit and file a bug if necessary. This should eventually be removed
507 # as well as glance api problem
508 echo -e "${blue}INFO: Sleeping 15 seconds while services come back from restart${reset}"
513 ##preping it for deployment and launch the deploy
515 function undercloud_prep_overcloud_deploy {
516 if [[ "${#deploy_options_array[@]}" -eq 0 || "${deploy_options_array['sdn_controller']}" == 'opendaylight' ]]; then
517 if [ "${deploy_options_array['sdn_l3']}" == 'True' ]; then
518 DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/opendaylight_l3.yaml"
519 elif [ "${deploy_options_array['sfc']}" == 'True' ]; then
520 DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/opendaylight_sfc.yaml"
521 elif [ "${deploy_options_array['vpn']}" == 'True' ]; then
522 DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/opendaylight_sdnvpn.yaml"
523 elif [ "${deploy_options_array['vpp']}" == 'True' ]; then
524 DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/opendaylight_fdio.yaml"
526 DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/opendaylight.yaml"
528 SDN_IMAGE=opendaylight
529 if [ "${deploy_options_array['sfc']}" == 'True' ]; then
531 if [ ! -f $RESOURCES/overcloud-full-${SDN_IMAGE}.qcow2 ]; then
532 echo "${red} $RESOURCES/overcloud-full-${SDN_IMAGE}.qcow2 is required to execute an SFC deployment."
533 echo "Please install the opnfv-apex-opendaylight-sfc package to provide this overcloud image for deployment.${reset}"
537 elif [ "${deploy_options_array['sdn_controller']}" == 'opendaylight-external' ]; then
538 DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/opendaylight-external.yaml"
539 SDN_IMAGE=opendaylight
540 elif [ "${deploy_options_array['sdn_controller']}" == 'onos' ]; then
541 DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/onos.yaml"
543 elif [ "${deploy_options_array['sdn_controller']}" == 'opencontrail' ]; then
544 echo -e "${red}ERROR: OpenContrail is currently unsupported...exiting${reset}"
546 elif [[ -z "${deploy_options_array['sdn_controller']}" || "${deploy_options_array['sdn_controller']}" == 'False' ]]; then
547 echo -e "${blue}INFO: SDN Controller disabled...will deploy nosdn scenario${reset}"
548 SDN_IMAGE=opendaylight
550 echo "${red}Invalid sdn_controller: ${deploy_options_array['sdn_controller']}${reset}"
551 echo "${red}Valid choices are opendaylight, opendaylight-external, onos, opencontrail, False, or null${reset}"
557 # Make sure the correct overcloud image is available
558 if [ ! -f $RESOURCES/overcloud-full-${SDN_IMAGE}.qcow2 ]; then
559 echo "${red} $RESOURCES/overcloud-full-${SDN_IMAGE}.qcow2 is required to execute your deployment."
560 echo "Both ONOS and OpenDaylight are currently deployed from this image."
561 echo "Please install the opnfv-apex package to provide this overcloud image for deployment.${reset}"
565 echo "Copying overcloud image to Undercloud"
566 ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" "rm -f overcloud-full.qcow2"
567 scp ${SSH_OPTIONS[@]} $RESOURCES/overcloud-full-${SDN_IMAGE}.qcow2 "stack@$UNDERCLOUD":overcloud-full.qcow2
569 # Install ovs-dpdk inside the overcloud image if it is enabled.
570 if [ "${deploy_options_array['dataplane']}" == 'ovs_dpdk' ]; then
571 # install dpdk packages before ovs
572 echo -e "${blue}INFO: Enabling kernel modules for dpdk inside overcloud image${reset}"
574 ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI
575 cat << EOF > vfio_pci.modules
577 exec /sbin/modprobe vfio_pci >/dev/null 2>&1
580 cat << EOF > uio_pci_generic.modules
582 exec /sbin/modprobe uio_pci_generic >/dev/null 2>&1
585 LIBGUESTFS_BACKEND=direct virt-customize --upload vfio_pci.modules:/etc/sysconfig/modules/ \
586 --upload uio_pci_generic.modules:/etc/sysconfig/modules/ \
587 --run-command "chmod 0755 /etc/sysconfig/modules/vfio_pci.modules" \
588 --run-command "chmod 0755 /etc/sysconfig/modules/uio_pci_generic.modules" \
589 --run-command "yum install -y /root/dpdk_rpms/*" \
590 -a overcloud-full.qcow2
592 elif [ "${deploy_options_array['dataplane']}" != 'ovs' ]; then
593 echo "${red}${deploy_options_array['dataplane']} not supported${reset}"
597 # Set ODL version accordingly
598 if [[ "${deploy_options_array['sdn_controller']}" == 'opendaylight' && "${deploy_options_array['odl_version']}" == 'boron' ]]; then
599 ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI
600 LIBGUESTFS_BACKEND=direct virt-customize --run-command "yum -y remove opendaylight" \
601 --run-command "yum -y install /root/boron/*" \
602 -a overcloud-full.qcow2
606 # Add performance deploy options if they have been set
607 if [ ! -z "${deploy_options_array['performance']}" ]; then
609 # Remove previous kernel args files per role
610 ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" "rm -f Compute-kernel_params.txt"
611 ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" "rm -f Controller-kernel_params.txt"
613 # Push performance options to subscript to modify per-role images as needed
614 for option in "${performance_options[@]}" ; do
615 echo -e "${blue}Setting performance option $option${reset}"
616 ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" "bash build_perf_image.sh $option"
619 # Build IPA kernel option ramdisks
620 ssh -T ${SSH_OPTIONS[@]} "root@$UNDERCLOUD" <<EOI
621 /bin/cp -f /home/stack/ironic-python-agent.initramfs /root/
624 gunzip -c ../ironic-python-agent.initramfs | cpio -i
625 if [ ! -f /home/stack/Compute-kernel_params.txt ]; then
626 touch /home/stack/Compute-kernel_params.txt
627 chown stack /home/stack/Compute-kernel_params.txt
629 /bin/cp -f /home/stack/Compute-kernel_params.txt tmp/kernel_params.txt
630 echo "Compute params set: "
631 cat tmp/kernel_params.txt
632 /bin/cp -f /root/image.py usr/lib/python2.7/site-packages/ironic_python_agent/extensions/image.py
633 /bin/cp -f /root/image.pyc usr/lib/python2.7/site-packages/ironic_python_agent/extensions/image.pyc
634 find . | cpio -o -H newc | gzip > /home/stack/Compute-ironic-python-agent.initramfs
635 chown stack /home/stack/Compute-ironic-python-agent.initramfs
636 if [ ! -f /home/stack/Controller-kernel_params.txt ]; then
637 touch /home/stack/Controller-kernel_params.txt
638 chown stack /home/stack/Controller-kernel_params.txt
640 /bin/cp -f /home/stack/Controller-kernel_params.txt tmp/kernel_params.txt
641 echo "Controller params set: "
642 cat tmp/kernel_params.txt
643 find . | cpio -o -H newc | gzip > /home/stack/Controller-ironic-python-agent.initramfs
644 chown stack /home/stack/Controller-ironic-python-agent.initramfs
649 DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/numa.yaml"
652 # make sure ceph is installed
653 DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/storage-environment.yaml"
655 # scale compute nodes according to inventory
656 total_nodes=$(ssh -T ${SSH_OPTIONS[@]} "root@$UNDERCLOUD" "cat /home/stack/instackenv.json | grep -c memory")
658 # check if HA is enabled
659 if [[ "$ha_enabled" == "True" ]]; then
660 DEPLOY_OPTIONS+=" --control-scale 3"
661 compute_nodes=$((total_nodes - 3))
662 DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/puppet-pacemaker.yaml"
664 compute_nodes=$((total_nodes - 1))
667 if [ "$compute_nodes" -le 0 ]; then
668 echo -e "${red}ERROR: Invalid number of compute nodes: ${compute_nodes}. Check your inventory file.${reset}"
671 echo -e "${blue}INFO: Number of compute nodes set for deployment: ${compute_nodes}${reset}"
672 DEPLOY_OPTIONS+=" --compute-scale ${compute_nodes}"
675 if [[ "$net_isolation_enabled" == "TRUE" ]]; then
676 #DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/network-isolation.yaml"
677 DEPLOY_OPTIONS+=" -e network-environment.yaml"
680 if [[ "$ha_enabled" == "True" ]] || [[ "$net_isolation_enabled" == "TRUE" ]]; then
681 DEPLOY_OPTIONS+=" --ntp-server $ntp_server"
684 if [[ ! "$virtual" == "TRUE" ]]; then
685 DEPLOY_OPTIONS+=" --control-flavor control --compute-flavor compute"
687 DEPLOY_OPTIONS+=" -e virtual-environment.yaml"
690 DEPLOY_OPTIONS+=" -e opnfv-environment.yaml"
692 echo -e "${blue}INFO: Deploy options set:\n${DEPLOY_OPTIONS}${reset}"
694 ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI
695 if [ "$debug" == 'TRUE' ]; then
696 LIBGUESTFS_BACKEND=direct virt-customize -a overcloud-full.qcow2 --root-password password:opnfvapex
701 echo "Uploading overcloud glance images"
702 openstack overcloud image upload
704 echo "Configuring undercloud and discovering nodes"
705 openstack baremetal import --json instackenv.json
706 openstack baremetal configure boot
707 bash -x set_perf_images.sh ${performance_roles[@]}
708 #if [[ -z "$virtual" ]]; then
709 # openstack baremetal introspection bulk start
711 echo "Configuring flavors"
712 for flavor in baremetal control compute; do
713 echo -e "${blue}INFO: Updating flavor: \${flavor}${reset}"
714 if openstack flavor list | grep \${flavor}; then
715 openstack flavor delete \${flavor}
717 openstack flavor create --id auto --ram 4096 --disk 39 --vcpus 1 \${flavor}
718 if ! openstack flavor list | grep \${flavor}; then
719 echo -e "${red}ERROR: Unable to create flavor \${flavor}${reset}"
722 openstack flavor set --property "cpu_arch"="x86_64" --property "capabilities:boot_option"="local" baremetal
723 openstack flavor set --property "cpu_arch"="x86_64" --property "capabilities:boot_option"="local" --property "capabilities:profile"="control" control
724 openstack flavor set --property "cpu_arch"="x86_64" --property "capabilities:boot_option"="local" --property "capabilities:profile"="compute" compute
725 echo "Configuring nameserver on ctlplane network"
727 for dns_server in ${dns_servers}; do
728 dns_server_ext="\${dns_server_ext} --dns-nameserver \${dns_server}"
730 neutron subnet-update \$(neutron subnet-list | grep -Ev "id|tenant|external|storage" | grep -v \\\\-\\\\- | awk {'print \$2'}) \${dns_server_ext}
731 echo "Executing overcloud deployment, this should run for an extended period without output."
732 sleep 60 #wait for Hypervisor stats to check-in to nova
733 # save deploy command so it can be used for debugging
734 cat > deploy_command << EOF
735 openstack overcloud deploy --templates $DEPLOY_OPTIONS --timeout 90
739 if [ "$interactive" == "TRUE" ]; then
740 if ! prompt_user "Overcloud Deployment"; then
741 echo -e "${blue}INFO: User requests exit${reset}"
746 ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI
748 openstack overcloud deploy --templates $DEPLOY_OPTIONS --timeout 90
749 if ! heat stack-list | grep CREATE_COMPLETE 1>/dev/null; then
750 $(typeset -f debug_stack)
757 if [ "${deploy_options_array['dataplane']}" == 'ovs_dpdk' ]; then
758 ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI || (echo "DPDK config failed, exiting..."; exit 1)
761 for node in \$(nova list | grep novacompute | grep -Eo "[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+"); do
762 echo "Running DPDK test app on \$node"
763 ssh -T ${SSH_OPTIONS[@]} "heat-admin@\$node" <<EOF
765 sudo dpdk_helloworld --no-pci
766 sudo dpdk_nic_bind -s
772 if [ "$debug" == 'TRUE' ]; then
773 ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI
775 echo "Keystone Endpoint List:"
776 openstack endpoint list
777 echo "Keystone Service List"
778 openstack service list
779 cinder quota-show \$(openstack project list | grep admin | awk {'print \$2'})
784 ##Post configuration after install
786 function configure_post_install {
787 local opnfv_attach_networks ovs_ip ip_range net_cidr tmp_ip
788 opnfv_attach_networks="admin_network public_network"
790 echo -e "${blue}INFO: Post Install Configuration Running...${reset}"
792 echo -e "${blue}INFO: Configuring ssh for root to overcloud nodes...${reset}"
793 # copy host key to instack
794 scp ${SSH_OPTIONS[@]} /root/.ssh/id_rsa.pub "stack@$UNDERCLOUD":jumphost_id_rsa.pub
796 # add host key to overcloud nodes authorized keys
797 ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" << EOI
799 nodes=\$(nova list | grep -Eo "[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+")
800 for node in \$nodes; do
801 cat ~/jumphost_id_rsa.pub | ssh -T ${SSH_OPTIONS[@]} "heat-admin@\$node" 'cat >> ~/.ssh/authorized_keys'
805 if [ "${deploy_options_array['dataplane']}" == 'ovs_dpdk' ]; then
806 echo -e "${blue}INFO: Bringing up br-phy and ovs-agent for dpdk compute nodes...${reset}"
807 compute_nodes=$(undercloud_connect stack "source stackrc; nova list | grep compute | wc -l")
809 while [ "$i" -lt "$compute_nodes" ]; do
810 overcloud_connect compute${i} "sudo ifup br-phy; sudo systemctl restart neutron-openvswitch-agent"
815 ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI
818 echo "Configuring Neutron external network"
819 neutron net-create external --router:external=True --tenant-id \$(openstack project show service | grep id | awk '{ print \$4 }')
820 neutron subnet-create --name external-net --tenant-id \$(openstack project show service | grep id | awk '{ print \$4 }') --disable-dhcp external --gateway ${public_network_gateway} --allocation-pool start=${public_network_floating_ip_range%%,*},end=${public_network_floating_ip_range##*,} ${public_network_cidr}
822 echo "Removing sahara endpoint and service"
823 sahara_service_id=\$(openstack service list | grep sahara | cut -d ' ' -f 2)
824 sahara_endpoint_id=\$(openstack endpoint list | grep sahara | cut -d ' ' -f 2)
825 openstack endpoint delete \$sahara_endpoint_id
826 openstack service delete \$sahara_service_id
828 echo "Removing swift endpoint and service"
829 swift_service_id=\$(openstack service list | grep swift | cut -d ' ' -f 2)
830 swift_endpoint_id=\$(openstack endpoint list | grep swift | cut -d ' ' -f 2)
831 openstack endpoint delete \$swift_endpoint_id
832 openstack service delete \$swift_service_id
834 if [ "${deploy_options_array['congress']}" == 'True' ]; then
835 for s in nova neutronv2 ceilometer cinder glancev2 keystone; do
836 openstack congress datasource create \$s "\$s" \\
837 --config username=\$OS_USERNAME \\
838 --config tenant_name=\$OS_TENANT_NAME \\
839 --config password=\$OS_PASSWORD \\
840 --config auth_url=\$OS_AUTH_URL
845 echo -e "${blue}INFO: Checking if OVS bridges have IP addresses...${reset}"
846 for network in ${opnfv_attach_networks}; do
847 ovs_ip=$(find_ip ${NET_MAP[$network]})
849 if [ -n "$ovs_ip" ]; then
850 echo -e "${blue}INFO: OVS Bridge ${NET_MAP[$network]} has IP address ${ovs_ip}${reset}"
852 echo -e "${blue}INFO: OVS Bridge ${NET_MAP[$network]} missing IP, will configure${reset}"
853 # use last IP of allocation pool
854 eval "ip_range=\${${network}_usable_ip_range}"
855 ovs_ip=${ip_range##*,}
856 eval "net_cidr=\${${network}_cidr}"
857 sudo ip addr add ${ovs_ip}/${net_cidr##*/} dev ${NET_MAP[$network]}
858 sudo ip link set up ${NET_MAP[$network]}
859 tmp_ip=$(find_ip ${NET_MAP[$network]})
860 if [ -n "$tmp_ip" ]; then
861 echo -e "${blue}INFO: OVS Bridge ${NET_MAP[$network]} IP set: ${tmp_ip}${reset}"
864 echo -e "${red}ERROR: Unable to set OVS Bridge ${NET_MAP[$network]} with IP: ${ovs_ip}${reset}"
870 # for virtual, we NAT public network through Undercloud
871 if [ "$virtual" == "TRUE" ]; then
872 if ! configure_undercloud_nat ${public_network_cidr}; then
873 echo -e "${red}ERROR: Unable to NAT undercloud with external net: ${public_network_cidr}${reset}"
876 echo -e "${blue}INFO: Undercloud VM has been setup to NAT Overcloud public network${reset}"
880 # for sfc deployments we need the vxlan workaround
881 if [ "${deploy_options_array['sfc']}" == 'True' ]; then
882 ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI
885 for node in \$(nova list | grep -Eo "[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+"); do
886 ssh -T ${SSH_OPTIONS[@]} "heat-admin@\$node" <<EOF
887 sudo ifconfig br-int up
888 sudo ip route add 123.123.123.0/24 dev br-int
894 # Collect deployment logs
895 ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI
896 mkdir -p ~/deploy_logs
900 for node in \$(nova list | grep -Eo "[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+"); do
901 ssh -T ${SSH_OPTIONS[@]} "heat-admin@\$node" <<EOF
902 sudo cp /var/log/messages /home/heat-admin/messages.log
903 sudo chown heat-admin /home/heat-admin/messages.log
905 scp ${SSH_OPTIONS[@]} heat-admin@\$node:/home/heat-admin/messages.log ~/deploy_logs/\$node.messages.log
906 if [ "$debug" == "TRUE" ]; then
907 nova list --ip \$node
908 echo "---------------------------"
909 echo "-----/var/log/messages-----"
910 echo "---------------------------"
911 cat ~/deploy_logs/\$node.messages.log
912 echo "---------------------------"
913 echo "----------END LOG----------"
914 echo "---------------------------"
916 ssh -T ${SSH_OPTIONS[@]} "heat-admin@\$node" <<EOF
917 sudo rm -f /home/heat-admin/messages.log
921 # Print out the undercloud IP and dashboard URL
923 echo "Undercloud IP: $UNDERCLOUD, please connect by doing 'opnfv-util undercloud'"
924 echo "Overcloud dashboard available at http://\$(heat output-show overcloud PublicVip | sed 's/"//g')/dashboard"
930 echo -e "Usage:\n$0 [arguments] \n"
931 echo -e " -d|--deploy-settings : Full path to deploy settings yaml file. Optional. Defaults to null"
932 echo -e " -i|--inventory : Full path to inventory yaml file. Required only for baremetal"
933 echo -e " -n|--net-settings : Full path to network settings file. Optional."
934 echo -e " -p|--ping-site : site to use to verify IP connectivity. Optional. Defaults to 8.8.8.8"
935 echo -e " -v|--virtual : Virtualize overcloud nodes instead of using baremetal."
936 echo -e " --flat : disable Network Isolation and use a single flat network for the underlay network."
937 echo -e " --no-post-config : disable Post Install configuration."
938 echo -e " --debug : enable debug output."
939 echo -e " --interactive : enable interactive deployment mode which requires user to confirm steps of deployment."
940 echo -e " --virtual-cpus : Number of CPUs to use per Overcloud VM in a virtual deployment (defaults to 4)."
941 echo -e " --virtual-ram : Amount of RAM to use per Overcloud VM in GB (defaults to 8)."
944 ##translates the command line parameters into variables
945 ##params: $@ the entire command line is passed
946 ##usage: parse_cmd_line() "$@"
948 echo -e "\n\n${blue}This script is used to deploy the Apex Installer and Provision OPNFV Target System${reset}\n\n"
949 echo "Use -h to display help"
952 while [ "${1:0:1}" = "-" ]
959 -d|--deploy-settings)
960 DEPLOY_SETTINGS_FILE=$2
961 echo "Deployment Configuration file: $2"
970 echo "Network Settings Configuration file: $2"
975 echo "Using $2 as the ping site"
980 echo "Executing a Virtual Deployment"
984 net_isolation_enabled="FALSE"
985 echo "Underlay Network Isolation Disabled: using flat configuration"
990 echo "Post install configuration disabled"
995 echo "Enable debug output"
1000 echo "Interactive mode enabled"
1005 echo "Number of CPUs per VM set to $VM_CPUS"
1010 echo "Amount of RAM per VM set to $VM_RAM"
1013 --virtual-computes )
1015 echo "Virtual Compute nodes set to $VM_COMPUTES"
1025 if [[ ! -z "$NETSETS" && "$net_isolation_enabled" == "FALSE" ]]; then
1026 echo -e "${red}INFO: Single flat network requested. Only admin_network settings will be used!${reset}"
1027 elif [[ -z "$NETSETS" ]]; then
1028 echo -e "${red}ERROR: You must provide a network_settings file with -n.${reset}"
1032 if [[ -n "$virtual" && -n "$INVENTORY_FILE" ]]; then
1033 echo -e "${red}ERROR: You should not specify an inventory with virtual deployments${reset}"
1037 if [[ -z "$DEPLOY_SETTINGS_FILE" || ! -f "$DEPLOY_SETTINGS_FILE" ]]; then
1038 echo -e "${red}ERROR: Deploy Settings: ${DEPLOY_SETTINGS_FILE} does not exist! Exiting...${reset}"
1042 if [[ ! -z "$NETSETS" && ! -f "$NETSETS" ]]; then
1043 echo -e "${red}ERROR: Network Settings: ${NETSETS} does not exist! Exiting...${reset}"
1047 if [[ ! -z "$INVENTORY_FILE" && ! -f "$INVENTORY_FILE" ]]; then
1048 echo -e "{$red}ERROR: Inventory File: ${INVENTORY_FILE} does not exist! Exiting...${reset}"
1052 if [[ -z "$virtual" && -z "$INVENTORY_FILE" ]]; then
1053 echo -e "${red}ERROR: You must specify an inventory file for baremetal deployments! Exiting...${reset}"
1057 if [[ "$net_isolation_enabled" == "FALSE" && "$post_config" == "TRUE" ]]; then
1058 echo -e "${blue}INFO: Post Install Configuration will be skipped. It is not supported with --flat${reset}"
1068 echo -e "${blue}INFO: Parsing network settings file...${reset}"
1069 parse_network_settings
1070 if ! configure_deps; then
1071 echo -e "${red}Dependency Validation Failed, Exiting.${reset}"
1074 if [ -n "$DEPLOY_SETTINGS_FILE" ]; then
1075 echo -e "${blue}INFO: Parsing deploy settings file...${reset}"
1076 parse_deploy_settings
1079 if [ "$virtual" == "TRUE" ]; then
1080 setup_virtual_baremetal $VM_CPUS $VM_RAM
1081 elif [ -n "$INVENTORY_FILE" ]; then
1082 parse_inventory_file
1084 configure_undercloud
1085 undercloud_prep_overcloud_deploy
1086 if [ "$post_config" == "TRUE" ]; then
1087 if ! configure_post_install; then
1088 echo -e "${red}ERROR:Post Install Configuration Failed, Exiting.${reset}"
1091 echo -e "${blue}INFO: Post Install Configuration Complete${reset}"
1094 if [[ "${deploy_options_array['sdn_controller']}" == 'onos' ]]; then
1095 if ! onos_update_gw_mac ${public_network_cidr} ${public_network_gateway}; then
1096 echo -e "${red}ERROR:ONOS Post Install Configuration Failed, Exiting.${reset}"
1099 echo -e "${blue}INFO: ONOS Post Install Configuration Complete${reset}"