我正在使用以下程序:
public class minitest {
public static void main(String[] args) {
Connect conn=null;
try{
int i;
conn = new Connect("xen:///", true);
int[] id = conn.listDomains();
int no=conn.numOfDomains();
System.out.println("length " +id.length);
}
}
}
该程序列出了KVM的虚拟机数量(在这种情况下,Connect语句将变为Connect("qemu:///system",true)
但Xen失败。每当我尝试访问id [0]时,就会出现数组越界异常。有足够的虚拟机在运行。
只有listDomain()不起作用。
其他功能在Xen和KVM上运行良好。
谢谢!
答案 0 :(得分:1)
在Java中使用这些函数用于XEN
Connect conn = null;
Domain d = null;
ConnectAuth defaultAuth = new ConnectAuthDefault();
conn = new Connect("xen:///", defaultAuth, 0);
System.out.println("Capabilities: " + conn.getCapabilities());
System.out.println("hostname: " + conn.getHostName());
System.out.println("version: " + conn.getLibVirVersion());
System.out.println("isSecure: " + conn.isSecure());
System.out.println("isEncrypted: " + conn.isEncrypted());
System.out.println("numOfDomains: " + conn.numOfDomains());
System.out.println("active Domains: " + conn.listDomains().length);
int[] ids = conn.listDomains();
System.out.println("Domains informations");
for (int i : ids) {
System.out.println(DASH);
System.out.println("Domain name = " + d.getName() + " | ID = " + d.getID() + " | OSType = " + d.getOSType());
System.out.println("MaxMemory = " + d.getMaxMemory() + " | " + d.getMaxVcpus());
System.out.println("UUID = " + d.getUUIDString());
System.out.println("Active? = " + d.isActive());
System.out.println("Persistent? = " + d.isPersistent());
DomainInfo df = d.getInfo();
System.out.println("CPUTime = " + df.cpuTime);
System.out.println("MaxMem = " + df.maxMem);
System.out.println("memory = " + df.memory);
System.out.println("nrVirtCpu = " + df.nrVirtCpu);
System.out.println("state = " + df.state);
}
...
d = conn.domainLookupByID(idToDelete);
d.destroy();
...
// create a domain
System.out.println("conn.domainCreateLinux:" + conn.domainCreateLinux(xml_file, 0));