Derick Montague | fded0d1 | 2019-12-11 06:16:40 -0600 | [diff] [blame] | 1 | import api from '../api'; |
Yoshie Muranaka | b8b6f79 | 2019-12-03 14:47:32 -0800 | [diff] [blame] | 2 | |
Yoshie Muranaka | dc04feb | 2019-12-04 08:41:22 -0800 | [diff] [blame] | 3 | const 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 | |
| 10 | const hostStateMapper = hostState => { |
| 11 | switch (hostState) { |
| 12 | case HOST_STATE.on: |
Yoshie Muranaka | 881ddc4 | 2020-04-21 19:24:29 -0700 | [diff] [blame] | 13 | case 'On': // Redfish PowerState |
Yoshie Muranaka | dc04feb | 2019-12-04 08:41:22 -0800 | [diff] [blame] | 14 | return 'on'; |
| 15 | case HOST_STATE.off: |
Yoshie Muranaka | 881ddc4 | 2020-04-21 19:24:29 -0700 | [diff] [blame] | 16 | case 'Off': // Redfish PowerState |
Yoshie Muranaka | dc04feb | 2019-12-04 08:41:22 -0800 | [diff] [blame] | 17 | return 'off'; |
| 18 | case HOST_STATE.error: |
Yoshie Muranaka | a3cbc65 | 2020-05-13 12:55:48 -0700 | [diff] [blame] | 19 | case 'Quiesced': // Redfish Status |
Yoshie Muranaka | dc04feb | 2019-12-04 08:41:22 -0800 | [diff] [blame] | 20 | return 'error'; |
Yoshie Muranaka | a3cbc65 | 2020-05-13 12:55:48 -0700 | [diff] [blame] | 21 | case HOST_STATE.diagnosticMode: |
| 22 | case 'InTest': // Redfish Status |
| 23 | return 'diagnosticMode'; |
Yoshie Muranaka | dc04feb | 2019-12-04 08:41:22 -0800 | [diff] [blame] | 24 | default: |
| 25 | return 'unreachable'; |
| 26 | } |
| 27 | }; |
| 28 | |
Yoshie Muranaka | b8b6f79 | 2019-12-03 14:47:32 -0800 | [diff] [blame] | 29 | const GlobalStore = { |
| 30 | namespaced: true, |
| 31 | state: { |
Yoshie Muranaka | e45f54b | 2020-03-26 15:23:34 -0700 | [diff] [blame] | 32 | bmcTime: null, |
Yoshie Muranaka | 68bbba2 | 2020-05-18 09:49:37 -0700 | [diff] [blame] | 33 | hostStatus: 'unreachable', |
| 34 | languagePreference: localStorage.getItem('storedLanguage') || 'en-US' |
Yoshie Muranaka | b8b6f79 | 2019-12-03 14:47:32 -0800 | [diff] [blame] | 35 | }, |
| 36 | getters: { |
Dixsie Wolmers | f65ee34 | 2020-01-22 19:47:56 -0600 | [diff] [blame] | 37 | hostStatus: state => state.hostStatus, |
Yoshie Muranaka | 68bbba2 | 2020-05-18 09:49:37 -0700 | [diff] [blame] | 38 | bmcTime: state => state.bmcTime, |
| 39 | languagePreference: state => state.languagePreference |
Yoshie Muranaka | b8b6f79 | 2019-12-03 14:47:32 -0800 | [diff] [blame] | 40 | }, |
| 41 | mutations: { |
Dixsie Wolmers | f65ee34 | 2020-01-22 19:47:56 -0600 | [diff] [blame] | 42 | setBmcTime: (state, bmcTime) => (state.bmcTime = bmcTime), |
| 43 | setHostStatus: (state, hostState) => |
Yoshie Muranaka | 68bbba2 | 2020-05-18 09:49:37 -0700 | [diff] [blame] | 44 | (state.hostStatus = hostStateMapper(hostState)), |
| 45 | setLanguagePreference: (state, language) => |
| 46 | (state.languagePreference = language) |
Yoshie Muranaka | b8b6f79 | 2019-12-03 14:47:32 -0800 | [diff] [blame] | 47 | }, |
| 48 | actions: { |
Yoshie Muranaka | 598bf7e | 2020-05-01 12:26:00 -0700 | [diff] [blame] | 49 | async getBmcTime({ commit }) { |
| 50 | return await api |
Yoshie Muranaka | a371d20 | 2020-04-13 10:42:09 -0700 | [diff] [blame] | 51 | .get('/redfish/v1/Managers/bmc') |
Dixsie Wolmers | f65ee34 | 2020-01-22 19:47:56 -0600 | [diff] [blame] | 52 | .then(response => { |
Yoshie Muranaka | a371d20 | 2020-04-13 10:42:09 -0700 | [diff] [blame] | 53 | const bmcDateTime = response.data.DateTime; |
| 54 | const date = new Date(bmcDateTime); |
Dixsie Wolmers | 97f4187 | 2020-02-23 15:56:16 -0600 | [diff] [blame] | 55 | commit('setBmcTime', date); |
Dixsie Wolmers | f65ee34 | 2020-01-22 19:47:56 -0600 | [diff] [blame] | 56 | }) |
| 57 | .catch(error => console.log(error)); |
| 58 | }, |
Yoshie Muranaka | dc04feb | 2019-12-04 08:41:22 -0800 | [diff] [blame] | 59 | getHostStatus({ commit }) { |
| 60 | api |
Yoshie Muranaka | 881ddc4 | 2020-04-21 19:24:29 -0700 | [diff] [blame] | 61 | .get('/redfish/v1/Systems/system') |
Yoshie Muranaka | a3cbc65 | 2020-05-13 12:55:48 -0700 | [diff] [blame] | 62 | .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 Muranaka | dc04feb | 2019-12-04 08:41:22 -0800 | [diff] [blame] | 71 | }) |
| 72 | .catch(error => console.log(error)); |
Yoshie Muranaka | b8b6f79 | 2019-12-03 14:47:32 -0800 | [diff] [blame] | 73 | } |
| 74 | } |
| 75 | }; |
| 76 | |
| 77 | export default GlobalStore; |