Re: [Ruby]How to retrieve nodes in <devices> ?

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

 



On Thu, Jan 9, 2014 at 11:04 AM, Teto <mattator@xxxxxxxxx> 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

--
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]