Skip to content

Instantly share code, notes, and snippets.

@wido
Last active November 9, 2015 12:45
Show Gist options
  • Save wido/30457cbe66e3965f00de to your computer and use it in GitHub Desktop.
Save wido/30457cbe66e3965f00de to your computer and use it in GitHub Desktop.
libvirt-java Qemu Guest Agent
import org.libvirt.Connect;
import org.libvirt.Domain;
import org.libvirt.LibvirtException;
public class GuestAgent {
public static void main(String argv[]) {
Connect conn = null;
try {
conn = new Connect("qemu+tcp://[::1]/system");
Domain testDomain = conn.domainLookupByName("guest-agent");
String result = testDomain.qemuAgentCommand("{\"execute\":\"guest-network-get-interfaces\"}", 2, 0);
System.out.println(result);
} catch (LibvirtException e) {
System.out.println("Failed to execute command: " + e.getMessage());
} catch (Exception e) {
System.out.println(e);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment