From 861c38d87fc8012f0f8e5e49d8cbf718629ff733 Mon Sep 17 00:00:00 2001 From: Pearl Dsilva Date: Fri, 18 Mar 2022 14:48:20 +0530 Subject: [PATCH 1/2] ui: Support to specify security groups when updating/editing a VM (adv zone + SG) --- ui/src/components/view/DetailsTab.vue | 11 ++++- ui/src/config/section/compute.js | 10 ++++- ui/src/views/compute/EditVM.vue | 62 ++++++++++++++++++++++++++- 3 files changed, 79 insertions(+), 4 deletions(-) diff --git a/ui/src/components/view/DetailsTab.vue b/ui/src/components/view/DetailsTab.vue index 9800448b7977..a228010b8500 100644 --- a/ui/src/components/view/DetailsTab.vue +++ b/ui/src/components/view/DetailsTab.vue @@ -41,14 +41,21 @@
{{ $t(dataResource[item].toLowerCase()) }} - {{ dataResource[item] }} + {{ dataResource[item] }}h
- {{ $toLocaleDate(dataResource[item]) }} + {{ $toLocaleDate(dataResource[item]) }}h
{{ dataResource[item]? $t('message.egress.rules.allow') : $t('message.egress.rules.deny') }}
+
+
+ + {{ securityGroup.name }}   + +
+
{{ dataResource[item] }}
diff --git a/ui/src/config/section/compute.js b/ui/src/config/section/compute.js index 955383b8d7c2..350c00d94927 100644 --- a/ui/src/config/section/compute.js +++ b/ui/src/config/section/compute.js @@ -67,7 +67,15 @@ export default { return fields }, searchFilters: ['name', 'zoneid', 'domainid', 'account', 'tags'], - details: ['displayname', 'name', 'id', 'state', 'ipaddress', 'ip6address', 'templatename', 'ostypename', 'serviceofferingname', 'isdynamicallyscalable', 'haenable', 'hypervisor', 'boottype', 'bootmode', 'account', 'domain', 'zonename'], + details: () => { + var fields = ['displayname', 'name', 'id', 'state', 'ipaddress', 'ip6address', 'templatename', 'ostypename', 'serviceofferingname', 'isdynamicallyscalable', 'haenable', 'hypervisor', 'boottype', 'bootmode', 'account', 'domain', 'zonename'] + const listZoneHaveSGEnabled = store.getters.zones.filter(zone => zone.securitygroupsenabled === true) + if (!listZoneHaveSGEnabled || listZoneHaveSGEnabled.length === 0) { + return fields + } + fields.push('securitygroup') + return fields + }, tabs: [{ component: shallowRef(defineAsyncComponent(() => import('@/views/compute/InstanceTab.vue'))) }], diff --git a/ui/src/views/compute/EditVM.vue b/ui/src/views/compute/EditVM.vue index ffd13e2459c1..87545c7e11c3 100644 --- a/ui/src/views/compute/EditVM.vue +++ b/ui/src/views/compute/EditVM.vue @@ -91,6 +91,25 @@ + + + +
+ {{ securitygroup.name || securitygroup.id }} +
+
+
+
{{ $t('label.cancel') }} @@ -124,8 +143,13 @@ export default { return { serviceOffering: {}, template: {}, + securityGroupsEnabled: false, dynamicScalingVmConfig: false, loading: false, + securitygroups: { + loading: false, + opts: [] + }, osTypes: { loading: false, opts: [] @@ -151,17 +175,48 @@ export default { displayname: this.resource.displayname, ostypeid: this.resource.ostypeid, isdynamicallyscalable: this.resource.isdynamicallyscalable, - group: this.resource.group + group: this.resource.group, + securitygroupids: this.resource.securitygroup.map(x => x.id) }) this.rules = reactive({}) }, fetchData () { + this.fetchZoneDetails() + this.fetchSecurityGroups() this.fetchOsTypes() this.fetchInstaceGroups() this.fetchServiceOfferingData() this.fetchTemplateData() this.fetchDynamicScalingVmConfig() }, + fetchZoneDetails () { + api('listZones', { + zoneid: this.resource.zoneid + }).then(response => { + const zone = response?.listzonesresponse?.zone || [] + this.securityGroupsEnabled = zone?.[0]?.securitygroupsenabled + }) + }, + fetchSecurityGroups () { + this.securitygroups.loading = true + api('listSecurityGroups', { + zoneid: this.resource.zoneid + }).then(json => { + const items = json.listsecuritygroupsresponse.securitygroup || [] + if (items && items.length > 0) { + for (let i = 0; i < items.length; i++) { + this.securitygroups.opts.push(items[i]) + } + this.securitygroups.opts.sort((a, b) => { + if (a.name < b.name) return -1 + if (a.name > b.name) return 1 + return 0 + }) + } + }).finally(() => { + this.securitygroups.loading = false + }) + }, fetchServiceOfferingData () { const params = {} params.id = this.resource.serviceofferingid @@ -242,6 +297,11 @@ export default { params.name = values.name params.displayname = values.displayname params.ostypeid = values.ostypeid + if (this.securityGroupsEnabled) { + if (values.securitygroupids) { + params.securitygroupids = values.securitygroupids + } + } if (values.isdynamicallyscalable !== undefined) { params.isdynamicallyscalable = values.isdynamicallyscalable } From 0bea1ecdca23f9d3e6215f67381e80a8256bdb8f Mon Sep 17 00:00:00 2001 From: Pearl Dsilva Date: Mon, 21 Mar 2022 09:52:38 +0530 Subject: [PATCH 2/2] cleanup --- ui/src/components/view/DetailsTab.vue | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ui/src/components/view/DetailsTab.vue b/ui/src/components/view/DetailsTab.vue index a228010b8500..2554ad233b89 100644 --- a/ui/src/components/view/DetailsTab.vue +++ b/ui/src/components/view/DetailsTab.vue @@ -41,10 +41,10 @@
{{ $t(dataResource[item].toLowerCase()) }} - {{ dataResource[item] }}h + {{ dataResource[item] }}
- {{ $toLocaleDate(dataResource[item]) }}h + {{ $toLocaleDate(dataResource[item]) }}
{{ dataResource[item]? $t('message.egress.rules.allow') : $t('message.egress.rules.deny') }}