[libvirt] RFC: libvirt java bindings based on JNA

Bryan Kearney bkearney at redhat.com
Tue Jul 28 12:42:42 UTC 2009


Thomas Treutner wrote:
> On Saturday 25 July 2009 13:56:36 Bryan Kearney wrote:
>> I would like to get some comments on an initial cut of the java bindings
>> on top of JNA[1]. They are not 100% complete (see below), but they are
>> good enough to be criticized. In addition, if there are features
>> additions to the API which people are interested in, I would appreciate
>> the feedback on that.
> 
> Thanks for your work!
> 
> I pulled from git, it compiles fine when provided with jna.jar - couldn't find 
> that except in my Eclipse 3.4 path. 
> 
> When using it with my tiny test application (which works fine with the JNI 
> version), it first complains that /etc/pki/CA/cacert.pem can not be found. As 
> I installed libvirt from source, it's in /usr/local/..., working fine with 
> JNI. So I did a symlink workaround for now.

Where did you see this complaint? Also.. what is your LD_LIBRARY_PATH 
set to when running this.


> 
> But fixing that, it doesn't work either:
> 
> 
> libvir: error : invalid argument in could not parse connection URI
> exception caught:org.libvirt.LibvirtException: invalid argument in could not 
> parse connection URI
> level:VIR_ERR_ERROR
> code:VIR_ERR_INVALID_ARG
> domain:VIR_FROM_NONE
> hasConn:false
> hasDom:false
> hasNet:false
> message:invalid argument in could not parse connection URI
> str1:invalid argument in %s
> str2:could not parse connection URI
> str3:null
> int1:0
> int2:0
> 
> 
> Code is:
> ...
>   conn = new Connect("xen://node02", false);
> ...
> 
> which works fine with JNI. 

Does

conn = new Connect("xen://node2/", false) ; do any better?

