Updated Branches: refs/heads/4.2 e94ec6b20 -> bab3f0fa0
CLOUDSTACK-4976 merge createVmFromTemplate in XSFP1 to CitrixResourceBase instead of fixing one bug in two different place. Anthony Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/bab3f0fa Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/bab3f0fa Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/bab3f0fa Branch: refs/heads/4.2 Commit: bab3f0fa0f04f8880c41bf30bfa734d3dfbace6f Parents: e94ec6b Author: Anthony Xu <anthony...@citrix.com> Authored: Tue Oct 29 14:01:46 2013 -0700 Committer: Anthony Xu <anthony...@citrix.com> Committed: Tue Oct 29 14:03:42 2013 -0700 ---------------------------------------------------------------------- .../xen/resource/CitrixResourceBase.java | 135 ++++++++++++------- .../xen/resource/XenServer56FP1Resource.java | 133 ------------------ 2 files changed, 86 insertions(+), 182 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/bab3f0fa/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java ---------------------------------------------------------------------- diff --git a/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java b/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java index c6256dc..bd04e02 100644 --- a/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java +++ b/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java @@ -174,6 +174,7 @@ import com.cloud.agent.api.to.VolumeTO; import com.cloud.exception.InternalErrorException; import com.cloud.host.Host.Type; import com.cloud.hypervisor.Hypervisor.HypervisorType; +import com.cloud.hypervisor.xen.resource.CitrixHelper; import com.cloud.network.HAProxyConfigurator; import com.cloud.network.LoadBalancerConfigurator; import com.cloud.network.Networks; @@ -1247,69 +1248,108 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe return vbd; } + + + public long getStaticMax(String os, boolean b, long dynamicMinRam, long dynamicMaxRam){ + return dynamicMaxRam; + } + + public long getStaticMin(String os, boolean b, long dynamicMinRam, long dynamicMaxRam){ + return dynamicMinRam; + } protected VM createVmFromTemplate(Connection conn, VirtualMachineTO vmSpec, Host host) throws XenAPIException, XmlRpcException { String guestOsTypeName = getGuestOsType(vmSpec.getOs(), vmSpec.getBootloader() == BootloaderType.CD); - if ( guestOsTypeName == null ) { - String msg = " Hypervisor " + this.getClass().getName() + " doesn't support guest OS type " + vmSpec.getOs() - + ". you can choose 'Other install media' to run it as HVM"; - s_logger.warn(msg); - throw new CloudRuntimeException(msg); - } Set<VM> templates = VM.getByNameLabel(conn, guestOsTypeName); assert templates.size() == 1 : "Should only have 1 template but found " + templates.size(); - if (!templates.iterator().hasNext()) { - throw new CloudRuntimeException("No matching OS type found for starting a [" + vmSpec.getOs() - + "] VM on host " + host.getHostname(conn)); - } VM template = templates.iterator().next(); - VM vm = template.createClone(conn, vmSpec.getName()); - VM.Record vmr = vm.getRecord(conn); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Created VM " + vmr.uuid + " for " + vmSpec.getName()); + + VM.Record vmr = template.getRecord(conn); + vmr.affinity = host; + vmr.otherConfig.remove("disks"); + vmr.otherConfig.remove("default_template"); + vmr.otherConfig.remove("mac_seed"); + vmr.isATemplate = false; + vmr.nameLabel = vmSpec.getName(); + vmr.actionsAfterCrash = Types.OnCrashBehaviour.DESTROY; + vmr.actionsAfterShutdown = Types.OnNormalExit.DESTROY; + + if (isDmcEnabled(conn, host) && vmSpec.isEnableDynamicallyScaleVm()) { + //scaling is allowed + vmr.memoryStaticMin = getStaticMin(vmSpec.getOs(), vmSpec.getBootloader() == BootloaderType.CD, vmSpec.getMinRam(), vmSpec.getMaxRam()); + vmr.memoryStaticMax = getStaticMax(vmSpec.getOs(), vmSpec.getBootloader() == BootloaderType.CD, vmSpec.getMinRam(), vmSpec.getMaxRam()); + vmr.memoryDynamicMin = vmSpec.getMinRam(); + vmr.memoryDynamicMax = vmSpec.getMaxRam(); + } else { + //scaling disallowed, set static memory target + if (vmSpec.isEnableDynamicallyScaleVm() && !isDmcEnabled(conn, host)) { + s_logger.warn("Host "+ host.getHostname(conn) +" does not support dynamic scaling, so the vm " + vmSpec.getName() + " is not dynamically scalable"); + } + vmr.memoryStaticMin = vmSpec.getMinRam(); + vmr.memoryStaticMax = vmSpec.getMaxRam(); + vmr.memoryDynamicMin = vmSpec.getMinRam(); + vmr.memoryDynamicMax = vmSpec.getMaxRam(); } - for (Console console : vmr.consoles) { - console.destroy(conn); + if (guestOsTypeName.toLowerCase().contains("windows")) { + vmr.VCPUsMax = (long) vmSpec.getCpus(); + } else { + vmr.VCPUsMax = 32L; } - vm.setIsATemplate(conn, false); - vm.setAffinity(conn, host); - vm.removeFromOtherConfig(conn, "disks"); - vm.setNameLabel(conn, vmSpec.getName()); - setMemory(conn, vm, vmSpec.getMinRam(),vmSpec.getMaxRam()); - vm.setVCPUsMax(conn, (long)vmSpec.getCpus()); - vm.setVCPUsAtStartup(conn, (long)vmSpec.getCpus()); + Map<String, String> details = vmSpec.getDetails(); + if ( details != null ) { + String timeoffset = details.get("timeoffset"); + if (timeoffset != null) { + Map<String, String> platform = vmr.platform; + platform.put("timeoffset", timeoffset); + vmr.platform = platform; + } + + String coresPerSocket = details.get("cpu.corespersocket"); + if (coresPerSocket != null) { + Map<String, String> platform = vmr.platform; + platform.put("cores-per-socket", coresPerSocket); + vmr.platform = platform; + } + } + + vmr.VCPUsAtStartup = (long) vmSpec.getCpus(); + vmr.consoles.clear(); + + VM vm = VM.create(conn, vmr); + if (s_logger.isDebugEnabled()) { + s_logger.debug("Created VM " + vm.getUuid(conn) + " for " + vmSpec.getName()); + } Map<String, String> vcpuParams = new HashMap<String, String>(); Integer speed = vmSpec.getMinSpeed(); if (speed != null) { - int cpuWeight = _maxWeight; //cpu_weight - long utilization = 0; // max CPU cap, default is unlimited + int cpuWeight = _maxWeight; // cpu_weight + int utilization = 0; // max CPU cap, default is unlimited - // weight based allocation - cpuWeight = (int)((speed*0.99) / _host.speed * _maxWeight); + // weight based allocation, CPU weight is calculated per VCPU + cpuWeight = (int) ((speed * 0.99) / _host.speed * _maxWeight); if (cpuWeight > _maxWeight) { cpuWeight = _maxWeight; } if (vmSpec.getLimitCpuUse()) { - utilization = ((long)speed * 100 * vmSpec.getCpus()) / _host.speed ; + // CPU cap is per VM, so need to assign cap based on the number of vcpus + utilization = (int) ((speed * 0.99 * vmSpec.getCpus()) / _host.speed * 100); } vcpuParams.put("weight", Integer.toString(cpuWeight)); - vcpuParams.put("cap", Long.toString(utilization)); + vcpuParams.put("cap", Integer.toString(utilization)); + } if (vcpuParams.size() > 0) { vm.setVCPUsParams(conn, vcpuParams); } - vm.setActionsAfterCrash(conn, Types.OnCrashBehaviour.DESTROY); - vm.setActionsAfterShutdown(conn, Types.OnNormalExit.DESTROY); - String bootArgs = vmSpec.getBootArgs(); if (bootArgs != null && bootArgs.length() > 0) { String pvargs = vm.getPVArgs(conn); @@ -1322,36 +1362,32 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe if (!(guestOsTypeName.startsWith("Windows") || guestOsTypeName.startsWith("Citrix") || guestOsTypeName.startsWith("Other"))) { if (vmSpec.getBootloader() == BootloaderType.CD) { - DiskTO [] disks = vmSpec.getDisks(); + DiskTO[] disks = vmSpec.getDisks(); for (DiskTO disk : disks) { - Volume.Type type = disk.getType(); - if (type == Volume.Type.ISO) { - TemplateObjectTO tmpl = (TemplateObjectTO)disk.getData(); - String osType = tmpl.getGuestOsType(); - if (tmpl.getFormat() == ImageFormat.ISO && osType != null ) { - String isoGuestOsName = getGuestOsType(osType, vmSpec.getBootloader() == BootloaderType.CD); - if (!isoGuestOsName.equals(guestOsTypeName)) { - vmSpec.setBootloader(BootloaderType.PyGrub); - } - } + if (disk.getType() == Volume.Type.ISO ) { + TemplateObjectTO iso = (TemplateObjectTO)disk.getData(); + String osType = iso.getGuestOsType(); + if (osType != null) { + String isoGuestOsName = getGuestOsType(osType, vmSpec.getBootloader() == BootloaderType.CD); + if (!isoGuestOsName.equals(guestOsTypeName)) { + vmSpec.setBootloader(BootloaderType.PyGrub); + } + } } } } if (vmSpec.getBootloader() == BootloaderType.CD) { vm.setPVBootloader(conn, "eliloader"); - Map<String, String> otherConfig = vm.getOtherConfig(conn); - if ( ! vm.getOtherConfig(conn).containsKey("install-repository") ) { - otherConfig.put( "install-repository", "cdrom"); + if (!vm.getOtherConfig(conn).containsKey("install-repository")) { + vm.addToOtherConfig(conn, "install-repository", "cdrom"); } - vm.setOtherConfig(conn, otherConfig); - } else if (vmSpec.getBootloader() == BootloaderType.PyGrub ){ + } else if (vmSpec.getBootloader() == BootloaderType.PyGrub) { vm.setPVBootloader(conn, "pygrub"); } else { vm.destroy(conn); throw new CloudRuntimeException("Unable to handle boot loader type: " + vmSpec.getBootloader()); } } - try { finalizeVmMetaData(vm, conn, vmSpec); } catch ( Exception e) { @@ -1359,6 +1395,7 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe } return vm; } + protected void finalizeVmMetaData(VM vm, Connection conn, VirtualMachineTO vmSpec) throws Exception { } http://git-wip-us.apache.org/repos/asf/cloudstack/blob/bab3f0fa/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/XenServer56FP1Resource.java ---------------------------------------------------------------------- diff --git a/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/XenServer56FP1Resource.java b/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/XenServer56FP1Resource.java index 4a9b526..9c65a03 100644 --- a/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/XenServer56FP1Resource.java +++ b/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/XenServer56FP1Resource.java @@ -152,139 +152,6 @@ public class XenServer56FP1Resource extends XenServer56Resource { return dynamicMinRam; } - @Override - protected VM createVmFromTemplate(Connection conn, VirtualMachineTO vmSpec, Host host) throws XenAPIException, XmlRpcException { - String guestOsTypeName = getGuestOsType(vmSpec.getOs(), vmSpec.getBootloader() == BootloaderType.CD); - Set<VM> templates = VM.getByNameLabel(conn, guestOsTypeName); - assert templates.size() == 1 : "Should only have 1 template but found " + templates.size(); - VM template = templates.iterator().next(); - - VM.Record vmr = template.getRecord(conn); - vmr.affinity = host; - vmr.otherConfig.remove("disks"); - vmr.otherConfig.remove("default_template"); - vmr.otherConfig.remove("mac_seed"); - vmr.isATemplate = false; - vmr.nameLabel = vmSpec.getName(); - vmr.actionsAfterCrash = Types.OnCrashBehaviour.DESTROY; - vmr.actionsAfterShutdown = Types.OnNormalExit.DESTROY; - - if (isDmcEnabled(conn, host) && vmSpec.isEnableDynamicallyScaleVm()) { - //scaling is allowed - vmr.memoryStaticMin = getStaticMin(vmSpec.getOs(), vmSpec.getBootloader() == BootloaderType.CD, vmSpec.getMinRam(), vmSpec.getMaxRam()); - vmr.memoryStaticMax = getStaticMax(vmSpec.getOs(), vmSpec.getBootloader() == BootloaderType.CD, vmSpec.getMinRam(), vmSpec.getMaxRam()); - vmr.memoryDynamicMin = vmSpec.getMinRam(); - vmr.memoryDynamicMax = vmSpec.getMaxRam(); - } else { - //scaling disallowed, set static memory target - if (vmSpec.isEnableDynamicallyScaleVm() && !isDmcEnabled(conn, host)) { - s_logger.warn("Host "+ host.getHostname(conn) +" does not support dynamic scaling, so the vm " + vmSpec.getName() + " is not dynamically scalable"); - } - vmr.memoryStaticMin = vmSpec.getMinRam(); - vmr.memoryStaticMax = vmSpec.getMaxRam(); - vmr.memoryDynamicMin = vmSpec.getMinRam(); - vmr.memoryDynamicMax = vmSpec.getMaxRam(); - } - - if (guestOsTypeName.toLowerCase().contains("windows")) { - vmr.VCPUsMax = (long) vmSpec.getCpus(); - } else { - vmr.VCPUsMax = 32L; - } - - Map<String, String> details = vmSpec.getDetails(); - if ( details != null ) { - String timeoffset = details.get("timeoffset"); - if (timeoffset != null) { - Map<String, String> platform = vmr.platform; - platform.put("timeoffset", timeoffset); - vmr.platform = platform; - } - - String coresPerSocket = details.get("cpu.corespersocket"); - if (coresPerSocket != null) { - Map<String, String> platform = vmr.platform; - platform.put("cores-per-socket", coresPerSocket); - vmr.platform = platform; - } - } - - vmr.VCPUsAtStartup = (long) vmSpec.getCpus(); - vmr.consoles.clear(); - - VM vm = VM.create(conn, vmr); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Created VM " + vm.getUuid(conn) + " for " + vmSpec.getName()); - } - - Map<String, String> vcpuParams = new HashMap<String, String>(); - - Integer speed = vmSpec.getMinSpeed(); - if (speed != null) { - - int cpuWeight = _maxWeight; // cpu_weight - int utilization = 0; // max CPU cap, default is unlimited - - // weight based allocation, CPU weight is calculated per VCPU - cpuWeight = (int) ((speed * 0.99) / _host.speed * _maxWeight); - if (cpuWeight > _maxWeight) { - cpuWeight = _maxWeight; - } - - if (vmSpec.getLimitCpuUse()) { - // CPU cap is per VM, so need to assign cap based on the number of vcpus - utilization = (int) ((speed * 0.99 * vmSpec.getCpus()) / _host.speed * 100); - } - - vcpuParams.put("weight", Integer.toString(cpuWeight)); - vcpuParams.put("cap", Integer.toString(utilization)); - - } - - if (vcpuParams.size() > 0) { - vm.setVCPUsParams(conn, vcpuParams); - } - - String bootArgs = vmSpec.getBootArgs(); - if (bootArgs != null && bootArgs.length() > 0) { - String pvargs = vm.getPVArgs(conn); - pvargs = pvargs + vmSpec.getBootArgs().replaceAll(" ", "%"); - if (s_logger.isDebugEnabled()) { - s_logger.debug("PV args are " + pvargs); - } - vm.setPVArgs(conn, pvargs); - } - - if (!(guestOsTypeName.startsWith("Windows") || guestOsTypeName.startsWith("Citrix") || guestOsTypeName.startsWith("Other"))) { - if (vmSpec.getBootloader() == BootloaderType.CD) { - DiskTO[] disks = vmSpec.getDisks(); - for (DiskTO disk : disks) { - if (disk.getType() == Volume.Type.ISO ) { - TemplateObjectTO iso = (TemplateObjectTO)disk.getData(); - String osType = iso.getGuestOsType(); - if (osType != null) { - String isoGuestOsName = getGuestOsType(osType, vmSpec.getBootloader() == BootloaderType.CD); - if (!isoGuestOsName.equals(guestOsTypeName)) { - vmSpec.setBootloader(BootloaderType.PyGrub); - } - } - } - } - } - if (vmSpec.getBootloader() == BootloaderType.CD) { - vm.setPVBootloader(conn, "eliloader"); - if (!vm.getOtherConfig(conn).containsKey("install-repository")) { - vm.addToOtherConfig(conn, "install-repository", "cdrom"); - } - } else if (vmSpec.getBootloader() == BootloaderType.PyGrub) { - vm.setPVBootloader(conn, "pygrub"); - } else { - vm.destroy(conn); - throw new CloudRuntimeException("Unable to handle boot loader type: " + vmSpec.getBootloader()); - } - } - return vm; - } /** * When Dynamic Memory Control (DMC) is enabled -