[ungleich-tools] craete a script for MAC and IP for Task#14206

This commit is contained in:
kjg 2026-09-18 22:04:17 +09:00
commit 329e2ba874

View file

@ -0,0 +1,41 @@
#!/bin/sh
# get IPv6 address and MAC via VM_ID
VM_ID="${1:-}"
if [ -z "$VM_ID" ]; then
echo "Usage: $0 <VM_ID>" >&2
echo "Example: $0 123" >&2
exit 1
fi
POD=$(kubectl -n ungleich get pods \
-l app.kubernetes.io/component=opennebula --output=jsonpath={.items..metadata.name})
if [ -z "$POD" ]; then
echo "Error: OpenNebula pod not found" >&2
exit 1
fi
XML=$(kubectl exec "$POD" -n ungleich -c oned -- \
/bin/bash -c "onevm show $VM_ID --xml") || exit 1
printf '%s\n' "$XML" | xmlstarlet sel \
-t \
-m '//VM/TEMPLATE/NIC' \
-v 'concat("eth", position() - 1, ": ", MAC, " ", IP, " ", IP6_GLOBAL)' \
-n
# IPS=$(printf '%s' "$XML" | xmllint --xpath 'string(//VM/TEMPLATE/NIC[IP6_GLOBAL]/IP6_GLOBAL)' - 2>/dev/null)
# MACS=$(printf '%s' "$XML" | xmllint --xpath 'string(//VM/TEMPLATE/NIC[IP6_GLOBAL]/MAC)' - 2>/dev/null)
# printf 'VM IP: %s\n' "$IPS"
# printf 'VM MAC: %s\n' "$MACS"
# IPS=$(kubectl exec -ti $POD -n ungleich -c oned -- /bin/bash -c "onevm show $VM_ID --xml | xmllint --xpath '//VM/TEMPLATE/NIC[IP6_GLOBAL]/concat(IP6_GLOBAL/text(), " ", MAC/text(), "\n")' -")
# printf 'VM IP and MAC: %s\n' "$IPS"
# kubectl -n ungleich exec -ti $POD -c oned -- /bin/bash