diff --git a/Makefile b/Makefile index 7422eb1..ee548ab 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,8 @@ .PHONY: \ all \ clean \ - publish + publish \ + vm .DEFAULT_GOAL := all @@ -26,3 +27,7 @@ $(foreach t,$(wildcard *.yaml),$(eval $(call genrules,$(t)))) publish: \ nvr1.ign rsync -rti $^ files.pyrocufflink.blue:public_html/ + +vm: \ + $(VMNAME).ign + sh mkvm.sh $(VMNAME) diff --git a/mkvm.sh b/mkvm.sh new file mode 100644 index 0000000..124c456 --- /dev/null +++ b/mkvm.sh @@ -0,0 +1,39 @@ +#!/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 +