1

我正在使用以下程序:

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 上运行良好。

谢谢!

4

1 回答 1

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));
于 2012-10-03T17:16:03.360 回答