[ungleich-tools] create script for VM ID

This commit is contained in:
kjg 2026-07-23 22:51:19 +09:00
commit abc7b5d790

19
k8s/k8s-opennebul-get-vmip.sh Executable file
View file

@ -0,0 +1,19 @@
#!/bin/sh
# get VM_ID via IPv6 address
TARGET="${1:-}"
if [ -z "$TARGET" ]; then
echo "Usage: $0 <IPv6-address only>" >&2
echo "Example: $0 2a0a:e5c0:2:2:0:c8ff:fe68:bee8" >&2
exit 1
fi
POD=$(kubectl -n ungleich get pods \
-l app.kubernetes.io/component=opennebula --output=jsonpath={.items..metadata.name})
IDS=$(kubectl exec -ti $POD -n ungleich -c oned -- /bin/bash -c "onevm list --xml | xmllint --xpath '//VM[TEMPLATE/NIC/IP6_GLOBAL=\"$TARGET\"]/ID/text()' -")
printf 'VM ID: %s\n' "$IDS"
# kubectl -n ungleich exec -ti $POD -c oned -- /bin/bash