Search in sources :

Example 1 with DiskAttachments

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

the class V3VmDisksServer method list.

@GET
public V3Disks list() {
    SystemResource systemResource = BackendApiResource.getInstance();
    // In version 4 of the API the collection of disks of a virtual machine has been replaced by the collection of
    // disk attachments, so we need to fetch the disk attachments:
    VmsResource vmsResource = systemResource.getVmsResource();
    VmResource vmResource = vmsResource.getVmResource(vmId);
    DiskAttachmentsResource attachmentsResource = vmResource.getDiskAttachmentsResource();
    DiskAttachments attachments = attachmentsResource.list();
    // For each disk, we need now to fetch it from the top level disks collection, and add the information from
    // the corresponding attachment:
    DisksResource disksResource = systemResource.getDisksResource();
    V3Disks disks = new V3Disks();
    for (DiskAttachment attachment : attachments.getDiskAttachments()) {
        DiskResource diskResource = disksResource.getDiskResource(attachment.getDisk().getId());
        Disk v4Disk = diskResource.get();
        V3Disk v3Disk = adaptOut(v4Disk);
        V3VmHelper.addDiskAttachmentDetails(attachment, v3Disk);
        V3VmHelper.fixDiskLinks(vmId, v3Disk);
        disks.getDisks().add(v3Disk);
    }
    return disks;
}
Also used : VmResource(org.ovirt.engine.api.resource.VmResource) DiskResource(org.ovirt.engine.api.resource.DiskResource) DiskAttachmentsResource(org.ovirt.engine.api.resource.DiskAttachmentsResource) DiskAttachment(org.ovirt.engine.api.model.DiskAttachment) V3Disk(org.ovirt.engine.api.v3.types.V3Disk) VmsResource(org.ovirt.engine.api.resource.VmsResource) V3Disks(org.ovirt.engine.api.v3.types.V3Disks) VmDisksResource(org.ovirt.engine.api.resource.VmDisksResource) DisksResource(org.ovirt.engine.api.resource.DisksResource) SystemResource(org.ovirt.engine.api.resource.SystemResource) DiskAttachments(org.ovirt.engine.api.model.DiskAttachments) Disk(org.ovirt.engine.api.model.Disk) V3Disk(org.ovirt.engine.api.v3.types.V3Disk) GET(javax.ws.rs.GET)

Example 2 with DiskAttachments

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

the class BackendExportDomainDiskAttachmentsResource method list.

// TODO: Currently we don't add links as the they are wrongly pointing to /vms/{vm_id}/diskattachemnts
// instead of /storagedomains/{storage_id}/vms/{vm_id}/diskattachments
// this needs to be added once the problem is solved
@Override
public DiskAttachments list() {
    DiskAttachments attachments = new DiskAttachments();
    attachments.getDiskAttachments().addAll(parent.getDiskMap().values().stream().map(d -> map(d.getDiskVmElementForVm(parent.vm.getId()))).collect(Collectors.toList()));
    return attachments;
}
Also used : DiskAttachments(org.ovirt.engine.api.model.DiskAttachments)

Example 3 with DiskAttachments

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

the class V3VMInAdapter method adapt.

