Search in sources :

Example 1 with VmInterfaceManager

use of org.ovirt.engine.core.bll.network.VmInterfaceManager in project ovirt-engine by oVirt.

the class AddVmCommand method addVmNetwork.

protected void addVmNetwork() {
    List<? extends VmNic> nics = getVmInterfaces();
    VmInterfaceManager vmInterfaceManager = new VmInterfaceManager(getMacPool());
    vmInterfaceManager.sortVmNics(nics, getVmInterfaceDevices());
    List<String> macAddresses = getMacPool().allocateMacAddresses(nics.size());
    // Add interfaces from template
    for (int i = 0; i < nics.size(); ++i) {
        VmNic iface = nics.get(i);
        Guid id = Guid.newGuid();
        srcVmNicIdToTargetVmNicIdMapping.put(iface.getId(), id);
        iface.setId(id);
        iface.setMacAddress(macAddresses.get(i));
        iface.setSpeed(VmInterfaceType.forValue(iface.getType()).getSpeed());
        iface.setVmTemplateId(null);
        iface.setVmId(getParameters().getVmStaticData().getId());
        updateProfileOnNic(iface);
        vmNicDao.save(iface);
        getCompensationContext().snapshotNewEntity(iface);
        vmNetworkStatisticsDao.save(iface.getStatistics());
        getCompensationContext().snapshotNewEntity(iface.getStatistics());
    }
}
Also used : Guid(org.ovirt.engine.core.compat.Guid) VmInterfaceManager(org.ovirt.engine.core.bll.network.VmInterfaceManager) VmNic(org.ovirt.engine.core.common.businessentities.network.VmNic)

Example 2 with VmInterfaceManager

use of org.ovirt.engine.core.bll.network.VmInterfaceManager 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());
}
Also used : VnicProfileHelper(org.ovirt.engine.core.bll.network.vm.VnicProfileHelper) VmNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface) VmInterfaceManager(org.ovirt.engine.core.bll.network.VmInterfaceManager)

Example 3 with VmInterfaceManager

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

Example 4 with VmInterfaceManager

use of org.ovirt.engine.core.bll.network.VmInterfaceManager in project ovirt-engine by oVirt.

the class TryBackToAllSnapshotsOfVmCommand method restoreVmConfigFromSnapshot.

private void restoreVmConfigFromSnapshot() {
    snapshotDao.updateStatus(getParameters().getDstSnapshotId(), SnapshotStatus.IN_PREVIEW);
    snapshotDao.updateStatus(snapshotDao.getId(getVm().getId(), SnapshotType.PREVIEW, SnapshotStatus.LOCKED), SnapshotStatus.OK);
    Guid activeSnapshotLeaseDomainId = null;
    if (isLeaseDomainIdUpdateNeeded()) {
        activeSnapshotLeaseDomainId = getVm().getStaticData().getLeaseStorageDomainId();
    }
    getSnapshotsManager().attempToRestoreVmConfigurationFromSnapshot(getVm(), getDstSnapshot(), snapshotDao.getId(getVm().getId(), SnapshotType.ACTIVE), getImagesToPreview(), getCompensationContext(), getCurrentUser(), new VmInterfaceManager(getMacPool()), isRestoreMemory());
    // custom preview - without leases
    if (!isRestoreLease()) {
        vmStaticDao.updateVmLeaseStorageDomainId(getVm().getId(), null);
        return;
    }
    Guid dstLeaseStorageDomainId = OvfUtils.fetchLeaseDomainId(getDstSnapshot().getVmConfiguration());
    if (isLeaseDomainIdUpdateNeeded()) {
        // previewed snapshot and active have leases on different domains, use the active snapshot lease
        vmStaticDao.updateVmLeaseStorageDomainId(getVm().getId(), activeSnapshotLeaseDomainId);
    } else if (getParameters().getDstLeaseDomainId() != null && !getParameters().getDstLeaseDomainId().equals(dstLeaseStorageDomainId)) {
        // custom preview - use the other snapshot lease.
        // if the given destination lease domain ID is not equals to the previewed snapshot lease domain ID
        // it means that the preview uses other lease domain ID that should set instead of the previewed snapshot
        // lease domain ID
        vmStaticDao.updateVmLeaseStorageDomainId(getVm().getId(), getParameters().getDstLeaseDomainId());
    }
}
Also used : Guid(org.ovirt.engine.core.compat.Guid) VmInterfaceManager(org.ovirt.engine.core.bll.network.VmInterfaceManager)

Example 5 with VmInterfaceManager

use of org.ovirt.engine.core.bll.network.VmInterfaceManager in project ovirt-engine by oVirt.

the class RestoreAllSnapshotsCommand method restoreConfiguration.

/**
 * Prepare to remove the active snapshot & restore the given snapshot to be the active one, including the
 * configuration.
 *
 * @param targetSnapshot
 *            The snapshot to restore to.
 */
private void restoreConfiguration(Snapshot targetSnapshot) {
    removedSnapshot = snapshotDao.get(getVmId(), SnapshotType.ACTIVE);
    snapshotsToRemove.add(removedSnapshot.getId());
    getSnapshotsManager().removeAllIllegalDisks(removedSnapshot.getId(), getVmId());
    getSnapshotsManager().attempToRestoreVmConfigurationFromSnapshot(getVm(), targetSnapshot, targetSnapshot.getId(), null, getCompensationContext(), getCurrentUser(), new VmInterfaceManager(getMacPool()), targetSnapshot.containsMemory());
    snapshotDao.remove(targetSnapshot.getId());
    // add active snapshot with status locked, so that other commands that depend on the VM's snapshots won't run in parallel
    getSnapshotsManager().addActiveSnapshot(targetSnapshot.getId(), getVm(), SnapshotStatus.LOCKED, targetSnapshot.getMemoryDiskId(), targetSnapshot.getMetadataDiskId(), getCompensationContext());
}
Also used : VmInterfaceManager(org.ovirt.engine.core.bll.network.VmInterfaceManager)

Aggregations

VmInterfaceManager (org.ovirt.engine.core.bll.network.VmInterfaceManager)6 VmNic (org.ovirt.engine.core.common.businessentities.network.VmNic)2 Guid (org.ovirt.engine.core.compat.Guid)2 ReadMacPool (org.ovirt.engine.core.bll.network.macpool.ReadMacPool)1 VnicProfileHelper (org.ovirt.engine.core.bll.network.vm.VnicProfileHelper)1 VmNetworkInterface (org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface)1 EngineMessage (org.ovirt.engine.core.common.errors.EngineMessage)1