> 
> When I use the test class (directly on a node where libvirtd is running, or 
> remote, it doesn't matter), connections to the test driver are refused, 
> although some test information seems to be gathered, and connecting with 
> virsh works perfectly:

Acutally.. this is bad output. I bet I left the call with the 
defaultAuth in there. Can you verify that there are 2 open calls in the 
code I sent?

Thanks!


> 
> node02:~# virsh --connect test:///default
> node02:~# java -cp libvirt-0.3.0pre.jar:jna.jar:. test
> libvir: Remote error : unable to connect to 'localhost': Connection refused
> exception caught:org.libvirt.LibvirtException: unable to connect 
> to 'localhost': Connection refused
> level:VIR_ERR_ERROR
> code:VIR_ERR_SYSTEM_ERROR
> domain:VIR_FROM_REMOTE
> hasConn:false
> hasDom:false
> hasNet:false
> message:unable to connect to 'localhost': Connection refused
> str1:%s
> str2:unable to connect to 'localhost': Connection refused
> str3:null
> int1:-1
> int2:-1
> 
> virNodeInfo.model:i686
> virNodeInfo.memory:3145728
> virNodeInfo.cpus:16
> virNodeInfo.nodes:2
> virNodeInfo.sockets:2
> virNodeInfo.cores:2
> virNodeInfo.threads:2
> getHostName:node02.scripty.at
> getCapabilities:<capabilities>
> 
>   <host>
>     <cpu>
>       <arch>i686</arch>
>       <features>
>         <pae/>
>         <nonpae/>
>       </features>
>     </cpu>
>     <topology>
>       <cells num='2'>
>         <cell id='0'>
>           <cpus num='8'>
>             <cpu id='0'/>
>             <cpu id='2'/>
>             <cpu id='4'/>
>             <cpu id='6'/>
>             <cpu id='8'/>
>             <cpu id='10'/>
>             <cpu id='12'/>
>             <cpu id='14'/>
>           </cpus>
>         </cell>
>         <cell id='1'>
>           <cpus num='8'>
>             <cpu id='1'/>
>             <cpu id='3'/>
>             <cpu id='5'/>
>             <cpu id='7'/>
>             <cpu id='9'/>
>             <cpu id='11'/>
>             <cpu id='13'/>
>             <cpu id='15'/>
>           </cpus>
>         </cell>
>       </cells>
>     </topology>
>   </host>
> 
>   <guest>
>     <os_type>hvm</os_type>
>     <arch name='i686'>
>       <wordsize>32</wordsize>
>       <emulator>/usr/bin/test-hv</emulator>
>       <domain type='test'>
>       </domain>
>     </arch>
>     <features>
>       <pae/>
>       <nonpae/>
>     </features>
>   </guest>
> 
>   <guest>
>     <os_type>xen</os_type>
>     <arch name='i686'>
>       <wordsize>32</wordsize>
>       <emulator>/usr/bin/test-hv</emulator>
>       <domain type='test'>
>       </domain>
>     </arch>
>     <features>
>       <pae/>
>       <nonpae/>
>     </features>
>   </guest>
> 
> </capabilities>
> 
> getMaxVcpus:32
> getType:Test
> getURI:test://
> getVersion:2
> getLibVirVersion:4006
> conn.networkCreateXML: org.libvirt.Network at 3d434234
> conn.networkDefineXML: org.libvirt.Network at 30f7f540
> numOfDefinedNetworks:1
> listDefinedNetworks:[Ljava.lang.String;@10b61fd1
>         -> deftest
> numOfNetworks:2
> listNetworks:[Ljava.lang.String;@24e2dae9
>         -> createst
>         -> default
> conn.domainDefineXML:org.libvirt.Domain at 27ce2dd4
> conn.domainCreateLinux:org.libvirt.Domain at 5122cdb6
> numOfDefinedDomains:1
> listDefinedDomains:[Ljava.lang.String;@43ef9157
>         deftest
> numOfDomains:2
> listDomains:[I at 252f0999
>         -> 2
>         -> 1
> networkLookupByName: deftest
> <============== FIXME ================>
> networkLookupByUUIDString: deftest
> virNetworkGetXMLDesc:<network>
>   <name>deftest</name>
>   <uuid>004b96e1-2d78-c30f-5aa5-f03c87d21e67</uuid>
>   <forward dev='eth0' mode='nat'/>
>   <bridge name='deftest' stp='on' forwardDelay='0' />
>   <ip address='192.168.88.1' netmask='255.255.255.0'>
>     <dhcp>
>       <range start='192.168.88.128' end='192.168.88.253' />
>     </dhcp>
>   </ip>
> </network>
> 
> virNetworkGetAutostart:false
> virNetworkGetBridgeName:deftest
> virNetworkGetName:deftest
> virNetworkGetUUID:[I at 443ecfff
> <============== FIXME ================>
> 004bffffff96ffffffe12d78ffffffc30f5affffffa5fffffff03cffffff87ffffffd21e67
> virNetworkGetName:004b96e1-2d78-c30f-5aa5-f03c87d21e67
> virNetworkDestroy:
> virNetworkCreate:
> virNetworkCreate (should error):
> libvir: Test error deftest: internal error Network is already running
> exception caught:org.libvirt.LibvirtException: internal error Network is 
> already running
> level:VIR_ERR_ERROR
> code:VIR_ERR_INTERNAL_ERROR
> domain:VIR_FROM_TEST
> hasConn:false
> hasDom:false
> hasNet:false
> message:internal error Network is already running
> str1:internal error %s
> str2:Network is already running
> str3:null
> int1:0
> int2:0
> 
> domainLookupByID: org.libvirt.Domain at a4a63d8
> domainLookupByName: org.libvirt.Domain at 19e0ff2f
> virDomainGetXMLDesc:<domain type='test' id='1'>
>   <name>test</name>
>   <uuid>d4bf820b-3c84-eebc-0947-98e00ed3c94f</uuid>
>   <memory>8388608</memory>
>   <currentMemory>2097152</currentMemory>
>   <vcpu>2</vcpu>
>   <os>
>     <type arch='i686'>hvm</type>
>     <boot dev='hd'/>
>   </os>
>   <clock offset='utc'/>
>   <on_poweroff>destroy</on_poweroff>
>   <on_reboot>restart</on_reboot>
>   <on_crash>destroy</on_crash>
>   <devices>
>   </devices>
> </domain>
> 
> virDomainGetAutostart:false
> virDomainGetConnect:org.libvirt.Connect at 29173ef
> virDomainGetID:1
> virDomainGetInfo:state:VIR_DOMAIN_RUNNING
> maxMem:8388608
> memory:2097152
> nrVirtCpu:2
> cpuTime:1248783222588997000
> 
> virDomainGetMaxMemory:8388608
> libvir: error : this function is not supported by the hypervisor: 
> virDomainGetMaxVcpus
> virDomainGetName:test
> virDomainGetOSType:linux
> virDomainGetSchedulerType:[Ljava.lang.String;@3a860d49
> virDomainGetSchedulerParameters:[Lorg.libvirt.SchedParameter;@18872380
> Uint:weight:1696596736
> VIR_DOMAIN_SCHED_FIELD_UINT:weight:0
> virDomainGetUUID:[I at 502bb514
> <============== FIXME ================>
> ffffffd4ffffffbfffffff820b3cffffff84ffffffeeffffffbc0947ffffff98ffffffe00effffffd3ffffffc94f
> virDomainGetUUIDString:d4bf820b-3c84-eebc-0947-98e00ed3c94f
> libvir: error : invalid connection pointer in virConnectGetHostname
> null
> Fini!
> 
> 
> Am I doing something wron
> 
> 
> 
> 
> 
> 
> 
> 
> 




More information about the libvir-list mailing list