2 # domipaddrs - print domain interfaces along with their MAC and IP addresses
8 print "Usage: %s [URI] DOMAIN" % sys
.argv
[0]
9 print " Print domain interfaces along with their MAC and IP addresses"
24 conn
= libvirt
.open(uri
)
26 print "Unable to open connection to libvirt"
30 dom
= conn
.lookupByName(name
)
31 except libvirt
.libvirtError
:
32 print "Domain %s not found" % name
35 ifaces
= dom
.interfaceAddresses(libvirt
.VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_LEASE
);
37 print "Failed to get domain interfaces"
40 print " {0:10} {1:20} {2:12} {3}".format("Interface", "MAC address", "Protocol", "Address")
42 def toIPAddrType(addrType
):
43 if addrType
== libvirt
.VIR_IP_ADDR_TYPE_IPV4
:
45 elif addrType
== libvirt
.VIR_IP_ADDR_TYPE_IPV6
:
48 for (name
, val
) in ifaces
.iteritems():
50 for addr
in val
['addrs']:
51 print " {0:10} {1:19}".format(name
, val
['hwaddr']),
52 print " {0:12} {1}/{2} ".format(toIPAddrType(addr
['type']), addr
['addr'], addr
['prefix']),
55 print " {0:10} {1:19}".format(name
, val
['hwaddr']),
56 print " {0:12} {1}".format("N/A", "N/A"),