Merge "fix: fix instance quota check when create instance"

This commit is contained in:
Zuul 2022-08-02 04:35:23 +00:00 committed by Gerrit Code Review
commit 7389707392

View File

@ -48,6 +48,7 @@ export class StepCreate extends StepAction {
init() { init() {
this.store = globalServerStore; this.store = globalServerStore;
this.projectStore = globalProjectStore; this.projectStore = globalProjectStore;
this.state.quotaLoading = true;
this.getQuota(); this.getQuota();
this.status = 'success'; this.status = 'success';
this.errorMsg = ''; this.errorMsg = '';
@ -64,10 +65,16 @@ export class StepCreate extends StepAction {
} }
async getQuota() { async getQuota() {
this.setState({
quotaLoading: true,
});
await Promise.all([ await Promise.all([
this.projectStore.fetchProjectNovaQuota(), this.projectStore.fetchProjectNovaQuota(),
this.projectStore.fetchProjectCinderQuota(), this.projectStore.fetchProjectCinderQuota(),
]); ]);
this.setState({
quotaLoading: false,
});
this.onCountChange(1); this.onCountChange(1);
} }
@ -160,20 +167,21 @@ export class StepCreate extends StepAction {
} }
get quotaInfo() { get quotaInfo() {
const { quotaLoading } = this.state;
if (quotaLoading) {
return [];
}
const { const {
instances = {}, instances = {},
cores = {}, cores = {},
ram = {}, ram = {},
} = toJS(this.projectStore.novaQuota) || {}; } = toJS(this.projectStore.novaQuota) || {};
const { limit } = instances || {};
if (!limit) {
return [];
}
const { data = {} } = this.state; const { data = {} } = this.state;
const { count = 1 } = data; const { count = 1 } = data;
const quotaError = this.checkQuotaInput();
const instanceQuotaInfo = { const instanceQuotaInfo = {
...instances, ...instances,
add: count, add: quotaError ? 0 : count,
name: 'instance', name: 'instance',
title: t('Instance'), title: t('Instance'),
// type: 'line', // type: 'line',
@ -182,7 +190,7 @@ export class StepCreate extends StepAction {
const { newCPU, newRam } = this.getFlavorInput(); const { newCPU, newRam } = this.getFlavorInput();
const cpuQuotaInfo = { const cpuQuotaInfo = {
...cores, ...cores,
add: newCPU, add: quotaError ? 0 : newCPU,
name: 'cpu', name: 'cpu',
title: t('CPU'), title: t('CPU'),
type: 'line', type: 'line',
@ -190,7 +198,7 @@ export class StepCreate extends StepAction {
const ramQuotaInfo = { const ramQuotaInfo = {
...ram, ...ram,
add: newRam, add: quotaError ? 0 : newRam,
name: 'ram', name: 'ram',
title: t('Memory (GiB)'), title: t('Memory (GiB)'),
type: 'line', type: 'line',
@ -200,14 +208,14 @@ export class StepCreate extends StepAction {
const { totalNewCount, totalNewSize } = this.getVolumeInputMap(); const { totalNewCount, totalNewSize } = this.getVolumeInputMap();
const volumeQuotaInfo = { const volumeQuotaInfo = {
...volumeQuota.volumes, ...volumeQuota.volumes,
add: totalNewCount, add: quotaError ? 0 : totalNewCount,
name: 'volume', name: 'volume',
title: t('Volume'), title: t('Volume'),
type: 'line', type: 'line',
}; };
const volumeSizeQuotaInfo = { const volumeSizeQuotaInfo = {
...volumeQuota.gigabytes, ...volumeQuota.gigabytes,
add: totalNewSize, add: quotaError ? 0 : totalNewSize,
name: 'volumeSize', name: 'volumeSize',
title: t('Volume Size'), title: t('Volume Size'),
type: 'line', type: 'line',
@ -221,7 +229,12 @@ export class StepCreate extends StepAction {
volumeSizeQuotaInfo, volumeSizeQuotaInfo,
]; ];
if (serverGroupQuota) { if (serverGroupQuota) {
quotaInfo.push(serverGroupQuota); const { add, ...rest } = serverGroupQuota;
const quota = {
...rest,
add: quotaError ? 0 : add,
};
quotaInfo.push(quota);
} }
return quotaInfo; return quotaInfo;
} }
@ -447,24 +460,45 @@ export class StepCreate extends StepAction {
return { marginTop: 8, marginBottom: 8, marginLeft: 10, maxWidth: 600 }; return { marginTop: 8, marginBottom: 8, marginLeft: 10, maxWidth: 600 };
} }
renderBadge() { checkInstanceQuota() {
const { quotaLoading } = this.state;
if (quotaLoading) {
return '';
}
const { instances = {} } = this.projectStore.novaQuota || {};
if (this.instanceQuota === 0) {
return this.getQuotaMessage(1, instances, t('Instance'));
}
return '';
}
checkQuotaInput() {
const instanceMsg = this.checkInstanceQuota();
const flavorMsg = this.checkFlavorQuota(); const flavorMsg = this.checkFlavorQuota();
const volumeMsg = this.checkVolumeQuota(); const volumeMsg = this.checkVolumeQuota();
const serverGroupMsg = this.checkSeverGroupQuota(); const serverGroupMsg = this.checkSeverGroupQuota();
if (!flavorMsg && !volumeMsg && !serverGroupMsg) { const error = instanceMsg || flavorMsg || volumeMsg || serverGroupMsg;
if (!error) {
this.status = 'success'; this.status = 'success';
this.errorMsg = ''; this.errorMsg = '';
return null; return '';
} }
this.status = 'error'; this.status = 'error';
const msg = flavorMsg || volumeMsg || serverGroupMsg; if (this.errorMsg !== error) {
if (this.errorMsg !== msg) { $message.error(error);
$message.error(msg); }
this.errorMsg = error;
return error;
}
renderBadge() {
const error = this.checkQuotaInput();
if (this.status === 'success') {
return null;
} }
this.errorMsg = msg;
return ( return (
<div style={this.badgeStyle}> <div style={this.badgeStyle}>
<Badge status="error" text={msg} /> <Badge status="error" text={error} />
</div> </div>
); );
} }