Skip to content

Commit

Permalink
core, webadmin: set new templates with specified vm-init
Browse files Browse the repository at this point in the history
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 <ahadas@redhat.com>
  • Loading branch information
ahadas committed Nov 27, 2022
1 parent 23aa972 commit 4448449
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1339,31 +1339,37 @@ private void onNewTemplate() {
private void postNameUniqueCheck() {
UnitVmModel model = (UnitVmModel) getWindow();
VM vm = getSelectedItem();
// populating VMInit
AsyncQuery<VM> 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) {
VM resultVm = new 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;
}

Expand Down

0 comments on commit 4448449

Please sign in to comment.