From 49b07a6f70a4700d11ca3145163aa66d2a03435c Mon Sep 17 00:00:00 2001 From: "Jingwei.Zhang" Date: Tue, 7 Sep 2021 17:56:23 +0800 Subject: [PATCH] fix: Remove price codes && update stores 1. Remove useless codes related to prices 2. Update client usage in stores Change-Id: I1c717842b4f9918ab7e1665c99847aa6960b9e44 --- src/stores/base.js | 8 +- src/stores/cinder/backup.js | 4 +- src/stores/cinder/extra-spec.js | 2 +- src/stores/cinder/pool.js | 2 +- src/stores/cinder/qos-spec-key.js | 2 +- src/stores/cinder/qos-spec.js | 2 +- src/stores/cinder/service.js | 2 +- src/stores/cinder/snapshot.js | 10 +- src/stores/cinder/volume-type.js | 12 +- src/stores/cinder/volume.js | 35 ++--- src/stores/glance/image.js | 4 +- src/stores/glance/instance-snapshot.js | 156 -------------------- src/stores/glance/metadata.js | 2 +- src/stores/heat/event.js | 2 +- src/stores/heat/resource.js | 2 +- src/stores/heat/service.js | 2 +- src/stores/heat/stack.js | 2 +- src/stores/index.jsx | 40 +++-- src/stores/ironic/ironic.js | 8 +- src/stores/ironic/port-group.js | 2 +- src/stores/ironic/port.js | 8 +- src/stores/keystone/catalog.js | 2 +- src/stores/keystone/domain.js | 2 +- src/stores/keystone/project.js | 20 ++- src/stores/keystone/role.js | 2 +- src/stores/keystone/tag.js | 8 +- src/stores/keystone/user-group.js | 4 +- src/stores/keystone/user.js | 6 +- src/stores/neutron/agent-network.js | 2 +- src/stores/neutron/agent-router.js | 2 +- src/stores/neutron/agent.js | 2 +- src/stores/neutron/fixed-ip.js | 2 +- src/stores/neutron/floatingIp.js | 2 +- src/stores/neutron/network.js | 38 +++-- src/stores/neutron/neutron.js | 8 +- src/stores/neutron/port-forwarding.js | 2 +- src/stores/neutron/port.js | 41 ++--- src/stores/neutron/qos-policy.js | 11 +- src/stores/neutron/router.js | 18 ++- src/stores/neutron/security-group.js | 4 +- src/stores/neutron/security-rule.js | 2 +- src/stores/neutron/static-route.js | 2 +- src/stores/neutron/subnet.js | 2 +- src/stores/neutron/virtual-adapter.js | 4 +- src/stores/neutron/vpn-endpoint-group.js | 2 +- src/stores/neutron/vpn-ike-policy.js | 2 +- src/stores/neutron/vpn-ipsec-connection.js | 2 +- src/stores/neutron/vpn-ipsec-policy.js | 2 +- src/stores/neutron/vpn-service.js | 2 +- src/stores/nova/action-log.js | 2 +- src/stores/nova/aggregate.js | 2 +- src/stores/nova/compute-host.js | 2 +- src/stores/nova/flavor.js | 4 +- src/stores/nova/hypervisor.js | 2 +- src/stores/nova/instance-volume.js | 25 +--- src/stores/nova/instance.js | 28 +++- src/stores/nova/keypair.js | 2 +- src/stores/nova/server-group.js | 2 +- src/stores/nova/zone.js | 2 +- src/stores/octavia/health-monitor.js | 2 +- src/stores/octavia/listener.js | 8 +- src/stores/octavia/loadbalancer.js | 2 +- src/stores/octavia/pool-member.js | 10 +- src/stores/octavia/pool.js | 2 +- src/stores/project.js | 8 +- src/stores/root.js | 8 - src/stores/skyline/recycle-server.js | 2 +- src/stores/skyline/server-group-instance.js | 2 +- src/stores/skyline/setting.js | 2 +- src/stores/skyline/skyline.js | 2 +- 70 files changed, 255 insertions(+), 367 deletions(-) delete mode 100644 src/stores/glance/instance-snapshot.js diff --git a/src/stores/base.js b/src/stores/base.js index d07e1e8b..ffdc0a3f 100644 --- a/src/stores/base.js +++ b/src/stores/base.js @@ -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; }; } diff --git a/src/stores/cinder/backup.js b/src/stores/cinder/backup.js index 5cc25a14..83aa73d7 100644 --- a/src/stores/cinder/backup.js +++ b/src/stores/cinder/backup.js @@ -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() { diff --git a/src/stores/cinder/extra-spec.js b/src/stores/cinder/extra-spec.js index 5416f031..f358f4c5 100644 --- a/src/stores/cinder/extra-spec.js +++ b/src/stores/cinder/extra-spec.js @@ -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() { diff --git a/src/stores/cinder/pool.js b/src/stores/cinder/pool.js index af494ece..a517ab41 100644 --- a/src/stores/cinder/pool.js +++ b/src/stores/cinder/pool.js @@ -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() { diff --git a/src/stores/cinder/qos-spec-key.js b/src/stores/cinder/qos-spec-key.js index d16b0603..d297cc2d 100644 --- a/src/stores/cinder/qos-spec-key.js +++ b/src/stores/cinder/qos-spec-key.js @@ -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() { diff --git a/src/stores/cinder/qos-spec.js b/src/stores/cinder/qos-spec.js index 9fd2a926..23e483fb 100644 --- a/src/stores/cinder/qos-spec.js +++ b/src/stores/cinder/qos-spec.js @@ -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() { diff --git a/src/stores/cinder/service.js b/src/stores/cinder/service.js index ac2d7063..8b084eab 100644 --- a/src/stores/cinder/service.js +++ b/src/stores/cinder/service.js @@ -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() { diff --git a/src/stores/cinder/snapshot.js b/src/stores/cinder/snapshot.js index 00fa88a6..e2ecd8b6 100644 --- a/src/stores/cinder/snapshot.js +++ b/src/stores/cinder/snapshot.js @@ -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; } diff --git a/src/stores/cinder/volume-type.js b/src/stores/cinder/volume-type.js index a50fa194..f0326b7a 100644 --- a/src/stores/cinder/volume-type.js +++ b/src/stores/cinder/volume-type.js @@ -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) => { diff --git a/src/stores/cinder/volume.js b/src/stores/cinder/volume.js index b9c53bfb..3406facf 100644 --- a/src/stores/cinder/volume.js +++ b/src/stores/cinder/volume.js @@ -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; } diff --git a/src/stores/glance/image.js b/src/stores/glance/image.js index 39a554db..2002ee28 100644 --- a/src/stores/glance/image.js +++ b/src/stores/glance/image.js @@ -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', diff --git a/src/stores/glance/instance-snapshot.js b/src/stores/glance/instance-snapshot.js deleted file mode 100644 index 111c51e8..00000000 --- a/src/stores/glance/instance-snapshot.js +++ /dev/null @@ -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; diff --git a/src/stores/glance/metadata.js b/src/stores/glance/metadata.js index dcdd700b..396c9a6f 100644 --- a/src/stores/glance/metadata.js +++ b/src/stores/glance/metadata.js @@ -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 diff --git a/src/stores/heat/event.js b/src/stores/heat/event.js index 3c2c5fb8..691ad5b4 100644 --- a/src/stores/heat/event.js +++ b/src/stores/heat/event.js @@ -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() { diff --git a/src/stores/heat/resource.js b/src/stores/heat/resource.js index b963c908..5747dc61 100644 --- a/src/stores/heat/resource.js +++ b/src/stores/heat/resource.js @@ -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() { diff --git a/src/stores/heat/service.js b/src/stores/heat/service.js index d859e757..636c24e7 100644 --- a/src/stores/heat/service.js +++ b/src/stores/heat/service.js @@ -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() { diff --git a/src/stores/heat/stack.js b/src/stores/heat/stack.js index 4f089317..ff55080d 100644 --- a/src/stores/heat/stack.js +++ b/src/stores/heat/stack.js @@ -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 diff --git a/src/stores/index.jsx b/src/stores/index.jsx index f7dc2a7d..f1134dd6 100644 --- a/src/stores/index.jsx +++ b/src/stores/index.jsx @@ -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, diff --git a/src/stores/ironic/ironic.js b/src/stores/ironic/ironic.js index d986b68c..b93791da 100644 --- a/src/stores/ironic/ironic.js +++ b/src/stores/ironic/ironic.js @@ -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; diff --git a/src/stores/ironic/port-group.js b/src/stores/ironic/port-group.js index b8cda14c..97f2dca1 100644 --- a/src/stores/ironic/port-group.js +++ b/src/stores/ironic/port-group.js @@ -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() { diff --git a/src/stores/ironic/port.js b/src/stores/ironic/port.js index 5a85dc0f..abbcaac5 100644 --- a/src/stores/ironic/port.js +++ b/src/stores/ironic/port.js @@ -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() { diff --git a/src/stores/keystone/catalog.js b/src/stores/keystone/catalog.js index 0cf25136..438dccd8 100644 --- a/src/stores/keystone/catalog.js +++ b/src/stores/keystone/catalog.js @@ -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() { diff --git a/src/stores/keystone/domain.js b/src/stores/keystone/domain.js index b1efd451..7db4eca2 100644 --- a/src/stores/keystone/domain.js +++ b/src/stores/keystone/domain.js @@ -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 diff --git a/src/stores/keystone/project.js b/src/stores/keystone/project.js index 32c58b2c..0b9ad33a 100644 --- a/src/stores/keystone/project.js +++ b/src/stores/keystone/project.js @@ -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; diff --git a/src/stores/keystone/role.js b/src/stores/keystone/role.js index 1dae4604..99824acc 100644 --- a/src/stores/keystone/role.js +++ b/src/stores/keystone/role.js @@ -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() { diff --git a/src/stores/keystone/tag.js b/src/stores/keystone/tag.js index 3f77b788..f7274e39 100644 --- a/src/stores/keystone/tag.js +++ b/src/stores/keystone/tag.js @@ -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) ); } } diff --git a/src/stores/keystone/user-group.js b/src/stores/keystone/user-group.js index ddd46052..911e1f18 100644 --- a/src/stores/keystone/user-group.js +++ b/src/stores/keystone/user-group.js @@ -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 diff --git a/src/stores/keystone/user.js b/src/stores/keystone/user.js index d1a444fa..d2584b60 100644 --- a/src/stores/keystone/user.js +++ b/src/stores/keystone/user.js @@ -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 diff --git a/src/stores/neutron/agent-network.js b/src/stores/neutron/agent-network.js index 803ecc9c..5e1f25ef 100644 --- a/src/stores/neutron/agent-network.js +++ b/src/stores/neutron/agent-network.js @@ -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() { diff --git a/src/stores/neutron/agent-router.js b/src/stores/neutron/agent-router.js index 12a389a4..e6b0801e 100644 --- a/src/stores/neutron/agent-router.js +++ b/src/stores/neutron/agent-router.js @@ -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() { diff --git a/src/stores/neutron/agent.js b/src/stores/neutron/agent.js index 2281f425..fa2c1839 100644 --- a/src/stores/neutron/agent.js +++ b/src/stores/neutron/agent.js @@ -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() { diff --git a/src/stores/neutron/fixed-ip.js b/src/stores/neutron/fixed-ip.js index 72199bd2..af46a180 100644 --- a/src/stores/neutron/fixed-ip.js +++ b/src/stores/neutron/fixed-ip.js @@ -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() { diff --git a/src/stores/neutron/floatingIp.js b/src/stores/neutron/floatingIp.js index 9ff3a172..ded7dcc8 100644 --- a/src/stores/neutron/floatingIp.js +++ b/src/stores/neutron/floatingIp.js @@ -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() { diff --git a/src/stores/neutron/network.js b/src/stores/neutron/network.js index be870c92..38a2972a 100644 --- a/src/stores/neutron/network.js +++ b/src/stores/neutron/network.js @@ -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(); diff --git a/src/stores/neutron/neutron.js b/src/stores/neutron/neutron.js index 561610e0..b48b9231 100644 --- a/src/stores/neutron/neutron.js +++ b/src/stores/neutron/neutron.js @@ -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; diff --git a/src/stores/neutron/port-forwarding.js b/src/stores/neutron/port-forwarding.js index 81f9782f..af7f2fd8 100644 --- a/src/stores/neutron/port-forwarding.js +++ b/src/stores/neutron/port-forwarding.js @@ -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() { diff --git a/src/stores/neutron/port.js b/src/stores/neutron/port.js index 8f1a5149..bdfbb5e5 100644 --- a/src/stores/neutron/port.js +++ b/src/stores/neutron/port.js @@ -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; diff --git a/src/stores/neutron/qos-policy.js b/src/stores/neutron/qos-policy.js index b37df35a..45b32604 100644 --- a/src/stores/neutron/qos-policy.js +++ b/src/stores/neutron/qos-policy.js @@ -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; } diff --git a/src/stores/neutron/router.js b/src/stores/neutron/router.js index 974bba5f..a9d0fac8 100644 --- a/src/stores/neutron/router.js +++ b/src/stores/neutron/router.js @@ -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 ( diff --git a/src/stores/neutron/security-group.js b/src/stores/neutron/security-group.js index c4d36b0b..9873b1a0 100644 --- a/src/stores/neutron/security-group.js +++ b/src/stores/neutron/security-group.js @@ -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() { diff --git a/src/stores/neutron/security-rule.js b/src/stores/neutron/security-rule.js index 204af759..c356d0a1 100644 --- a/src/stores/neutron/security-rule.js +++ b/src/stores/neutron/security-rule.js @@ -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() { diff --git a/src/stores/neutron/static-route.js b/src/stores/neutron/static-route.js index 7933c527..e98380c8 100644 --- a/src/stores/neutron/static-route.js +++ b/src/stores/neutron/static-route.js @@ -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() { diff --git a/src/stores/neutron/subnet.js b/src/stores/neutron/subnet.js index bfac3595..cf340880 100644 --- a/src/stores/neutron/subnet.js +++ b/src/stores/neutron/subnet.js @@ -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() { diff --git a/src/stores/neutron/virtual-adapter.js b/src/stores/neutron/virtual-adapter.js index 328893af..1f5ff877 100644 --- a/src/stores/neutron/virtual-adapter.js +++ b/src/stores/neutron/virtual-adapter.js @@ -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() { diff --git a/src/stores/neutron/vpn-endpoint-group.js b/src/stores/neutron/vpn-endpoint-group.js index 95c68f75..d03f25bb 100644 --- a/src/stores/neutron/vpn-endpoint-group.js +++ b/src/stores/neutron/vpn-endpoint-group.js @@ -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() { diff --git a/src/stores/neutron/vpn-ike-policy.js b/src/stores/neutron/vpn-ike-policy.js index 7ce74911..d7125c6f 100644 --- a/src/stores/neutron/vpn-ike-policy.js +++ b/src/stores/neutron/vpn-ike-policy.js @@ -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() { diff --git a/src/stores/neutron/vpn-ipsec-connection.js b/src/stores/neutron/vpn-ipsec-connection.js index a75c623d..f476cb3e 100644 --- a/src/stores/neutron/vpn-ipsec-connection.js +++ b/src/stores/neutron/vpn-ipsec-connection.js @@ -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() { diff --git a/src/stores/neutron/vpn-ipsec-policy.js b/src/stores/neutron/vpn-ipsec-policy.js index 9a9347b7..781768b9 100644 --- a/src/stores/neutron/vpn-ipsec-policy.js +++ b/src/stores/neutron/vpn-ipsec-policy.js @@ -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() { diff --git a/src/stores/neutron/vpn-service.js b/src/stores/neutron/vpn-service.js index 1af87c49..6f9f3dcf 100644 --- a/src/stores/neutron/vpn-service.js +++ b/src/stores/neutron/vpn-service.js @@ -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() { diff --git a/src/stores/nova/action-log.js b/src/stores/nova/action-log.js index 1dd147f9..2e1eb3ff 100644 --- a/src/stores/nova/action-log.js +++ b/src/stores/nova/action-log.js @@ -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() { diff --git a/src/stores/nova/aggregate.js b/src/stores/nova/aggregate.js index 0d2685f3..559423af 100644 --- a/src/stores/nova/aggregate.js +++ b/src/stores/nova/aggregate.js @@ -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() { diff --git a/src/stores/nova/compute-host.js b/src/stores/nova/compute-host.js index 56705bbb..910f325b 100644 --- a/src/stores/nova/compute-host.js +++ b/src/stores/nova/compute-host.js @@ -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() { diff --git a/src/stores/nova/flavor.js b/src/stores/nova/flavor.js index 53d34370..9499e3fb 100644 --- a/src/stores/nova/flavor.js +++ b/src/stores/nova/flavor.js @@ -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, diff --git a/src/stores/nova/hypervisor.js b/src/stores/nova/hypervisor.js index c6c47dcb..080d19c3 100644 --- a/src/stores/nova/hypervisor.js +++ b/src/stores/nova/hypervisor.js @@ -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 diff --git a/src/stores/nova/instance-volume.js b/src/stores/nova/instance-volume.js index 0962f267..9c803229 100644 --- a/src/stores/nova/instance-volume.js +++ b/src/stores/nova/instance-volume.js @@ -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; } } diff --git a/src/stores/nova/instance.js b/src/stores/nova/instance.js index 82ba3b90..8865311a 100644 --- a/src/stores/nova/instance.js +++ b/src/stores/nova/instance.js @@ -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) {} diff --git a/src/stores/nova/keypair.js b/src/stores/nova/keypair.js index bc4c41ce..116a9415 100644 --- a/src/stores/nova/keypair.js +++ b/src/stores/nova/keypair.js @@ -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() { diff --git a/src/stores/nova/server-group.js b/src/stores/nova/server-group.js index 6f96b233..a761ef6a 100644 --- a/src/stores/nova/server-group.js +++ b/src/stores/nova/server-group.js @@ -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() { diff --git a/src/stores/nova/zone.js b/src/stores/nova/zone.js index 294af0fd..7a5a5507 100644 --- a/src/stores/nova/zone.js +++ b/src/stores/nova/zone.js @@ -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() { diff --git a/src/stores/octavia/health-monitor.js b/src/stores/octavia/health-monitor.js index 3c059849..432e84a1 100644 --- a/src/stores/octavia/health-monitor.js +++ b/src/stores/octavia/health-monitor.js @@ -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() { diff --git a/src/stores/octavia/listener.js b/src/stores/octavia/listener.js index 421ab28c..d5ce9c05 100644 --- a/src/stores/octavia/listener.js +++ b/src/stores/octavia/listener.js @@ -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) { diff --git a/src/stores/octavia/loadbalancer.js b/src/stores/octavia/loadbalancer.js index d73e45d3..6caa272c 100644 --- a/src/stores/octavia/loadbalancer.js +++ b/src/stores/octavia/loadbalancer.js @@ -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() { diff --git a/src/stores/octavia/pool-member.js b/src/stores/octavia/pool-member.js index 050e38f4..b90c43e0 100644 --- a/src/stores/octavia/pool-member.js +++ b/src/stores/octavia/pool-member.js @@ -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) ); } diff --git a/src/stores/octavia/pool.js b/src/stores/octavia/pool.js index 1f05cee3..0fd5d4a8 100644 --- a/src/stores/octavia/pool.js +++ b/src/stores/octavia/pool.js @@ -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() { diff --git a/src/stores/project.js b/src/stores/project.js index 58cd7019..0f1ada06 100644 --- a/src/stores/project.js +++ b/src/stores/project.js @@ -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); diff --git a/src/stores/root.js b/src/stores/root.js index d86ba04f..0a94a055 100644 --- a/src/stores/root.js +++ b/src/stores/root.js @@ -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 diff --git a/src/stores/skyline/recycle-server.js b/src/stores/skyline/recycle-server.js index b0ae58ab..5cf927e9 100644 --- a/src/stores/skyline/recycle-server.js +++ b/src/stores/skyline/recycle-server.js @@ -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() { diff --git a/src/stores/skyline/server-group-instance.js b/src/stores/skyline/server-group-instance.js index 74677128..ccec34ef 100644 --- a/src/stores/skyline/server-group-instance.js +++ b/src/stores/skyline/server-group-instance.js @@ -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() { diff --git a/src/stores/skyline/setting.js b/src/stores/skyline/setting.js index f02df2db..8ecf276e 100644 --- a/src/stores/skyline/setting.js +++ b/src/stores/skyline/setting.js @@ -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() { diff --git a/src/stores/skyline/skyline.js b/src/stores/skyline/skyline.js index 32fc3d48..c7912550 100644 --- a/src/stores/skyline/skyline.js +++ b/src/stores/skyline/skyline.js @@ -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