public VM createVmFromTemplate(final Connection conn, final VirtualMachineTO vmSpec, final Host host) throws XenAPIException, XmlRpcException { final String guestOsTypeName = getGuestOsType(vmSpec.getPlatformEmulator()); final Set<VM> templates = VM.getByNameLabel(conn, guestOsTypeName); if (templates == null || templates.isEmpty()) { vmr.otherConfig.remove("mac_seed"); vmr.isATemplate = false; vmr.nameLabel = vmSpec.getName(); vmr.actionsAfterCrash = Types.OnCrashBehaviour.DESTROY; vmr.actionsAfterShutdown = Types.OnNormalExit.DESTROY; vmr.otherConfig.put("vm_uuid", vmSpec.getUuid()); vmr.VCPUsMax = (long)vmSpec.getCpus(); // FIX ME: In case of dynamic Map<String, String> guestOsDetails = vmSpec.getGuestOsDetails(); if (isDmcEnabled(conn, host) && vmSpec.isEnableDynamicallyScaleVm()) { vmr.memoryStaticMin = getStaticMin(vmSpec.getOs(), vmSpec.getBootloader() == BootloaderType.CD, vmSpec.getMinRam(), vmSpec.getMaxRam(), recommendedMemoryMin); vmr.memoryStaticMax = getStaticMax(vmSpec.getOs(), vmSpec.getBootloader() == BootloaderType.CD, vmSpec.getMinRam(), vmSpec.getMaxRam(), recommendedMemoryMax); vmr.memoryDynamicMin = vmSpec.getMinRam(); vmr.memoryDynamicMax = vmSpec.getMaxRam(); if (guestOsTypeName.toLowerCase().contains("windows")) { vmr.VCPUsMax = (long)vmSpec.getCpus(); } else { if (vmSpec.getVcpuMaxLimit() != null) { vmr.VCPUsMax = (long)vmSpec.getVcpuMaxLimit(); 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");
@Override public boolean replugNic(final Network network, final NicTO nic, final VirtualMachineTO vm, final ReservationContext context, final DeployDestination dest) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { boolean result = true; final VMInstanceVO router = _vmDao.findById(vm.getId()); if (router.getState() == State.Running) { try { final ReplugNicCommand replugNicCmd = new ReplugNicCommand(nic, vm.getName(), vm.getType(), vm.getDetails()); final Commands cmds = new Commands(Command.OnError.Stop); cmds.addCommand("replugnic", replugNicCmd); _agentMgr.send(dest.getHost().getId(), cmds); final ReplugNicAnswer replugNicAnswer = cmds.getAnswer(ReplugNicAnswer.class); if (replugNicAnswer == null || !replugNicAnswer.getResult()) { s_logger.warn("Unable to replug nic for vm " + vm.getName()); result = false; } } catch (final OperationTimedoutException e) { throw new AgentUnavailableException("Unable to plug nic for router " + vm.getName() + " in network " + network, dest.getHost().getId(), e); } } else { s_logger.warn("Unable to apply ReplugNic, vm " + router + " is not in the right state " + router.getState()); throw new ResourceUnavailableException("Unable to apply ReplugNic on the backend," + " vm " + vm + " is not in the right state", DataCenter.class, router.getDataCenterId()); } return result; }
@Override public VirtualMachineTO implement(VirtualMachineProfile vm) { VirtualMachineTO to = toVirtualMachineTO(vm); VMInstanceVO vo = _vmDao.findById(vm.getId()); if (vo.getLastHostId() == null) { to.setBootArgs(BaremetalManager.DO_PXE); } Map<String, String> details = new HashMap<String, String>(); details.put("template", vm.getTemplate().getUrl()); to.setDetails(details); // Determine the VM's OS description GuestOSVO guestOS = _guestOsDao.findById(vm.getVirtualMachine().getGuestOSId()); to.setOs(guestOS.getDisplayName()); return to; }
private void addExtraConfig(VirtualMachineTO vmTO) { Map<String, String> details = vmTO.getDetails(); for (String key : details.keySet()) { if (key.startsWith(ApiConstants.EXTRA_CONFIG)) { vmTO.addExtraConfig(key, details.get(key)); } } }
protected void applySpecToVm(OvmVm.Details vm, VirtualMachineTO spec) { vm.name = spec.getName(); vm.memory = spec.getMinRam(); vm.cpuNum = spec.getCpus(); vm.uuid = UUID.nameUUIDFromBytes(spec.getName().getBytes()).toString(); if (spec.getBootloader() == BootloaderType.CD) { vm.bootDev = OvmVm.CD; vm.type = OvmVm.HVM; } else { vm.bootDev = OvmVm.HDD; String osType = OvmHelper.getOvmGuestType(spec.getOs()); if (OvmHelper.ORACLE_LINUX.equals(osType)) { vm.type = OvmVm.PV; } else if (OvmHelper.WINDOWS.equals(osType) || OvmHelper.ORACLE_SOLARIS.equals(osType)) { vm.type = OvmVm.HVM; } else { throw new CloudRuntimeException(spec.getOs() + " is not supported" + ",Oracle VM only supports Oracle Linux and Windows"); } } }
@Override public synchronized StartAnswer execute(StartCommand cmd) { VirtualMachineTO vmSpec = cmd.getVirtualMachine(); String vmName = vmSpec.getName(); State state = State.Stopped; Xen xen = new Xen(c); vm.setVmCpus(vmSpec.getCpus()); vm.setVmMemory(vmSpec.getMinRam() / 1024 / 1024); vm.setVmUuid(UUID.nameUUIDFromBytes(vmSpec.getName().getBytes(Charset.defaultCharset())).toString()); vm.setVmName(vmName); String domType = guesttypes.getOvm3GuestType(vmSpec.getOs()); if (domType == null || domType.isEmpty()) { domType = "default"; LOGGER.debug("VM Virt type missing setting to: " + domType); } else { LOGGER.debug("VM Virt type set to " + domType + " for " + vmSpec.getOs()); if (vmSpec.getBootloader() == BootloaderType.CD) { LOGGER.warn("CD booting is not supported"); if (vmSpec.getType() != VirtualMachine.Type.User) { vm.setVmExtra(vmSpec.getBootArgs().replace(" ", "%")); String svmPath = configuration.getAgentOvmRepoPath() + "/" + ovmObject.deDash(vm.getPrimaryPoolUuid()) + "/ISOs"; String svmIso = svmPath + "/" + storagepool.getSystemVMPatchIsoFile().getName(); vm.setVnc("0.0.0.0", vmSpec.getVncPassword());
public LibvirtVMDef createVMFromSpec(final VirtualMachineTO vmTO) { final LibvirtVMDef vm = new LibvirtVMDef(); vm.setDomainName(vmTO.getName()); String uuid = vmTO.getUuid(); uuid = getUuid(uuid); vm.setDomUUID(uuid); vm.setDomDescription(vmTO.getOs()); vm.setPlatformEmulator(vmTO.getPlatformEmulator()); Map<String, String> extraConfig = vmTO.getExtraConfig(); if (dpdkSupport && (!extraConfig.containsKey(DPDK_NUMA) || !extraConfig.containsKey(DPDK_HUGE_PAGES))) { s_logger.info("DPDK is enabled but it needs extra configurations for CPU NUMA and Huge Pages for VM deployment"); if (HypervisorType.LXC == _hypervisorType && VirtualMachine.Type.User == vmTO.getType()) { guest.setGuestArch(vmTO.getArch()); guest.setMachineType("pc"); guest.setUuid(uuid); if (vmTO.getMinRam() != vmTO.getMaxRam() && !_noMemBalloon) { grd.setMemBalloning(true); grd.setCurrentMem(vmTO.getMinRam() / 1024); grd.setMemorySize(vmTO.getMaxRam() / 1024); } else { grd.setMemorySize(vmTO.getMaxRam() / 1024); final int vcpus = vmTO.getCpus(); grd.setVcpuNum(vcpus); vm.addComp(grd);
final Connection conn = citrixResourceBase.getConnection(); final VirtualMachineTO vmSpec = command.getVirtualMachine(); final String vmName = vmSpec.getName(); VmPowerState state = VmPowerState.HALTED; VM vm = null; final GPUDeviceTO gpuDevice = vmSpec.getGpuDevice(); if (gpuDevice != null) { s_logger.debug("Creating VGPU for of VGPU type: " + gpuDevice.getVgpuType() + " in GPU group " + gpuDevice.getGpuGroup() + " for VM " + vmName); if (vmSpec.getType() != VirtualMachine.Type.User) { citrixResourceBase.createPatchVbd(conn, vmName, vm); List<DiskTO> disks = new ArrayList<DiskTO>(vmSpec.getDisks().length); int index = 0; for (final DiskTO disk : vmSpec.getDisks()) { if (Volume.Type.ISO.equals(disk.getType())) { disks.add(0, disk); final VDI newVdi = citrixResourceBase.prepareManagedDisk(conn, disk, vmSpec.getId(), vmSpec.getName()); citrixResourceBase.createVbd(conn, disk, vmName, vm, vmSpec.getBootloader(), newVdi); for (final NicTO nic : vmSpec.getNics()) { citrixResourceBase.createVif(conn, vmName, vm, vmSpec, nic); for (final NicTO nic : vmSpec.getNics()) { if (nic.getBroadcastType() == Networks.BroadcastDomainType.Vswitch) { final HashMap<String, String> args = citrixResourceBase.parseDefaultOvsRuleComamnd(BroadcastDomainType.getValue(nic.getBroadcastUri()));
@Override public Answer execute(final StartCommand command, final LibvirtComputingResource libvirtComputingResource) { final VirtualMachineTO vmSpec = command.getVirtualMachine(); vmSpec.setVncAddr(command.getHostIp()); final String vmName = vmSpec.getName(); LibvirtVMDef vm = null; conn = libvirtUtilitiesHelper.getConnectionByType(vm.getHvsType()); final NicTO[] nics = vmSpec.getNics(); if (vmSpec.getType() != VirtualMachine.Type.User) { nic.setPxeDisable(true); nic.setDpdkDisabled(true); if (vmSpec.getType() != VirtualMachine.Type.User) { libvirtComputingResource.configureDefaultNetworkRulesForSystemVm(conn, vmName); break; secIpsStr = "0;"; libvirtComputingResource.defaultNetworkRules(conn, vmName, nic, vmSpec.getId(), secIpsStr); if (vmSpec.getType() != VirtualMachine.Type.User) { libvirtComputingResource.passCmdLine(vmName, vmSpec.getBootArgs());
final Long newDynamicMemoryMin = vmSpec.getMinRam(); final Long newDynamicMemoryMax = vmSpec.getMaxRam(); if (staticMemoryMin > newDynamicMemoryMin || newDynamicMemoryMax > staticMemoryMax) { throw new CloudRuntimeException("Cannot scale up the vm because of memory constraint violation: " + "0 <= memory-static-min(" + staticMemoryMin + ") <= memory-dynamic-min(" vm.setVCPUsNumberLive(conn, (long)vmSpec.getCpus()); final Integer speed = vmSpec.getMinSpeed(); if (speed != null) { if (vmSpec.getLimitCpuUse()) { long utilization = 0; // max CPU cap, default is unlimited utilization = (int)(vmSpec.getMaxSpeed() * 0.99 * vmSpec.getCpus() / _host.getSpeed() * 100); callHostPlugin(conn, "vmops", "add_to_VCPUs_params_live", "key", "cap", "value", Long.toString(utilization), "vmname", vmSpec.getName()); callHostPlugin(conn, "vmops", "add_to_VCPUs_params_live", "key", "weight", "value", Integer.toString(cpuWeight), "vmname", vmSpec.getName());
@Override public synchronized StartAnswer execute(StartCommand cmd) { VirtualMachineTO vmSpec = cmd.getVirtualMachine(); String vmName = vmSpec.getName(); OvmVm.Details vmDetails = null; try { vmDetails = new OvmVm.Details(); applySpecToVm(vmDetails, vmSpec); createVbds(vmDetails, vmSpec); createVifs(vmDetails, vmSpec); startVm(vmDetails); // Add security group rules NicTO[] nics = vmSpec.getNics(); for (NicTO nic : nics) { if (nic.isSecurityGroupEnabled()) { if (vmSpec.getType().equals(VirtualMachine.Type.User)) { defaultNetworkRulesForUserVm(vmName, vmSpec.getId(), nic); } } } return new StartAnswer(cmd); } catch (Exception e) { s_logger.debug("Start vm " + vmName + " failed", e); cleanup(vmDetails); return new StartAnswer(cmd, e.getMessage()); } }
int minspeed = (int)(offering.getSpeed() / vmProfile.getCpuOvercommitRatio()); int maxspeed = (offering.getSpeed()); VirtualMachineTO to = new VirtualMachineTO(vm.getId(), vm.getInstanceName(), vm.getType(), offering.getCpu(), minspeed, maxspeed, minMemory * 1024l * 1024l, offering.getRamSize() * 1024l * 1024l, null, null, vm.isHaEnabled(), vm.limitCpuUse(), vm.getVncPassword()); to.setBootArgs(vmProfile.getBootArgs()); to.setNics(nics); to.setDisks(vmProfile.getDisks().toArray(new DiskTO[vmProfile.getDisks().size()])); to.setArch("i686"); } else { to.setArch("x86_64"); to.setDetails(detailsInVm); if ((offeringDetail = _serviceOfferingDetailsDao.findDetail(offering.getId(), GPU.Keys.vgpuType.toString())) != null) { ServiceOfferingDetailsVO groupName = _serviceOfferingDetailsDao.findDetail(offering.getId(), GPU.Keys.pciDevice.toString()); to.setGpuDevice(_resourceMgr.getGPUDevice(vm.getHostId(), groupName.getValue(), offeringDetail.getValue())); VMInstanceVO vmInstance = _virtualMachineDao.findById(to.getId()); to.setEnableDynamicallyScaleVm(isDynamicallyScalable); to.setUuid(vmInstance.getUuid()); to.setVmData(vmProfile.getVmData()); to.setConfigDriveLabel(vmProfile.getConfigDriveLabel()); to.setConfigDriveIsoRootFolder(vmProfile.getConfigDriveIsoRootFolder()); to.setConfigDriveIsoFile(vmProfile.getConfigDriveIsoFile()); to.setState(vm.getState());
final VirtualMachineTO vmSpec = command.getVirtualMachine(); final List<Pair<VolumeTO, StorageFilerTO>> volumeToFiler = command.getVolumeToFilerAsList(); final String vmName = vmSpec.getName(); Task task = null; for (final NicTO nicTo : vmSpec.getNics()) { xenServer610Resource.getNetwork(connection, nicTo); final Set<VM> vms = VM.getByNameLabel(connection, vmSpec.getName()); final VM vmToMigrate = vms.iterator().next(); final List<VolumeObjectTO> volumeToList = xenServer610Resource.getUpdatedVolumePathsOfMigratedVm(connection, vmToMigrate, vmSpec.getDisks()); vmToMigrate.setAffinity(connection, host); return new MigrateWithStorageAnswer(command, volumeToList);
NicTO[] nics = to.getNics(); to.setNics(expandedNics); for(NicTO nicTo : sortNicsByDeviceId(to.getNics())) { sbMacSequence.append(nicTo.getMac()).append("|"); String bootArgs = to.getBootArgs(); to.setBootArgs(bootArgs + " nic_macs=" + sbMacSequence.toString()); to.setOs(guestOS.getDisplayName());
@Override public MockVm createVmFromSpec(VirtualMachineTO vmSpec) { String vmName = vmSpec.getName(); long ramSize = vmSpec.getMinRam(); int utilizationPercent = randSeed.nextInt() % 100; MockVm vm = null; synchronized (this) { vm = vms.get(vmName); if (vm == null) { if (ramSize > getHostFreeMemory()) { s_logger.debug("host is out of memory"); throw new CloudRuntimeException("Host is out of Memory"); } int vncPort = allocVncPort(); if (vncPort < 0) { s_logger.debug("Unable to allocate VNC port"); throw new CloudRuntimeException("Unable to allocate vnc port"); } vm = new MockVm(vmName, State.Running, ramSize, vmSpec.getCpus(), utilizationPercent, vncPort); vms.put(vmName, vm); } } return vm; }
List<String[]> vmDataList = vm.getVmData(); String configDriveLabel = vm.getConfigDriveLabel(); final NicTO[] nics = vm.getNics(); try { citrixResourceBase.prepareISO(conn, vm.getName(), vmDataList, configDriveLabel); s_logger.debug("4. The VM " + vm.getName() + " is in Migrating state");
VMInstanceVO vmInstance = _vmDao.findById(vmTO.getId()); vmTO.setState(vmInstance.getState()); List<MigrateDiskInfo> migrateDiskInfoList = new ArrayList<MigrateDiskInfo>(); VMInstanceVO vm = _vmDao.findById(vmTO.getId()); boolean isWindows = _guestOsCategoryDao.findById(_guestOsDao.findById(vm.getGuestOSId()).getCategoryId()).getName().equalsIgnoreCase("Windows"); MigrateCommand migrateCommand = new MigrateCommand(vmTO.getName(), destHost.getPrivateIpAddress(), isWindows, vmTO, true);