我正在尝试使用以下代码在 KVM 管理程序上创建活动/空闲虚拟机的快照:
看起来 xmlDesc 没有足够的信息来创建既不运行也不空闲的虚拟机的快照,或者可能是不同的东西?
在传递给方法之前我是否必须修改 xml 转储?或者快照需要一些单独的目标img文件?
有谁知道如何解决这个问题?
package org.vmclient;
import org.libvirt.Connect;
import org.libvirt.Domain;
import org.libvirt.DomainInfo;
import org.libvirt.DomainSnapshot;
import org.libvirt.LibvirtException;
public class Test {
public static void main(String[] args) {
// create and initialize variables
Connect connect = null;
Domain domain = null;
int numberOfSnaps;
DomainSnapshot domainSnapshot;
/*
* do NOT change! Create a connection
*/
try {
connect = new Connect("qemu:///system");
} catch (LibvirtException e) {
System.out.println("exception caught:" + e);
System.out.println(e.getError());
}
/*
* Perform an activity
*/
try {
//create a snapshot
domain = connect.domainLookupByName("Ubuntu");
/*
DomainInfo di = new DomainInfo();
di = domain.getInfo();
System.out.println(di);
*/
numberOfSnaps = domain.snapshotNum();
System.out.println(numberOfSnaps);
//1. get xmlDesc of current machine
String xmlDesc = domain.getXMLDesc(0);
//2. check if xmlDesc isnt empty
System.out.println(xmlDesc);
//3. pass xmlDesc to create a snapshot of the machine
//try {
domainSnapshot = domain.snapshotCreateXML(xmlDesc);
//}catch(LibvirtException e){
//System.out.println(e.getMessage());
//}
System.out.println("working ??");
//4. check if snap was created
numberOfSnaps = domain.snapshotNum();
System.out.println(numberOfSnaps);
} catch (LibvirtException e) {
System.out.println("exception caught:" + e);
System.out.println(e.getError());
}
}//end main
}//end Test.java
错误信息:
libvir: Domain Snapshot error : XML error: domainsnapshot
exception caught:org.libvirt.LibvirtException: XML error: domainsnapshot
level:VIR_ERR_ERROR
code:VIR_ERR_XML_ERROR
domain:VIR_FROM_DOMAIN_SNAPSHOT
hasConn:false
hasDom:false
hasNet:false
message:XML error: domainsnapshot
str1:XML error: %s
str2:domainsnapshot
str3:null
int1:-1
int2:-1