diff --git a/src/pages/base/containers/AdminOverview/components/ResourceOverview.jsx b/src/pages/base/containers/AdminOverview/components/ResourceOverview.jsx
index f6b78743..6bbbc50e 100644
--- a/src/pages/base/containers/AdminOverview/components/ResourceOverview.jsx
+++ b/src/pages/base/containers/AdminOverview/components/ResourceOverview.jsx
@@ -83,7 +83,7 @@ const volumeColors = {
export class virtualResourceInfo extends Component {
componentDidMount() {
- this.props.store.getVirtualResource();
+ this.props.store.getVirtualResourceOverview();
}
get card() {
diff --git a/src/pages/base/containers/AdminOverview/components/VirtualResource.jsx b/src/pages/base/containers/AdminOverview/components/VirtualResource.jsx
index b154715b..b8a304aa 100644
--- a/src/pages/base/containers/AdminOverview/components/VirtualResource.jsx
+++ b/src/pages/base/containers/AdminOverview/components/VirtualResource.jsx
@@ -15,7 +15,6 @@
import React, { Component } from 'react';
import { Row, Col, Card, Descriptions, Progress, Avatar } from 'antd';
import { inject, observer } from 'mobx-react';
-import globalHypervisorStore from 'stores/nova/hypervisor';
import styles from '../style.less';
export const resourceCircle = [
@@ -38,13 +37,8 @@ export const color = {
};
export class ResourceCircle extends Component {
- constructor(props) {
- super(props);
- this.store = globalHypervisorStore;
- }
-
componentDidMount() {
- this.store.getOverview();
+ this.props.store.getVirtualResource();
}
get resourceCircle() {
@@ -56,7 +50,7 @@ export class ResourceCircle extends Component {
}
renderCircle = (item, index) => {
- const { overview } = this.store;
+ const { overview } = this.props.store;
const resource = overview[item.resource];
const used = overview[item.used];
@@ -114,7 +108,7 @@ export class ResourceCircle extends Component {
};
render() {
- const { isLoading } = this.store;
+ const { isLoading } = this.props.store;
return (
;
+ return ;
}
renderResourceOverview() {
- return ;
+ return ;
}
renderComputeService() {
diff --git a/src/stores/nova/hypervisor.js b/src/stores/nova/hypervisor.js
index 5bff02d5..2ecf25b9 100644
--- a/src/stores/nova/hypervisor.js
+++ b/src/stores/nova/hypervisor.js
@@ -139,7 +139,7 @@ export class HypervisorStore extends Base {
}
@action
- getOverview = async () => {
+ getVirtualResource = async () => {
this.isLoading = true;
const hypervisorResult = await this.client.listDetail();
const { hypervisors } = hypervisorResult;
diff --git a/src/stores/nova/server.js b/src/stores/nova/server.js
new file mode 100644
index 00000000..6345a309
--- /dev/null
+++ b/src/stores/nova/server.js
@@ -0,0 +1,111 @@
+// 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 { action, extendObservable } from 'mobx';
+import client from 'client';
+import Base from 'stores/base';
+import globalRootStore from 'stores/root';
+
+export class ServerStore extends Base {
+ constructor() {
+ super();
+ extendObservable(this, {
+ virtualResource: {},
+ virtualResourceLoading: true,
+ });
+ }
+
+ get client() {
+ return client.nova.servers;
+ }
+
+ @action
+ async getVirtualResourceOverview() {
+ this.virtualResourceLoading = true;
+ const promiseArray = [
+ this.requestListAllByLimit({ all_tenants: true }, 1000),
+ this.requestListAllByLimit({ all_tenants: true, status: 'ACTIVE' }, 1000),
+ this.requestListAllByLimit({ all_tenants: true, status: 'ERROR' }, 1000),
+ this.requestListAllByLimit(
+ { all_tenants: true, status: 'SHUTOFF' },
+ 1000
+ ),
+ ];
+ if (globalRootStore.checkEndpoint('cinder')) {
+ const volumeResource = [
+ client.skyline.extension.volumes({ limit: 10, all_projects: true }),
+ client.skyline.extension.volumes({
+ limit: 10,
+ all_projects: true,
+ status: 'in-use',
+ }),
+ client.skyline.extension.volumes({
+ limit: 10,
+ all_projects: true,
+ status: 'error',
+ }),
+ client.skyline.extension.volumes({
+ limit: 10,
+ all_projects: true,
+ status: 'available',
+ }),
+ ];
+ promiseArray.push(...volumeResource);
+ }
+ const [
+ allServers,
+ activeServers,
+ errorServers,
+ shutoffServers,
+ allVolumes,
+ attachVolumes,
+ errorVolumes,
+ availableVolumes,
+ ] = await Promise.all(promiseArray);
+ const allServersCount = allServers.length;
+ const activeServersCount = activeServers.length;
+ const errorServersCount = errorServers.length;
+ const shutoffServersCount = shutoffServers.length;
+ const serviceNum = {
+ all: allServersCount,
+ active: activeServersCount,
+ error: errorServersCount,
+ shutoff: shutoffServersCount,
+ other:
+ allServersCount -
+ (activeServersCount + errorServersCount + shutoffServersCount),
+ };
+ this.virtualResource = { serviceNum };
+ if (globalRootStore.checkEndpoint('cinder')) {
+ const { count: allVolumesCount } = allVolumes;
+ const { count: attachVolumesCount } = attachVolumes;
+ const { count: errorVolumesCount } = errorVolumes;
+ const { count: availableVolumesCount } = availableVolumes;
+ const volumeNum = {
+ all: allVolumesCount,
+ active: attachVolumesCount,
+ error: errorVolumesCount,
+ available: availableVolumesCount,
+ other:
+ allVolumesCount -
+ (attachVolumesCount + errorVolumesCount + availableVolumesCount),
+ };
+ this.virtualResource.volumeNum = volumeNum;
+ }
+ this.virtualResourceLoading = false;
+ }
+}
+
+const globalServerStore = new ServerStore();
+export default globalServerStore;
diff --git a/src/stores/overview-admin.js b/src/stores/overview-admin.js
index a8f175f4..ef78fd99 100644
--- a/src/stores/overview-admin.js
+++ b/src/stores/overview-admin.js
@@ -14,41 +14,21 @@
import { extendObservable, action } from 'mobx';
import client from 'client';
-import globalRootStore from 'stores/root';
export default class OverviewStore {
constructor() {
- this.reset(true);
- }
-
- get initValue() {
- return {
+ extendObservable(this, {
projectInfoLoading: true,
computeServiceLoading: true,
networkServiceLoading: true,
- virtualResourceLoading: true,
computeService: [],
networkService: [],
- virtualResource: {},
platformNum: {
projectNum: 0,
userNum: 0,
nodeNum: 0,
},
- };
- }
-
- @action
- reset(init) {
- const state = this.initValue;
-
- if (init) {
- extendObservable(this, state);
- } else {
- Object.keys(state).forEach((key) => {
- this[key] = state[key];
- });
- }
+ });
}
@action
@@ -71,91 +51,6 @@ export default class OverviewStore {
this.projectInfoLoading = false;
}
- @action
- async getVirtualResource() {
- this.virtualResourceLoading = true;
- const promiseArray = [
- client.skyline.extension.servers({ limit: 10, all_projects: true }),
- client.skyline.extension.servers({
- limit: 10,
- all_projects: true,
- status: 'ACTIVE',
- }),
- client.skyline.extension.servers({
- limit: 10,
- all_projects: true,
- status: 'ERROR',
- }),
- client.skyline.extension.servers({
- limit: 10,
- all_projects: true,
- status: 'SHUTOFF',
- }),
- ];
- if (globalRootStore.checkEndpoint('cinder')) {
- const volumeResource = [
- client.skyline.extension.volumes({ limit: 10, all_projects: true }),
- client.skyline.extension.volumes({
- limit: 10,
- all_projects: true,
- status: 'in-use',
- }),
- client.skyline.extension.volumes({
- limit: 10,
- all_projects: true,
- status: 'error',
- }),
- client.skyline.extension.volumes({
- limit: 10,
- all_projects: true,
- status: 'available',
- }),
- ];
- promiseArray.push(...volumeResource);
- }
- const [
- allServers,
- activeServers,
- errorServers,
- shutoffServers,
- allVolumes,
- attachVolumes,
- errorVolumes,
- availableVolumes,
- ] = await Promise.all(promiseArray);
- const { count: allServersCount } = allServers;
- const { count: activeServersCount } = activeServers;
- const { count: errorServersCount } = errorServers;
- const { count: shutoffServersCount } = shutoffServers;
- const serviceNum = {
- all: allServersCount,
- active: activeServersCount,
- error: errorServersCount,
- shutoff: shutoffServersCount,
- other:
- allServersCount -
- (activeServersCount + errorServersCount + shutoffServersCount),
- };
- this.virtualResource = { serviceNum };
- if (globalRootStore.checkEndpoint('cinder')) {
- const { count: allVolumesCount } = allVolumes;
- const { count: attachVolumesCount } = attachVolumes;
- const { count: errorVolumesCount } = errorVolumes;
- const { count: availableVolumesCount } = availableVolumes;
- const volumeNum = {
- all: allVolumesCount,
- active: attachVolumesCount,
- error: errorVolumesCount,
- available: availableVolumesCount,
- other:
- allVolumesCount -
- (attachVolumesCount + errorVolumesCount + availableVolumesCount),
- };
- this.virtualResource.volumeNum = volumeNum;
- }
- this.virtualResourceLoading = false;
- }
-
@action
async getComputeService() {
this.computeServiceLoading = true;