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);
}
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;
});
}
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);
}
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));
}
}
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();
}
Aggregations