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', |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 7 | diagnosticMode: 'xyz.openbmc_project.State.Host.HostState.DiagnosticMode', |
Yoshie Muranaka | dc04feb | 2019-12-04 08:41:22 -0800 | [diff] [blame] | 8 | }; |
| 9 | |
Derick Montague | 71114fe | 2021-05-06 18:17:34 -0500 | [diff] [blame] | 10 | const serverStateMapper = (hostState) => { |
Yoshie Muranaka | dc04feb | 2019-12-04 08:41:22 -0800 | [diff] [blame] | 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: { |
Sukanya Pandey | c5c2ae9 | 2020-12-09 16:14:19 +0530 | [diff] [blame] | 32 | assetTag: null, |
Yoshie Muranaka | e45f54b | 2020-03-26 15:23:34 -0700 | [diff] [blame] | 33 | bmcTime: null, |
Sukanya Pandey | 4dd7eab | 2021-08-16 18:59:14 +0530 | [diff] [blame] | 34 | modelType: null, |
| 35 | serialNumber: null, |
Derick Montague | 71114fe | 2021-05-06 18:17:34 -0500 | [diff] [blame] | 36 | serverStatus: 'unreachable', |
Sukanya Pandey | b1f559f | 2020-04-28 20:18:28 +0530 | [diff] [blame] | 37 | languagePreference: localStorage.getItem('storedLanguage') || 'en-US', |
Sukanya Pandey | fc16f3c | 2020-06-23 22:54:27 +0530 | [diff] [blame] | 38 | isUtcDisplay: localStorage.getItem('storedUtcDisplay') |
| 39 | ? JSON.parse(localStorage.getItem('storedUtcDisplay')) |
| 40 | : true, |
Sukanya Pandey | dd6aa0a | 2020-10-08 20:47:39 +0530 | [diff] [blame] | 41 | username: localStorage.getItem('storedUsername'), |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 42 | isAuthorized: true, |
Yoshie Muranaka | b8b6f79 | 2019-12-03 14:47:32 -0800 | [diff] [blame] | 43 | }, |
| 44 | getters: { |
Sukanya Pandey | c5c2ae9 | 2020-12-09 16:14:19 +0530 | [diff] [blame] | 45 | assetTag: (state) => state.assetTag, |
Sukanya Pandey | 4dd7eab | 2021-08-16 18:59:14 +0530 | [diff] [blame] | 46 | modelType: (state) => state.modelType, |
| 47 | serialNumber: (state) => state.serialNumber, |
Derick Montague | 71114fe | 2021-05-06 18:17:34 -0500 | [diff] [blame] | 48 | serverStatus: (state) => state.serverStatus, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 49 | bmcTime: (state) => state.bmcTime, |
| 50 | languagePreference: (state) => state.languagePreference, |
| 51 | isUtcDisplay: (state) => state.isUtcDisplay, |
| 52 | username: (state) => state.username, |
| 53 | isAuthorized: (state) => state.isAuthorized, |
Yoshie Muranaka | b8b6f79 | 2019-12-03 14:47:32 -0800 | [diff] [blame] | 54 | }, |
| 55 | mutations: { |
Sukanya Pandey | c5c2ae9 | 2020-12-09 16:14:19 +0530 | [diff] [blame] | 56 | setAssetTag: (state, assetTag) => (state.assetTag = assetTag), |
Sukanya Pandey | 4dd7eab | 2021-08-16 18:59:14 +0530 | [diff] [blame] | 57 | setModelType: (state, modelType) => (state.modelType = modelType), |
| 58 | setSerialNumber: (state, serialNumber) => |
| 59 | (state.serialNumber = serialNumber), |
Dixsie Wolmers | f65ee34 | 2020-01-22 19:47:56 -0600 | [diff] [blame] | 60 | setBmcTime: (state, bmcTime) => (state.bmcTime = bmcTime), |
Derick Montague | 71114fe | 2021-05-06 18:17:34 -0500 | [diff] [blame] | 61 | setServerStatus: (state, serverState) => |
| 62 | (state.serverStatus = serverStateMapper(serverState)), |
Yoshie Muranaka | 68bbba2 | 2020-05-18 09:49:37 -0700 | [diff] [blame] | 63 | setLanguagePreference: (state, language) => |
Sukanya Pandey | b1f559f | 2020-04-28 20:18:28 +0530 | [diff] [blame] | 64 | (state.languagePreference = language), |
Sukanya Pandey | fc16f3c | 2020-06-23 22:54:27 +0530 | [diff] [blame] | 65 | setUsername: (state, username) => (state.username = username), |
Sukanya Pandey | dd6aa0a | 2020-10-08 20:47:39 +0530 | [diff] [blame] | 66 | setUtcTime: (state, isUtcDisplay) => (state.isUtcDisplay = isUtcDisplay), |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 67 | setUnauthorized: (state) => { |
Sukanya Pandey | dd6aa0a | 2020-10-08 20:47:39 +0530 | [diff] [blame] | 68 | state.isAuthorized = false; |
| 69 | window.setTimeout(() => { |
| 70 | state.isAuthorized = true; |
| 71 | }, 100); |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 72 | }, |
Yoshie Muranaka | b8b6f79 | 2019-12-03 14:47:32 -0800 | [diff] [blame] | 73 | }, |
| 74 | actions: { |
Yoshie Muranaka | 598bf7e | 2020-05-01 12:26:00 -0700 | [diff] [blame] | 75 | async getBmcTime({ commit }) { |
| 76 | return await api |
Yoshie Muranaka | a371d20 | 2020-04-13 10:42:09 -0700 | [diff] [blame] | 77 | .get('/redfish/v1/Managers/bmc') |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 78 | .then((response) => { |
Yoshie Muranaka | a371d20 | 2020-04-13 10:42:09 -0700 | [diff] [blame] | 79 | const bmcDateTime = response.data.DateTime; |
| 80 | const date = new Date(bmcDateTime); |
Dixsie Wolmers | 97f4187 | 2020-02-23 15:56:16 -0600 | [diff] [blame] | 81 | commit('setBmcTime', date); |
Dixsie Wolmers | f65ee34 | 2020-01-22 19:47:56 -0600 | [diff] [blame] | 82 | }) |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 83 | .catch((error) => console.log(error)); |
Dixsie Wolmers | f65ee34 | 2020-01-22 19:47:56 -0600 | [diff] [blame] | 84 | }, |
Sukanya Pandey | 4dd7eab | 2021-08-16 18:59:14 +0530 | [diff] [blame] | 85 | getSystemInfo({ commit }) { |
Yoshie Muranaka | dc04feb | 2019-12-04 08:41:22 -0800 | [diff] [blame] | 86 | api |
Yoshie Muranaka | 881ddc4 | 2020-04-21 19:24:29 -0700 | [diff] [blame] | 87 | .get('/redfish/v1/Systems/system') |
Sukanya Pandey | c5c2ae9 | 2020-12-09 16:14:19 +0530 | [diff] [blame] | 88 | .then( |
Sukanya Pandey | 4dd7eab | 2021-08-16 18:59:14 +0530 | [diff] [blame] | 89 | ({ |
| 90 | data: { |
| 91 | AssetTag, |
| 92 | Model, |
| 93 | PowerState, |
| 94 | SerialNumber, |
| 95 | Status: { State } = {}, |
| 96 | }, |
| 97 | } = {}) => { |
Sukanya Pandey | c5c2ae9 | 2020-12-09 16:14:19 +0530 | [diff] [blame] | 98 | commit('setAssetTag', AssetTag); |
Sukanya Pandey | 4dd7eab | 2021-08-16 18:59:14 +0530 | [diff] [blame] | 99 | commit('setSerialNumber', SerialNumber); |
| 100 | commit('setModelType', Model); |
Sukanya Pandey | c5c2ae9 | 2020-12-09 16:14:19 +0530 | [diff] [blame] | 101 | if (State === 'Quiesced' || State === 'InTest') { |
| 102 | // OpenBMC's host state interface is mapped to 2 Redfish |
| 103 | // properties "Status""State" and "PowerState". Look first |
| 104 | // at State for certain cases. |
Derick Montague | 71114fe | 2021-05-06 18:17:34 -0500 | [diff] [blame] | 105 | commit('setServerStatus', State); |
Sukanya Pandey | c5c2ae9 | 2020-12-09 16:14:19 +0530 | [diff] [blame] | 106 | } else { |
Derick Montague | 71114fe | 2021-05-06 18:17:34 -0500 | [diff] [blame] | 107 | commit('setServerStatus', PowerState); |
Sukanya Pandey | c5c2ae9 | 2020-12-09 16:14:19 +0530 | [diff] [blame] | 108 | } |
Yoshie Muranaka | a3cbc65 | 2020-05-13 12:55:48 -0700 | [diff] [blame] | 109 | } |
Sukanya Pandey | c5c2ae9 | 2020-12-09 16:14:19 +0530 | [diff] [blame] | 110 | ) |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 111 | .catch((error) => console.log(error)); |
| 112 | }, |
| 113 | }, |
Yoshie Muranaka | b8b6f79 | 2019-12-03 14:47:32 -0800 | [diff] [blame] | 114 | }; |
| 115 | |
| 116 | export default GlobalStore; |