static Disk getModel() { Disk model = new Disk(); model.setFormat(DiskFormat.COW); model.setSparse(true); model.setShareable(false); model.setPropagateErrors(true); model.setStorageDomains(new StorageDomains()); model.getStorageDomains().getStorageDomains().add(new StorageDomain()); model.getStorageDomains().getStorageDomains().get(0).setId(GUIDS[2].toString()); model.setProvisionedSize(1000000000L); return model; }
@Override public V3Disk adapt(Disk from) { V3Disk to = new V3Disk(); 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.isSetDiskProfile()) { to.setDiskProfile(adaptOut(from.getDiskProfile())); if (from.isSetFormat()) { to.setFormat(from.getFormat().value()); if (from.isSetId()) { to.setId(from.getId());
@Mapping(from = org.ovirt.engine.core.common.businessentities.storage.Disk.class, to = Disk.class) public static Disk map(org.ovirt.engine.core.common.businessentities.storage.Disk entity, Disk template) { Disk model = template != null ? template : new Disk(); // name is depreciated, use alias instead. model.setName(entity.getDiskAlias()); model.setAlias(entity.getDiskAlias()); if (entity.getId() != null) { model.setId(entity.getId().toString()); } model.setPropagateErrors(PropagateErrors.On == entity.getPropagateErrors()); model.setWipeAfterDelete(entity.isWipeAfterDelete()); model.setShareable(entity.isShareable()); model.setDescription(entity.getDiskDescription()); model.setLogicalName(entity.getLogicalName()); model.setStorageType(map(entity.getDiskStorageType())); if (entity.getDiskStorageType() == org.ovirt.engine.core.common.businessentities.storage.DiskStorageType.IMAGE || entity.getDiskStorageType() == org.ovirt.engine.core.common.businessentities.storage.DiskStorageType.CINDER || entity.getDiskStorageType() == org.ovirt.engine.core.common.businessentities.storage.DiskStorageType.MANAGED_BLOCK_STORAGE) { mapDiskImageToDiskFields((DiskImage) entity, model); } else { model.setLunStorage(StorageLogicalUnitMapper.map(((LunDisk) entity).getLun(), new HostStorage())); if (entity.getSgio() != null) { model.setSgio(map(entity.getSgio(), null)); } } model.setContentType(mapDiskContentType(entity.getContentType())); return model; }
@Override protected Disk postPopulate(Disk model) { model.setFormat(DiskFormat.COW); model.setSgio(ScsiGenericIO.FILTERED); model.setStatus(DiskStatus.ILLEGAL); model.setLunStorage(null); return model; }
protected Disk getUpdate() { Disk update = new Disk(); update.setWipeAfterDelete(false); update.setReadOnly(true); return update; }
@Override public Disk adapt(V3Disk from) { Disk to = new Disk(); if (from.isSetLinks()) { to.getLinks().addAll(adaptIn(from.getLinks())); to.setActions(adaptIn(from.getActions())); to.setActive(from.isActive()); to.setActualSize(from.getActualSize()); to.setAlias(from.getAlias()); to.setComment(from.getComment()); to.setDescription(from.getDescription()); to.setDiskProfile(adaptIn(from.getDiskProfile())); to.setFormat(DiskFormat.fromValue(from.getFormat())); to.setId(from.getId()); to.setHref(from.getHref()); to.setImageId(from.getImageId()); to.setInstanceType(adaptIn(from.getInstanceType()));
private static void mapDiskToDiskImageProperties(Disk disk, DiskImage diskImage) { if (disk.isSetImageId()) { diskImage.setImageId(GuidUtils.asGuid(disk.getImageId())); if (disk.isSetProvisionedSize()) { diskImage.setSize(disk.getProvisionedSize()); if (disk.isSetFormat()) { diskImage.setVolumeFormat(map(disk.getFormat(), null)); if (disk.isSetQcowVersion()) { diskImage.setQcowCompat(mapQcowVersion(disk.getQcowVersion())); if (disk.isSetStatus()) { diskImage.setImageStatus(mapDiskStatus(disk.getStatus())); if (disk.isSetSnapshot() && disk.getSnapshot().isSetId()) { diskImage.setVmSnapshotId(GuidUtils.asGuid(disk.getSnapshot().getId())); if (disk.isSetSparse()) { diskImage.setVolumeType(disk.isSparse() ? VolumeType.Sparse : VolumeType.Preallocated); if (disk.isSetInitialSize()) { diskImage.setActualSizeInBytes(disk.getInitialSize()); if (disk.isSetStorageDomains() && disk.getStorageDomains().isSetStorageDomains() && disk.getStorageDomains().getStorageDomains().get(0).isSetId()) { StorageDomain storageDomain = disk.getStorageDomains().getStorageDomains().get(0); diskImage.setStorageIds(new ArrayList<>());
org.ovirt.engine.core.common.businessentities.storage.Disk engineDisk = template; if (engineDisk == null) { if (disk.isSetLunStorage()) { engineDisk = new LunDisk(); } else if (disk.getStorageType() != null) { DiskStorageType diskStorageType = disk.getStorageType(); switch (diskStorageType) { case CINDER: if (disk.isSetName()) { engineDisk.setDiskAlias(disk.getName()); if (disk.isSetAlias()) { engineDisk.setDiskAlias(disk.getAlias()); if (disk.isSetId()) { engineDisk.setId(GuidUtils.asGuid(disk.getId())); if (disk.isSetPropagateErrors()) { engineDisk.setPropagateErrors(disk.isPropagateErrors() ? PropagateErrors.On : PropagateErrors.Off); if (disk.isSetWipeAfterDelete()) { engineDisk.setWipeAfterDelete(disk.isWipeAfterDelete()); if (disk.isSetLogicalName()) { engineDisk.setLogicalName(disk.getLogicalName()); if (disk.isSetDescription()) {
private static void mapDiskImageToDiskFields(DiskImage entity, Disk model) { if (entity.getImageId() != null) { model.setImageId(entity.getImageId().toString()); model.setProvisionedSize(entity.getSize()); if (entity.hasActualSize()) { model.setActualSize(entity.getActualSizeInBytes()); if (entity.isAllowSnapshot()){ model.setTotalSize((long) entity.getActualDiskWithSnapshotsSizeInBytes()); model.setSnapshot(new Snapshot()); model.getSnapshot().setId(entity.getSnapshotId().toString()); model.setFormat(map(entity.getVolumeFormat(), null)); model.setQcowVersion(mapQcowCompat(entity.getQcowCompat())); model.setStatus(mapDiskStatus(entity.getImageStatus())); model.setSparse(VolumeType.Sparse == entity.getVolumeType()); if (entity.getStorageIds() != null && entity.getStorageIds().size() > 0) { if (!model.isSetStorageDomains()) { model.setStorageDomains(new StorageDomains()); model.getStorageDomains().getStorageDomains().add(storageDomain); model.setQuota(quota); model.setDiskProfile(diskProfile);
@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.getDescription(), transform.getDescription()); assertEquals(model.getLogicalName(), transform.getLogicalName()); assertEquals(model.getOpenstackVolumeType().getName(), transform.getOpenstackVolumeType().getName()); assertNotNull(model.getSnapshot()); assertEquals(model.getSnapshot().getId(), transform.getSnapshot().getId()); assertEquals(model.getStatus(), transform.getStatus(), "unexpected status"); assertEquals(model.isSparse(), transform.isSparse(), "unexpected sparse"); assertEquals(model.isPropagateErrors(), transform.isPropagateErrors(), "unexpected propagate errors"); assertEquals(model.isWipeAfterDelete(), transform.isWipeAfterDelete(), "unexpected wipe after delete"); assertEquals(model.isShareable(), transform.isShareable(), "unexpected shareable"); }
static void verifyModelSpecific(Disk model, int index) { assertEquals(GUIDS[index].toString(), model.getId()); assertFalse(model.isSetVm()); assertTrue(model.isSparse()); assertTrue(model.isPropagateErrors()); }
private void verifyModelSpecific(Disk model, int index) { assertEquals(GUIDS[index].toString(), model.getId()); assertTrue(model.isSparse()); assertTrue(model.isPropagateErrors()); }
protected Map<Guid, Guid> getDiskToDestinationMap(Action action) { Map<Guid, Guid> diskToDestinationMap = new HashMap<>(); if (action.isSetVm() && action.getVm().isSetDiskAttachments() && action.getVm().getDiskAttachments().isSetDiskAttachments()) { for (DiskAttachment diskAttachment : action.getVm().getDiskAttachments().getDiskAttachments()) { Disk disk = diskAttachment.getDisk(); if (disk != null && disk.isSetId() && disk.isSetStorageDomains() && disk.getStorageDomains().isSetStorageDomains() && disk.getStorageDomains().getStorageDomains().get(0).isSetId()) { diskToDestinationMap.put(Guid.createGuidFromStringDefaultEmpty(disk.getId()), Guid.createGuidFromStringDefaultEmpty(disk.getStorageDomains().getStorageDomains().get(0).getId())); } } } return diskToDestinationMap; } }
private void setVolumesTypeFormat(Action action) { if (action.isSetVm()) { Vm modelVm = action.getVm(); if (!modelVm.isSetDiskAttachments()) { return; } Map<Guid, org.ovirt.engine.core.common.businessentities.storage.Disk> entityDisks = getDiskMap(); for (DiskAttachment modelDiskAttachment : modelVm.getDiskAttachments().getDiskAttachments()) { Disk modelDisk = modelDiskAttachment.getDisk(); if (modelDisk != null) { validateParameters(modelDisk, "id"); Guid modelDiskId = Guid.createGuidFromString(modelDisk.getId()); DiskImage entityDisk = (DiskImage) entityDisks.get(modelDiskId); if (entityDisk == null) { continue; } if (modelDisk.isSetFormat()) { VolumeFormat entityDiskFormat = DiskMapper.map(modelDisk.getFormat(), null); entityDisk.setVolumeFormat(entityDiskFormat); } if (modelDisk.isSetSparse()) { entityDisk.setVolumeType(modelDisk.isSparse() ? VolumeType.Sparse : VolumeType.Preallocated); } } } } }
@Override protected void verify(Disk model, Disk transform) { assertNotNull(transform); assertEquals(model.getId(), transform.getId()); assertEquals(model.isPropagateErrors(), transform.isPropagateErrors(), "unexpected propagate errors"); assertEquals(model.isWipeAfterDelete(), transform.isWipeAfterDelete(), "unexpected wipe after delete"); assertEquals(model.isShareable(), transform.isShareable(), "unexpected shareable"); }
@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()); } }
throw new ValidationException("Parameter 'disk' is mandatory but was not provided."); if (disk.getFormat()==null) { throw new ValidationException("Parameter 'disk.format' is mandatory but was not provided."); if (disk.getInterface()==null) { throw new ValidationException("Parameter 'disk.interface' is mandatory but was not provided."); && disk.getLunStorage()!=null && disk.getLunStorage().getLogicalUnits()!=null && disk.getLunStorage().getLogicalUnits().getLogicalUnits()!=null && disk.getLunStorage().getLogicalUnits().getLogicalUnits().size() > 0 && disk.getLunStorage().getLogicalUnits().getLogicalUnits().get(0).getTarget()!=null && disk.getLunStorage()!=null && disk.getLunStorage().getLogicalUnits()!=null && disk.getLunStorage().getLogicalUnits().getLogicalUnits()!=null && disk.getLunStorage().getLogicalUnits().getLogicalUnits().size() > 0 && disk.getLunStorage().getLogicalUnits().getLogicalUnits().get(0).getPort()!=null && disk.getLunStorage()!=null && disk.getLunStorage().getLogicalUnits()!=null && disk.getLunStorage().getLogicalUnits().getLogicalUnits()!=null && disk.getLunStorage().getLogicalUnits().getLogicalUnits().size() > 0 && disk.getLunStorage().getLogicalUnits().getLogicalUnits().get(0).getId()!=null && disk.getLunStorage()!=null && disk.getLunStorage().getLogicalUnits()!=null && disk.getLunStorage().getLogicalUnits().getLogicalUnits()!=null && disk.getLunStorage().getLogicalUnits().getLogicalUnits().size() > 0 && disk.getLunStorage().getLogicalUnits().getLogicalUnits().get(0).getAddress()!=null && disk.getLunStorage()!=null && disk.getLunStorage().getType()!=null ) { return DisksResource.class.getMethod("addLun", Disk.class); && disk.getProvisionedSize()!=null ) { return DisksResource.class.getMethod("addOnStorageDomain", Disk.class);
@Override public Disk get() { for (Disk disk : collection.list().getDisks()) { if (disk.getId().equals(diskId)) { return disk; } } throw new WebApplicationException(Response.status(Response.Status.NOT_FOUND).build()); }