Search in sources :

Example 41 with Disk

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

the class AbstractBackendStorageDomainDiskResource method get.

public Disk get() {
    Disk disk;
    boolean unregistered = ParametersHelper.getBooleanParameter(httpHeaders, uriInfo, UNREGISTERED, true, false);
    if (unregistered) {
        QueryReturnValue result = runQuery(QueryType.GetDiskByDiskId, new IdQueryParameters(guid));
        if (!result.getSucceeded() || result.getReturnValue() == null) {
            Guid dataCenterId = BackendDataCenterHelper.lookupByStorageDomainId(this, storageDomainId);
            disk = performGet(QueryType.GetUnregisteredDisk, new GetUnregisteredDiskQueryParameters(guid, storageDomainId, dataCenterId));
        } else {
            // since the unregistered parameter was passed.
            return notFound();
        }
    } else {
        disk = getDelegate().get();
    }
    if (disk.isSetStorageDomains() && !disk.getStorageDomains().getStorageDomains().isEmpty()) {
        for (StorageDomain sd : disk.getStorageDomains().getStorageDomains()) {
            if (sd.isSetId() && sd.getId().equals(storageDomainId.toString())) {
                return disk;
            }
        }
    }
    return notFound();
}
Also used : QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) StorageDomain(org.ovirt.engine.api.model.StorageDomain) IdQueryParameters(org.ovirt.engine.core.common.queries.IdQueryParameters) Guid(org.ovirt.engine.core.compat.Guid) GetUnregisteredDiskQueryParameters(org.ovirt.engine.core.common.queries.GetUnregisteredDiskQueryParameters) Disk(org.ovirt.engine.api.model.Disk)

Example 42 with Disk

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

the class AbstractBackendStorageDomainDisksResource method add.

public Response add(Disk disk) {
    // Unregistering a disk using this method was deprecated in version 4.2
    // unregistered support for add disk has moved to BackendAttachedStorageDomainDiskResource..
    boolean unregistered = ParametersHelper.getBooleanParameter(httpHeaders, uriInfo, UNREGISTERED, true, false);
    if (unregistered) {
        // First we need to query the backend to fill in all the information about the disk from the VDSM.
        // We don't just use the information from the Disk object because it's missing a few things like creation
        // date and last modified date.
        Guid dataCenterId = BackendDataCenterHelper.lookupByStorageDomainId(this, storageDomainId);
        GetUnregisteredDiskQueryParameters getDiskParams = new GetUnregisteredDiskQueryParameters(asGuid(disk.getId()), storageDomainId, dataCenterId);
        DiskImage unregisteredDisk = getEntity(DiskImage.class, QueryType.GetUnregisteredDisk, getDiskParams, disk.getId());
        unregisteredDisk = (DiskImage) getMapper(Disk.class, org.ovirt.engine.core.common.businessentities.storage.Disk.class).map(disk, unregisteredDisk);
        RegisterDiskParameters registerDiskParams = new RegisterDiskParameters(unregisteredDisk, storageDomainId);
        return performCreate(ActionType.RegisterDisk, registerDiskParams, ID_RESOLVER);
    } else {
        validateDiskForCreation(disk);
        AddDiskParameters params = new AddDiskParameters();
        params.setDiskInfo(getMapper(Disk.class, org.ovirt.engine.core.common.businessentities.storage.Disk.class).map(disk, null));
        params.setStorageDomainId(this.storageDomainId);
        return performCreate(ActionType.AddDisk, params, ID_RESOLVER);
    }
}
Also used : Guid(org.ovirt.engine.core.compat.Guid) AddDiskParameters(org.ovirt.engine.core.common.action.AddDiskParameters) RegisterDiskParameters(org.ovirt.engine.core.common.action.RegisterDiskParameters) GetUnregisteredDiskQueryParameters(org.ovirt.engine.core.common.queries.GetUnregisteredDiskQueryParameters) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) Disk(org.ovirt.engine.api.model.Disk)

Example 43 with Disk

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

the class V3VmOutAdapter method adapt.

