cleanup and notes...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2023-07-05 22:40:29 +03:00
parent 1dd4741737
commit 2c52251ff7

View File

@ -4,6 +4,7 @@
CT_DIR=${CT_DIR:=/etc/pve/lxc/}
#----------------------------------------------------------------------
# XXX this is quite generic, might be a good idea to move this to a
# seporate lib/file...
@ -21,45 +22,12 @@ CT_DIR=${CT_DIR:=/etc/pve/lxc/}
}
#----------------------------------------------------------------------
# CT hostname <-> id...
ct2hostname(){
local ct=${CT_DIR}/${1}.conf
local host=$(cat $ct | grep hostname | head -1)
echo ${host/hostname: /}
}
hostname2ct(){
if [ -e "${CT_DIR}/${1}.conf" ] ; then
echo $1
fi
local running=$2
running=${running:=any}
local ct
local host
for ct in "${CT_DIR}"/*.conf ; do
host=$(cat $ct | grep hostname | head -1)
host=${host/hostname: /}
if [ "$host" = $1 ] ; then
ct=${ct#${CT_DIR}}
ct=${ct%.conf}
ct=${ct#\/}
# filter results if needed...
if [ $running = "any" ] ; then
echo $ct
else
local status=`pct status $ct`
if [ "$running" = "${status/status: /}" ] ; then
echo $ct
fi
fi
fi
done
}
#----------------------------------------------------------------------
# Fill section...
#
# XXX this is quite generic...
fillsection(){ (
usage(){
echo "Usage:"
@ -115,5 +83,44 @@ fillsection(){ (
) }
#----------------------------------------------------------------------
# CT hostname <-> CT id...
ct2hostname(){
local ct=${CT_DIR}/${1}.conf
local host=$(cat $ct | grep hostname | head -1)
echo ${host/hostname: /}
}
hostname2ct(){
if [ -e "${CT_DIR}/${1}.conf" ] ; then
echo $1
fi
local running=$2
running=${running:=any}
local ct
local host
for ct in "${CT_DIR}"/*.conf ; do
host=$(cat $ct | grep hostname | head -1)
host=${host/hostname: /}
if [ "$host" = $1 ] ; then
ct=${ct#${CT_DIR}}
ct=${ct%.conf}
ct=${ct#\/}
# filter results if needed...
if [ $running = "any" ] ; then
echo $ct
else
local status=`pct status $ct`
if [ "$running" = "${status/status: /}" ] ; then
echo $ct
fi
fi
fi
done
}
#----------------------------------------------------------------------
# vim:set ts=4 sw=4 nowrap :