Liron Ar has uploaded a new change for review.

Change subject: core, restapi: provide capabillity to get vm ovf config
......................................................................

core, restapi: provide capabillity to get vm ovf config

This patch adds the capabllity to get the current vm configuration (if
possible) through the ovirt rest-api.

The usage is done through a GET request to /api/vms or /api/vms/GUID/
with All-Content header with 'true' as the value.

If the VM OVF configuration couldn't be generated succesfully (if the vm
is currentky locked for example), the configuration won't be returned as
part of the result.

Change-Id: I5cbcd666519ffd138fd3efd4e130495529eaec0f
Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=1047965
Signed-off-by: Liron Aravot <[email protected]>
---
A 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetVmOvfByVmIdQuery.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/OvfHelper.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/VdcQueryType.java
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
M 
backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendVmResourceTest.java
M 
backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendVmsResourceTest.java
M 
backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/VmMapper.java
M 
backend/manager/modules/restapi/types/src/test/java/org/ovirt/engine/api/restapi/types/VmMapperTest.java
9 files changed, 171 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/87/24287/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetVmOvfByVmIdQuery.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetVmOvfByVmIdQuery.java
new file mode 100644
index 0000000..ed6725b
--- /dev/null
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetVmOvfByVmIdQuery.java
@@ -0,0 +1,29 @@
+package org.ovirt.engine.core.bll;
+
+import org.ovirt.engine.core.common.businessentities.VM;
+import org.ovirt.engine.core.common.queries.IdQueryParameters;
+
+public class GetVmOvfByVmIdQuery<P extends IdQueryParameters> extends 
QueriesCommandBase<P> {
+
+    public GetVmOvfByVmIdQuery(P parameters) {
+        super(parameters);
+    }
+
+    @Override
+    protected void executeQueryCommand() {
+        VM vm = getDbFacade().getVmDao().get(getParameters().getId());
+        if (vm == null) {
+            return;
+        }
+
+        OvfHelper ovfHelper = new OvfHelper();
+        String ovfData = ovfHelper.generateOvfConfigurationForVm(vm);
+
+        if (ovfData == null) {
+            return;
+        }
+
+        getQueryReturnValue().setReturnValue(ovfData);
+        getQueryReturnValue().setSucceeded(true);
+    }
+}
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/OvfHelper.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/OvfHelper.java
index e1c644f..0e96c62 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/OvfHelper.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/OvfHelper.java
@@ -4,10 +4,16 @@
 import java.util.List;
 import java.util.Map;
 
+import org.apache.commons.lang.StringUtils;
+import org.ovirt.engine.core.bll.utils.ClusterUtils;
+import org.ovirt.engine.core.bll.validator.DiskImagesValidator;
 import org.ovirt.engine.core.common.businessentities.DiskImage;
 import org.ovirt.engine.core.common.businessentities.VM;
+import org.ovirt.engine.core.common.businessentities.VMStatus;
+import org.ovirt.engine.core.common.businessentities.VmTemplate;
 import 
org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface;
 import org.ovirt.engine.core.compat.Guid;
+import org.ovirt.engine.core.dal.dbbroker.DbFacade;
 import org.ovirt.engine.core.utils.ovf.OvfManager;
 import org.ovirt.engine.core.utils.ovf.OvfReaderException;
 
@@ -50,6 +56,57 @@
         return vm;
     }
 
