Shahar Havivi has uploaded a new change for review.

Change subject: restapi: add use_sysprep and use_cloud_init for Vm creation
......................................................................

restapi: add use_sysprep and use_cloud_init for Vm creation

By default we attach sysprep for new Windows VM - added new tags for the
user to determine the behaviour, for backward compatibility the default
is to attach sysprep for new Windows VMs.

Bug-Url: https://bugzilla.redhat.com/1190663
Signed-off-by: Shahar Havivi <shah...@redhat.com>
Change-Id: Ie712895fa3414e33f0bbd158d79505bbbb5d877b
---
M 
backend/manager/modules/restapi/interface/definition/src/main/resources/api.xsd
M 
backend/manager/modules/restapi/interface/definition/src/main/resources/rsdl_metadata.yaml
M 
backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVmResource.java
M 
backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVmsResource.java
4 files changed, 27 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/88/40988/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 16cf751..a9ee535 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
@@ -3288,6 +3288,8 @@
           <xs:element name="custom_properties" type="CustomProperties" 
minOccurs="0" maxOccurs="1"/>
           <xs:element name="custom_emulated_machine" type="xs:string" 
minOccurs="0" maxOccurs="1"/>
           <xs:element name="custom_cpu_model" type="xs:string" minOccurs="0" 
maxOccurs="1"/>
+          <xs:element name="use_sysprep" type="xs:boolean" minOccurs="0" 
maxOccurs="1"/>
+          <xs:element name="use_cloud_init" 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.yaml
 
b/backend/manager/modules/restapi/interface/definition/src/main/resources/rsdl_metadata.yaml
index 5e1662b..8ac221a 100644
--- 
a/backend/manager/modules/restapi/interface/definition/src/main/resources/rsdl_metadata.yaml
+++ 
b/backend/manager/modules/restapi/interface/definition/src/main/resources/rsdl_metadata.yaml
@@ -99,6 +99,8 @@
           vm.cpu_profile.id: xs:string
           vm.migration.auto_converge: xs:string
           vm.migration.compressed: xs:string
+          vm.use_sysprep: xs:boolean
+          vm.use_cloud_init: xs:boolean
         description: update the virtual machine in the system for the given 
virtual machine id with the values specified in the request
 - name: /vms/{vm:id}/applications|rel=get
   description: get all the applications installed on the vm identified by the 
given id
@@ -182,6 +184,8 @@
           vm.cpu_profile.id: xs:string
           vm.migration.auto_converge: xs:string
           vm.migration.compressed: xs:string
+          vm.use_sysprep: xs:boolean
+          vm.use_cloud_init: xs:boolean
         description: add a virtual machine to the system from scratch
       # the following signature is for clone VM from a Snapshot - requires the 
Snapshot ID
       - mandatoryArguments: {vm.name: 'xs:string', vm.template.id|name: 
'xs:string', vm.cluster.id|name: 'xs:string',
@@ -376,6 +380,8 @@
             payload_file.name: xs:string
             payload_file.content: xs:string
             payload_file.type: xs:string
+          action.vm.use_sysprep: xs:boolean
+          action.vm.use_cloud_init: xs:boolean
         description: start a virtual machine in the system identified by the 
given id with the options specified in the request body
     headers:
       Filter: {value: true|false, required: false}
diff --git 
a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVmResource.java
 
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVmResource.java
index 0f53f82..e4ccce2 100644
--- 
a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVmResource.java
+++ 
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVmResource.java
@@ -5,9 +5,11 @@
 
 import java.util.List;
 import java.util.Set;
+
 import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriInfo;
+
 import org.ovirt.engine.api.common.util.DetailHelper;
 import org.ovirt.engine.api.common.util.QueryHelper;
 import org.ovirt.engine.api.model.Action;
@@ -375,9 +377,12 @@
                 }
             }
             params.setInitializationType(InitializationType.CloudInit);
-            ((RunVmOnceParams) params).setVmInit(
+            params.setVmInit(
                     getMapper(CloudInit.class, VmInit.class)
                     .map(cloudInit, null));
+        } else if (!Boolean.FALSE.equals(vm.isUseSysprep()) || 
!Boolean.FALSE.equals(vm.isUseCloudInit())) {
+            // We are setting default initialization for backward compatibility
+            params.setVmInit(new VmInit());
         }
 
         return params;
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 c86cd1b..6dde7a0 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
@@ -6,8 +6,10 @@
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+
 import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.Response;
+
 import org.apache.commons.lang.ObjectUtils;
 import org.ovirt.engine.api.common.util.DetailHelper;
 import org.ovirt.engine.api.model.Action;
@@ -460,6 +462,7 @@
         params.setStorageDomainId(storageDomainId);
         params.setDiskInfoDestinationMap(getDisksToClone(vm.getDisks(), 
template.getId()));
         params.setMakeCreatorExplicitOwner(shouldMakeCreatorExplicitOwner());
+        setDefaultInitialization(staticVm, vm);
         setupCloneTemplatePermissions(vm, params);
         addDevicesToParams(params, vm, template, instanceType, 
staticVm.getOsId(), cluster);
         DisplayHelper.setGraphicsToParams(vm.getDisplay(), params);
@@ -481,12 +484,22 @@
         params.setMakeCreatorExplicitOwner(shouldMakeCreatorExplicitOwner());
         addDevicesToParams(params, vm, null, instanceType, staticVm.getOsId(), 
cluster);
         DisplayHelper.setGraphicsToParams(vm.getDisplay(), params);
+        setDefaultInitialization(staticVm, vm);
 
         return performCreate(VdcActionType.AddVmFromScratch,
                                params,
                                new 
QueryIdResolver<Guid>(VdcQueryType.GetVmByVmId, IdQueryParameters.class));
     }
 
+    private void setDefaultInitialization(VmStatic staticVm, VM vm) {
+        if (!Boolean.FALSE.equals(vm.isUseSysprep()) && 
!Boolean.FALSE.equals(vm.isUseCloudInit())) {
+            // We are setting default initialization for backward compatibility
+            if (staticVm.getVmInit() == null) {
+                staticVm.setVmInit(new VmInit());
+            }
+        }
+    }
+
     public ArrayList<DiskImage> mapDisks(Disks disks) {
         ArrayList<DiskImage> diskImages = null;
         if (disks!=null && disks.isSetDisks()) {


-- 
To view, visit https://gerrit.ovirt.org/40988
To unsubscribe, visit https://gerrit.ovirt.org/settings

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

Reply via email to