diff --git a/k8s/k8s-opennebula-get-ip-mac.sh b/k8s/k8s-opennebula-get-ip-mac.sh new file mode 100755 index 0000000..607738f --- /dev/null +++ b/k8s/k8s-opennebula-get-ip-mac.sh @@ -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 " >&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