@Override
public Vm adapt(V3VM from) {
    Vm to = new Vm();
    if (from.isSetLinks()) {
        to.getLinks().addAll(adaptIn(from.getLinks()));
    }
    if (from.isSetActions()) {
        to.setActions(adaptIn(from.getActions()));
    }
    if (from.isSetBios()) {
        to.setBios(adaptIn(from.getBios()));
    }
    if (from.isSetCdroms()) {
        to.setCdroms(adaptIn(from.getCdroms()));
    }
    if (from.isSetCluster()) {
        to.setCluster(adaptIn(from.getCluster()));
    }
    if (from.isSetComment()) {
        to.setComment(from.getComment());
    }
    if (from.isSetConsole()) {
        to.setConsole(adaptIn(from.getConsole()));
    }
    if (from.isSetCpu()) {
        to.setCpu(adaptIn(from.getCpu()));
    }
    if (from.isSetCpuProfile()) {
        to.setCpuProfile(adaptIn(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(adaptIn(from.getCustomProperties()));
    }
    if (from.isSetDeleteProtected()) {
        to.setDeleteProtected(from.isDeleteProtected());
    }
    if (from.isSetDescription()) {
        to.setDescription(from.getDescription());
    }
    if (from.isSetDisks()) {
        DiskAttachments toAttachments = new DiskAttachments();
        for (V3Disk fromDisk : from.getDisks().getDisks()) {
            DiskAttachment toAttachment = new DiskAttachment();
            toAttachment.setDisk(adaptIn(fromDisk));
            toAttachments.getDiskAttachments().add(toAttachment);
        }
        to.setDiskAttachments(toAttachments);
    }
    if (from.isSetDisplay()) {
        to.setDisplay(adaptIn(from.getDisplay()));
    }
    if (from.isSetDomain()) {
        to.setDomain(adaptIn(from.getDomain()));
    }
    if (from.isSetExternalHostProvider()) {
        to.setExternalHostProvider(adaptIn(from.getExternalHostProvider()));
    }
    if (from.isSetFloppies()) {
        to.setFloppies(adaptIn(from.getFloppies()));
    }
    if (from.isSetGuestOperatingSystem()) {
        to.setGuestOperatingSystem(adaptIn(from.getGuestOperatingSystem()));
    }
    if (from.isSetGuestTimeZone()) {
        to.setGuestTimeZone(adaptIn(from.getGuestTimeZone()));
    }
    if (from.isSetHighAvailability()) {
        to.setHighAvailability(adaptIn(from.getHighAvailability()));
    }
    if (from.isSetHost()) {
        to.setHost(adaptIn(from.getHost()));
    }
    if (from.isSetId()) {
        to.setId(from.getId());
    }
    if (from.isSetHref()) {
        to.setHref(from.getHref());
    }
    if (from.isSetInitialization()) {
        to.setInitialization(adaptIn(from.getInitialization()));
    }
    if (from.isSetInstanceType()) {
        to.setInstanceType(adaptIn(from.getInstanceType()));
    }
    if (from.isSetIo()) {
        to.setIo(adaptIn(from.getIo()));
    }
    if (from.isSetKatelloErrata()) {
        to.setKatelloErrata(adaptIn(from.getKatelloErrata()));
    }
    if (from.isSetLargeIcon()) {
        to.setLargeIcon(adaptIn(from.getLargeIcon()));
    }
    if (from.isSetMemory()) {
        to.setMemory(from.getMemory());
    }
    if (from.isSetMemoryPolicy()) {
        to.setMemoryPolicy(adaptIn(from.getMemoryPolicy()));
    }
    if (from.isSetMigration()) {
        to.setMigration(adaptIn(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(adaptIn(from.getNics()));
    }
    if (from.isSetNumaTuneMode()) {
        to.setNumaTuneMode(NumaTuneMode.fromValue(from.getNumaTuneMode()));
    }
    if (from.isSetOrigin()) {
        to.setOrigin(from.getOrigin());
    }
    if (from.isSetOs()) {
        to.setOs(adaptIn(from.getOs()));
    }
    if (from.isSetPayloads()) {
        to.setPayloads(adaptIn(from.getPayloads()));
    }
    if (from.isSetPermissions()) {
        to.setPermissions(adaptIn(from.getPermissions()));
    }
    if (from.isSetPlacementPolicy()) {
        to.setPlacementPolicy(adaptIn(from.getPlacementPolicy()));
    }
    if (from.isSetQuota()) {
        to.setQuota(adaptIn(from.getQuota()));
    }
    if (from.isSetReportedDevices()) {
        to.setReportedDevices(adaptIn(from.getReportedDevices()));
    }
    if (from.isSetRngDevice()) {
        to.setRngDevice(adaptIn(from.getRngDevice()));
    }
    if (from.isSetRunOnce()) {
        to.setRunOnce(from.isRunOnce());
    }
    if (from.isSetSerialNumber()) {
        to.setSerialNumber(adaptIn(from.getSerialNumber()));
    }
    if (from.isSetSmallIcon()) {
        to.setSmallIcon(adaptIn(from.getSmallIcon()));
    }
    if (from.isSetSnapshots()) {
        to.setSnapshots(adaptIn(from.getSnapshots()));
    }
    if (from.isSetSoundcardEnabled()) {
        to.setSoundcardEnabled(from.isSoundcardEnabled());
    }
    if (from.isSetSso()) {
        to.setSso(adaptIn(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(adaptIn(from.getStatistics()));
    }
    V3Status status = from.getStatus();
    if (status != null) {
        if (status.isSetState()) {
            to.setStatus(VmStatus.fromValue(status.getState()));
        }
        if (status.isSetDetail()) {
            to.setStatusDetail(status.getDetail());
        }
    }
    if (from.isSetStopReason()) {
        to.setStopReason(from.getStopReason());
    }
    if (from.isSetStopTime()) {
        to.setStopTime(from.getStopTime());
    }
    if (from.isSetStorageDomain()) {
        to.setStorageDomain(adaptIn(from.getStorageDomain()));
    }
    if (from.isSetTags()) {
        to.setTags(adaptIn(from.getTags()));
    }
    if (from.isSetTemplate()) {
        to.setTemplate(adaptIn(from.getTemplate()));
    }
    if (from.isSetTimeZone()) {
        to.setTimeZone(adaptIn(from.getTimeZone()));
    }
    if (from.isSetTunnelMigration()) {
        to.setTunnelMigration(from.isTunnelMigration());
    }
    if (from.isSetType()) {
        to.setType(VmType.fromValue(from.getType()));
    }
    if (from.isSetUsb()) {
        to.setUsb(adaptIn(from.getUsb()));
    }
    if (from.isSetUseLatestTemplateVersion()) {
        to.setUseLatestTemplateVersion(from.isUseLatestTemplateVersion());
    }
    if (from.isSetVirtioScsi()) {
        to.setVirtioScsi(adaptIn(from.getVirtioScsi()));
    }
    if (from.isSetVmPool()) {
        to.setVmPool(adaptIn(from.getVmPool()));
    }
    if (from.isSetWatchdogs()) {
        to.setWatchdogs(adaptIn(from.getWatchdogs()));
    }
    // new structured "time_zone" element containing the name of the time zone and the UTC offset:
    if (from.isSetTimezone() && !to.isSetTimeZone()) {
        TimeZone timeZone = new TimeZone();
        timeZone.setName(from.getTimezone());
        to.setTimeZone(timeZone);
    }
    return to;
}
Also used : TimeZone(org.ovirt.engine.api.model.TimeZone) DiskAttachment(org.ovirt.engine.api.model.DiskAttachment) V3Disk(org.ovirt.engine.api.v3.types.V3Disk) Vm(org.ovirt.engine.api.model.Vm) DiskAttachments(org.ovirt.engine.api.model.DiskAttachments) V3Status(org.ovirt.engine.api.v3.types.V3Status)

Example 4 with DiskAttachments

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

the class BackendVmsResourceTest method createDiskAttachmentsCollection.

private DiskAttachments createDiskAttachmentsCollection() {
    DiskAttachments diskAttachments = new DiskAttachments();
    diskAttachments.getDiskAttachments().add(map(createDiskList().get(0), null));
    return diskAttachments;
}
Also used : DiskAttachments(org.ovirt.engine.api.model.DiskAttachments)

Example 5 with DiskAttachments

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

the class BackendVmsResourceTest method testClone.

@Test
public void testClone() throws Exception {
    setUriInfo(addMatrixParameterExpectations(setUpBasicUriExpectations(), BackendVmsResource.CLONE, "true"));
    setUpGetPayloadExpectations(1, 2);
    setUpGetBallooningExpectations(1, 2);
    setUpGetGraphicsExpectations(1);
    setUpGetConsoleExpectations(1, 2);
    setUpGetVmOvfExpectations(2);
    setUpGetVirtioScsiExpectations(2);
    setUpGetSoundcardExpectations(1, 2);
    setUpGetRngDeviceExpectations(1, 2);
    setUpGetCertuficateExpectations(1, 2);
    setUpEntityQueryExpectations(QueryType.GetVmTemplate, GetVmTemplateParameters.class, new String[] { "Id" }, new Object[] { GUIDS[1] }, getTemplateEntity(1));
    setUpEntityQueryExpectations(QueryType.GetClusterById, IdQueryParameters.class, new String[] { "Id" }, new Object[] { GUIDS[2] }, getClusterEntity());
    setUpCreationExpectations(ActionType.AddVmFromTemplate, AddVmParameters.class, new String[] { "StorageDomainId" }, new Object[] { GUIDS[0] }, true, true, GUIDS[2], QueryType.GetVmByVmId, IdQueryParameters.class, new String[] { "Id" }, new Object[] { GUIDS[2] }, getEntity(2));
    Response response = collection.add(createModel(new DiskAttachments()));
    assertEquals(201, response.getStatus());
    assertTrue(response.getEntity() instanceof Vm);
    verifyModel((Vm) response.getEntity(), 2);
}
Also used : Response(javax.ws.rs.core.Response) Vm(org.ovirt.engine.api.model.Vm) DiskAttachments(org.ovirt.engine.api.model.DiskAttachments) Test(org.junit.Test)

Aggregations

DiskAttachments (org.ovirt.engine.api.model.DiskAttachments)9 DiskAttachment (org.ovirt.engine.api.model.DiskAttachment)5 Disk (org.ovirt.engine.api.model.Disk)3 Vm (org.ovirt.engine.api.model.Vm)3 V3Disk (org.ovirt.engine.api.v3.types.V3Disk)3 Test (org.junit.Test)2 GET (javax.ws.rs.GET)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 Response (javax.ws.rs.core.Response)1 UriInfo (javax.ws.rs.core.UriInfo)1 Action (org.ovirt.engine.api.model.Action)1 Cdroms (org.ovirt.engine.api.model.Cdroms)1 CustomProperties (org.ovirt.engine.api.model.CustomProperties)1 Floppies (org.ovirt.engine.api.model.Floppies)1 KatelloErrata (org.ovirt.engine.api.model.KatelloErrata)1 Nics (org.ovirt.engine.api.model.Nics)1 Payloads (org.ovirt.engine.api.model.Payloads)1 Permissions (org.ovirt.engine.api.model.Permissions)1 ReportedDevices (org.ovirt.engine.api.model.ReportedDevices)1 Snapshot (org.ovirt.engine.api.model.Snapshot)1