@Override
public V3VM adapt(Vm from) {
    V3VM to = new V3VM();
    // Remove the links for "rels" that are new in version 4 of the API:
    if (from.isSetLinks()) {
        List<Link> links = from.getLinks().stream().filter(link -> !RELS_TO_REMOVE.contains(link.getRel())).collect(toList());
        to.getLinks().addAll(adaptOut(links));
    }
    if (from.isSetActions()) {
        to.setActions(adaptOut(from.getActions()));
        // In version 3 of the API the actions related to snapshots used non standard URL segments, with underscores
        // to separate words: preview_snapshot, commit_snapshot and undo_snapshot. In version 4 of the API all the
        // URL segments use the same style for URL segments, without underscores, there are no exceptions. So in
        // order to keep backwards compatibility we need to add the underscores to the action links generated by
        // version 4 of the API.
        to.getActions().getLinks().stream().filter(this::isSnapshotLink).forEach(this::fixSnapshotLink);
    }
    if (from.isSetBios()) {
        to.setBios(adaptOut(from.getBios()));
    }
    if (from.isSetCdroms()) {
        to.setCdroms(new V3CdRoms());
        to.getCdroms().getCdRoms().addAll(adaptOut(from.getCdroms().getCdroms()));
    }
    if (from.isSetCluster()) {
        to.setCluster(adaptOut(from.getCluster()));
    }
    if (from.isSetComment()) {
        to.setComment(from.getComment());
    }
    if (from.isSetConsole()) {
        to.setConsole(adaptOut(from.getConsole()));
    }
    if (from.isSetCpu()) {
        to.setCpu(adaptOut(from.getCpu()));
    }
    if (from.isSetCpuProfile()) {
        to.setCpuProfile(adaptOut(from.getCpuProfile()));
    }
    if (from.isSetCpuShares()) {
        to.setCpuShares(from.getCpuShares());
    }
    if (from.isSetCreationTime()) {
        to.setCreationTime(from.getCreationTime());
    }
    if (from.isSetCustomCpuModel()) {
        to.setCustomCpuModel(from.getCustomCpuModel());
    }
    if (from.isSetCustomEmulatedMachine()) {
        to.setCustomEmulatedMachine(from.getCustomEmulatedMachine());
    }
    if (from.isSetCustomProperties()) {
        to.setCustomProperties(new V3CustomProperties());
        to.getCustomProperties().getCustomProperty().addAll(adaptOut(from.getCustomProperties().getCustomProperties()));
    }
    if (from.isSetDeleteProtected()) {
        to.setDeleteProtected(from.isDeleteProtected());
    }
    if (from.isSetDescription()) {
        to.setDescription(from.getDescription());
    }
    if (from.isSetDiskAttachments()) {
        V3Disks toDisks = new V3Disks();
        for (DiskAttachment fromDiskAttachment : from.getDiskAttachments().getDiskAttachments()) {
            Disk fromDisk = fromDiskAttachment.getDisk();
            if (fromDisk != null) {
                V3Disk toDisk = adaptOut(fromDisk);
                toDisks.getDisks().add(toDisk);
            }
        }
        to.setDisks(toDisks);
    }
    if (from.isSetDisplay()) {
        to.setDisplay(adaptOut(from.getDisplay()));
    }
    if (from.isSetDomain()) {
        to.setDomain(adaptOut(from.getDomain()));
    }
    if (from.isSetExternalHostProvider()) {
        to.setExternalHostProvider(adaptOut(from.getExternalHostProvider()));
    }
    if (from.isSetFloppies()) {
        to.setFloppies(new V3Floppies());
        to.getFloppies().getFloppies().addAll(adaptOut(from.getFloppies().getFloppies()));
    }
    if (from.isSetGuestOperatingSystem()) {
        to.setGuestOperatingSystem(adaptOut(from.getGuestOperatingSystem()));
    }
    if (from.isSetGuestTimeZone()) {
        to.setGuestTimeZone(adaptOut(from.getGuestTimeZone()));
    }
    if (from.isSetHighAvailability()) {
        to.setHighAvailability(adaptOut(from.getHighAvailability()));
    }
    if (from.isSetHost()) {
        to.setHost(adaptOut(from.getHost()));
    }
    if (from.isSetId()) {
        to.setId(from.getId());
    }
    if (from.isSetHref()) {
        to.setHref(from.getHref());
    }
    if (from.isSetInitialization()) {
        to.setInitialization(adaptOut(from.getInitialization()));
    }
    if (from.isSetInstanceType()) {
        to.setInstanceType(adaptOut(from.getInstanceType()));
    }
    if (from.isSetIo()) {
        to.setIo(adaptOut(from.getIo()));
    }
    if (from.isSetKatelloErrata()) {
        to.setKatelloErrata(new V3KatelloErrata());
        to.getKatelloErrata().getKatelloErrata().addAll(adaptOut(from.getKatelloErrata().getKatelloErrata()));
    }
    if (from.isSetLargeIcon()) {
        to.setLargeIcon(adaptOut(from.getLargeIcon()));
    }
    if (from.isSetMemory()) {
        to.setMemory(from.getMemory());
    }
    if (from.isSetMemoryPolicy()) {
        to.setMemoryPolicy(adaptOut(from.getMemoryPolicy()));
    }
    if (from.isSetMigration()) {
        to.setMigration(adaptOut(from.getMigration()));
    }
    if (from.isSetMigrationDowntime()) {
        to.setMigrationDowntime(from.getMigrationDowntime());
    }
    if (from.isSetName()) {
        to.setName(from.getName());
    }
    if (from.isSetNextRunConfigurationExists()) {
        to.setNextRunConfigurationExists(from.isNextRunConfigurationExists());
    }
    if (from.isSetNics()) {
        to.setNics(new V3Nics());
        to.getNics().getNics().addAll(adaptOut(from.getNics().getNics()));
    }
    if (from.isSetNumaTuneMode()) {
        to.setNumaTuneMode(from.getNumaTuneMode().value());
    }
    if (from.isSetOrigin()) {
        to.setOrigin(from.getOrigin());
    }
    if (from.isSetOs()) {
        to.setOs(adaptOut(from.getOs()));
    }
    if (from.isSetPayloads()) {
        to.setPayloads(new V3Payloads());
        to.getPayloads().getPayload().addAll(adaptOut(from.getPayloads().getPayloads()));
    }
    if (from.isSetPermissions()) {
        to.setPermissions(new V3Permissions());
        to.getPermissions().getPermissions().addAll(adaptOut(from.getPermissions().getPermissions()));
    }
    if (from.isSetPlacementPolicy()) {
        to.setPlacementPolicy(adaptOut(from.getPlacementPolicy()));
    }
    if (from.isSetQuota()) {
        to.setQuota(adaptOut(from.getQuota()));
    }
    if (from.isSetReportedDevices()) {
        to.setReportedDevices(new V3ReportedDevices());
        to.getReportedDevices().getReportedDevices().addAll(adaptOut(from.getReportedDevices().getReportedDevices()));
    }
    if (from.isSetRngDevice()) {
        to.setRngDevice(adaptOut(from.getRngDevice()));
    }
    if (from.isSetRunOnce()) {
        to.setRunOnce(from.isRunOnce());
    }
    if (from.isSetSerialNumber()) {
        to.setSerialNumber(adaptOut(from.getSerialNumber()));
    }
    if (from.isSetSmallIcon()) {
        to.setSmallIcon(adaptOut(from.getSmallIcon()));
    }
    if (from.isSetSnapshots()) {
        to.setSnapshots(new V3Snapshots());
        to.getSnapshots().getSnapshots().addAll(adaptOut(from.getSnapshots().getSnapshots()));
    }
    if (from.isSetSoundcardEnabled()) {
        to.setSoundcardEnabled(from.isSoundcardEnabled());
    }
    if (from.isSetSso()) {
        to.setSso(adaptOut(from.getSso()));
    }
    if (from.isSetStartPaused()) {
        to.setStartPaused(from.isStartPaused());
    }
    if (from.isSetStartTime()) {
        to.setStartTime(from.getStartTime());
    }
    if (from.isSetStateless()) {
        to.setStateless(from.isStateless());
    }
    if (from.isSetStatistics()) {
        to.setStatistics(new V3Statistics());
        to.getStatistics().getStatistics().addAll(adaptOut(from.getStatistics().getStatistics()));
    }
    if (from.isSetStatus()) {
        V3Status status = to.getStatus();
        if (status == null) {
            status = new V3Status();
            to.setStatus(status);
        }
        status.setState(from.getStatus().value());
    }
    if (from.isSetStatusDetail()) {
        V3Status status = to.getStatus();
        if (status == null) {
            status = new V3Status();
            to.setStatus(status);
        }
        status.setDetail(from.getStatusDetail());
    }
    if (from.isSetStopReason()) {
        to.setStopReason(from.getStopReason());
    }
    if (from.isSetStopTime()) {
        to.setStopTime(from.getStopTime());
    }
    if (from.isSetStorageDomain()) {
        to.setStorageDomain(adaptOut(from.getStorageDomain()));
    }
    if (from.isSetTags()) {
        to.setTags(new V3Tags());
        to.getTags().getTags().addAll(adaptOut(from.getTags().getTags()));
    }
    if (from.isSetTemplate()) {
        to.setTemplate(adaptOut(from.getTemplate()));
    }
    if (from.isSetTimeZone()) {
        to.setTimeZone(adaptOut(from.getTimeZone()));
    }
    if (from.isSetTunnelMigration()) {
        to.setTunnelMigration(from.isTunnelMigration());
    }
    if (from.isSetType()) {
        to.setType(from.getType().value());
    }
    if (from.isSetUsb()) {
        to.setUsb(adaptOut(from.getUsb()));
    }
    if (from.isSetUseLatestTemplateVersion()) {
        to.setUseLatestTemplateVersion(from.isUseLatestTemplateVersion());
    }
    if (from.isSetVirtioScsi()) {
        to.setVirtioScsi(adaptOut(from.getVirtioScsi()));
    }
    if (from.isSetVmPool()) {
        to.setVmPool(adaptOut(from.getVmPool()));
    }
    if (from.isSetWatchdogs()) {
        to.setWatchdogs(new V3WatchDogs());
        to.getWatchdogs().getWatchDogs().addAll(adaptOut(from.getWatchdogs().getWatchdogs()));
    }
    // new structured "time_zone" element containing the name of the time zone and the UTC offset:
    if (from.isSetTimeZone() && !to.isSetTimezone()) {
        TimeZone timeZone = from.getTimeZone();
        if (timeZone.isSetName()) {
            to.setTimezone(timeZone.getName());
        }
    }
    // If the V4 virtual machine has a value for the "fqdn" element, then copy it to the V3 "guest_info" element:
    if (from.isSetFqdn()) {
        V3GuestInfo guestInfo = to.getGuestInfo();
        if (guestInfo == null) {
            guestInfo = new V3GuestInfo();
            to.setGuestInfo(guestInfo);
        }
        guestInfo.setFqdn(from.getFqdn());
    }
    return to;
}
Also used : V3Tags(org.ovirt.engine.api.v3.types.V3Tags) V3Permissions(org.ovirt.engine.api.v3.types.V3Permissions) Vm(org.ovirt.engine.api.model.Vm) V3WatchDogs(org.ovirt.engine.api.v3.types.V3WatchDogs) TimeZone(org.ovirt.engine.api.model.TimeZone) V3CdRoms(org.ovirt.engine.api.v3.types.V3CdRoms) V3VM(org.ovirt.engine.api.v3.types.V3VM) HashSet(java.util.HashSet) DiskAttachment(org.ovirt.engine.api.model.DiskAttachment) Disk(org.ovirt.engine.api.model.Disk) V3GuestInfo(org.ovirt.engine.api.v3.types.V3GuestInfo) V3OutAdapters.adaptOut(org.ovirt.engine.api.v3.adapters.V3OutAdapters.adaptOut) V3Disk(org.ovirt.engine.api.v3.types.V3Disk) V3Status(org.ovirt.engine.api.v3.types.V3Status) V3Adapter(org.ovirt.engine.api.v3.V3Adapter) V3Floppies(org.ovirt.engine.api.v3.types.V3Floppies) V3KatelloErrata(org.ovirt.engine.api.v3.types.V3KatelloErrata) V3ReportedDevices(org.ovirt.engine.api.v3.types.V3ReportedDevices) Set(java.util.Set) V3Statistics(org.ovirt.engine.api.v3.types.V3Statistics) V3Snapshots(org.ovirt.engine.api.v3.types.V3Snapshots) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) V3Nics(org.ovirt.engine.api.v3.types.V3Nics) Link(org.ovirt.engine.api.model.Link) V3Disks(org.ovirt.engine.api.v3.types.V3Disks) V3CustomProperties(org.ovirt.engine.api.v3.types.V3CustomProperties) V3Link(org.ovirt.engine.api.v3.types.V3Link) V3Payloads(org.ovirt.engine.api.v3.types.V3Payloads) V3Floppies(org.ovirt.engine.api.v3.types.V3Floppies) V3Tags(org.ovirt.engine.api.v3.types.V3Tags) V3Permissions(org.ovirt.engine.api.v3.types.V3Permissions) V3KatelloErrata(org.ovirt.engine.api.v3.types.V3KatelloErrata) V3Payloads(org.ovirt.engine.api.v3.types.V3Payloads) V3ReportedDevices(org.ovirt.engine.api.v3.types.V3ReportedDevices) V3Statistics(org.ovirt.engine.api.v3.types.V3Statistics) V3WatchDogs(org.ovirt.engine.api.v3.types.V3WatchDogs) TimeZone(org.ovirt.engine.api.model.TimeZone) V3VM(org.ovirt.engine.api.v3.types.V3VM) DiskAttachment(org.ovirt.engine.api.model.DiskAttachment) V3CustomProperties(org.ovirt.engine.api.v3.types.V3CustomProperties) V3Disk(org.ovirt.engine.api.v3.types.V3Disk) V3Snapshots(org.ovirt.engine.api.v3.types.V3Snapshots) V3Disks(org.ovirt.engine.api.v3.types.V3Disks) V3Status(org.ovirt.engine.api.v3.types.V3Status) V3GuestInfo(org.ovirt.engine.api.v3.types.V3GuestInfo) V3Nics(org.ovirt.engine.api.v3.types.V3Nics) Disk(org.ovirt.engine.api.model.Disk) V3Disk(org.ovirt.engine.api.v3.types.V3Disk) Link(org.ovirt.engine.api.model.Link) V3Link(org.ovirt.engine.api.v3.types.V3Link) V3CdRoms(org.ovirt.engine.api.v3.types.V3CdRoms)

