[ungleich-tools] craete a script for MAC and IP for Task#14206
This commit is contained in:
parent
e29b29eab5
commit
329e2ba874
1 changed files with 41 additions and 0 deletions
41
k8s/k8s-opennebula-get-ip-mac.sh
Executable file
41
k8s/k8s-opennebula-get-ip-mac.sh
Executable 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue