feature: added ip-gather command for improved workflow
This commit is contained in:
parent
5b91c9f3f5
commit
2802db394f
3 changed files with 50 additions and 1 deletions
36
packages/ip-gather/default.nix
Normal file
36
packages/ip-gather/default.nix
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
# incus-ip-collector.nix
|
||||
{
|
||||
writeShellScriptBin,
|
||||
}:
|
||||
|
||||
writeShellScriptBin "ip-gather" ''
|
||||
set -euo pipefail
|
||||
|
||||
remote_host="''${1:-"administrator@olympus"}"
|
||||
output_file="''${2:-container_ips.json}"
|
||||
|
||||
generate_json() {
|
||||
echo "{"
|
||||
first=true
|
||||
for c in $(incus list --format csv -c n | awk '!/NAME/ {print $1}'); do
|
||||
ip=$(incus exec "$c" -- ip -6 addr show dev ygg0 2>/dev/null | awk '/inet6/ {print $2}' | cut -d/ -f1 | grep -v '^fe80' | head -n1)
|
||||
if [ -n "$ip" ]; then
|
||||
[ "$first" = false ] && echo ","
|
||||
echo -n " \"$c\": \"$ip\""
|
||||
first=false
|
||||
fi
|
||||
done
|
||||
echo ""
|
||||
echo "}"
|
||||
}
|
||||
|
||||
if [ -n "''${remote_host}" ]; then
|
||||
# Execute remotely and save to local file
|
||||
ssh "$remote_host" "$(declare -f generate_json); generate_json" > "$output_file"
|
||||
else
|
||||
# Execute locally and save to file
|
||||
generate_json > "$output_file"
|
||||
fi
|
||||
|
||||
echo "Container IPs saved to: $output_file"
|
||||
''
|
||||
Loading…
Add table
Add a link
Reference in a new issue