#!/bin/bash # Mostly this just copies the below XML, but inserting random MAC address # and UUID strings, and other options as appropriate. SCRIPT_ROOT=$(readlink -f $(dirname "$0")/..) . "${SCRIPT_ROOT}/common.sh" || exit 1 DEFINE_string vm_name "CoreOS" "Name for this VM" DEFINE_string disk_image "" "Disk image to reference." DEFINE_integer memory_size 1024 "Memory size in MB" DEFINE_string output_pvs "" "Path to write pvs file to, required." DEFINE_boolean template ${FLAGS_FALSE} "Whether this vm is a template." # Parse command line FLAGS "$@" || exit 1 eval set -- "${FLAGS_ARGV}" # Die on any errors. switch_to_strict_mode if [[ ! -d "${FLAGS_disk_image}" ]]; then echo "No such disk image '${FLAGS_disk_image}'" >&2 exit 1 fi snapshot_image=$(find "${FLAGS_disk_image}" -name '*.hds') DISK_UUID=$(uuidgen) DISK_NAME=$(basename "${FLAGS_disk_image}") DISK_VIRTUAL_SIZE_BYTES=$(qemu-img info -f parallels --output json \ "${snapshot_image}" | jq --raw-output '.["virtual-size"]') DISK_ACTUAL_SIZE_BYTES=$(du --bytes "${snapshot_image}" | cut -f1) if [[ -z "${DISK_VIRTUAL_SIZE_BYTES}" ]]; then echo "Unable to determine virtual size of '${snapshot_image}'" >&2 exit 1 fi PARALLELS_MAC_PREFIX=001C42 macgen() { hexdump -n3 -e "\"${PARALLELS_MAC_PREFIX}%06X\n\"" /dev/urandom } datep() { date -u "+%Y-%m-%d %H:%M:%S" } template=0 if [ ${FLAGS_template} -eq ${FLAGS_TRUE} ]; then template=1 fi cat >"${FLAGS_output_pvs}" < 10.3.0-29227 0 {$(uuidgen)} {$(uuidgen)} ${FLAGS_vm_name} {0ba0dd3e-d0bf-420c-a0b2-b83cb4d885c1} 1 $(datep) $(datep) 0 1336536201 0 0 0 1 9 2309 ${template} 0 0 0 0 0 0 0 0 0 0 6 1 1 0 5 2 0 0 15 3 0 0 8 4 0 0 0 0 1 2 0 0 1 1 4 0 1 0 0 0 0 0 0 1 1 0 0 0 1 1 0 0 0 1 1 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1752-01-01 00:00:00 1752-01-01 00:00:00 0 0.0.0.0 0 0 0 1 0 1 0 0 1 1 0 0 0 0 0 1 0 0 1 0 0 1 0 1 0 0 1 1 1 0 1 1 0 0 0 1 0 0 1 0 1 1 1 1 1 1 1 0 0 0 2 1 1 1 0 0 0 0 0 0 1 1 0 0 1 0 0 0 0 0 0 1 60 0 0 0.8 1 1 1 0 0 0 0 0 0 1 0 0 0 0 0 86400 10 2 1 0 86400 50 0 0 0 0 0 0 1752-01-01 00:00:00 https://parallels.com 1800 864000 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 0 0 1 0 2 1 0 0 0 2 0 0 0 1 3 0 ${FLAGS_memory_size} 0 128 4294967295 50 1 70 0 0 0 0 0 2 1 1 0 {$(uuidgen)} 0 1 1 1 ${DISK_NAME} ${DISK_NAME} 0 2 0 1 $((DISK_VIRTUAL_SIZE_BYTES / 1024 / 1024)) $((DISK_ACTUAL_SIZE_BYTES / 1024 / 1024)) 0 0 0 2 level2 0 1 1 1 eth0 eth0 0 -1 Default Adapter $(macgen) $(macgen) 0 2 0 3 0 1 1 1 0 0 0 0 0 0 0 0 EOF