From a9720d540f27c5d3809b509d84eaa2b2f189af59 Mon Sep 17 00:00:00 2001 From: Pearl Dsilva Date: Wed, 12 Aug 2020 15:10:54 +0530 Subject: [PATCH] storage: Add storage policies field for DiskOffering and Primary storage creation Forms (#548) Add storage policies field for DiskOffering, COmputeOffering and Primary storage creation Forms Co-authored-by: Pearl Dsilva Signed-off-by: Rohit Yadav --- ui/src/locales/en.json | 1 + ui/src/views/infra/AddPrimaryStorage.vue | 37 ++++++++++++--- ui/src/views/offering/AddComputeOffering.vue | 42 ++++++++++++++++- ui/src/views/offering/AddDiskOffering.vue | 47 +++++++++++++++++++- 4 files changed, 119 insertions(+), 8 deletions(-) diff --git a/ui/src/locales/en.json b/ui/src/locales/en.json index c19ac23385f..669cef669cf 100644 --- a/ui/src/locales/en.json +++ b/ui/src/locales/en.json @@ -2224,6 +2224,7 @@ "label.vms.in.tier": "VMs in tier", "label.vmstate": "VM State", "label.vmtotal": "Total of VMs", +"label.vmware.storage.policy": "VMWare Storage Policy", "label.vmwaredcid": "VMware Datacenter ID", "label.vmwaredcname": "VMware Datacenter Name", "label.vmwaredcvcenter": "VMware Datacenter vCenter", diff --git a/ui/src/views/infra/AddPrimaryStorage.vue b/ui/src/views/infra/AddPrimaryStorage.vue index e043e623c6c..fb9fa632de3 100644 --- a/ui/src/views/infra/AddPrimaryStorage.vue +++ b/ui/src/views/infra/AddPrimaryStorage.vue @@ -89,12 +89,13 @@
+ v-if="protocolSelected === 'nfs' || protocolSelected === 'SMB' || protocolSelected === 'iscsi' || protocolSelected === 'vmfs'|| protocolSelected === 'Gluster' || + (protocolSelected === 'PreSetup' && hypervisorType === 'VMware') || protocolSelected === 'datastorecluster'">
-
+
@@ -118,7 +119,7 @@
-
+
@@ -312,9 +313,12 @@ export default { if (this.hypervisorType === 'KVM') { this.protocols = ['nfs', 'SharedMountPoint', 'RBD', 'CLVM', 'Gluster', 'custom'] } else if (this.hypervisorType === 'XenServer') { - this.protocols = ['nfs', 'preSetup', 'iscsi', 'custom'] + this.protocols = ['nfs', 'PreSetup', 'iscsi', 'custom'] } else if (this.hypervisorType === 'VMware') { this.protocols = ['nfs', 'vmfs', 'custom'] + if ('importVsphereStoragePolicies' in this.$store.getters.apis) { + this.protocols = ['nfs', 'PreSetup', 'datastorecluster', 'custom'] + } } else if (this.hypervisorType === 'Hyperv') { this.protocols = ['SMB'] } else if (this.hypervisorType === 'Ovm') { @@ -358,6 +362,15 @@ export default { } return url }, + datastoreclusterURL (server, path) { + var url + if (server.indexOf('://') === -1) { + url = 'datastorecluster://' + server + path + } else { + url = server + path + } + return url + }, ocfs2URL (server, path) { var url if (server.indexOf('://') === -1) { @@ -475,8 +488,22 @@ export default { Object.keys(smbParams).forEach((key, index) => { params['details[' + index.toString() + '].' + key] = smbParams[key] }) - } else if (values.protocol === 'PreSetup') { + } else if (values.protocol === 'PreSetup' && values.hypervisor !== 'VMware') { url = this.presetupURL(server, path) + } else if (values.protocol === 'PreSetup' && values.hypervisor === 'VMware') { + path = values.vCenterDataCenter + if (path.substring(0, 1) !== '/') { + path = '/' + path + } + path += '/' + values.vCenterDataStore + url = this.presetupURL(server, path) + } else if (values.protocol === 'datastorecluster' && values.hypervisor === 'VMware') { + path = values.vCenterDataCenter + if (path.substring(0, 1) !== '/') { + path = '/' + path + } + path += '/' + values.vCenterDataStore + url = this.datastoreclusterURL(server, path) } else if (values.protocol === 'ocfs2') { url = this.ocfs2URL(server, path) } else if (values.protocol === 'SharedMountPoint') { diff --git a/ui/src/views/offering/AddComputeOffering.vue b/ui/src/views/offering/AddComputeOffering.vue index 5de5205ddaf..80b7c41170d 100644 --- a/ui/src/views/offering/AddComputeOffering.vue +++ b/ui/src/views/offering/AddComputeOffering.vue @@ -688,6 +688,7 @@ :filterOption="(input, option) => { return option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0 }" + @select="val => fetchvSphereStoragePolicies(val)" :loading="zoneLoading" :placeholder="this.$t('label.zoneid')"> @@ -695,6 +696,21 @@ + + + {{ $t('label.vmware.storage.policy') }} + + + + + + + {{ policy.name || policy.id }} + + +
{{ this.$t('label.cancel') }} @@ -727,9 +743,11 @@ export default { domains: [], domainLoading: false, selectedZones: [], + selectedZoneIndex: [], zones: [], zoneLoading: false, selectedDeployementPlanner: null, + storagePolicies: null, storageTags: [], storageTagLoading: false, deploymentPlanners: [], @@ -760,7 +778,11 @@ export default { } }, beforeCreate () { - this.form = this.$form.createForm(this) + this.form = this.$form.createForm(this, { + onValuesChange: (_, values) => { + this.selectedZoneIndex = values.zoneid + } + }) this.apiParams = {} var apiConfig = this.$store.getters.apis.createServiceOffering || {} apiConfig.params.forEach(param => { @@ -848,6 +870,21 @@ export default { this.deploymentPlannerLoading = false }) }, + fetchvSphereStoragePolicies (zoneIndex) { + if (zoneIndex === 0 || this.selectedZoneIndex.length > 1) { + this.storagePolicies = null + return + } + const zoneid = this.zones[zoneIndex].id + if ('importVsphereStoragePolicies' in this.$store.getters.apis) { + this.storagePolicies = [] + api('listVsphereStoragePolicies', { + zoneid: zoneid + }).then(response => { + this.storagePolicies = response.listvspherestoragepoliciesresponse.StoragePolicy || [] + }) + } + }, handleStorageTypeChange (val) { this.storageType = val }, @@ -1016,6 +1053,9 @@ export default { if (zoneId) { params.zoneid = zoneId } + if (values.storagepolicy) { + params.storagepolicy = values.storagepolicy + } api('createServiceOffering', params).then(json => { const message = this.isSystem ? `${this.$t('message.create.service.offering')}: ` diff --git a/ui/src/views/offering/AddDiskOffering.vue b/ui/src/views/offering/AddDiskOffering.vue index 0a5ddaf86b8..a38fc57f980 100644 --- a/ui/src/views/offering/AddDiskOffering.vue +++ b/ui/src/views/offering/AddDiskOffering.vue @@ -398,6 +398,7 @@ :filterOption="(input, option) => { return option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0 }" + @select="val => fetchvSphereStoragePolicies(val)" :loading="zoneLoading" :placeholder="this.$t('label.zoneid')"> @@ -405,6 +406,21 @@ + + + {{ $t('label.vmware.storage.policy') }} + + + + + + + {{ policy.name || policy.id }} + + +
{{ this.$t('label.cancel') }} @@ -420,6 +436,10 @@ import { api } from '@/api' export default { name: 'AddDiskOffering', props: { + resource: { + type: Object, + required: true + } }, components: { }, @@ -432,8 +452,9 @@ export default { isCustomizedDiskIops: false, writeCacheType: 'none', selectedDomains: [], - selectedZones: [], + selectedZoneIndex: [], storageTags: [], + storagePolicies: null, storageTagLoading: false, isPublic: true, domains: [], @@ -444,7 +465,11 @@ export default { } }, beforeCreate () { - this.form = this.$form.createForm(this) + this.form = this.$form.createForm(this, { + onValuesChange: (_, values) => { + this.selectedZoneIndex = values.zoneid + } + }) this.apiParams = {} var apiConfig = this.$store.getters.apis.createDiskOffering || {} apiConfig.params.forEach(param => { @@ -518,6 +543,21 @@ export default { this.storageTagLoading = false }) }, + fetchvSphereStoragePolicies (zoneIndex) { + if (zoneIndex === 0 || this.selectedZoneIndex.length > 1) { + this.storagePolicies = null + return + } + const zoneid = this.zones[zoneIndex].id + if ('importVsphereStoragePolicies' in this.$store.getters.apis) { + this.storagePolicies = [] + api('listVsphereStoragePolicies', { + zoneid: zoneid + }).then(response => { + this.storagePolicies = response.listvspherestoragepoliciesresponse.StoragePolicy || [] + }) + } + }, handleStorageTypeChange (val) { this.storageType = val }, @@ -606,6 +646,9 @@ export default { if (zoneId) { params.zoneid = zoneId } + if (values.storagepolicy) { + params.storagepolicy = values.storagepolicy + } api('createDiskOffering', params).then(json => { this.$message.success(`${this.$t('message.disk.offering.created')} ${values.name}}`) }).catch(error => {