SurenNeware | 6185909 | 2020-10-01 09:37:32 +0530 | [diff] [blame^] | 1 | import api from '@/store/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', |
Sukanya Pandey | b1f559f | 2020-04-28 20:18:28 +0530 | [diff] [blame] | 34 | languagePreference: localStorage.getItem('storedLanguage') || 'en-US', |
Sukanya Pandey | fc16f3c | 2020-06-23 22:54:27 +0530 | [diff] [blame] | 35 | isUtcDisplay: localStorage.getItem('storedUtcDisplay') |
| 36 | ? JSON.parse(localStorage.getItem('storedUtcDisplay')) |
| 37 | : true, |
Sukanya Pandey | b1f559f | 2020-04-28 20:18:28 +0530 | [diff] [blame] | 38 | username: localStorage.getItem('storedUsername') |
Yoshie Muranaka | b8b6f79 | 2019-12-03 14:47:32 -0800 | [diff] [blame] | 39 | }, |
| 40 | getters: { |
Dixsie Wolmers | f65ee34 | 2020-01-22 19:47:56 -0600 | [diff] [blame] | 41 | hostStatus: state => state.hostStatus, |
Yoshie Muranaka | 68bbba2 | 2020-05-18 09:49:37 -0700 | [diff] [blame] | 42 | bmcTime: state => state.bmcTime, |
Sukanya Pandey | b1f559f | 2020-04-28 20:18:28 +0530 | [diff] [blame] | 43 | languagePreference: state => state.languagePreference, |
Sukanya Pandey | fc16f3c | 2020-06-23 22:54:27 +0530 | [diff] [blame] | 44 | isUtcDisplay: state => state.isUtcDisplay, |
Sukanya Pandey | b1f559f | 2020-04-28 20:18:28 +0530 | [diff] [blame] | 45 | username: state => state.username |
Yoshie Muranaka | b8b6f79 | 2019-12-03 14:47:32 -0800 | [diff] [blame] | 46 | }, |
| 47 | mutations: { |
Dixsie Wolmers | f65ee34 | 2020-01-22 19:47:56 -0600 | [diff] [blame] | 48 | setBmcTime: (state, bmcTime) => (state.bmcTime = bmcTime), |
| 49 | setHostStatus: (state, hostState) => |
Yoshie Muranaka | 68bbba2 | 2020-05-18 09:49:37 -0700 | [diff] [blame] | 50 | (state.hostStatus = hostStateMapper(hostState)), |
| 51 | setLanguagePreference: (state, language) => |
Sukanya Pandey | b1f559f | 2020-04-28 20:18:28 +0530 | [diff] [blame] | 52 | (state.languagePreference = language), |
Sukanya Pandey | fc16f3c | 2020-06-23 22:54:27 +0530 | [diff] [blame] | 53 | setUsername: (state, username) => (state.username = username), |
| 54 | setUtcTime: (state, isUtcDisplay) => (state.isUtcDisplay = isUtcDisplay) |
Yoshie Muranaka | b8b6f79 | 2019-12-03 14:47:32 -0800 | [diff] [blame] | 55 | }, |
| 56 | actions: { |
Yoshie Muranaka | 598bf7e | 2020-05-01 12:26:00 -0700 | [diff] [blame] | 57 | async getBmcTime({ commit }) { |
| 58 | return await api |
Yoshie Muranaka | a371d20 | 2020-04-13 10:42:09 -0700 | [diff] [blame] | 59 | .get('/redfish/v1/Managers/bmc') |
Dixsie Wolmers | f65ee34 | 2020-01-22 19:47:56 -0600 | [diff] [blame] | 60 | .then(response => { |
Yoshie Muranaka | a371d20 | 2020-04-13 10:42:09 -0700 | [diff] [blame] | 61 | const bmcDateTime = response.data.DateTime; |
| 62 | const date = new Date(bmcDateTime); |
Dixsie Wolmers | 97f4187 | 2020-02-23 15:56:16 -0600 | [diff] [blame] | 63 | commit('setBmcTime', date); |
Dixsie Wolmers | f65ee34 | 2020-01-22 19:47:56 -0600 | [diff] [blame] | 64 | }) |
| 65 | .catch(error => console.log(error)); |
| 66 | }, |
Yoshie Muranaka | dc04feb | 2019-12-04 08:41:22 -0800 | [diff] [blame] | 67 | getHostStatus({ commit }) { |
| 68 | api |
Yoshie Muranaka | 881ddc4 | 2020-04-21 19:24:29 -0700 | [diff] [blame] | 69 | .get('/redfish/v1/Systems/system') |
Yoshie Muranaka | a3cbc65 | 2020-05-13 12:55:48 -0700 | [diff] [blame] | 70 | .then(({ data: { PowerState, Status: { State } = {} } } = {}) => { |
| 71 | if (State === 'Quiesced' || State === 'InTest') { |
| 72 | // OpenBMC's host state interface is mapped to 2 Redfish |
| 73 | // properties "Status""State" and "PowerState". Look first |
| 74 | // at State for certain cases. |
| 75 | commit('setHostStatus', State); |
| 76 | } else { |
| 77 | commit('setHostStatus', PowerState); |
| 78 | } |
Yoshie Muranaka | dc04feb | 2019-12-04 08:41:22 -0800 | [diff] [blame] | 79 | }) |
| 80 | .catch(error => console.log(error)); |
Yoshie Muranaka | b8b6f79 | 2019-12-03 14:47:32 -0800 | [diff] [blame] | 81 | } |
| 82 | } |
| 83 | }; |
| 84 | |
| 85 | export default GlobalStore; |