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: |
| 13 | return 'on'; |
| 14 | case HOST_STATE.off: |
| 15 | return 'off'; |
| 16 | case HOST_STATE.error: |
| 17 | return 'error'; |
| 18 | // TODO: Add mapping for DiagnosticMode |
| 19 | default: |
| 20 | return 'unreachable'; |
| 21 | } |
| 22 | }; |
| 23 | |
Yoshie Muranaka | b8b6f79 | 2019-12-03 14:47:32 -0800 | [diff] [blame] | 24 | const GlobalStore = { |
| 25 | namespaced: true, |
| 26 | state: { |
Derick Montague | fded0d1 | 2019-12-11 06:16:40 -0600 | [diff] [blame] | 27 | hostName: '--', |
Dixsie Wolmers | f65ee34 | 2020-01-22 19:47:56 -0600 | [diff] [blame] | 28 | bmcTime: null, |
Yoshie Muranaka | dc04feb | 2019-12-04 08:41:22 -0800 | [diff] [blame] | 29 | hostStatus: 'unreachable' |
Yoshie Muranaka | b8b6f79 | 2019-12-03 14:47:32 -0800 | [diff] [blame] | 30 | }, |
| 31 | getters: { |
Dixsie Wolmers | f65ee34 | 2020-01-22 19:47:56 -0600 | [diff] [blame] | 32 | hostName: state => state.hostName, |
| 33 | hostStatus: state => state.hostStatus, |
| 34 | bmcTime: state => state.bmcTime |
Yoshie Muranaka | b8b6f79 | 2019-12-03 14:47:32 -0800 | [diff] [blame] | 35 | }, |
| 36 | mutations: { |
Dixsie Wolmers | f65ee34 | 2020-01-22 19:47:56 -0600 | [diff] [blame] | 37 | setHostName: (state, hostName) => (state.hostName = hostName), |
| 38 | setBmcTime: (state, bmcTime) => (state.bmcTime = bmcTime), |
| 39 | setHostStatus: (state, hostState) => |
| 40 | (state.hostState = hostStateMapper(hostState)) |
Yoshie Muranaka | b8b6f79 | 2019-12-03 14:47:32 -0800 | [diff] [blame] | 41 | }, |
| 42 | actions: { |
| 43 | getHostName({ commit }) { |
| 44 | api |
Derick Montague | fded0d1 | 2019-12-11 06:16:40 -0600 | [diff] [blame] | 45 | .get('/xyz/openbmc_project/network/config/attr/HostName') |
Yoshie Muranaka | b8b6f79 | 2019-12-03 14:47:32 -0800 | [diff] [blame] | 46 | .then(response => { |
| 47 | const hostName = response.data.data; |
Derick Montague | fded0d1 | 2019-12-11 06:16:40 -0600 | [diff] [blame] | 48 | commit('setHostName', hostName); |
Yoshie Muranaka | b8b6f79 | 2019-12-03 14:47:32 -0800 | [diff] [blame] | 49 | }) |
| 50 | .catch(error => console.log(error)); |
Yoshie Muranaka | dc04feb | 2019-12-04 08:41:22 -0800 | [diff] [blame] | 51 | }, |
Dixsie Wolmers | f65ee34 | 2020-01-22 19:47:56 -0600 | [diff] [blame] | 52 | getBmcTime({ commit }) { |
| 53 | api |
| 54 | .get('/xyz/openbmc_project/time/bmc') |
| 55 | .then(response => { |
| 56 | // bmcTime is stored in microseconds, convert to millseconds |
| 57 | const bmcTime = response.data.data.Elapsed / 1000; |
| 58 | commit('setBmcTime', bmcTime); |
| 59 | }) |
| 60 | .catch(error => console.log(error)); |
| 61 | }, |
Yoshie Muranaka | dc04feb | 2019-12-04 08:41:22 -0800 | [diff] [blame] | 62 | getHostStatus({ commit }) { |
| 63 | api |
| 64 | .get('/xyz/openbmc_project/state/host0/attr/CurrentHostState') |
| 65 | .then(response => { |
| 66 | const hostState = response.data.data; |
| 67 | commit('setHostStatus', hostState); |
| 68 | }) |
| 69 | .catch(error => console.log(error)); |
Yoshie Muranaka | b8b6f79 | 2019-12-03 14:47:32 -0800 | [diff] [blame] | 70 | } |
| 71 | } |
| 72 | }; |
| 73 | |
| 74 | export default GlobalStore; |