blob: 80d9c1a32656bf1ec9434abcd09a5d7b2b9e00d9 [file] [log] [blame]
Derick Montaguefded0d12019-12-11 06:16:40 -06001import api from '../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',
7 diagnosticMode: 'xyz.openbmc_project.State.Host.HostState.DiagnosticMode'
8};
9
10const 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 Muranakab8b6f792019-12-03 14:47:32 -080024const GlobalStore = {
25 namespaced: true,
26 state: {
Derick Montaguefded0d12019-12-11 06:16:40 -060027 hostName: '--',
Yoshie Muranakadc04feb2019-12-04 08:41:22 -080028 hostStatus: 'unreachable'
Yoshie Muranakab8b6f792019-12-03 14:47:32 -080029 },
30 getters: {
31 hostName(state) {
32 return state.hostName;
33 },
34 hostStatus(state) {
35 return state.hostStatus;
36 }
37 },
38 mutations: {
39 setHostName(state, hostName) {
40 state.hostName = hostName;
Yoshie Muranakadc04feb2019-12-04 08:41:22 -080041 },
42 setHostStatus(state, hostState) {
43 state.hostStatus = hostStateMapper(hostState);
Yoshie Muranakab8b6f792019-12-03 14:47:32 -080044 }
45 },
46 actions: {
47 getHostName({ commit }) {
48 api
Derick Montaguefded0d12019-12-11 06:16:40 -060049 .get('/xyz/openbmc_project/network/config/attr/HostName')
Yoshie Muranakab8b6f792019-12-03 14:47:32 -080050 .then(response => {
51 const hostName = response.data.data;
Derick Montaguefded0d12019-12-11 06:16:40 -060052 commit('setHostName', hostName);
Yoshie Muranakab8b6f792019-12-03 14:47:32 -080053 })
54 .catch(error => console.log(error));
Yoshie Muranakadc04feb2019-12-04 08:41:22 -080055 },
56 getHostStatus({ commit }) {
57 api
58 .get('/xyz/openbmc_project/state/host0/attr/CurrentHostState')
59 .then(response => {
60 const hostState = response.data.data;
61 commit('setHostStatus', hostState);
62 })
63 .catch(error => console.log(error));
Yoshie Muranakab8b6f792019-12-03 14:47:32 -080064 }
65 }
66};
67
68export default GlobalStore;