Example 44 with Disk

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

the class PermissionMapper method setObjectId.

/**
 * Completeness of "{entityType}.id" already validated
 */
private static void setObjectId(Permission model, org.ovirt.engine.core.common.businessentities.Permission entity) {
    String id = entity.getObjectId().toString();
    switch(entity.getObjectType()) {
        case System:
            break;
        case StoragePool:
            model.setDataCenter(new DataCenter());
            model.getDataCenter().setId(id);
            break;
        case Cluster:
            model.setCluster(new Cluster());
            model.getCluster().setId(id);
            break;
        case VDS:
            model.setHost(new Host());
            model.getHost().setId(id);
            break;
        case Storage:
            model.setStorageDomain(new StorageDomain());
            model.getStorageDomain().setId(id);
            break;
        case VM:
            model.setVm(new Vm());
            model.getVm().setId(id);
            break;
        case VmPool:
            model.setVmPool(new VmPool());
            model.getVmPool().setId(id);
            break;
        case VmTemplate:
            model.setTemplate(new Template());
            model.getTemplate().setId(id);
            break;
        case Disk:
            model.setDisk(new Disk());
            model.getDisk().setId(id);
            break;
        default:
            assert false;
    }
}
Also used : StorageDomain(org.ovirt.engine.api.model.StorageDomain) DataCenter(org.ovirt.engine.api.model.DataCenter) VmPool(org.ovirt.engine.api.model.VmPool) Vm(org.ovirt.engine.api.model.Vm) Cluster(org.ovirt.engine.api.model.Cluster) Host(org.ovirt.engine.api.model.Host) Disk(org.ovirt.engine.api.model.Disk) Template(org.ovirt.engine.api.model.Template)

