Shmuel Leib Melamud has uploaded a new change for review. Change subject: restapi: Add VM parameters to VmPool collection ......................................................................
restapi: Add VM parameters to VmPool collection A majority of VM parameters that are available in the UI when adding VM Pool were missing from REST API VmPool collection. Added new <vm> subelement with all the VM fields into the <vmpool> element. The values of these fields override the values of the corresponding template parameters. The structure is: <vm_pool> <size>50</size> ... <template id="xxx"/> <vm> <some_overriden_field_a>new value</some_overriden_field_a> <some_overriden_field_b>new value 2</some_overriden_field_b> </vm> </vm_pool> Description on oVirt Wiki: http://www.ovirt.org/Features/Vm_Parameters_in_REST_API_for_Vm_Pools Change-Id: I791791a99abdf258f42b3e06288567f1b6c0bbf4 Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=1195167 Signed-off-by: Shmuel Melamud <[email protected]> --- M backend/manager/modules/restapi/interface/definition/src/main/resources/api.xsd M backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/AbstractBackendCollectionResource.java M backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVmPoolsResource.java M backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/VmPoolMapper.java 4 files changed, 29 insertions(+), 5 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/55/38755/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 b035ec74..a625769 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 @@ -3483,6 +3483,7 @@ <xs:element name="size" type="xs:int" minOccurs="0"/> <xs:element ref="cluster" minOccurs="0" maxOccurs="1"/> <xs:element ref="template" minOccurs="0" maxOccurs="1"/> + <xs:element ref="vm" minOccurs="0" maxOccurs="1"/> <xs:element name="prestarted_vms" type="xs:int" minOccurs="0"/> <xs:element name="max_user_vms" type="xs:int" minOccurs="0"/> <xs:element ref="display" minOccurs="0" maxOccurs="1"/> diff --git a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/AbstractBackendCollectionResource.java b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/AbstractBackendCollectionResource.java index 80da17d..95ac4ac 100644 --- a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/AbstractBackendCollectionResource.java +++ b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/AbstractBackendCollectionResource.java @@ -147,7 +147,7 @@ boolean block, Class<? extends BaseResource> suggestedParentType) { - // create (overidable) + // create (overridable) VdcReturnValueBase createResult = doCreateEntity(task, taskParams); // fetch + map diff --git a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVmPoolsResource.java b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVmPoolsResource.java index 31715fd..593aa4a 100644 --- a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVmPoolsResource.java +++ b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVmPoolsResource.java @@ -115,6 +115,7 @@ VM vm = getVM(model); model.setTemplate(new Template()); model.getTemplate().setId(vm.getVmtGuid().toString()); + model = getMapper(VM.class, VmPool.class).map(vm, model); } return model; } @@ -136,7 +137,7 @@ // apply template VmStatic vmStatic = getMapper(VmTemplate.class, VmStatic.class).map(template, null); // override with client-provided data - VM vm = getMapper(VmPool.class, VM.class).map(model, new VM(vmStatic, new VmDynamic(), new VmStatistics())); + VM vm = new VM(getMapper(VmPool.class, VmStatic.class).map(model, vmStatic), new VmDynamic(), new VmStatistics()); return vm; } diff --git a/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/VmPoolMapper.java b/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/VmPoolMapper.java index 0de055a..547a8fa 100644 --- a/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/VmPoolMapper.java +++ b/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/VmPoolMapper.java @@ -6,6 +6,7 @@ import org.ovirt.engine.api.model.VmPool; import org.ovirt.engine.api.restapi.utils.GuidUtils; import org.ovirt.engine.core.common.businessentities.VM; +import org.ovirt.engine.core.common.businessentities.VmStatic; public class VmPoolMapper { @@ -51,14 +52,24 @@ @Mapping(from = VmPool.class, to = VM.class) public static VM map(VmPool model, VM template) { VM entity = template != null ? template : new VM(); + entity.setStaticData(map(model, template.getStaticData())); + return entity; + } + + @Mapping(from = VmPool.class, to = VmStatic.class) + public static VmStatic map(VmPool model, VmStatic template) { + VmStatic entity = template != null ? template : new VmStatic(); + if (model.getVm() != null) { + entity = VmMapper.map(model.getVm(), template); + } entity.setName(model.getName()); - entity.setVmDescription(model.getDescription()); + entity.setDescription(model.getDescription()); if (model.isSetTemplate() && - model.getTemplate().isSetId()) { + model.getTemplate().isSetId()) { entity.setVmtGuid(GuidUtils.asGuid(model.getTemplate().getId())); } if (model.isSetCluster() && - model.getCluster().isSetId()) { + model.getCluster().isSetId()) { entity.setVdsGroupId(GuidUtils.asGuid(model.getCluster().getId())); } return entity; @@ -87,4 +98,15 @@ return model; } + + @Mapping(from = VM.class, to = VmPool.class) + public static VmPool map(VM vm, VmPool template) { + VmPool model = template != null ? template : new VmPool(); + org.ovirt.engine.api.model.VM vmModel = VmMapper.map(vm, (org.ovirt.engine.api.model.VM) null); + vmModel.setCluster(null); + vmModel.setTemplate(null); + vmModel.setVmPool(null); + model.setVm(vmModel); + return model; + } } -- To view, visit https://gerrit.ovirt.org/38755 To unsubscribe, visit https://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I791791a99abdf258f42b3e06288567f1b6c0bbf4 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Shmuel Leib Melamud <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
