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