blob: 18d5043d463eefb4eabc90e7642a29e397399af3 [file] [log] [blame]
Derick Montaguefded0d12019-12-11 06:16:40 -06001import api from '../api';
Yoshie Muranakab8b6f792019-12-03 14:47:32 -08002
Yoshie Muranakadc04feb2019-12-04 08:41:22 -08003const HOST_STATE = {
4 on: 'xyz.openbmc_project.State.Host.HostState.Running',
5 off: 'xyz.openbmc_project.State.Host.HostState.Off',
6 error: 'xyz.openbmc_project.State.Host.HostState.Quiesced',
7 diagnosticMode: 'xyz.openbmc_project.State.Host.HostState.DiagnosticMode'
8};
9
10const hostStateMapper = hostState => {
11 switch (hostState) {
12 case HOST_STATE.on:
13 return 'on';
14 case HOST_STATE.off:
15 return 'off';
16 case HOST_STATE.error:
17 return 'error';
18 // TODO: Add mapping for DiagnosticMode
19 default:
20 return 'unreachable';
21 }
22};
23
Yoshie Muranakab8b6f792019-12-03 14:47:32 -080024const GlobalStore = {
25 namespaced: true,
26 state: {
Derick Montaguefded0d12019-12-11 06:16:40 -060027 hostName: '--',
Dixsie Wolmersf65ee342020-01-22 19:47:56 -060028 bmcTime: null,
Yoshie Muranakadc04feb2019-12-04 08:41:22 -080029 hostStatus: 'unreachable'
Yoshie Muranakab8b6f792019-12-03 14:47:32 -080030 },
31 getters: {
Dixsie Wolmersf65ee342020-01-22 19:47:56 -060032 hostName: state => state.hostName,
33 hostStatus: state => state.hostStatus,
34 bmcTime: state => state.bmcTime
Yoshie Muranakab8b6f792019-12-03 14:47:32 -080035 },
36 mutations: {
Dixsie Wolmersf65ee342020-01-22 19:47:56 -060037 setHostName: (state, hostName) => (state.hostName = hostName),
38 setBmcTime: (state, bmcTime) => (state.bmcTime = bmcTime),
39 setHostStatus: (state, hostState) =>
40 (state.hostState = hostStateMapper(hostState))
Yoshie Muranakab8b6f792019-12-03 14:47:32 -080041 },
42 actions: {
43 getHostName({ commit }) {
44 api
Derick Montaguefded0d12019-12-11 06:16:40 -060045 .get('/xyz/openbmc_project/network/config/attr/HostName')
Yoshie Muranakab8b6f792019-12-03 14:47:32 -080046 .then(response => {
47 const hostName = response.data.data;
Derick Montaguefded0d12019-12-11 06:16:40 -060048 commit('setHostName', hostName);
Yoshie Muranakab8b6f792019-12-03 14:47:32 -080049 })
50 .catch(error => console.log(error));
Yoshie Muranakadc04feb2019-12-04 08:41:22 -080051 },
Dixsie Wolmersf65ee342020-01-22 19:47:56 -060052 getBmcTime({ commit }) {
53 api
54 .get('/xyz/openbmc_project/time/bmc')
55 .then(response => {
56 // bmcTime is stored in microseconds, convert to millseconds
57 const bmcTime = response.data.data.Elapsed / 1000;
58 commit('setBmcTime', bmcTime);
59 })
60 .catch(error => console.log(error));
61 },
Yoshie Muranakadc04feb2019-12-04 08:41:22 -080062 getHostStatus({ commit }) {
63 api
64 .get('/xyz/openbmc_project/state/host0/attr/CurrentHostState')
65 .then(response => {
66 const hostState = response.data.data;
67 commit('setHostStatus', hostState);
68 })
69 .catch(error => console.log(error));
Yoshie Muranakab8b6f792019-12-03 14:47:32 -080070 }
71 }
72};
73
74export default GlobalStore;