You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ro...@apache.org on 2021/09/06 12:58:56 UTC
[cloudstack] branch 4.15 updated: api,
ui: fix NPE with deployVirtualMachine when null boottype (#5387)
This is an automated email from the ASF dual-hosted git repository.
rohit pushed a commit to branch 4.15
in repository https://gitbox.apache.org/repos/asf/cloudstack.git
The following commit(s) were added to refs/heads/4.15 by this push:
new f564597 api, ui: fix NPE with deployVirtualMachine when null boottype (#5387)
f564597 is described below
commit f564597e9246d1cc28ce02e1ebbe55f4afec1a1b
Author: Abhishek Kumar <ab...@gmail.com>
AuthorDate: Mon Sep 6 18:28:32 2021 +0530
api, ui: fix NPE with deployVirtualMachine when null boottype (#5387)
* api: fix NPE with deployVirtualMachine when null boottype
Signed-off-by: Abhishek Kumar <ab...@gmail.com>
* throw exception for empty bootmode
Signed-off-by: Abhishek Kumar <ab...@gmail.com>
* fix
Signed-off-by: Abhishek Kumar <ab...@gmail.com>
* ui: fix boot options
Signed-off-by: Abhishek Kumar <ab...@gmail.com>
* check
Signed-off-by: Abhishek Kumar <ab...@gmail.com>
---
.../api/command/user/vm/DeployVMCmd.java | 21 +++++----
ui/src/views/compute/DeployVM.vue | 51 ++++++++--------------
2 files changed, 31 insertions(+), 41 deletions(-)
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java
index 6d7cc9c..801e025 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java
@@ -27,8 +27,6 @@ import java.util.Map;
import javax.annotation.Nonnull;
-import com.cloud.utils.StringUtils;
-
import org.apache.cloudstack.acl.RoleType;
import org.apache.cloudstack.affinity.AffinityGroupResponse;
import org.apache.cloudstack.api.ACL;
@@ -70,6 +68,7 @@ import com.cloud.network.Network.IpAddresses;
import com.cloud.offering.DiskOffering;
import com.cloud.template.VirtualMachineTemplate;
import com.cloud.uservm.UserVm;
+import com.cloud.utils.StringUtils;
import com.cloud.utils.net.Dhcp;
import com.cloud.utils.net.NetUtils;
import com.cloud.vm.VirtualMachine;
@@ -265,7 +264,7 @@ public class DeployVMCmd extends BaseAsyncCreateCustomIdCmd implements SecurityG
return domainId;
}
- public ApiConstants.BootType getBootType() {
+ public ApiConstants.BootType getBootType() {
if (StringUtils.isNotBlank(bootType)) {
try {
String type = bootType.trim().toUpperCase();
@@ -310,11 +309,17 @@ public class DeployVMCmd extends BaseAsyncCreateCustomIdCmd implements SecurityG
String mode = bootMode.trim().toUpperCase();
return ApiConstants.BootMode.valueOf(mode);
} catch (IllegalArgumentException e) {
- String errMesg = "Invalid bootMode " + bootMode + "Specified for vm " + getName()
- + " Valid values are: "+ Arrays.toString(ApiConstants.BootMode.values());
- s_logger.warn(errMesg);
- throw new InvalidParameterValueException(errMesg);
- }
+ String msg = String.format("Invalid %s: %s specified for VM: %s. Valid values are: %s",
+ ApiConstants.BOOT_MODE, bootMode, getName(), Arrays.toString(ApiConstants.BootMode.values()));
+ s_logger.error(msg);
+ throw new InvalidParameterValueException(msg);
+ }
+ }
+ if (ApiConstants.BootType.UEFI.equals(getBootType())) {
+ String msg = String.format("%s must be specified for the VM with boot type: %s. Valid values are: %s",
+ ApiConstants.BOOT_MODE, getBootType(), Arrays.toString(ApiConstants.BootMode.values()));
+ s_logger.error(msg);
+ throw new InvalidParameterValueException(msg);
}
return null;
}
diff --git a/ui/src/views/compute/DeployVM.vue b/ui/src/views/compute/DeployVM.vue
index 2b415ef..6578a87 100644
--- a/ui/src/views/compute/DeployVM.vue
+++ b/ui/src/views/compute/DeployVM.vue
@@ -487,16 +487,15 @@
<template slot="description" v-if="zoneSelected">
<span>
{{ $t('label.isadvanced') }}
- <a-switch @change="val => { this.showDetails = val }" :checked="this.showDetails" style="margin-left: 10px"/>
+ <a-switch @change="val => { showDetails = val }" :checked="showDetails" style="margin-left: 10px"/>
</span>
<div style="margin-top: 15px" v-show="this.showDetails">
<div
v-if="vm.templateid && ['KVM', 'VMware', 'XenServer'].includes(hypervisor) && !template.deployasis">
<a-form-item :label="$t('label.boottype')">
<a-select
- v-decorator="['boottype']"
- @change="fetchBootModes"
- >
+ v-decorator="['boottype', { initialValue: options.bootTypes && options.bootTypes.length > 0 ? options.bootTypes[0].id : undefined }]"
+ @change="onBootTypeChange">
<a-select-option v-for="bootType in options.bootTypes" :key="bootType.id">
{{ bootType.description }}
</a-select-option>
@@ -504,7 +503,7 @@
</a-form-item>
<a-form-item :label="$t('label.bootmode')">
<a-select
- v-decorator="['bootmode']">
+ v-decorator="['bootmode', { initialValue: options.bootModes && options.bootModes.length > 0 ? options.bootModes[0].id : undefined }]">
<a-select-option v-for="bootMode in options.bootModes" :key="bootMode.id">
{{ bootMode.description }}
</a-select-option>
@@ -1227,39 +1226,21 @@ export default {
await this.fetchAllTemplates()
},
fetchBootTypes () {
- const bootTypes = []
-
- bootTypes.push({
- id: 'BIOS',
- description: 'BIOS'
- })
- bootTypes.push({
- id: 'UEFI',
- description: 'UEFI'
- })
-
- this.options.bootTypes = bootTypes
+ this.options.bootTypes = [
+ { id: 'BIOS', description: 'BIOS' },
+ { id: 'UEFI', description: 'UEFI' }
+ ]
this.$forceUpdate()
},
fetchBootModes (bootType) {
- const bootModes = []
-
+ const bootModes = [
+ { id: 'LEGACY', description: 'LEGACY' }
+ ]
if (bootType === 'UEFI') {
- bootModes.push({
- id: 'LEGACY',
- description: 'LEGACY'
- })
- bootModes.push({
- id: 'SECURE',
- description: 'SECURE'
- })
- } else {
- bootModes.push({
- id: 'LEGACY',
- description: 'LEGACY'
- })
+ bootModes.unshift(
+ { id: 'SECURE', description: 'SECURE' }
+ )
}
-
this.options.bootModes = bootModes
this.$forceUpdate()
},
@@ -2035,6 +2016,10 @@ export default {
},
updateIOPSValue (input, value) {
this[input] = value
+ },
+ onBootTypeChange (value) {
+ this.fetchBootModes(value)
+ this.updateFieldValue('bootmode', this.options.bootModes?.[0]?.id || undefined)
}
}
}