2

i'm having a problem with connecting to QEMU with Libvirt API, here is the code:

import org.libvirt.Connect;
import org.libvirt.ConnectAuth;
import org.libvirt.ConnectAuthDefault;
import org.libvirt.LibvirtException;
import org.libvirt.NodeInfo;

public class Main 
{
  public static void main(String[] args)
  {
    System.setProperty("jna.library.path", "/home/johann/workspace/LibvirtTest/lib");
    try {
      ConnectAuth ca = new ConnectAuthDefault();
      Connect conn = new Connect("qemu+tcp://192.168.122.0/24", ca, 0);
      NodeInfo ni = conn.nodeInfo();

      System.out.println("model: " + ni.model + " mem(kb):" + ni.memory);

    } catch(LibvirtException le) {
       le.printStackTrace();
    }
  }
}

The problem is with the line

Connect conn = new Connect("qemu+tcp://192.168.122.0/24", ca, 0);

It makes the compiler throws this exception

Exception in thread "main" java.lang.UnsatisfiedLinkError:       com.sun.jna.Native.pointerSize()I
at com.sun.jna.Native.pointerSize(Native Method)
at com.sun.jna.Native.<clinit>(Native.java:88)
at org.libvirt.jna.Libvirt.<clinit>(Unknown Source)
at org.libvirt.Connect.<clinit>(Unknown Source)
at Main.main(Main.java:16)

I have found this address and port in the Virtual Machine Manager localhost QEMU details, but it doesn't seems to work...

Thanks in advance! :)

1

1 Answer 1

1

It seems the address is not ok.

"qemu+type://loginname@ip:port/system" would be right.

In your case it seems 192.168.122.0/24 is an ip and subnetmask because /24 equals subnetmask 255.255.255.0 and doesn't belong here... If it is a port you have to write :24. Also /system is missing

qemu+tcp://192.168.122.0:24/system should do the job - if not try two things:

1st Get rid of :24 and test

2nd Add username as shown above and test

One of this possibilities should work assuming the rest of your code is correct. Have fun!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.