|
|
@ -24,11 +24,31 @@ function lookup { |
|
|
function list { |
|
|
function list { |
|
|
containers=$(lxc-ls "$CONTAINER_NAME") |
|
|
containers=$(lxc-ls "$CONTAINER_NAME") |
|
|
for id in $containers; do |
|
|
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) |
|
|
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" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
info=$(lxc-info -si $id) |
|
|
|
|
|
state=($(lxc-info "$id" | grep ^State:)) && state="${state[1]}" # get an array, then take the second element |
|
|
|
|
|
|
|
|
|
|
|
ips_input=($(echo "$info" | grep '^IP:')) || ips_input=() |
|
|
|
|
|
ips_result=() |
|
|
|
|
|
[[ ${#ips_input[@]} -gt 1 ]] && transform_array_to_odd_values_only ips_input ips_result |
|
|
|
|
|
|
|
|
|
|
|
# convert array to string joined by ',' |
|
|
|
|
|
ips_result=$( |
|
|
|
|
|
IFS="," |
|
|
|
|
|
builtin echo "${ips_result[*]}" |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
printf '%-5s %-30s %s %s\n' "$id" "$hostname" "$state" "$ips_result" |
|
|
|
|
|
done |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function transform_array_to_odd_values_only { |
|
|
|
|
|
local -n input=$1 |
|
|
|
|
|
local -n output=$2 |
|
|
|
|
|
|
|
|
|
|
|
for i in "${!input[@]}"; do |
|
|
|
|
|
((i % 2 == 1)) && output+=("${input[$i]}") |
|
|
done |
|
|
done |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|