use of com.cloud.agent.api.to.MetadataTO 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;
for (final NicProfile nicProfile : nicProfiles) {
nics[i++] = toNicTO(nicProfile);
}
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.setVmData(vmProfile.getVmData());
to.setConfigDriveLabel(vmProfile.getConfigDriveLabel());
to.setConfigDriveIsoRootFolder(vmProfile.getConfigDriveIsoRootFolder());
to.setConfigDriveIsoFile(vmProfile.getConfigDriveIsoFile());
final MetadataTO metadataTO = new MetadataTO();
final DomainVO domain = _domainDao.findById(vm.getDomainId());
metadataTO.setDomainUuid(domain.getUuid());
to.setMetadata(metadataTO);
return to;
}
use of com.cloud.agent.api.to.MetadataTO 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(vmTo.getOs());
vm.setPlatformEmulator(vmTo.getPlatformEmulator());
final MetadataTO metadataTo = vmTo.getMetadata();
if (metadataTo != null) {
final MetadataDef metadata = new MetadataDef();
metadata.getNodes().put("domainUuid", metadataTo.getDomainUuid());
vm.addComponent(metadata);
}
final GuestDef guest = new GuestDef();
guest.setGuestType(GuestDef.GuestType.KVM);
vm.setHvsType(HypervisorType.KVM.toString().toLowerCase());
vm.setLibvirtVersion(hypervisorLibvirtVersion);
vm.setQemuVersion(hypervisorQemuVersion);
guest.setGuestArch(vmTo.getArch());
guest.setMachineType("pc");
guest.setUuid(uuid);
guest.setManufacturer(vmTo.getManufacturer());
guest.setBootOrder(GuestDef.BootOrder.CDROM);
guest.setBootOrder(GuestDef.BootOrder.HARDISK);
vm.addComponent(guest);
final GuestResourceDef grd = new GuestResourceDef();
if (vmTo.getMinRam() != vmTo.getMaxRam() && !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() == VirtualMachine.Type.User) {
cmd.setFeatures(getCpuFeatures());
}
// 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 (VirtualMachine.Type.DomainRouter.equals(vmTo.getType())) {
ctd.setShares(vmTo.getCpus() * libvirtComputingResourceProperties.getGuestCpuSharesRouter());
} else {
ctd.setShares(vmTo.getCpus() * libvirtComputingResourceProperties.getGuestCpuShares());
}
vm.addComponent(ctd);
final FeaturesDef features = new FeaturesDef();
features.addFeatures("pae");
features.addFeatures("apic");
features.addFeatures("acpi");
vm.addComponent(features);
final TermPolicy term = new TermPolicy();
if (VirtualMachine.Type.DomainRouter.equals(vmTo.getType())) {
term.setCrashPolicy(getRouterTermpolicyCrash());
term.setPowerOffPolicy(getRouterTermpolicyPowerOff());
term.setRebootPolicy(getRouterTermpolicyReboot());
} else {
term.setCrashPolicy(getVmTermpolicyCrash());
term.setPowerOffPolicy(getVmTermpolicyPowerOff());
term.setRebootPolicy(getVmTermpolicyReboot());
}
vm.addComponent(term);
final ClockDef clock = new ClockDef();
if (vmTo.getOs().startsWith("Windows")) {
clock.setClockOffset(ClockDef.ClockOffset.LOCALTIME);
} else if (vmTo.getType() != VirtualMachine.Type.User || isGuestVirtIoCapable(vmTo.getOs())) {
if (hypervisorLibvirtVersion >= 9 * 1000 + 10) {
clock.addTimer("kvmclock", null, null, isKvmclockDisabled());
}
}
// Recommended default clock/timer settings - https://bugzilla.redhat.com/show_bug.cgi?id=1053847
clock.addTimer("rtc", "catchup", null);
clock.addTimer("pit", "delay", null);
vm.addComponent(clock);
final DevicesDef devices = new DevicesDef();
devices.setEmulatorPath(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 (libvirtComputingResourceProperties.getVmRngEnable()) {
final RngDef rngDevice = new RngDef(rngPath, rngBackendModel);
devices.addDevice(rngDevice);
}
final WatchDogDef watchDog = new WatchDogDef(libvirtComputingResourceProperties.getVmWatchdogAction(), libvirtComputingResourceProperties.getVmWatchdogModel());
devices.addDevice(watchDog);
final VideoDef videoCard = new VideoDef(libvirtComputingResourceProperties.getVmVideoHardware(), 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);
LibvirtDiskDef.DiskBus diskBusType = getDiskModelFromVmDetail(vmTo);
if (diskBusType == null) {
diskBusType = getGuestDiskModel(vmTo.getPlatformEmulator());
}
// If we're using virtio scsi, then we need to add a virtual scsi controller
if (diskBusType == LibvirtDiskDef.DiskBus.SCSI) {
vmTo.getName();
final ScsiDef sd = new ScsiDef((short) 0, 0, 0, 9, 0);
devices.addDevice(sd);
logger.debug("Adding SCSI definition for " + vmTo.getName() + ":\n" + sd.toString());
}
vm.addComponent(devices);
return vm;
}
Aggregations