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 ! virsh list --all | grep baremetal${i} > /dev/null; then
44 define_vm baremetal${i} network 41 'admin_network' $vcpus $ramsize
45 for n in private_network public_network storage_network api_network; do
46 if [[ $enabled_network_list =~ $n ]]; then
48 virsh attach-interface --domain baremetal${i} --type network --source $n --model virtio --config
52 echo "Found Baremetal ${i} VM, using existing VM"
54 #virsh vol-list default | grep baremetal${i} 2>&1> /dev/null || virsh vol-create-as default baremetal${i}.qcow2 41G --format qcow2
55 mac=$(virsh domiflist baremetal${i} | grep admin_network | awk '{ print $5 }')
57 if [ "$VM_COMPUTES" -gt 0 ]; then
58 capability="profile:compute"
59 VM_COMPUTES=$((VM_COMPUTES - 1))
61 capability="profile:control"
64 cat >> $CONFIG/instackenv-virt.json << EOF
66 "pm_addr": "192.168.122.1",
68 "pm_password": "INSERT_STACK_USER_PRIV_KEY",
77 "capabilities": "$capability"
82 #truncate the last line to remove the comma behind the bracket
83 tail -n 1 $CONFIG/instackenv-virt.json | wc -c | xargs -I {} truncate $CONFIG/instackenv-virt.json -s -{}
85 #finally reclose the bracket and close the instackenv.json file
86 cat >> $CONFIG/instackenv-virt.json << EOF
90 "host-ip": "192.168.122.1",
91 "power_manager": "nova.virt.baremetal.virtual_power_driver.VirtualPowerManager",
93 "ssh-key": "INSERT_STACK_USER_PRIV_KEY",
97 #Overwrite the tripleo-inclubator domain.xml with our own, keeping a backup.
98 if [ ! -f /usr/share/tripleo/templates/domain.xml.bak ]; then
99 /usr/bin/mv -f /usr/share/tripleo/templates/domain.xml /usr/share/tripleo/templates/domain.xml.bak
102 /usr/bin/cp -f $LIB/installer/domain.xml /usr/share/tripleo/templates/domain.xml
105 ##Create virtual nodes in virsh
106 ##params: name - String: libvirt name for VM
107 ## bootdev - String: boot device for the VM
108 ## disksize - Number: size of the disk in GB
109 ## ovs_bridges: - List: list of ovs bridges
110 ## vcpus - Number of VCPUs to use (defaults to 4)
111 ## ramsize - Size of RAM for VM in MB (defaults to 8192)
112 function define_vm () {
118 elif [ -z "$6" ]; then
126 # Create the libvirt storage volume
127 if virsh vol-list default | grep ${1}.qcow2 2>&1> /dev/null; then
128 volume_path=$(virsh vol-path --pool default ${1}.qcow2 || echo "/var/lib/libvirt/images/${1}.qcow2")
129 echo "Volume ${1} exists. Deleting Existing Volume $volume_path"
130 virsh vol-dumpxml ${1}.qcow2 --pool default > /dev/null || echo '' #ok for this to fail
132 virsh vol-delete ${1}.qcow2 --pool default
134 virsh vol-create-as default ${1}.qcow2 ${3}G --format qcow2
135 volume_path=$(virsh vol-path --pool default ${1}.qcow2)
136 if [ ! -f $volume_path ]; then
137 echo "$volume_path Not created successfully... Aborting"
142 /usr/libexec/openstack-tripleo/configure-vm --name $1 \
144 --image "$volume_path" \
149 --libvirt-nic-driver virtio \
150 --baremetal-interface $4