+    public String generateOvfConfigurationForVm(VM vm) {
+        if (VMStatus.ImageLocked != vm.getStatus()) {
+            VmHandler.updateDisksFromDb(vm);
+            DiskImagesValidator validator = new 
DiskImagesValidator(vm.getDiskList());
+            if (validator.diskImagesNotLocked().isValid()) {
+                loadVmData(vm);
+                Long currentDbGeneration = 
getDbFacade().getVmStaticDao().getDbGeneration(vm.getId());
+                // currentDbGeneration can be null in case that the vm was 
deleted during the run of OvfDataUpdater.
+                if (currentDbGeneration != null && 
vm.getStaticData().getDbGeneration() == currentDbGeneration) {
+                    return buildMetadataDictionaryForVm(vm);
+                }
+            }
+        }
+
+        return null;
+    }
+
+    /**
+     * Adds the given vm metadata to the given map
+     */
+    private String buildMetadataDictionaryForVm(VM vm) {
+        ArrayList<DiskImage> AllVmImages = new ArrayList<DiskImage>();
+        List<DiskImage> filteredDisks = 
ImagesHandler.filterImageDisks(vm.getDiskList(), false, true, true);
+
+        for (DiskImage diskImage : filteredDisks) {
+            List<DiskImage> images = 
ImagesHandler.getAllImageSnapshots(diskImage.getImageId(),
+                    diskImage.getImageTemplateId());
+            AllVmImages.addAll(images);
+        }
+
+        return ovfManager.ExportVm(vm, AllVmImages, 
ClusterUtils.getCompatibilityVersion(vm));
+    }
+
+    private void loadVmData(VM vm) {
+        if (vm.getInterfaces().isEmpty()) {
+            
vm.setInterfaces(getDbFacade().getVmNetworkInterfaceDao().getAllForVm(vm.getId()));
+        }
+        if (StringUtils.isEmpty(vm.getVmtName())) {
+            if (!Guid.Empty.equals(vm.getVmtGuid())) {
+                VmTemplate t = 
getDbFacade().getVmTemplateDao().get(vm.getVmtGuid());
+                vm.setVmtName(t.getName());
+            } else {
+                vm.setVmtName(VmTemplateHandler.BLANK_VM_TEMPLATE_NAME);
+            }
+        }
+    }
+
+    private DbFacade getDbFacade() {
+        return DbFacade.getInstance();
+    }
+
     public boolean isOvfTemplate(String ovfstring) {
         return ovfManager.IsOvfTemplate(ovfstring);
     }
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/VdcQueryType.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/VdcQueryType.java
index 90d154d..81c8fb9 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/VdcQueryType.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/VdcQueryType.java
@@ -13,6 +13,7 @@
     GetVmCustomProperties(VdcQueryAuthType.User),
     GetVmConfigurationBySnapshot(VdcQueryAuthType.User),
     GetVmFromConfiguration(VdcQueryAuthType.User),
+    GetVmOvfByVmId(VdcQueryAuthType.User),
     GetSnapshotBySnapshotId(VdcQueryAuthType.User),
     GetVmsByDiskGuid,
     GetVmPayload(VdcQueryAuthType.User),
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 a159936..a0e7bd7 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
@@ -362,6 +362,7 @@
     protected VM doPopulate(VM model, 
org.ovirt.engine.core.common.businessentities.VM entity) {
         parent.setConsoleDevice(model);
         parent.setVirtioScsiController(model);
+        parent.setVmOvfConfiguration(model);
         return model;
     }
 
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 bc0e26f..b50f9fa 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,6 +6,7 @@
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+
 import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.Response;
 
@@ -13,9 +14,9 @@
 import org.ovirt.engine.api.common.util.DetailHelper.Detail;
 import org.ovirt.engine.api.model.Action;
 import org.ovirt.engine.api.model.Certificate;
-import org.ovirt.engine.api.model.Console;
 import org.ovirt.engine.api.model.Configuration;
 import org.ovirt.engine.api.model.ConfigurationType;
+import org.ovirt.engine.api.model.Console;
 import org.ovirt.engine.api.model.Disk;
 import org.ovirt.engine.api.model.Disks;
 import org.ovirt.engine.api.model.Display;
@@ -529,6 +530,23 @@
         vm.getMemoryPolicy().setBallooning(balloonEnabled);
     }
 
