diff --git a/functions/@testvm::cleanup b/functions/@testvm::cleanup new file mode 100644 index 0000000..f0a5fb1 --- /dev/null +++ b/functions/@testvm::cleanup @@ -0,0 +1,27 @@ +# vim: set ft=zsh sw=4 ts=4 sts=4 et : + +@testvm::cleanup() { + local destroy=false + local pattern='^fmos-[a-f0-9]{8}$' + while [ $# -gt 0 ]; do + case "$1" in + --destroy) + destroy=true + ;; + *) + pattern="${1}" + ;; + esac + shift + done + if ${destroy}; then + virsh list --name \ + | awk "/${pattern}/{print}" \ + | xargs -r -n1 virsh destroy + fi + virsh list --inactive --name \ + | awk "/${pattern}/{print}" \ + | xargs -r -n1 virsh undefine --remove-all-storage --nvram +} + +@testvm::cleanup "$@" diff --git a/functions/@testvm::connect b/functions/@testvm::connect new file mode 100644 index 0000000..3e5d8c2 --- /dev/null +++ b/functions/@testvm::connect @@ -0,0 +1,22 @@ +# vim: set ft=zsh sw=4 ts=4 sts=4 et : + +@testvm::connect() { + local _term + local testvm_domain=${TESTVM_DOMAIN:-dustin.test} + local testvm="${1}" + shift + if [ -z "${SSHPASS}" ]; then + export SSHPASS='F!r3m0n1' + fi + case ${TERM} in + [Aa]lacritty) + _term=xterm-256color + ;; + esac + if [[ ! "${testvm}" = *.* ]]; then + testvm="${testvm}.${testvm_domain}" + fi + TERM=${_term:-${TERM}} sshpass -e ssh ${testvm} "$@" +} + +@testvm::connect "$@" diff --git a/functions/@testvm::delete b/functions/@testvm::delete new file mode 100644 index 0000000..19b2e9f --- /dev/null +++ b/functions/@testvm::delete @@ -0,0 +1,8 @@ +# vim: set ft=zsh sw=4 ts=4 sts=4 et : + +@testvm::delete() { + virsh destroy "${1}" || : + virsh undefine "${1}" --remove-all-storage --nvram +} + +@testvm::delete "$@" diff --git a/functions/@testvm::sftp b/functions/@testvm::sftp new file mode 100644 index 0000000..b1f9585 --- /dev/null +++ b/functions/@testvm::sftp @@ -0,0 +1,17 @@ +# vim: set ft=zsh sw=4 ts=4 sts=4 et : + +@testvm::sftp() { + local _term + local testvm_domain=${TESTVM_DOMAIN:-dustin.test} + if [ -z "${SSHPASS}" ]; then + export SSHPASS='F!r3m0n1' + fi + case ${TERM} in + Alacritty) + _term=xterm-256color + ;; + esac + TERM=${_term:-${TERM}} sshpass -e sftp ${1}.${testvm_domain}${2:+:${2}} +} + +@testvm::sftp "$@" diff --git a/functions/@vmname b/functions/@vmname new file mode 100644 index 0000000..e678724 --- /dev/null +++ b/functions/@vmname @@ -0,0 +1 @@ +printf 'fmos-%08x\n' $(od -An -tu -N4 /dev/urandom)