use of org.ovirt.engine.core.common.businessentities.VmStatic in project ovirt-engine by oVirt.
the class AddVmCommand method addVmStatic.
private void addVmStatic() {
VmStatic vmStatic = getParameters().getVmStaticData();
if (vmStatic.getOrigin() == null) {
vmStatic.setOrigin(OriginType.valueOf(Config.getValue(ConfigValues.OriginType)));
}
vmStatic.setId(getVmId());
vmStatic.setQuotaId(getQuotaId());
vmStatic.setCreationDate(new Date());
vmStatic.setCreatedByUserId(getUserId());
setIconIds(vmStatic);
// Parses the custom properties field that was filled by frontend to
// predefined and user defined fields
VmPropertiesUtils.getInstance().separateCustomPropertiesToUserAndPredefined(getEffectiveCompatibilityVersion(), vmStatic);
updateOriginalTemplate(vmStatic);
vmStaticDao.save(vmStatic);
getCompensationContext().snapshotNewEntity(vmStatic);
}
use of org.ovirt.engine.core.common.businessentities.VmStatic in project ovirt-engine by oVirt.
the class AddVmCommand method addPermissionSubjectForAdminLevelProperties.
protected void addPermissionSubjectForAdminLevelProperties(List<PermissionSubject> permissionList) {
VmStatic vmFromParams = getParameters().getVmStaticData();
VmTemplate vmTemplate = getVmTemplate();
if (vmFromParams != null && vmTemplate != null) {
// user needs specific permission to change custom properties
if (!Objects.equals(vmFromParams.getCustomProperties(), vmTemplate.getCustomProperties())) {
permissionList.add(new PermissionSubject(getClusterId(), VdcObjectType.Cluster, ActionGroup.CHANGE_VM_CUSTOM_PROPERTIES));
}
// if the template is blank we ignore his pinned hosts
if (vmTemplate.isBlank()) {
return;
}
Set<Guid> dedicatedVmForVdsFromUser = new HashSet<>(vmFromParams.getDedicatedVmForVdsList());
Set<Guid> dedicatedVmForVdsFromTemplate = new HashSet<>(vmTemplate.getDedicatedVmForVdsList());
// host-specific parameters can be changed by administration role only
if (!dedicatedVmForVdsFromUser.equals(dedicatedVmForVdsFromTemplate) || !StringUtils.isEmpty(vmFromParams.getCpuPinning())) {
permissionList.add(new PermissionSubject(getClusterId(), VdcObjectType.Cluster, ActionGroup.EDIT_ADMIN_VM_PROPERTIES));
}
}
}
use of org.ovirt.engine.core.common.businessentities.VmStatic in project ovirt-engine by oVirt.
the class CpuPinningValidatorTest method setUp.
@Before
public void setUp() {
vmStatic = new VmStatic();
vmStatic.setNumOfSockets(6);
vmStatic.setCpuPerSocket(2);
vmStatic.setDedicatedVmForVdsList(Guid.Empty);
}
use of org.ovirt.engine.core.common.businessentities.VmStatic in project ovirt-engine by oVirt.
the class VdsBrokerObjectsBuilder method buildVmStaticDataFromExternalProvider.
private static VmStatic buildVmStaticDataFromExternalProvider(Map<String, Object> struct) {
if (!struct.containsKey(VdsProperties.vm_guid) || !struct.containsKey(VdsProperties.vm_name) || !struct.containsKey(VdsProperties.mem_size_mb) || !struct.containsKey(VdsProperties.num_of_cpus)) {
return null;
}
VmStatic vmStatic = new VmStatic();
vmStatic.setId(Guid.createGuidFromString((String) struct.get(VdsProperties.vm_guid)));
vmStatic.setName((String) struct.get(VdsProperties.vm_name));
vmStatic.setMemSizeMb(parseIntVdsProperty(struct.get(VdsProperties.mem_size_mb)));
vmStatic.setNumOfSockets(parseIntVdsProperty(struct.get(VdsProperties.num_of_cpus)));
vmStatic.setCustomCpuName((String) struct.get(VdsProperties.cpu_model));
vmStatic.setCustomEmulatedMachine((String) struct.get(VdsProperties.emulatedMachine));
addGraphicsDeviceFromExternalProvider(vmStatic, struct);
if (struct.containsKey(VdsProperties.vm_disks)) {
for (Object disk : (Object[]) struct.get(VdsProperties.vm_disks)) {
Map<String, Object> diskMap = (Map<String, Object>) disk;
if (VdsProperties.Disk.equals(diskMap.get(VdsProperties.type))) {
DiskImage image = buildDiskImageFromExternalProvider(diskMap, vmStatic.getId());
vmStatic.getImages().add(image);
}
}
}
if (struct.containsKey(VdsProperties.NETWORKS)) {
int idx = 0;
for (Object networkMap : (Object[]) struct.get(VdsProperties.NETWORKS)) {
VmNetworkInterface nic = buildNetworkInterfaceFromExternalProvider((Map<String, Object>) networkMap);
nic.setName(String.format("nic%d", ++idx));
nic.setVmName(vmStatic.getName());
nic.setVmId(vmStatic.getId());
vmStatic.getInterfaces().add(nic);
}
}
return vmStatic;
}
use of org.ovirt.engine.core.common.businessentities.VmStatic in project ovirt-engine by oVirt.
the class UpdateVmCommand method executeVmCommand.
@Override
protected void executeVmCommand() {
// needs to be here for post-actions
oldVm = getVm();
if (isUpdateVmTemplateVersion) {
updateVmTemplateVersion();
// template version was changed, no more work is required
return;
}
newVmStatic = getParameters().getVmStaticData();
if (isRunningConfigurationNeeded()) {
vmHandler.createNextRunSnapshot(getVm(), getParameters().getVmStaticData(), getParameters(), getCompensationContext());
vmHandler.setVmDestroyOnReboot(getVm());
}
vmHandler.warnMemorySizeLegal(getParameters().getVm().getStaticData(), getEffectiveCompatibilityVersion());
vmStaticDao.incrementDbGeneration(getVm().getId());
newVmStatic.setCreationDate(oldVm.getStaticData().getCreationDate());
newVmStatic.setQuotaId(getQuotaId());
// save user selected value for hotplug before overriding with db values (when updating running vm)
VM userVm = new VM();
userVm.setStaticData(new VmStatic(newVmStatic));
if (newVmStatic.getCreationDate().equals(DateTime.getMinValue())) {
newVmStatic.setCreationDate(new Date());
}
if (getVm().isRunningOrPaused() && !getVm().isHostedEngine()) {
if (!vmHandler.copyNonEditableFieldsToDestination(oldVm.getStaticData(), newVmStatic, isHotSetEnabled(), oldVm.getStatus(), getParameters().isMemoryHotUnplugEnabled())) {
// fail update vm if some fields could not be copied
throw new EngineException(EngineError.FAILED_UPDATE_RUNNING_VM);
}
}
if ((getVm().isRunningOrPaused() || getVm().isPreviewSnapshot() || getVm().isSuspended()) && !getVm().isHostedEngine()) {
if (getVm().getCustomCompatibilityVersion() == null && getParameters().getClusterLevelChangeFromVersion() != null) {
// For backward compatibility after cluster version change
// When running/paused: Set temporary custom compatibility version till the NextRun is applied (VM cold reboot)
// When snapshot in preview: keep the custom compatibility version even after commit or roll back by undo
newVmStatic.setCustomCompatibilityVersion(getParameters().getClusterLevelChangeFromVersion());
}
}
updateVmNetworks();
updateVmNumaNodes();
updateAffinityLabels();
if (!updateVmLease()) {
return;
}
if (isHotSetEnabled()) {
hotSetCpus(userVm);
updateCurrentMemory(userVm);
}
final List<Guid> oldIconIds = iconUtils.updateVmIcon(oldVm.getStaticData(), newVmStatic, getParameters().getVmLargeIcon());
resourceManager.getVmManager(getVmId()).update(newVmStatic);
if (getVm().isNotRunning()) {
updateVmPayload();
getVmDeviceUtils().updateVmDevices(getParameters(), oldVm, this::getCluster);
updateWatchdog();
updateRngDevice();
updateGraphicsDevices();
updateVmHostDevices();
updateDeviceAddresses();
}
iconUtils.removeUnusedIcons(oldIconIds);
vmHandler.updateVmInitToDB(getParameters().getVmStaticData());
checkTrustedService();
liveUpdateCpuProfile();
setSucceeded(true);
}
Aggregations