Update scripts for defining libvirt vms
* added shared functions file
* added env_vars file
* added script for deploying slave
Related-Prod: PROD-29666 (PROD:29666)
Change-Id: Iaa7e6b7383465fda446a61ffb7d74573565b352c
diff --git a/predefine-vm/README.rst b/predefine-vm/README.rst
index fae8f34..d69acd4 100644
--- a/predefine-vm/README.rst
+++ b/predefine-vm/README.rst
@@ -18,7 +18,8 @@
* VM_NAME - the name of VM to be created in VirtualBox. Default: 'cfg01-mcp.local'.
* VM_SOURCE_DISK - the name of virtual disk to be used for virtual machine. Can be relative or absolute path.
- * VM_CONFIG_DISK - same as VM_SOURCE_DISK, but for config-drive ISO file.
+ You can download and use the following image: http://images.mcp.mirantis.net/cfg01-day01-2019.2.0.qcow2
+ * VM_CONFIG_DISK - Config-drive ISO file, can be relative or absolute path.
* VM_MGM_BRIDGE_NAME - Bridge name to use for deploy management network. Should have Internet access if not
offline case. Optional, default: 'br-mgm'
* VM_CTL_BRIDGE_NAME - Bridge name to use for control network. Optional, default: 'br-ctl'
@@ -42,6 +43,53 @@
It is recommended to specify username and password during model generation for login via VM console if
something goes wrong. Once you are logged in you can follow usual debug procedure for cfg01 node.
+Deploy OpenStack All-In-One node on Ubuntu with QEMU/KVM (libvirt)
+==================================================================
+
+**Prerequisites**
+
+Setup cfg01 node and it's up, running and configured.
+
+**Common info**
+
+Script define-slave-vm.sh gives you an ability to deploy OpenStack All-in-one VM with provided Qcwo2 disk
+image and config-drive iso file on your local laptop.
+
+Script is operating by next ENV variables:
+
+ * SLAVE_VM_NAME - the name of VM to be created in VirtualBox.
+ * SLAVE_VM_SOURCE_DISK - the name of virtual disk to be used for virtual machine. Can be relative or absolute path.
+ You can download and use the following image: http://images.mcp.mirantis.net/ubuntu-16-04-x64-mcp2019.2.0.qcow2
+ * SLAVE_VM_MEM_KB - amount of RAM for VM in KB. Default is: 16777216
+ * SLAVE_VM_CPUS - amount of CPUs to use. Default is: 4.
+
+Next parameters should be same as for cfg01 node:
+
+ * VM_CONFIG_DISK
+ * VM_MGM_BRIDGE_NAME
+ * VM_CTL_BRIDGE_NAME
+ * VM_MGM_BRIDGE_DISABLE
+ * VM_CTL_BRIDGE_DISABLE
+ * VM_MGM_NETWORK_NAME
+ * VM_CTL_NETWORK_NAME
+ * VM_MGM_NETWORK_GATEWAY
+ * VM_MGM_NETWORK_MASK
+ * VM_CTL_NETWORK_GATEWAY
+ * VM_CTL_NETWORK_MASK
+
+Also once you setup cfg01 setup the next parameter: export CREATE_NEWORKS=false
+This parameter will disable network recreation, which can be needed in case of changing network setup.
+
+Also if you are not going to use system bridges, set next parameters to true:
+
+ * VM_MGM_BRIDGE_DISABLE=true
+ * VM_CTL_BRIDGE_DISABLE=true
+
+This will switch using to locally created virsh networks.
+
+Script will check that disk and cfg01 config-drive are present and then prepare config-drive for all-in-one node.
+Once VM is up and running you can use ``virsh console`` to check what is going on during deploy. For that VM will be used
+same fail safe user as for cfg01.
Deploy cfg01 on Mac OS with VirtualBox
======================================
diff --git a/predefine-vm/define-slave-vm.sh b/predefine-vm/define-slave-vm.sh
new file mode 100755
index 0000000..fd60dca
--- /dev/null
+++ b/predefine-vm/define-slave-vm.sh
@@ -0,0 +1,109 @@
+#!/bin/bash
+
+functionsFile="$(pwd)/functions.sh"
+
+if [[ ! -f ${functionsFile} ]]; then
+ echo "ERROR: Can not find 'functions' libfile (${functionsFile}), check your mcp/mcp-common-scripts repo."
+ exit 1
+else
+ source ${functionsFile}
+fi
+
+if [[ -z ${SLAVE_VM_NAME} ]]; then
+ echo "ERROR: \$SLAVE_VM_NAME not set!"
+ exit 1
+fi
+if [[ -z ${SLAVE_VM_SOURCE_DISK} ]] || [[ ! -f ${SLAVE_VM_SOURCE_DISK} ]]; then
+ echo "ERROR: \$SLAVE_VM_SOURCE_DISK not set, or file does not exist!"
+ exit 1
+fi
+if [[ -z ${VM_CONFIG_DISK} ]] || [[ ! -f ${VM_CONFIG_DISK} ]]; then
+ echo "ERROR: \$VM_CONFIG_DISK not set, or file does not exist!"
+ exit 1
+fi
+
+check_packages "slave"
+
+configDriveDir="$(dirname $0)/../config-drive"
+pushd "${configDriveDir}"
+tmpDir=$(mktemp -d -p $(pwd))
+mount ${VM_CONFIG_DISK} ${tmpDir}
+contextFile=$(find ${tmpDir}/mcp -name context_data.yml)
+allocationDataFile=$(find ${tmpDir}/mcp -name allocation_data.yml)
+saltMasterIp=$(grep salt_master_management_address ${contextFile} | cut -f 2 -d ':' | tr -d ' ')
+clusterDomain=$(grep cluster_domain ${contextFile} | cut -f 2 -d ':' | tr -d ' ')
+aioIp=$(grep 'aio_node_deploy_address:' ${allocationDataFile} | cut -f 2 -d ':' | tr -d ' ')
+aioHostname=$(grep 'aio_node_hostname:' ${allocationDataFile} | cut -f 2 -d ':' | tr -d ' ')
+aioFailSafeUserKey=$(grep cfg_failsafe_ssh_public_key ${contextFile} | cut -f 2 -d ':' | tr -d ' ')
+aioFailSafeUser=$(grep cfg_failsafe_user ${contextFile} | cut -f 2 -d ':' | tr -d ' ')
+networkDataFile=$(find ${tmpDir}/openstack -name network_data.json )
+networkDataFileBaseName=$(basename ${networkDataFile})
+cp ${networkDataFile} ./${networkDataFileBaseName}
+sed -i ${networkDataFileBaseName} -e "s/${saltMasterIp}/${aioIp}/g"
+umount ${tmpDir}
+rm -rf ${tmpDir}
+
+cat <<EOF > ./user_data
+#cloud-config
+output : { all : '| tee -a /var/log/cloud-init-output.log' }
+growpart:
+ mode: auto
+ devices:
+ - '/'
+ - '/dev/vda3'
+ ignore_growroot_disabled: false
+write_files:
+ - content: |
+ root:
+ size: '70%VG'
+ var_log:
+ size: '10%VG'
+ var_log_audit:
+ size: '500M'
+ var_tmp:
+ size: '3000M'
+ tmp:
+ size: '500M'
+ owner: root:root
+ path: /usr/share/growlvm/image-layout.yml
+slave_boot:
+ - &slave_boot |
+ #!/bin/bash
+
+ # Redirect all outputs
+ exec > >(tee -i /tmp/cloud-init-bootstrap.log) 2>&1
+ set -xe
+
+ echo "Configuring Salt minion ..."
+ [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d
+ echo -e "id: ${aioHostname}.${clusterDomain}\nmaster: ${saltMasterIp}" > /etc/salt/minion.d/minion.conf
+ cat >> /etc/salt/minion.d/minion.conf << EOF
+ max_event_size: 100000000
+ acceptance_wait_time_max: 60
+ acceptance_wait_time: 10
+ random_reauth_delay: 270
+ recon_default: 1000
+ recon_max: 60000
+ recon_randomize: True
+ auth_timeout: 60
+ EOF
+ service salt-minion restart
+runcmd:
+ - 'if lvs vg0; then pvresize /dev/vda3; fi'
+ - 'if lvs vg0; then /usr/bin/growlvm.py --image-layout-file /usr/share/growlvm/image-layout.yml; fi'
+ - [bash, -cex, *slave_boot]
+EOF
+
+isoArgs="--name ${aioHostname} --hostname ${aioHostname}.${clusterDomain} --user-data $(pwd)/user_data --network-data $(pwd)/${networkDataFileBaseName} --cloud-user-name ${aioFailSafeUser} --ssh-key ${aioFailSafeUserKey} --quiet --clean-up"
+python ./create_config_drive.py ${isoArgs}
+qemu-img resize ${SLAVE_VM_SOURCE_DISK} 80G
+#### Make sure that both files are saved to system path which is available for libvirt-qemu:kvm
+export SLAVE_VM_SOURCE_DISK=$(place_file_under_libvirt ${SLAVE_VM_SOURCE_DISK})
+export SLAVE_VM_CONFIG_DISK=$(place_file_under_libvirt ${aioHostname}.${clusterDomain}-config.iso)
+export CREATE_NETWORKS=${CREATE_NETWORKS:-true}
+popd
+
+render_config "${SLAVE_VM_NAME}" "${SLAVE_VM_MEM_KB}" "${SLAVE_VM_CPUS}" "${SLAVE_VM_SOURCE_DISK}" "${SLAVE_VM_CONFIG_DISK}" "${CREATE_NETWORKS}"
+
+virsh define $(pwd)/${SLAVE_VM_NAME}-vm.xml
+virsh autostart ${SLAVE_VM_NAME}
diff --git a/predefine-vm/define-vm.sh b/predefine-vm/define-vm.sh
index 93f05a5..11bff46 100755
--- a/predefine-vm/define-vm.sh
+++ b/predefine-vm/define-vm.sh
@@ -1,189 +1,35 @@
#!/bin/bash -xe
-VM_MGM_BRIDGE_DISABLE=${VM_MGM_BRIDGE_DISABLE:-false}
-VM_CTL_BRIDGE_DISABLE=${VM_CTL_BRIDGE_DISABLE:-false}
-VM_MGM_BRIDGE_NAME=${VM_MGM_BRIDGE_NAME:-"br-mgm"}
-VM_CTL_BRIDGE_NAME=${VM_CTL_BRIDGE_NAME:-"br-ctl"}
-VM_MGM_NETWORK_NAME=${VM_MGM_NETWORK_NAME:-"mgm_network"}
-VM_CTL_NETWORK_NAME=${VM_CTL_NETWORK_NAME:-"ctl_network"}
-VM_MEM_KB=${VM_MEM_KB:-"12589056"}
-VM_CPUS=${VM_CPUS:-"4"}
-# optional params if you won't use bridge on host
-VM_MGM_NETWORK_GATEWAY=${VM_MGM_NETWORK_GATEWAY:-"192.168.56.1"}
-VM_MGM_NETWORK_MASK=${VM_MGM_NETWORK_MASK:-"255.255.255.0"}
-VM_CTL_NETWORK_GATEWAY=${VM_CTL_NETWORK_GATEWAY:-"192.168.57.1"}
-VM_CTL_NETWORK_MASK=${VM_CTL_NETWORK_MASK:-"255.255.255.0"}
+functionsFile="$(pwd)/functions.sh"
+
+if [[ ! -f ${functionsFile} ]]; then
+ echo "ERROR: Can not find 'functions' libfile (${functionsFile}), check your mcp/mcp-common-scripts repo."
+ exit 1
+else
+ source ${functionsFile}
+fi
if [[ -z ${VM_NAME} ]]; then
echo "ERROR: \$VM_NAME not set!"
exit 1
fi
-if [[ ! -f ${VM_SOURCE_DISK} ]] || [[ -z ${VM_SOURCE_DISK} ]]; then
+if [[ -z ${VM_SOURCE_DISK} ]] || [[ ! -f ${VM_SOURCE_DISK} ]]; then
echo "ERROR: \$VM_SOURCE_DISK not set, or file does not exist!"
exit 1
fi
-if [[ ! -f ${VM_CONFIG_DISK} ]] || [[ -z ${VM_CONFIG_DISK} ]]; then
+if [[ -z ${VM_CONFIG_DISK} ]] || [[ ! -f ${VM_CONFIG_DISK} ]]; then
echo "ERROR: \$VM_CONFIG_DISK not set, or file does not exist!"
exit 1
fi
-function check_packages {
- PACKAGES="libvirt-bin qemu-kvm"
- for i in $PACKAGES; do
- dpkg -s $i &> /dev/null || { echo "Package $i is not installed!"; exit 1; }
- done
-}
-
-function create_network {
- local network=${1}
- virsh net-destroy ${network} 2> /dev/null || true
- virsh net-undefine ${network} 2> /dev/null || true
- virsh net-define ${network}.xml
- virsh net-autostart ${network}
- virsh net-start ${network}
-}
-
-function create_bridge_network {
- local network=$1
- local bridge_name=$2
- cat <<EOF > $(pwd)/${network}.xml
-<network>
- <name>${network}</name>
- <forward mode="bridge"/>
- <bridge name="${bridge_name}" />
-</network>
-EOF
- create_network ${network}
-}
-
-function create_host_network {
- local network=$1
- local gateway=$2
- local netmask=$3
- local nat=${4:-false}
- cat <<EOF > $(pwd)/${network}.xml
-<network>
- <name>${network}</name>
- <bridge name="${network}" />
- <ip address="${gateway}" netmask="${netmask}"/>
-EOF
- if [[ "${nat}" =~ [Tt]rue ]]; then
- cat <<EOF>> $(pwd)/${network}.xml
- <forward mode="nat"/>
-EOF
- fi
- cat <<EOF>> $(pwd)/${network}.xml
-</network>
-EOF
- create_network ${network}
-}
-
check_packages
-# Template definition
-cat <<EOF > $(pwd)/${VM_NAME}-vm.xml
-<domain type='kvm'>
- <name>$VM_NAME</name>
- <memory unit='KiB'>$VM_MEM_KB</memory>
- <currentMemory unit='KiB'>$VM_MEM_KB</currentMemory>
- <vcpu placement='static'>$VM_CPUS</vcpu>
- <resource>
- <partition>/machine</partition>
- </resource>
- <os>
- <type >hvm</type>
- <boot dev='hd'/>
- </os>
- <features>
- <acpi/>
- </features>
- <clock offset='utc'>
- <timer name='rtc' tickpolicy='catchup'/>
- <timer name='pit' tickpolicy='delay'/>
- <timer name='hpet' present='no'/>
- </clock>
- <pm>
- <suspend-to-mem enabled='no'/>
- <suspend-to-disk enabled='no'/>
- </pm>
- <devices>
- <emulator>/usr/bin/kvm-spice</emulator>
- <disk type='file' device='disk'>
- <driver name='qemu' type='qcow2' cache='none'/>
- <source file='$VM_SOURCE_DISK'/>
- <target dev='vda' bus='virtio'/>
- <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
- </disk>
- <disk type='file' device='cdrom'>
- <driver name='qemu' type='raw'/>
- <source file='$VM_CONFIG_DISK'/>
- <backingStore/>
- <target dev='hda' bus='ide'/>
- <readonly/>
- <address type='drive' controller='0' bus='0' target='0' unit='0'/>
- </disk>
-EOF
-if [[ "${VM_MGM_BRIDGE_DISABLE}" =~ [Ff]alse ]]; then
- create_bridge_network "${VM_MGM_NETWORK_NAME}" "${VM_MGM_BRIDGE_NAME}"
- cat <<EOF >> $(pwd)/${VM_NAME}-vm.xml
- <interface type='bridge'>
- <source bridge='$VM_MGM_BRIDGE_NAME'/>
- <model type='virtio'/>
- <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
- </interface>
-EOF
-else
- create_host_network "${VM_MGM_NETWORK_NAME}" "${VM_MGM_NETWORK_GATEWAY}" "${VM_MGM_NETWORK_MASK}" true
- cat <<EOF >> $(pwd)/${VM_NAME}-vm.xml
- <interface type='network'>
- <source network='$VM_MGM_NETWORK_NAME'/>
- <model type='virtio'/>
- <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
- </interface>
-EOF
-fi
+#### Make sure that both files are saved to system path which is available for libvirt-qemu:kvm
+export VM_SOURCE_DISK=$(place_file_under_libvirt ${VM_SOURCE_DISK})
+export VM_CONFIG_DISK=$(place_file_under_libvirt ${VM_CONFIG_DISK})
+export CREATE_NETWORKS=${CREATE_NETWORKS:-true}
-if [[ "${VM_MGM_BRIDGE_DISABLE}" =~ [Ff]alse ]]; then
- create_bridge_network "${VM_CTL_NETWORK_NAME}" "${VM_CTL_BRIDGE_NAME}"
- cat <<EOF >> $(pwd)/${VM_NAME}-vm.xml
- <interface type='bridge'>
- <source bridge='$VM_CTL_BRIDGE_NAME'/>
- <model type='virtio'/>
- <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
- </interface>
-EOF
-else
- create_host_network "${VM_CTL_NETWORK_NAME}" "${VM_CTL_NETWORK_GATEWAY}" "${VM_CTL_NETWORK_MASK}"
- cat <<EOF >> $(pwd)/${VM_NAME}-vm.xml
- <interface type='network'>
- <source network='$VM_CTL_NETWORK_NAME'/>
- <model type='virtio'/>
- <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
- </interface>
-EOF
-fi
-
-cat <<EOF >> $(pwd)/${VM_NAME}-vm.xml
- <serial type='pty'>
- <source path='/dev/pts/1'/>
- <target port='0'/>
- </serial>
- <console type='pty' tty='/dev/pts/1'>
- <source path='/dev/pts/1'/>
- <target type='serial' port='0'/>
- </console>
- <graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1'>
- <listen type='address' address='127.0.0.1'/>
- </graphics>
- <rng model='virtio'>
- <backend model='random'>/dev/random</backend>
- </rng>
- </devices>
-</domain>
-EOF
-
-echo "INFO: rendered VM config:"
-cat $(pwd)/${VM_NAME}-vm.xml
+render_config "${VM_NAME}" "${VM_MEM_KB}" "${VM_CPUS}" "${VM_SOURCE_DISK}" "${VM_CONFIG_DISK}" "${CREATE_NETWORKS}"
virsh define $(pwd)/${VM_NAME}-vm.xml
virsh autostart ${VM_NAME}
diff --git a/predefine-vm/env_vars.sh b/predefine-vm/env_vars.sh
new file mode 100644
index 0000000..38141a9
--- /dev/null
+++ b/predefine-vm/env_vars.sh
@@ -0,0 +1,17 @@
+export VM_MGM_BRIDGE_DISABLE=${VM_MGM_BRIDGE_DISABLE:-false}
+export VM_CTL_BRIDGE_DISABLE=${VM_CTL_BRIDGE_DISABLE:-false}
+export VM_MGM_BRIDGE_NAME=${VM_MGM_BRIDGE_NAME:-"br-mgm"}
+export VM_CTL_BRIDGE_NAME=${VM_CTL_BRIDGE_NAME:-"br-ctl"}
+export VM_MGM_NETWORK_NAME=${VM_MGM_NETWORK_NAME:-"mgm_network"}
+export VM_CTL_NETWORK_NAME=${VM_CTL_NETWORK_NAME:-"ctl_network"}
+export VM_MEM_KB=${VM_MEM_KB:-"12589056"}
+export VM_CPUS=${VM_CPUS:-"4"}
+# optional params if you won't use bridge on host
+export VM_MGM_NETWORK_GATEWAY=${VM_MGM_NETWORK_GATEWAY:-"192.168.56.1"}
+export VM_MGM_NETWORK_MASK=${VM_MGM_NETWORK_MASK:-"255.255.255.0"}
+export VM_CTL_NETWORK_GATEWAY=${VM_CTL_NETWORK_GATEWAY:-"192.168.57.1"}
+export VM_CTL_NETWORK_MASK=${VM_CTL_NETWORK_MASK:-"255.255.255.0"}
+# optional params if you want enable slave vm
+export SLAVE_VM_MEM_KB=${SLAVE_VM_MEM_KB:-"16777216"}
+export SLAVE_VM_CPUS=${SLAVE_VM_CPUS:-"4"}
+export SLAVE_VM_DISK_SIZE=${SLAVE_VM_DISK_SIZE:-"50G"}
\ No newline at end of file
diff --git a/predefine-vm/functions.sh b/predefine-vm/functions.sh
new file mode 100644
index 0000000..eb8b733
--- /dev/null
+++ b/predefine-vm/functions.sh
@@ -0,0 +1,191 @@
+#!/bin/bash
+
+envFile="$(pwd)/env_vars.sh"
+if [[ ! -f ${envFile} ]]; then
+ echo "ERROR: Can not find 'env_vars' libfile (${envFile}), check your mcp/mcp-common-scripts repo."
+ exit 1
+else
+ source ${envFile}
+fi
+
+function check_packages {
+ local slave=$1
+ local packages="libvirt-bin qemu-kvm"
+ if [[ -n "${slave}" ]]; then
+ packages="${packages} qemu-utils python-ipaddress mkisofs"
+ fi
+ for i in $packages; do
+ dpkg -s $i &> /dev/null || { echo "Package $i is not installed!"; exit 1; }
+ done
+}
+
+function create_network {
+ local network=${1}
+ virsh net-destroy ${network} 2> /dev/null || true
+ virsh net-undefine ${network} 2> /dev/null || true
+ virsh net-define ${network}.xml
+ virsh net-autostart ${network}
+ virsh net-start ${network}
+}
+
+function create_bridge_network {
+ local network=$1
+ local bridge_name=$2
+ cat <<EOF > $(pwd)/${network}.xml
+<network>
+ <name>${network}</name>
+ <forward mode="bridge"/>
+ <bridge name="${bridge_name}" />
+</network>
+EOF
+ create_network ${network}
+}
+
+function create_host_network {
+ local network=$1
+ local gateway=$2
+ local netmask=$3
+ local nat=${4:-false}
+ cat <<EOF > $(pwd)/${network}.xml
+<network>
+ <name>${network}</name>
+ <bridge name="${network}" />
+ <ip address="${gateway}" netmask="${netmask}"/>
+EOF
+ if [[ "${nat}" =~ [Tt]rue ]]; then
+ cat <<EOF>> $(pwd)/${network}.xml
+ <forward mode="nat"/>
+EOF
+ fi
+ cat <<EOF>> $(pwd)/${network}.xml
+</network>
+EOF
+ create_network ${network}
+}
+
+function place_file_under_libvirt() {
+ local libvirtPath="/var/lib/libvirt/images"
+ local image=${1}
+ local basenameFile=$(basename ${image})
+ cp "${image}" "${libvirtPath}/${basenameFile}"
+ chown -R libvirt-qemu:kvm "${libvirtPath}"
+ echo "${libvirtPath}/${basenameFile}"
+}
+
+function render_config() {
+ local vmName=$1
+ local vmMemKB=$2
+ local vmCPUs=$3
+ local vmSourceDisk=$4
+ local vmConfigDisk=$5
+ local createNetworks=${6:-true}
+ # Template definition
+ cat <<EOF > $(pwd)/${vmName}-vm.xml
+<domain type='kvm'>
+ <name>$vmName</name>
+ <memory unit='KiB'>$vmMemKB</memory>
+ <currentMemory unit='KiB'>$vmMemKB</currentMemory>
+ <vcpu placement='static'>$vmCPUs</vcpu>
+ <resource>
+ <partition>/machine</partition>
+ </resource>
+ <os>
+ <type >hvm</type>
+ <boot dev='hd'/>
+ </os>
+ <features>
+ <acpi/>
+ </features>
+ <clock offset='utc'>
+ <timer name='rtc' tickpolicy='catchup'/>
+ <timer name='pit' tickpolicy='delay'/>
+ <timer name='hpet' present='no'/>
+ </clock>
+ <pm>
+ <suspend-to-mem enabled='no'/>
+ <suspend-to-disk enabled='no'/>
+ </pm>
+ <devices>
+ <emulator>/usr/bin/kvm-spice</emulator>
+ <disk type='file' device='disk'>
+ <driver name='qemu' type='qcow2' cache='none'/>
+ <source file='$vmSourceDisk'/>
+ <target dev='vda' bus='virtio'/>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
+ </disk>
+EOF
+ if [[ -n "${vmConfigDisk}" ]]; then
+ cat <<EOF >> $(pwd)/${vmName}-vm.xml
+ <disk type='file' device='cdrom'>
+ <driver name='qemu' type='raw'/>
+ <source file='$vmConfigDisk'/>
+ <backingStore/>
+ <target dev='hda' bus='ide'/>
+ <readonly/>
+ <address type='drive' controller='0' bus='0' target='0' unit='0'/>
+ </disk>
+EOF
+ fi
+
+ if [[ "${VM_MGM_BRIDGE_DISABLE}" =~ [Ff]alse ]]; then
+ [[ "${createNetworks}" =~ [Tt]rue ]] && create_bridge_network "${VM_MGM_NETWORK_NAME}" "${VM_MGM_BRIDGE_NAME}"
+ cat <<EOF >> $(pwd)/${vmName}-vm.xml
+ <interface type='bridge'>
+ <source bridge='$VM_MGM_BRIDGE_NAME'/>
+ <model type='virtio'/>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
+ </interface>
+EOF
+ else
+ [[ "${createNetworks}" =~ [Tt]rue ]] && create_host_network "${VM_MGM_NETWORK_NAME}" "${VM_MGM_NETWORK_GATEWAY}" "${VM_MGM_NETWORK_MASK}" true
+ cat <<EOF >> $(pwd)/${vmName}-vm.xml
+ <interface type='network'>
+ <source network='$VM_MGM_NETWORK_NAME'/>
+ <model type='virtio'/>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
+ </interface>
+EOF
+fi
+
+ if [[ "${VM_MGM_BRIDGE_DISABLE}" =~ [Ff]alse ]]; then
+ [[ "${createNetworks}" =~ [Tt]rue ]] && create_bridge_network "${VM_CTL_NETWORK_NAME}" "${VM_CTL_BRIDGE_NAME}"
+ cat <<EOF >> $(pwd)/${vmName}-vm.xml
+ <interface type='bridge'>
+ <source bridge='$VM_CTL_BRIDGE_NAME'/>
+ <model type='virtio'/>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
+ </interface>
+EOF
+ else
+ [[ "${createNetworks}" =~ [Tt]rue ]] && create_host_network "${VM_CTL_NETWORK_NAME}" "${VM_CTL_NETWORK_GATEWAY}" "${VM_CTL_NETWORK_MASK}"
+ cat <<EOF >> $(pwd)/${vmName}-vm.xml
+ <interface type='network'>
+ <source network='$VM_CTL_NETWORK_NAME'/>
+ <model type='virtio'/>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
+ </interface>
+EOF
+fi
+
+ cat <<EOF >> $(pwd)/${vmName}-vm.xml
+ <serial type='pty'>
+ <source path='/dev/pts/1'/>
+ <target port='0'/>
+ </serial>
+ <console type='pty' tty='/dev/pts/1'>
+ <source path='/dev/pts/1'/>
+ <target type='serial' port='0'/>
+ </console>
+ <graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1'>
+ <listen type='address' address='127.0.0.1'/>
+ </graphics>
+ <rng model='virtio'>
+ <backend model='random'>/dev/random</backend>
+ </rng>
+ </devices>
+</domain>
+EOF
+
+ echo "INFO: rendered VM config:"
+ cat $(pwd)/${vmName}-vm.xml
+}
\ No newline at end of file