You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by se...@apache.org on 2014/06/07 10:50:45 UTC
[05/16] Cleanup of Xen and XenServer terms. Cloned xen plugin
creating a xenserver plugin, then removed xen plugin
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a8212d9e/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/XcpOssResource.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/XcpOssResource.java b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/XcpOssResource.java
new file mode 100644
index 0000000..170730e
--- /dev/null
+++ b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/XcpOssResource.java
@@ -0,0 +1,195 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package com.cloud.hypervisor.xenserver.resource;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+import javax.ejb.Local;
+
+import org.apache.log4j.Logger;
+import org.apache.xmlrpc.XmlRpcException;
+
+import com.cloud.agent.api.Answer;
+import com.cloud.agent.api.Command;
+import com.cloud.agent.api.NetworkUsageAnswer;
+import com.cloud.agent.api.NetworkUsageCommand;
+import com.cloud.agent.api.StartupRoutingCommand;
+import com.cloud.agent.api.StartupStorageCommand;
+import com.cloud.agent.api.StopAnswer;
+import com.cloud.agent.api.StopCommand;
+import com.cloud.agent.api.StoragePoolInfo;
+import com.cloud.resource.ServerResource;
+import com.cloud.storage.Storage;
+import com.cloud.utils.exception.CloudRuntimeException;
+import com.cloud.utils.script.Script;
+import com.xensource.xenapi.Connection;
+import com.xensource.xenapi.Host;
+import com.xensource.xenapi.SR;
+import com.xensource.xenapi.Types;
+import com.xensource.xenapi.Types.XenAPIException;
+import com.xensource.xenapi.VBD;
+import com.xensource.xenapi.VDI;
+import com.xensource.xenapi.VM;
+
+@Local(value = ServerResource.class)
+public class XcpOssResource extends CitrixResourceBase {
+ private final static Logger s_logger = Logger.getLogger(XcpOssResource.class);
+ private static final long mem_32m = 33554432L;
+
+ @Override
+ protected List<File> getPatchFiles() {
+ List<File> files = new ArrayList<File>();
+ String patch = "scripts/vm/hypervisor/xenserver/xcposs/patch";
+ String patchfilePath = Script.findScript("", patch);
+ if (patchfilePath == null) {
+ throw new CloudRuntimeException("Unable to find patch file " + patch);
+ }
+ File file = new File(patchfilePath);
+ files.add(file);
+ return files;
+ }
+
+ @Override
+ protected void fillHostInfo(Connection conn, StartupRoutingCommand cmd) {
+ super.fillHostInfo(conn, cmd);
+ cmd.setCaps(cmd.getCapabilities() + " , hvm");
+ }
+
+ @Override
+ protected boolean launchHeartBeat(Connection conn) {
+ return true;
+ }
+
+ protected StartupStorageCommand initializeLocalSR(Connection conn) {
+ SR extsr = getLocalEXTSR(conn);
+ if (extsr != null) {
+ try {
+ String extuuid = extsr.getUuid(conn);
+ _host.localSRuuid = extuuid;
+ long cap = extsr.getPhysicalSize(conn);
+ if (cap > 0) {
+ long avail = cap - extsr.getPhysicalUtilisation(conn);
+ String name = "Cloud Stack Local EXT Storage Pool for " + _host.uuid;
+ extsr.setNameDescription(conn, name);
+ Host host = Host.getByUuid(conn, _host.uuid);
+ String address = host.getAddress(conn);
+ StoragePoolInfo pInfo = new StoragePoolInfo(extsr.getNameLabel(conn), address, SRType.EXT.toString(), SRType.EXT.toString(), Storage.StoragePoolType.EXT, cap, avail);
+ StartupStorageCommand cmd = new StartupStorageCommand();
+ cmd.setPoolInfo(pInfo);
+ cmd.setGuid(_host.uuid);
+ cmd.setDataCenter(Long.toString(_dcId));
+ cmd.setResourceType(Storage.StorageResourceType.STORAGE_POOL);
+ return cmd;
+ }
+ } catch (XenAPIException e) {
+ String msg = "build local EXT info err in host:" + _host.uuid + e.toString();
+ s_logger.warn(msg);
+ } catch (XmlRpcException e) {
+ String msg = "build local EXT info err in host:" + _host.uuid + e.getMessage();
+ s_logger.warn(msg);
+ }
+ }
+ return null;
+ }
+
+ @Override
+ protected String getGuestOsType(String stdType, boolean bootFromCD) {
+ if (stdType.equalsIgnoreCase("Debian GNU/Linux 6(64-bit)")) {
+ return "Debian Squeeze 6.0 (64-bit)";
+ } else if (stdType.equalsIgnoreCase("CentOS 5.6 (64-bit)")) {
+ return "CentOS 5 (64-bit)";
+ } else {
+ return CitrixHelper.getXcpGuestOsType(stdType);
+ }
+ }
+
+ @Override
+ protected synchronized VBD createPatchVbd(Connection conn, String vmName, VM vm) throws XmlRpcException, XenAPIException {
+ if (_host.localSRuuid != null) {
+ //create an iso vdi on it
+ String result = callHostPlugin(conn, "vmops", "createISOVHD", "uuid", _host.localSRuuid);
+ if (result == null || result.equalsIgnoreCase("Failed")) {
+ throw new CloudRuntimeException("can not create systemvm vdi");
+ }
+
+ Set<VDI> vdis = VDI.getByNameLabel(conn, "systemvm-vdi");
+ if (vdis.size() != 1) {
+ throw new CloudRuntimeException("can not find systemvmiso");
+ }
+ VDI systemvmVDI = vdis.iterator().next();
+
+ VBD.Record cdromVBDR = new VBD.Record();
+ cdromVBDR.VM = vm;
+ cdromVBDR.empty = false;
+ cdromVBDR.bootable = false;
+ cdromVBDR.userdevice = "3";
+ cdromVBDR.mode = Types.VbdMode.RO;
+ cdromVBDR.type = Types.VbdType.DISK;
+ cdromVBDR.VDI = systemvmVDI;
+ VBD cdromVBD = VBD.create(conn, cdromVBDR);
+ return cdromVBD;
+ } else {
+ throw new CloudRuntimeException("can not find local sr");
+ }
+ }
+
+ protected NetworkUsageAnswer execute(NetworkUsageCommand cmd) {
+ try {
+ Connection conn = getConnection();
+ if (cmd.getOption() != null && cmd.getOption().equals("create")) {
+ String result = networkUsage(conn, cmd.getPrivateIP(), "create", null);
+ NetworkUsageAnswer answer = new NetworkUsageAnswer(cmd, result, 0L, 0L);
+ return answer;
+ }
+ long[] stats = getNetworkStats(conn, cmd.getPrivateIP());
+ NetworkUsageAnswer answer = new NetworkUsageAnswer(cmd, "", stats[0], stats[1]);
+ return answer;
+ } catch (Exception ex) {
+ s_logger.warn("Failed to get network usage stats due to ", ex);
+ return new NetworkUsageAnswer(cmd, ex);
+ }
+ }
+
+ @Override
+ public Answer executeRequest(Command cmd) {
+ if (cmd instanceof NetworkUsageCommand) {
+ return execute((NetworkUsageCommand) cmd);
+ } else {
+ return super.executeRequest(cmd);
+ }
+ }
+
+ @Override
+ public StopAnswer execute(StopCommand cmd) {
+ StopAnswer answer = super.execute(cmd);
+ String vmName = cmd.getVmName();
+ if (vmName.startsWith("v-")) {
+ Connection conn = getConnection();
+ callHostPlugin(conn, "vmops", "setDNATRule", "add", "false");
+ }
+ return answer;
+ }
+
+ @Override
+ protected void setMemory(Connection conn, VM vm, long minMemsize, long maxMemsize) throws XmlRpcException, XenAPIException {
+ vm.setMemoryLimits(conn, mem_32m, maxMemsize, minMemsize, maxMemsize);
+ }
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a8212d9e/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/XcpServer16Resource.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/XcpServer16Resource.java b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/XcpServer16Resource.java
new file mode 100644
index 0000000..f5bede8
--- /dev/null
+++ b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/XcpServer16Resource.java
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package com.cloud.hypervisor.xenserver.resource;
+
+public class XcpServer16Resource extends XcpServerResource {
+
+ public XcpServer16Resource() {
+ super();
+ }
+
+ @Override
+ protected String getGuestOsType(String stdType, boolean bootFromCD) {
+ return CitrixHelper.getXcp160GuestOsType(stdType);
+ }
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a8212d9e/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/XcpServerResource.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/XcpServerResource.java b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/XcpServerResource.java
new file mode 100644
index 0000000..2825008
--- /dev/null
+++ b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/XcpServerResource.java
@@ -0,0 +1,160 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package com.cloud.hypervisor.xenserver.resource;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.ejb.Local;
+
+import org.apache.log4j.Logger;
+import org.apache.xmlrpc.XmlRpcException;
+
+import com.xensource.xenapi.Connection;
+import com.xensource.xenapi.Host;
+import com.xensource.xenapi.Types.XenAPIException;
+import com.xensource.xenapi.VM;
+
+import com.cloud.agent.api.Answer;
+import com.cloud.agent.api.Command;
+import com.cloud.agent.api.NetworkUsageAnswer;
+import com.cloud.agent.api.NetworkUsageCommand;
+import com.cloud.resource.ServerResource;
+import com.cloud.utils.exception.CloudRuntimeException;
+import com.cloud.utils.script.Script;
+
+@Local(value = ServerResource.class)
+public class XcpServerResource extends CitrixResourceBase {
+ private final static Logger s_logger = Logger.getLogger(XcpServerResource.class);
+ private static final long mem_32m = 33554432L;
+ private String version;
+
+ public XcpServerResource() {
+ super();
+ }
+
+ @Override
+ public Answer executeRequest(Command cmd) {
+ if (cmd instanceof NetworkUsageCommand) {
+ return execute((NetworkUsageCommand)cmd);
+ } else {
+ return super.executeRequest(cmd);
+ }
+ }
+
+ @Override
+ protected List<File> getPatchFiles() {
+ List<File> files = new ArrayList<File>();
+ String patch = "scripts/vm/hypervisor/xenserver/xcpserver/patch";
+ String patchfilePath = Script.findScript("", patch);
+ if (patchfilePath == null) {
+ throw new CloudRuntimeException("Unable to find patch file " + patch);
+ }
+ File file = new File(patchfilePath);
+ files.add(file);
+ return files;
+ }
+
+ @Override
+ protected String getGuestOsType(String stdType, boolean bootFromCD) {
+ return CitrixHelper.getXcpGuestOsType(stdType);
+ }
+
+ protected NetworkUsageAnswer execute(NetworkUsageCommand cmd) {
+ try {
+ Connection conn = getConnection();
+ if (cmd.getOption() != null && cmd.getOption().equals("create")) {
+ String result = networkUsage(conn, cmd.getPrivateIP(), "create", null);
+ NetworkUsageAnswer answer = new NetworkUsageAnswer(cmd, result, 0L, 0L);
+ return answer;
+ }
+ long[] stats = getNetworkStats(conn, cmd.getPrivateIP());
+ NetworkUsageAnswer answer = new NetworkUsageAnswer(cmd, "", stats[0], stats[1]);
+ return answer;
+ } catch (Exception ex) {
+ s_logger.warn("Failed to get network usage stats due to ", ex);
+ return new NetworkUsageAnswer(cmd, ex);
+ }
+ }
+
+ /**
+ XCP provides four memory configuration fields through which
+ administrators can control this behaviour:
+
+ * static-min
+ * dynamic-min
+ * dynamic-max
+ * static-max
+
+ The fields static-{min,max} act as *hard* lower and upper
+ bounds for a guest's memory. For a running guest:
+ * it's not possible to assign the guest more memory than
+ static-max without first shutting down the guest.
+ * it's not possible to assign the guest less memory than
+ static-min without first shutting down the guest.
+
+ The fields dynamic-{min,max} act as *soft* lower and upper
+ bounds for a guest's memory. It's possible to change these
+ fields even when a guest is running.
+
+ The dynamic range must lie wholly within the static range. To
+ put it another way, XCP at all times ensures that:
+
+ static-min <= dynamic-min <= dynamic-max <= static-max
+
+ At all times, XCP will attempt to keep a guest's memory usage
+ between dynamic-min and dynamic-max.
+
+ If dynamic-min = dynamic-max, then XCP will attempt to keep
+ a guest's memory allocation at a constant size.
+
+ If dynamic-min < dynamic-max, then XCP will attempt to give
+ the guest as much memory as possible, while keeping the guest
+ within dynamic-min and dynamic-max.
+
+ If there is enough memory on a given host to give all resident
+ guests dynamic-max, then XCP will attempt do so.
+
+ If there is not enough memory to give all guests dynamic-max,
+ then XCP will ask each of the guests (on that host) to use
+ an amount of memory that is the same *proportional* distance
+ between dynamic-min and dynamic-max.
+
+ XCP will refuse to start guests if starting those guests would
+ cause the sum of all the dynamic-min values to exceed the total
+ host memory (taking into account various memory overheads).
+
+ cf: https://wiki.xenserver.org/index.php?title=XCP_FAQ_Dynamic_Memory_Control
+ */
+ @Override
+ protected void setMemory(Connection conn, VM vm, long minMemsize, long maxMemsize) throws XmlRpcException, XenAPIException {
+ //setMemoryLimits(staticMin, staticMax, dynamicMin, dynamicMax)
+ if (s_logger.isDebugEnabled()) {
+ s_logger.debug("Memory Limits for VM [" + vm.getNameLabel(conn) + "[staticMin:" + mem_32m + ", staticMax:" + maxMemsize + ", dynamicMin: " + minMemsize +
+ ", dynamicMax:" + maxMemsize + "]]");
+ }
+ vm.setMemoryLimits(conn, mem_32m, maxMemsize, minMemsize, maxMemsize);
+ }
+
+ @Override
+ protected boolean isDmcEnabled(Connection conn, Host host) {
+ //Dynamic Memory Control (DMC) is a technology provided by Xen Cloud Platform (XCP), starting from the 0.5 release
+ //For the supported XCPs dmc is default enabled, XCP 1.0.0, 1.1.0, 1.4.x, 1.5 beta, 1.6.x;
+ return true;
+ }
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a8212d9e/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/XenServer56FP1Resource.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/XenServer56FP1Resource.java b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/XenServer56FP1Resource.java
new file mode 100644
index 0000000..ddedaf5
--- /dev/null
+++ b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/XenServer56FP1Resource.java
@@ -0,0 +1,168 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package com.cloud.hypervisor.xenserver.resource;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.ejb.Local;
+
+import org.apache.log4j.Logger;
+import org.apache.xmlrpc.XmlRpcException;
+
+import com.xensource.xenapi.Connection;
+import com.xensource.xenapi.Host;
+import com.xensource.xenapi.Types.XenAPIException;
+import com.xensource.xenapi.VBD;
+import com.xensource.xenapi.VDI;
+import com.xensource.xenapi.VM;
+
+import com.cloud.agent.api.FenceAnswer;
+import com.cloud.agent.api.FenceCommand;
+import com.cloud.resource.ServerResource;
+import com.cloud.utils.exception.CloudRuntimeException;
+import com.cloud.utils.script.Script;
+
+@Local(value = ServerResource.class)
+public class XenServer56FP1Resource extends XenServer56Resource {
+ private static final long mem_128m = 134217728L;
+ private static final Logger s_logger = Logger.getLogger(XenServer56FP1Resource.class);
+
+ public XenServer56FP1Resource() {
+ super();
+ }
+
+ @Override
+ protected String getGuestOsType(String stdType, boolean bootFromCD) {
+ return CitrixHelper.getXenServer56FP1GuestOsType(stdType, bootFromCD);
+ }
+
+ @Override
+ protected List<File> getPatchFiles() {
+ List<File> files = new ArrayList<File>();
+ String patch = "scripts/vm/hypervisor/xenserver/xenserver56fp1/patch";
+ String patchfilePath = Script.findScript("", patch);
+ if (patchfilePath == null) {
+ throw new CloudRuntimeException("Unable to find patch file " + patch);
+ }
+ File file = new File(patchfilePath);
+ files.add(file);
+ return files;
+ }
+
+ @Override
+ protected FenceAnswer execute(FenceCommand cmd) {
+ Connection conn = getConnection();
+ try {
+ Boolean alive = check_heartbeat(cmd.getHostGuid());
+ if ( alive == null ) {
+ s_logger.debug("Failed to check heartbeat, so unable to fence");
+ return new FenceAnswer(cmd, false, "Failed to check heartbeat, so unable to fence");
+ }
+ if ( alive ) {
+ s_logger.debug("Heart beat is still going so unable to fence");
+ return new FenceAnswer(cmd, false, "Heartbeat is still going on unable to fence");
+ }
+ Set<VM> vms = VM.getByNameLabel(conn, cmd.getVmName());
+ for (VM vm : vms) {
+ Set<VDI> vdis = new HashSet<VDI>();
+ Set<VBD> vbds = vm.getVBDs(conn);
+ for (VBD vbd : vbds) {
+ VDI vdi = vbd.getVDI(conn);
+ if (!isRefNull(vdi)) {
+ vdis.add(vdi);
+ }
+ }
+ synchronized (_cluster.intern()) {
+ s_vms.remove(_cluster, _name, vm.getNameLabel(conn));
+ }
+ s_logger.info("Fence command for VM " + cmd.getVmName());
+ vm.powerStateReset(conn);
+ vm.destroy(conn);
+ for (VDI vdi : vdis) {
+ Map<String, String> smConfig = vdi.getSmConfig(conn);
+ for (String key : smConfig.keySet()) {
+ if (key.startsWith("host_")) {
+ vdi.removeFromSmConfig(conn, key);
+ break;
+ }
+ }
+ }
+ }
+ return new FenceAnswer(cmd);
+ } catch (XmlRpcException e) {
+ s_logger.warn("Unable to fence", e);
+ return new FenceAnswer(cmd, false, e.getMessage());
+ } catch (XenAPIException e) {
+ s_logger.warn("Unable to fence", e);
+ return new FenceAnswer(cmd, false, e.getMessage());
+ }
+ }
+
+ @Override
+ public long getStaticMax(String os, boolean b, long dynamicMinRam, long dynamicMaxRam) {
+ long recommendedValue = CitrixHelper.getXenServer56FP1StaticMax(os, b);
+ if (recommendedValue == 0) {
+ s_logger.warn("No recommended value found for dynamic max, setting static max and dynamic max equal");
+ return dynamicMaxRam;
+ }
+
+ long staticMax = Math.min(recommendedValue, 4l * dynamicMinRam); // XS constraint for stability
+ if (dynamicMaxRam > staticMax) { // XS contraint that dynamic max <= static max
+ s_logger.warn("dynamixMax " + dynamicMaxRam + " cant be greater than static max " + staticMax +
+ ", can lead to stability issues. Setting static max as much as dynamic max ");
+ return dynamicMaxRam;
+ }
+ return staticMax;
+ }
+
+ @Override
+ public long getStaticMin(String os, boolean b, long dynamicMinRam, long dynamicMaxRam) {
+ long recommendedValue = CitrixHelper.getXenServer56FP1StaticMin(os, b);
+ if (recommendedValue == 0) {
+ s_logger.warn("No recommended value found for dynamic min");
+ return dynamicMinRam;
+ }
+
+ if (dynamicMinRam < recommendedValue) { // XS contraint that dynamic min > static min
+ s_logger.warn("Vm is set to dynamixMin " + dynamicMinRam + " less than the recommended static min " + recommendedValue + ", could lead to stability issues.");
+ }
+ return dynamicMinRam;
+ }
+
+ /**
+ * When Dynamic Memory Control (DMC) is enabled -
+ * xenserver allows scaling the guest memory while the guest is running
+ *
+ * This is determined by the 'restrict_dmc' option on the host.
+ * When false, scaling is allowed hence DMC is enabled
+ */
+ @Override
+ protected boolean isDmcEnabled(Connection conn, Host host) throws XenAPIException, XmlRpcException {
+ Map<String, String> hostParams = new HashMap<String, String>();
+ hostParams = host.getLicenseParams(conn);
+
+ Boolean isDmcEnabled = hostParams.get("restrict_dmc").equalsIgnoreCase("false");
+
+ return isDmcEnabled;
+ }
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a8212d9e/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/XenServer56Resource.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/XenServer56Resource.java b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/XenServer56Resource.java
new file mode 100644
index 0000000..99cd09d
--- /dev/null
+++ b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/XenServer56Resource.java
@@ -0,0 +1,330 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package com.cloud.hypervisor.xenserver.resource;
+
+import com.cloud.agent.api.Answer;
+import com.cloud.agent.api.CheckOnHostAnswer;
+import com.cloud.agent.api.CheckOnHostCommand;
+import com.cloud.agent.api.Command;
+import com.cloud.agent.api.FenceAnswer;
+import com.cloud.agent.api.FenceCommand;
+import com.cloud.agent.api.NetworkUsageAnswer;
+import com.cloud.agent.api.NetworkUsageCommand;
+import com.cloud.agent.api.StartupCommand;
+import com.cloud.resource.ServerResource;
+import com.cloud.utils.ExecutionResult;
+import com.cloud.utils.exception.CloudRuntimeException;
+import com.cloud.utils.script.Script;
+import com.cloud.utils.ssh.SSHCmdHelper;
+import com.xensource.xenapi.Connection;
+import com.xensource.xenapi.Host;
+import com.xensource.xenapi.Network;
+import com.xensource.xenapi.PIF;
+import com.xensource.xenapi.Types.IpConfigurationMode;
+import com.xensource.xenapi.Types.XenAPIException;
+import com.xensource.xenapi.VLAN;
+import com.xensource.xenapi.VM;
+import org.apache.log4j.Logger;
+import org.apache.xmlrpc.XmlRpcException;
+
+import javax.ejb.Local;
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+@Local(value = ServerResource.class)
+public class XenServer56Resource extends CitrixResourceBase {
+ private final static Logger s_logger = Logger.getLogger(XenServer56Resource.class);
+
+ @Override
+ public Answer executeRequest(Command cmd) {
+ if (cmd instanceof FenceCommand) {
+ return execute((FenceCommand)cmd);
+ } else if (cmd instanceof NetworkUsageCommand) {
+ return execute((NetworkUsageCommand)cmd);
+ } else {
+ return super.executeRequest(cmd);
+ }
+ }
+
+ @Override
+ protected String getGuestOsType(String stdType, boolean bootFromCD) {
+ return CitrixHelper.getXenServerGuestOsType(stdType, bootFromCD);
+ }
+
+ @Override
+ protected List<File> getPatchFiles() {
+ List<File> files = new ArrayList<File>();
+ String patch = "scripts/vm/hypervisor/xenserver/xenserver56/patch";
+ String patchfilePath = Script.findScript("", patch);
+ if (patchfilePath == null) {
+ throw new CloudRuntimeException("Unable to find patch file " + patch);
+ }
+ File file = new File(patchfilePath);
+ files.add(file);
+
+ return files;
+ }
+
+ @Override
+ protected void disableVlanNetwork(Connection conn, Network network) {
+ try {
+ Network.Record networkr = network.getRecord(conn);
+ if (!networkr.nameLabel.startsWith("VLAN")) {
+ return;
+ }
+ String bridge = networkr.bridge.trim();
+ for (PIF pif : networkr.PIFs) {
+ PIF.Record pifr = pif.getRecord(conn);
+ if (!pifr.host.getUuid(conn).equalsIgnoreCase(_host.uuid)) {
+ continue;
+ }
+
+ VLAN vlan = pifr.VLANMasterOf;
+ if (vlan != null) {
+ String vlannum = pifr.VLAN.toString();
+ String device = pifr.device.trim();
+ if (vlannum.equals("-1")) {
+ return;
+ }
+ try {
+ vlan.destroy(conn);
+ Host host = Host.getByUuid(conn, _host.uuid);
+ host.forgetDataSourceArchives(conn, "pif_" + bridge + "_tx");
+ host.forgetDataSourceArchives(conn, "pif_" + bridge + "_rx");
+ host.forgetDataSourceArchives(conn, "pif_" + device + "." + vlannum + "_tx");
+ host.forgetDataSourceArchives(conn, "pif_" + device + "." + vlannum + "_rx");
+ } catch (XenAPIException e) {
+ s_logger.info("Catch " + e.getClass().getName() + ": failed to destory VLAN " + device + " on host " + _host.uuid + " due to " + e.toString());
+ }
+ }
+ return;
+ }
+ } catch (XenAPIException e) {
+ String msg = "Unable to disable VLAN network due to " + e.toString();
+ s_logger.warn(msg, e);
+ } catch (Exception e) {
+ String msg = "Unable to disable VLAN network due to " + e.getMessage();
+ s_logger.warn(msg, e);
+ }
+ }
+
+ @Override
+ protected String networkUsage(Connection conn, final String privateIpAddress, final String option, final String vif) {
+ String args = "";
+ if (option.equals("get")) {
+ args += "-g";
+ } else if (option.equals("create")) {
+ args += "-c";
+ } else if (option.equals("reset")) {
+ args += "-r";
+ } else if (option.equals("addVif")) {
+ args += "-a ";
+ args += vif;
+ } else if (option.equals("deleteVif")) {
+ args += "-d ";
+ args += vif;
+ }
+
+ return executeInVR(privateIpAddress, "netusage.sh", args).getDetails();
+ }
+
+ protected NetworkUsageAnswer VPCNetworkUsage(NetworkUsageCommand cmd) {
+ try {
+ Connection conn = getConnection();
+ String option = cmd.getOption();
+ String publicIp = cmd.getGatewayIP();
+
+ String args = " -l " + publicIp + " ";
+ if (option.equals("get")) {
+ args += "-g";
+ } else if (option.equals("create")) {
+ args += "-c";
+ String vpcCIDR = cmd.getVpcCIDR();
+ args += " -v " + vpcCIDR;
+ } else if (option.equals("reset")) {
+ args += "-r";
+ } else if (option.equals("vpn")) {
+ args += "-n";
+ } else if (option.equals("remove")) {
+ args += "-d";
+ } else {
+ return new NetworkUsageAnswer(cmd, "success", 0L, 0L);
+ }
+
+ ExecutionResult result = executeInVR(cmd.getPrivateIP(), "vpc_netusage.sh", args);
+ String detail = result.getDetails();
+ if (!result.isSuccess()) {
+ throw new Exception(" vpc network usage plugin call failed ");
+ }
+ if (option.equals("get") || option.equals("vpn")) {
+ long[] stats = new long[2];
+ if (detail != null) {
+ String[] splitResult = detail.split(":");
+ int i = 0;
+ while (i < splitResult.length - 1) {
+ stats[0] += (new Long(splitResult[i++])).longValue();
+ stats[1] += (new Long(splitResult[i++])).longValue();
+ }
+ return new NetworkUsageAnswer(cmd, "success", stats[0], stats[1]);
+ }
+ }
+ return new NetworkUsageAnswer(cmd, "success", 0L, 0L);
+ } catch (Exception ex) {
+ s_logger.warn("Failed to get network usage stats due to ", ex);
+ return new NetworkUsageAnswer(cmd, ex);
+ }
+ }
+
+ protected NetworkUsageAnswer execute(NetworkUsageCommand cmd) {
+ if (cmd.isForVpc()) {
+ return VPCNetworkUsage(cmd);
+ }
+ try {
+ Connection conn = getConnection();
+ if (cmd.getOption() != null && cmd.getOption().equals("create")) {
+ String result = networkUsage(conn, cmd.getPrivateIP(), "create", null);
+ NetworkUsageAnswer answer = new NetworkUsageAnswer(cmd, result, 0L, 0L);
+ return answer;
+ }
+ long[] stats = getNetworkStats(conn, cmd.getPrivateIP());
+ NetworkUsageAnswer answer = new NetworkUsageAnswer(cmd, "", stats[0], stats[1]);
+ return answer;
+ } catch (Exception ex) {
+ s_logger.warn("Failed to get network usage stats due to ", ex);
+ return new NetworkUsageAnswer(cmd, ex);
+ }
+ }
+
+ protected Boolean check_heartbeat(String hostuuid) {
+ com.trilead.ssh2.Connection sshConnection = new com.trilead.ssh2.Connection(_host.ip, 22);
+ try {
+ sshConnection.connect(null, 60000, 60000);
+ if (!sshConnection.authenticateWithPassword(_username, _password.peek())) {
+ throw new CloudRuntimeException("Unable to authenticate");
+ }
+
+ String shcmd = "/opt/cloud/bin/check_heartbeat.sh " + hostuuid + " "
+ + Integer.toString(_heartbeatInterval * 2);
+ if (!SSHCmdHelper.sshExecuteCmd(sshConnection, shcmd)) {
+ s_logger.debug("Heart beat is gone so dead.");
+ return false;
+ }
+ s_logger.debug("Heart beat is still going");
+ return true;
+ } catch (Exception e) {
+ s_logger.debug("health check failed due to catch exception " + e.toString());
+ return null;
+ } finally {
+ sshConnection.close();
+ }
+ }
+
+ protected FenceAnswer execute(FenceCommand cmd) {
+ Connection conn = getConnection();
+ try {
+ Boolean alive = check_heartbeat(cmd.getHostGuid());
+ if ( alive == null ) {
+ s_logger.debug("Failed to check heartbeat, so unable to fence");
+ return new FenceAnswer(cmd, false, "Failed to check heartbeat, so unable to fence");
+ }
+ if ( alive ) {
+ s_logger.debug("Heart beat is still going so unable to fence");
+ return new FenceAnswer(cmd, false, "Heartbeat is still going on unable to fence");
+ }
+ Set<VM> vms = VM.getByNameLabel(conn, cmd.getVmName());
+ for (VM vm : vms) {
+ synchronized (_cluster.intern()) {
+ s_vms.remove(_cluster, _name, vm.getNameLabel(conn));
+ }
+ s_logger.info("Fence command for VM " + cmd.getVmName());
+ vm.powerStateReset(conn);
+ vm.destroy(conn);
+ }
+ return new FenceAnswer(cmd);
+ } catch (XmlRpcException e) {
+ s_logger.warn("Unable to fence", e);
+ return new FenceAnswer(cmd, false, e.getMessage());
+ } catch (XenAPIException e) {
+ s_logger.warn("Unable to fence", e);
+ return new FenceAnswer(cmd, false, e.getMessage());
+ }
+ }
+
+
+ @Override
+ protected boolean transferManagementNetwork(Connection conn, Host host, PIF src, PIF.Record spr, PIF dest) throws XmlRpcException, XenAPIException {
+ dest.reconfigureIp(conn, spr.ipConfigurationMode, spr.IP, spr.netmask, spr.gateway, spr.DNS);
+ Host.managementReconfigure(conn, dest);
+ String hostUuid = null;
+ int count = 0;
+ while (count < 10) {
+ try {
+ Thread.sleep(10000);
+ hostUuid = host.getUuid(conn);
+ if (hostUuid != null) {
+ break;
+ }
+ } catch (XmlRpcException e) {
+ s_logger.debug("Waiting for host to come back: " + e.getMessage());
+ } catch (XenAPIException e) {
+ s_logger.debug("Waiting for host to come back: " + e.getMessage());
+ } catch (InterruptedException e) {
+ s_logger.debug("Gotta run");
+ return false;
+ }
+ }
+ if (hostUuid == null) {
+ s_logger.warn("Unable to transfer the management network from " + spr.uuid);
+ return false;
+ }
+
+ src.reconfigureIp(conn, IpConfigurationMode.NONE, null, null, null, null);
+ return true;
+ }
+
+ @Override
+ public StartupCommand[] initialize() {
+ pingXAPI();
+ StartupCommand[] cmds = super.initialize();
+ return cmds;
+ }
+
+
+ @Override
+ protected CheckOnHostAnswer execute(CheckOnHostCommand cmd) {
+ Boolean alive = check_heartbeat(cmd.getHost().getGuid());
+ String msg = "";
+ if (alive == null) {
+ msg = " cannot determine ";
+ } else if ( alive == true) {
+ msg = "Heart beat is still going";
+ } else {
+ msg = "Heart beat is gone so dead.";
+ }
+ s_logger.debug(msg);
+ return new CheckOnHostAnswer(cmd, alive, msg);
+
+ }
+
+
+ public XenServer56Resource() {
+ super();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a8212d9e/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/XenServer56SP2Resource.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/XenServer56SP2Resource.java b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/XenServer56SP2Resource.java
new file mode 100644
index 0000000..cfe6f15
--- /dev/null
+++ b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/XenServer56SP2Resource.java
@@ -0,0 +1,89 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package com.cloud.hypervisor.xenserver.resource;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.ejb.Local;
+
+import org.apache.log4j.Logger;
+
+import com.cloud.resource.ServerResource;
+import com.cloud.utils.exception.CloudRuntimeException;
+import com.cloud.utils.script.Script;
+
+@Local(value = ServerResource.class)
+public class XenServer56SP2Resource extends XenServer56FP1Resource {
+ private static final Logger s_logger = Logger.getLogger(XenServer56SP2Resource.class);
+
+ public XenServer56SP2Resource() {
+ super();
+ _xsMemoryUsed = 128 * 1024 * 1024L;
+ _xsVirtualizationFactor = 62.0 / 64.0;
+ }
+
+ @Override
+ protected String getGuestOsType(String stdType, boolean bootFromCD) {
+ return CitrixHelper.getXenServer56SP2GuestOsType(stdType, bootFromCD);
+ }
+
+ @Override
+ protected List<File> getPatchFiles() {
+ List<File> files = new ArrayList<File>();
+ String patch = "scripts/vm/hypervisor/xenserver/xenserver56fp1/patch";
+ String patchfilePath = Script.findScript("", patch);
+ if (patchfilePath == null) {
+ throw new CloudRuntimeException("Unable to find patch file " + patch);
+ }
+ File file = new File(patchfilePath);
+ files.add(file);
+ return files;
+ }
+
+ @Override
+ public long getStaticMax(String os, boolean b, long dynamicMinRam, long dynamicMaxRam) {
+ long recommendedValue = CitrixHelper.getXenServer56SP2StaticMax(os, b);
+ if (recommendedValue == 0) {
+ s_logger.warn("No recommended value found for dynamic max, setting static max and dynamic max equal");
+ return dynamicMaxRam;
+ }
+ long staticMax = Math.min(recommendedValue, 4l * dynamicMinRam); // XS constraint for stability
+ if (dynamicMaxRam > staticMax) { // XS contraint that dynamic max <= static max
+ s_logger.warn("dynamixMax " + dynamicMaxRam + " cant be greater than static max " + staticMax +
+ ", can lead to stability issues. Setting static max as much as dynamic max ");
+ return dynamicMaxRam;
+ }
+ return staticMax;
+ }
+
+ @Override
+ public long getStaticMin(String os, boolean b, long dynamicMinRam, long dynamicMaxRam) {
+ long recommendedValue = CitrixHelper.getXenServer56SP2StaticMin(os, b);
+ if (recommendedValue == 0) {
+ s_logger.warn("No recommended value found for dynamic min");
+ return dynamicMinRam;
+ }
+
+ if (dynamicMinRam < recommendedValue) { // XS contraint that dynamic min > static min
+ s_logger.warn("Vm is set to dynamixMin " + dynamicMinRam + " less than the recommended static min " + recommendedValue + ", could lead to stability issues");
+ }
+ return dynamicMinRam;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a8212d9e/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/XenServer600Resource.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/XenServer600Resource.java b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/XenServer600Resource.java
new file mode 100644
index 0000000..c5f762c
--- /dev/null
+++ b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/XenServer600Resource.java
@@ -0,0 +1,87 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package com.cloud.hypervisor.xenserver.resource;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.ejb.Local;
+
+import org.apache.log4j.Logger;
+
+import com.cloud.resource.ServerResource;
+import com.cloud.utils.exception.CloudRuntimeException;
+import com.cloud.utils.script.Script;
+
+@Local(value = ServerResource.class)
+public class XenServer600Resource extends XenServer56SP2Resource {
+ private static final Logger s_logger = Logger.getLogger(XenServer600Resource.class);
+
+ public XenServer600Resource() {
+ super();
+ }
+
+ @Override
+ protected String getGuestOsType(String stdType, boolean bootFromCD) {
+ return CitrixHelper.getXenServer600GuestOsType(stdType, bootFromCD);
+ }
+
+ @Override
+ public long getStaticMax(String os, boolean b, long dynamicMinRam, long dynamicMaxRam) {
+ long recommendedValue = CitrixHelper.getXenServer600StaticMax(os, b);
+ if (recommendedValue == 0) {
+ s_logger.warn("No recommended value found for dynamic max, setting static max and dynamic max equal");
+ return dynamicMaxRam;
+ }
+ long staticMax = Math.min(recommendedValue, 4l * dynamicMinRam); // XS constraint for stability
+ if (dynamicMaxRam > staticMax) { // XS contraint that dynamic max <= static max
+ s_logger.warn("dynamixMax " + dynamicMaxRam + " cant be greater than static max " + staticMax +
+ ", can lead to stability issues. Setting static max as much as dynamic max ");
+ return dynamicMaxRam;
+ }
+ return staticMax;
+ }
+
+ @Override
+ public long getStaticMin(String os, boolean b, long dynamicMinRam, long dynamicMaxRam) {
+ long recommendedValue = CitrixHelper.getXenServer600StaticMin(os, b);
+ if (recommendedValue == 0) {
+ s_logger.warn("No recommended value found for dynamic min");
+ return dynamicMinRam;
+ }
+
+ if (dynamicMinRam < recommendedValue) { // XS contraint that dynamic min > static min
+ s_logger.warn("Vm is set to dynamixMin " + dynamicMinRam + " less than the recommended static min " + recommendedValue + ", could lead to stability issues");
+ }
+ return dynamicMinRam;
+ }
+
+ @Override
+ protected List<File> getPatchFiles() {
+ List<File> files = new ArrayList<File>();
+ String patch = "scripts/vm/hypervisor/xenserver/xenserver60/patch";
+ String patchfilePath = Script.findScript("", patch);
+ if (patchfilePath == null) {
+ throw new CloudRuntimeException("Unable to find patch file " + patch);
+ }
+ File file = new File(patchfilePath);
+ files.add(file);
+ return files;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a8212d9e/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/XenServer602Resource.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/XenServer602Resource.java b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/XenServer602Resource.java
new file mode 100644
index 0000000..f180adb
--- /dev/null
+++ b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/XenServer602Resource.java
@@ -0,0 +1,64 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package com.cloud.hypervisor.xenserver.resource;
+import javax.ejb.Local;
+import org.apache.log4j.Logger;
+import com.cloud.resource.ServerResource;
+
+@Local(value = ServerResource.class)
+public class XenServer602Resource extends XenServer600Resource {
+ private static final Logger s_logger = Logger.getLogger(XenServer602Resource.class);
+
+ public XenServer602Resource() {
+ super();
+ }
+
+ @Override
+ protected String getGuestOsType(String stdType, boolean bootFromCD) {
+ return CitrixHelper.getXenServer602GuestOsType(stdType, bootFromCD);
+ }
+
+ @Override
+ public long getStaticMax(String os, boolean b, long dynamicMinRam, long dynamicMaxRam) {
+ long recommendedValue = CitrixHelper.getXenServer602StaticMax(os, b);
+ if (recommendedValue == 0) {
+ s_logger.warn("No recommended value found for dynamic max, setting static max and dynamic max equal");
+ return dynamicMaxRam;
+ }
+ long staticMax = Math.min(recommendedValue, 4l * dynamicMinRam); // XS constraint for stability
+ if (dynamicMaxRam > staticMax) { // XS contraint that dynamic max <= static max
+ s_logger.warn("dynamixMax " + dynamicMaxRam + " cant be greater than static max " + staticMax +
+ ", can lead to stability issues. Setting static max as much as dynamic max ");
+ return dynamicMaxRam;
+ }
+ return staticMax;
+ }
+
+ @Override
+ public long getStaticMin(String os, boolean b, long dynamicMinRam, long dynamicMaxRam) {
+ long recommendedValue = CitrixHelper.getXenServer602StaticMin(os, b);
+ if (recommendedValue == 0) {
+ s_logger.warn("No recommended value found for dynamic min");
+ return dynamicMinRam;
+ }
+ if (dynamicMinRam < recommendedValue) { // XS contraint that dynamic min > static min
+ s_logger.warn("Vm is set to dynamixMin " + dynamicMinRam + " less than the recommended static min " + recommendedValue + ", could lead to stability issues");
+ }
+ return dynamicMinRam;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a8212d9e/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/XenServer610Resource.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/XenServer610Resource.java b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/XenServer610Resource.java
new file mode 100644
index 0000000..7807f93
--- /dev/null
+++ b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/XenServer610Resource.java
@@ -0,0 +1,437 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package com.cloud.hypervisor.xenserver.resource;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.ejb.Local;
+
+import org.apache.log4j.Logger;
+import org.apache.xmlrpc.XmlRpcException;
+
+import com.xensource.xenapi.Connection;
+import com.xensource.xenapi.Host;
+import com.xensource.xenapi.Network;
+import com.xensource.xenapi.SR;
+import com.xensource.xenapi.Task;
+import com.xensource.xenapi.Types;
+import com.xensource.xenapi.Types.XenAPIException;
+import com.xensource.xenapi.VBD;
+import com.xensource.xenapi.VDI;
+import com.xensource.xenapi.VIF;
+import com.xensource.xenapi.VM;
+
+import org.apache.cloudstack.storage.to.VolumeObjectTO;
+
+import com.cloud.agent.api.Answer;
+import com.cloud.agent.api.Command;
+import com.cloud.agent.api.MigrateWithStorageAnswer;
+import com.cloud.agent.api.MigrateWithStorageCommand;
+import com.cloud.agent.api.MigrateWithStorageCompleteAnswer;
+import com.cloud.agent.api.MigrateWithStorageCompleteCommand;
+import com.cloud.agent.api.MigrateWithStorageReceiveAnswer;
+import com.cloud.agent.api.MigrateWithStorageReceiveCommand;
+import com.cloud.agent.api.MigrateWithStorageSendAnswer;
+import com.cloud.agent.api.MigrateWithStorageSendCommand;
+import com.cloud.agent.api.storage.MigrateVolumeAnswer;
+import com.cloud.agent.api.storage.MigrateVolumeCommand;
+import com.cloud.agent.api.to.DiskTO;
+import com.cloud.agent.api.to.NicTO;
+import com.cloud.agent.api.to.StorageFilerTO;
+import com.cloud.agent.api.to.VirtualMachineTO;
+import com.cloud.agent.api.to.VolumeTO;
+import com.cloud.network.Networks.TrafficType;
+import com.cloud.resource.ServerResource;
+import com.cloud.storage.Volume;
+import com.cloud.utils.exception.CloudRuntimeException;
+import com.cloud.vm.VirtualMachine.State;
+
+@Local(value = ServerResource.class)
+public class XenServer610Resource extends XenServer602Resource {
+ private static final Logger s_logger = Logger.getLogger(XenServer610Resource.class);
+
+ public XenServer610Resource() {
+ super();
+ }
+
+ @Override
+ protected String getGuestOsType(String stdType, boolean bootFromCD) {
+ return CitrixHelper.getXenServer610GuestOsType(stdType, bootFromCD);
+ }
+
+ @Override
+ public Answer executeRequest(Command cmd) {
+ if (cmd instanceof MigrateWithStorageCommand) {
+ return execute((MigrateWithStorageCommand)cmd);
+ } else if (cmd instanceof MigrateWithStorageReceiveCommand) {
+ return execute((MigrateWithStorageReceiveCommand)cmd);
+ } else if (cmd instanceof MigrateWithStorageSendCommand) {
+ return execute((MigrateWithStorageSendCommand)cmd);
+ } else if (cmd instanceof MigrateWithStorageCompleteCommand) {
+ return execute((MigrateWithStorageCompleteCommand)cmd);
+ } else if (cmd instanceof MigrateVolumeCommand) {
+ return execute((MigrateVolumeCommand)cmd);
+ } else {
+ return super.executeRequest(cmd);
+ }
+ }
+
+ private List<VolumeObjectTO> getUpdatedVolumePathsOfMigratedVm(Connection connection, VM migratedVm, DiskTO[] volumes) throws CloudRuntimeException {
+ List<VolumeObjectTO> volumeToList = new ArrayList<VolumeObjectTO>();
+
+ try {
+ // Volume paths would have changed. Return that information.
+ Set<VBD> vbds = migratedVm.getVBDs(connection);
+ Map<String, VDI> deviceIdToVdiMap = new HashMap<String, VDI>();
+ // get vdi:vbdr to a map
+ for (VBD vbd : vbds) {
+ VBD.Record vbdr = vbd.getRecord(connection);
+ if (vbdr.type == Types.VbdType.DISK) {
+ VDI vdi = vbdr.VDI;
+ deviceIdToVdiMap.put(vbdr.userdevice, vdi);
+ }
+ }
+
+ for (DiskTO volumeTo : volumes) {
+ if (volumeTo.getType() != Volume.Type.ISO) {
+ VolumeObjectTO vol = (VolumeObjectTO)volumeTo.getData();
+ Long deviceId = volumeTo.getDiskSeq();
+ VDI vdi = deviceIdToVdiMap.get(deviceId.toString());
+ VolumeObjectTO newVol = new VolumeObjectTO();
+ newVol.setPath(vdi.getUuid(connection));
+ newVol.setId(vol.getId());
+ volumeToList.add(newVol);
+ }
+ }
+ } catch (Exception e) {
+ s_logger.error("Unable to get the updated VDI paths of the migrated vm " + e.toString(), e);
+ throw new CloudRuntimeException("Unable to get the updated VDI paths of the migrated vm " + e.toString(), e);
+ }
+
+ return volumeToList;
+ }
+
+ protected MigrateWithStorageAnswer execute(MigrateWithStorageCommand cmd) {
+ Connection connection = getConnection();
+ VirtualMachineTO vmSpec = cmd.getVirtualMachine();
+ Map<VolumeTO, StorageFilerTO> volumeToFiler = cmd.getVolumeToFiler();
+ final String vmName = vmSpec.getName();
+ State state = s_vms.getState(_cluster, vmName);
+ Task task = null;
+
+ synchronized (_cluster.intern()) {
+ s_vms.put(_cluster, _name, vmName, State.Stopping);
+ }
+
+ try {
+ prepareISO(connection, vmSpec.getName());
+ Map<String, String> other = new HashMap<String, String>();
+ other.put("live", "true");
+ Network networkForSm = getNativeNetworkForTraffic(connection, TrafficType.Storage, null).getNetwork();
+ Host host = Host.getByUuid(connection, _host.uuid);
+ Map<String, String> token = host.migrateReceive(connection, networkForSm, other);
+
+ // Get the vm to migrate.
+ Set<VM> vms = VM.getByNameLabel(connection, vmSpec.getName());
+ VM vmToMigrate = vms.iterator().next();
+
+ // Create the vif map. The vm stays in the same cluster so we have to pass an empty vif map.
+ Map<VIF, Network> vifMap = new HashMap<VIF, Network>();
+ Map<VDI, SR> vdiMap = new HashMap<VDI, SR>();
+ for (Map.Entry<VolumeTO, StorageFilerTO> entry : volumeToFiler.entrySet()) {
+ vdiMap.put(getVDIbyUuid(connection, entry.getKey().getPath()), getStorageRepository(connection, entry.getValue().getUuid()));
+ }
+
+ // Check migration with storage is possible.
+ task = vmToMigrate.assertCanMigrateAsync(connection, token, true, vdiMap, vifMap, other);
+ try {
+ // poll every 1 seconds
+ long timeout = (_migratewait) * 1000L;
+ waitForTask(connection, task, 1000, timeout);
+ checkForSuccess(connection, task);
+ } catch (Types.HandleInvalid e) {
+ s_logger.error("Error while checking if vm " + vmName + " can be migrated to the destination host " + host, e);
+ throw new CloudRuntimeException("Error while checking if vm " + vmName + " can be migrated to the " + "destination host " + host, e);
+ }
+
+ // Migrate now.
+ task = vmToMigrate.migrateSendAsync(connection, token, true, vdiMap, vifMap, other);
+ try {
+ // poll every 1 seconds.
+ long timeout = (_migratewait) * 1000L;
+ waitForTask(connection, task, 1000, timeout);
+ checkForSuccess(connection, task);
+ } catch (Types.HandleInvalid e) {
+ s_logger.error("Error while migrating vm " + vmName + " to the destination host " + host, e);
+ throw new CloudRuntimeException("Error while migrating vm " + vmName + " to the destination host " + host, e);
+ }
+
+ // Volume paths would have changed. Return that information.
+ List<VolumeObjectTO> volumeToList = getUpdatedVolumePathsOfMigratedVm(connection, vmToMigrate, vmSpec.getDisks());
+ vmToMigrate.setAffinity(connection, host);
+ state = State.Stopping;
+
+ return new MigrateWithStorageAnswer(cmd, volumeToList);
+ } catch (Exception e) {
+ s_logger.warn("Catch Exception " + e.getClass().getName() + ". Storage motion failed due to " + e.toString(), e);
+ return new MigrateWithStorageAnswer(cmd, e);
+ } finally {
+ if (task != null) {
+ try {
+ task.destroy(connection);
+ } catch (Exception e) {
+ s_logger.debug("Unable to destroy task " + task.toString() + " on host " + _host.uuid + " due to " + e.toString());
+ }
+ }
+
+ synchronized (_cluster.intern()) {
+ s_vms.put(_cluster, _name, vmName, state);
+ }
+ }
+ }
+
+ protected MigrateWithStorageReceiveAnswer execute(MigrateWithStorageReceiveCommand cmd) {
+ Connection connection = getConnection();
+ VirtualMachineTO vmSpec = cmd.getVirtualMachine();
+ Map<VolumeTO, StorageFilerTO> volumeToFiler = cmd.getVolumeToFiler();
+
+ try {
+ // Get a map of all the SRs to which the vdis will be migrated.
+ Map<VolumeTO, Object> volumeToSr = new HashMap<VolumeTO, Object>();
+ for (Map.Entry<VolumeTO, StorageFilerTO> entry : volumeToFiler.entrySet()) {
+ SR sr = getStorageRepository(connection, entry.getValue().getUuid());
+ volumeToSr.put(entry.getKey(), sr);
+ }
+
+ // Get the list of networks to which the vifs will attach.
+ Map<NicTO, Object> nicToNetwork = new HashMap<NicTO, Object>();
+ for (NicTO nicTo : vmSpec.getNics()) {
+ Network network = getNetwork(connection, nicTo);
+ nicToNetwork.put(nicTo, network);
+ }
+
+ Map<String, String> other = new HashMap<String, String>();
+ other.put("live", "true");
+ Network network = getNativeNetworkForTraffic(connection, TrafficType.Storage, null).getNetwork();
+ Host host = Host.getByUuid(connection, _host.uuid);
+ Map<String, String> token = host.migrateReceive(connection, network, other);
+
+ return new MigrateWithStorageReceiveAnswer(cmd, volumeToSr, nicToNetwork, token);
+ } catch (CloudRuntimeException e) {
+ s_logger.error("Migration of vm " + vmSpec.getName() + " with storage failed due to " + e.toString(), e);
+ return new MigrateWithStorageReceiveAnswer(cmd, e);
+ } catch (Exception e) {
+ s_logger.error("Migration of vm " + vmSpec.getName() + " with storage failed due to " + e.toString(), e);
+ return new MigrateWithStorageReceiveAnswer(cmd, e);
+ }
+ }
+
+ protected MigrateWithStorageSendAnswer execute(MigrateWithStorageSendCommand cmd) {
+ Connection connection = getConnection();
+ VirtualMachineTO vmSpec = cmd.getVirtualMachine();
+ Map<VolumeTO, Object> volumeToSr = cmd.getVolumeToSr();
+ Map<NicTO, Object> nicToNetwork = cmd.getNicToNetwork();
+ Map<String, String> token = cmd.getToken();
+ final String vmName = vmSpec.getName();
+ State state = s_vms.getState(_cluster, vmName);
+ Set<VolumeTO> volumeToSet = null;
+ boolean migrated = false;
+ Task task = null;
+
+ synchronized (_cluster.intern()) {
+ s_vms.put(_cluster, _name, vmName, State.Stopping);
+ }
+
+ try {
+ Set<VM> vms = VM.getByNameLabel(connection, vmSpec.getName());
+ VM vmToMigrate = vms.iterator().next();
+ Map<String, String> other = new HashMap<String, String>();
+ other.put("live", "true");
+
+ // Create the vdi map which tells what volumes of the vm need to go on which sr on the destination.
+ Map<VDI, SR> vdiMap = new HashMap<VDI, SR>();
+ for (Map.Entry<VolumeTO, Object> entry : volumeToSr.entrySet()) {
+ if (entry.getValue() instanceof SR) {
+ SR sr = (SR)entry.getValue();
+ VDI vdi = getVDIbyUuid(connection, entry.getKey().getPath());
+ vdiMap.put(vdi, sr);
+ } else {
+ throw new CloudRuntimeException("The object " + entry.getValue() + " passed is not of type SR.");
+ }
+ }
+
+ // Create the vif map.
+ Map<VIF, Network> vifMap = new HashMap<VIF, Network>();
+ for (Map.Entry<NicTO, Object> entry : nicToNetwork.entrySet()) {
+ if (entry.getValue() instanceof Network) {
+ Network network = (Network)entry.getValue();
+ VIF vif = getVifByMac(connection, vmToMigrate, entry.getKey().getMac());
+ vifMap.put(vif, network);
+ } else {
+ throw new CloudRuntimeException("The object " + entry.getValue() + " passed is not of type Network.");
+ }
+ }
+
+ // Check migration with storage is possible.
+ task = vmToMigrate.assertCanMigrateAsync(connection, token, true, vdiMap, vifMap, other);
+ try {
+ // poll every 1 seconds.
+ long timeout = (_migratewait) * 1000L;
+ waitForTask(connection, task, 1000, timeout);
+ checkForSuccess(connection, task);
+ } catch (Types.HandleInvalid e) {
+ s_logger.error("Error while checking if vm " + vmName + " can be migrated.", e);
+ throw new CloudRuntimeException("Error while checking if vm " + vmName + " can be migrated.", e);
+ }
+
+ // Migrate now.
+ task = vmToMigrate.migrateSendAsync(connection, token, true, vdiMap, vifMap, other);
+ try {
+ // poll every 1 seconds.
+ long timeout = (_migratewait) * 1000L;
+ waitForTask(connection, task, 1000, timeout);
+ checkForSuccess(connection, task);
+ } catch (Types.HandleInvalid e) {
+ s_logger.error("Error while migrating vm " + vmName, e);
+ throw new CloudRuntimeException("Error while migrating vm " + vmName, e);
+ }
+
+ migrated = true;
+ return new MigrateWithStorageSendAnswer(cmd, volumeToSet);
+ } catch (CloudRuntimeException e) {
+ s_logger.error("Migration of vm " + vmName + " with storage failed due to " + e.toString(), e);
+ return new MigrateWithStorageSendAnswer(cmd, e);
+ } catch (Exception e) {
+ s_logger.error("Migration of vm " + vmName + " with storage failed due to " + e.toString(), e);
+ return new MigrateWithStorageSendAnswer(cmd, e);
+ } finally {
+ if (task != null) {
+ try {
+ task.destroy(connection);
+ } catch (Exception e) {
+ s_logger.debug("Unable to destroy task " + task.toString() + " on host " + _host.uuid + " due to " + e.toString());
+ }
+ }
+
+ // Keep cluster/vm sync happy.
+ synchronized (_cluster.intern()) {
+ if (migrated) {
+ s_vms.remove(_cluster, _name, vmName);
+ } else {
+ s_vms.put(_cluster, _name, vmName, state);
+ }
+ }
+ }
+ }
+
+ protected MigrateWithStorageCompleteAnswer execute(MigrateWithStorageCompleteCommand cmd) {
+ Connection connection = getConnection();
+ VirtualMachineTO vmSpec = cmd.getVirtualMachine();
+
+ try {
+ Host host = Host.getByUuid(connection, _host.uuid);
+ Set<VM> vms = VM.getByNameLabel(connection, vmSpec.getName());
+ VM migratedVm = vms.iterator().next();
+
+ // Check the vm is present on the new host.
+ if (migratedVm == null) {
+ throw new CloudRuntimeException("Couldn't find the migrated vm " + vmSpec.getName() + " on the destination host.");
+ }
+
+ // Volume paths would have changed. Return that information.
+ List<VolumeObjectTO> volumeToSet = getUpdatedVolumePathsOfMigratedVm(connection, migratedVm, vmSpec.getDisks());
+ migratedVm.setAffinity(connection, host);
+
+ synchronized (_cluster.intern()) {
+ s_vms.put(_cluster, _name, vmSpec.getName(), State.Running);
+ }
+
+ return new MigrateWithStorageCompleteAnswer(cmd, volumeToSet);
+ } catch (CloudRuntimeException e) {
+ s_logger.error("Migration of vm " + vmSpec.getName() + " with storage failed due to " + e.toString(), e);
+ return new MigrateWithStorageCompleteAnswer(cmd, e);
+ } catch (Exception e) {
+ s_logger.error("Migration of vm " + vmSpec.getName() + " with storage failed due to " + e.toString(), e);
+ return new MigrateWithStorageCompleteAnswer(cmd, e);
+ }
+ }
+
+ protected MigrateVolumeAnswer execute(MigrateVolumeCommand cmd) {
+ Connection connection = getConnection();
+ String volumeUUID = cmd.getVolumePath();
+ StorageFilerTO poolTO = cmd.getPool();
+
+ try {
+ SR destinationPool = getStorageRepository(connection, poolTO.getUuid());
+ VDI srcVolume = getVDIbyUuid(connection, volumeUUID);
+ Map<String, String> other = new HashMap<String, String>();
+ other.put("live", "true");
+
+ // Live migrate the vdi across pool.
+ Task task = srcVolume.poolMigrateAsync(connection, destinationPool, other);
+ long timeout = (_migratewait) * 1000L;
+ waitForTask(connection, task, 1000, timeout);
+ checkForSuccess(connection, task);
+ VDI dvdi = Types.toVDI(task, connection);
+
+ return new MigrateVolumeAnswer(cmd, true, null, dvdi.getUuid(connection));
+ } catch (Exception e) {
+ String msg = "Catch Exception " + e.getClass().getName() + " due to " + e.toString();
+ s_logger.error(msg, e);
+ return new MigrateVolumeAnswer(cmd, false, msg, null);
+ }
+ }
+
+ @Override
+ public long getStaticMax(String os, boolean b, long dynamicMinRam, long dynamicMaxRam) {
+ long recommendedValue = CitrixHelper.getXenServer610StaticMax(os, b);
+ if (recommendedValue == 0) {
+ s_logger.warn("No recommended value found for dynamic max, setting static max and dynamic max equal");
+ return dynamicMaxRam;
+ }
+ long staticMax = Math.min(recommendedValue, 4l * dynamicMinRam); // XS constraint for stability
+ if (dynamicMaxRam > staticMax) { // XS contraint that dynamic max <= static max
+ s_logger.warn("dynamixMax " + dynamicMaxRam + " cant be greater than static max " + staticMax +
+ ", can lead to stability issues. Setting static max as much as dynamic max ");
+ return dynamicMaxRam;
+ }
+ return staticMax;
+ }
+
+ @Override
+ public long getStaticMin(String os, boolean b, long dynamicMinRam, long dynamicMaxRam) {
+ long recommendedValue = CitrixHelper.getXenServer610StaticMin(os, b);
+ if (recommendedValue == 0) {
+ s_logger.warn("No recommended value found for dynamic min");
+ return dynamicMinRam;
+ }
+
+ if (dynamicMinRam < recommendedValue) { // XS contraint that dynamic min > static min
+ s_logger.warn("Vm is set to dynamixMin " + dynamicMinRam + " less than the recommended static min " + recommendedValue + ", could lead to stability issues");
+ }
+ return dynamicMinRam;
+ }
+
+ @Override
+ protected void plugDom0Vif(Connection conn, VIF dom0Vif) throws XmlRpcException, XenAPIException {
+ // do nothing. In xenserver 6.1 and beyond this step isn't needed.
+ }
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a8212d9e/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/XenServer620Resource.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/XenServer620Resource.java b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/XenServer620Resource.java
new file mode 100644
index 0000000..0c8cc0b
--- /dev/null
+++ b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/XenServer620Resource.java
@@ -0,0 +1,108 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package com.cloud.hypervisor.xenserver.resource;
+import com.xensource.xenapi.Connection;
+import com.xensource.xenapi.Host;
+import com.xensource.xenapi.HostPatch;
+import com.xensource.xenapi.PoolPatch;
+import org.apache.cloudstack.hypervisor.xenserver.XenserverConfigs;
+import java.util.Map;
+import java.util.Set;
+
+import javax.ejb.Local;
+
+import org.apache.log4j.Logger;
+
+import com.cloud.agent.api.StartupRoutingCommand;
+import com.cloud.resource.ServerResource;
+
+@Local(value = ServerResource.class)
+public class XenServer620Resource extends XenServer610Resource {
+ private static final Logger s_logger = Logger.getLogger(XenServer620Resource.class);
+
+ public XenServer620Resource() {
+ super();
+ }
+
+ @Override
+ protected String getGuestOsType(String stdType, boolean bootFromCD) {
+ return CitrixHelper.getXenServer620GuestOsType(stdType, bootFromCD);
+ }
+
+ @Override
+ public long getStaticMax(String os, boolean b, long dynamicMinRam, long dynamicMaxRam) {
+ long recommendedValue = CitrixHelper.getXenServer620StaticMax(os, b);
+ if (recommendedValue == 0) {
+ s_logger.warn("No recommended value found for dynamic max, setting static max and dynamic max equal");
+ return dynamicMaxRam;
+ }
+ long staticMax = Math.min(recommendedValue, 4l * dynamicMinRam); // XS constraint for stability
+ if (dynamicMaxRam > staticMax) { // XS contraint that dynamic max <= static max
+ s_logger.warn("dynamixMax " + dynamicMaxRam + " cant be greater than static max " + staticMax +
+ ", can lead to stability issues. Setting static max as much as dynamic max ");
+ return dynamicMaxRam;
+ }
+ return staticMax;
+ }
+
+ @Override
+ public long getStaticMin(String os, boolean b, long dynamicMinRam, long dynamicMaxRam) {
+ long recommendedValue = CitrixHelper.getXenServer620StaticMin(os, b);
+ if (recommendedValue == 0) {
+ s_logger.warn("No recommended value found for dynamic min");
+ return dynamicMinRam;
+ }
+
+ if (dynamicMinRam < recommendedValue) { // XS contraint that dynamic min > static min
+ s_logger.warn("Vm is set to dynamixMin " + dynamicMinRam + " less than the recommended static min " + recommendedValue + ", could lead to stability issues");
+ }
+ return dynamicMinRam;
+ }
+
+ protected boolean hostHasHotFix(Connection conn, String hotFixUuid) {
+ try {
+ Host host = Host.getByUuid(conn, _host.uuid);
+ Host.Record re = host.getRecord(conn);
+ Set<HostPatch> patches = re.patches;
+ PoolPatch poolPatch = PoolPatch.getByUuid(conn, hotFixUuid);
+ for(HostPatch patch : patches) {
+ PoolPatch pp = patch.getPoolPatch(conn);
+ if (pp.equals(poolPatch) && patch.getApplied(conn)) {
+ return true;
+ }
+ }
+ } catch (Exception e) {
+ s_logger.debug("can't get patches information for hotFix: " + hotFixUuid);
+ }
+ return false;
+ }
+
+ protected void fillHostInfo(Connection conn, StartupRoutingCommand cmd) {
+ super.fillHostInfo(conn, cmd);
+ Map<String, String> details = cmd.getHostDetails();
+ Boolean hotFix62ESP1004 = hostHasHotFix(conn, XenserverConfigs.XSHotFix62ESP1004);
+ if( hotFix62ESP1004 != null && hotFix62ESP1004 ) {
+ details.put(XenserverConfigs.XS620HotFix , XenserverConfigs.XSHotFix62ESP1004);
+ } else {
+ Boolean hotFix62ESP1 = hostHasHotFix(conn, XenserverConfigs.XSHotFix62ESP1);
+ if( hotFix62ESP1 != null && hotFix62ESP1 ) {
+ details.put(XenserverConfigs.XS620HotFix , XenserverConfigs.XSHotFix62ESP1);
+ }
+ }
+ cmd.setHostDetails(details);
+ }
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a8212d9e/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/XenServer620SP1Resource.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/XenServer620SP1Resource.java b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/XenServer620SP1Resource.java
new file mode 100644
index 0000000..3584ff2
--- /dev/null
+++ b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/XenServer620SP1Resource.java
@@ -0,0 +1,199 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package com.cloud.hypervisor.xenserver.resource;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+import javax.ejb.Local;
+
+import org.apache.log4j.Logger;
+import org.apache.xmlrpc.XmlRpcException;
+
+import com.cloud.agent.api.Answer;
+import com.cloud.agent.api.Command;
+import com.cloud.agent.api.GetGPUStatsAnswer;
+import com.cloud.agent.api.GetGPUStatsCommand;
+import com.cloud.agent.api.StartCommand;
+import com.cloud.agent.api.StartupRoutingCommand;
+import com.cloud.agent.api.VgpuTypesInfo;
+import com.cloud.agent.api.to.GPUDeviceTO;
+import com.cloud.resource.ServerResource;
+import com.xensource.xenapi.Connection;
+import com.xensource.xenapi.GPUGroup;
+import com.xensource.xenapi.Host;
+import com.xensource.xenapi.PGPU;
+import com.xensource.xenapi.Types.XenAPIException;
+import com.xensource.xenapi.VGPU;
+import com.xensource.xenapi.VGPUType;
+import com.xensource.xenapi.VGPUType.Record;
+import com.xensource.xenapi.VM;
+
+@Local(value=ServerResource.class)
+public class XenServer620SP1Resource extends XenServer620Resource {
+ private static final Logger s_logger = Logger.getLogger(XenServer620SP1Resource.class);
+
+ public XenServer620SP1Resource() {
+ super();
+ }
+
+ @Override
+ public Answer executeRequest(Command cmd) {
+ Class<? extends Command> clazz = cmd.getClass();
+ if (clazz == GetGPUStatsCommand.class) {
+ return execute((GetGPUStatsCommand) cmd);
+ } else {
+ return super.executeRequest(cmd);
+ }
+ }
+
+ protected GetGPUStatsAnswer execute(GetGPUStatsCommand cmd) {
+ Connection conn = getConnection();
+ HashMap<String, HashMap<String, VgpuTypesInfo>> groupDetails = new HashMap<String, HashMap<String, VgpuTypesInfo>>();
+ try {
+ groupDetails = getGPUGroupDetails(conn);
+ } catch (Exception e) {
+ String msg = "Unable to get GPU stats" + e.toString();
+ s_logger.warn(msg, e);
+ }
+ return new GetGPUStatsAnswer(cmd, groupDetails);
+ }
+
+ @Override
+ protected void fillHostInfo(Connection conn, StartupRoutingCommand cmd) {
+ super.fillHostInfo(conn, cmd);
+ try {
+ HashMap<String, HashMap<String, VgpuTypesInfo>> groupDetails = getGPUGroupDetails(conn);
+ cmd.setGpuGroupDetails(groupDetails);
+ } catch (Exception e) {
+ if (s_logger.isDebugEnabled()) {
+ s_logger.debug("Error while getting GPU device info from host " + cmd.getName(), e);
+ }
+ }
+ }
+
+ @Override
+ protected HashMap<String, HashMap<String, VgpuTypesInfo>> getGPUGroupDetails(Connection conn) throws XenAPIException, XmlRpcException {
+ HashMap<String, HashMap<String, VgpuTypesInfo>> groupDetails = new HashMap<String, HashMap<String, VgpuTypesInfo>>();
+ Host host = Host.getByUuid(conn, _host.uuid);
+ Set<PGPU> pgpus = host.getPGPUs(conn);
+ Iterator<PGPU> iter = pgpus.iterator();
+ while (iter.hasNext()) {
+ PGPU pgpu = iter.next();
+ GPUGroup gpuGroup = pgpu.getGPUGroup(conn);
+ Set<VGPUType> enabledVGPUTypes = gpuGroup.getEnabledVGPUTypes(conn);
+ String groupName = gpuGroup.getNameLabel(conn);
+ HashMap<String, VgpuTypesInfo> gpuCapacity = new HashMap<String, VgpuTypesInfo>();
+ if (groupDetails.get(groupName) != null) {
+ gpuCapacity = groupDetails.get(groupName);
+ }
+ // Get remaining capacity of all the enabled VGPU in a PGPU
+ if(enabledVGPUTypes != null) {
+ Iterator<VGPUType> it = enabledVGPUTypes.iterator();
+ while (it.hasNext()) {
+ VGPUType type = it.next();
+ Record record = type.getRecord(conn);
+ Long remainingCapacity = pgpu.getRemainingCapacity(conn, type);
+ Long maxCapacity = pgpu.getSupportedVGPUMaxCapacities(conn).get(type);
+ VgpuTypesInfo entry;
+ if ((entry = gpuCapacity.get(record.modelName)) != null) {
+ remainingCapacity += entry.getRemainingCapacity();
+ maxCapacity += entry.getMaxCapacity();
+ entry.setRemainingCapacity(remainingCapacity);
+ entry.setMaxVmCapacity(maxCapacity);
+ gpuCapacity.put(record.modelName, entry);
+ } else {
+ VgpuTypesInfo vgpuTypeRecord = new VgpuTypesInfo(null, record.modelName, record.framebufferSize, record.maxHeads,
+ record.maxResolutionX, record.maxResolutionY, maxCapacity, remainingCapacity, maxCapacity);
+ gpuCapacity.put(record.modelName, vgpuTypeRecord);
+ }
+ }
+ }
+ groupDetails.put(groupName, gpuCapacity);
+ }
+ return groupDetails;
+ }
+
+ @Override
+ protected void createVGPU(Connection conn, StartCommand cmd, VM vm, GPUDeviceTO gpuDevice) throws XenAPIException, XmlRpcException {
+ if (s_logger.isDebugEnabled()) {
+ s_logger.debug("Creating VGPU of VGPU type [ " + gpuDevice.getVgpuType() + " ] in gpu group" + gpuDevice.getGpuGroup()
+ + " for VM " + cmd.getVirtualMachine().getName());
+ }
+
+ Set<GPUGroup> groups = GPUGroup.getByNameLabel(conn, gpuDevice.getGpuGroup());
+ assert groups.size() == 1 : "Should only have 1 group but found " + groups.size();
+ GPUGroup gpuGroup = groups.iterator().next();
+
+ Set<VGPUType> vgpuTypes = gpuGroup.getEnabledVGPUTypes(conn);
+ Iterator<VGPUType> iter = vgpuTypes.iterator();
+ VGPUType vgpuType = null;
+ while (iter.hasNext()) {
+ VGPUType entry = iter.next();
+ if (entry.getModelName(conn).equals(gpuDevice.getVgpuType())) {
+ vgpuType = entry;
+ }
+ }
+ String device = "0"; // Only allow device = "0" for now, as XenServer supports just a single vGPU per VM.
+ Map<String, String> other_config = new HashMap<String, String>();
+ VGPU.create(conn, vm, gpuGroup, device, other_config, vgpuType);
+
+ if (s_logger.isDebugEnabled()) {
+ s_logger.debug("Created VGPU of VGPU type [ " + gpuDevice.getVgpuType() + " ] for VM " + cmd.getVirtualMachine().getName());
+ }
+ // Calculate and set remaining GPU capacity in the host.
+ cmd.getVirtualMachine().getGpuDevice().setGroupDetails(getGPUGroupDetails(conn));
+ }
+
+ @Override
+ protected String getGuestOsType(String stdType, boolean bootFromCD) {
+ return CitrixHelper.getXenServer620SP1GuestOsType(stdType, bootFromCD);
+ }
+
+ @Override
+ public long getStaticMax(String os, boolean b, long dynamicMinRam, long dynamicMaxRam){
+ long recommendedValue = CitrixHelper.getXenServer620SP1StaticMax(os, b);
+ if(recommendedValue == 0){
+ s_logger.warn("No recommended value found for dynamic max, setting static max and dynamic max equal");
+ return dynamicMaxRam;
+ }
+ long staticMax = Math.min(recommendedValue, 4l * dynamicMinRam); // XS constraint for stability
+ if (dynamicMaxRam > staticMax){ // XS contraint that dynamic max <= static max
+ s_logger.warn("dynamixMax " + dynamicMaxRam + " cant be greater than static max " + staticMax + ", can lead to stability issues. Setting static max as much as dynamic max ");
+ return dynamicMaxRam;
+ }
+ return staticMax;
+ }
+
+ @Override
+ public long getStaticMin(String os, boolean b, long dynamicMinRam, long dynamicMaxRam){
+ long recommendedValue = CitrixHelper.getXenServer620SP1StaticMin(os, b);
+ if(recommendedValue == 0){
+ s_logger.warn("No recommended value found for dynamic min");
+ return dynamicMinRam;
+ }
+
+ if(dynamicMinRam < recommendedValue){ // XS contraint that dynamic min > static min
+ s_logger.warn("Vm is set to dynamixMin " + dynamicMinRam + " less than the recommended static min " + recommendedValue + ", could lead to stability issues");
+ }
+ return dynamicMinRam;
+ }
+}