我尝试使用以下代码在 KVM 虚拟机管理程序上创建 Activity/空闲虚拟机的快照:
看起来 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
最佳答案
xml 文件错误, getXMLDesc(int 标志) 提供域的 XML 描述。
您应该自己创建快照xml,而不是自动生成。
关于java - 如何使用 libvirt 创建虚拟机快照?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15453673/