From 3b1ddc54a0b4c3633b6e87753012713cb2507a38 Mon Sep 17 00:00:00 2001 From: zhangke Date: Tue, 18 Oct 2022 17:21:12 +0800 Subject: [PATCH] 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 --- ...ata-Disk-Of-Snapshot-3b23e998665187c1.yaml | 8 +++++++ .../Instance/actions/StepCreate/index.jsx | 23 ++++++++++++++----- 2 files changed, 25 insertions(+), 6 deletions(-) create mode 100644 releasenotes/notes/Show-Data-Disk-Of-Snapshot-3b23e998665187c1.yaml diff --git a/releasenotes/notes/Show-Data-Disk-Of-Snapshot-3b23e998665187c1.yaml b/releasenotes/notes/Show-Data-Disk-Of-Snapshot-3b23e998665187c1.yaml new file mode 100644 index 00000000..85b6c0b3 --- /dev/null +++ b/releasenotes/notes/Show-Data-Disk-Of-Snapshot-3b23e998665187c1.yaml @@ -0,0 +1,8 @@ +--- +fixes: + - | + `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. diff --git a/src/pages/compute/containers/Instance/actions/StepCreate/index.jsx b/src/pages/compute/containers/Instance/actions/StepCreate/index.jsx index 18ae1fd9..c3160b3f 100644 --- a/src/pages/compute/containers/Instance/actions/StepCreate/index.jsx +++ b/src/pages/compute/containers/Instance/actions/StepCreate/index.jsx @@ -22,6 +22,7 @@ import globalProjectStore from 'stores/keystone/project'; import classnames from 'classnames'; import { isEmpty, isFinite, isString } from 'lodash'; import { getUserData } from 'resources/nova/instance'; +import { getAllDataDisks } from 'resources/cinder/snapshot'; import { getGiBValue } from 'utils/index'; import Notify from 'components/Notify'; import ConfirmStep from './ConfirmStep'; @@ -299,12 +300,14 @@ export class StepCreate extends StepAction { count = 1, source: { value: sourceValue } = {}, instanceSnapshotDisk = {}, + instanceSnapshotDataVolumes = [], } = data; const newCountMap = {}; const newSizeMap = {}; let totalNewCount = 0; let totalNewSize = 0; - if (sourceValue === 'instanceSnapshot' && instanceSnapshotDisk) { + const isSnapshotType = sourceValue === 'instanceSnapshot'; + if (isSnapshotType && instanceSnapshotDisk) { const { size, typeOption: { label } = {} } = instanceSnapshotDisk; if (label) { newCountMap[label] = !newCountMap[label] ? 1 : newCountMap[label] + 1; @@ -322,11 +325,19 @@ export class StepCreate extends StepAction { totalNewCount += 1 * count; totalNewSize += size * count; } - if (dataDisk) { - dataDisk.forEach((item) => { - if (item.value && item.value.type) { - const { size } = item.value; - const { label } = item.value.typeOption || {}; + if ( + dataDisk || + (isSnapshotType && instanceSnapshotDataVolumes?.length > 0) + ) { + 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] ? 1 * count : newCountMap[label] + 1 * count;