+    protected VM setVmOvfConfiguration (VM vm) {
+        VdcQueryReturnValue queryReturnValue =
+                runQuery(VdcQueryType.GetVmOvfByVmId,
+                        new 
IdQueryParameters(Guid.createGuidFromString(vm.getId())));
+
+        if (queryReturnValue.getSucceeded() && 
queryReturnValue.getReturnValue() != null) {
+            String configuration = queryReturnValue.getReturnValue();
+            if (configuration != null) {
+                return VmMapper.map(configuration,
+                        ConfigurationType.OVF,
+                        vm);
+            }
+        }
+
+        return vm;
+    }
+
     protected void setConsoleDevice(VM model) {
         if (!model.isSetConsole()) {
             model.setConsole(new Console());
@@ -574,6 +592,7 @@
         setConsoleDevice(model);
         setVirtioScsiController(model);
         setCertificateInfo(model);
+        setVmOvfConfiguration(model);
         return model;
     }
 
diff --git 
a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendVmResourceTest.java
 
b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendVmResourceTest.java
index ebd6ffc..3e98f94 100644
--- 
a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendVmResourceTest.java
+++ 
b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendVmResourceTest.java
@@ -169,6 +169,7 @@
             
expect(httpHeaders.getRequestHeader(BackendResource.POPULATE)).andReturn(populates).anyTimes();
             setUpGetConsoleExpectations(new int[]{0});
             setUpGetVirtioScsiExpectations(new int[] {0});
+            setUpGetVmOvfExpectations(new int[] {0});
         }
         setUpGetEntityExpectations(1);
         setUpGetPayloadExpectations(0, 1);
@@ -210,6 +211,7 @@
         setUpGetBallooningExpectations();
         setUpGetBallooningExpectations();
         setUpGetConsoleExpectations(new int[] {0});
