Search in sources :

Example 1 with VnicProfileHelper

use of org.ovirt.engine.core.bll.network.vm.VnicProfileHelper 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 2 with VnicProfileHelper

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

the class AddVmAndCloneImageCommand method addVmNetwork.

@Override
protected void addVmNetwork() {
    VnicProfileHelper vnicProfileHelper = new VnicProfileHelper(getClusterId(), getStoragePoolId(), AuditLogType.ADD_VM_FROM_SNAPSHOT_INVALID_INTERFACES);
    for (VmNetworkInterface iface : getVmFromConfiguration().getInterfaces()) {
        vnicProfileHelper.updateNicWithVnicProfileForUser(iface, getCurrentUser());
    }
    vnicProfileHelper.auditInvalidInterfaces(getVmName());
    super.addVmNetwork();
}
Also used : VnicProfileHelper(org.ovirt.engine.core.bll.network.vm.VnicProfileHelper) VmNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface)

Example 3 with VnicProfileHelper

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

the class SnapshotsManager method synchronizeNics.

/**
 * Synchronize the VM's {@link VmNetworkInterface}s with the ones from the snapshot.<br>
 * All existing NICs will be deleted, and the ones from the snapshot re-added.<br>
 * In case a MAC address is already in use, the user will be issued a warning in the audit log.
 *
 * @param user
 *            The user that performs the action
 * @param vmInterfaceManager vmInterfaceManager instance
 */
private void synchronizeNics(VM snapshotedVm, CompensationContext compensationContext, DbUser user, VmInterfaceManager vmInterfaceManager, boolean macsInSnapshotAreExpectedToBeAlreadyAllocated) {
    VnicProfileHelper vnicProfileHelper = new VnicProfileHelper(snapshotedVm.getClusterId(), snapshotedVm.getStoragePoolId(), AuditLogType.IMPORTEXPORT_SNAPSHOT_VM_INVALID_INTERFACES);
    MacPool macPool = vmInterfaceManager.getMacPool();
    /*what is at moment of calling this in DB are data related to (stateless) VM being updated/overwritten by
         * snapshot data.
         */
    List<VmNic> dbNics = vmNicDao.getAllForVm(snapshotedVm.getId());
    /*
         * while snapshotedVm.getInterfaces() are interfaces taken from VM passed into here via parameter. This instance originates from same DB
         * record, but it was updated with ovf snapshot, so at the moment of calling this, VM is filled with data to
         * which we need to revert for example stateless VM being stopped.
         */
    new SyncMacsOfDbNicsWithSnapshot(macPool, auditLogDirector, macsInSnapshotAreExpectedToBeAlreadyAllocated).sync(dbNics, snapshotedVm.getInterfaces());
    vmInterfaceManager.removeAll(dbNics);
    for (VmNetworkInterface vmInterface : snapshotedVm.getInterfaces()) {
        vmInterface.setVmId(snapshotedVm.getId());
        // These fields might not be saved in the OVF, so fill them with reasonable values.
        if (vmInterface.getId() == null) {
            vmInterface.setId(Guid.newGuid());
        }
        vnicProfileHelper.updateNicWithVnicProfileForUser(vmInterface, user);
        vmInterfaceManager.persistIface(vmInterface, compensationContext);
    }
    vnicProfileHelper.auditInvalidInterfaces(snapshotedVm.getName());
}
Also used : MacPool(org.ovirt.engine.core.bll.network.macpool.MacPool) VnicProfileHelper(org.ovirt.engine.core.bll.network.vm.VnicProfileHelper) VmNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface) VmNic(org.ovirt.engine.core.common.businessentities.network.VmNic)

Example 4 with VnicProfileHelper

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

the class ImportVmTemplateCommand method addVmInterfaces.

protected void addVmInterfaces() {
    VnicProfileHelper vnicProfileHelper = new VnicProfileHelper(getVmTemplate().getClusterId(), getStoragePoolId(), AuditLogType.IMPORTEXPORT_IMPORT_TEMPLATE_INVALID_INTERFACES);
    for (VmNetworkInterface iface : getVmTemplate().getInterfaces()) {
        if (iface.getId() == null) {
            iface.setId(Guid.newGuid());
        }
        iface.setVmId(getVmTemplateId());
        VmNic nic = new VmNic();
        nic.setId(iface.getId());
        nic.setVmTemplateId(getVmTemplateId());
        nic.setName(iface.getName());
        nic.setLinked(iface.isLinked());
        nic.setSpeed(iface.getSpeed());
        nic.setType(iface.getType());
        vnicProfileHelper.updateNicWithVnicProfileForUser(iface, getCurrentUser());
        nic.setVnicProfileId(iface.getVnicProfileId());
        vmNicDao.save(nic);
        getCompensationContext().snapshotNewEntity(nic);
        VmNetworkStatistics iStat = new VmNetworkStatistics();
        nic.setStatistics(iStat);
        iStat.setId(iface.getId());
        iStat.setVmId(getVmTemplateId());
        vmNetworkStatisticsDao.save(iStat);
        getCompensationContext().snapshotNewEntity(iStat);
    }
    vnicProfileHelper.auditInvalidInterfaces(getVmTemplateName());
}
Also used : VnicProfileHelper(org.ovirt.engine.core.bll.network.vm.VnicProfileHelper) VmNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface) VmNetworkStatistics(org.ovirt.engine.core.common.businessentities.network.VmNetworkStatistics) VmNic(org.ovirt.engine.core.common.businessentities.network.VmNic)

Aggregations

VnicProfileHelper (org.ovirt.engine.core.bll.network.vm.VnicProfileHelper)4 VmNetworkInterface (org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface)4 VmNic (org.ovirt.engine.core.common.businessentities.network.VmNic)2 VmInterfaceManager (org.ovirt.engine.core.bll.network.VmInterfaceManager)1 MacPool (org.ovirt.engine.core.bll.network.macpool.MacPool)1 VmNetworkStatistics (org.ovirt.engine.core.common.businessentities.network.VmNetworkStatistics)1