provision/kvm/get-kvm-link-local
2024-10-17 15:04:16 -07:00

22 lines
591 B
Bash
Executable file

#!/bin/bash
if [[ $# -ne 1 ]]; then
echo "USAGE: $0 <domain>"
exit 0
else
domain="$1"
fi
if [[ ! -e /etc/libvirt/qemu/${domain}.xml ]]; then
echo "Error: ${domain} configuration not found on this system"
exit 1
fi
macAddress=$(sudo grep -o -E '([[:xdigit:]]{1,2}:){5}[[:xdigit:]]{1,2}' /etc/libvirt/qemu/${domain}.xml)
# courtesy of https://stackoverflow.com/a/48378567
printf "%02x%s" $(( 16#${macAddress:0:2} ^ 2#00000010 )) "${macAddress:2}" \
| sed -E -e 's/([0-9a-zA-Z]{2})*/0x\0|/g' \
| tr -d ':\n' \
| xargs -d '|' \
printf "fe80::%02x%02x:%02xff:fe%02x:%02x%02x\n"