Merge "feat: support server group quota check when create instance"
This commit is contained in:
commit
ac0139473b
@ -29,6 +29,7 @@ import { physicalNodeTypes } from 'resources/nova/instance';
|
|||||||
import { getOptions } from 'utils';
|
import { getOptions } from 'utils';
|
||||||
import CreateKeyPair from 'pages/compute/containers/Keypair/actions/Create';
|
import CreateKeyPair from 'pages/compute/containers/Keypair/actions/Create';
|
||||||
import ItemActionButtons from 'components/Tables/Base/ItemActionButtons';
|
import ItemActionButtons from 'components/Tables/Base/ItemActionButtons';
|
||||||
|
import { has } from 'lodash';
|
||||||
import styles from '../index.less';
|
import styles from '../index.less';
|
||||||
|
|
||||||
export class SystemStep extends Base {
|
export class SystemStep extends Base {
|
||||||
@ -85,15 +86,10 @@ export class SystemStep extends Base {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get serverGroups() {
|
get serverGroups() {
|
||||||
return (this.serverGroupStore.list.data || [])
|
return (this.serverGroupStore.list.data || []).filter((it) => {
|
||||||
.filter((it) => {
|
const { servergroup } = this.locationParams;
|
||||||
const { servergroup } = this.locationParams;
|
return servergroup ? it.id === servergroup : true;
|
||||||
return servergroup ? it.id === servergroup : true;
|
});
|
||||||
})
|
|
||||||
.map((it) => ({
|
|
||||||
...it,
|
|
||||||
key: it.id,
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get serverGroupRequired() {
|
get serverGroupRequired() {
|
||||||
@ -198,6 +194,10 @@ export class SystemStep extends Base {
|
|||||||
async getServerGroups() {
|
async getServerGroups() {
|
||||||
await this.serverGroupStore.fetchList();
|
await this.serverGroupStore.fetchList();
|
||||||
this.updateDefaultValue();
|
this.updateDefaultValue();
|
||||||
|
const { servergroup } = this.locationParams;
|
||||||
|
if (servergroup) {
|
||||||
|
this.onServerGroupChange({ selectedRows: this.serverGroups });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
get nameForStateUpdate() {
|
get nameForStateUpdate() {
|
||||||
@ -208,6 +208,7 @@ export class SystemStep extends Base {
|
|||||||
'confirmPassword',
|
'confirmPassword',
|
||||||
'more',
|
'more',
|
||||||
'physicalNodeType',
|
'physicalNodeType',
|
||||||
|
'serverGroup',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -235,6 +236,19 @@ export class SystemStep extends Base {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
onValuesChange = (changedFields) => {
|
||||||
|
if (has(changedFields, 'serverGroup')) {
|
||||||
|
this.onServerGroupChange(changedFields.serverGroup);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
onServerGroupChange = (value) => {
|
||||||
|
const { selectedRows = [] } = value || {};
|
||||||
|
this.updateContext({
|
||||||
|
serverGroupRow: selectedRows[0] || null,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
getKeyPairHeader() {
|
getKeyPairHeader() {
|
||||||
const { isLoading } = this.keyPairStore.list || {};
|
const { isLoading } = this.keyPairStore.list || {};
|
||||||
if (isLoading) {
|
if (isLoading) {
|
||||||
@ -377,6 +391,7 @@ export class SystemStep extends Base {
|
|||||||
data: this.serverGroups,
|
data: this.serverGroups,
|
||||||
isLoading: this.serverGroupStore.list.isLoading,
|
isLoading: this.serverGroupStore.list.isLoading,
|
||||||
required: this.serverGroupRequired,
|
required: this.serverGroupRequired,
|
||||||
|
// onChange: this.onServerGroupChange,
|
||||||
extra: t(
|
extra: t(
|
||||||
'Using server groups, you can create cloud hosts on the same/different physical nodes as much as possible to meet the affinity/non-affinity requirements of business applications.'
|
'Using server groups, you can create cloud hosts on the same/different physical nodes as much as possible to meet the affinity/non-affinity requirements of business applications.'
|
||||||
),
|
),
|
||||||
|
@ -212,13 +212,18 @@ export class StepCreate extends StepAction {
|
|||||||
title: t('Volume Size'),
|
title: t('Volume Size'),
|
||||||
type: 'line',
|
type: 'line',
|
||||||
};
|
};
|
||||||
return [
|
const serverGroupQuota = this.getServerGroupQuota();
|
||||||
|
const quotaInfo = [
|
||||||
instanceQuotaInfo,
|
instanceQuotaInfo,
|
||||||
cpuQuotaInfo,
|
cpuQuotaInfo,
|
||||||
ramQuotaInfo,
|
ramQuotaInfo,
|
||||||
volumeQuotaInfo,
|
volumeQuotaInfo,
|
||||||
volumeSizeQuotaInfo,
|
volumeSizeQuotaInfo,
|
||||||
];
|
];
|
||||||
|
if (serverGroupQuota) {
|
||||||
|
quotaInfo.push(serverGroupQuota);
|
||||||
|
}
|
||||||
|
return quotaInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
get errorText() {
|
get errorText() {
|
||||||
@ -404,6 +409,40 @@ export class StepCreate extends StepAction {
|
|||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getServerGroupQuota() {
|
||||||
|
const { data } = this.state;
|
||||||
|
const { serverGroupRow, count = 1 } = data;
|
||||||
|
if (!serverGroupRow) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
const { server_group_members: { limit = 0 } = {} } =
|
||||||
|
this.projectStore.novaQuota;
|
||||||
|
const { members = [] } = serverGroupRow || {};
|
||||||
|
const used = members.length;
|
||||||
|
const left = limit === -1 ? -1 : limit - used;
|
||||||
|
return {
|
||||||
|
add: count,
|
||||||
|
used,
|
||||||
|
limit,
|
||||||
|
left,
|
||||||
|
title: t('Server Group Member'),
|
||||||
|
name: 'serverGroupMember',
|
||||||
|
type: 'line',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
checkSeverGroupQuota() {
|
||||||
|
const quota = this.getServerGroupQuota();
|
||||||
|
if (!quota) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
const { add, left } = quota || {};
|
||||||
|
if (left !== -1 && left < add) {
|
||||||
|
return this.getQuotaMessage(add, quota, t('Server Group Member'));
|
||||||
|
}
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
get badgeStyle() {
|
get badgeStyle() {
|
||||||
return { marginTop: 8, marginBottom: 8, marginLeft: 10, maxWidth: 600 };
|
return { marginTop: 8, marginBottom: 8, marginLeft: 10, maxWidth: 600 };
|
||||||
}
|
}
|
||||||
@ -411,13 +450,14 @@ export class StepCreate extends StepAction {
|
|||||||
renderBadge() {
|
renderBadge() {
|
||||||
const flavorMsg = this.checkFlavorQuota();
|
const flavorMsg = this.checkFlavorQuota();
|
||||||
const volumeMsg = this.checkVolumeQuota();
|
const volumeMsg = this.checkVolumeQuota();
|
||||||
if (!flavorMsg && !volumeMsg) {
|
const serverGroupMsg = this.checkSeverGroupQuota();
|
||||||
|
if (!flavorMsg && !volumeMsg && !serverGroupMsg) {
|
||||||
this.status = 'success';
|
this.status = 'success';
|
||||||
this.errorMsg = '';
|
this.errorMsg = '';
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
this.status = 'error';
|
this.status = 'error';
|
||||||
const msg = flavorMsg || volumeMsg;
|
const msg = flavorMsg || volumeMsg || serverGroupMsg;
|
||||||
if (this.errorMsg !== msg) {
|
if (this.errorMsg !== msg) {
|
||||||
$message.error(msg);
|
$message.error(msg);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user