Search in sources :

Example 6 with DiskAttachment

use of org.ovirt.engine.api.model.DiskAttachment in project ovirt-engine by oVirt.

the class BackendVmsResourceTest method map.

private DiskAttachment map(DiskImage entity, DiskAttachment template) {
    Disk disk = getMapper(org.ovirt.engine.core.common.businessentities.storage.Disk.class, Disk.class).map(entity, null);
    DiskAttachment diskAttachment = new DiskAttachment();
    diskAttachment.setDisk(disk);
    return diskAttachment;
}
Also used : DiskAttachment(org.ovirt.engine.api.model.DiskAttachment) Disk(org.ovirt.engine.api.model.Disk)

Example 7 with DiskAttachment

use of org.ovirt.engine.api.model.DiskAttachment in project ovirt-engine by oVirt.

the class BackendVmsResource method prepareImagesForCloneFromSnapshotParams.

private void prepareImagesForCloneFromSnapshotParams(DiskAttachments disksAttachments, Map<Guid, DiskImage> imagesFromConfiguration) {
    if (disksAttachments.getDiskAttachments() != null) {
        for (DiskAttachment diskAttachment : disksAttachments.getDiskAttachments()) {
            Disk disk = diskAttachment.getDisk();
            if (disk != null && disk.isSetImageId()) {
                DiskImage diskImageFromConfig = imagesFromConfiguration.get(asGuid(disk.getImageId()));
                DiskImage diskImage = (DiskImage) getMapper(Disk.class, org.ovirt.engine.core.common.businessentities.storage.Disk.class).map(disk, diskImageFromConfig);
                imagesFromConfiguration.put(diskImage.getId(), diskImage);
            }
        }
    }
}
Also used : DiskAttachment(org.ovirt.engine.api.model.DiskAttachment) Disk(org.ovirt.engine.api.model.Disk) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage)

Example 8 with DiskAttachment

use of org.ovirt.engine.api.model.DiskAttachment in project ovirt-engine by oVirt.

the class BackendVmDisksResource method add.

@Override
public Response add(Disk disk) {
    DiskAttachment diskAttachment = new DiskAttachment();
    if (disk.isSetBootable()) {
        diskAttachment.setBootable(disk.isBootable());
    } else {
        diskAttachment.setBootable(false);
    }
    if (disk.isSetInterface()) {
        diskAttachment.setInterface(disk.getInterface());
    } else {
        diskAttachment.setInterface(DiskInterface.VIRTIO);
    }
    if (disk.isSetActive()) {
        diskAttachment.setActive(disk.isActive());
    }
    diskAttachment.setDisk(disk);
    if (disk.isSetId()) {
        Guid diskId = Guid.createGuidFromStringDefaultEmpty(disk.getId());
        return getAttachmentsResource().attachDiskToVm(this, diskAttachment, new OldAttachDiskResolver(diskId));
    } else {
        return getAttachmentsResource().createDisk(this, diskAttachment, new OldAddDiskResolver());
    }
}
Also used : DiskAttachment(org.ovirt.engine.api.model.DiskAttachment) Guid(org.ovirt.engine.core.compat.Guid)

Example 9 with DiskAttachment

use of org.ovirt.engine.api.model.DiskAttachment in project ovirt-engine by oVirt.

the class BackendTemplatesResource method getDestinationTemplateDiskMap.

