use of org.ovirt.engine.core.common.errors.EngineMessage in project ovirt-engine by oVirt.
the class UpdateVmTemplateCommand method validate.
@Override
protected boolean validate() {
boolean isInstanceType = isInstanceType();
boolean isBlankTemplate = isBlankTemplate();
if (getCluster() == null && !(isInstanceType || isBlankTemplate)) {
addValidationMessage(EngineMessage.ACTION_TYPE_FAILED_CLUSTER_CAN_NOT_BE_EMPTY);
return false;
}
boolean returnValue = false;
if (oldTemplate == null) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_TEMPLATE_DOES_NOT_EXIST);
}
if (!StringUtils.equals(oldTemplate.getName(), getVmTemplate().getName())) {
if (!getVmTemplate().isBaseTemplate()) {
// template version should always have the name of the base template
return failValidation(EngineMessage.VMT_CANNOT_UPDATE_VERSION_NAME);
} else {
// must be unique also across datacenters.
if (isInstanceType) {
if (isInstanceWithSameNameExists(getVmTemplateName())) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_NAME_ALREADY_USED);
}
} else {
if (isVmTemplateWithSameNameExist(getVmTemplateName(), isBlankTemplate ? null : getCluster().getStoragePoolId())) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_NAME_ALREADY_USED);
}
}
}
}
Version effectiveCompatibilityVersion = CompatibilityVersionUtils.getEffective(getParameters().getVmTemplateData(), this::getCluster);
if (getParameters().getVmTemplateData().getVmType() == VmType.HighPerformance && !FeatureSupported.isHighPerformanceTypeSupported(effectiveCompatibilityVersion)) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_HIGH_PERFORMANCE_IS_NOT_SUPPORTED, String.format("$Version %s", effectiveCompatibilityVersion));
}
if (vmHandler.isVmPriorityValueLegal(getParameters().getVmTemplateData().getPriority()).isValid() && checkDomain()) {
returnValue = vmTemplateHandler.isUpdateValid(oldTemplate, getVmTemplate());
if (!returnValue) {
addValidationMessage(EngineMessage.VMT_CANNOT_UPDATE_ILLEGAL_FIELD);
}
}
if (!validate(vmHandler.validateSmartCardDevice(getParameters().getVmTemplateData()))) {
return false;
}
if (!setAndValidateCpuProfile()) {
return false;
}
if (getParameters().getVmLargeIcon() != null && !validate(IconValidator.validate(IconValidator.DimensionsType.LARGE_CUSTOM_ICON, getParameters().getVmLargeIcon()))) {
return false;
}
if (getParameters().getVmTemplateData() != null && getParameters().getVmTemplateData().getSmallIconId() != null && // icon id is ignored if large icon is sent
getParameters().getVmLargeIcon() == null && !validate(IconValidator.validateIconId(getParameters().getVmTemplateData().getSmallIconId(), "Small"))) {
return false;
}
if (getParameters().getVmTemplateData() != null && getParameters().getVmTemplateData().getLargeIconId() != null && // icon id is ignored if large icon is sent
getParameters().getVmLargeIcon() == null && !validate(IconValidator.validateIconId(getParameters().getVmTemplateData().getLargeIconId(), "Large"))) {
return false;
}
if (returnValue && getParameters().getWatchdog() != null) {
returnValue = validate(new VmWatchdogValidator.VmWatchdogClusterIndependentValidator(getParameters().getWatchdog()).isValid());
}
if (!validate(vmHandler.validateMaxMemorySize(getParameters().getVmTemplateData(), CompatibilityVersionUtils.getEffective(getParameters().getVmTemplateData(), this::getCluster)))) {
return false;
}
List<EngineMessage> msgs = openStackMetadataAdapter.validate(getParameters().getVmTemplateData().getVmInit());
if (!CollectionUtils.isEmpty(msgs)) {
return failValidation(msgs);
}
if (!isInstanceType && !isBlankTemplate && returnValue) {
return doClusterRelatedChecks();
} else {
return returnValue;
}
}
use of org.ovirt.engine.core.common.errors.EngineMessage in project ovirt-engine by oVirt.
the class ActivateDeactivateVmNicCommand method macAvailable.
protected ValidationResult macAvailable() {
VmNic nic = getParameters().getNic();
EngineMessage failMessage = EngineMessage.NETWORK_MAC_ADDRESS_IN_USE;
return ValidationResult.failWith(failMessage, ReplacementUtils.getVariableAssignmentString(failMessage, nic.getMacAddress())).when(new VmInterfaceManager().tooManyPluggedInterfaceWithSameMac(nic, getMacPool()));
}
use of org.ovirt.engine.core.common.errors.EngineMessage in project ovirt-engine by oVirt.
the class VmValidator method checkPciAndIdeLimit.
/**
* This method checks that with the given parameters, the max PCI and IDE limits defined are not passed.
*/
public static ValidationResult checkPciAndIdeLimit(int osId, Version clusterVersion, int monitorsNumber, List<? extends VmNic> interfaces, List<DiskVmElement> diskVmElements, boolean virtioScsiEnabled, boolean hasWatchdog, boolean isBalloonEnabled, boolean isSoundDeviceEnabled) {
// this adds: monitors + 2 * (interfaces with type rtl_pv) + (all other
// interfaces) + (all disks that are not IDE)
int pciInUse = monitorsNumber;
for (VmNic a : interfaces) {
if (a.getType() != null && VmInterfaceType.forValue(a.getType()) == VmInterfaceType.rtl8139_pv) {
pciInUse += 2;
} else if (a.getType() != null && VmInterfaceType.forValue(a.getType()) == VmInterfaceType.spaprVlan) {
// Do not count sPAPR VLAN devices since they are not PCI
} else {
pciInUse += 1;
}
}
pciInUse += diskVmElements.stream().filter(dve -> dve.getDiskInterface() == DiskInterface.VirtIO).count();
// VirtIO SCSI controller requires one PCI slot
pciInUse += virtioScsiEnabled ? 1 : 0;
// VmWatchdog controller requires one PCI slot
pciInUse += hasWatchdog ? 1 : 0;
// Balloon controller requires one PCI slot
pciInUse += isBalloonEnabled ? 1 : 0;
// Sound device controller requires one PCI slot
pciInUse += isSoundDeviceEnabled ? 1 : 0;
OsRepository osRepository = Injector.get(OsRepository.class);
int maxPciSlots = osRepository.getMaxPciDevices(osId, clusterVersion);
ArrayList<EngineMessage> messages = new ArrayList<>();
if (pciInUse > maxPciSlots) {
messages.add(EngineMessage.ACTION_TYPE_FAILED_EXCEEDED_MAX_PCI_SLOTS);
} else if (VmCommand.MAX_IDE_SLOTS < diskVmElements.stream().filter(a -> a.getDiskInterface() == DiskInterface.IDE).count()) {
messages.add(EngineMessage.ACTION_TYPE_FAILED_EXCEEDED_MAX_IDE_SLOTS);
} else if (VmCommand.MAX_VIRTIO_SCSI_DISKS < diskVmElements.stream().filter(a -> a.getDiskInterface() == DiskInterface.VirtIO_SCSI).count()) {
messages.add(EngineMessage.ACTION_TYPE_FAILED_EXCEEDED_MAX_VIRTIO_SCSI_DISKS);
} else if (VmCommand.MAX_SPAPR_SCSI_DISKS < diskVmElements.stream().filter(a -> a.getDiskInterface() == DiskInterface.SPAPR_VSCSI).count()) {
messages.add(EngineMessage.ACTION_TYPE_FAILED_EXCEEDED_MAX_SPAPR_VSCSI_DISKS);
}
if (!messages.isEmpty()) {
return new ValidationResult(messages);
}
return ValidationResult.VALID;
}
use of org.ovirt.engine.core.common.errors.EngineMessage in project ovirt-engine by oVirt.
the class VnicProfileValidator method vnicProfileNotUsed.
protected ValidationResult vnicProfileNotUsed(List<? extends Nameable> entities, EngineMessage entitiesReplacementPlural, EngineMessage entitiesReplacementSingular) {
if (entities.isEmpty()) {
return ValidationResult.VALID;
}
Collection<String> replacements = ReplacementUtils.replaceWithNameable("ENTITIES_USING_VNIC_PROFILE", entities);
EngineMessage replacementMessageToUse = entities.size() == 1 ? entitiesReplacementSingular : entitiesReplacementPlural;
replacements.add(replacementMessageToUse.name());
return new ValidationResult(getVNicProfileInUseValidationMessage(entities.size()), replacements);
}
use of org.ovirt.engine.core.common.errors.EngineMessage in project ovirt-engine by oVirt.
the class NetworkAttachmentValidator method networkExists.
public ValidationResult networkExists() {
Guid networkId = attachment.getNetworkId();
String networkName = attachment.getNetworkName();
// User did not specify neither id nor name.
if (networkId == null && networkName == null) {
return new ValidationResult(EngineMessage.NETWORK_ATTACHMENT_NETWORK_ID_OR_NAME_IS_NOT_SET);
}
// User specified id, for which completors did not find Network record.
if (networkId != null && networkName == null) {
EngineMessage engineMessage = EngineMessage.NETWORK_HAVING_ID_NOT_EXISTS;
return new ValidationResult(engineMessage, ReplacementUtils.getVariableAssignmentString(engineMessage, networkId.toString()));
}
// User specified name, for which completors did not find Network record.
if (networkId == null && networkName != null) {
EngineMessage engineMessage = EngineMessage.NETWORK_HAVING_NAME_NOT_EXISTS;
return new ValidationResult(engineMessage, ReplacementUtils.getVariableAssignmentString(engineMessage, networkName));
}
return ValidationResult.VALID;
}
Aggregations