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
7
container_ips.json
Normal file
7
container_ips.json
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
{
|
||||||
|
"arma-reforger-tofu": "201:61dd:8232:55d9:f6ee:2594:d661:b202",
|
||||||
|
"base-tofu": "200:d642:9eee:8f38:d9f3:8272:817d:75da",
|
||||||
|
"forgejo-runner-tofu": "201:ea26:66c7:657b:3599:63a6:c66c:d388",
|
||||||
|
"observer-tofu": "200:b938:d405:92df:a6e:1ffd:5213:26b",
|
||||||
|
"tofu": "200:1978:6503:e6f0:2dbe:11fd:74b:ff64"
|
||||||
|
}
|
||||||
|
|
@ -1,11 +1,17 @@
|
||||||
{
|
{
|
||||||
perSystem =
|
perSystem =
|
||||||
{ pkgs, ... }:
|
{
|
||||||
|
self',
|
||||||
|
pkgs,
|
||||||
|
system,
|
||||||
|
...
|
||||||
|
}:
|
||||||
{
|
{
|
||||||
devShells.default = pkgs.mkShell {
|
devShells.default = pkgs.mkShell {
|
||||||
name = "nixos-unified-template-shell";
|
name = "nixos-unified-template-shell";
|
||||||
meta.description = "Shell environment for modifying this Nix configuration";
|
meta.description = "Shell environment for modifying this Nix configuration";
|
||||||
packages = with pkgs; [
|
packages = with pkgs; [
|
||||||
|
self'.packages.ip-gather
|
||||||
openssh
|
openssh
|
||||||
deploy-rs
|
deploy-rs
|
||||||
ssh-to-age
|
ssh-to-age
|
||||||
|
|
|
||||||
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