-
Notifications
You must be signed in to change notification settings - Fork 31
/
virt-addr
executable file
·57 lines (45 loc) · 963 Bytes
/
virt-addr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/bin/sh
ARGS=$(getopt -o mn:i: --long macaddr,network:,index: -n virt-addr -- "$@")
if [ $? -ne 0 ]; then
echo "usage: $0: [--network <network>] [--index <index>] <name>" >&2
exit 2
fi
eval set -- "$ARGS"
while :; do
case "$1" in
-n|--network)
LIBVIRT_NETWORK=$2
shift 2
;;
-i|--index)
INTERFACE_INDEX=$2
shift 2
;;
-m|--macaddr)
ONLY_MACADDR=1
shift
;;
-l|--lease-file)
LIBVIRT_LEASE_FILE=$2
shift 2
;;
--) shift
break
;;
-*) echo "ERROR: unimplemented option: $1" >&2
exit 2
;;
esac
done
: ${LIBVIRT_NETWORK:=default}
: ${LIBVIRT_LEASE_FILE:=/var/lib/libvirt/dnsmasq/${LIBVIRT_NETWORK}.leases}
: ${INTERFACE_INDEX:=1}
dom_name=$1
shift
macaddr=$(virsh dumpxml $dom_name |
xmllint --xpath "string((//interface/mac/@address)[${INTERFACE_INDEX}])" -)
if [ "$ONLY_MACADDR" = 1 ]; then
echo $macaddr
exit
fi
awk -vmacaddress=$macaddr '$2 == macaddress {print $3}' $LIBVIRT_LEASE_FILE