From 46cece5c4af44d161d08128dddfbc97cf1356770 Mon Sep 17 00:00:00 2001 From: utchoang Date: Fri, 1 Jul 2022 16:53:26 +0700 Subject: [PATCH 1/4] add authmethod to addhost in zone wizard --- ui/src/views/infra/zone/StaticInputsForm.vue | 49 +++++++++++++++++-- .../infra/zone/ZoneWizardAddResources.vue | 27 ++++++++++ .../views/infra/zone/ZoneWizardLaunchZone.vue | 3 +- 3 files changed, 74 insertions(+), 5 deletions(-) diff --git a/ui/src/views/infra/zone/StaticInputsForm.vue b/ui/src/views/infra/zone/StaticInputsForm.vue index 0c23a3ad0835..3cc04136f41f 100644 --- a/ui/src/views/infra/zone/StaticInputsForm.vue +++ b/ui/src/views/infra/zone/StaticInputsForm.vue @@ -67,6 +67,26 @@ v-model:value="form[field.key]" v-focus="index === 0" /> + + + + {{ $t(radioItem.label) }} + + + + + + { @@ -236,6 +256,27 @@ export default { return false } return true + }, + isDisplaySubItem (conditions) { + if (!conditions || Object.keys(conditions).length === 0) { + return true + } + let isShow = true + Object.keys(conditions).forEach(key => { + if (!isShow) return false + + const condition = conditions[key] + const fieldVal = this.form[key] + ? this.form[key] + : (this.prefillContent?.[key] || null) + if (Array.isArray(condition) && !condition.includes(fieldVal)) { + isShow = false + } else if (!Array.isArray(condition) && fieldVal !== condition) { + isShow = false + } + }) + + return isShow } } } diff --git a/ui/src/views/infra/zone/ZoneWizardAddResources.vue b/ui/src/views/infra/zone/ZoneWizardAddResources.vue index 8a52ec91007c..c8df0432216c 100644 --- a/ui/src/views/infra/zone/ZoneWizardAddResources.vue +++ b/ui/src/views/infra/zone/ZoneWizardAddResources.vue @@ -284,6 +284,33 @@ export default { hypervisor: ['VMware', 'BareMetal', 'Ovm', 'Hyperv', 'KVM', 'XenServer', 'LXC', 'Simulator'] } }, + { + title: 'label.authentication.method', + key: 'authmethod', + placeHolder: 'message.error.authmethod', + required: false, + radioGroup: true, + defaultValue: 'password', + radioOption: [{ + label: 'label.password', + value: 'password' + }, { + label: 'label.authentication.sshkey', + value: 'sshkey', + condition: { + hypervisor: ['KVM'] + } + }], + display: { + hypervisor: ['BareMetal', 'Ovm', 'Hyperv', 'KVM', 'XenServer', 'LXC', 'Simulator'] + }, + alert: { + message: 'message.add.host.sshkey', + display: { + authmethod: 'sshkey' + } + } + }, { title: 'label.password', key: 'hostPassword', diff --git a/ui/src/views/infra/zone/ZoneWizardLaunchZone.vue b/ui/src/views/infra/zone/ZoneWizardLaunchZone.vue index 432523c901a2..7f23c3b643ad 100644 --- a/ui/src/views/infra/zone/ZoneWizardLaunchZone.vue +++ b/ui/src/views/infra/zone/ZoneWizardLaunchZone.vue @@ -1211,6 +1211,7 @@ export default { this.addStep('message.adding.host', 'hostResource') const hostData = {} + const hostPassword = this.prefillContent?.authmethod !== 'password' ? '' : (this.prefillContent?.hostPassword || null) hostData.zoneid = this.stepData.zoneReturned.id hostData.podid = this.stepData.podReturned.id hostData.clusterid = this.stepData.clusterReturned.id @@ -1218,7 +1219,7 @@ export default { hostData.clustertype = this.stepData.clusterReturned.clustertype hostData.hosttags = this.prefillContent?.hostTags || null hostData.username = this.prefillContent?.hostUserName || null - hostData.password = this.prefillContent?.hostPassword || null + hostData.password = hostPassword const hostname = this.prefillContent?.hostName || null let url = null if (hostname.indexOf('http://') === -1) { From a9674fe987390758513c2d0274e6524658c4edbc Mon Sep 17 00:00:00 2001 From: utchoang Date: Mon, 4 Jul 2022 08:23:54 +0700 Subject: [PATCH 2/4] add a condition for hiding password field --- ui/src/views/infra/zone/StaticInputsForm.vue | 6 +++--- ui/src/views/infra/zone/ZoneWizardAddResources.vue | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/ui/src/views/infra/zone/StaticInputsForm.vue b/ui/src/views/infra/zone/StaticInputsForm.vue index 3cc04136f41f..c12bd7fc0700 100644 --- a/ui/src/views/infra/zone/StaticInputsForm.vue +++ b/ui/src/views/infra/zone/StaticInputsForm.vue @@ -77,11 +77,11 @@ :key="idx"> + v-if="isDisplayItem(radioItem.condition)"> {{ $t(radioItem.label) }} - + @@ -257,7 +257,7 @@ export default { } return true }, - isDisplaySubItem (conditions) { + isDisplayItem (conditions) { if (!conditions || Object.keys(conditions).length === 0) { return true } diff --git a/ui/src/views/infra/zone/ZoneWizardAddResources.vue b/ui/src/views/infra/zone/ZoneWizardAddResources.vue index c8df0432216c..ad16ef30aa1c 100644 --- a/ui/src/views/infra/zone/ZoneWizardAddResources.vue +++ b/ui/src/views/infra/zone/ZoneWizardAddResources.vue @@ -318,7 +318,8 @@ export default { required: true, password: true, display: { - hypervisor: ['VMware', 'BareMetal', 'Ovm', 'Hyperv', 'KVM', 'XenServer', 'LXC', 'Simulator'] + hypervisor: ['VMware', 'BareMetal', 'Ovm', 'Hyperv', 'KVM', 'XenServer', 'LXC', 'Simulator'], + authmethod: 'password' } }, { From f56e47fc1200028ee5864398fd2346e33639e855 Mon Sep 17 00:00:00 2001 From: utchoang Date: Mon, 4 Jul 2022 11:45:29 +0700 Subject: [PATCH 3/4] set default value when switch hypervisor --- ui/src/views/infra/zone/StaticInputsForm.vue | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/ui/src/views/infra/zone/StaticInputsForm.vue b/ui/src/views/infra/zone/StaticInputsForm.vue index c12bd7fc0700..7bc6f18610da 100644 --- a/ui/src/views/infra/zone/StaticInputsForm.vue +++ b/ui/src/views/infra/zone/StaticInputsForm.vue @@ -138,6 +138,11 @@ export default { created () { this.initForm() }, + computed: { + hypervisor () { + return this.prefillContent?.hypervisor || null + } + }, mounted () { this.fillValue() }, @@ -200,6 +205,9 @@ export default { } }, getPrefilled (field) { + if (field.key === 'authmethod' && this.hypervisor !== 'KVM') { + return field.defaultValue || null + } return this.prefillContent?.[field.key] || field.value || field.defaultValue || null }, handleSubmit () { From b71176af7878fd6a00edce020e24e85f2db5c1a9 Mon Sep 17 00:00:00 2001 From: utchoang Date: Mon, 4 Jul 2022 11:46:58 +0700 Subject: [PATCH 4/4] add more value for authmethod --- ui/src/views/infra/zone/StaticInputsForm.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/src/views/infra/zone/StaticInputsForm.vue b/ui/src/views/infra/zone/StaticInputsForm.vue index 7bc6f18610da..6604ba32c885 100644 --- a/ui/src/views/infra/zone/StaticInputsForm.vue +++ b/ui/src/views/infra/zone/StaticInputsForm.vue @@ -206,7 +206,7 @@ export default { }, getPrefilled (field) { if (field.key === 'authmethod' && this.hypervisor !== 'KVM') { - return field.defaultValue || null + return field.value || field.defaultValue || 'password' } return this.prefillContent?.[field.key] || field.value || field.defaultValue || null },