Skip to content

Commit 28f425a

Browse files
authored
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
1 parent 00fe5f1 commit 28f425a

File tree

1 file changed

+29
-6
lines changed

1 file changed

+29
-6
lines changed

ui/src/views/compute/EditVM.vue

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
}"
8585
:options="groups.opts" />
8686
</a-form-item>
87-
<a-form-item>
87+
<a-form-item v-if="userDataEnabled">
8888
<template #label>
8989
<tooltip-label :title="$t('label.userdata')" :tooltip="apiParams.userdata.description"/>
9090
</template>
@@ -143,6 +143,7 @@ export default {
143143
return {
144144
serviceOffering: {},
145145
template: {},
146+
userDataEnabled: false,
146147
securityGroupsEnabled: false,
147148
dynamicScalingVmConfig: false,
148149
loading: false,
@@ -289,15 +290,37 @@ export default {
289290
return decodedData.toString('utf-8')
290291
},
291292
fetchUserData () {
292-
const params = {
293-
id: this.resource.id,
294-
userdata: true
293+
let networkId
294+
this.resource.nic.forEach(nic => {
295+
if (nic.isdefault) {
296+
networkId = nic.networkid
297+
}
298+
})
299+
if (!networkId) {
300+
return
301+
}
302+
const listNetworkParams = {
303+
id: networkId,
304+
listall: true
295305
}
306+
api(`listNetworks`, listNetworkParams).then(json => {
307+
json.listnetworksresponse.network[0].service.forEach(service => {
308+
if (service.name === 'UserData') {
309+
this.userDataEnabled = true
296310
297-
api('listVirtualMachines', params).then(json => {
298-
this.form.userdata = this.decodeUserData(json.listvirtualmachinesresponse.virtualmachine[0].userdata || '')
311+
const listVmParams = {
312+
id: this.resource.id,
313+
userdata: true,
314+
listall: true
315+
}
316+
api('listVirtualMachines', listVmParams).then(json => {
317+
this.form.userdata = atob(json.listvirtualmachinesresponse.virtualmachine[0].userdata || '')
318+
})
319+
}
320+
})
299321
})
300322
},
323+
301324
handleSubmit () {
302325
this.formRef.value.validate().then(() => {
303326
const values = toRaw(this.form)

0 commit comments

Comments
 (0)