From 4448449110e42b7251d2892959a0c23199b75483 Mon Sep 17 00:00:00 2001 From: Arik Hadas Date: Sun, 27 Nov 2022 14:50:34 +0200 Subject: [PATCH] core, webadmin: set new templates with specified vm-init Previously, the backend (AddVmTemplate) set new templates with the vm-init configuration of the VM that they were created from. This prevented users from creating templates with modified vm-init configuration or without vm- init configuration from VMs that are set with vm-init. Users could either change the VM first or modify the created template to achieve this. Now, the backend respects the vm-init configuration that is specified by clients. While the handling of vm-init in REST-API works well, the UI did not pass the vm-init configuration of the VM that templates were created from. Therefore, the webadmin is changed to load the vm-init configuration of the VM that a template is created from and pass it to the backend now. Signed-off-by: Arik Hadas --- .../engine/core/bll/AddVmTemplateCommand.java | 6 +-- .../uicommonweb/models/vms/VmListModel.java | 40 +++++++++++-------- 2 files changed, 26 insertions(+), 20 deletions(-) diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmTemplateCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmTemplateCommand.java index 4f9324ffa53..96a790a9c16 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmTemplateCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmTemplateCommand.java @@ -1003,10 +1003,10 @@ private void addVmTemplateToDb() { vmTemplateDao.save(getVmTemplate()); getCompensationContext().snapshotNewEntity(getVmTemplate()); setActionReturnValue(getVmTemplate().getId()); - // Load Vm Init from DB and set it to the template - vmHandler.updateVmInitFromDB(getParameters().getMasterVm(), false); getVmTemplate().setVmInit(getParameters().getMasterVm().getVmInit()); - vmHandler.addVmInitToDB(getVmTemplate().getVmInit()); + if (getVmTemplate().getVmInit() != null) { + vmHandler.addVmInitToDB(getVmTemplate().getVmInit()); + } } private void updateVmIcons() { diff --git a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VmListModel.java b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VmListModel.java index c3a3d74808a..a020e9f9854 100644 --- a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VmListModel.java +++ b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VmListModel.java @@ -1339,24 +1339,29 @@ private void onNewTemplate() { private void postNameUniqueCheck() { UnitVmModel model = (UnitVmModel) getWindow(); VM vm = getSelectedItem(); + // populating VMInit + AsyncQuery getVmInitQuery = new AsyncQuery<>(completeVm -> { + VM newVm = buildVmOnNewTemplate(model, completeVm); + + AddVmTemplateParameters addVmTemplateParameters = + new AddVmTemplateParameters(newVm, + model.getName().getEntity(), + model.getDescription().getEntity()); + BuilderExecutor.build(model, addVmTemplateParameters, new UnitToAddVmTemplateParametersBuilder()); + model.startProgress(); + Frontend.getInstance().runAction(ActionType.AddVmTemplate, addVmTemplateParameters, + result -> { + getWindow().stopProgress(); + ActionReturnValue returnValueBase = result.getReturnValue(); + if (returnValueBase != null && returnValueBase.getSucceeded()) { + cancel(); + } - VM newVm = buildVmOnNewTemplate(model, vm); - - AddVmTemplateParameters addVmTemplateParameters = - new AddVmTemplateParameters(newVm, - model.getName().getEntity(), - model.getDescription().getEntity()); - BuilderExecutor.build(model, addVmTemplateParameters, new UnitToAddVmTemplateParametersBuilder()); - model.startProgress(); - Frontend.getInstance().runAction(ActionType.AddVmTemplate, addVmTemplateParameters, - result -> { - getWindow().stopProgress(); - ActionReturnValue returnValueBase = result.getReturnValue(); - if (returnValueBase != null && returnValueBase.getSucceeded()) { - cancel(); - } - - }, this); + }, this); + }); + // TODO: if we ever support creation of templates from a running vm, + // we would need to take into account next-run configuration here + AsyncDataProvider.getInstance().getVmById(getVmInitQuery, vm.getId()); } protected static VM buildVmOnNewTemplate(UnitVmModel model, VM vm) { @@ -1364,6 +1369,7 @@ protected static VM buildVmOnNewTemplate(UnitVmModel model, VM vm) { resultVm.setId(vm.getId()); BuilderExecutor.build(model, resultVm.getStaticData(), new CommonUnitToVmBaseBuilder()); BuilderExecutor.build(vm.getStaticData(), resultVm.getStaticData(), new VmBaseToVmBaseForTemplateCompositeBaseBuilder()); + resultVm.setVmInit(vm.getVmInit()); return resultVm; }