@Override
  public Response add(Disk disk) {
    validateEnums(Disk.class, disk);

    if (disk.isSetId()) {
      return Response.fromResponse(attachDiskToVm(disk))
          .entity(map(lookupEntity(asGuid(disk.getId()))))
          .build();
    } else {
      validateDiskForCreation(disk);
      return performCreate(
          addAction, getAddParameters(map(disk), disk), getEntityIdResolver(disk.getName()));
    }
  }
Ejemplo n.º 2
0
 @Override
 protected void verify(Disk model, Disk transform) {
   assertNotNull(transform);
   assertEquals(model.getId(), transform.getId());
   assertEquals(model.getImageId(), transform.getImageId());
   assertEquals(model.getFormat(), transform.getFormat());
   assertEquals(model.getInterface(), transform.getInterface());
   assertEquals(model.isActive(), transform.isActive());
   assertEquals(model.isReadOnly(), transform.isReadOnly());
   assertEquals(model.getDescription(), transform.getDescription());
   assertEquals(model.getLogicalName(), transform.getLogicalName());
   assertNotNull(model.getSnapshot());
   assertEquals(model.getSnapshot().getId(), transform.getSnapshot().getId());
   assertEquals(
       "unexpected status", model.getStatus().getState(), transform.getStatus().getState());
   assertEquals("unexpected sparse", model.isSparse(), transform.isSparse());
   assertEquals("unexpected bootable", model.isBootable(), transform.isBootable());
   assertEquals(
       "unexpected propagate errors", model.isPropagateErrors(), transform.isPropagateErrors());
   assertEquals(
       "unexpected wipe after delete", model.isWipeAfterDelete(), transform.isWipeAfterDelete());
   assertEquals("unexpected shareable", model.isShareable(), transform.isShareable());
 }
 Disk addStatistics(
     Disk model,
     org.ovirt.engine.core.common.businessentities.Disk entity,
     UriInfo ui,
     HttpHeaders httpHeaders) {
   if (DetailHelper.include(httpHeaders, "statistics")) {
     model.setStatistics(new Statistics());
     DiskStatisticalQuery query = new DiskStatisticalQuery(newModel(model.getId()));
     List<Statistic> statistics = query.getStatistics(entity);
     for (Statistic statistic : statistics) {
       LinkHelper.addLinks(ui, statistic, query.getParentType());
     }
     model.getStatistics().getStatistics().addAll(statistics);
   }
   return model;
 }
  private Response attachDiskToVm(Disk disk) {
    boolean isDiskActive = BooleanUtils.toBooleanDefaultIfNull(disk.isActive(), false);
    boolean isDiskReadOnly = BooleanUtils.toBooleanDefaultIfNull(disk.isReadOnly(), false);
    AttachDetachVmDiskParameters params =
        new AttachDetachVmDiskParameters(
            parentId,
            Guid.createGuidFromStringDefaultEmpty(disk.getId()),
            isDiskActive,
            isDiskReadOnly);

    if (disk.isSetSnapshot()) {
      validateParameters(disk, "snapshot.id");
      params.setSnapshotId(asGuid(disk.getSnapshot().getId()));
    }

    return performAction(VdcActionType.AttachDiskToVm, params);
  }