Amit Aviram has uploaded a new change for review.

Change subject: restapi: Enabling disk information editing when adding a new 
template.
......................................................................

restapi: Enabling disk information editing when adding a new template.

Currently when adding a new template, its disks edit is enabled only when
the disk's storage domain is specified- In this case, editing any other field
is ignored by the REST, which is an unexpected behavior to the user,
and also makes the new copied destination disk to lose data.

This patch makes the REST request for a new template to consider every
given value related to the new template's disks whether the storage domain is
specified and whether it is not. The specified attributes given in the REST
request will be patched on the original disk using a mapper.

Change-Id: Ib0baf4e5bd7233fbc4eab2f1f671b8b15e08ba03
Bug-Url: https://bugzilla.redhat.com/1105887
Signed-off-by: Amit Aviram <aavi...@redhat.com>
---
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/Disk.java
M 
backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendTemplatesResource.java
2 files changed, 27 insertions(+), 9 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/08/37808/1

diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/Disk.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/Disk.java
index a8d9455..7c5cbf0 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/Disk.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/Disk.java
@@ -140,6 +140,10 @@
         this.ovfStore = ovfStore;
     }
 
+    public boolean isDiskImage() {
+        return getDiskStorageType() == DiskStorageType.IMAGE;
+    }
+
     /**
      * Enum of the disk's type, which defines which underlying storage details 
will be contained in the {@link Disk}
      * object instance.
diff --git 
a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendTemplatesResource.java
 
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendTemplatesResource.java
index 04ea243..b8380e5 100644
--- 
a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendTemplatesResource.java
+++ 
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendTemplatesResource.java
@@ -17,6 +17,7 @@
 import org.ovirt.engine.api.model.VirtIOSCSI;
 import org.ovirt.engine.api.resource.TemplateResource;
 import org.ovirt.engine.api.resource.TemplatesResource;
+import org.ovirt.engine.api.restapi.types.DiskMapper;
 import org.ovirt.engine.api.restapi.types.RngDeviceMapper;
 import org.ovirt.engine.api.restapi.types.VmMapper;
 import org.ovirt.engine.api.restapi.util.DisplayHelper;
@@ -92,6 +93,7 @@
         AddVmTemplateParameters params = new AddVmTemplateParameters(staticVm,
                                        template.getName(),
                                        template.getDescription());
+
         if (template.getVersion() != null) {
             
params.setBaseTemplateId(Guid.createGuidFromString(template.getVersion().getBaseTemplate().getId()));
             
params.setTemplateVersionName(template.getVersion().getVersionName());
@@ -145,21 +147,33 @@
         if (vm.isSetDisks() && vm.getDisks().isSetDisks()) {
             diskToDestinationMap = new HashMap<Guid, DiskImage>();
             for (Disk disk : vm.getDisks().getDisks()) {
-                if (disk.isSetId() && disk.isSetStorageDomains() && 
disk.getStorageDomains().isSetStorageDomains()
-                        && 
disk.getStorageDomains().getStorageDomains().get(0).isSetId()) {
-                    DiskImage diskImage = new DiskImage();
-                    diskImage.setId(asGuid(disk.getId()));
-                    diskImage.setStorageIds(new ArrayList<Guid>());
-                    Guid newStorageDomainId = isDomainSet ? storageDomainId : 
asGuid(disk.getStorageDomains()
-                            .getStorageDomains().get(0).getId());
-                    diskImage.getStorageIds().add(newStorageDomainId);
-                    diskToDestinationMap.put(diskImage.getId(), diskImage);
+                if (disk.isSetId()) {
+                    org.ovirt.engine.core.common.businessentities.Disk 
sourceDisk = queryDisk(disk);
+
+                    // VM template can only have disk images
+                    if (sourceDisk.isDiskImage()) {
+                        DiskImage destinationDisk = (DiskImage) 
DiskMapper.map(disk, sourceDisk);
+
+                        if (disk.isSetStorageDomains() && 
disk.getStorageDomains().isSetStorageDomains()
+                                && 
disk.getStorageDomains().getStorageDomains().get(0).isSetId()) {
+                            destinationDisk.setStorageIds(new 
ArrayList<Guid>());
+                            Guid newStorageDomainId = isDomainSet ? 
storageDomainId : asGuid(disk.getStorageDomains().
+                                    getStorageDomains().get(0).getId());
+                            
destinationDisk.getStorageIds().add(newStorageDomainId);
+                        }
+                        diskToDestinationMap.put(destinationDisk.getId(), 
destinationDisk);
+                    }
                 }
             }
         }
         return diskToDestinationMap;
     }
 
+    private org.ovirt.engine.core.common.businessentities.Disk queryDisk(Disk 
disk) {
+        VdcQueryReturnValue queryReturnValue = 
runQuery(VdcQueryType.GetDiskByDiskId, new IdQueryParameters(new 
Guid(disk.getId())));
+        return queryReturnValue.getReturnValue();
+    }
+
     @Override
     public Response performRemove(String id) {
         return performAction(VdcActionType.RemoveVmTemplate, new 
VmTemplateParametersBase(asGuid(id)));


-- 
To view, visit http://gerrit.ovirt.org/37808
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib0baf4e5bd7233fbc4eab2f1f671b8b15e08ba03
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Amit Aviram <aavi...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to