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

Re: [Libvir] Ruby bindings for libvirt



On Thu, Aug 30, 2007 at 05:32:19PM +0800, Meng Kuan wrote:
> Hi,
> 
> I am exploring the possibility of creating ruby bindings for libvirt.  
> The only attempt I found after some searching is this:
> 
>   http://www.cs.ucsb.edu/~ckrintz/racelab/jisha/
> 
> Following the SWIG method as described in the above URL, I have  
> gotten to the following point:
> 
>   [root dell1 libvirt_ruby]# irb
>   irb(main):001:0> require 'libvirt_ruby'
>   => true
>   irb(main):002:0> conn = Libvirt_ruby.virConnectOpenReadOnly("")
>   => #<SWIG::TYPE_p__virConnect:0x2aaaaabc46c8>
>   irb(main):003:0>  dom = Libvirt_ruby.virDomainLookupByID(conn, 0)
>   => #<SWIG::TYPE_p__virDomain:0x2aaaaabb5df8>
>   irb(main):004:0> ret = Libvirt_ruby.virDomainGetInfo(dom, info)
>   NameError: undefined local variable or method `info' for main:Object
>           from (irb):4
>   irb(main):005:0>
> 
> I am not sure how to create and pass in a ptr to a virDomainInfo  
> struct object into the virDomainGetInfo call within ruby.

  Honnestly, I don't know ruby so no idea.

> Note that I was trying to following the info1.c example on the  
> libvirt website:
> 
>   http://libvirt.org/examples/info1.c
> 
> As you can tell, this is the first time I am trying to create any  
> sort of language bindings for a C library.
> 
> Some questions:
> 
> 1. Is there a better way of creating ruby bindings for libvirt  
> besides SWIG? If so, any pointers on what should be done?

  There is a formal XML definition of the libvirt API
     http://libvirt.org/libvirt-api.xml
The waythe python bindings are built is that a python script parses
this XML and then generate the C and python modules needed for the
bindings. I'm not sure this really helps you but at least this mean
you don't have parse the C header files if you want to automate the
process.

> 2. Alternatively I can try to make my ruby code use libvirt-python  
> bindings as a python library. Has anyone done so? Any problems with  
> this approach?

  No idea. But I would be a bit worried about piling up layers like
that, might work for you though..

Daniel

-- 
Red Hat Virtualization group http://redhat.com/virtualization/
Daniel Veillard      | virtualization library  http://libvirt.org/
veillard redhat com  | libxml GNOME XML XSLT toolkit  http://xmlsoft.org/
http://veillard.com/ | Rpmfind RPM search engine  http://rpmfind.net/


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