Example 45 with Disk

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

the class BackendStorageDomainVmResourceTest method testImportWithDiskWithoutId.

@Test
public void testImportWithDiskWithoutId() throws Exception {
    StorageDomain storageDomain = new StorageDomain();
    storageDomain.setId(GUIDS[2].toString());
    org.ovirt.engine.api.model.Cluster cluster = new org.ovirt.engine.api.model.Cluster();
    cluster.setId(GUIDS[1].toString());
    setUpGetDataCenterByStorageDomainExpectations(STORAGE_DOMAIN_ID);
    setUpGetEntityExpectations(1, StorageDomainType.ImportExport, GUIDS[2]);
    UriInfo uriInfo = setUpBasicUriExpectations();
    uriInfo = addMatrixParameterExpectations(uriInfo, BackendStorageDomainVmResource.COLLAPSE_SNAPSHOTS, Boolean.toString(true));
    setUriInfo(uriInfo);
    Action action = new Action();
    action.setStorageDomain(storageDomain);
    action.setCluster(cluster);
    action.setClone(false);
    Vm vm = new Vm();
    DiskAttachments diskAttachments = new DiskAttachments();
    DiskAttachment diskAttachment = new DiskAttachment();
    diskAttachment.setDisk(new Disk());
    diskAttachments.getDiskAttachments().add(diskAttachment);
    vm.setDiskAttachments(diskAttachments);
    action.setVm(vm);
    try {
        resource.doImport(action);
        fail("expected WebApplicationException");
    } catch (WebApplicationException wae) {
        verifyIncompleteException(wae, "Disk", "setVolumesTypeFormat", "id");
    }
}
Also used : Action(org.ovirt.engine.api.model.Action) WebApplicationException(javax.ws.rs.WebApplicationException) Cluster(org.ovirt.engine.core.common.businessentities.Cluster) DiskAttachments(org.ovirt.engine.api.model.DiskAttachments) BackendStorageDomainVmsResourceTest.setUpStorageDomain(org.ovirt.engine.api.restapi.resource.BackendStorageDomainVmsResourceTest.setUpStorageDomain) StorageDomain(org.ovirt.engine.api.model.StorageDomain) DiskAttachment(org.ovirt.engine.api.model.DiskAttachment) Vm(org.ovirt.engine.api.model.Vm) Disk(org.ovirt.engine.api.model.Disk) UriInfo(javax.ws.rs.core.UriInfo) Test(org.junit.Test)

Aggregations

Disk (org.ovirt.engine.api.model.Disk)68 Test (org.junit.Test)33 Response (javax.ws.rs.core.Response)13 Guid (org.ovirt.engine.core.compat.Guid)13 WebApplicationException (javax.ws.rs.WebApplicationException)10 DiskAttachment (org.ovirt.engine.api.model.DiskAttachment)10 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)10 StorageDomain (org.ovirt.engine.api.model.StorageDomain)9 AsyncTaskStatus (org.ovirt.engine.core.common.businessentities.AsyncTaskStatus)7 Vm (org.ovirt.engine.api.model.Vm)6 StorageDomains (org.ovirt.engine.api.model.StorageDomains)4 V3Disk (org.ovirt.engine.api.v3.types.V3Disk)4 DiskAttachments (org.ovirt.engine.api.model.DiskAttachments)3 V3Disks (org.ovirt.engine.api.v3.types.V3Disks)3 UriInfo (javax.ws.rs.core.UriInfo)2 HostStorage (org.ovirt.engine.api.model.HostStorage)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 V3KatelloErrata (org.ovirt.engine.api.v3.types.V3KatelloErrata)2