nutools/lib/ulib/virsh

41 lines
1.1 KiB
Bash

##@cooked comments # -*- coding: utf-8 mode: sh -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8
## Fonction de support pour virsh
##@cooked nocomments
uprovide virsh
function virsh_filter() {
# filtrer une sortie liste de virsh. En pratique, ne prendre que les lignes
# non vides à partir de la ligne "----*"
awk '
BEGIN { dump = 0 }
/^---/ { dump = 1; next }
dump && $0 != "" { print }
'
}
function virsh_list() {
virsh list "$@" | virsh_filter
}
function virsh_pool_list() {
virsh pool-list "$@" | virsh_filter
}
function guess_vm_type() {
# Afficher hn, kvm, vmware, virtualbox ou openvz suivant que l'on est
# *probablement* respectivement sur une machine physique, une machine
# virtuelle kvm, vmware, virtualbox, openvz
# XXX pour le moment, seuls openvz, kvm et hn sont supportés
local ctid="$(grep envID /proc/self/status | awk '{print $2}')"
if [ -n "$ctid" -a "$ctid" != "0" ]; then
echo openvz
return 0
fi
local cpuid="$(grep 'model name' /proc/cpuinfo)"
if quietgrep QEMU <<<"$cpuid"; then
echo kvm
else
echo hn
fi
}