Skip to content

Commit ee01f4d

Browse files
committed
webadmin: fix template creation resource issues
Fixes an issue where creating a template from a VM or VM snapshot can result in incorrect vCPU values and potentially incorrect memory values in the template. With this change, VmListModel.onNewTemplate() now runs model.validate() so that "Create Template" could fail fast if the VM model is invalid, instead of creating a template with wrong memory/CPU settings. Furthermore, getTotalCpuCores() is now called inside a callback function in order to avoid a race condition. Signed-off-by: Guoyong Zhang <[email protected]>
1 parent cc21354 commit ee01f4d

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VmListModel.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1326,11 +1326,9 @@ private void onNewTemplate() {
13261326
return;
13271327
}
13281328

1329-
if (!model.validateNaming()) {
1330-
return;
1331-
}
1332-
1333-
if (model.getIsSubTemplate().getEntity()) {
1329+
if (!model.validate(false)) {
1330+
model.setIsValid(false);
1331+
} else if (model.getIsSubTemplate().getEntity()) {
13341332
postNameUniqueCheck();
13351333
} else {
13361334
String name = model.getName().getEntity();
@@ -2193,7 +2191,7 @@ public void executeCommand(UICommand command) {
21932191
}
21942192

21952193
protected void exportOva() {
2196-
VM selectedEntity = (VM) getSelectedItem();
2194+
VM selectedEntity = getSelectedItem();
21972195
if (selectedEntity == null) {
21982196
return;
21992197
}

frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VmModelBehaviorBase.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1694,17 +1694,17 @@ public void updateMaxMemory() {
16941694
}
16951695

16961696
public void updateMemory() {
1697-
Integer memoryMb = getModel().getMemSize().getEntity();
16981697
AsyncDataProvider.getMinMemoryForOs(new AsyncQuery<>(minMemory -> {
1698+
Integer memoryMb = getModel().getMemSize().getEntity();
16991699
if (memoryMb == null || memoryMb < minMemory) {
17001700
getModel().getMemSize().setEntity(minMemory);
17011701
}
17021702
}), getSelectedOSType(), getCompatibilityVersion());
17031703
}
17041704

17051705
public void updateTotalCpuCores() {
1706-
int cpuCores = getTotalCpuCores();
17071706
AsyncDataProvider.getMinCpus(new AsyncQuery<>(minCpus -> {
1707+
int cpuCores = getTotalCpuCores();
17081708
if (cpuCores < minCpus) {
17091709
getModel().getTotalCPUCores().setEntity(Integer.toString(minCpus));
17101710
}

0 commit comments

Comments
 (0)