summaryrefslogtreecommitdiff
path: root/.local/bin/stop-vm
blob: 6c922507e94563a5b76f28635d9e668c213bc4c1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/bin/sh
# Stops domains given as arguments

opts=$(getopt -o 'as' -l 'all,save' -- "$@")
eval set -- "$opts"
all=0
save=0
while true
do
	case $1 in
		'-a'|'--all') all=1; shift; continue ;;
		'-s'|'--save') save=1; shift; continue ;;
		'--') shift; break;;
	esac
done

[ $all -eq 1 ] && domains="$(virsh list | grep running | awk '{print $2}')" || domains="$@"
for domain in $domains
do
	[ $save -eq 1 ] && virsh managedsave $domain || virsh shutdown $domain
done