blob: 218feb6758a60c7a6ccb83575b038ba4c2511170 [file] [log] [blame]
SurenNeware61859092020-10-01 09:37:32 +05301import api from '@/store/api';
Yoshie Muranakab8b6f792019-12-03 14:47:32 -08002
Yoshie Muranakadc04feb2019-12-04 08:41:22 -08003const 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 Montague602e98a2020-10-21 16:20:00 -05007 diagnosticMode: 'xyz.openbmc_project.State.Host.HostState.DiagnosticMode',
Yoshie Muranakadc04feb2019-12-04 08:41:22 -08008};
9
Derick Montague602e98a2020-10-21 16:20:00 -050010const hostStateMapper = (hostState) => {
Yoshie Muranakadc04feb2019-12-04 08:41:22 -080011 switch (hostState) {
12 case HOST_STATE.on:
Yoshie Muranaka881ddc42020-04-21 19:24:29 -070013 case 'On': // Redfish PowerState
Yoshie Muranakadc04feb2019-12-04 08:41:22 -080014 return 'on';
15 case HOST_STATE.off:
Yoshie Muranaka881ddc42020-04-21 19:24:29 -070016 case 'Off': // Redfish PowerState
Yoshie Muranakadc04feb2019-12-04 08:41:22 -080017 return 'off';
18 case HOST_STATE.error:
Yoshie Muranakaa3cbc652020-05-13 12:55:48 -070019 case 'Quiesced': // Redfish Status
Yoshie Muranakadc04feb2019-12-04 08:41:22 -080020 return 'error';
Yoshie Muranakaa3cbc652020-05-13 12:55:48 -070021 case HOST_STATE.diagnosticMode:
22 case 'InTest': // Redfish Status
23 return 'diagnosticMode';
Yoshie Muranakadc04feb2019-12-04 08:41:22 -080024 default:
25 return 'unreachable';
26 }
27};
28
Yoshie Muranakab8b6f792019-12-03 14:47:32 -080029const GlobalStore = {
30 namespaced: true,
31 state: {
Yoshie Muranakae45f54b2020-03-26 15:23:34 -070032 bmcTime: null,
Yoshie Muranaka68bbba22020-05-18 09:49:37 -070033 hostStatus: 'unreachable',
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +053034 languagePreference: localStorage.getItem('storedLanguage') || 'en-US',
Sukanya Pandeyfc16f3c2020-06-23 22:54:27 +053035 isUtcDisplay: localStorage.getItem('storedUtcDisplay')
36 ? JSON.parse(localStorage.getItem('storedUtcDisplay'))
37 : true,
Sukanya Pandeydd6aa0a2020-10-08 20:47:39 +053038 username: localStorage.getItem('storedUsername'),
Derick Montague602e98a2020-10-21 16:20:00 -050039 isAuthorized: true,
Yoshie Muranakab8b6f792019-12-03 14:47:32 -080040 },
41 getters: {
Derick Montague602e98a2020-10-21 16:20:00 -050042 hostStatus: (state) => state.hostStatus,
43 bmcTime: (state) => state.bmcTime,
44 languagePreference: (state) => state.languagePreference,
45 isUtcDisplay: (state) => state.isUtcDisplay,
46 username: (state) => state.username,
47 isAuthorized: (state) => state.isAuthorized,
Yoshie Muranakab8b6f792019-12-03 14:47:32 -080048 },
49 mutations: {
Dixsie Wolmersf65ee342020-01-22 19:47:56 -060050 setBmcTime: (state, bmcTime) => (state.bmcTime = bmcTime),
51 setHostStatus: (state, hostState) =>
Yoshie Muranaka68bbba22020-05-18 09:49:37 -070052 (state.hostStatus = hostStateMapper(hostState)),
53 setLanguagePreference: (state, language) =>
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +053054 (state.languagePreference = language),
Sukanya Pandeyfc16f3c2020-06-23 22:54:27 +053055 setUsername: (state, username) => (state.username = username),
Sukanya Pandeydd6aa0a2020-10-08 20:47:39 +053056 setUtcTime: (state, isUtcDisplay) => (state.isUtcDisplay = isUtcDisplay),
Derick Montague602e98a2020-10-21 16:20:00 -050057 setUnauthorized: (state) => {
Sukanya Pandeydd6aa0a2020-10-08 20:47:39 +053058 state.isAuthorized = false;
59 window.setTimeout(() => {
60 state.isAuthorized = true;
61 }, 100);
Derick Montague602e98a2020-10-21 16:20:00 -050062 },
Yoshie Muranakab8b6f792019-12-03 14:47:32 -080063 },
64 actions: {
Yoshie Muranaka598bf7e2020-05-01 12:26:00 -070065 async getBmcTime({ commit }) {
66 return await api
Yoshie Muranakaa371d202020-04-13 10:42:09 -070067 .get('/redfish/v1/Managers/bmc')
Derick Montague602e98a2020-10-21 16:20:00 -050068 .then((response) => {
Yoshie Muranakaa371d202020-04-13 10:42:09 -070069 const bmcDateTime = response.data.DateTime;
70 const date = new Date(bmcDateTime);
Dixsie Wolmers97f41872020-02-23 15:56:16 -060071 commit('setBmcTime', date);
Dixsie Wolmersf65ee342020-01-22 19:47:56 -060072 })
Derick Montague602e98a2020-10-21 16:20:00 -050073 .catch((error) => console.log(error));
Dixsie Wolmersf65ee342020-01-22 19:47:56 -060074 },
Yoshie Muranakadc04feb2019-12-04 08:41:22 -080075 getHostStatus({ commit }) {
76 api
Yoshie Muranaka881ddc42020-04-21 19:24:29 -070077 .get('/redfish/v1/Systems/system')
Yoshie Muranakaa3cbc652020-05-13 12:55:48 -070078 .then(({ data: { PowerState, Status: { State } = {} } } = {}) => {
79 if (State === 'Quiesced' || State === 'InTest') {
80 // OpenBMC's host state interface is mapped to 2 Redfish
81 // properties "Status""State" and "PowerState". Look first
82 // at State for certain cases.
83 commit('setHostStatus', State);
84 } else {
85 commit('setHostStatus', PowerState);
86 }
Yoshie Muranakadc04feb2019-12-04 08:41:22 -080087 })
Derick Montague602e98a2020-10-21 16:20:00 -050088 .catch((error) => console.log(error));
89 },
90 },
Yoshie Muranakab8b6f792019-12-03 14:47:32 -080091};
92
93export default GlobalStore;