Search in sources :

Example 36 with VmNic

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;
}
Also used : ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) ArrayList(java.util.ArrayList) ActivateDeactivateVmNicParameters(org.ovirt.engine.core.common.action.ActivateDeactivateVmNicParameters) VmNic(org.ovirt.engine.core.common.businessentities.network.VmNic)

Example 37 with VmNic

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;
}
Also used : DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) LunDisk(org.ovirt.engine.core.common.businessentities.storage.LunDisk) VmNic(org.ovirt.engine.core.common.businessentities.network.VmNic)

Example 38 with VmNic

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());
    }
}
Also used : VmNic(org.ovirt.engine.core.common.businessentities.network.VmNic)

Example 39 with VmNic

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);
}
Also used : VM(org.ovirt.engine.core.common.businessentities.VM) Network(org.ovirt.engine.core.common.businessentities.network.Network) AffinityGroup(org.ovirt.engine.core.common.scheduling.AffinityGroup) VmNic(org.ovirt.engine.core.common.businessentities.network.VmNic)

Example 40 with VmNic

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;
}
Also used : Network(org.ovirt.engine.core.common.businessentities.network.Network) VmNic(org.ovirt.engine.core.common.businessentities.network.VmNic)

Aggregations

VmNic (org.ovirt.engine.core.common.businessentities.network.VmNic)47 Test (org.junit.Test)9 ArrayList (java.util.ArrayList)8 VM (org.ovirt.engine.core.common.businessentities.VM)6 VmDevice (org.ovirt.engine.core.common.businessentities.VmDevice)6 Network (org.ovirt.engine.core.common.businessentities.network.Network)5 Guid (org.ovirt.engine.core.compat.Guid)5 HashMap (java.util.HashMap)4 VmDeviceId (org.ovirt.engine.core.common.businessentities.VmDeviceId)4 VmNetworkInterface (org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface)4 List (java.util.List)3 Map (java.util.Map)3 VmNicValidator (org.ovirt.engine.core.bll.validator.VmNicValidator)3 Version (org.ovirt.engine.core.compat.Version)3 Collectors (java.util.stream.Collectors)2 VmInterfaceManager (org.ovirt.engine.core.bll.network.VmInterfaceManager)2 MacPool (org.ovirt.engine.core.bll.network.macpool.MacPool)2 VnicProfileHelper (org.ovirt.engine.core.bll.network.vm.VnicProfileHelper)2 VnicProfile (org.ovirt.engine.core.common.businessentities.network.VnicProfile)2 EngineMessage (org.ovirt.engine.core.common.errors.EngineMessage)2