blob: 42e9e2bf9a15f7efcf9a12beeff85d09b29e68f5 [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 Muranaka68bbba22020-05-18 09:49:37 -070033 hostStatus: 'unreachable',
34 languagePreference: localStorage.getItem('storedLanguage') || 'en-US'
Yoshie Muranakab8b6f792019-12-03 14:47:32 -080035 },
36 getters: {
Dixsie Wolmersf65ee342020-01-22 19:47:56 -060037 hostStatus: state => state.hostStatus,
Yoshie Muranaka68bbba22020-05-18 09:49:37 -070038 bmcTime: state => state.bmcTime,
39 languagePreference: state => state.languagePreference
Yoshie Muranakab8b6f792019-12-03 14:47:32 -080040 },
41 mutations: {
Dixsie Wolmersf65ee342020-01-22 19:47:56 -060042 setBmcTime: (state, bmcTime) => (state.bmcTime = bmcTime),
43 setHostStatus: (state, hostState) =>
Yoshie Muranaka68bbba22020-05-18 09:49:37 -070044 (state.hostStatus = hostStateMapper(hostState)),
45 setLanguagePreference: (state, language) =>
46 (state.languagePreference = language)
Yoshie Muranakab8b6f792019-12-03 14:47:32 -080047 },
48 actions: {
Yoshie Muranaka598bf7e2020-05-01 12:26:00 -070049 async getBmcTime({ commit }) {
50 return await api
Yoshie Muranakaa371d202020-04-13 10:42:09 -070051 .get('/redfish/v1/Managers/bmc')
Dixsie Wolmersf65ee342020-01-22 19:47:56 -060052 .then(response => {
Yoshie Muranakaa371d202020-04-13 10:42:09 -070053 const bmcDateTime = response.data.DateTime;
54 const date = new Date(bmcDateTime);
Dixsie Wolmers97f41872020-02-23 15:56:16 -060055 commit('setBmcTime', date);
Dixsie Wolmersf65ee342020-01-22 19:47:56 -060056 })
57 .catch(error => console.log(error));
58 },
Yoshie Muranakadc04feb2019-12-04 08:41:22 -080059 getHostStatus({ commit }) {
60 api
Yoshie Muranaka881ddc42020-04-21 19:24:29 -070061 .get('/redfish/v1/Systems/system')
Yoshie Muranakaa3cbc652020-05-13 12:55:48 -070062 .then(({ data: { PowerState, Status: { State } = {} } } = {}) => {
63 if (State === 'Quiesced' || State === 'InTest') {
64 // OpenBMC's host state interface is mapped to 2 Redfish
65 // properties "Status""State" and "PowerState". Look first
66 // at State for certain cases.
67 commit('setHostStatus', State);
68 } else {
69 commit('setHostStatus', PowerState);
70 }
Yoshie Muranakadc04feb2019-12-04 08:41:22 -080071 })
72 .catch(error => console.log(error));
Yoshie Muranakab8b6f792019-12-03 14:47:32 -080073 }
74 }
75};
76
77export default GlobalStore;