blob: 1327422a30b743ea2bfed732b40eefb78e431a53 [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:
Yoshie Muranaka881ddc42020-04-21 19:24:29 -070013 case 'On': // Redfish PowerState
Yoshie Muranakadc04feb2019-12-04 08:41:22 -080014 return 'on';
15 case HOST_STATE.off:
Yoshie Muranaka881ddc42020-04-21 19:24:29 -070016 case 'Off': // Redfish PowerState
Yoshie Muranakadc04feb2019-12-04 08:41:22 -080017 return 'off';
18 case HOST_STATE.error:
Yoshie Muranakaa3cbc652020-05-13 12:55:48 -070019 case 'Quiesced': // Redfish Status
Yoshie Muranakadc04feb2019-12-04 08:41:22 -080020 return 'error';
Yoshie Muranakaa3cbc652020-05-13 12:55:48 -070021 case HOST_STATE.diagnosticMode:
22 case 'InTest': // Redfish Status
23 return 'diagnosticMode';
Yoshie Muranakadc04feb2019-12-04 08:41:22 -080024 default:
25 return 'unreachable';
26 }
27};
28
Yoshie Muranakab8b6f792019-12-03 14:47:32 -080029const GlobalStore = {
30 namespaced: true,
31 state: {
Yoshie Muranakae45f54b2020-03-26 15:23:34 -070032 bmcTime: null,
Yoshie Muranakadc04feb2019-12-04 08:41:22 -080033 hostStatus: 'unreachable'
Yoshie Muranakab8b6f792019-12-03 14:47:32 -080034 },
35 getters: {
Dixsie Wolmersf65ee342020-01-22 19:47:56 -060036 hostStatus: state => state.hostStatus,
37 bmcTime: state => state.bmcTime
Yoshie Muranakab8b6f792019-12-03 14:47:32 -080038 },
39 mutations: {
Dixsie Wolmersf65ee342020-01-22 19:47:56 -060040 setBmcTime: (state, bmcTime) => (state.bmcTime = bmcTime),
41 setHostStatus: (state, hostState) =>
Yoshie Muranaka1ace1d92020-02-06 13:47:28 -080042 (state.hostStatus = hostStateMapper(hostState))
Yoshie Muranakab8b6f792019-12-03 14:47:32 -080043 },
44 actions: {
Yoshie Muranaka598bf7e2020-05-01 12:26:00 -070045 async getBmcTime({ commit }) {
46 return await api
Yoshie Muranakaa371d202020-04-13 10:42:09 -070047 .get('/redfish/v1/Managers/bmc')
Dixsie Wolmersf65ee342020-01-22 19:47:56 -060048 .then(response => {
Yoshie Muranakaa371d202020-04-13 10:42:09 -070049 const bmcDateTime = response.data.DateTime;
50 const date = new Date(bmcDateTime);
Dixsie Wolmers97f41872020-02-23 15:56:16 -060051 commit('setBmcTime', date);
Dixsie Wolmersf65ee342020-01-22 19:47:56 -060052 })
53 .catch(error => console.log(error));
54 },
Yoshie Muranakadc04feb2019-12-04 08:41:22 -080055 getHostStatus({ commit }) {
56 api
Yoshie Muranaka881ddc42020-04-21 19:24:29 -070057 .get('/redfish/v1/Systems/system')
Yoshie Muranakaa3cbc652020-05-13 12:55:48 -070058 .then(({ data: { PowerState, Status: { State } = {} } } = {}) => {
59 if (State === 'Quiesced' || State === 'InTest') {
60 // OpenBMC's host state interface is mapped to 2 Redfish
61 // properties "Status""State" and "PowerState". Look first
62 // at State for certain cases.
63 commit('setHostStatus', State);
64 } else {
65 commit('setHostStatus', PowerState);
66 }
Yoshie Muranakadc04feb2019-12-04 08:41:22 -080067 })
68 .catch(error => console.log(error));
Yoshie Muranakab8b6f792019-12-03 14:47:32 -080069 }
70 }
71};
72
73export default GlobalStore;