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
This commit is contained in:
xusongfu 2022-12-07 15:55:44 +08:00
parent a2d170e285
commit 228ccff07b
7 changed files with 82 additions and 20 deletions

View File

@ -132,7 +132,7 @@ export class BaseDetail extends Base {
} }
get specCard() { 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; this.detailData;
const imageUrl = image_id const imageUrl = image_id
? this.getLinkRender('imageDetail', image_id, { ? this.getLinkRender('imageDetail', image_id, {
@ -140,11 +140,12 @@ export class BaseDetail extends Base {
}) })
: '-'; : '-';
const keypairUrl = keypair_id const keypairUrl =
? this.getLinkRender('keypairDetail', keypair_id, { keypair_id && selfKeypair
id: keypair_id, ? this.getLinkRender('keypairDetail', keypair_id, {
}) id: keypair_id,
: '-'; })
: keypair_id || '-';
const flavorUrl = flavor_id const flavorUrl = flavor_id
? this.getLinkRender('flavorDetail', flavor_id, { ? this.getLinkRender('flavorDetail', flavor_id, {
@ -169,7 +170,7 @@ export class BaseDetail extends Base {
hidden: this.isAdminPage, hidden: this.isAdminPage,
}, },
{ {
label: t('Flavor ID'), label: t('Node Flavor ID'),
content: flavorUrl, content: flavorUrl,
}, },
{ {

View File

@ -107,8 +107,8 @@ export class StepCreate extends StepAction {
const requestLabels = {}; const requestLabels = {};
if (additionalLabels) { if (additionalLabels) {
additionalLabels.forEach((item) => { additionalLabels.forEach((item) => {
const labelKey = item.value.key.toLowerCase().trim(); const labelKey = item.value.key;
const labelValue = item.value.value.toLowerCase().trim(); const labelValue = item.value.value;
requestLabels[labelKey] = labelValue; requestLabels[labelKey] = labelValue;
}); });
} }

View File

@ -81,6 +81,11 @@ export class StepInfo extends Base {
}, },
], ],
columns: getBaseTemplateColumns(this), columns: getBaseTemplateColumns(this),
onChange: (value) => {
this.updateContext({
clusterTemplate: value,
});
},
}, },
]; ];
} }

View File

@ -65,26 +65,40 @@ export class StepNodeSpec extends Base {
}; };
get defaultValue() { get defaultValue() {
const { context: { clusterTemplate = {} } = {} } = this.props;
const { selectedRows = [] } = clusterTemplate;
const { master_flavor_id, flavor_id } = selectedRows[0] || {};
return { return {
master_count: 1, master_count: 1,
node_count: 1, node_count: 1,
masterFlavor: {
selectedRowKeys: [master_flavor_id],
},
flavor: { selectedRowKeys: [flavor_id] },
}; };
} }
get formItems() { get formItems() {
const { context: { clusterTemplate = {} } = {} } = this.props; const { context: { clusterTemplate = {} } = {} } = this.props;
const { selectedRows = [] } = clusterTemplate; 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 { initKeyPair } = this.state;
const templateHasSelfKeypair = keypair_id && selfKeypair;
const templateInitKeypair = {
selectedRowKeys: [keypair_id],
};
return [ return [
{ {
name: 'keypair', name: 'keypair',
label: t('Keypair'), label: t('Keypair'),
type: 'select-table', type: 'select-table',
required: !keypair_id, required: !templateHasSelfKeypair,
data: this.keypairs, data: this.keypairs,
initValue: initKeyPair, initValue:
initKeyPair || (templateHasSelfKeypair && templateInitKeypair),
isLoading: this.keyPairStore.list.isLoading, isLoading: this.keyPairStore.list.isLoading,
header: getKeyPairHeader(this), header: getKeyPairHeader(this),
tip: t( tip: t(

View File

@ -15,6 +15,7 @@ import { toJS } from 'mobx';
import { StepAction } from 'src/containers/Action'; import { StepAction } from 'src/containers/Action';
import globalClustersStore from 'src/stores/magnum/clusters'; import globalClustersStore from 'src/stores/magnum/clusters';
import globalProjectStore from 'stores/keystone/project'; import globalProjectStore from 'stores/keystone/project';
import globalFlavorStore from 'stores/nova/flavor';
import { getGiBValue } from 'utils'; import { getGiBValue } from 'utils';
import { message as $message } from 'antd'; import { message as $message } from 'antd';
import StepInfo from './StepInfo'; import StepInfo from './StepInfo';
@ -85,6 +86,10 @@ export class StepCreate extends StepAction {
return this.props.rootStore.checkEndpoint('cinder'); return this.props.rootStore.checkEndpoint('cinder');
} }
get flavors() {
return toJS(globalFlavorStore.list.data) || [];
}
get showQuota() { get showQuota() {
return true; return true;
} }
@ -179,6 +184,20 @@ export class StepCreate extends StepAction {
return ''; 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() { getFlavorInput() {
const { data = {} } = this.state; const { data = {} } = this.state;
const { const {
@ -187,10 +206,11 @@ export class StepCreate extends StepAction {
masterFlavor: { selectedRows: selectedRowsMaster = [] } = {}, masterFlavor: { selectedRows: selectedRowsMaster = [] } = {},
master_count = 1, master_count = 1,
} = data; } = data;
const { vcpus = 0, ram = 0 } = selectedRows[0] || {}; const { vcpus = 0, ram = 0 } =
selectedRows[0] || this.templateFlavor.workTemplateFlavor || {};
const ramGiB = getGiBValue(ram); const ramGiB = getGiBValue(ram);
const { vcpus: vcpusMaster = 0, ram: ramMaster = 0 } = const { vcpus: vcpusMaster = 0, ram: ramMaster = 0 } =
selectedRowsMaster[0] || {}; selectedRowsMaster[0] || this.templateFlavor.masterTemplateFlavor || {};
const ramGiBMaster = getGiBValue(ramMaster); const ramGiBMaster = getGiBValue(ramMaster);
const newCPU = vcpus * node_count + vcpusMaster * master_count; const newCPU = vcpus * node_count + vcpusMaster * master_count;
const newRam = ramGiB * node_count + ramGiBMaster * master_count; const newRam = ramGiB * node_count + ramGiBMaster * master_count;
@ -262,8 +282,8 @@ export class StepCreate extends StepAction {
if (additionalLabels) { if (additionalLabels) {
additionalLabels.forEach((item) => { additionalLabels.forEach((item) => {
const labelKey = item.value.key.toLowerCase().trim(); const labelKey = item.value.key;
const labelValue = item.value.value.toLowerCase().trim(); const labelValue = item.value.value;
requestLabels[labelKey] = labelValue; requestLabels[labelKey] = labelValue;
}); });
} }

View File

@ -33,10 +33,11 @@ export const getBaseTemplateColumns = (self) => [
isHideable: true, isHideable: true,
dataIndex: 'keypair_id', dataIndex: 'keypair_id',
hidden: self.isAdminPage, hidden: self.isAdminPage,
render: (value) => { render: (value, row) => {
return value if (value && row.selfKeypair) {
? self.getLinkRender('keypairDetail', value, { id: value }) return self.getLinkRender('keypairDetail', value, { id: value });
: '-'; }
return value || '-';
}, },
}, },
]; ];

View File

@ -61,6 +61,27 @@ export class ClusterTemplatesStore extends Base {
id: data.uuid, 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(); const globalClusterTemplateStore = new ClusterTemplatesStore();