blob: 74eb1e80b9b542541cfc2a7d8c96e0d39ad1b94a [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 Montague71114fe2021-05-06 18:17:34 -050010const serverStateMapper = (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: {
Sukanya Pandeyc5c2ae92020-12-09 16:14:19 +053032 assetTag: null,
Yoshie Muranakae45f54b2020-03-26 15:23:34 -070033 bmcTime: null,
Sukanya Pandey4dd7eab2021-08-16 18:59:14 +053034 modelType: null,
35 serialNumber: null,
Derick Montague71114fe2021-05-06 18:17:34 -050036 serverStatus: 'unreachable',
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +053037 languagePreference: localStorage.getItem('storedLanguage') || 'en-US',
Sukanya Pandeyfc16f3c2020-06-23 22:54:27 +053038 isUtcDisplay: localStorage.getItem('storedUtcDisplay')
39 ? JSON.parse(localStorage.getItem('storedUtcDisplay'))
40 : true,
Sukanya Pandeydd6aa0a2020-10-08 20:47:39 +053041 username: localStorage.getItem('storedUsername'),
Derick Montague602e98a2020-10-21 16:20:00 -050042 isAuthorized: true,
Damian Celicoaeb19812022-11-24 02:00:53 +010043 userPrivilege: null,
Yoshie Muranakab8b6f792019-12-03 14:47:32 -080044 },
45 getters: {
Sukanya Pandeyc5c2ae92020-12-09 16:14:19 +053046 assetTag: (state) => state.assetTag,
Sukanya Pandey4dd7eab2021-08-16 18:59:14 +053047 modelType: (state) => state.modelType,
48 serialNumber: (state) => state.serialNumber,
Derick Montague71114fe2021-05-06 18:17:34 -050049 serverStatus: (state) => state.serverStatus,
Derick Montague602e98a2020-10-21 16:20:00 -050050 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 Celicoaeb19812022-11-24 02:00:53 +010055 userPrivilege: (state) => state.userPrivilege,
Yoshie Muranakab8b6f792019-12-03 14:47:32 -080056 },
57 mutations: {
Sukanya Pandeyc5c2ae92020-12-09 16:14:19 +053058 setAssetTag: (state, assetTag) => (state.assetTag = assetTag),
Sukanya Pandey4dd7eab2021-08-16 18:59:14 +053059 setModelType: (state, modelType) => (state.modelType = modelType),
60 setSerialNumber: (state, serialNumber) =>
61 (state.serialNumber = serialNumber),
Dixsie Wolmersf65ee342020-01-22 19:47:56 -060062 setBmcTime: (state, bmcTime) => (state.bmcTime = bmcTime),
Derick Montague71114fe2021-05-06 18:17:34 -050063 setServerStatus: (state, serverState) =>
64 (state.serverStatus = serverStateMapper(serverState)),
Yoshie Muranaka68bbba22020-05-18 09:49:37 -070065 setLanguagePreference: (state, language) =>
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +053066 (state.languagePreference = language),
Sukanya Pandeyfc16f3c2020-06-23 22:54:27 +053067 setUsername: (state, username) => (state.username = username),
Sukanya Pandeydd6aa0a2020-10-08 20:47:39 +053068 setUtcTime: (state, isUtcDisplay) => (state.isUtcDisplay = isUtcDisplay),
Derick Montague602e98a2020-10-21 16:20:00 -050069 setUnauthorized: (state) => {
Sukanya Pandeydd6aa0a2020-10-08 20:47:39 +053070 state.isAuthorized = false;
71 window.setTimeout(() => {
72 state.isAuthorized = true;
73 }, 100);
Derick Montague602e98a2020-10-21 16:20:00 -050074 },
Damian Celicoaeb19812022-11-24 02:00:53 +010075 setPrivilege: (state, privilege) => {
76 state.userPrivilege = privilege;
77 },
Yoshie Muranakab8b6f792019-12-03 14:47:32 -080078 },
79 actions: {
Yoshie Muranaka598bf7e2020-05-01 12:26:00 -070080 async getBmcTime({ commit }) {
81 return await api
Yoshie Muranakaa371d202020-04-13 10:42:09 -070082 .get('/redfish/v1/Managers/bmc')
Derick Montague602e98a2020-10-21 16:20:00 -050083 .then((response) => {
Yoshie Muranakaa371d202020-04-13 10:42:09 -070084 const bmcDateTime = response.data.DateTime;
85 const date = new Date(bmcDateTime);
Dixsie Wolmers97f41872020-02-23 15:56:16 -060086 commit('setBmcTime', date);
Dixsie Wolmersf65ee342020-01-22 19:47:56 -060087 })
Derick Montague602e98a2020-10-21 16:20:00 -050088 .catch((error) => console.log(error));
Dixsie Wolmersf65ee342020-01-22 19:47:56 -060089 },
Sukanya Pandey4dd7eab2021-08-16 18:59:14 +053090 getSystemInfo({ commit }) {
Yoshie Muranakadc04feb2019-12-04 08:41:22 -080091 api
Yoshie Muranaka881ddc42020-04-21 19:24:29 -070092 .get('/redfish/v1/Systems/system')
Sukanya Pandeyc5c2ae92020-12-09 16:14:19 +053093 .then(
Sukanya Pandey4dd7eab2021-08-16 18:59:14 +053094 ({
95 data: {
96 AssetTag,
97 Model,
98 PowerState,
99 SerialNumber,
100 Status: { State } = {},
101 },
102 } = {}) => {
Sukanya Pandeyc5c2ae92020-12-09 16:14:19 +0530103 commit('setAssetTag', AssetTag);
Sukanya Pandey4dd7eab2021-08-16 18:59:14 +0530104 commit('setSerialNumber', SerialNumber);
105 commit('setModelType', Model);
Sukanya Pandeyc5c2ae92020-12-09 16:14:19 +0530106 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 Montague71114fe2021-05-06 18:17:34 -0500110 commit('setServerStatus', State);
Sukanya Pandeyc5c2ae92020-12-09 16:14:19 +0530111 } else {
Derick Montague71114fe2021-05-06 18:17:34 -0500112 commit('setServerStatus', PowerState);
Sukanya Pandeyc5c2ae92020-12-09 16:14:19 +0530113 }
Yoshie Muranakaa3cbc652020-05-13 12:55:48 -0700114 }
Sukanya Pandeyc5c2ae92020-12-09 16:14:19 +0530115 )
Derick Montague602e98a2020-10-21 16:20:00 -0500116 .catch((error) => console.log(error));
117 },
118 },
Yoshie Muranakab8b6f792019-12-03 14:47:32 -0800119};
120
121export default GlobalStore;