protected HashMap<Guid, DiskImage> getDestinationTemplateDiskMap(Vm vm, Guid vmId, Guid storageDomainId, boolean isTemplateGeneralStorageDomainSet) {
    HashMap<Guid, DiskImage> destinationTemplateDiskMap = null;
    if (vm.isSetDiskAttachments() && vm.getDiskAttachments().isSetDiskAttachments()) {
        destinationTemplateDiskMap = new HashMap<>();
        Map<Guid, org.ovirt.engine.core.common.businessentities.storage.Disk> vmSourceDisks = queryVmDisksMap(vmId);
        for (DiskAttachment diskAttachment : vm.getDiskAttachments().getDiskAttachments()) {
            Disk disk = diskAttachment.getDisk();
            if (disk == null || !disk.isSetId()) {
                continue;
            }
            Guid currDiskID = asGuid(disk.getId());
            org.ovirt.engine.core.common.businessentities.storage.Disk sourceDisk = vmSourceDisks.get(currDiskID);
            // VM template can only have disk images
            if (sourceDisk == null || !isDiskImage(sourceDisk)) {
                continue;
            }
            DiskImage destinationDisk = (DiskImage) DiskMapper.map(disk, sourceDisk);
            if (isTemplateGeneralStorageDomainSet) {
                destinationDisk.setStorageIds(new ArrayList<>(Arrays.asList(storageDomainId)));
            }
            // Since domain can be changed, do not set profile and quota for this disk.
            destinationDisk.setDiskProfileId(null);
            destinationDisk.setQuotaId(null);
            destinationTemplateDiskMap.put(destinationDisk.getId(), destinationDisk);
        }
    }
    return destinationTemplateDiskMap;
}
Also used : Guid(org.ovirt.engine.core.compat.Guid) DiskAttachment(org.ovirt.engine.api.model.DiskAttachment) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) Disk(org.ovirt.engine.api.model.Disk)

Example 10 with DiskAttachment

use of org.ovirt.engine.api.model.DiskAttachment in project ovirt-engine by oVirt.

the class V3DiskSnapshotOutAdapter method adapt.

@Override
public V3DiskSnapshot adapt(DiskSnapshot from) {
    V3DiskSnapshot to = new V3DiskSnapshot();
    if (from.isSetLinks()) {
        to.getLinks().addAll(adaptOut(from.getLinks()));
    }
    if (from.isSetActions()) {
        to.setActions(adaptOut(from.getActions()));
    }
    if (from.isSetActualSize()) {
        to.setActualSize(from.getActualSize());
    }
    if (from.isSetAlias()) {
        to.setAlias(from.getAlias());
    }
    if (from.isSetComment()) {
        to.setComment(from.getComment());
    }
    if (from.isSetDescription()) {
        to.setDescription(from.getDescription());
    }
    if (from.isSetDisk()) {
        to.setDisk(adaptOut(from.getDisk()));
    }
    if (from.isSetDiskProfile()) {
        to.setDiskProfile(adaptOut(from.getDiskProfile()));
    }
    if (from.isSetFormat()) {
        to.setFormat(from.getFormat().value());
    }
    if (from.isSetId()) {
        to.setId(from.getId());
    }
    if (from.isSetHref()) {
        to.setHref(from.getHref());
    }
    if (from.isSetImageId()) {
        to.setImageId(from.getImageId());
    }
    if (from.isSetInstanceType()) {
        to.setInstanceType(adaptOut(from.getInstanceType()));
    }
    if (from.isSetLogicalName()) {
        to.setLogicalName(from.getLogicalName());
    }
    if (from.isSetLunStorage()) {
        to.setLunStorage(adaptOut(from.getLunStorage()));
    }
    if (from.isSetName()) {
        to.setName(from.getName());
    }
    if (from.isSetOpenstackVolumeType()) {
        to.setOpenstackVolumeType(adaptOut(from.getOpenstackVolumeType()));
    }
    if (from.isSetPropagateErrors()) {
        to.setPropagateErrors(from.isPropagateErrors());
    }
    if (from.isSetProvisionedSize()) {
        to.setProvisionedSize(from.getProvisionedSize());
    }
    if (from.isSetQuota()) {
        to.setQuota(adaptOut(from.getQuota()));
    }
    if (from.isSetReadOnly()) {
        to.setReadOnly(from.isReadOnly());
    }
    if (from.isSetSgio()) {
        to.setSgio(from.getSgio().value());
    }
    if (from.isSetShareable()) {
        to.setShareable(from.isShareable());
    }
    if (from.isSetSnapshot()) {
        to.setSnapshot(adaptOut(from.getSnapshot()));
    }
    if (from.isSetSparse()) {
        to.setSparse(from.isSparse());
    }
    if (from.isSetStatistics()) {
        to.setStatistics(new V3Statistics());
        to.getStatistics().getStatistics().addAll(adaptOut(from.getStatistics().getStatistics()));
    }
    if (from.isSetStatus()) {
        V3Status status = new V3Status();
        status.setState(from.getStatus().value());
        to.setStatus(status);
    }
    if (from.isSetStorageDomain()) {
        to.setStorageDomain(adaptOut(from.getStorageDomain()));
    }
    if (from.isSetStorageDomains()) {
        to.setStorageDomains(new V3StorageDomains());
        to.getStorageDomains().getStorageDomains().addAll(adaptOut(from.getStorageDomains().getStorageDomains()));
    }
    if (from.isSetStorageType()) {
        to.setStorageType(from.getStorageType().value());
    }
    if (from.isSetTemplate()) {
        to.setTemplate(adaptOut(from.getTemplate()));
    }
    if (from.isSetUsesScsiReservation()) {
        to.setUsesScsiReservation(from.isUsesScsiReservation());
    }
    if (from.isSetVm()) {
        to.setVm(adaptOut(from.getVm()));
    }
    if (from.isSetVms()) {
        to.setVms(new V3VMs());
        to.getVms().getVMs().addAll(adaptOut(from.getVms().getVms()));
    }
    if (from.isSetWipeAfterDelete()) {
        to.setWipeAfterDelete(from.isWipeAfterDelete());
    }
    // continue supporting it. To do so we need to find the disk attachment and copy this attribute to the disk.
    if (to.isSetId() && to.isSetVm() && to.getVm().isSetId()) {
        String diskId = to.getId();
        String vmId = to.getVm().getId();
        VmsResource vmsResource = BackendApiResource.getInstance().getVmsResource();
        VmResource vmResource = vmsResource.getVmResource(vmId);
        DiskAttachmentsResource attachmentsResource = vmResource.getDiskAttachmentsResource();
        DiskAttachmentResource attachmentResource = attachmentsResource.getAttachmentResource(diskId);
        DiskAttachment attachment = attachmentResource.get();
        if (attachment.isSetActive()) {
            to.setActive(attachment.isActive());
        }
    }
    return to;
}
Also used : VmResource(org.ovirt.engine.api.resource.VmResource) DiskAttachmentsResource(org.ovirt.engine.api.resource.DiskAttachmentsResource) DiskAttachmentResource(org.ovirt.engine.api.resource.DiskAttachmentResource) DiskAttachment(org.ovirt.engine.api.model.DiskAttachment) VmsResource(org.ovirt.engine.api.resource.VmsResource) V3DiskSnapshot(org.ovirt.engine.api.v3.types.V3DiskSnapshot) V3Status(org.ovirt.engine.api.v3.types.V3Status) V3Statistics(org.ovirt.engine.api.v3.types.V3Statistics) V3VMs(org.ovirt.engine.api.v3.types.V3VMs) V3StorageDomains(org.ovirt.engine.api.v3.types.V3StorageDomains)

