fix: Remove price codes && update stores

1. Remove useless codes related to prices
2. Update client usage in stores

Change-Id: I1c717842b4f9918ab7e1665c99847aa6960b9e44
This commit is contained in:
Jingwei.Zhang 2021-09-07 17:56:23 +08:00
parent 535badf92e
commit 49b07a6f70
70 changed files with 255 additions and 367 deletions

View File

@ -15,9 +15,9 @@
import { get } from 'lodash';
import { action, observable } from 'mobx';
import client from 'client';
import List from './base-list';
import globalProjectMapStore from './project';
import globalRootStore from './root';
import List from 'stores/base-list';
import globalProjectMapStore from 'stores/project';
import globalRootStore from 'stores/root';
export default class BaseStore {
list = new List();
@ -129,7 +129,7 @@ export default class BaseStore {
get paramsFuncPage() {
return (params) => {
const { current, withPrice, ...rest } = params;
const { current, ...rest } = params;
return rest;
};
}

View File

@ -14,8 +14,8 @@
import { action } from 'mobx';
import client from 'client';
import Base from '../base';
import { VolumeStore } from './volume';
import Base from 'stores/base';
import { VolumeStore } from 'stores/cinder/volume';
export class BackupStore extends Base {
get client() {

View File

@ -14,7 +14,7 @@
import { action } from 'mobx';
import client from 'client';
import Base from '../base';
import Base from 'stores/base';
export class ExtraSpecStore extends Base {
get client() {

View File

@ -14,7 +14,7 @@
import { isNumber } from 'lodash';
import client from 'client';
import Base from '../base';
import Base from 'stores/base';
export class PoolStore extends Base {
get client() {

View File

@ -14,7 +14,7 @@
import { action } from 'mobx';
import client from 'client';
import Base from '../base';
import Base from 'stores/base';
export class QosSpecKeyStore extends Base {
get client() {

View File

@ -14,7 +14,7 @@
import { action } from 'mobx';
import client from 'client';
import Base from '../base';
import Base from 'stores/base';
export class QosSpecStore extends Base {
get client() {

View File

@ -14,7 +14,7 @@
import { action } from 'mobx';
import client from 'client';
import Base from '../base';
import Base from 'stores/base';
export class ServiceStore extends Base {
get client() {

View File

@ -14,13 +14,17 @@
import { action } from 'mobx';
import client from 'client';
import Base from '../base';
import Base from 'stores/base';
export class SnapshotStore extends Base {
get client() {
return client.cinder.snapshots;
}
get volumeClient() {
return client.cinder.volumes;
}
get listResponseKey() {
return 'volume_snapshots';
}
@ -31,7 +35,7 @@ export class SnapshotStore extends Base {
get paramsFunc() {
return (params) => {
const { id, withPrice, ...rest } = params;
const { id, ...rest } = params;
return rest;
};
}
@ -47,7 +51,7 @@ export class SnapshotStore extends Base {
async detailDidFetch(item) {
const { volume_id } = item;
const { volume } = await client.cinder.volumes.show(volume_id);
const { volume } = await this.volumeClient.show(volume_id);
item.volume = volume;
return item;
}

View File

@ -15,7 +15,7 @@
import { action, observable } from 'mobx';
import client from 'client';
import { uniq } from 'lodash';
import Base from '../base';
import Base from 'stores/base';
export class VolumeTypeStore extends Base {
@observable
@ -28,6 +28,10 @@ export class VolumeTypeStore extends Base {
return client.cinder.types;
}
get qosClient() {
return client.cinder.qosSpecs;
}
get listFilterByProject() {
return false;
}
@ -64,7 +68,7 @@ export class VolumeTypeStore extends Base {
items.filter((it) => !!it.qos_specs_id).map((it) => it.qos_specs_id)
);
if (qosIds.length) {
const qosReqs = qosIds.map((id) => client.cinder.qosSpecs.show(id));
const qosReqs = qosIds.map((id) => this.qosClient.show(id));
const qosResults = await Promise.all(qosReqs);
const qosItems = qosResults.map((it) => it.qos_specs);
items.forEach((it) => {
@ -80,7 +84,7 @@ export class VolumeTypeStore extends Base {
items.filter((it) => !!it.qos_specs_id).map((it) => it.qos_specs_id)
);
if (qosIds.length) {
const qosReqs = qosIds.map((id) => client.cinder.qosSpecs.show(id));
const qosReqs = qosIds.map((id) => this.qosClient.show(id));
const qosResults = await Promise.all(qosReqs);
const qosItems = qosResults.map((it) => it.qos_specs);
items.forEach((it) => {
@ -207,7 +211,7 @@ export class VolumeTypeStore extends Base {
this.projectVolumeTypes = types;
return types;
}
const projectTypes = types.filter((it) => it.public);
const projectTypes = types.filter((it) => it.is_public);
const reqs = privateTypes.map((it) => this.client.getAccess(it.id));
const accessResults = await Promise.all(reqs);
accessResults.forEach((it) => {

View File

@ -16,8 +16,8 @@ import { action, observable } from 'mobx';
import { isOsDisk } from 'resources/volume';
import { renderFilterMap } from 'utils/index';
import client from 'client';
import Base from '../base';
import globalVolumeTypeStore from './volume-type';
import Base from 'stores/base';
import globalVolumeTypeStore from 'stores/cinder/volume-type';
export class VolumeStore extends Base {
@observable
@ -40,6 +40,14 @@ export class VolumeStore extends Base {
return client.cinder.volumeTransfers;
}
get quotaClient() {
return client.cinder.quotaSets;
}
get zoneClient() {
return client.cinder.azones;
}
listFetchByClient(params, originParams) {
const { recycle } = originParams;
if (recycle) {
@ -82,19 +90,9 @@ export class VolumeStore extends Base {
};
async listDidFetch(items, _, filters) {
const { withPrice } = filters;
if (items.length === 0) {
return items;
}
if (withPrice) {
const volumeTypes = await globalVolumeTypeStore.fetchList({ withPrice });
items.forEach((item) => {
const { size, volume_type } = item;
const volumeType = volumeTypes.find((it) => it.name === volume_type);
const cost = volumeType ? (volumeType.priceCost * size).toFixed(2) : 0;
item.cost = cost;
});
}
const { serverId } = filters;
return !serverId
? items
@ -105,26 +103,19 @@ export class VolumeStore extends Base {
);
}
async detailDidFetch(item, all_projects, { withPrice }) {
async detailDidFetch(item, all_projects) {
const { id } = item;
try {
const result = await this.fetchList({ uuid: id, all_projects });
item.itemInList = result[0];
item.attachmentsContrib = result[0].attachments;
} catch (e) {}
if (withPrice) {
const volumeTypes = await globalVolumeTypeStore.fetchList({ withPrice });
const { size, volume_type } = item;
const volumeType = volumeTypes.find((it) => it.name === volume_type);
const cost = volumeType ? (volumeType.priceCost * size).toFixed(2) : 0;
item.cost = cost;
}
return item;
}
@action
async fetchQuota() {
const result = await client.cinder.quotaSets.show(this.currentProjectId, {
const result = await this.quotaClient.show(this.currentProjectId, {
usage: 'True',
});
this.quotaSet = result.quota_set;
@ -132,7 +123,7 @@ export class VolumeStore extends Base {
@action
async fetchAvailabilityZoneList() {
const result = await client.cinder.azones.list();
const result = await this.zoneClient.list();
this.availabilityZones = result.availabilityZoneInfo;
}

View File

@ -14,7 +14,7 @@
import { action, observable } from 'mobx';
import client from 'client';
import Base from '../base';
import Base from 'stores/base';
export class ImageStore extends Base {
@observable
@ -41,7 +41,7 @@ export class ImageStore extends Base {
get paramsFuncPage() {
return (params) => {
const { current, all_projects, withPrice, ...rest } = params;
const { current, all_projects, ...rest } = params;
return {
...rest,
// image_type: 'image',

View File

@ -1,156 +0,0 @@
// Copyright 2021 99cloud
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import client from 'client';
import Base from '../base';
export class InstanceSnapshotStore extends Base {
get client() {
return client.glance.images;
}
get listFilterByProject() {
return true;
}
get fetchListByLimit() {
return false;
}
updateParamsSortPage = (params, sortKey, sortOrder) => {
if (sortKey && sortOrder) {
params.sort_key = sortKey;
params.sort_dir = sortOrder === 'descend' ? 'desc' : 'asc';
}
};
get paramsFunc() {
return this.paramsFuncPage;
}
get paramsFuncPage() {
return (params, all_projects) => {
const { id, current, owner, ...rest } = params;
const newParams = {
...rest,
image_type: 'snapshot',
};
if (owner) {
newParams.owner = owner;
} else if (!all_projects) {
newParams.owner = this.currentProjectId;
}
return newParams;
};
}
async getCountForPage(params) {
const { limit, marker, ...rest } = params;
const result = await this.client.count(rest);
return result;
}
get mapperBeforeFetchProject() {
return (data) => ({
...data,
project_name: data.owner_project_name || data.project_name,
});
}
async listDidFetch(items, allProjects, filters) {
if (items.length === 0) {
return items;
}
const { id } = filters;
if (!id) {
return items;
}
const volumeParams = {};
const snapshotParams = { all_tenants: allProjects };
const results = await Promise.all([
client.cinder.snapshots.list(snapshotParams),
client.nova.servers.volumeAttachments.list(id, volumeParams),
]);
const snapshotsAll = results[0].snapshots;
const volumesAll = results[1].volumeAttachments;
const datas = [];
items.forEach((data) => {
const { block_device_mapping: bdm = '[]' } = data;
const snapshot = JSON.parse(bdm).find((it) => it.boot_index === 0);
if (snapshot) {
data.snapshotId = snapshot.snapshot_id;
const snapshotDetail = snapshotsAll.find(
(it) => it.id === snapshot.snapshot_id
);
if (snapshotDetail) {
const volumeId = snapshotDetail.volume_id;
const volume = volumesAll.find((it) => it.volumeId === volumeId);
if (volume) {
datas.push(data);
}
}
} else {
const { instance_uuid: instanceId } = data;
if (id === instanceId) {
datas.push(data);
}
}
});
return datas;
}
async detailDidFetch(item) {
item.originData = { ...item };
const { block_device_mapping: bdm = '[]' } = item;
const snapshot = JSON.parse(bdm).find((it) => it.boot_index === 0);
let instanceId = null;
let instanceName = '';
if (snapshot) {
const { snapshot_id: snapshotId } = snapshot;
item.snapshotId = snapshotId;
const snapshotResult = await client.cinder.snapshots.show(snapshotId);
const snapshotDetail = snapshotResult.snapshot;
item.snapshotDetail = snapshotDetail;
const { volume_id: volumeId } = snapshotDetail;
const volumeResult = await client.cinder.volumes.show(volumeId);
const volumeDetail = volumeResult.volume;
item.volumeDetail = volumeDetail;
instanceId =
volumeDetail.attachments.length > 0
? volumeDetail.attachments[0].server_id
: '';
} else {
// fix for not bfv instance
const { instance_uuid } = item;
instanceId = instance_uuid;
}
let instanceResult = {};
try {
if (instanceId) {
instanceResult = await client.nova.servers.show(instanceId);
const { server: { name } = {} } = instanceResult;
instanceName = name;
}
} catch (e) {}
item.instance = {
server_id: instanceId,
server_name: instanceName,
};
item.instanceDetail = instanceResult.server || {};
return item;
}
}
const globalInstanceSnapshotStore = new InstanceSnapshotStore();
export default globalInstanceSnapshotStore;

View File

@ -14,7 +14,7 @@
import { action, observable } from 'mobx';
import client from 'client';
import Base from '../base';
import Base from 'stores/base';
export class MetadataStore extends Base {
@observable

View File

@ -13,7 +13,7 @@
// limitations under the License.
import client from 'client';
import Base from '../base';
import Base from 'stores/base';
export class StackEventStore extends Base {
get client() {

View File

@ -13,7 +13,7 @@
// limitations under the License.
import client from 'client';
import Base from '../base';
import Base from 'stores/base';
export class StackResourceStore extends Base {
get client() {

View File

@ -13,7 +13,7 @@
// limitations under the License.
import client from 'client';
import Base from '../base';
import Base from 'stores/base';
export class HeatServiceStore extends Base {
get client() {

View File

@ -14,7 +14,7 @@
import { action, observable } from 'mobx';
import client from 'client';
import Base from '../base';
import Base from 'stores/base';
export class StackStore extends Base {
@observable

View File

@ -1,29 +1,27 @@
import globalFloatingIpsStore from './neutron/floatingIp';
import globalImageStore from './glance/image';
import globalServerStore from './nova/instance';
import globalInstanceSnapshotStore from './glance/instance-snapshot';
import globalKeypairStore from './nova/keypair';
import globalNetworkStore from './neutron/network';
import globalPortForwardingStore from './neutron/port-forwarding';
import globalQoSPolicyStore from './neutron/qos-policy';
import globalRecycleBinStore from './skyline/recycle-server';
import globalSecurityGroupStore from './neutron/security-group';
import globalSecurityGroupRuleStore from './neutron/security-rule';
import globalServerGroupStore from './nova/server-group';
import globalSnapshotStore from './cinder/snapshot';
import globalStaticRouteStore from './neutron/static-route';
import globalSubnetStore from './neutron/subnet';
import globalVirtualAdapterStore from './neutron/virtual-adapter';
import globalVolumeStore from './cinder/volume';
import globalComputeHostStore from './nova/compute-host';
import globalHypervisorStore from './nova/hypervisor';
import globalStackStore from './heat/stack';
import globalFloatingIpsStore from 'stores/neutron/floatingIp';
import globalImageStore from 'stores/glance/image';
import globalServerStore from 'stores/nova/instance';
import globalKeypairStore from 'stores/nova/keypair';
import globalNetworkStore from 'stores/neutron/network';
import globalPortForwardingStore from 'stores/neutron/port-forwarding';
import globalQoSPolicyStore from 'stores/neutron/qos-policy';
import globalRecycleBinStore from 'stores/skyline/recycle-server';
import globalSecurityGroupStore from 'stores/neutron/security-group';
import globalSecurityGroupRuleStore from 'stores/neutron/security-rule';
import globalServerGroupStore from 'stores/nova/server-group';
import globalSnapshotStore from 'stores/cinder/snapshot';
import globalStaticRouteStore from 'stores/neutron/static-route';
import globalSubnetStore from 'stores/neutron/subnet';
import globalVirtualAdapterStore from 'stores/neutron/virtual-adapter';
import globalVolumeStore from 'stores/cinder/volume';
import globalComputeHostStore from 'stores/nova/compute-host';
import globalHypervisorStore from 'stores/nova/hypervisor';
import globalStackStore from 'stores/heat/stack';
export default {
globalFloatingIpsStore,
globalImageStore,
globalServerStore,
globalInstanceSnapshotStore,
globalKeypairStore,
globalNetworkStore,
globalPortForwardingStore,

View File

@ -14,7 +14,7 @@
import { action, observable } from 'mobx';
import client from 'client';
import Base from '../base';
import Base from 'stores/base';
export class IronicStore extends Base {
@observable
@ -34,6 +34,10 @@ export class IronicStore extends Base {
return client.ironic.ports;
}
get traitClient() {
return client.placement.traits;
}
get listWithDetail() {
return true;
}
@ -138,7 +142,7 @@ export class IronicStore extends Base {
@action
async getTraits() {
const result = await client.placement.traits.list();
const result = await this.traitClient.list();
const { traits = [] } = result;
traits.sort();
this.traits = traits;

View File

@ -14,7 +14,7 @@
import { action } from 'mobx';
import client from 'client';
import Base from '../base';
import Base from 'stores/base';
export class IronicPortGroupStore extends Base {
get client() {

View File

@ -14,16 +14,20 @@
import { action } from 'mobx';
import client from 'client';
import Base from '../base';
import Base from 'stores/base';
export class IronicPortStore extends Base {
get client() {
return client.ironic.ports;
}
get nodePortsClient() {
return client.ironic.nodes.ports;
}
listFetchByClient(params, originParams) {
const { id } = originParams;
return client.ironic.nodes.ports.listDetail(id, params);
return this.nodePortsClient.listDetail(id, params);
}
get paramsFunc() {

View File

@ -13,7 +13,7 @@
// limitations under the License.
import client from 'client';
import Base from '../base';
import Base from 'stores/base';
export class AuthCatalogStore extends Base {
get client() {

View File

@ -15,7 +15,7 @@
import { action, observable } from 'mobx';
import { get } from 'lodash';
import client from 'client';
import Base from '../base';
import Base from 'stores/base';
export class DomainStore extends Base {
@observable

View File

@ -16,7 +16,7 @@ import { action, observable } from 'mobx';
import { getGBValue } from 'utils/index';
import { get, isNil, isEmpty } from 'lodash';
import client from 'client';
import Base from '../base';
import Base from 'stores/base';
export class ProjectStore extends Base {
@observable
@ -50,6 +50,18 @@ export class ProjectStore extends Base {
return client.keystone.users;
}
get novaQuotaClient() {
return client.nova.quotaSets;
}
get cinderQuotaClient() {
return client.cinder.quotaSets;
}
get neutronQuotaClient() {
return client.neutron.quotas;
}
@action
async fetchList({
limit,
@ -254,9 +266,9 @@ export class ProjectStore extends Base {
@action
async fetchProjectQuota({ project_id }) {
const [novaResult, cinderResult, neutronResult] = await Promise.all([
client.nova.quotaSets.detail(project_id),
client.cinder.quotaSets.show(project_id, { usage: 'True' }),
client.neutron.quotas.details(project_id),
this.novaQuotaClient.detail(project_id),
this.cinderQuotaClient.show(project_id, { usage: 'True' }),
this.neutronQuotaClient.details(project_id),
]);
this.isSubmitting = false;
const { quota_set: novaQuota } = novaResult;

View File

@ -14,7 +14,7 @@
import { action, observable } from 'mobx';
import client from 'client';
import Base from '../base';
import Base from 'stores/base';
export class RoleStore extends Base {
get client() {

View File

@ -14,13 +14,17 @@
import { action } from 'mobx';
import client from 'client';
import Base from '../base';
import Base from 'stores/base';
export class TagStore extends Base {
get client() {
return client.keystone.projects.tags;
}
get projectClient() {
return client.keystone.projects;
}
listFetchByClient(params, originParams) {
const { project_id } = originParams;
return this.client.list(project_id, params);
@ -33,7 +37,7 @@ export class TagStore extends Base {
@action
update({ project_id }, newObject) {
return this.submitting(
client.keystone.projects.updateTags(project_id, newObject)
this.projectClient.updateTags(project_id, newObject)
);
}
}

View File

@ -15,8 +15,8 @@
import { action, observable } from 'mobx';
import { get } from 'lodash';
import client from 'client';
import Base from '../base';
import globalProjectStore from './project';
import Base from 'stores/base';
import globalProjectStore from 'stores/keystone/project';
export class GroupStore extends Base {
@observable

View File

@ -17,9 +17,9 @@ import { get } from 'lodash';
import List from 'stores/base-list';
import client from 'client';
import globalRootStore from 'stores/root';
import globalProjectStore from './project';
import globalGroupStore from './user-group';
import Base from '../base';
import globalProjectStore from 'stores/keystone/project';
import globalGroupStore from 'stores/keystone/user-group';
import Base from 'stores/base';
export class UserStore extends Base {
@observable

View File

@ -15,7 +15,7 @@
import { action } from 'mobx';
import client from 'client';
import { isArray } from 'lodash';
import Base from '../base';
import Base from 'stores/base';
export class NeutronAgentNetworkStore extends Base {
get client() {

View File

@ -15,7 +15,7 @@
import { action } from 'mobx';
import client from 'client';
import { isArray } from 'lodash';
import Base from '../base';
import Base from 'stores/base';
export class NeutronAgentRouterStore extends Base {
get client() {

View File

@ -13,7 +13,7 @@
// limitations under the License.
import client from 'client';
import Base from '../base';
import Base from 'stores/base';
export class NeutronAgentStore extends Base {
get client() {

View File

@ -15,7 +15,7 @@
import globalNetworkStore from 'stores/neutron/network';
import globalFloatingIpsStore from 'stores/neutron/floatingIp';
import client from 'client';
import Base from '../base';
import Base from 'stores/base';
export class FixedIpStore extends Base {
get client() {

View File

@ -17,7 +17,7 @@ import globalRouterStore from 'stores/neutron/router';
import globalServerStore from 'stores/nova/instance';
import globalLbaasStore from 'stores/octavia/loadbalancer';
import client from 'client';
import Base from '../base';
import Base from 'stores/base';
export class FloatingIpStore extends Base {
get client() {

View File

@ -18,7 +18,7 @@ import { get } from 'lodash';
import globalProjectStore from 'stores/keystone/project';
import client from 'client';
import { isExternalNetwork } from 'resources/network';
import Base from '../base';
import Base from 'stores/base';
const { splitToArray } = networkUtils;
@ -36,6 +36,26 @@ export class NetworkStore extends Base {
return client.neutron.networks;
}
get subnetClient() {
return client.neutron.subnets;
}
get extensionClient() {
return client.neutron.extensions;
}
get routerClient() {
return client.neutron.routers;
}
get ipClient() {
return client.neutron.networkIpAvailabilities;
}
get portClient() {
return client.neutron.ports;
}
get listFilterByProject() {
return true;
}
@ -65,7 +85,7 @@ export class NetworkStore extends Base {
}
listExtensions = async () => {
const extensions = await client.neutron.extensions.list();
const extensions = await this.extensionClient.list();
return extensions;
};
@ -141,7 +161,7 @@ export class NetworkStore extends Base {
// 处理使用IP数量只有管理员或者当前网络所有者才能查看
if (isAdminPage || currentProjectId === originData.project_id) {
const used = await client.neutron.networkIpAvailabilities.show(id);
const used = await this.ipClient.show(id);
this.detail = {
...this.detail,
...used.network_ip_availability,
@ -172,7 +192,7 @@ export class NetworkStore extends Base {
@action
async fetchSubnetDetail({ id }) {
try {
const resData = await client.neutron.subnets.show(id);
const resData = await this.subnetClient.show(id);
return resData.subnet;
} catch (e) {
return {};
@ -181,7 +201,7 @@ export class NetworkStore extends Base {
@action
async fetchTopoNetwork() {
await Promise.all([this.client.list(), client.neutron.subnets.list()]).then(
await Promise.all([this.client.list(), this.subnetClient.list()]).then(
([resData, subnetRes]) => {
resData.subnets = subnetRes.subnets;
resData.networks = resData.networks.filter(
@ -201,9 +221,9 @@ export class NetworkStore extends Base {
project_id: this.currentProjectId,
};
await Promise.all([
client.neutron.routers.list(params),
client.skyline.extension.servers(),
client.neutron.ports.list(params),
this.routerClient.list(params),
this.extensionClient.servers(),
this.portClient.list(params),
]).then(([routersRes, serversRes, portRes]) => {
const resData = this.topology;
routersRes.routers.map((it) => {
@ -299,7 +319,7 @@ export class NetworkStore extends Base {
gateway_ip: disable_gateway ? null : gateway_ip,
cidr,
};
return client.neutron.subnets.create({ subnet: data });
return this.subnetClient.create({ subnet: data });
}
}
const globalNetworkStore = new NetworkStore();

View File

@ -14,7 +14,7 @@
import { action, observable } from 'mobx';
import client from 'client';
import Base from '../base';
import Base from 'stores/base';
export class NeutronStore extends Base {
@observable
@ -23,10 +23,14 @@ export class NeutronStore extends Base {
@observable
zoneLoading = false;
get zoneClient() {
return client.neutron.azones;
}
@action
async fetchAvailableZones() {
this.zoneLoading = true;
const resData = await client.neutron.azones.list();
const resData = await this.zoneClient.list();
const { availability_zones: items = [] } = resData;
this.availableZones = items;
this.zoneLoading = false;

View File

@ -14,7 +14,7 @@
import { action } from 'mobx';
import client from 'client';
import Base from '../base';
import Base from 'stores/base';
export class PortForwardingStore extends Base {
get client() {

View File

@ -13,20 +13,27 @@
// limitations under the License.
import { action } from 'mobx';
import { get, uniq } from 'lodash';
import { get } from 'lodash';
import client from 'client';
import { isExternalNetwork } from 'resources/network';
import Base from '../base';
import Base from 'stores/base';
export class PortStore extends Base {
get client() {
return client.neutron.ports;
}
get networkClient() {
return client.neutron.ports;
}
get routerClient() {
return client.neutron.routers;
}
async detailDidFetch(item) {
const { network_id } = item;
try {
const res = await client.neutron.networks.show(network_id);
const res = await this.networkClient.show(network_id);
item.network = res.network;
item.network_name = item.network.name;
return item;
@ -35,32 +42,10 @@ export class PortStore extends Base {
}
}
async listDidFetch(items, allProjects, filters) {
const { withPrice } = filters;
if (!withPrice) {
return items;
}
const networkIds = uniq(items.map((it) => it.network_id));
const networkResults = await Promise.all(
networkIds.map((it) => {
return client.neutron.networks.show(it);
})
);
const networks = networkResults.map((it) => it.network);
return items.map((it) => {
const network = networks.find((net) => net.id === it.network_id);
return {
...it,
network,
isExternalNetwork: isExternalNetwork(network),
};
});
}
async listDidFetchByFirewall(items) {
const [networkResult, routerResult] = await Promise.all([
client.neutron.networks.list(),
client.neutron.routers.list(),
this.networkClient.list(),
this.routerClient.list(),
]);
const { routers = [] } = routerResult;
const { networks = [] } = networkResult;

View File

@ -13,13 +13,17 @@
// limitations under the License.
import client from 'client';
import Base from '../base';
import Base from 'stores/base';
export class QoSPolicyStore extends Base {
get client() {
return client.neutron.qosPolicies;
}
get projectClient() {
return client.keystone.projects;
}
get listResponseKey() {
return 'policies';
}
@ -47,7 +51,7 @@ export class QoSPolicyStore extends Base {
get paramsFuncPage() {
return (params) => {
const { current, withPrice, withFIPPrice, ...rest } = params;
const { current, ...rest } = params;
return rest;
};
}
@ -93,8 +97,7 @@ export class QoSPolicyStore extends Base {
async detailDidFetch(item, all_projects) {
if (all_projects) {
item.project_name =
(await client.keystone.projects.show(item.project_id)).project.name ||
'-';
(await this.projectClient.show(item.project_id)).project.name || '-';
}
return item;
}

View File

@ -15,14 +15,22 @@
import { observable } from 'mobx';
import { PortStore } from 'stores/neutron/port';
import client from 'client';
import Base from '../base';
import globalNetworkStore from './network';
import Base from 'stores/base';
import globalNetworkStore from 'stores/neutron/network';
export class RouterStore extends Base {
get client() {
return client.neutron.routers;
}
get subnetClient() {
return client.neutron.subnets;
}
get portClient() {
return client.neutron.ports;
}
get listFilterByProject() {
return true;
}
@ -95,7 +103,7 @@ export class RouterStore extends Base {
}
async fetchConnectedSubnets(routerItem) {
const subnetResult = await client.neutron.subnets.list();
const subnetResult = await this.subnetClient.list();
const { subnets } = subnetResult;
const routerInterfaceList = [
'network:router_interface_distributed',
@ -161,7 +169,7 @@ export class RouterStore extends Base {
],
},
};
const port = await client.neutron.ports.create(portBody);
const port = await this.portClient.create(portBody);
const portId = port.port.id;
const newBody = {
port_id: portId,
@ -183,7 +191,7 @@ export class RouterStore extends Base {
const portParams = {
network_id: networkId,
};
const result = await client.neutron.ports.list(portParams);
const result = await this.portClient.list(portParams);
const port = result.ports.find((it) => {
const { fixed_ips: fixedIps } = it;
return (

View File

@ -15,8 +15,8 @@
import { action } from 'mobx';
import { mapperRule } from 'resources/security-group-rule';
import client from 'client';
import Base from '../base';
import globalProjectMapStore from '../project';
import Base from 'stores/base';
import globalProjectMapStore from 'stores/project';
export class SecurityGroupStore extends Base {
get client() {

View File

@ -14,7 +14,7 @@
import { mapperRule } from 'resources/security-group-rule';
import client from 'client';
import Base from '../base';
import Base from 'stores/base';
export class SecurityGroupRuleStore extends Base {
get client() {

View File

@ -15,7 +15,7 @@
import { action } from 'mobx';
import { get } from 'lodash';
import client from 'client';
import Base from '../base';
import Base from 'stores/base';
export class StaticRouteStore extends Base {
get client() {

View File

@ -14,7 +14,7 @@
import { action } from 'mobx';
import client from 'client';
import Base from '../base';
import Base from 'stores/base';
export class SubnetStore extends Base {
get client() {

View File

@ -17,8 +17,8 @@ import { action, observable, toJS } from 'mobx';
import globalSecurityGroupStore from 'stores/neutron/security-group';
import globalFloatingIpsStore from 'stores/neutron/floatingIp';
import client from 'client';
import List from '../base-list';
import Base from '../base';
import List from 'stores/base-list';
import Base from 'stores/base';
export class VirtualAdapterStore extends Base {
get client() {

View File

@ -13,7 +13,7 @@
// limitations under the License.
import client from 'client';
import Base from '../base';
import Base from 'stores/base';
export class VpnEndPointGroupStore extends Base {
get client() {

View File

@ -13,7 +13,7 @@
// limitations under the License.
import client from 'client';
import Base from '../base';
import Base from 'stores/base';
export class VpnIKEPolicyStore extends Base {
get client() {

View File

@ -17,7 +17,7 @@ import { get } from 'lodash';
import globalVpnIKEPolicyStore from 'stores/neutron/vpn-ike-policy';
import globalVpnIPSecPolicyStore from 'stores/neutron/vpn-ipsec-policy';
import client from 'client';
import Base from '../base';
import Base from 'stores/base';
export class VpnIPsecConnectionStore extends Base {
get client() {

View File

@ -13,7 +13,7 @@
// limitations under the License.
import client from 'client';
import Base from '../base';
import Base from 'stores/base';
export class VpnIPSecPolicyStore extends Base {
get client() {

View File

@ -13,7 +13,7 @@
// limitations under the License.
import client from 'client';
import Base from '../base';
import Base from 'stores/base';
export class VpnServicesStore extends Base {
get client() {

View File

@ -13,7 +13,7 @@
// limitations under the License.
import client from 'client';
import Base from '../base';
import Base from 'stores/base';
export class ActionLogStore extends Base {
get client() {

View File

@ -14,7 +14,7 @@
import { action } from 'mobx';
import client from 'client';
import Base from '../base';
import Base from 'stores/base';
export class AggregateStore extends Base {
get client() {

View File

@ -14,7 +14,7 @@
import { action } from 'mobx';
import client from 'client';
import Base from '../base';
import Base from 'stores/base';
export class ComputeHostStore extends Base {
get client() {

View File

@ -15,7 +15,7 @@
/* eslint-disable prefer-destructuring */
import { action, observable } from 'mobx';
import client from 'client';
import Base from '../base';
import Base from 'stores/base';
export class FlavorStore extends Base {
@observable
@ -84,7 +84,7 @@ export class FlavorStore extends Base {
get paramsFunc() {
return (params) => {
const { all_projects, name, withPrice, ...rest } = params;
const { all_projects, name, ...rest } = params;
if (all_projects) {
return {
...rest,

View File

@ -16,7 +16,7 @@ import { getGBValue } from 'utils/index';
import { action, observable } from 'mobx';
import { get } from 'lodash';
import client from 'client';
import Base from '../base';
import Base from 'stores/base';
export class HypervisorStore extends Base {
@observable

View File

@ -14,8 +14,7 @@
import { isOsDisk } from 'resources/volume';
import client from 'client';
import Base from '../base';
import globalVolumeTypeStore from '../cinder/volume-type';
import Base from 'stores/base';
export class InstanceVolumeStore extends Base {
get client() {
@ -30,15 +29,8 @@ export class InstanceVolumeStore extends Base {
get paramsFunc() {
return (params) => {
const {
id,
serverId,
all_projects,
projectId,
serverName,
withPrice,
...rest
} = params;
const { id, serverId, all_projects, projectId, serverName, ...rest } =
params;
return rest;
};
}
@ -65,7 +57,7 @@ export class InstanceVolumeStore extends Base {
if (items.length === 0) {
return items;
}
const { serverName, serverId, withPrice } = filters;
const { serverName, serverId } = filters;
const { project_id, project_name } = items[0];
const results = await Promise.all(
items.map((it) => {
@ -89,15 +81,6 @@ export class InstanceVolumeStore extends Base {
project_name,
};
});
if (withPrice) {
const volumeTypes = await globalVolumeTypeStore.fetchList({ withPrice });
volumes.forEach((item) => {
const { size, volume_type } = item;
const volumeType = volumeTypes.find((it) => it.name === volume_type);
const cost = volumeType ? (volumeType.priceCost * size).toFixed(2) : 0;
item.cost = cost;
});
}
return volumes;
}
}

View File

@ -15,7 +15,7 @@
import { action, observable } from 'mobx';
import { get } from 'lodash';
import client from 'client';
import Base from '../base';
import Base from 'stores/base';
import { RecycleBinStore } from '../skyline/recycle-server';
export class ServerStore extends Base {
@ -35,6 +35,22 @@ export class ServerStore extends Base {
return client.nova.servers;
}
get imageClient() {
return client.glance.images;
}
get portClient() {
return client.neutron.ports;
}
get networkClient() {
return client.neutron.networks;
}
get sgClient() {
return client.neutron.securityGroups;
}
get mapper() {
return (item) => {
item.status = item.status.toLowerCase();
@ -115,7 +131,7 @@ export class ServerStore extends Base {
return newData;
}
const { members, isServerGroup, host } = filters;
const isoImages = await client.glance.images.list({ disk_format: 'iso' });
const isoImages = await this.imageClient.list({ disk_format: 'iso' });
const { images } = isoImages;
if (images[0]) {
const imageId = images.map((it) => it.id);
@ -140,8 +156,8 @@ export class ServerStore extends Base {
this.interface.isLoading = true;
const params = { device_id: id };
const [resData, networks] = await Promise.all([
client.neutron.ports.list(params),
client.neutron.networks.list(),
this.portClient.list(params),
this.networkClient.list(),
]);
const interfaces = resData.ports;
const interfaceAll = [];
@ -167,7 +183,7 @@ export class ServerStore extends Base {
@action
async fetchSecurityGroup({ id }) {
this.securityGroups.isLoading = true;
const portResult = await client.neutron.ports.list({
const portResult = await this.portClient.list({
device_id: id,
});
const { ports = [] } = portResult;
@ -177,7 +193,7 @@ export class ServerStore extends Base {
let sgItems = [];
try {
const result = await Promise.all(
sgIds.map((it) => client.neutron.securityGroups.show(it))
sgIds.map((it) => this.sgClient.show(it))
);
sgItems = result.map((it) => it.security_group);
} catch (e) {}

View File

@ -13,7 +13,7 @@
// limitations under the License.
import client from 'client';
import Base from '../base';
import Base from 'stores/base';
export class KeypairStore extends Base {
get client() {

View File

@ -13,7 +13,7 @@
// limitations under the License.
import client from 'client';
import Base from '../base';
import Base from 'stores/base';
export class ServerGroupStore extends Base {
get client() {

View File

@ -15,7 +15,7 @@
import { action } from 'mobx';
import { isEmpty, isNull } from 'lodash';
import client from 'client';
import Base from '../base';
import Base from 'stores/base';
export class AvailabilityZoneStore extends Base {
get client() {

View File

@ -13,7 +13,7 @@
// limitations under the License.
import client from 'client';
import Base from '../base';
import Base from 'stores/base';
export class HealthMonitorStore extends Base {
get client() {

View File

@ -13,13 +13,17 @@
// limitations under the License.
import client from 'client';
import Base from '../base';
import Base from 'stores/base';
export class ListenerStore extends Base {
get client() {
return client.octavia.listeners;
}
get poolClient() {
return client.octavia.pools;
}
get listFilterByProject() {
return true;
}
@ -47,7 +51,7 @@ export class ListenerStore extends Base {
if (default_pool_id) {
// pool attach listener or loadbalancer
try {
const res = await client.octavia.pools.show(default_pool_id);
const res = await this.poolClient.show(default_pool_id);
item.default_pool = res.pool;
return item;
} catch (err) {

View File

@ -15,7 +15,7 @@
import { action } from 'mobx';
import { get } from 'lodash';
import client from 'client';
import Base from '../base';
import Base from 'stores/base';
export class LbaasStore extends Base {
get client() {

View File

@ -14,11 +14,15 @@
import { action } from 'mobx';
import client from 'client';
import Base from '../base';
import Base from 'stores/base';
export class PoolMemberStore extends Base {
get client() {
return client.octavia.pools.members;
return this.poolClient.members;
}
get poolClient() {
return client.octavia.pools;
}
get responseKey() {
@ -46,7 +50,7 @@ export class PoolMemberStore extends Base {
const body = {};
body[this.listResponseKey] = data;
return this.submitting(
client.octavia.pools.batchUpdateMembers(default_pool_id, body)
this.poolClient.batchUpdateMembers(default_pool_id, body)
);
}

View File

@ -13,7 +13,7 @@
// limitations under the License.
import client from 'client';
import Base from '../base';
import Base from 'stores/base';
export class PoolStore extends Base {
get client() {

View File

@ -16,10 +16,14 @@ import { action, observable } from 'mobx';
import { has } from 'lodash';
import client from 'client';
class ProjectMapStore {
export class ProjectMapStore {
@observable
projectMap = {};
get client() {
return client.keystone.projects;
}
@action
async fetchProjectDetail({ id }) {
const project = {
@ -28,7 +32,7 @@ class ProjectMapStore {
if (!has(this.projectMap, id)) {
let result = 'error';
try {
result = await client.keystone.projects.show(id);
result = await this.client.show(id);
} catch (e) {
// eslint-disable-next-line no-console
console.log(e);

View File

@ -146,14 +146,6 @@ export class RootStore {
const exp = getLocalTime(keystone_token_exp).valueOf();
setLocalStorageItem('keystone_token', keystone_token, 0, exp);
this.endpoints = endpoints;
this.checkBilling();
}
@action
checkBilling() {
const enableBilling =
this.checkLicense('billing') && this.checkEndpoint('billing_system');
this.enableBilling = enableBilling;
}
@action

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
import Base from '../base';
import Base from 'stores/base';
export class RecycleBinStore extends Base {
get responseKey() {

View File

@ -13,7 +13,7 @@
// limitations under the License.
import { groupArray } from 'utils/index';
import Base from '../base';
import Base from 'stores/base';
export class ServerGroupInstanceStore extends Base {
get listResponseKey() {

View File

@ -14,7 +14,7 @@
import { action } from 'mobx';
import client from 'client';
import Base from '../base';
import Base from 'stores/base';
export class SettingStore extends Base {
get client() {

View File

@ -14,7 +14,7 @@
import { action, observable } from 'mobx';
import client from 'client';
import Base from '../base';
import Base from 'stores/base';
export class SkylineStore extends Base {
@observable