From e03182b072507dfa74182c04ddbd20198af58591 Mon Sep 17 00:00:00 2001 From: xusongfu Date: Tue, 20 Dec 2022 16:04:38 +0800 Subject: [PATCH] fix: fix the magnum quotai and other infos 1. support volume quota when create cluster instance 2. fix subnet reseting when fixed network changed 3. show project id of cluster template if switch to administrator platform Closes-Bug: #2000141 Change-Id: I6cb59e9f74c76cb3d0901e89c9bf01d48a85d747 --- .../ClusterTemplates/Detail/index.jsx | 5 ++ .../actions/StepCreate/StepNetwork/index.jsx | 32 ++++++-- .../containers/ClusterTemplates/index.jsx | 7 ++ .../actions/StepCreate/StepNetworks/index.jsx | 5 ++ .../actions/StepCreate/StepNodeSpec/index.jsx | 13 +++- .../Clusters/actions/StepCreate/index.jsx | 74 ++++++++++++------- src/resources/magnum/template.js | 6 ++ src/stores/magnum/clusterTemplates.js | 8 +- 8 files changed, 111 insertions(+), 39 deletions(-) diff --git a/src/pages/container-infra/containers/ClusterTemplates/Detail/index.jsx b/src/pages/container-infra/containers/ClusterTemplates/Detail/index.jsx index 50b92d15..cc76e933 100644 --- a/src/pages/container-infra/containers/ClusterTemplates/Detail/index.jsx +++ b/src/pages/container-infra/containers/ClusterTemplates/Detail/index.jsx @@ -56,6 +56,11 @@ export class ClusterTemplateDetail extends Base { dataIndex: 'updated_at', valueRender: 'toLocalTime', }, + { + title: t('Project ID'), + dataIndex: 'project_id', + hidden: !this.isAdminPage, + }, ]; } diff --git a/src/pages/container-infra/containers/ClusterTemplates/actions/StepCreate/StepNetwork/index.jsx b/src/pages/container-infra/containers/ClusterTemplates/actions/StepCreate/StepNetwork/index.jsx index 382e14fa..b7953a8c 100644 --- a/src/pages/container-infra/containers/ClusterTemplates/actions/StepCreate/StepNetwork/index.jsx +++ b/src/pages/container-infra/containers/ClusterTemplates/actions/StepCreate/StepNetwork/index.jsx @@ -96,6 +96,10 @@ export class StepNetwork extends Base { master_lb_enabled, floating_ip_enabled, } = {}, + context: { + fixedNetwork: fixedNetworkContext, + fixedSubnet: fixedSubnetContext, + }, } = this.props; values = { network_driver, @@ -111,13 +115,13 @@ export class StepNetwork extends Base { floating_ip_enabled, }; if (fixed_network) { - values.fixedNetwork = { + values.fixedNetwork = fixedNetworkContext || { selectedRowKeys: [fixed_network], selectedRows: [fixedNetwork], }; } if (fixed_subnet) { - values.fixedSubnet = { + values.fixedSubnet = fixedSubnetContext || { selectedRowKeys: [fixed_subnet], selectedRows: [fixedSubnet], }; @@ -128,7 +132,15 @@ export class StepNetwork extends Base { } get formItems() { - const { extra: { network_driver } = {} } = this.props; + const { + extra: { network_driver, fixed_subnet, fixedSubnet } = {}, + context: { fixedSubnet: fixedSubnetContext }, + } = this.props; + + const initSubnet = fixedSubnetContext || { + selectedRowKeys: fixed_subnet ? [fixed_subnet] : [], + selectedRows: fixedSubnet ? [fixedSubnet] : [], + }; return [ { @@ -204,10 +216,10 @@ export class StepNetwork extends Base { onChange: (value) => { this.updateContext({ fixedNetwork: value, - }); - this.updateFormValue('fixedSubnet', { - selectedRowKeys: [], - selectedRows: [], + fixedSubnet: { + selectedRowKeys: [], + selectedRows: [], + }, }); }, }, @@ -223,6 +235,12 @@ export class StepNetwork extends Base { }, ], columns: subnetColumns, + initValue: initSubnet, + onChange: (value) => { + this.updateContext({ + fixedSubnet: value, + }); + }, }, { name: 'dns_nameserver', diff --git a/src/pages/container-infra/containers/ClusterTemplates/index.jsx b/src/pages/container-infra/containers/ClusterTemplates/index.jsx index 1ade66ec..23045444 100644 --- a/src/pages/container-infra/containers/ClusterTemplates/index.jsx +++ b/src/pages/container-infra/containers/ClusterTemplates/index.jsx @@ -33,6 +33,13 @@ export class ClusterTemplates extends Base { return false; } + updateFetchParams = (params) => { + return { + ...params, + shouldFetchProject: this.isAdminPage, + }; + }; + get actionConfigs() { if (this.isAdminPage) { return actionConfigs.actionConfigsAdmin; diff --git a/src/pages/container-infra/containers/Clusters/actions/StepCreate/StepNetworks/index.jsx b/src/pages/container-infra/containers/Clusters/actions/StepCreate/StepNetworks/index.jsx index da56bb11..5ab60e99 100644 --- a/src/pages/container-infra/containers/Clusters/actions/StepCreate/StepNetworks/index.jsx +++ b/src/pages/container-infra/containers/Clusters/actions/StepCreate/StepNetworks/index.jsx @@ -185,6 +185,11 @@ export class StepNetworks extends Base { }, ], columns: subnetColumns, + onChange: (value) => { + this.updateContext({ + fixedSubnet: value, + }); + }, initValue: initSubnet, }, { diff --git a/src/pages/container-infra/containers/Clusters/actions/StepCreate/StepNodeSpec/index.jsx b/src/pages/container-infra/containers/Clusters/actions/StepCreate/StepNodeSpec/index.jsx index aab20223..3036aeac 100644 --- a/src/pages/container-infra/containers/Clusters/actions/StepCreate/StepNodeSpec/index.jsx +++ b/src/pages/container-infra/containers/Clusters/actions/StepCreate/StepNodeSpec/index.jsx @@ -74,15 +74,22 @@ export class StepNodeSpec extends Base { get defaultValue() { const { - context: { clusterTemplate = {}, keypair, masterFlavor, flavor } = {}, + context: { + clusterTemplate = {}, + keypair, + masterFlavor, + flavor, + master_count, + node_count, + } = {}, } = this.props; const { selectedRows = [] } = clusterTemplate; const { master_flavor_id, flavor_id, keypair_id, selfKeypair } = selectedRows[0] || {}; return { - master_count: 1, - node_count: 1, + master_count: master_count || 1, + node_count: node_count || 1, masterFlavor: masterFlavor || { selectedRowKeys: master_flavor_id ? [master_flavor_id] : [], selectedRows: this.masterFlavors.filter( diff --git a/src/pages/container-infra/containers/Clusters/actions/StepCreate/index.jsx b/src/pages/container-infra/containers/Clusters/actions/StepCreate/index.jsx index 85543260..d0a9cc27 100644 --- a/src/pages/container-infra/containers/Clusters/actions/StepCreate/index.jsx +++ b/src/pages/container-infra/containers/Clusters/actions/StepCreate/index.jsx @@ -131,6 +131,7 @@ export class StepCreate extends StepAction { title: t('Clusters'), }; + const { newNodes } = this.getNodesInput(); const { instances = {}, cores = {}, @@ -138,7 +139,7 @@ export class StepCreate extends StepAction { } = toJS(this.projectStore.novaQuota) || {}; const instanceQuotaInfo = { ...instances, - add: quotaError ? 0 : 1, + add: quotaError ? 0 : newNodes, name: 'instance', title: t('Instance'), type: 'line', @@ -161,11 +162,21 @@ export class StepCreate extends StepAction { type: 'line', }; + const { volumes } = toJS(this.projectStore.cinderQuota) || {}; + const volumeQuotaInfo = { + ...volumes, + add: quotaError ? 0 : newNodes, + name: 'volume', + title: t('Volume'), + type: 'line', + }; + const quotaInfo = [ clusterQuotaInfo, instanceQuotaInfo, cpuQuotaInfo, ramQuotaInfo, + volumeQuotaInfo, ]; return quotaInfo; @@ -184,15 +195,25 @@ export class StepCreate extends StepAction { return ''; } + getNodesInput() { + const { data = {} } = this.state; + const { node_count = 0, master_count = 0 } = data; + const newNodes = node_count + master_count; + return { + newNodes, + }; + } + checkInstanceQuota() { const { quotaLoading } = this.state; if (quotaLoading) { return ''; } + const { newNodes } = this.getNodesInput(); const { instances = {} } = this.projectStore.novaQuota || {}; const { left = 0 } = instances; - if (left === 0) { - return this.getQuotaMessage(1, instances, t('Instance')); + if (left !== -1 && left < newNodes) { + return this.getQuotaMessage(newNodes, instances, t('Instance')); } return ''; } @@ -247,11 +268,26 @@ export class StepCreate extends StepAction { return ''; } + checkVolumeQuota() { + const { quotaLoading } = this.state; + if (quotaLoading) { + return ''; + } + const { newNodes } = this.getNodesInput(); + const { volumes } = toJS(this.projectStore.cinderQuota) || {}; + const { left = 0 } = volumes; + if (left !== -1 && left < newNodes) { + return this.getQuotaMessage(newNodes, volumes, t('Volume')); + } + return ''; + } + checkQuotaInput() { const clusterMsg = this.checkClusterQuota(); const instanceMsg = this.checkInstanceQuota(); const flavorMsg = this.checkFlavorQuota(); - const error = clusterMsg || instanceMsg || flavorMsg; + const volumeMsg = this.checkVolumeQuota(); + const error = clusterMsg || instanceMsg || flavorMsg || volumeMsg; if (!error) { this.status = 'success'; this.errorMsg = ''; @@ -304,6 +340,7 @@ export class StepCreate extends StepAction { } const data = { + ...rest, name: values.name, labels: { ...requestLabels, @@ -311,31 +348,14 @@ export class StepCreate extends StepAction { auto_scaling_enabled: `${!!auto_scaling_enabled}`, }, cluster_template_id: clusterTemplate.selectedRowKeys[0], - ...rest, + keypair: (keypair && keypair.selectedRowKeys[0]) || null, + master_flavor_id: + (masterFlavor && masterFlavor.selectedRowKeys[0]) || null, + flavor_id: (flavor && flavor.selectedRowKeys[0]) || null, + fixed_network: (!newNetwork && fixedNetwork.selectedRowKeys[0]) || null, + fixed_subnet: (!newNetwork && fixedSubnet.selectedRowKeys[0]) || null, }; - if (keypair) { - data.keypair = keypair.selectedRowKeys[0]; - } - - if (masterFlavor) { - data.master_flavor_id = masterFlavor.selectedRowKeys[0]; - } - - if (flavor) { - data.flavor_id = flavor.selectedRowKeys[0]; - } - - if (!newNetwork && fixedNetwork) { - const { selectedRowKeys = [] } = fixedNetwork; - data.fixed_network = selectedRowKeys[0]; - } - - if (!newNetwork && fixedSubnet) { - const { selectedRowKeys = [] } = fixedSubnet; - data.fixed_subnet = selectedRowKeys[0]; - } - return this.store.create(data); }; } diff --git a/src/resources/magnum/template.js b/src/resources/magnum/template.js index d63d629c..2e02c0ee 100644 --- a/src/resources/magnum/template.js +++ b/src/resources/magnum/template.js @@ -51,6 +51,12 @@ export const getBaseSimpleFlavorColumns = (self) => [ dataIndex: 'name', routeName: self ? self.getRouteName('flavorDetail') : '', }, + { + title: t('Project ID/Name'), + dataIndex: 'project_name', + isHideable: true, + hidden: !self.isAdminPage, + }, { title: t('Architecture'), dataIndex: 'architecture', diff --git a/src/stores/magnum/clusterTemplates.js b/src/stores/magnum/clusterTemplates.js index 08487631..b61063fc 100644 --- a/src/stores/magnum/clusterTemplates.js +++ b/src/stores/magnum/clusterTemplates.js @@ -78,10 +78,14 @@ export class ClusterTemplatesStore extends Base { }); } - async listDidFetch(items) { + async listDidFetch(items, _, filters) { if (!items.length) return items; + const { shouldFetchProject } = filters; + const newData = await this.listDidFetchProject(items, { + all_projects: shouldFetchProject, + }); const { keypairs = [] } = (await client.nova.keypairs.list()) || {}; - return items.map((it) => { + return newData.map((it) => { const keypair = keypairs.find((k) => k?.keypair?.name === it.keypair_id); if (keypair) { it.selfKeypair = true;