use of org.ovirt.engine.core.common.businessentities.network.VmNic in project ovirt-engine by oVirt.
the class MacsUsedAcrossWholeSystem method calculateAllMacsUsedInVmAndItsSnapshot.
private Stream<String> calculateAllMacsUsedInVmAndItsSnapshot(List<? extends VmNic> vmInterfaces, List<? extends VmNic> snapshotInterfaces) {
CountMacUsageDifference countMacUsageDifference = new CountMacUsageDifference(macAddressesOfInterfaces(snapshotInterfaces), macAddressesOfInterfaces(vmInterfaces));
Stream<String> macsDuplicatedByNumberOfTimesTheyAreUsed = countMacUsageDifference.maxUsage().entrySet().stream().flatMap(entry -> LongStream.range(0, entry.getValue()).boxed().map(e -> entry.getKey()));
return macsDuplicatedByNumberOfTimesTheyAreUsed;
}
use of org.ovirt.engine.core.common.businessentities.network.VmNic in project ovirt-engine by oVirt.
the class RemoveVmInterfaceCommand method executeVmCommand.
@Override
protected void executeVmCommand() {
this.setVmName(vmStaticDao.get(getParameters().getVmId()).getName());
VmNic iface = vmNicDao.get(getParameters().getInterfaceId());
if (iface != null) {
interfaceName = iface.getName();
// Get Interface type.
String interType = VmInterfaceType.forValue(iface.getType()).getDescription();
if (interType != null) {
addCustomValue("InterfaceType", interType);
}
externalNetworkManagerFactory.create(iface).deallocateIfExternal();
}
// remove from db
TransactionSupport.executeInNewTransaction(() -> {
vmStaticDao.incrementDbGeneration(getParameters().getVmId());
vmNicDao.remove(getParameters().getInterfaceId());
vmNetworkStatisticsDao.remove(getParameters().getInterfaceId());
vmDeviceDao.remove(new VmDeviceId(getParameters().getInterfaceId(), getParameters().getVmId()));
// return mac to pool
if (iface != null) {
String macOfNicBeingRemoved = iface.getMacAddress();
MacIsNotReservedInSnapshotAndCanBeReleased canBeReleased = new MacIsNotReservedInSnapshotAndCanBeReleased();
if (canBeReleased.macCanBeReleased(macOfNicBeingRemoved, getVm(), snapshotsManager)) {
getMacPool().freeMac(macOfNicBeingRemoved);
}
}
setSucceeded(true);
return null;
});
}
use of org.ovirt.engine.core.common.businessentities.network.VmNic in project ovirt-engine by oVirt.
the class ReorderVmNicsCommand method reorderNics.
private void reorderNics() {
Map<Guid, VmDevice> vmInterfaceDevices = getVmInterfaceDevices();
List<VmNic> nics = vmNicDao.getAllForVm(getParameters().getVmId());
List<VmNic> nicsToReorder = new ArrayList<>();
List<String> macsToReorder = new ArrayList<>();
for (VmNic nic : nics) {
VmDevice nicDevice = vmInterfaceDevices.get(nic.getId());
// If there is not device, or the PCI address is empty
if (nicDevice == null || StringUtils.isEmpty(nicDevice.getAddress())) {
nicsToReorder.add(nic);
// We know that all the NICs have a MAC address
macsToReorder.add(nic.getMacAddress());
}
}
// Sorting the NICs to reorder by name
Collections.sort(nicsToReorder, numericSuffixNameableComparator);
// Sorting the MAC addresses to reorder
Collections.sort(macsToReorder);
for (int i = 0; i < nicsToReorder.size(); ++i) {
VmNic nic = nicsToReorder.get(i);
nic.setMacAddress(macsToReorder.get(i));
vmNicDao.update(nic);
}
}
use of org.ovirt.engine.core.common.businessentities.network.VmNic in project ovirt-engine by oVirt.
the class UpdateVmTemplateInterfaceCommand method getPermissionCheckSubjects.
@Override
public List<PermissionSubject> getPermissionCheckSubjects() {
List<PermissionSubject> permissionList = super.getPermissionCheckSubjects();
VmNic nic = getParameters().getInterface();
if (nic != null && nic.getVnicProfileId() != null && getVmTemplate() != null) {
VmNic oldNic = vmNicDao.get(nic.getId());
if (oldNic == null || isVnicProfileChanged(oldNic, nic)) {
permissionList.add(new PermissionSubject(nic.getVnicProfileId(), VdcObjectType.VnicProfile, getActionType().getActionGroup()));
}
}
return permissionList;
}
use of org.ovirt.engine.core.common.businessentities.network.VmNic 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;
}
Aggregations