[libvirt] [Ruby]How to retrieve nodes in <devices> ?
Chris Lalancette
clalancette at gmail.com
Thu Jan 9 18:53:00 UTC 2014
On Thu, Jan 9, 2014 at 11:04 AM, Teto <mattator at gmail.com> wrote:
> Hi,
>
> I would like to list devices (for instance I would like to retrieve
> the <filesystem> part in <devices><filesystem
> type="mount">...</filesystem></devices>) embedded in a domain via the
> ruby bindings ?
The steps are roughly:
1. require 'libvirt'
2. Connect to libvirt using the open method
3. Find the domain you care about using lookup_domain_by_name
4. Get the XML for the domain
5. Parse the domain XML using nokogiri or similar
It would look something like this (the details will be somewhat
different depending on which connection URI and domain you are using):
require 'libvirt'
conn = Libvirt::open('qemu:///system')
dom = conn.lookup_domain_by_name('f19')
xml_doc = Nokogiri::XML(dom.xml_desc)
devs = xml_doc.xpath('/domain/devices')
After that last line, you'll have the ability to iterate over the
devices, and do whatever you want with them. Hope this helps!
Chris
More information about the libvir-list
mailing list