fix: Calculate quota based on the data disk of the selected instance snapshot

When the Start source is the instance snapshot, the quota
should be calculated according to the data disk of the selected
instance snapshot and the newly added data disk

Closes-Bug: #1992739
Change-Id: I035b1edb5e0441e63d7919ea5933731bd687c1d2
This commit is contained in:
zhangke 2022-10-18 17:21:12 +08:00 committed by Boxiang Zhu
parent 33f90ae331
commit 3b1ddc54a0
2 changed files with 25 additions and 6 deletions

View File

@ -0,0 +1,8 @@
---
fixes:
- |
`Bug #1992739 <https://bugs.launchpad.net/skyline-console/+bug/1992739>`_:
When the instance snapshot is used to create instance, if the instance
snapshot is associated with data disks, it is supported to show necessary
data disk information and make quota measurable.

View File

@ -22,6 +22,7 @@ import globalProjectStore from 'stores/keystone/project';
import classnames from 'classnames'; import classnames from 'classnames';
import { isEmpty, isFinite, isString } from 'lodash'; import { isEmpty, isFinite, isString } from 'lodash';
import { getUserData } from 'resources/nova/instance'; import { getUserData } from 'resources/nova/instance';
import { getAllDataDisks } from 'resources/cinder/snapshot';
import { getGiBValue } from 'utils/index'; import { getGiBValue } from 'utils/index';
import Notify from 'components/Notify'; import Notify from 'components/Notify';
import ConfirmStep from './ConfirmStep'; import ConfirmStep from './ConfirmStep';
@ -299,12 +300,14 @@ export class StepCreate extends StepAction {
count = 1, count = 1,
source: { value: sourceValue } = {}, source: { value: sourceValue } = {},
instanceSnapshotDisk = {}, instanceSnapshotDisk = {},
instanceSnapshotDataVolumes = [],
} = data; } = data;
const newCountMap = {}; const newCountMap = {};
const newSizeMap = {}; const newSizeMap = {};
let totalNewCount = 0; let totalNewCount = 0;
let totalNewSize = 0; let totalNewSize = 0;
if (sourceValue === 'instanceSnapshot' && instanceSnapshotDisk) { const isSnapshotType = sourceValue === 'instanceSnapshot';
if (isSnapshotType && instanceSnapshotDisk) {
const { size, typeOption: { label } = {} } = instanceSnapshotDisk; const { size, typeOption: { label } = {} } = instanceSnapshotDisk;
if (label) { if (label) {
newCountMap[label] = !newCountMap[label] ? 1 : newCountMap[label] + 1; newCountMap[label] = !newCountMap[label] ? 1 : newCountMap[label] + 1;
@ -322,11 +325,19 @@ export class StepCreate extends StepAction {
totalNewCount += 1 * count; totalNewCount += 1 * count;
totalNewSize += size * count; totalNewSize += size * count;
} }
if (dataDisk) { if (
dataDisk.forEach((item) => { dataDisk ||
if (item.value && item.value.type) { (isSnapshotType && instanceSnapshotDataVolumes?.length > 0)
const { size } = item.value; ) {
const { label } = item.value.typeOption || {}; const allDataDisks = getAllDataDisks({
dataDisk,
instanceSnapshotDataVolumes,
});
allDataDisks.forEach((item) => {
const diskItem = item.value || {};
if (diskItem.type) {
const { size, typeOption } = diskItem;
const { label } = typeOption || {};
newCountMap[label] = !newCountMap[label] newCountMap[label] = !newCountMap[label]
? 1 * count ? 1 * count
: newCountMap[label] + 1 * count; : newCountMap[label] + 1 * count;