我正在使用XenServer 6.5
在Java中,我使用SDK库
<dependency>
<groupId>net.java.dev.vcc.thirdparty</groupId>
<artifactId>xen-api</artifactId>
<version>6.2.0-3.1</version>
</dependency>
然后我用模板创建我的实例。
VM template = VM.getByNameLabel(connection, templateName).iterator()
.next();
VM vm = template.createClone(connection, instanceName);
vm.setIsATemplate(connection, false);
vm.removeFromOtherConfig(connection, "disks");
vm.setNameLabel(connection, instanceName);
vm.setMemoryStaticMin(connection, new Long(256));
vm.setMemoryDynamicMin(connection, new Long(256));
vm.setMemoryDynamicMax(connection, new Long(256));
vm.setMemoryStaticMax(connection, new Long(256));
vm.setVCPUsAtStartup(connection, new Long(1));
创建实例后,我尝试启动它。
VM vm = VM.getByNameLabel(connection, name).iterator().next();
vm.start(connection, false, false);
System.out.println(vm.getPowerState(connection));
但它返回
The server failed to handle your request, due to an internal error. The given message may give details useful for debugging the problem.
at com.xensource.xenapi.Types.checkResponse(Types.java:1609)
at com.xensource.xenapi.Connection.dispatch(Connection.java:395)
at com.xensource.xenapi.VM.start(VM.java:3118)
at com.apo.region.vm.XenConnectionsManager.startVM(XenConnectionsManager.java:79)
at com.apo.region.controller.VMController.list(VMController.java:36)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:776)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:705)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:967)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:858)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:843)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:957)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:620)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
我在互联网上搜索,发现了 create函数没有两个布尔参数:
vm.start(connection);
但我尝试使用不同版本的Maven:
vm.start(connection, false, false);
错误消息没有太多信息。我错过了任何步骤吗?
答案 0 :(得分:0)
我很抱歉这么晚回答,但我昨天刚看到这个问题,我想在回答你之前先测试一下。
关于内存问题,任何内存设置都是以字节为单位,因此,参数很长(允许大容量内存配置)。你只能在两个内存中设置新的VM,静态和动态,低于Spectrum!
考虑到这一点,我的假设是你的内存限制太低,因为 GUEST OS 有内存限制(特别是Windows)。在这个blog中,您可以看到与其他虚拟机管理程序相关的客户操作系统的最小/最大内存(但我认为在Xenserver中是相同的)。
无论如何,这个片段对我来说是使用相同的maven依赖,和你一样的xenserver - 6.5 - 。
有关vm.start(con,false,false)
的更多信息,您可以下载Xenserver 6.5 SDK并查看与VM相关的javadoc。第二个参数是允许在暂停模式下启动,第三个参数是强制启动操作。
try
{
Connection con = new Connection(new URL(url));
Session.loginWithPassword(con, user, pass);
String templateName = "template-test";
String instanceName = "testVM";
VM template = VM.getByNameLabel(con, templateName).iterator().next();
VM vm = template.createClone(con, instanceName);
vm.setNameLabel(con, instanceName);
//This numbers are upper than required minimum for Windows 7
//My Guest OS
vm.setMemoryStaticMin(connection, 1073741824L);
vm.setMemoryDynamicMin(connection, 4294967296L);
vm.setMemoryDynamicMax(connection, 1073741824L);
vm.setMemoryStaticMax(connection, 4294967296L);
vm.setVCPUsAtStartup(con, 1L);
vm.provision(con);
VM vm2 = VM.getByNameLabel(con, instanceName).iterator().next();
vm2.start(con, false, false);
System.out.println(vm2.getPowerState(con));
}
catch (Exception e)
{
e.printStackTrace();
}