alexz | 1c02cd6 | 2018-04-15 22:18:03 +0200 | [diff] [blame] | 1 | #!/bin/bash -xe |
| 2 | |
Denis Egorenko | c265640 | 2019-04-19 18:17:50 +0400 | [diff] [blame] | 3 | functionsFile="$(pwd)/functions.sh" |
| 4 | |
| 5 | if [[ ! -f ${functionsFile} ]]; then |
| 6 | echo "ERROR: Can not find 'functions' libfile (${functionsFile}), check your mcp/mcp-common-scripts repo." |
| 7 | exit 1 |
| 8 | else |
| 9 | source ${functionsFile} |
| 10 | fi |
alexz | 1c02cd6 | 2018-04-15 22:18:03 +0200 | [diff] [blame] | 11 | |
| 12 | if [[ -z ${VM_NAME} ]]; then |
| 13 | echo "ERROR: \$VM_NAME not set!" |
| 14 | exit 1 |
| 15 | fi |
Denis Egorenko | c265640 | 2019-04-19 18:17:50 +0400 | [diff] [blame] | 16 | if [[ -z ${VM_SOURCE_DISK} ]] || [[ ! -f ${VM_SOURCE_DISK} ]]; then |
alexz | 1c02cd6 | 2018-04-15 22:18:03 +0200 | [diff] [blame] | 17 | echo "ERROR: \$VM_SOURCE_DISK not set, or file does not exist!" |
| 18 | exit 1 |
| 19 | fi |
Denis Egorenko | c265640 | 2019-04-19 18:17:50 +0400 | [diff] [blame] | 20 | if [[ -z ${VM_CONFIG_DISK} ]] || [[ ! -f ${VM_CONFIG_DISK} ]]; then |
alexz | 1c02cd6 | 2018-04-15 22:18:03 +0200 | [diff] [blame] | 21 | echo "ERROR: \$VM_CONFIG_DISK not set, or file does not exist!" |
| 22 | exit 1 |
| 23 | fi |
| 24 | |
Denis Egorenko | dcc233d | 2019-03-06 18:09:24 +0400 | [diff] [blame] | 25 | check_packages |
| 26 | |
Denis Egorenko | c265640 | 2019-04-19 18:17:50 +0400 | [diff] [blame] | 27 | #### Make sure that both files are saved to system path which is available for libvirt-qemu:kvm |
| 28 | export VM_SOURCE_DISK=$(place_file_under_libvirt ${VM_SOURCE_DISK}) |
| 29 | export VM_CONFIG_DISK=$(place_file_under_libvirt ${VM_CONFIG_DISK}) |
| 30 | export CREATE_NETWORKS=${CREATE_NETWORKS:-true} |
Denis Egorenko | dcc233d | 2019-03-06 18:09:24 +0400 | [diff] [blame] | 31 | |
Denis Egorenko | c265640 | 2019-04-19 18:17:50 +0400 | [diff] [blame] | 32 | render_config "${VM_NAME}" "${VM_MEM_KB}" "${VM_CPUS}" "${VM_SOURCE_DISK}" "${VM_CONFIG_DISK}" "${CREATE_NETWORKS}" |
alexz | 1c02cd6 | 2018-04-15 22:18:03 +0200 | [diff] [blame] | 33 | |
| 34 | virsh define $(pwd)/${VM_NAME}-vm.xml |
| 35 | virsh autostart ${VM_NAME} |