use of com.cloud.model.enumeration.BootOrder in project cosmic by MissionCriticalCloud.
the class LibvirtComputingResource method createVmFromSpec.
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("This VM is optimised for: " + vmTo.getOptimiseFor().toString());
vm.setPlatformEmulator(vmTo.getPlatformEmulator());
final MetadataTO metadataTo = vmTo.getMetadata();
if (metadataTo != null) {
final MetadataDef metadata = new MetadataDef();
metadata.getNodes().put("cosmicDomainUuid", metadataTo.getDomainUuid());
metadata.getNodes().put("cosmicDomainName", metadataTo.getCosmicDomainName());
metadata.getNodes().put("cosmicDomainPath", metadataTo.getCosmicDomainPath());
metadata.getNodes().put("cosmicInternalVmId", metadataTo.getVmId());
metadata.getNodes().put("cosmicInstanceName", metadataTo.getInstanceName());
metadata.getNodes().put("cosmicXmlGeneratedInCosmicVersion", LibvirtComputingResource.class.getPackage().getImplementationVersion());
metadata.getNodes().put("cosmicXmlGeneratedDateTime", getCurrentLocalDateTimeStamp());
metadata.getNodes().put("cosmicXmlGeneratedEpoch", getCurrentEpoch());
metadata.getNodes().put("cosmicVmHostname", metadataTo.getHostname());
metadata.getNodes().put("cosmicOptimiseFor", vmTo.getOptimiseFor().toString());
final List<String> vpcNameList = metadataTo.getVpcNameList();
if (vpcNameList != null) {
for (final String vpcName : vpcNameList) {
metadata.getNodes().put("cosmicVPC", vpcName);
}
}
final Map<String, String> vmTags = metadataTo.getResourceTags();
if (vmTags != null) {
for (Map.Entry<String, String> vmTag : vmTags.entrySet()) {
metadata.getNodes().put("cosmicTag_" + vmTag.getKey(), vmTag.getValue());
}
}
vm.addComponent(metadata);
}
final GuestDef guest = new GuestDef();
guest.setGuestType(LibvirtVmDef.GuestType.KVM);
vm.setHvsType(HypervisorType.KVM.toString().toLowerCase());
vm.setLibvirtVersion(this.hypervisorLibvirtVersion);
vm.setQemuVersion(this.hypervisorQemuVersion);
guest.setGuestArch(vmTo.getArch());
guest.setMachineType("pc");
guest.setUuid(uuid);
guest.setManufacturer(vmTo.getManufacturer());
guest.setBootMenuTimeout(vmTo.getBootMenuTimeout());
if (vmTo.getBootOrder() != null) {
for (BootOrder device : vmTo.getBootOrder()) {
guest.setBootOrder(device);
}
} else {
guest.setBootOrder(BootOrder.CDROM);
guest.setBootOrder(BootOrder.HARDDISK);
}
vm.addComponent(guest);
final GuestResourceDef grd = new GuestResourceDef();
if (vmTo.getMinRam() != vmTo.getMaxRam() && !this.libvirtComputingResourceProperties.getVmMemballoonDisable()) {
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.addComponent(grd);
final CpuModeDef cmd = new CpuModeDef();
cmd.setMode(getGuestCpuMode());
cmd.setModel(getGuestCpuModel());
cmd.setCpuflags(vmTo.getCpuflags());
if (vmTo.getType() == VirtualMachineType.User) {
cmd.setFeatures(getCpuFeatures());
}
// But only when maintenance policy is live migrate
if (OptimiseFor.Windows.equals(vmTo.getOptimiseFor()) && MaintenancePolicy.LiveMigrate.equals(vmTo.getMaintenancePolicy())) {
String extended_cpu_flags = vmTo.getCpuflags();
if (extended_cpu_flags == null) {
extended_cpu_flags = "-hypervisor";
} else {
extended_cpu_flags += " -hypervisor";
}
cmd.setCpuflags(extended_cpu_flags);
}
// multi cores per socket, for larger core configs
if (vcpus % 6 == 0) {
final int sockets = vcpus / 6;
cmd.setTopology(6, sockets);
} else if (vcpus % 4 == 0) {
final int sockets = vcpus / 4;
cmd.setTopology(4, sockets);
}
vm.addComponent(cmd);
final CpuTuneDef ctd = new CpuTuneDef();
if (VirtualMachineType.DomainRouter.equals(vmTo.getType())) {
ctd.setShares(vmTo.getCpus() * this.libvirtComputingResourceProperties.getGuestCpuSharesRouter());
} else {
ctd.setShares(vmTo.getCpus() * this.libvirtComputingResourceProperties.getGuestCpuShares());
}
vm.addComponent(ctd);
final FeaturesDef features = new FeaturesDef();
features.addFeature("pae");
features.addFeature("apic");
features.addFeature("acpi");
vm.addComponent(features);
if (vmTo.getOptimiseFor() == OptimiseFor.Windows) {
final HyperVEnlightenmentFeatureDef hyperVFeatures = new HyperVEnlightenmentFeatureDef();
hyperVFeatures.addFeature("relaxed", true);
hyperVFeatures.addFeature("vapic", true);
hyperVFeatures.addFeature("spinlocks", true);
hyperVFeatures.setRetries(8191);
features.addHyperVFeature(hyperVFeatures);
}
final TermPolicy term = new TermPolicy();
if (VirtualMachineType.User.equals(vmTo.getType())) {
term.setCrashPolicy(getVmTermpolicyCrash());
term.setPowerOffPolicy(getVmTermpolicyPowerOff());
term.setRebootPolicy(getVmTermpolicyReboot());
} else {
term.setCrashPolicy(getSystemTermpolicyCrash());
term.setPowerOffPolicy(getSystemTermpolicyPowerOff());
term.setRebootPolicy(getSystemTermpolicyReboot());
}
vm.addComponent(term);
final ClockDef clock = new ClockDef();
Boolean kvmClockEnabled = !isKvmClockDisabled();
Boolean hypervClockEnabled = false;
Boolean trackGuest = false;
if (vmTo.getOptimiseFor() == OptimiseFor.Windows) {
clock.setClockOffset(ClockDef.ClockOffset.LOCALTIME);
kvmClockEnabled = false;
hypervClockEnabled = true;
trackGuest = true;
}
clock.addTimer("kvmclock", null, kvmClockEnabled, false);
clock.addTimer("hypervclock", null, hypervClockEnabled, false);
// Recommended default clock/timer settings - https://bugzilla.redhat.com/show_bug.cgi?id=1053847
// Important note for track="guest" in Windows VMs:
// https://docs.fedoraproject.org/en-US/Fedora_Draft_Documentation/0
// .1/html/Virtualization_Deployment_and_Administration_Guide/sect-Virtualization-Tips_and_tricks-Libvirt_Managed_Timers.html
clock.addTimer("rtc", "catchup", true, trackGuest);
clock.addTimer("pit", "delay", true, false);
clock.addTimer("hpet", null, false, false);
vm.addComponent(clock);
final DevicesDef devices = new DevicesDef();
devices.setEmulatorPath(this.hypervisorPath);
devices.setGuestType(guest.getGuestType());
final SerialDef serial = new SerialDef("pty", null, (short) 0);
devices.addDevice(serial);
final QemuGuestAgentDef guestagent = new QemuGuestAgentDef();
devices.addDevice(guestagent);
if (this.libvirtComputingResourceProperties.getVmRngEnable()) {
final RngDef rngDevice = new RngDef(this.rngPath, this.rngBackendModel);
devices.addDevice(rngDevice);
}
final WatchDogDef watchDog = new WatchDogDef(this.libvirtComputingResourceProperties.getVmWatchdogAction(), this.libvirtComputingResourceProperties.getVmWatchdogModel());
devices.addDevice(watchDog);
final VideoDef videoCard = new VideoDef(this.libvirtComputingResourceProperties.getVmVideoHardware(), this.libvirtComputingResourceProperties.getVmVideoRam());
devices.addDevice(videoCard);
final ConsoleDef console = new ConsoleDef("pty", null, null, (short) 0);
devices.addDevice(console);
// add the VNC port passwd here, get the passwd from the vmInstance.
final String passwd = vmTo.getVncPassword();
final GraphicDef grap = new GraphicDef("vnc", (short) 0, true, passwd, null);
devices.addDevice(grap);
final InputDef input = new InputDef("tablet", "usb");
devices.addDevice(input);
// Always add a virtio scsi controller
vmTo.getName();
final ScsiDef sd = new ScsiDef((short) 0, 0, 0, 9, 0, vcpus);
devices.addDevice(sd);
logger.debug("Adding SCSI definition for " + vmTo.getName() + ":\n" + sd.toString());
vm.addComponent(devices);
return vm;
}
use of com.cloud.model.enumeration.BootOrder in project cosmic by MissionCriticalCloud.
the class HypervisorGuruBase method toVirtualMachineTO.
protected VirtualMachineTO toVirtualMachineTO(final VirtualMachineProfile vmProfile) {
final ServiceOffering offering = _serviceOfferingDao.findById(vmProfile.getId(), vmProfile.getServiceOfferingId());
final VirtualMachine vm = vmProfile.getVirtualMachine();
final Long minMemory = (long) (offering.getRamSize() / vmProfile.getMemoryOvercommitRatio());
final VirtualMachineTO to = new VirtualMachineTO(vm.getId(), vm.getInstanceName(), vm.getType(), offering.getCpu(), minMemory * 1024l * 1024l, offering.getRamSize() * 1024l * 1024l, null, null, vm.isHaEnabled(), vm.limitCpuUse(), vm.getVncPassword());
to.setBootArgs(vmProfile.getBootArgs());
final List<NicProfile> nicProfiles = vmProfile.getNics();
final NicTO[] nics = new NicTO[nicProfiles.size()];
int i = 0;
List<Long> vpcList = new ArrayList<>();
for (final NicProfile nicProfile : nicProfiles) {
nics[i++] = toNicTO(nicProfile);
if (TrafficType.Guest.equals(nicProfile.getTrafficType())) {
final NetworkVO network = _networkDao.findById(nicProfile.getNetworkId());
final Long vpcId = network.getVpcId();
if (vpcId != null) {
vpcList.add(network.getVpcId());
}
}
}
to.setNics(nics);
to.setDisks(vmProfile.getDisks().toArray(new DiskTO[vmProfile.getDisks().size()]));
if (vmProfile.getTemplate().getBits() == 32) {
to.setArch("i686");
} else {
to.setArch("x86_64");
}
final Map<String, String> detailsInVm = _userVmDetailsDao.listDetailsKeyPairs(vm.getId());
if (detailsInVm != null) {
to.setDetails(detailsInVm);
}
// Set GPU details
ServiceOfferingDetailsVO offeringDetail;
if ((offeringDetail = _serviceOfferingDetailsDao.findDetail(offering.getId(), GPU.Keys.vgpuType.toString())) != null) {
final ServiceOfferingDetailsVO groupName = _serviceOfferingDetailsDao.findDetail(offering.getId(), GPU.Keys.pciDevice.toString());
to.setGpuDevice(_resourceMgr.getGPUDevice(vm.getHostId(), groupName.getValue(), offeringDetail.getValue()));
}
// Workaround to make sure the TO has the UUID we need for Niciri integration
final VMInstanceVO vmInstance = _virtualMachineDao.findById(to.getId());
// check if XStools tools are present in the VM and dynamic scaling feature is enabled (per zone/global)
final Boolean isDynamicallyScalable = vmInstance.isDynamicallyScalable() && UserVmManager.EnableDynamicallyScaleVm.valueIn(vm.getDataCenterId());
to.setEnableDynamicallyScaleVm(isDynamicallyScalable);
to.setUuid(vmInstance.getUuid());
to.setManufacturer(vmInstance.getManufacturerString());
to.setOptimiseFor(vmInstance.getOptimiseFor());
to.setMaintenancePolicy(vmInstance.getMaintenancePolicy());
to.setBootMenuTimeout(vmInstance.getBootMenuTimeout());
to.setLastStartVersion(vmInstance.getLastStartVersion());
to.setLastStartDateTime(vmInstance.getLastStartDateTime());
to.setVmData(vmProfile.getVmData());
to.setConfigDriveLabel(vmProfile.getConfigDriveLabel());
to.setConfigDriveIsoRootFolder(vmProfile.getConfigDriveIsoRootFolder());
to.setConfigDriveIsoFile(vmProfile.getConfigDriveIsoFile());
LinkedHashSet<BootOrder> order = new LinkedHashSet<>();
if (vmInstance.getBootOrder() != null) {
for (final String dev : vmInstance.getBootOrder().split(",")) {
order.add(BootOrder.stringToEnum(dev));
}
} else {
// If bootorder column in DB is empty do default behaviour
order.add(BootOrder.CDROM);
order.add(BootOrder.HARDDISK);
}
to.setBootOrder(new ArrayList<>(order));
final MetadataTO metadataTO = new MetadataTO();
final DomainVO domain = _domainDao.findById(vm.getDomainId());
metadataTO.setDomainUuid(domain.getUuid());
metadataTO.setCosmicDomainName(domain.getName());
metadataTO.setCosmicDomainPath(domain.getPath());
metadataTO.setInstanceName(vm.getInstanceName());
metadataTO.setVmId(vm.getId());
metadataTO.setHostname(vm.getHostName());
final Map<String, String> resourceDetails = ApiDBUtils.getResourceDetails(vm.getId(), ResourceTag.ResourceObjectType.UserVm);
final Map<String, String> resourceTags = new HashMap<String, String>();
final List<String> vpcNameList = new LinkedList<>();
if (VirtualMachineType.User.equals(vm.getType())) {
final List<? extends ResourceTag> tags = ApiDBUtils.listByResourceTypeAndId(ResourceTag.ResourceObjectType.UserVm, vm.getId());
for (final ResourceTag tag : tags) {
resourceTags.put("instance_" + tag.getKey(), tag.getValue());
}
}
for (final Long vpcId : vpcList) {
final VpcVO vpc = _vpcDao.findById(vpcId);
if (vpc != null) {
vpcNameList.add(vpc.getName());
}
final List<? extends ResourceTag> tags = ApiDBUtils.listByResourceTypeAndId(ResourceTag.ResourceObjectType.Vpc, vpcId);
for (final ResourceTag tag : tags) {
if (tag != null) {
resourceTags.put("vpc_" + tag.getKey(), tag.getValue());
}
}
}
metadataTO.setResourceDetails(resourceDetails);
metadataTO.setResourceTags(resourceTags);
metadataTO.setVpcNameList(vpcNameList);
to.setMetadata(metadataTO);
return to;
}
Aggregations