Re: [libvirt] Using libvirt to obtain mac address of virtual domain

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Daniel Berteaud wrote:
If you need to get the mac address from bash, you can use this:

virsh dumpxml myguest | grep 'mac address' | cut -d\' -f2

You'll get one mac address per line (one line per NIC on the guest)

An alternate approach which doesn't depend on the specific manner in which the XML is pretty-printed follows:

virsh dumpxml myguest \
  | xmlstarlet sel -t \
      -m "/domain/devices/interface[@type='network']/mac" \
      -v '@address' \
      -n

This does add an external dependency (see http://xmlstar.sf.net/), but I find XMLStarlet useful in conjunction with libvirt in other cases -- for instance, for programatically adding or modifying devices within the domain XML.

--
Libvir-list mailing list
Libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]