refactor: optimize the way to fetch the list of volumes mounted on the instance
Use the skyline extension volumes api with uuid param to fetch the list of the volumes mounted on the instance, instead of fetch all the volumes and filtered by the instance id Change-Id: Ie792a661d3fbf54a0f96c377e4d402e6bd0db323
This commit is contained in:
parent
2caa340ba6
commit
afefcf6fdb
@ -13,7 +13,7 @@
|
||||
// limitations under the License.
|
||||
|
||||
import { inject, observer } from 'mobx-react';
|
||||
import { VolumeStore } from 'stores/cinder/volume';
|
||||
import { InstanceVolumeStore } from 'stores/nova/instance-volume';
|
||||
import globalServerStore from 'stores/nova/instance';
|
||||
import globalRootStore from 'stores/root';
|
||||
import { ModalAction } from 'containers/Action';
|
||||
@ -27,7 +27,7 @@ export class DetachVolume extends ModalAction {
|
||||
|
||||
init() {
|
||||
this.store = globalServerStore;
|
||||
this.volumeStore = new VolumeStore();
|
||||
this.volumeStore = new InstanceVolumeStore();
|
||||
this.getVolumes();
|
||||
}
|
||||
|
||||
|
@ -91,14 +91,10 @@ export class Volume extends Base {
|
||||
|
||||
updateFetchParams = (params) => {
|
||||
if (this.inDetailPage) {
|
||||
const { match, detail } = this.props;
|
||||
const { id } = match.params;
|
||||
const { tenant_id: projectId, name } = detail || {};
|
||||
const { id, ...rest } = params;
|
||||
return {
|
||||
...params,
|
||||
...rest,
|
||||
serverId: id,
|
||||
serverName: name,
|
||||
projectId,
|
||||
};
|
||||
}
|
||||
return params;
|
||||
|
@ -14,7 +14,7 @@
|
||||
|
||||
import React from 'react';
|
||||
import { yesNoOptions } from 'utils/constants';
|
||||
import { toLocalTimeFilter } from 'utils/index';
|
||||
import { toLocalTimeFilter, renderFilterMap } from 'utils/index';
|
||||
import globalProjectStore from 'stores/keystone/project';
|
||||
import globalVolumeStore from 'stores/cinder/volume';
|
||||
import { isEmpty } from 'lodash';
|
||||
@ -75,6 +75,19 @@ export const isOsDisk = (item) => {
|
||||
return false;
|
||||
};
|
||||
|
||||
export const updateVolume = (volume) => {
|
||||
return {
|
||||
...volume,
|
||||
disk_tag: isOsDisk(volume) ? 'os_disk' : 'data_disk',
|
||||
description: volume.description || (volume.origin_data || {}).description,
|
||||
delete_interval:
|
||||
volume.metadata && volume.metadata.delete_interval
|
||||
? new Date(renderFilterMap.toLocalTime(volume.updated_at)).getTime() +
|
||||
Number(volume.metadata.delete_interval) * 1000
|
||||
: null,
|
||||
};
|
||||
};
|
||||
|
||||
export const isAttachIsoVolume = (item) => {
|
||||
if (
|
||||
item.bootable === 'true' &&
|
||||
@ -239,7 +252,6 @@ export const getVolumeColumnsList = (self) => {
|
||||
title: t('ID/Name'),
|
||||
dataIndex: 'name',
|
||||
routeName: self.getRouteName('volumeDetail'),
|
||||
stringify: (name, record) => name || record.id,
|
||||
sortKey: 'name',
|
||||
},
|
||||
{
|
||||
|
@ -13,7 +13,6 @@
|
||||
// limitations under the License.
|
||||
|
||||
import { action, observable } from 'mobx';
|
||||
import { renderFilterMap } from 'utils/index';
|
||||
import client from 'client';
|
||||
import Base from 'stores/base';
|
||||
import globalVolumeTypeStore from 'stores/cinder/volume-type';
|
||||
@ -64,22 +63,9 @@ export class VolumeStore extends Base {
|
||||
return this.skylineClient.extension.volumes(params);
|
||||
}
|
||||
|
||||
isOsDisk(item) {
|
||||
const { isOsDisk } = require('resources/cinder/volume');
|
||||
return isOsDisk(item);
|
||||
}
|
||||
|
||||
get mapper() {
|
||||
return (volume) => ({
|
||||
...volume,
|
||||
disk_tag: this.isOsDisk(volume) ? 'os_disk' : 'data_disk',
|
||||
description: volume.description || (volume.origin_data || {}).description,
|
||||
delete_interval:
|
||||
volume.metadata && volume.metadata.delete_interval
|
||||
? new Date(renderFilterMap.toLocalTime(volume.updated_at)).getTime() +
|
||||
Number(volume.metadata.delete_interval) * 1000
|
||||
: null,
|
||||
});
|
||||
const { updateVolume } = require('resources/cinder/volume');
|
||||
return (volume) => updateVolume(volume);
|
||||
}
|
||||
|
||||
get paramsFunc() {
|
||||
|
@ -12,9 +12,10 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
import { isOsDisk } from 'resources/cinder/volume';
|
||||
import client from 'client';
|
||||
import Base from 'stores/base';
|
||||
import { groupArray } from 'utils/index';
|
||||
import { updateVolume } from 'resources/cinder/volume';
|
||||
|
||||
export class InstanceVolumeStore extends Base {
|
||||
get client() {
|
||||
@ -46,42 +47,30 @@ export class InstanceVolumeStore extends Base {
|
||||
}
|
||||
|
||||
get mapper() {
|
||||
return (volume) => ({
|
||||
...volume,
|
||||
disk_tag: isOsDisk(volume) ? 'os_disk' : 'data_disk',
|
||||
host: volume['os-vol-host-attr:host'],
|
||||
});
|
||||
return (volume) => updateVolume(volume);
|
||||
}
|
||||
|
||||
async listDidFetch(items, allProjects, filters) {
|
||||
get groupArraySize() {
|
||||
return 10;
|
||||
}
|
||||
|
||||
async listDidFetch(items, allProjects) {
|
||||
if (items.length === 0) {
|
||||
return items;
|
||||
}
|
||||
const { serverName, serverId } = filters;
|
||||
const { project_id, project_name } = items[0];
|
||||
const volumeIds = items.map((it) => it.volumeId);
|
||||
const idArray = groupArray(volumeIds, this.groupArraySize);
|
||||
const results = await Promise.all(
|
||||
items.map((it) => {
|
||||
const { volumeId } = it;
|
||||
return client.cinder.volumes.show(volumeId);
|
||||
idArray.map((it) => {
|
||||
const newParams = { uuid: it, all_projects: allProjects };
|
||||
return this.skylineClient.extension.volumes(newParams);
|
||||
})
|
||||
);
|
||||
const volumes = results.map((result) => {
|
||||
const { volume } = result;
|
||||
const { attachments = [] } = volume;
|
||||
const newAttachments = attachments.filter(
|
||||
(it) => it.server_id === serverId
|
||||
);
|
||||
newAttachments.forEach((it) => {
|
||||
it.server_name = serverName;
|
||||
const resultVolumes = [];
|
||||
results.forEach((result) => {
|
||||
resultVolumes.push(...result.volumes);
|
||||
});
|
||||
volume.attachments = newAttachments;
|
||||
return {
|
||||
...volume,
|
||||
project_id,
|
||||
project_name,
|
||||
};
|
||||
});
|
||||
return volumes;
|
||||
return resultVolumes;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user