Search in sources :

Example 11 with VmDeviceId

use of org.ovirt.engine.core.common.businessentities.VmDeviceId in project ovirt-engine by oVirt.

the class RemoveAllVmTemplateImageTemplatesCommand method executeCommand.

@SuppressWarnings("unchecked")
@Override
protected void executeCommand() {
    List<DiskImage> imageTemplates = DisksFilter.filterImageDisks(diskDao.getAllForVm(getVmTemplateId()), ONLY_ACTIVE);
    for (DiskImage template : imageTemplates) {
        // remove this disk in all domain that were sent
        for (Guid domain : (Collection<Guid>) CollectionUtils.intersection(getParameters().getStorageDomainsList(), template.getStorageIds())) {
            ImagesContainterParametersBase tempVar = new ImagesContainterParametersBase(template.getImageId(), getVmTemplateId());
            tempVar.setStorageDomainId(domain);
            tempVar.setStoragePoolId(template.getStoragePoolId());
            tempVar.setImageGroupID(template.getId());
            tempVar.setEntityInfo(getParameters().getEntityInfo());
            tempVar.setWipeAfterDelete(template.isWipeAfterDelete());
            tempVar.setTransactionScopeOption(TransactionScopeOption.RequiresNew);
            tempVar.setParentCommand(getActionType());
            tempVar.setParentParameters(getParameters());
            ActionReturnValue actionReturnValue = runInternalActionWithTasksContext(ActionType.RemoveTemplateSnapshot, tempVar);
            if (actionReturnValue.getSucceeded()) {
                getReturnValue().getInternalVdsmTaskIdList().addAll(actionReturnValue.getInternalVdsmTaskIdList());
            } else {
                log.error("Can't remove image id '{}' for template id '{}' from domain id '{}' due to: {}.", template.getImageId(), getVmTemplateId(), domain, actionReturnValue.getFault().getMessage());
            }
            imageStorageDomainMapDao.remove(new ImageStorageDomainMapId(template.getImageId(), domain));
        }
        DiskImage diskImage = diskImageDao.get(template.getImageId());
        if (diskImage != null) {
            baseDiskDao.remove(template.getId());
            vmDeviceDao.remove(new VmDeviceId(diskImage.getImageId(), getVmTemplateId()));
            imageStorageDomainMapDao.remove(diskImage.getImageId());
            imageDao.remove(template.getImageId());
        }
    }
    setSucceeded(true);
}
Also used : ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) ImagesContainterParametersBase(org.ovirt.engine.core.common.action.ImagesContainterParametersBase) ImageStorageDomainMapId(org.ovirt.engine.core.common.businessentities.storage.ImageStorageDomainMapId) Collection(java.util.Collection) Guid(org.ovirt.engine.core.compat.Guid) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) VmDeviceId(org.ovirt.engine.core.common.businessentities.VmDeviceId)

Example 12 with VmDeviceId

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

Example 13 with VmDeviceId

use of org.ovirt.engine.core.common.businessentities.VmDeviceId in project ovirt-engine by oVirt.

the class RemoveVmTemplateInterfaceCommand method executeCommand.

@Override
protected void executeCommand() {
    VmNetworkInterface iface = vmNetworkInterfaceDao.get(getParameters().getInterfaceId());
    if (iface != null) {
        addCustomValue("InterfaceName", iface.getName());
        addCustomValue("InterfaceType", VmInterfaceType.forValue(iface.getType()).getDescription());
    }
    vmDeviceDao.remove(new VmDeviceId(getParameters().getInterfaceId(), getParameters().getVmTemplateId()));
    vmNicDao.remove(getParameters().getInterfaceId());
    setSucceeded(true);
}
Also used : VmNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface) VmDeviceId(org.ovirt.engine.core.common.businessentities.VmDeviceId)

Example 14 with VmDeviceId

use of org.ovirt.engine.core.common.businessentities.VmDeviceId in project ovirt-engine by oVirt.

the class SnapshotsManager method populateDisksWithVmData.

private void populateDisksWithVmData(List<? extends Disk> disks, Guid vmId) {
    for (Disk disk : disks) {
        DiskVmElement dve = diskVmElementDao.get(new VmDeviceId(disk.getId(), vmId));
        disk.setDiskVmElements(Collections.singletonList(dve));
    }
}
Also used : DiskVmElement(org.ovirt.engine.core.common.businessentities.storage.DiskVmElement) Disk(org.ovirt.engine.core.common.businessentities.storage.Disk) VmDeviceId(org.ovirt.engine.core.common.businessentities.VmDeviceId)

Example 15 with VmDeviceId

use of org.ovirt.engine.core.common.businessentities.VmDeviceId in project ovirt-engine by oVirt.

the class RemoveDiskCommandTest method setUp.

@Before
public void setUp() {
    disk = new DiskImage();
    setupDisk();
    Guid vmId = Guid.newGuid();
    vm = new VM();
    vm.setId(vmId);
    VmDeviceId vmDeviceId = new VmDeviceId(diskId, vmId);
    VmDevice vmDevice = new VmDevice();
    vmDevice.setId(vmDeviceId);
    vmDevice.setPlugged(true);
    when(vmDao.getVmsListForDisk(diskId, Boolean.TRUE)).thenReturn(Collections.singletonList(vm));
    when(vmDeviceDao.get(vmDeviceId)).thenReturn(vmDevice);
    doReturn(disk).when(cmd).getDisk();
    doReturn(ActionType.RemoveDisk).when(cmd).getActionType();
}
Also used : VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) VM(org.ovirt.engine.core.common.businessentities.VM) Guid(org.ovirt.engine.core.compat.Guid) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) VmDeviceId(org.ovirt.engine.core.common.businessentities.VmDeviceId) Before(org.junit.Before)

Aggregations

VmDeviceId (org.ovirt.engine.core.common.businessentities.VmDeviceId)75 VmDevice (org.ovirt.engine.core.common.businessentities.VmDevice)40 DiskVmElement (org.ovirt.engine.core.common.businessentities.storage.DiskVmElement)21 Guid (org.ovirt.engine.core.compat.Guid)19 HashMap (java.util.HashMap)13 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)12 Test (org.junit.Test)10 Disk (org.ovirt.engine.core.common.businessentities.storage.Disk)9 ArrayList (java.util.ArrayList)7 Map (java.util.Map)5 GraphicsType (org.ovirt.engine.core.common.businessentities.GraphicsType)5 VM (org.ovirt.engine.core.common.businessentities.VM)5 VmPayload (org.ovirt.engine.core.common.businessentities.VmPayload)4 VmNetworkInterface (org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface)4 VmNic (org.ovirt.engine.core.common.businessentities.network.VmNic)4 Collection (java.util.Collection)3 HashSet (java.util.HashSet)3 DisplayType (org.ovirt.engine.core.common.businessentities.DisplayType)3 CinderDisk (org.ovirt.engine.core.common.businessentities.storage.CinderDisk)3 LunDisk (org.ovirt.engine.core.common.businessentities.storage.LunDisk)3