0
我想調用創建新虛擬機的方法。除了UUID,我擁有一切。我怎樣才能在我的參數中插入隨機生成的UUID來調用該方法?參數Java servlet中的UUID Libvirt
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
response.getWriter().append("Served at: ").append(request.getContextPath());
createVM("test",,20000,2,"/home/jur/Downloads/debian-8.6.0-amd64-netinst.iso");
}
public boolean createVM(String vmName,
UUID vmUuid,
long vmMemory,
int vmCpu,
String vmImage) {
String template;
Connect conn;
try {
System.out.println("Connecting to local hypervisor");
conn = new Connect("qemu:///system");
System.out.println("Creating template");
vmUuid = UUID.randomUUID();
template = TEMPLATE;
template = template.replace("$vmName", vmName);
template = template.replace("$vmMemory", String.valueOf(vmMemory));
template = template.replace("$vmCpu", String.valueOf(vmCpu));
template = template.replace("$vmImage", vmImage);
template = template.replace("$vmUuid", vmUuid.toString());
System.out.println("Resulting template: \n" + template);
System.out.println("Creating VM");
Domain domain = conn.domainCreateXML(template, 0);
conn.close();
} catch (LibvirtException e) {
e.printStackTrace();
return false;
}
return true;
}
爲什麼你需要在你的方法簽名UUID如果你重新分配它的隨機值('vmUuid = UUID.randomUUID();')裏面的方法? –
'createVM(「test」,UUID.randomUUID(),20000,2,「/ home/jur/Downloads/debian-8.6.0-amd64-netinst.iso」);'會工作,但在你的方法中你會覆蓋反正UUID? –