From 28f425a9f97bee9ed505017c119e865cd4ff0a73 Mon Sep 17 00:00:00 2001 From: Felipe <124818914+FelipeM525@users.noreply.github.com> Date: Tue, 1 Oct 2024 17:37:47 -0300 Subject: [PATCH] Hide UserData field from the EditVM view for VMs that do not offer it (#9731) * added a v-if directive within the EditVm view to not show the field userdata if the vm's network does not offer the feature * added the parameter listall:true to the requests made to listNetworks and listVirtualMachines --- ui/src/views/compute/EditVM.vue | 35 +++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/ui/src/views/compute/EditVM.vue b/ui/src/views/compute/EditVM.vue index 550c4645ed6..876bc7819b4 100644 --- a/ui/src/views/compute/EditVM.vue +++ b/ui/src/views/compute/EditVM.vue @@ -84,7 +84,7 @@ }" :options="groups.opts" /> - + @@ -143,6 +143,7 @@ export default { return { serviceOffering: {}, template: {}, + userDataEnabled: false, securityGroupsEnabled: false, dynamicScalingVmConfig: false, loading: false, @@ -289,15 +290,37 @@ export default { return decodedData.toString('utf-8') }, fetchUserData () { - const params = { - id: this.resource.id, - userdata: true + let networkId + this.resource.nic.forEach(nic => { + if (nic.isdefault) { + networkId = nic.networkid + } + }) + if (!networkId) { + return } + const listNetworkParams = { + id: networkId, + listall: true + } + api(`listNetworks`, listNetworkParams).then(json => { + json.listnetworksresponse.network[0].service.forEach(service => { + if (service.name === 'UserData') { + this.userDataEnabled = true - api('listVirtualMachines', params).then(json => { - this.form.userdata = this.decodeUserData(json.listvirtualmachinesresponse.virtualmachine[0].userdata || '') + const listVmParams = { + id: this.resource.id, + userdata: true, + listall: true + } + api('listVirtualMachines', listVmParams).then(json => { + this.form.userdata = atob(json.listvirtualmachinesresponse.virtualmachine[0].userdata || '') + }) + } + }) }) }, + handleSubmit () { this.formRef.value.validate().then(() => { const values = toRaw(this.form)