import { extendObservable, action } from 'mobx';
import client from 'client';
export default class OverviewStore {
constructor() {
extendObservable(this, {
projectInfoLoading: true,
computeServiceLoading: true,
networkServiceLoading: true,
computeService: [],
networkService: [],
platformNum: {
projectNum: 0,
userNum: 0,
nodeNum: 0,
},
});
}
@action
async getProjectInfoData() {
this.projectInfoLoading = true;
const promiseArray = [
client.keystone.projects.list(),
client.keystone.users.list(),
client.nova.services.list({ binary: 'nova-compute' }),
];
const [projectsResult, userResult, hostResult] = await Promise.all(
promiseArray
);
const { projects = [] } = projectsResult;
const { users = [] } = userResult;
const { services = [] } = hostResult;
this.platformNum.projectNum = projects.length;
this.platformNum.userNum = users.length;
this.platformNum.nodeNum = services.length;
this.projectInfoLoading = false;
}
@action
async getComputeService() {
this.computeServiceLoading = true;
const servicesResult = await client.nova.services.list();
const { services } = servicesResult;
this.computeService = services;
this.computeServiceLoading = false;
}
@action
async getNetworkService() {
this.networkServiceLoading = true;
const networkResult = await client.neutron.agents.list();
const { agents } = networkResult;
this.networkService = agents;
this.networkServiceLoading = false;
}
}