You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
950 B
39 lines
950 B
#!/usr/bin/env bash
|
|
|
|
# CONSTANTS
|
|
|
|
CONTAINER_NAME=$1
|
|
|
|
# FUNCTIONS
|
|
|
|
function usage {
|
|
echo "$(basename "$0") [CONTAINER_NAME]"
|
|
}
|
|
|
|
function lookup {
|
|
cmd="pvesh get /cluster/resources --type vm --output=json | jq --raw-output '.[] | \"\(.name) \(.vmid)\"'"
|
|
if [[ $CONTAINER_NAME == "--all" ]]; then
|
|
eval "$cmd"
|
|
else
|
|
cmd="$cmd | egrep '^$CONTAINER_NAME '"
|
|
found=$(eval "$cmd") || (echo >&2 "ERROR: container <$CONTAINER_NAME> not found!" && exit 10)
|
|
echo "$found" | cut -d' ' -f2
|
|
fi
|
|
}
|
|
|
|
function list {
|
|
containers=$(lxc-ls "$CONTAINER_NAME")
|
|
for id in $containers; do
|
|
info=$(lxc-info -si $id)
|
|
state=$(echo "$info" | grep '^State:') && state="${state:15}" # remove 15 leading chars
|
|
hostname=$(grep -m1 hostname: "/etc/pve/lxc/$id.conf" | cut -d' ' -f2)
|
|
ip=$(echo "$info" | grep '^IP:') && ip="${ip:15}"
|
|
printf '%-5s %-30s %s %s\n' "$id" "$hostname" "$state" "$ip"
|
|
done
|
|
}
|
|
|
|
# MAIN
|
|
|
|
set -Eue
|
|
# [[ "$#" -lt 1 ]] && usage && exit 1
|
|
list
|