Tal Nisan has uploaded a new change for review.

Change subject: restapi: Added detach only options on VM remove
......................................................................

restapi: Added detach only options on VM remove

Change-Id: Id5ba4a2cec3184340bc302558cad3a0bfea0c7ac
Signed-off-by: Tal Nisan <[email protected]>
---
M 
backend/manager/modules/restapi/interface/definition/src/main/resources/api.xsd
M 
backend/manager/modules/restapi/interface/definition/src/main/resources/rsdl_metadata_v-3.1.yaml
M 
backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVmsResource.java
M 
backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendVmsResourceTest.java
4 files changed, 28 insertions(+), 7 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/82/10682/1

diff --git 
a/backend/manager/modules/restapi/interface/definition/src/main/resources/api.xsd
 
b/backend/manager/modules/restapi/interface/definition/src/main/resources/api.xsd
index 75f0e48..ec89206 100644
--- 
a/backend/manager/modules/restapi/interface/definition/src/main/resources/api.xsd
+++ 
b/backend/manager/modules/restapi/interface/definition/src/main/resources/api.xsd
@@ -2389,6 +2389,7 @@
             </xs:annotation>
           </xs:element>
           <xs:element name="clone" type="xs:boolean" minOccurs="0" 
maxOccurs="1"/>
+          <xs:element name="detach_only" type="xs:boolean" minOccurs="0" 
maxOccurs="1"/>
         </xs:sequence>
       </xs:extension>
     </xs:complexContent>
diff --git 
a/backend/manager/modules/restapi/interface/definition/src/main/resources/rsdl_metadata_v-3.1.yaml
 
b/backend/manager/modules/restapi/interface/definition/src/main/resources/rsdl_metadata_v-3.1.yaml
index 8ba7b3a..7a6c50f 100644
--- 
a/backend/manager/modules/restapi/interface/definition/src/main/resources/rsdl_metadata_v-3.1.yaml
+++ 
b/backend/manager/modules/restapi/interface/definition/src/main/resources/rsdl_metadata_v-3.1.yaml
@@ -29,7 +29,7 @@
       parameterType: Action
       signatures:
       - mandatoryArguments: {}
-        optionalArguments: {action.force: 'xs:boolean'}
+        optionalArguments: {action.force: 'xs:boolean', 
action.vm.disks.detach_only: 'xs:boolean'}
     urlparams:
       async: {context: matrix, type: 'xs:boolean', value: true|false, 
required: false}
     headers:
diff --git 
a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVmsResource.java
 
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVmsResource.java
index 648ec69..9222ce1 100644
--- 
a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVmsResource.java
+++ 
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVmsResource.java
@@ -356,12 +356,13 @@
     @Override
     public Response remove(String id, Action action) {
         getEntity(id);
-        return performAction(VdcActionType.RemoveVm,
-                             new RemoveVmParameters(asGuid(id),
-                                                    action != null && 
action.isSetForce() ? action.isForce()
-                                                                               
      :
-                                                                               
      false));
-
+        boolean forceRemove = action != null && action.isSetForce() ? 
action.isForce() : false;
+        RemoveVmParameters params = new RemoveVmParameters(asGuid(id), 
forceRemove);
+        // If detach only is set we do not remove the VM disks
+        if (action.isSetVm() && action.getVm().isSetDisks() && 
action.getVm().getDisks().isSetDetachOnly()) {
+            params.setRemoveDisks(false);
+        }
+        return performAction(VdcActionType.RemoveVm, params);
     }
 
     protected VMs 
mapCollection(List<org.ovirt.engine.core.common.businessentities.VM> entities, 
boolean isFiltered) {
diff --git 
a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendVmsResourceTest.java
 
b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendVmsResourceTest.java
index f417039..2696e15 100644
--- 
a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendVmsResourceTest.java
+++ 
b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendVmsResourceTest.java
@@ -116,6 +116,22 @@
     }
 
     @Test
+    public void testRemoveDetachOnly() throws Exception {
+        setUriInfo(setUpBasicUriExpectations());
+        setUpGetEntityExpectations();
+        setUpGetPayloadExpectations(0);
+        setUpGetBallooningExpectations();
+        setUpActionExpectations(VdcActionType.RemoveVm, 
RemoveVmParameters.class, new String[] {
+                "VmId", "RemoveDisks" }, new Object[] { GUIDS[0], 
Boolean.FALSE }, true, true);
+
+        Action action = new Action();
+        action.setVm(new VM());
+        action.getVm().setDisks(new Disks());
+        action.getVm().getDisks().setDetachOnly(true);
+        verifyRemove(collection.remove(GUIDS[0].toString(), action));
+    }
+
+    @Test
     public void testRemoveForcedIncomplete() throws Exception {
         setUriInfo(setUpBasicUriExpectations());
         setUpGetEntityExpectations();
@@ -834,10 +850,12 @@
         return model;
     }
 
+    @Override
     protected List<VM> getCollection() {
         return collection.list().getVMs();
     }
 
+    @Override
     protected void verifyModel(VM model, int index) {
         super.verifyModel(model, index);
         verifyModelSpecific(model, index);
@@ -880,6 +898,7 @@
         model.setStorageDomain(storageDomain);
     }
 
+    @Override
     protected org.ovirt.engine.core.common.businessentities.VM getEntity(int 
index) {
         return setUpEntityExpectations(
                 
control.createMock(org.ovirt.engine.core.common.businessentities.VM.class),


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id5ba4a2cec3184340bc302558cad3a0bfea0c7ac
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Tal Nisan <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to