fix: fix the magnum quotai and other infos

1. support volume quota when create cluster instance
2. fix subnet reseting when fixed network changed
3. show project id of cluster template if switch to administrator platform

Closes-Bug: #2000141
Change-Id: I6cb59e9f74c76cb3d0901e89c9bf01d48a85d747
This commit is contained in:
xusongfu 2022-12-20 16:04:38 +08:00
parent d48aca89a4
commit e03182b072
8 changed files with 111 additions and 39 deletions

View File

@ -56,6 +56,11 @@ export class ClusterTemplateDetail extends Base {
dataIndex: 'updated_at',
valueRender: 'toLocalTime',
},
{
title: t('Project ID'),
dataIndex: 'project_id',
hidden: !this.isAdminPage,
},
];
}

View File

@ -96,6 +96,10 @@ export class StepNetwork extends Base {
master_lb_enabled,
floating_ip_enabled,
} = {},
context: {
fixedNetwork: fixedNetworkContext,
fixedSubnet: fixedSubnetContext,
},
} = this.props;
values = {
network_driver,
@ -111,13 +115,13 @@ export class StepNetwork extends Base {
floating_ip_enabled,
};
if (fixed_network) {
values.fixedNetwork = {
values.fixedNetwork = fixedNetworkContext || {
selectedRowKeys: [fixed_network],
selectedRows: [fixedNetwork],
};
}
if (fixed_subnet) {
values.fixedSubnet = {
values.fixedSubnet = fixedSubnetContext || {
selectedRowKeys: [fixed_subnet],
selectedRows: [fixedSubnet],
};
@ -128,7 +132,15 @@ export class StepNetwork extends Base {
}
get formItems() {
const { extra: { network_driver } = {} } = this.props;
const {
extra: { network_driver, fixed_subnet, fixedSubnet } = {},
context: { fixedSubnet: fixedSubnetContext },
} = this.props;
const initSubnet = fixedSubnetContext || {
selectedRowKeys: fixed_subnet ? [fixed_subnet] : [],
selectedRows: fixedSubnet ? [fixedSubnet] : [],
};
return [
{
@ -204,10 +216,10 @@ export class StepNetwork extends Base {
onChange: (value) => {
this.updateContext({
fixedNetwork: value,
});
this.updateFormValue('fixedSubnet', {
selectedRowKeys: [],
selectedRows: [],
fixedSubnet: {
selectedRowKeys: [],
selectedRows: [],
},
});
},
},
@ -223,6 +235,12 @@ export class StepNetwork extends Base {
},
],
columns: subnetColumns,
initValue: initSubnet,
onChange: (value) => {
this.updateContext({
fixedSubnet: value,
});
},
},
{
name: 'dns_nameserver',

View File

@ -33,6 +33,13 @@ export class ClusterTemplates extends Base {
return false;
}
updateFetchParams = (params) => {
return {
...params,
shouldFetchProject: this.isAdminPage,
};
};
get actionConfigs() {
if (this.isAdminPage) {
return actionConfigs.actionConfigsAdmin;

View File

@ -185,6 +185,11 @@ export class StepNetworks extends Base {
},
],
columns: subnetColumns,
onChange: (value) => {
this.updateContext({
fixedSubnet: value,
});
},
initValue: initSubnet,
},
{

View File

@ -74,15 +74,22 @@ export class StepNodeSpec extends Base {
get defaultValue() {
const {
context: { clusterTemplate = {}, keypair, masterFlavor, flavor } = {},
context: {
clusterTemplate = {},
keypair,
masterFlavor,
flavor,
master_count,
node_count,
} = {},
} = this.props;
const { selectedRows = [] } = clusterTemplate;
const { master_flavor_id, flavor_id, keypair_id, selfKeypair } =
selectedRows[0] || {};
return {
master_count: 1,
node_count: 1,
master_count: master_count || 1,
node_count: node_count || 1,
masterFlavor: masterFlavor || {
selectedRowKeys: master_flavor_id ? [master_flavor_id] : [],
selectedRows: this.masterFlavors.filter(

View File

@ -131,6 +131,7 @@ export class StepCreate extends StepAction {
title: t('Clusters'),
};
const { newNodes } = this.getNodesInput();
const {
instances = {},
cores = {},
@ -138,7 +139,7 @@ export class StepCreate extends StepAction {
} = toJS(this.projectStore.novaQuota) || {};
const instanceQuotaInfo = {
...instances,
add: quotaError ? 0 : 1,
add: quotaError ? 0 : newNodes,
name: 'instance',
title: t('Instance'),
type: 'line',
@ -161,11 +162,21 @@ export class StepCreate extends StepAction {
type: 'line',
};
const { volumes } = toJS(this.projectStore.cinderQuota) || {};
const volumeQuotaInfo = {
...volumes,
add: quotaError ? 0 : newNodes,
name: 'volume',
title: t('Volume'),
type: 'line',
};
const quotaInfo = [
clusterQuotaInfo,
instanceQuotaInfo,
cpuQuotaInfo,
ramQuotaInfo,
volumeQuotaInfo,
];
return quotaInfo;
@ -184,15 +195,25 @@ export class StepCreate extends StepAction {
return '';
}
getNodesInput() {
const { data = {} } = this.state;
const { node_count = 0, master_count = 0 } = data;
const newNodes = node_count + master_count;
return {
newNodes,
};
}
checkInstanceQuota() {
const { quotaLoading } = this.state;
if (quotaLoading) {
return '';
}
const { newNodes } = this.getNodesInput();
const { instances = {} } = this.projectStore.novaQuota || {};
const { left = 0 } = instances;
if (left === 0) {
return this.getQuotaMessage(1, instances, t('Instance'));
if (left !== -1 && left < newNodes) {
return this.getQuotaMessage(newNodes, instances, t('Instance'));
}
return '';
}
@ -247,11 +268,26 @@ export class StepCreate extends StepAction {
return '';
}
checkVolumeQuota() {
const { quotaLoading } = this.state;
if (quotaLoading) {
return '';
}
const { newNodes } = this.getNodesInput();
const { volumes } = toJS(this.projectStore.cinderQuota) || {};
const { left = 0 } = volumes;
if (left !== -1 && left < newNodes) {
return this.getQuotaMessage(newNodes, volumes, t('Volume'));
}
return '';
}
checkQuotaInput() {
const clusterMsg = this.checkClusterQuota();
const instanceMsg = this.checkInstanceQuota();
const flavorMsg = this.checkFlavorQuota();
const error = clusterMsg || instanceMsg || flavorMsg;
const volumeMsg = this.checkVolumeQuota();
const error = clusterMsg || instanceMsg || flavorMsg || volumeMsg;
if (!error) {
this.status = 'success';
this.errorMsg = '';
@ -304,6 +340,7 @@ export class StepCreate extends StepAction {
}
const data = {
...rest,
name: values.name,
labels: {
...requestLabels,
@ -311,31 +348,14 @@ export class StepCreate extends StepAction {
auto_scaling_enabled: `${!!auto_scaling_enabled}`,
},
cluster_template_id: clusterTemplate.selectedRowKeys[0],
...rest,
keypair: (keypair && keypair.selectedRowKeys[0]) || null,
master_flavor_id:
(masterFlavor && masterFlavor.selectedRowKeys[0]) || null,
flavor_id: (flavor && flavor.selectedRowKeys[0]) || null,
fixed_network: (!newNetwork && fixedNetwork.selectedRowKeys[0]) || null,
fixed_subnet: (!newNetwork && fixedSubnet.selectedRowKeys[0]) || null,
};
if (keypair) {
data.keypair = keypair.selectedRowKeys[0];
}
if (masterFlavor) {
data.master_flavor_id = masterFlavor.selectedRowKeys[0];
}
if (flavor) {
data.flavor_id = flavor.selectedRowKeys[0];
}
if (!newNetwork && fixedNetwork) {
const { selectedRowKeys = [] } = fixedNetwork;
data.fixed_network = selectedRowKeys[0];
}
if (!newNetwork && fixedSubnet) {
const { selectedRowKeys = [] } = fixedSubnet;
data.fixed_subnet = selectedRowKeys[0];
}
return this.store.create(data);
};
}

View File

@ -51,6 +51,12 @@ export const getBaseSimpleFlavorColumns = (self) => [
dataIndex: 'name',
routeName: self ? self.getRouteName('flavorDetail') : '',
},
{
title: t('Project ID/Name'),
dataIndex: 'project_name',
isHideable: true,
hidden: !self.isAdminPage,
},
{
title: t('Architecture'),
dataIndex: 'architecture',

View File

@ -78,10 +78,14 @@ export class ClusterTemplatesStore extends Base {
});
}
async listDidFetch(items) {
async listDidFetch(items, _, filters) {
if (!items.length) return items;
const { shouldFetchProject } = filters;
const newData = await this.listDidFetchProject(items, {
all_projects: shouldFetchProject,
});
const { keypairs = [] } = (await client.nova.keypairs.list()) || {};
return items.map((it) => {
return newData.map((it) => {
const keypair = keypairs.find((k) => k?.keypair?.name === it.keypair_id);
if (keypair) {
it.selfKeypair = true;