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