blob: 1e195527bbfee6922c619dbe11cdeb02ecc49e60 [file] [log] [blame]
Dixsie Wolmers8f030ba2020-12-07 13:12:53 -06001import api from '@/store/api';
2import i18n from '@/i18n';
3
Sandeepa Singhb4406162021-07-26 15:05:39 +05304const PoliciesStore = {
Dixsie Wolmers8f030ba2020-12-07 13:12:53 -06005 namespaced: true,
6 state: {
7 sshProtocolEnabled: false,
8 ipmiProtocolEnabled: false,
9 },
10 getters: {
11 sshProtocolEnabled: (state) => state.sshProtocolEnabled,
12 ipmiProtocolEnabled: (state) => state.ipmiProtocolEnabled,
13 },
14 mutations: {
15 setSshProtocolEnabled: (state, sshProtocolEnabled) =>
16 (state.sshProtocolEnabled = sshProtocolEnabled),
17 setIpmiProtocolEnabled: (state, ipmiProtocolEnabled) =>
18 (state.ipmiProtocolEnabled = ipmiProtocolEnabled),
19 },
20 actions: {
21 async getNetworkProtocolStatus({ commit }) {
22 return await api
23 .get('/redfish/v1/Managers/bmc/NetworkProtocol')
24 .then((response) => {
25 const sshProtocol = response.data.SSH.ProtocolEnabled;
26 const ipmiProtocol = response.data.IPMI.ProtocolEnabled;
27 commit('setSshProtocolEnabled', sshProtocol);
28 commit('setIpmiProtocolEnabled', ipmiProtocol);
29 })
30 .catch((error) => console.log(error));
31 },
32 async saveIpmiProtocolState({ commit }, protocolEnabled) {
33 commit('setIpmiProtocolEnabled', protocolEnabled);
34 const ipmi = {
35 IPMI: {
36 ProtocolEnabled: protocolEnabled,
37 },
38 };
39 return await api
40 .patch('/redfish/v1/Managers/bmc/NetworkProtocol', ipmi)
41 .then(() => {
42 if (protocolEnabled) {
Sandeepa Singhb4406162021-07-26 15:05:39 +053043 return i18n.t('pagePolicies.toast.successIpmiEnabled');
Dixsie Wolmers8f030ba2020-12-07 13:12:53 -060044 } else {
Sandeepa Singhb4406162021-07-26 15:05:39 +053045 return i18n.t('pagePolicies.toast.successIpmiDisabled');
Dixsie Wolmers8f030ba2020-12-07 13:12:53 -060046 }
47 })
48 .catch((error) => {
49 console.log(error);
50 commit('setIpmiProtocolEnabled', !protocolEnabled);
51 if (protocolEnabled) {
Sandeepa Singhb4406162021-07-26 15:05:39 +053052 throw new Error(i18n.t('pagePolicies.toast.errorIpmiEnabled'));
Dixsie Wolmers8f030ba2020-12-07 13:12:53 -060053 } else {
Sandeepa Singhb4406162021-07-26 15:05:39 +053054 throw new Error(i18n.t('pagePolicies.toast.errorIpmiDisabled'));
Dixsie Wolmers8f030ba2020-12-07 13:12:53 -060055 }
56 });
57 },
58 async saveSshProtocolState({ commit }, protocolEnabled) {
59 commit('setSshProtocolEnabled', protocolEnabled);
60 const ssh = {
61 SSH: {
62 ProtocolEnabled: protocolEnabled,
63 },
64 };
65 return await api
66 .patch('/redfish/v1/Managers/bmc/NetworkProtocol', ssh)
67 .then(() => {
68 if (protocolEnabled) {
Sandeepa Singhb4406162021-07-26 15:05:39 +053069 return i18n.t('pagePolicies.toast.successSshEnabled');
Dixsie Wolmers8f030ba2020-12-07 13:12:53 -060070 } else {
Sandeepa Singhb4406162021-07-26 15:05:39 +053071 return i18n.t('pagePolicies.toast.successSshDisabled');
Dixsie Wolmers8f030ba2020-12-07 13:12:53 -060072 }
73 })
74 .catch((error) => {
75 console.log(error);
76 commit('setSshProtocolEnabled', !protocolEnabled);
77 if (protocolEnabled) {
Sandeepa Singhb4406162021-07-26 15:05:39 +053078 throw new Error(i18n.t('pagePolicies.toast.errorSshEnabled'));
Dixsie Wolmers8f030ba2020-12-07 13:12:53 -060079 } else {
Sandeepa Singhb4406162021-07-26 15:05:39 +053080 throw new Error(i18n.t('pagePolicies.toast.errorSshDisabled'));
Dixsie Wolmers8f030ba2020-12-07 13:12:53 -060081 }
82 });
83 },
84 },
85};
86
Sandeepa Singhb4406162021-07-26 15:05:39 +053087export default PoliciesStore;