+        setUpGetVmOvfExpectations(new int[] {0});
         setUpGetVirtioScsiExpectations(new int[] {0});
         setUriInfo(setUpActionExpectations(VdcActionType.UpdateVm,
                                            VmManagementParametersBase.class,
@@ -236,6 +238,7 @@
         setUpGetBallooningExpectations();
         setUpGetBallooningExpectations();
         setUpGetConsoleExpectations(new int[] {0});
+        setUpGetVmOvfExpectations(new int[] {0});
         setUpGetVirtioScsiExpectations(new int[] {0});
 
         setUriInfo(setUpActionExpectations(VdcActionType.UpdateVm,
@@ -277,6 +280,7 @@
         setUpGetBallooningExpectations();
         setUpGetBallooningExpectations();
         setUpGetConsoleExpectations(new int[]{0});
+        setUpGetVmOvfExpectations(new int[] {0});
         setUpGetVirtioScsiExpectations(new int[] {0});
         setUpGetEntityExpectations("Hosts: name=" + NAMES[1],
                 SearchType.VDS,
@@ -314,6 +318,7 @@
         setUpGetBallooningExpectations();
         setUpGetBallooningExpectations();
         setUpGetConsoleExpectations(new int[] {0});
+        setUpGetVmOvfExpectations(new int[] {0});
         setUpGetVirtioScsiExpectations(new int[] {0});
         setUriInfo(setUpActionExpectations(VdcActionType.ChangeVMCluster,
                                            ChangeVMClusterParameters.class,
@@ -945,4 +950,13 @@
         }
     }
 
+    private void setUpGetVmOvfExpectations(int ... idxs) throws Exception {
+        for (int i = 0; i < idxs.length; i++) {
+            setUpGetEntityExpectations(VdcQueryType.GetVmOvfByVmId,
+                    IdQueryParameters.class,
+                    new String[] { "Id" },
+                    new Object[] { GUIDS[idxs[i]] },
+                    "configuration");
+        }
+    }
 }
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 dd034fa..a43b2f5 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
@@ -233,6 +233,7 @@
         setUpGetBallooningExpectations(1, 0);
         setUpGetConsoleExpectations(new int[]{0});
         setUpGetVirtioScsiExpectations(new int[]{0});
+        setUpGetVmOvfExpectations(new int[]{0});
         setUpGetCertuficateExpectations(1, 0);
         setUpEntityQueryExpectations(VdcQueryType.GetVdsGroupByVdsGroupId,
                 IdQueryParameters.class,
@@ -280,6 +281,7 @@
         setUpHttpHeaderExpectations("Expect", "201-created");
         setUpGetPayloadExpectations(2, 0);
         setUpGetConsoleExpectations(new int[]{0, 0});
+        setUpGetVmOvfExpectations(new int[]{0, 0});
         setUpGetVirtioScsiExpectations(new int[]{0, 0});
         setUpGetBallooningExpectations(2, 0);
         setUpGetCertuficateExpectations(2, 0);
@@ -336,6 +338,7 @@
         setUpGetPayloadExpectations(2, 0);
         setUpGetBallooningExpectations(2, 0);
         setUpGetConsoleExpectations(new int[]{0, 0});
+        setUpGetVmOvfExpectations(new int[]{0, 0});
         setUpGetVirtioScsiExpectations(new int[]{0, 0});
         setUpGetCertuficateExpectations(2, 0);
         setUpEntityQueryExpectations(VdcQueryType.GetVmByVmId,
@@ -387,6 +390,7 @@
         setUpGetPayloadExpectations(2, 0);
         setUpGetBallooningExpectations(2, 0);
         setUpGetConsoleExpectations(new int[]{0, 0});
+        setUpGetVmOvfExpectations(new int[]{0, 0});
         setUpGetVirtioScsiExpectations(new int[]{0, 0});
         setUpGetCertuficateExpectations(2, 0);
         setUpHttpHeaderExpectations("Expect", "201-created");
@@ -485,6 +489,7 @@
         setUpGetPayloadExpectations(1, 2);
         setUpGetBallooningExpectations(1, 2);
         setUpGetConsoleExpectations(new int[]{1, 2});
+        setUpGetVmOvfExpectations(new int[]{2});
         setUpGetVirtioScsiExpectations(new int[]{2});
         setUpGetCertuficateExpectations(1, 2);
         setUpEntityQueryExpectations(VdcQueryType.GetVmTemplate,
@@ -533,6 +538,7 @@
         setUpGetBallooningExpectations(1, 2);
         setUpGetCertuficateExpectations(1, 2);
         setUpGetConsoleExpectations(new int[]{0, 2});
+        setUpGetVmOvfExpectations(new int[]{2});
         setUpGetVirtioScsiExpectations(new int[]{2});
         setUpEntityQueryExpectations(VdcQueryType.GetVmConfigurationBySnapshot,
                 IdQueryParameters.class,
@@ -567,6 +573,7 @@
         setUpGetPayloadExpectations(1, 2);
         setUpGetBallooningExpectations(1, 2);
         setUpGetConsoleExpectations(new int[]{1, 2});
+        setUpGetVmOvfExpectations(new int[]{2});
         setUpGetVirtioScsiExpectations(new int[]{2});
         setUpGetCertuficateExpectations(1, 2);
         setUpEntityQueryExpectations(VdcQueryType.GetVmTemplate,
@@ -605,6 +612,7 @@
         setUpGetBallooningExpectations(1, 2);
         setUpGetCertuficateExpectations(1, 2);
         setUpGetConsoleExpectations(new int[]{1, 2});
+        setUpGetVmOvfExpectations(new int[]{2});
         setUpGetVirtioScsiExpectations(new int[]{2});
         setUpEntityQueryExpectations(VdcQueryType.GetVmTemplate,
                                      GetVmTemplateParameters.class,
@@ -641,6 +649,7 @@
         setUpGetBallooningExpectations(1, 2);
         setUpGetCertuficateExpectations(1, 2);
         setUpGetConsoleExpectations(new int[]{2});
+        setUpGetVmOvfExpectations(new int[]{2});
         setUpGetVirtioScsiExpectations(new int[]{2});
         VM model = createModel(null);
         org.ovirt.engine.core.common.businessentities.VM returnedVM = 
getEntity(2);
@@ -678,6 +687,7 @@
         setUpGetBallooningExpectations(1, 2);
         setUpGetCertuficateExpectations(1, 2);
         setUpGetConsoleExpectations(new int[]{2});
+        setUpGetVmOvfExpectations(new int[]{2});
         setUpGetVirtioScsiExpectations(new int[]{2});
         VM model = createModel(null);
         org.ovirt.engine.core.common.businessentities.VM returnedVM = 
getEntity(2);
@@ -772,6 +782,7 @@
         setUpGetPayloadExpectations(1, 2);
         setUpGetBallooningExpectations(1, 2);
         setUpGetConsoleExpectations(new int[]{1, 2});
+        setUpGetVmOvfExpectations(new int[]{2});
         setUpGetVirtioScsiExpectations(new int[]{2});
         setUpGetCertuficateExpectations(1, 2);
         setUpGetEntityExpectations("Hosts: name=" + NAMES[1],
@@ -823,6 +834,7 @@
         setUpGetPayloadExpectations(1, 2);
         setUpGetBallooningExpectations(1, 2);
         setUpGetConsoleExpectations(new int[]{1, 2});
+        setUpGetVmOvfExpectations(new int[]{2});
         setUpGetVirtioScsiExpectations(new int[]{2});
         setUpGetCertuficateExpectations(1, 2);
         setUpEntityQueryExpectations(VdcQueryType.GetVmTemplate,
@@ -863,6 +875,7 @@
         setUpGetPayloadExpectations(1, 2);
         setUpGetBallooningExpectations(1, 2);
         setUpGetConsoleExpectations(new int[]{1, 2});
+        setUpGetVmOvfExpectations(new int[]{2});
         setUpGetVirtioScsiExpectations(new int[]{2});
         setUpGetCertuficateExpectations(1, 2);
         setUpEntityQueryExpectations(VdcQueryType.GetVmTemplate,
@@ -924,6 +937,7 @@
         setUpGetBallooningExpectations(1, 2);
         setUpGetCertuficateExpectations(1, 2);
         setUpGetConsoleExpectations(new int[]{1, 2});
+        setUpGetVmOvfExpectations(new int[]{2});
         setUpGetVirtioScsiExpectations(new int[]{2});
         setUpEntityQueryExpectations(VdcQueryType.GetVmTemplate,
                                      GetVmTemplateParameters.class,
@@ -975,6 +989,7 @@
         setUpGetCertuficateExpectations(1, 2);
 
         setUpGetConsoleExpectations(new int[]{1, 2});
+        setUpGetVmOvfExpectations(new int[]{2});
         setUpGetVirtioScsiExpectations(new int[]{2});
         setUpEntityQueryExpectations(VdcQueryType.GetVmTemplate,
                                      GetVmTemplateParameters.class,
@@ -1045,6 +1060,7 @@
             setUpGetPayloadExpectations(3);
             setUpGetBallooningExpectations(3);
             setUpGetConsoleExpectations(new int[]{0, 1, 2});
+            setUpGetVmOvfExpectations(new int[]{0, 1, 2});
             setUpGetVirtioScsiExpectations(new int[]{0, 1, 2});
             setUpGetCertuficateExpectations(3);
         }
@@ -1063,6 +1079,7 @@
         setUpGetPayloadExpectations(3);
         setUpGetBallooningExpectations(3);
         setUpGetConsoleExpectations(new int[]{0, 1, 2});
+        setUpGetVmOvfExpectations(new int[]{0, 1, 2});
         setUpGetVirtioScsiExpectations(new int[]{0, 1, 2});
         setUpGetCertuficateExpectations(3);
         setUpQueryExpectations("");
@@ -1408,4 +1425,13 @@
         }
     }
 
+    private void setUpGetVmOvfExpectations(int ... idxs) throws Exception {
+        for (int i = 0; i < idxs.length; i++) {
+            setUpGetEntityExpectations(VdcQueryType.GetVmOvfByVmId,
+                    IdQueryParameters.class,
+                    new String[] { "Id" },
+                    new Object[] { GUIDS[idxs[i]] },
+                    "configuration");
+        }
+    }
 }
diff --git 
a/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/VmMapper.java
 
b/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/VmMapper.java
index ccd5f5b..97d61cb 100644
--- 
a/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/VmMapper.java
+++ 
b/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/VmMapper.java
@@ -18,6 +18,7 @@
 import org.ovirt.engine.api.model.CPU;
 import org.ovirt.engine.api.model.CloudInit;
 import org.ovirt.engine.api.model.Cluster;
+import org.ovirt.engine.api.model.Configuration;
 import org.ovirt.engine.api.model.ConfigurationType;
 import org.ovirt.engine.api.model.CpuMode;
 import org.ovirt.engine.api.model.CpuTopology;
@@ -34,6 +35,7 @@
 import org.ovirt.engine.api.model.Host;
 import org.ovirt.engine.api.model.IP;
 import org.ovirt.engine.api.model.IPs;
+import org.ovirt.engine.api.model.Initialization;
 import org.ovirt.engine.api.model.MemoryPolicy;
 import org.ovirt.engine.api.model.NIC;
 import org.ovirt.engine.api.model.OperatingSystem;
@@ -670,6 +672,14 @@
         }
     }
 
+    public static VM map(String configuration, ConfigurationType type, VM vm) {
+        vm.setInitialization(new Initialization());
+        vm.getInitialization().setConfiguration(new Configuration());
+        vm.getInitialization().getConfiguration().setData(configuration);
+        vm.getInitialization().getConfiguration().setType(type.value());
+        return vm;
+    }
+
     @Mapping(from = org.ovirt.engine.api.model.VmDeviceType.class, to = 
VmDeviceType.class)
     public static VmDeviceType map(org.ovirt.engine.api.model.VmDeviceType 
deviceType, VmDeviceType template) {
         switch (deviceType) {
diff --git 
a/backend/manager/modules/restapi/types/src/test/java/org/ovirt/engine/api/restapi/types/VmMapperTest.java
 
b/backend/manager/modules/restapi/types/src/test/java/org/ovirt/engine/api/restapi/types/VmMapperTest.java
index 25bbb38..d60edef 100644
--- 
a/backend/manager/modules/restapi/types/src/test/java/org/ovirt/engine/api/restapi/types/VmMapperTest.java
+++ 
b/backend/manager/modules/restapi/types/src/test/java/org/ovirt/engine/api/restapi/types/VmMapperTest.java
@@ -157,6 +157,19 @@
         assertEquals(payload.getVolumeId(), vmPayload.getVolumeId());
     }
 
+
+    @Test
+    public void ovfConfigurationMap() {
+        String ovfConfig = "config";
+        ConfigurationType configurationType = ConfigurationType.OVF;
+        VM model = new VM();
+        VmMapper.map(ovfConfig, ConfigurationType.OVF, model);
+        assertNotNull(model.getInitialization());
+        assertNotNull(model.getInitialization().getConfiguration());
+        assertEquals(model.getInitialization().getConfiguration().getData(), 
ovfConfig);
+        assertEquals(model.getInitialization().getConfiguration().getType(), 
configurationType);
+    }
+
     @Test
     public void testGustIp() {
         org.ovirt.engine.core.common.businessentities.VM vm = new 
org.ovirt.engine.core.common.businessentities.VM();


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

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

Reply via email to