ignition/mkvm.sh

40 lines
915 B
Bash

#!/bin/sh
# vim: set sw=4 ts=4 sts=4 et :
: "${POOL:=default}"
: "${VCPUS:=2}"
: "${MEMORY:=2048}"
: "${DISK_SIZE:=10}"
: "${NETWORK=network=prod}"
VMNAME="$1"
pooldir=$(virsh pool-dumpxml "${POOL}" | xmllint --xpath '//path/text()' -)
vmhost=$(virsh uri | cut -d/ -f3)
ign="${pooldir}/${VMNAME}.ign"
if [ -n "${vmhost}" ]; then
scp -s "${VMNAME}".ign "${vmhost}:${ign}"
else
cp "${VMNAME}".ign "${ign}"
fi
image=$(virsh vol-list "${POOL}" \
| awk '/fedora-coreos-.*-qemu/{print $2}' \
| sort -V \
| tail -n1)
virt-install \
--name "${VMNAME}" \
--vcpus "${VCPUS}" \
--memory "${MEMORY}" \
--os-variant fedora-coreos-stable \
--graphics none \
--sound none \
--disk size="${DISK_SIZE},backing_store=${image}" \
${DISK:+--disk "${DISK}"} \
--network "${NETWORK}" \
--qemu-commandline="--fw_cfg name=opt/com.coreos/config,file=${ign}" \
--import