dustin
/
zdotdir
Archived
1
0
Fork 0

functions: Add test vm functions

* `@testvm::cleanup`: Deletes (after optionally powering off) test VMs
  matching a pattern
* `@testvm::connect`: Connects to test VM using SSH
* `@testvm::delete`: Powers off and deletes a specific test VM
* `@testvm::sftp`: Connects to a test VM using SFTP
master
Dustin 2020-03-25 10:50:43 -05:00
parent d9d559c327
commit e120838f8a
5 changed files with 75 additions and 0 deletions

View File

@ -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 "$@"

View File

@ -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 "$@"

View File

@ -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 "$@"

17
functions/@testvm::sftp Normal file
View File

@ -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 "$@"

1
functions/@vmname Normal file
View File

@ -0,0 +1 @@
printf 'fmos-%08x\n' $(od -An -tu -N4 /dev/urandom)