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 ##Create virtual nodes in virsh
12 ##params: vcpus, ramsize
13 function setup_virtual_baremetal {
18 elif [ -z "$2" ]; then
25 #start by generating the opening json for instackenv.json
26 cat > $CONFIG/instackenv-virt.json << EOF
31 # next create the virtual machines and add their definitions to the file
32 if [ "$ha_enabled" == "False" ]; then
33 # 1 controller + computes
34 # zero based so just pass compute count
37 # 3 controller + computes
38 # zero based so add 2 to compute count
39 vm_index=$((2+$VM_COMPUTES))
42 for i in $(seq 0 $vm_index); do
43 if [ "$VM_COMPUTES" -gt 0 ]; then
44 capability="profile:compute"
45 VM_COMPUTES=$((VM_COMPUTES - 1))
47 capability="profile:control"
48 if [[ "${deploy_options_array['sdn_controller']}" == 'opendaylight' && "$ramsize" -lt 10240 ]]; then
49 echo "WARN: RAM per controller too low. OpenDaylight specified in HA deployment requires at least 10GB"
50 echo "INFO: Increasing RAM per controller to 10GB"
54 if ! virsh list --all | grep baremetal${i} > /dev/null; then
55 define_vm baremetal${i} network 41 'admin_network' $vcpus $ramsize
56 for n in private_network public_network storage_network api_network; do
57 if [[ $enabled_network_list =~ $n ]]; then
59 virsh attach-interface --domain baremetal${i} --type network --source $n --model virtio --config
63 echo "Found Baremetal ${i} VM, using existing VM"
65 #virsh vol-list default | grep baremetal${i} 2>&1> /dev/null || virsh vol-create-as default baremetal${i}.qcow2 41G --format qcow2
66 mac=$(virsh domiflist baremetal${i} | grep admin_network | awk '{ print $5 }')
68 cat >> $CONFIG/instackenv-virt.json << EOF
70 "pm_addr": "192.168.122.1",
72 "pm_password": "INSERT_STACK_USER_PRIV_KEY",
81 "capabilities": "$capability"
86 #truncate the last line to remove the comma behind the bracket
87 tail -n 1 $CONFIG/instackenv-virt.json | wc -c | xargs -I {} truncate $CONFIG/instackenv-virt.json -s -{}
89 #finally reclose the bracket and close the instackenv.json file
90 cat >> $CONFIG/instackenv-virt.json << EOF
94 "host-ip": "192.168.122.1",
95 "power_manager": "nova.virt.baremetal.virtual_power_driver.VirtualPowerManager",
97 "ssh-key": "INSERT_STACK_USER_PRIV_KEY",
101 #Overwrite the tripleo-inclubator domain.xml with our own, keeping a backup.
102 if [ ! -f /usr/share/tripleo/templates/domain.xml.bak ]; then
103 /usr/bin/mv -f /usr/share/tripleo/templates/domain.xml /usr/share/tripleo/templates/domain.xml.bak
106 /usr/bin/cp -f $LIB/installer/domain.xml /usr/share/tripleo/templates/domain.xml
109 ##Create virtual nodes in virsh
110 ##params: name - String: libvirt name for VM
111 ## bootdev - String: boot device for the VM
112 ## disksize - Number: size of the disk in GB
113 ## ovs_bridges: - List: list of ovs bridges
114 ## vcpus - Number of VCPUs to use (defaults to 4)
115 ## ramsize - Size of RAM for VM in MB (defaults to 8192)
116 function define_vm () {
122 elif [ -z "$6" ]; then
130 # Create the libvirt storage volume
131 if virsh vol-list default | grep ${1}.qcow2 2>&1> /dev/null; then
132 volume_path=$(virsh vol-path --pool default ${1}.qcow2 || echo "/var/lib/libvirt/images/${1}.qcow2")
133 echo "Volume ${1} exists. Deleting Existing Volume $volume_path"
134 virsh vol-dumpxml ${1}.qcow2 --pool default > /dev/null || echo '' #ok for this to fail
136 virsh vol-delete ${1}.qcow2 --pool default
138 virsh vol-create-as default ${1}.qcow2 ${3}G --format qcow2
139 volume_path=$(virsh vol-path --pool default ${1}.qcow2)
140 if [ ! -f $volume_path ]; then
141 echo "$volume_path Not created successfully... Aborting"
146 /usr/libexec/openstack-tripleo/configure-vm --name $1 \
148 --image "$volume_path" \
153 --libvirt-nic-driver virtio \
154 --baremetal-interface $4