Created
December 11, 2011 21:00
-
-
Save rilindo/1462717 to your computer and use it in GitHub Desktop.
List KVM domains and their IPs. Note that the mac and IP must be in the arp table
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
require 'libvirt' | |
require 'xml' | |
def maptoip(mac,vm) | |
IO.popen("ip neigh").each do | line| | |
if (line.split(/\s+/)[4] == mac) | |
puts "#{line.split(/\s+/)[0]} - #{mac} - #{vm}" | |
break | |
end | |
end | |
end | |
conn = Libvirt::open('qemu:///system') | |
conn.list_domains.each do |domid| | |
dom = conn.lookup_domain_by_id(domid) | |
parser = XML::Parser.string(dom.xml_desc) | |
doc = parser.parse | |
doc.find('//devices/interface').each do |s| | |
s.each do |node| | |
maptoip(node[:address],dom.name) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment