root / plugins / lxc / lxc-lib @ 3e865223
Historique | Voir | Annoter | Télécharger (1,13 ko)
| 1 |
: << =cut |
|---|---|
| 2 |
|
| 3 |
=head1 NAME |
| 4 |
|
| 5 |
lxc-lib -- some base functions for the lxc_* plugins |
| 6 |
|
| 7 |
=head1 AUTHOR |
| 8 |
|
| 9 |
schaefer@alphanet.ch |
| 10 |
|
| 11 |
=head1 LICENSE |
| 12 |
|
| 13 |
GPLv3 |
| 14 |
|
| 15 |
=cut |
| 16 |
|
| 17 |
lxcpath=${lxcpath:-/var/lib/lxc}
|
| 18 |
|
| 19 |
function active_guests {
|
| 20 |
local g active i ok |
| 21 |
for g in $(lxc-ls | sort -u) |
| 22 |
do |
| 23 |
# handle optional exclude list in $1 |
| 24 |
ok=1 |
| 25 |
for i in $1 |
| 26 |
do |
| 27 |
if [ "$i" = "$g" ]; then |
| 28 |
ok=0 |
| 29 |
fi |
| 30 |
done |
| 31 |
|
| 32 |
if [ $ok = 1 ]; then |
| 33 |
if lxc-info -n $g 2>&1 | grep -qs RUNNING; then |
| 34 |
active="$active $g" |
| 35 |
fi |
| 36 |
fi |
| 37 |
done |
| 38 |
|
| 39 |
echo $active |
| 40 |
} |
| 41 |
|
| 42 |
function lxc_cgroup {
|
| 43 |
# lxc3 |
| 44 |
lxc-cgroup -o /dev/stdout -l INFO $* | sed 's/^.*lxc_cgroup.c:main:[0-9][0-9]* - //' |
| 45 |
|
| 46 |
# lxc < 3 |
| 47 |
# lxc-cgroup $* |
| 48 |
} |
| 49 |
|
| 50 |
function lxc_clean_fieldname {
|
| 51 |
# workaround for bug leaving out the first number |
| 52 |
echo $(clean_fieldname ${1::1}$1)
|
| 53 |
} |
| 54 |
|
| 55 |
function lxc_netdev {
|
| 56 |
local g=$1 dev |
| 57 |
|
| 58 |
if [ -f $lxcpath/$g/config ]; then |
| 59 |
# lxc3 |
| 60 |
egrep '^lxc.net.0.veth.pair' $lxcpath/$g/config | awk '{print $NF;}'
|
| 61 |
|
| 62 |
# lxc < 3 |
| 63 |
# egrep '^lxc.network.veth.pair' $lxcpath/$g/config | awk '{print $NF;}'
|
| 64 |
else |
| 65 |
echo unknown |
| 66 |
fi |
| 67 |
} |
