From 228ccff07b3e760ed835a8e85cc62e8c7fd99f18 Mon Sep 17 00:00:00 2001 From: xusongfu Date: Wed, 7 Dec 2022 15:55:44 +0800 Subject: [PATCH] fix: Improve quota in magnum service 1.Show quota info by template when create cluster if did not select flavor or master flavor 2.Remove link of keypair if the keypair is not belong to the current user Change-Id: Ic6faebfa21b92479b982770a00046a54882f21d8 --- .../ClusterTemplates/Detail/BaseDetail.jsx | 15 +++++----- .../actions/StepCreate/index.jsx | 4 +-- .../actions/StepCreate/StepInfo/index.jsx | 5 ++++ .../actions/StepCreate/StepNodeSpec/index.jsx | 20 +++++++++++-- .../Clusters/actions/StepCreate/index.jsx | 28 ++++++++++++++++--- src/resources/magnum/template.js | 9 +++--- src/stores/magnum/clusterTemplates.js | 21 ++++++++++++++ 7 files changed, 82 insertions(+), 20 deletions(-) diff --git a/src/pages/container-infra/containers/ClusterTemplates/Detail/BaseDetail.jsx b/src/pages/container-infra/containers/ClusterTemplates/Detail/BaseDetail.jsx index ee957cf8..898dfb60 100644 --- a/src/pages/container-infra/containers/ClusterTemplates/Detail/BaseDetail.jsx +++ b/src/pages/container-infra/containers/ClusterTemplates/Detail/BaseDetail.jsx @@ -132,7 +132,7 @@ export class BaseDetail extends Base { } get specCard() { - const { image_id, keypair_id, flavor_id, master_flavor_id } = + const { image_id, keypair_id, flavor_id, master_flavor_id, selfKeypair } = this.detailData; const imageUrl = image_id ? this.getLinkRender('imageDetail', image_id, { @@ -140,11 +140,12 @@ export class BaseDetail extends Base { }) : '-'; - const keypairUrl = keypair_id - ? this.getLinkRender('keypairDetail', keypair_id, { - id: keypair_id, - }) - : '-'; + const keypairUrl = + keypair_id && selfKeypair + ? this.getLinkRender('keypairDetail', keypair_id, { + id: keypair_id, + }) + : keypair_id || '-'; const flavorUrl = flavor_id ? this.getLinkRender('flavorDetail', flavor_id, { @@ -169,7 +170,7 @@ export class BaseDetail extends Base { hidden: this.isAdminPage, }, { - label: t('Flavor ID'), + label: t('Node Flavor ID'), content: flavorUrl, }, { diff --git a/src/pages/container-infra/containers/ClusterTemplates/actions/StepCreate/index.jsx b/src/pages/container-infra/containers/ClusterTemplates/actions/StepCreate/index.jsx index c9b8b5c9..5cf58a03 100644 --- a/src/pages/container-infra/containers/ClusterTemplates/actions/StepCreate/index.jsx +++ b/src/pages/container-infra/containers/ClusterTemplates/actions/StepCreate/index.jsx @@ -107,8 +107,8 @@ export class StepCreate extends StepAction { const requestLabels = {}; if (additionalLabels) { additionalLabels.forEach((item) => { - const labelKey = item.value.key.toLowerCase().trim(); - const labelValue = item.value.value.toLowerCase().trim(); + const labelKey = item.value.key; + const labelValue = item.value.value; requestLabels[labelKey] = labelValue; }); } diff --git a/src/pages/container-infra/containers/Clusters/actions/StepCreate/StepInfo/index.jsx b/src/pages/container-infra/containers/Clusters/actions/StepCreate/StepInfo/index.jsx index d517e832..70c53430 100644 --- a/src/pages/container-infra/containers/Clusters/actions/StepCreate/StepInfo/index.jsx +++ b/src/pages/container-infra/containers/Clusters/actions/StepCreate/StepInfo/index.jsx @@ -81,6 +81,11 @@ export class StepInfo extends Base { }, ], columns: getBaseTemplateColumns(this), + onChange: (value) => { + this.updateContext({ + clusterTemplate: value, + }); + }, }, ]; } 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 40549116..2573afc7 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 @@ -65,26 +65,40 @@ export class StepNodeSpec extends Base { }; get defaultValue() { + const { context: { clusterTemplate = {} } = {} } = this.props; + const { selectedRows = [] } = clusterTemplate; + const { master_flavor_id, flavor_id } = selectedRows[0] || {}; + return { master_count: 1, node_count: 1, + masterFlavor: { + selectedRowKeys: [master_flavor_id], + }, + flavor: { selectedRowKeys: [flavor_id] }, }; } get formItems() { const { context: { clusterTemplate = {} } = {} } = this.props; const { selectedRows = [] } = clusterTemplate; - const { master_flavor_id, flavor_id, keypair_id } = selectedRows[0] || {}; + const { master_flavor_id, flavor_id, keypair_id, selfKeypair } = + selectedRows[0] || {}; const { initKeyPair } = this.state; + const templateHasSelfKeypair = keypair_id && selfKeypair; + const templateInitKeypair = { + selectedRowKeys: [keypair_id], + }; return [ { name: 'keypair', label: t('Keypair'), type: 'select-table', - required: !keypair_id, + required: !templateHasSelfKeypair, data: this.keypairs, - initValue: initKeyPair, + initValue: + initKeyPair || (templateHasSelfKeypair && templateInitKeypair), isLoading: this.keyPairStore.list.isLoading, header: getKeyPairHeader(this), tip: t( 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 60c31615..590e27ea 100644 --- a/src/pages/container-infra/containers/Clusters/actions/StepCreate/index.jsx +++ b/src/pages/container-infra/containers/Clusters/actions/StepCreate/index.jsx @@ -15,6 +15,7 @@ import { toJS } from 'mobx'; import { StepAction } from 'src/containers/Action'; import globalClustersStore from 'src/stores/magnum/clusters'; import globalProjectStore from 'stores/keystone/project'; +import globalFlavorStore from 'stores/nova/flavor'; import { getGiBValue } from 'utils'; import { message as $message } from 'antd'; import StepInfo from './StepInfo'; @@ -85,6 +86,10 @@ export class StepCreate extends StepAction { return this.props.rootStore.checkEndpoint('cinder'); } + get flavors() { + return toJS(globalFlavorStore.list.data) || []; + } + get showQuota() { return true; } @@ -179,6 +184,20 @@ export class StepCreate extends StepAction { return ''; } + get templateFlavor() { + const { data = {} } = this.state; + const { clusterTemplate: { selectedRows = [] } = {} } = data; + const { master_flavor_id, flavor_id } = selectedRows[0] || {}; + const masterTemplateFlavor = this.flavors.find( + (it) => it.id === master_flavor_id + ); + const workTemplateFlavor = this.flavors.find((it) => it.id === flavor_id); + return { + masterTemplateFlavor, + workTemplateFlavor, + }; + } + getFlavorInput() { const { data = {} } = this.state; const { @@ -187,10 +206,11 @@ export class StepCreate extends StepAction { masterFlavor: { selectedRows: selectedRowsMaster = [] } = {}, master_count = 1, } = data; - const { vcpus = 0, ram = 0 } = selectedRows[0] || {}; + const { vcpus = 0, ram = 0 } = + selectedRows[0] || this.templateFlavor.workTemplateFlavor || {}; const ramGiB = getGiBValue(ram); const { vcpus: vcpusMaster = 0, ram: ramMaster = 0 } = - selectedRowsMaster[0] || {}; + selectedRowsMaster[0] || this.templateFlavor.masterTemplateFlavor || {}; const ramGiBMaster = getGiBValue(ramMaster); const newCPU = vcpus * node_count + vcpusMaster * master_count; const newRam = ramGiB * node_count + ramGiBMaster * master_count; @@ -262,8 +282,8 @@ export class StepCreate extends StepAction { if (additionalLabels) { additionalLabels.forEach((item) => { - const labelKey = item.value.key.toLowerCase().trim(); - const labelValue = item.value.value.toLowerCase().trim(); + const labelKey = item.value.key; + const labelValue = item.value.value; requestLabels[labelKey] = labelValue; }); } diff --git a/src/resources/magnum/template.js b/src/resources/magnum/template.js index c3460edc..60788d4d 100644 --- a/src/resources/magnum/template.js +++ b/src/resources/magnum/template.js @@ -33,10 +33,11 @@ export const getBaseTemplateColumns = (self) => [ isHideable: true, dataIndex: 'keypair_id', hidden: self.isAdminPage, - render: (value) => { - return value - ? self.getLinkRender('keypairDetail', value, { id: value }) - : '-'; + render: (value, row) => { + if (value && row.selfKeypair) { + return self.getLinkRender('keypairDetail', value, { id: value }); + } + return value || '-'; }, }, ]; diff --git a/src/stores/magnum/clusterTemplates.js b/src/stores/magnum/clusterTemplates.js index 3c49bb63..700923a8 100644 --- a/src/stores/magnum/clusterTemplates.js +++ b/src/stores/magnum/clusterTemplates.js @@ -61,6 +61,27 @@ export class ClusterTemplatesStore extends Base { id: data.uuid, }); } + + async listDidFetch(items) { + if (!items.length) return items; + const { keypairs = [] } = (await client.nova.keypairs.list()) || {}; + return items.map((it) => { + const keypair = keypairs.find((k) => k?.keypair?.name === it.keypair_id); + if (keypair) { + it.selfKeypair = true; + } + return it; + }); + } + + async detailDidFetch(item) { + const { keypairs = [] } = (await client.nova.keypairs.list()) || {}; + const keypair = keypairs.find((k) => k?.keypair?.name === item.keypair_id); + if (keypair) { + item.selfKeypair = true; + } + return item; + } } const globalClusterTemplateStore = new ClusterTemplatesStore();