use of org.ovirt.engine.core.common.businessentities.network.VmNic in project ovirt-engine by oVirt.
the class MigrateVmCommand method replugNics.
private List<VmNic> replugNics(List<ActivateDeactivateVmNicParameters> parametersList) {
log.debug("About to call {} with parameters: {}", ActionType.ActivateDeactivateVmNic, Arrays.toString(parametersList.toArray()));
List<VmNic> notRepluggedNics = new ArrayList<>();
for (ActivateDeactivateVmNicParameters parameter : parametersList) {
ActionReturnValue returnValue = runInternalAction(ActionType.ActivateDeactivateVmNic, parameter);
boolean nicPlugSucceeded = returnValue.getSucceeded();
if (!nicPlugSucceeded) {
notRepluggedNics.add(parameter.getNic());
}
}
return notRepluggedNics;
}
use of org.ovirt.engine.core.common.businessentities.network.VmNic in project ovirt-engine by oVirt.
the class RemoveVmCommand method removeVm.
private boolean removeVm() {
final List<DiskImage> diskImages = DisksFilter.filterImageDisks(getVm().getDiskList(), ONLY_NOT_SHAREABLE, ONLY_ACTIVE);
final List<LunDisk> lunDisks = DisksFilter.filterLunDisks(getVm().getDiskMap().values(), ONLY_NOT_SHAREABLE);
for (VmNic nic : getInterfaces()) {
externalNetworkManagerFactory.create(nic).deallocateIfExternal();
}
removeMemoryVolumes();
TransactionSupport.executeInNewTransaction(() -> {
removeVmFromDb();
if (getParameters().isRemoveDisks()) {
for (DiskImage image : diskImages) {
getCompensationContext().snapshotEntityStatus(image.getImage(), ImageStatus.ILLEGAL);
imagesHandler.updateImageStatus(image.getImage().getId(), ImageStatus.LOCKED);
}
for (LunDisk lunDisk : lunDisks) {
imagesHandler.removeLunDisk(lunDisk);
}
getCompensationContext().stateChanged();
} else {
for (DiskImage image : diskImages) {
imageDao.updateImageVmSnapshotId(image.getImageId(), null);
}
}
return null;
});
Collection<DiskImage> unremovedDisks = Collections.emptyList();
if (getParameters().isRemoveDisks()) {
if (!diskImages.isEmpty()) {
unremovedDisks = removeVmImages(diskImages).getActionReturnValue();
}
unremovedDisks.addAll(removeCinderDisks());
if (!unremovedDisks.isEmpty()) {
processUnremovedDisks(unremovedDisks);
return false;
}
}
vmDeleted.fire(getVmId());
return true;
}
use of org.ovirt.engine.core.common.businessentities.network.VmNic in project ovirt-engine by oVirt.
the class AddVmTemplateCommand method addVmInterfaces.
private void addVmInterfaces(Map<Guid, Guid> srcDeviceIdToTargetDeviceIdMapping) {
List<VmNic> interfaces = vmNicDao.getAllForVm(getParameters().getMasterVm().getId());
for (VmNic iface : interfaces) {
VmNic iDynamic = new VmNic();
iDynamic.setId(Guid.newGuid());
iDynamic.setVmTemplateId(getVmTemplateId());
iDynamic.setName(iface.getName());
iDynamic.setVnicProfileId(iface.getVnicProfileId());
iDynamic.setSpeed(VmInterfaceType.forValue(iface.getType()).getSpeed());
iDynamic.setType(iface.getType());
iDynamic.setLinked(iface.isLinked());
vmNicDao.save(iDynamic);
srcDeviceIdToTargetDeviceIdMapping.put(iface.getId(), iDynamic.getId());
}
}
use of org.ovirt.engine.core.common.businessentities.network.VmNic in project ovirt-engine by oVirt.
the class ChangeVMClusterCommand method executeCommand.
@Override
protected void executeCommand() {
VM vm = getVm();
boolean clusterRemainedTheSame = originalClusterId.equals(newClusterId);
if (clusterRemainedTheSame) {
setSucceeded(true);
return;
}
// update vm interfaces
List<Network> networks = networkDao.getAllForCluster(newClusterId);
List<VmNic> interfaces = vmNicDao.getAllForVm(getParameters().getVmId());
for (final VmNic iface : interfaces) {
if (iface.getVnicProfileId() != null) {
final Network network = networkHelper.getNetworkByVnicProfileId(iface.getVnicProfileId());
boolean networkFoundInCluster = networks.stream().anyMatch(n -> Objects.equals(n.getId(), network.getId()));
// interface connection
if (!networkFoundInCluster) {
iface.setVnicProfileId(null);
vmNicDao.update(iface);
}
}
}
if (vm.getDedicatedVmForVdsList().size() > 0) {
vm.setDedicatedVmForVdsList(Collections.emptyList());
dedicatedHostWasCleared = true;
}
vm.setClusterId(newClusterId);
// Set cpu profile from the new cluster
cpuProfileHelper.assignFirstCpuProfile(vm.getStaticData(), getUserIdIfExternal().orElse(null));
vmStaticDao.update(vm.getStaticData());
moveMacsToAnotherMacPoolIfNeeded();
// change vm cluster should remove the vm from all associated affinity groups
List<AffinityGroup> allAffinityGroupsByVmId = affinityGroupDao.getAllAffinityGroupsByVmId(vm.getId());
if (!allAffinityGroupsByVmId.isEmpty()) {
String groups = allAffinityGroupsByVmId.stream().map(AffinityGroup::getName).collect(Collectors.joining(" "));
log.info("Due to cluster change, removing VM from associated affinity group(s): {}", groups);
affinityGroupDao.removeVmFromAffinityGroups(vm.getId());
}
setSucceeded(true);
}
use of org.ovirt.engine.core.common.businessentities.network.VmNic in project ovirt-engine by oVirt.
the class ChangeVmClusterValidator method validateDestinationClusterContainsNetworks.
/**
* Checks that the destination cluster has all the networks that the given NICs require.<br>
* No network on a NIC is allowed (it's checked when running VM).
*
* @param interfaces The NICs to check networks on.
* @return Whether the destination cluster has all networks configured or not.
*/
private boolean validateDestinationClusterContainsNetworks(List<VmNic> interfaces) {
List<Network> networks = networkDao.getAllForCluster(targetClusterId);
StringBuilder missingNets = new StringBuilder();
for (VmNic iface : interfaces) {
Network network = networkHelper.getNetworkByVnicProfileId(iface.getVnicProfileId());
if (network != null) {
boolean exists = false;
for (Network net : networks) {
if (net.getName().equals(network.getName())) {
exists = true;
break;
}
}
if (!exists) {
if (missingNets.length() > 0) {
missingNets.append(", ");
}
missingNets.append(network.getName());
}
}
}
if (missingNets.length() > 0) {
parentCommand.addValidationMessage(EngineMessage.MOVE_VM_CLUSTER_MISSING_NETWORK);
parentCommand.addValidationMessageVariable("networks", missingNets.toString());
return false;
}
return true;
}
Aggregations