blob: 879d8d8954c0e54c244933e97ebf76f963faf9c5 [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 Muranaka881ddc42020-04-21 19:24:29 -070019 // TODO: Map Redfish Quiesced when bmcweb supports
Yoshie Muranakadc04feb2019-12-04 08:41:22 -080020 return 'error';
21 // TODO: Add mapping for DiagnosticMode
22 default:
23 return 'unreachable';
24 }
25};
26
Yoshie Muranakab8b6f792019-12-03 14:47:32 -080027const GlobalStore = {
28 namespaced: true,
29 state: {
Yoshie Muranakae45f54b2020-03-26 15:23:34 -070030 bmcTime: null,
Yoshie Muranakadc04feb2019-12-04 08:41:22 -080031 hostStatus: 'unreachable'
Yoshie Muranakab8b6f792019-12-03 14:47:32 -080032 },
33 getters: {
Dixsie Wolmersf65ee342020-01-22 19:47:56 -060034 hostStatus: state => state.hostStatus,
35 bmcTime: state => state.bmcTime
Yoshie Muranakab8b6f792019-12-03 14:47:32 -080036 },
37 mutations: {
Dixsie Wolmersf65ee342020-01-22 19:47:56 -060038 setBmcTime: (state, bmcTime) => (state.bmcTime = bmcTime),
39 setHostStatus: (state, hostState) =>
Yoshie Muranaka1ace1d92020-02-06 13:47:28 -080040 (state.hostStatus = hostStateMapper(hostState))
Yoshie Muranakab8b6f792019-12-03 14:47:32 -080041 },
42 actions: {
Yoshie Muranaka598bf7e2020-05-01 12:26:00 -070043 async getBmcTime({ commit }) {
44 return await api
Yoshie Muranakaa371d202020-04-13 10:42:09 -070045 .get('/redfish/v1/Managers/bmc')
Dixsie Wolmersf65ee342020-01-22 19:47:56 -060046 .then(response => {
Yoshie Muranakaa371d202020-04-13 10:42:09 -070047 const bmcDateTime = response.data.DateTime;
48 const date = new Date(bmcDateTime);
Dixsie Wolmers97f41872020-02-23 15:56:16 -060049 commit('setBmcTime', date);
Dixsie Wolmersf65ee342020-01-22 19:47:56 -060050 })
51 .catch(error => console.log(error));
52 },
Yoshie Muranakadc04feb2019-12-04 08:41:22 -080053 getHostStatus({ commit }) {
54 api
Yoshie Muranaka881ddc42020-04-21 19:24:29 -070055 .get('/redfish/v1/Systems/system')
56 .then(({ data: { PowerState } } = {}) => {
57 commit('setHostStatus', PowerState);
Yoshie Muranakadc04feb2019-12-04 08:41:22 -080058 })
59 .catch(error => console.log(error));
Yoshie Muranakab8b6f792019-12-03 14:47:32 -080060 }
61 }
62};
63
64export default GlobalStore;