| Dixsie Wolmers | 8f030ba | 2020-12-07 13:12:53 -0600 | [diff] [blame] | 1 | import api from '@/store/api'; | 
|  | 2 | import i18n from '@/i18n'; | 
|  | 3 |  | 
| Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 4 | const PoliciesStore = { | 
| Dixsie Wolmers | 8f030ba | 2020-12-07 13:12:53 -0600 | [diff] [blame] | 5 | 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 Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 43 | return i18n.t('pagePolicies.toast.successIpmiEnabled'); | 
| Dixsie Wolmers | 8f030ba | 2020-12-07 13:12:53 -0600 | [diff] [blame] | 44 | } else { | 
| Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 45 | return i18n.t('pagePolicies.toast.successIpmiDisabled'); | 
| Dixsie Wolmers | 8f030ba | 2020-12-07 13:12:53 -0600 | [diff] [blame] | 46 | } | 
|  | 47 | }) | 
|  | 48 | .catch((error) => { | 
|  | 49 | console.log(error); | 
|  | 50 | commit('setIpmiProtocolEnabled', !protocolEnabled); | 
|  | 51 | if (protocolEnabled) { | 
| Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 52 | throw new Error(i18n.t('pagePolicies.toast.errorIpmiEnabled')); | 
| Dixsie Wolmers | 8f030ba | 2020-12-07 13:12:53 -0600 | [diff] [blame] | 53 | } else { | 
| Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 54 | throw new Error(i18n.t('pagePolicies.toast.errorIpmiDisabled')); | 
| Dixsie Wolmers | 8f030ba | 2020-12-07 13:12:53 -0600 | [diff] [blame] | 55 | } | 
|  | 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 Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 69 | return i18n.t('pagePolicies.toast.successSshEnabled'); | 
| Dixsie Wolmers | 8f030ba | 2020-12-07 13:12:53 -0600 | [diff] [blame] | 70 | } else { | 
| Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 71 | return i18n.t('pagePolicies.toast.successSshDisabled'); | 
| Dixsie Wolmers | 8f030ba | 2020-12-07 13:12:53 -0600 | [diff] [blame] | 72 | } | 
|  | 73 | }) | 
|  | 74 | .catch((error) => { | 
|  | 75 | console.log(error); | 
|  | 76 | commit('setSshProtocolEnabled', !protocolEnabled); | 
|  | 77 | if (protocolEnabled) { | 
| Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 78 | throw new Error(i18n.t('pagePolicies.toast.errorSshEnabled')); | 
| Dixsie Wolmers | 8f030ba | 2020-12-07 13:12:53 -0600 | [diff] [blame] | 79 | } else { | 
| Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 80 | throw new Error(i18n.t('pagePolicies.toast.errorSshDisabled')); | 
| Dixsie Wolmers | 8f030ba | 2020-12-07 13:12:53 -0600 | [diff] [blame] | 81 | } | 
|  | 82 | }); | 
|  | 83 | }, | 
|  | 84 | }, | 
|  | 85 | }; | 
|  | 86 |  | 
| Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 87 | export default PoliciesStore; |