: << =cut =head1 NAME lxc-lib -- some base functions for the lxc_* plugins =head1 AUTHOR schaefer@alphanet.ch =head1 LICENSE GPLv3 =cut lxcpath=${lxcpath:-/var/lib/lxc} function active_guests { local g active i ok for g in $(lxc-ls | sort -u) do # handle optional exclude list in $1 ok=1 for i in $1 do if [ "$i" = "$g" ]; then ok=0 fi done if [ $ok = 1 ]; then if lxc-info -n $g 2>&1 | grep -qs RUNNING; then active="$active $g" fi fi done echo $active } function lxc_cgroup { # lxc3 lxc-cgroup -o /dev/stdout -l INFO $* | sed 's/^.*lxc_cgroup.c:main:[0-9][0-9]* - //' # lxc < 3 # lxc-cgroup $* } function lxc_clean_fieldname { # workaround for bug leaving out the first number echo $(clean_fieldname ${1::1}$1) } function lxc_netdev { local g=$1 dev if [ -f $lxcpath/$g/config ]; then # lxc3 egrep '^lxc.net.0.veth.pair' $lxcpath/$g/config | awk '{print $NF;}' # lxc < 3 # egrep '^lxc.network.veth.pair' $lxcpath/$g/config | awk '{print $NF;}' else echo unknown fi }