use of org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface in project ovirt-engine by oVirt.
the class VmInterfaceListModel method canRemoveNics.
private boolean canRemoveNics() {
VM vm = getEntity();
if (VMStatus.Down.equals(vm.getStatus())) {
return true;
}
List<VmNetworkInterface> nics = getSelectedItems() != null ? getSelectedItems() : new ArrayList<VmNetworkInterface>();
for (VmNetworkInterface nic : nics) {
if (nic.isPlugged()) {
return false;
}
}
return true;
}
use of org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface in project ovirt-engine by oVirt.
the class VmInstanceTypeManager method updateNetworkInterfacesByTemplate.
public void updateNetworkInterfacesByTemplate(VmBase vmBase) {
QueryType queryType = (vmBase instanceof VmTemplate) ? QueryType.GetTemplateInterfacesByTemplateId : QueryType.GetVmInterfacesByVmId;
AsyncQuery<QueryReturnValue> query = new AsyncQuery<>(returnValue -> {
if (returnValue == null) {
return;
}
List<VmNetworkInterface> nics = returnValue.getReturnValue();
updateNetworkInterfaces(getNetworkProfileBehavior(), nics);
});
Frontend.getInstance().runQuery(queryType, new IdQueryParameters(vmBase.getId()), query);
}
use of org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface in project ovirt-engine by oVirt.
the class ImportVmCommandBase method validate.
@Override
protected boolean validate() {
if (getVm() == null) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_VM_NOT_FOUND);
}
if (getCluster() == null) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_CLUSTER_CAN_NOT_BE_EMPTY);
}
if (getParameters().getStoragePoolId() != null && !getParameters().getStoragePoolId().equals(getCluster().getStoragePoolId())) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_CLUSTER_IS_NOT_VALID);
}
macPool = getMacPool();
List<VmNetworkInterface> nicsUnableToBeImported = getVm().getInterfaces().stream().filter(this::ifaceMacCannotBeAddedToMacPool).collect(Collectors.toList());
if (!nicsUnableToBeImported.isEmpty()) {
EngineMessage engineMessage = EngineMessage.ACTION_TYPE_FAILED_CANNOT_ADD_IFACE_DUE_TO_MAC_DUPLICATES;
Collection<String> replacements = ReplacementUtils.getListVariableAssignmentString(engineMessage, nicsUnableToBeImported);
return validate(new ValidationResult(engineMessage, replacements));
}
List<EngineMessage> msgs = openStackMetadataAdapter.validate(getVm().getVmInit());
if (!CollectionUtils.isEmpty(msgs)) {
return failValidation(msgs);
}
return true;
}
use of org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface in project ovirt-engine by oVirt.
the class ImportVmCommandBase method addVmInterfaces.
protected void addVmInterfaces() {
VmInterfaceManager vmInterfaceManager = new VmInterfaceManager(macPool);
VnicProfileHelper vnicProfileHelper = new VnicProfileHelper(getClusterId(), getStoragePoolId(), AuditLogType.IMPORTEXPORT_IMPORT_VM_INVALID_INTERFACES);
List<VmNetworkInterface> nics = getVm().getInterfaces();
vmInterfaceManager.sortVmNics(nics, getVm().getStaticData().getManagedDeviceMap());
if (!getParameters().isImportAsNewEntity() && isExternalMacsToBeReported()) {
reportExternalMacs();
}
for (VmNetworkInterface iface : getVm().getInterfaces()) {
initInterface(iface);
vnicProfileHelper.updateNicWithVnicProfileForUser(iface, getCurrentUser());
vmInterfaceManager.add(iface, getCompensationContext(), shouldReassignMac(iface));
macsAdded.add(iface.getMacAddress());
}
vnicProfileHelper.auditInvalidInterfaces(getVmName());
}
use of org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface in project ovirt-engine by oVirt.
the class ImportVmTemplateCommand method validate.
@Override
protected boolean validate() {
if (getVmTemplate() == null) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_VM_NOT_FOUND);
}
if (getCluster() == null) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_CLUSTER_CAN_NOT_BE_EMPTY);
}
if (!getCluster().getStoragePoolId().equals(getStoragePoolId())) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_CLUSTER_IS_NOT_VALID);
}
setDescription(getVmTemplateName());
// check that the storage pool is valid
if (!validate(createStoragePoolValidator().existsAndUp()) || !validateTemplateArchitecture() || !isClusterCompatible()) {
return false;
}
// set the source domain and check that it is ImportExport type and active
setSourceDomainId(getParameters().getSourceDomainId());
StorageDomainValidator sourceDomainValidator = new StorageDomainValidator(getSourceDomain());
if (!validate(sourceDomainValidator.isDomainExistAndActive())) {
return false;
}
if ((getSourceDomain().getStorageDomainType() != StorageDomainType.ImportExport) && !getParameters().isImagesExistOnTargetStorageDomain()) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_STORAGE_DOMAIN_TYPE_ILLEGAL);
}
if (!getParameters().isImagesExistOnTargetStorageDomain()) {
// Set the template images from the Export domain and change each image id storage is to the import domain
GetAllFromExportDomainQueryParameters tempVar = new GetAllFromExportDomainQueryParameters(getParameters().getStoragePoolId(), getParameters().getSourceDomainId());
QueryReturnValue qretVal = runInternalQuery(QueryType.GetTemplatesFromExportDomain, tempVar);
if (!qretVal.getSucceeded()) {
return false;
}
Map<VmTemplate, List<DiskImage>> templates = qretVal.getReturnValue();
ArrayList<DiskImage> images = new ArrayList<>();
for (Map.Entry<VmTemplate, List<DiskImage>> entry : templates.entrySet()) {
if (entry.getKey().getId().equals(getVmTemplate().getId())) {
images = new ArrayList<>(entry.getValue());
getVmTemplate().setInterfaces(entry.getKey().getInterfaces());
getVmTemplate().setOvfVersion(entry.getKey().getOvfVersion());
break;
}
}
getParameters().setImages(images);
getVmTemplate().setImages(images);
ensureDomainMap(getImages(), getParameters().getDestDomainId());
HashMap<Guid, DiskImage> imageMap = new HashMap<>();
for (DiskImage image : images) {
if (Guid.Empty.equals(image.getVmSnapshotId())) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_CORRUPTED_VM_SNAPSHOT_ID);
}
StorageDomain storageDomain = getStorageDomain(imageToDestinationDomainMap.get(image.getId()));
StorageDomainValidator validator = new StorageDomainValidator(storageDomain);
if (!validate(validator.isDomainExistAndActive()) || !validate(validator.domainIsValidDestination())) {
return false;
}
StorageDomainStatic targetDomain = storageDomain.getStorageStaticData();
changeRawToCowIfSparseOnBlockDevice(targetDomain.getStorageType(), image);
if (!ImagesHandler.checkImageConfiguration(targetDomain, image, getReturnValue().getValidationMessages())) {
return false;
}
image.setStoragePoolId(getParameters().getStoragePoolId());
image.setStorageIds(new ArrayList<>(Collections.singletonList(storageDomain.getId())));
imageMap.put(image.getImageId(), image);
}
getVmTemplate().setDiskImageMap(imageMap);
}
sourceTemplateId = getVmTemplateId();
if (getParameters().isImportAsNewEntity()) {
initImportClonedTemplate();
}
VmTemplate duplicateTemplate = vmTemplateDao.get(getParameters().getVmTemplate().getId());
// check that the template does not exists in the target domain
if (duplicateTemplate != null) {
return failValidation(EngineMessage.VMT_CANNOT_IMPORT_TEMPLATE_EXISTS, String.format("$TemplateName %1$s", duplicateTemplate.getName()));
}
if (getVmTemplate().isBaseTemplate() && isVmTemplateWithSameNameExist()) {
return failValidation(EngineMessage.VM_CANNOT_IMPORT_TEMPLATE_NAME_EXISTS);
}
if (!validateNoDuplicateDiskImages(getImages())) {
return false;
}
if (getImages() != null && !getImages().isEmpty() && !getParameters().isImagesExistOnTargetStorageDomain()) {
if (!validateSpaceRequirements(getImages())) {
return false;
}
}
List<VmNetworkInterface> vmNetworkInterfaces = getVmTemplate().getInterfaces();
vmNicMacsUtils.replaceInvalidEmptyStringMacAddressesWithNull(vmNetworkInterfaces);
if (!validate(vmNicMacsUtils.validateMacAddress(vmNetworkInterfaces))) {
return false;
}
// if this is a template version, check base template exist
if (!getVmTemplate().isBaseTemplate()) {
VmTemplate baseTemplate = vmTemplateDao.get(getVmTemplate().getBaseTemplateId());
if (baseTemplate == null) {
return failValidation(EngineMessage.VMT_CANNOT_IMPORT_TEMPLATE_VERSION_MISSING_BASE);
}
}
if (!setAndValidateDiskProfiles()) {
return false;
}
if (!setAndValidateCpuProfile()) {
return false;
}
if (!validate(vmHandler.validateMaxMemorySize(getVmTemplate(), getEffectiveCompatibilityVersion()))) {
return false;
}
List<EngineMessage> msgs = openStackMetadataAdapter.validate(getVmTemplate().getVmInit());
if (!CollectionUtils.isEmpty(msgs)) {
return failValidation(msgs);
}
return true;
}
Aggregations