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, |
Nikhil Ashoka | aee2714 | 2022-01-27 19:10:31 +0530 | [diff] [blame] | 9 | rtadEnabled: 'Disabled', |
| 10 | vtpmEnabled: 'Disabled', |
Dixsie Wolmers | 8f030ba | 2020-12-07 13:12:53 -0600 | [diff] [blame] | 11 | }, |
| 12 | getters: { |
| 13 | sshProtocolEnabled: (state) => state.sshProtocolEnabled, |
| 14 | ipmiProtocolEnabled: (state) => state.ipmiProtocolEnabled, |
Nikhil Ashoka | aee2714 | 2022-01-27 19:10:31 +0530 | [diff] [blame] | 15 | rtadEnabled: (state) => state.rtadEnabled, |
| 16 | vtpmEnabled: (state) => state.vtpmEnabled, |
Dixsie Wolmers | 8f030ba | 2020-12-07 13:12:53 -0600 | [diff] [blame] | 17 | }, |
| 18 | mutations: { |
| 19 | setSshProtocolEnabled: (state, sshProtocolEnabled) => |
| 20 | (state.sshProtocolEnabled = sshProtocolEnabled), |
| 21 | setIpmiProtocolEnabled: (state, ipmiProtocolEnabled) => |
| 22 | (state.ipmiProtocolEnabled = ipmiProtocolEnabled), |
Nikhil Ashoka | aee2714 | 2022-01-27 19:10:31 +0530 | [diff] [blame] | 23 | setRtadEnabled: (state, rtadEnabled) => (state.rtadEnabled = rtadEnabled), |
| 24 | setVtpmEnabled: (state, vtpmEnabled) => (state.vtpmEnabled = vtpmEnabled), |
Dixsie Wolmers | 8f030ba | 2020-12-07 13:12:53 -0600 | [diff] [blame] | 25 | }, |
| 26 | actions: { |
| 27 | async getNetworkProtocolStatus({ commit }) { |
| 28 | return await api |
| 29 | .get('/redfish/v1/Managers/bmc/NetworkProtocol') |
| 30 | .then((response) => { |
| 31 | const sshProtocol = response.data.SSH.ProtocolEnabled; |
| 32 | const ipmiProtocol = response.data.IPMI.ProtocolEnabled; |
| 33 | commit('setSshProtocolEnabled', sshProtocol); |
| 34 | commit('setIpmiProtocolEnabled', ipmiProtocol); |
| 35 | }) |
| 36 | .catch((error) => console.log(error)); |
| 37 | }, |
Nikhil Ashoka | aee2714 | 2022-01-27 19:10:31 +0530 | [diff] [blame] | 38 | async getBiosStatus({ commit }) { |
| 39 | return await api |
| 40 | .get('/redfish/v1/Systems/system/Bios') |
| 41 | .then((response) => { |
| 42 | commit('setRtadEnabled', response.data.Attributes.pvm_rtad); |
| 43 | commit('setVtpmEnabled', response.data.Attributes.pvm_vtpm); |
| 44 | }) |
| 45 | .catch((error) => console.log(error)); |
| 46 | }, |
Dixsie Wolmers | 8f030ba | 2020-12-07 13:12:53 -0600 | [diff] [blame] | 47 | async saveIpmiProtocolState({ commit }, protocolEnabled) { |
| 48 | commit('setIpmiProtocolEnabled', protocolEnabled); |
| 49 | const ipmi = { |
| 50 | IPMI: { |
| 51 | ProtocolEnabled: protocolEnabled, |
| 52 | }, |
| 53 | }; |
| 54 | return await api |
| 55 | .patch('/redfish/v1/Managers/bmc/NetworkProtocol', ipmi) |
| 56 | .then(() => { |
| 57 | if (protocolEnabled) { |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 58 | return i18n.t('pagePolicies.toast.successIpmiEnabled'); |
Dixsie Wolmers | 8f030ba | 2020-12-07 13:12:53 -0600 | [diff] [blame] | 59 | } else { |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 60 | return i18n.t('pagePolicies.toast.successIpmiDisabled'); |
Dixsie Wolmers | 8f030ba | 2020-12-07 13:12:53 -0600 | [diff] [blame] | 61 | } |
| 62 | }) |
| 63 | .catch((error) => { |
| 64 | console.log(error); |
| 65 | commit('setIpmiProtocolEnabled', !protocolEnabled); |
| 66 | if (protocolEnabled) { |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 67 | throw new Error(i18n.t('pagePolicies.toast.errorIpmiEnabled')); |
Dixsie Wolmers | 8f030ba | 2020-12-07 13:12:53 -0600 | [diff] [blame] | 68 | } else { |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 69 | throw new Error(i18n.t('pagePolicies.toast.errorIpmiDisabled')); |
Dixsie Wolmers | 8f030ba | 2020-12-07 13:12:53 -0600 | [diff] [blame] | 70 | } |
| 71 | }); |
| 72 | }, |
| 73 | async saveSshProtocolState({ commit }, protocolEnabled) { |
| 74 | commit('setSshProtocolEnabled', protocolEnabled); |
| 75 | const ssh = { |
| 76 | SSH: { |
| 77 | ProtocolEnabled: protocolEnabled, |
| 78 | }, |
| 79 | }; |
| 80 | return await api |
| 81 | .patch('/redfish/v1/Managers/bmc/NetworkProtocol', ssh) |
| 82 | .then(() => { |
| 83 | if (protocolEnabled) { |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 84 | return i18n.t('pagePolicies.toast.successSshEnabled'); |
Dixsie Wolmers | 8f030ba | 2020-12-07 13:12:53 -0600 | [diff] [blame] | 85 | } else { |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 86 | return i18n.t('pagePolicies.toast.successSshDisabled'); |
Dixsie Wolmers | 8f030ba | 2020-12-07 13:12:53 -0600 | [diff] [blame] | 87 | } |
| 88 | }) |
| 89 | .catch((error) => { |
| 90 | console.log(error); |
| 91 | commit('setSshProtocolEnabled', !protocolEnabled); |
| 92 | if (protocolEnabled) { |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 93 | throw new Error(i18n.t('pagePolicies.toast.errorSshEnabled')); |
Dixsie Wolmers | 8f030ba | 2020-12-07 13:12:53 -0600 | [diff] [blame] | 94 | } else { |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 95 | throw new Error(i18n.t('pagePolicies.toast.errorSshDisabled')); |
Dixsie Wolmers | 8f030ba | 2020-12-07 13:12:53 -0600 | [diff] [blame] | 96 | } |
| 97 | }); |
| 98 | }, |
Nikhil Ashoka | aee2714 | 2022-01-27 19:10:31 +0530 | [diff] [blame] | 99 | async saveRtadState({ commit }, updatedRtad) { |
| 100 | commit('setRtadEnabled', updatedRtad); |
| 101 | return await api |
| 102 | .patch('/redfish/v1/Systems/system/Bios/Settings', { |
| 103 | Attributes: { |
| 104 | pvm_rtad: updatedRtad, |
| 105 | }, |
| 106 | }) |
| 107 | .then(() => { |
| 108 | if (updatedRtad === 'Enabled') { |
| 109 | return i18n.t('pagePolicies.toast.successRtadEnabled'); |
| 110 | } else { |
| 111 | return i18n.t('pagePolicies.toast.successRtadDisabled'); |
| 112 | } |
| 113 | }) |
| 114 | .catch((error) => { |
| 115 | console.log(error); |
| 116 | if (updatedRtad === 'Enabled') { |
| 117 | throw new Error(i18n.t('pagePolicies.toast.errorRtadEnabled')); |
| 118 | } else { |
| 119 | throw new Error(i18n.t('pagePolicies.toast.errorRtadDisabled')); |
| 120 | } |
| 121 | }); |
| 122 | }, |
| 123 | async saveVtpmState({ commit }, updatedVtpm) { |
| 124 | commit('setVtpmEnabled', updatedVtpm); |
| 125 | return await api |
| 126 | .patch('/redfish/v1/Systems/system/Bios/Settings', { |
| 127 | Attributes: { |
| 128 | pvm_vtpm: updatedVtpm, |
| 129 | }, |
| 130 | }) |
| 131 | .then(() => { |
| 132 | if (updatedVtpm === 'Enabled') { |
| 133 | return i18n.t('pagePolicies.toast.successVtpmEnabled'); |
| 134 | } else { |
| 135 | return i18n.t('pagePolicies.toast.successVtpmDisabled'); |
| 136 | } |
| 137 | }) |
| 138 | .catch((error) => { |
| 139 | console.log(error); |
| 140 | if (updatedVtpm === 'Enabled') { |
| 141 | throw new Error(i18n.t('pagePolicies.toast.errorVtpmEnabled')); |
| 142 | } else { |
| 143 | throw new Error(i18n.t('pagePolicies.toast.errorVtpmDisabled')); |
| 144 | } |
| 145 | }); |
| 146 | }, |
Dixsie Wolmers | 8f030ba | 2020-12-07 13:12:53 -0600 | [diff] [blame] | 147 | }, |
| 148 | }; |
| 149 | |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 150 | export default PoliciesStore; |