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
This commit is contained in:
Felipe 2024-10-01 17:37:47 -03:00 committed by GitHub
parent 00fe5f1471
commit 28f425a9f9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -84,7 +84,7 @@
}" }"
:options="groups.opts" /> :options="groups.opts" />
</a-form-item> </a-form-item>
<a-form-item> <a-form-item v-if="userDataEnabled">
<template #label> <template #label>
<tooltip-label :title="$t('label.userdata')" :tooltip="apiParams.userdata.description"/> <tooltip-label :title="$t('label.userdata')" :tooltip="apiParams.userdata.description"/>
</template> </template>
@ -143,6 +143,7 @@ export default {
return { return {
serviceOffering: {}, serviceOffering: {},
template: {}, template: {},
userDataEnabled: false,
securityGroupsEnabled: false, securityGroupsEnabled: false,
dynamicScalingVmConfig: false, dynamicScalingVmConfig: false,
loading: false, loading: false,
@ -289,15 +290,37 @@ export default {
return decodedData.toString('utf-8') return decodedData.toString('utf-8')
}, },
fetchUserData () { fetchUserData () {
const params = { let networkId
id: this.resource.id, this.resource.nic.forEach(nic => {
userdata: true 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 => { const listVmParams = {
this.form.userdata = this.decodeUserData(json.listvirtualmachinesresponse.virtualmachine[0].userdata || '') id: this.resource.id,
userdata: true,
listall: true
}
api('listVirtualMachines', listVmParams).then(json => {
this.form.userdata = atob(json.listvirtualmachinesresponse.virtualmachine[0].userdata || '')
})
}
})
}) })
}, },
handleSubmit () { handleSubmit () {
this.formRef.value.validate().then(() => { this.formRef.value.validate().then(() => {
const values = toRaw(this.form) const values = toRaw(this.form)