mirror of
https://github.com/flynx/proxmox-utils.git
synced 2026-01-09 04:01:24 +00:00
cleanup and notes...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
1dd4741737
commit
2c52251ff7
81
.pct-helpers
81
.pct-helpers
@ -4,6 +4,7 @@
|
|||||||
CT_DIR=${CT_DIR:=/etc/pve/lxc/}
|
CT_DIR=${CT_DIR:=/etc/pve/lxc/}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
# XXX this is quite generic, might be a good idea to move this to a
|
# XXX this is quite generic, might be a good idea to move this to a
|
||||||
# seporate lib/file...
|
# 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(){ (
|
fillsection(){ (
|
||||||
usage(){
|
usage(){
|
||||||
echo "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 :
|
# vim:set ts=4 sw=4 nowrap :
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user