From 84f19d8f3641fbe5c4fe1adb66fb99a3fa6976dc Mon Sep 17 00:00:00 2001 From: Wei Zhou Date: Mon, 7 Mar 2022 11:59:52 +0100 Subject: [PATCH] UI: update vm with userdata (#6051) * UI: update vm with userdata * Update ui/src/views/compute/EditVM.vue Co-authored-by: David Jumani * Update #6051: small fixes Co-authored-by: David Jumani --- ui/src/views/compute/EditVM.vue | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/ui/src/views/compute/EditVM.vue b/ui/src/views/compute/EditVM.vue index ee4273d5a66..e3348bcfb71 100644 --- a/ui/src/views/compute/EditVM.vue +++ b/ui/src/views/compute/EditVM.vue @@ -74,6 +74,12 @@ }" :dataSource="groups.opts" /> + + + + +
{{ this.$t('label.cancel') }} @@ -145,7 +151,6 @@ export default { }, fetchTemplateData () { const params = {} - console.log('templateid ' + this.resource.templateid) params.id = this.resource.templateid params.isrecursive = true params.templatefilter = 'all' @@ -198,6 +203,14 @@ export default { this.$notifyError(error) }).finally(() => { this.groups.loading = false }) }, + sanitizeReverse (value) { + const reversedValue = value + .replace(/&/g, '&') + .replace(/</g, '<') + .replace(/>/g, '>') + + return reversedValue + }, handleSubmit (e) { e.preventDefault() this.form.validateFieldsAndScroll((err, values) => { @@ -214,10 +227,15 @@ export default { if (values.haenable !== undefined) { params.haenable = values.haenable } - params.group = values.group + if (values.group && values.group.length > 0) { + params.group = values.group + } + if (values.userdata && values.userdata.length > 0) { + params.userdata = encodeURIComponent(btoa(this.sanitizeReverse(values.userdata))) + } this.loading = true - api('updateVirtualMachine', params).then(json => { + api('updateVirtualMachine', {}, 'POST', params).then(json => { this.$message.success({ content: `${this.$t('label.action.edit.instance')} - ${values.name}`, duration: 2