Aggregations

DiskAttachment (org.ovirt.engine.api.model.DiskAttachment)16 Disk (org.ovirt.engine.api.model.Disk)10 DiskAttachments (org.ovirt.engine.api.model.DiskAttachments)5 Vm (org.ovirt.engine.api.model.Vm)5 V3Disk (org.ovirt.engine.api.v3.types.V3Disk)5 V3Status (org.ovirt.engine.api.v3.types.V3Status)4 Guid (org.ovirt.engine.core.compat.Guid)4 DiskAttachmentsResource (org.ovirt.engine.api.resource.DiskAttachmentsResource)3 VmResource (org.ovirt.engine.api.resource.VmResource)3 VmsResource (org.ovirt.engine.api.resource.VmsResource)3 V3Disks (org.ovirt.engine.api.v3.types.V3Disks)3 V3Statistics (org.ovirt.engine.api.v3.types.V3Statistics)3 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)3 WebApplicationException (javax.ws.rs.WebApplicationException)2 TimeZone (org.ovirt.engine.api.model.TimeZone)2 DiskAttachmentResource (org.ovirt.engine.api.resource.DiskAttachmentResource)2 SystemResource (org.ovirt.engine.api.resource.SystemResource)2 V3CdRoms (org.ovirt.engine.api.v3.types.V3CdRoms)2 V3CustomProperties (org.ovirt.engine.api.v3.types.V3CustomProperties)2 V3Floppies (org.ovirt.engine.api.v3.types.V3Floppies)2