Merge "feat: support quota when create trove instance"
This commit is contained in:
commit
0db91b1e55
@ -122,7 +122,7 @@ export class StepDetails extends Base {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'size',
|
name: 'size',
|
||||||
label: t('Size (GiB)'),
|
label: t('Database Disk (GiB)'),
|
||||||
type: 'input-int',
|
type: 'input-int',
|
||||||
min: 1,
|
min: 1,
|
||||||
placeholder: t('Size'),
|
placeholder: t('Size'),
|
||||||
|
@ -15,6 +15,8 @@
|
|||||||
import { StepAction } from 'containers/Action';
|
import { StepAction } from 'containers/Action';
|
||||||
import { inject, observer } from 'mobx-react';
|
import { inject, observer } from 'mobx-react';
|
||||||
import globalInstancesStore from 'stores/trove/instances';
|
import globalInstancesStore from 'stores/trove/instances';
|
||||||
|
import globalProjectStore from 'stores/keystone/project';
|
||||||
|
import { message as $message } from 'antd';
|
||||||
import StepDetails from './StepDetails';
|
import StepDetails from './StepDetails';
|
||||||
import StepNetworking from './StepNetworking';
|
import StepNetworking from './StepNetworking';
|
||||||
import StepInitializeDatabases from './StepInitializeDatabases';
|
import StepInitializeDatabases from './StepInitializeDatabases';
|
||||||
@ -23,6 +25,10 @@ import StepAdvanced from './StepAdvanced';
|
|||||||
export class StepCreate extends StepAction {
|
export class StepCreate extends StepAction {
|
||||||
init() {
|
init() {
|
||||||
this.store = globalInstancesStore;
|
this.store = globalInstancesStore;
|
||||||
|
this.projectStore = globalProjectStore;
|
||||||
|
this.getQuota();
|
||||||
|
this.state.isLoading = true;
|
||||||
|
this.errorMsg = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
static id = 'create-database-instance';
|
static id = 'create-database-instance';
|
||||||
@ -70,6 +76,102 @@ export class StepCreate extends StepAction {
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get showQuota() {
|
||||||
|
return this.props.rootStore.hasAdminOnlyRole;
|
||||||
|
}
|
||||||
|
|
||||||
|
async getQuota() {
|
||||||
|
if (this.showQuota) {
|
||||||
|
await this.projectStore.fetchProjectTroveQuota(this.currentProjectId);
|
||||||
|
this.setState({
|
||||||
|
isLoading: false,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
get quotaInfo() {
|
||||||
|
if (this.state.isLoading) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
const { instances = {}, volumes = {} } = this.projectStore.troveQuota || {};
|
||||||
|
|
||||||
|
const { left = 0 } = instances || {};
|
||||||
|
const { data: { size = 0 } = {} } = this.state;
|
||||||
|
const instanceQuotaInfo = {
|
||||||
|
...instances,
|
||||||
|
add: left ? 1 : 0,
|
||||||
|
name: 'instance',
|
||||||
|
title: t('Database Instance'),
|
||||||
|
};
|
||||||
|
|
||||||
|
const { left: volumeLeft = 0 } = volumes;
|
||||||
|
const volumeSizeQuotaInfo = {
|
||||||
|
...volumes,
|
||||||
|
add: volumeLeft === -1 || size <= volumeLeft ? size : 0,
|
||||||
|
name: 'volumeSize',
|
||||||
|
title: t('Database Disk (GiB)'),
|
||||||
|
type: 'line',
|
||||||
|
};
|
||||||
|
|
||||||
|
this.checkQuota(this.state.data, this.projectStore.troveQuota);
|
||||||
|
return [instanceQuotaInfo, volumeSizeQuotaInfo];
|
||||||
|
}
|
||||||
|
|
||||||
|
getQuotaMessage(input, left, name) {
|
||||||
|
if (left === -1) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
if (left === 0) {
|
||||||
|
return t('Quota: Insufficient { name } quota to create resources.', {
|
||||||
|
name,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (input > left) {
|
||||||
|
return t(
|
||||||
|
'Insufficient {name} quota to create resources(left { quota }, input { input }).',
|
||||||
|
{ name, quota: left, input }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
checkQuota(data, quota) {
|
||||||
|
const {
|
||||||
|
instances: { left: instanceLeft = 0 } = {},
|
||||||
|
volumes: { left: volumeLeft = 0 } = {},
|
||||||
|
} = quota || {};
|
||||||
|
const { size = 0 } = data || {};
|
||||||
|
|
||||||
|
const instanceMsg = this.getQuotaMessage(
|
||||||
|
1,
|
||||||
|
instanceLeft,
|
||||||
|
t('Database Instance')
|
||||||
|
);
|
||||||
|
const sizeMsg = this.getQuotaMessage(
|
||||||
|
size,
|
||||||
|
volumeLeft,
|
||||||
|
t('Database Disk (GiB)')
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!instanceMsg && !sizeMsg) {
|
||||||
|
this.errorMsg = '';
|
||||||
|
} else {
|
||||||
|
const msg = instanceMsg || sizeMsg;
|
||||||
|
if (this.errorMsg !== msg) {
|
||||||
|
$message.error(msg);
|
||||||
|
}
|
||||||
|
this.errorMsg = msg;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
get disableNext() {
|
||||||
|
return !!this.errorMsg;
|
||||||
|
}
|
||||||
|
|
||||||
|
get disableSubmit() {
|
||||||
|
return !!this.errorMsg;
|
||||||
|
}
|
||||||
|
|
||||||
onSubmit = (values) => {
|
onSubmit = (values) => {
|
||||||
let network = [];
|
let network = [];
|
||||||
|
|
||||||
|
@ -101,7 +101,7 @@ export class Instances extends Base {
|
|||||||
isHideable: true,
|
isHideable: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: t('Volume Capacity (GiB)'),
|
title: t('Database Disk (GiB)'),
|
||||||
dataIndex: 'size',
|
dataIndex: 'size',
|
||||||
isHideable: true,
|
isHideable: true,
|
||||||
render: (value) => (value ? `${value}GiB` : '-'),
|
render: (value) => (value ? `${value}GiB` : '-'),
|
||||||
|
Loading…
Reference in New Issue
Block a user