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 |
Sean Zhang | 8841b7d | 2024-06-15 08:42:41 +0300 | [diff] [blame] | 34 | .get(`${await this.dispatch('global/getBmcPath')}/NetworkProtocol`) |
Dixsie Wolmers | 8f030ba | 2020-12-07 13:12:53 -0600 | [diff] [blame] | 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 |
Sean Zhang | 8841b7d | 2024-06-15 08:42:41 +0300 | [diff] [blame] | 45 | .get(`${await this.dispatch('global/getSystemPath')}/Bios`) |
Nikhil Ashoka | aee2714 | 2022-01-27 19:10:31 +0530 | [diff] [blame] | 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 |
Sean Zhang | 8841b7d | 2024-06-15 08:42:41 +0300 | [diff] [blame] | 69 | .patch( |
| 70 | `${await this.dispatch('global/getBmcPath')}/NetworkProtocol`, |
| 71 | ipmi, |
| 72 | ) |
Dixsie Wolmers | 8f030ba | 2020-12-07 13:12:53 -0600 | [diff] [blame] | 73 | .then(() => { |
| 74 | if (protocolEnabled) { |
Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame] | 75 | return i18n.global.t('pagePolicies.toast.successIpmiEnabled'); |
Dixsie Wolmers | 8f030ba | 2020-12-07 13:12:53 -0600 | [diff] [blame] | 76 | } else { |
Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame] | 77 | return i18n.global.t('pagePolicies.toast.successIpmiDisabled'); |
Dixsie Wolmers | 8f030ba | 2020-12-07 13:12:53 -0600 | [diff] [blame] | 78 | } |
| 79 | }) |
| 80 | .catch((error) => { |
| 81 | console.log(error); |
| 82 | commit('setIpmiProtocolEnabled', !protocolEnabled); |
| 83 | if (protocolEnabled) { |
Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame] | 84 | throw new Error( |
| 85 | i18n.global.t('pagePolicies.toast.errorIpmiEnabled'), |
| 86 | ); |
Dixsie Wolmers | 8f030ba | 2020-12-07 13:12:53 -0600 | [diff] [blame] | 87 | } else { |
Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame] | 88 | throw new Error( |
| 89 | i18n.global.t('pagePolicies.toast.errorIpmiDisabled'), |
| 90 | ); |
Dixsie Wolmers | 8f030ba | 2020-12-07 13:12:53 -0600 | [diff] [blame] | 91 | } |
| 92 | }); |
| 93 | }, |
| 94 | async saveSshProtocolState({ commit }, protocolEnabled) { |
| 95 | commit('setSshProtocolEnabled', protocolEnabled); |
| 96 | const ssh = { |
| 97 | SSH: { |
| 98 | ProtocolEnabled: protocolEnabled, |
| 99 | }, |
| 100 | }; |
| 101 | return await api |
Sean Zhang | 8841b7d | 2024-06-15 08:42:41 +0300 | [diff] [blame] | 102 | .patch( |
| 103 | `${await this.dispatch('global/getBmcPath')}/NetworkProtocol`, |
| 104 | ssh, |
| 105 | ) |
Dixsie Wolmers | 8f030ba | 2020-12-07 13:12:53 -0600 | [diff] [blame] | 106 | .then(() => { |
| 107 | if (protocolEnabled) { |
Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame] | 108 | return i18n.global.t('pagePolicies.toast.successSshEnabled'); |
Dixsie Wolmers | 8f030ba | 2020-12-07 13:12:53 -0600 | [diff] [blame] | 109 | } else { |
Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame] | 110 | return i18n.global.t('pagePolicies.toast.successSshDisabled'); |
Dixsie Wolmers | 8f030ba | 2020-12-07 13:12:53 -0600 | [diff] [blame] | 111 | } |
| 112 | }) |
| 113 | .catch((error) => { |
| 114 | console.log(error); |
| 115 | commit('setSshProtocolEnabled', !protocolEnabled); |
| 116 | if (protocolEnabled) { |
Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame] | 117 | throw new Error( |
| 118 | i18n.global.t('pagePolicies.toast.errorSshEnabled'), |
| 119 | ); |
Dixsie Wolmers | 8f030ba | 2020-12-07 13:12:53 -0600 | [diff] [blame] | 120 | } else { |
Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame] | 121 | throw new Error( |
| 122 | i18n.global.t('pagePolicies.toast.errorSshDisabled'), |
| 123 | ); |
Dixsie Wolmers | 8f030ba | 2020-12-07 13:12:53 -0600 | [diff] [blame] | 124 | } |
| 125 | }); |
| 126 | }, |
Nikhil Ashoka | aee2714 | 2022-01-27 19:10:31 +0530 | [diff] [blame] | 127 | async saveRtadState({ commit }, updatedRtad) { |
| 128 | commit('setRtadEnabled', updatedRtad); |
| 129 | return await api |
Sean Zhang | 8841b7d | 2024-06-15 08:42:41 +0300 | [diff] [blame] | 130 | .patch(`${await this.dispatch('global/getSystemPath')}/Bios/Settings`, { |
Nikhil Ashoka | aee2714 | 2022-01-27 19:10:31 +0530 | [diff] [blame] | 131 | Attributes: { |
| 132 | pvm_rtad: updatedRtad, |
| 133 | }, |
| 134 | }) |
| 135 | .then(() => { |
| 136 | if (updatedRtad === 'Enabled') { |
Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame] | 137 | return i18n.global.t('pagePolicies.toast.successRtadEnabled'); |
Nikhil Ashoka | aee2714 | 2022-01-27 19:10:31 +0530 | [diff] [blame] | 138 | } else { |
Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame] | 139 | return i18n.global.t('pagePolicies.toast.successRtadDisabled'); |
Nikhil Ashoka | aee2714 | 2022-01-27 19:10:31 +0530 | [diff] [blame] | 140 | } |
| 141 | }) |
| 142 | .catch((error) => { |
| 143 | console.log(error); |
| 144 | if (updatedRtad === 'Enabled') { |
Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame] | 145 | throw new Error( |
| 146 | i18n.global.t('pagePolicies.toast.errorRtadEnabled'), |
| 147 | ); |
Nikhil Ashoka | aee2714 | 2022-01-27 19:10:31 +0530 | [diff] [blame] | 148 | } else { |
Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame] | 149 | throw new Error( |
| 150 | i18n.global.t('pagePolicies.toast.errorRtadDisabled'), |
| 151 | ); |
Nikhil Ashoka | aee2714 | 2022-01-27 19:10:31 +0530 | [diff] [blame] | 152 | } |
| 153 | }); |
| 154 | }, |
| 155 | async saveVtpmState({ commit }, updatedVtpm) { |
| 156 | commit('setVtpmEnabled', updatedVtpm); |
| 157 | return await api |
Sean Zhang | 8841b7d | 2024-06-15 08:42:41 +0300 | [diff] [blame] | 158 | .patch(`${await this.dispatch('global/getSystemPath')}/Bios/Settings`, { |
Nikhil Ashoka | aee2714 | 2022-01-27 19:10:31 +0530 | [diff] [blame] | 159 | Attributes: { |
| 160 | pvm_vtpm: updatedVtpm, |
| 161 | }, |
| 162 | }) |
| 163 | .then(() => { |
| 164 | if (updatedVtpm === 'Enabled') { |
Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame] | 165 | return i18n.global.t('pagePolicies.toast.successVtpmEnabled'); |
Nikhil Ashoka | aee2714 | 2022-01-27 19:10:31 +0530 | [diff] [blame] | 166 | } else { |
Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame] | 167 | return i18n.global.t('pagePolicies.toast.successVtpmDisabled'); |
Nikhil Ashoka | aee2714 | 2022-01-27 19:10:31 +0530 | [diff] [blame] | 168 | } |
| 169 | }) |
| 170 | .catch((error) => { |
| 171 | console.log(error); |
| 172 | if (updatedVtpm === 'Enabled') { |
Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame] | 173 | throw new Error( |
| 174 | i18n.global.t('pagePolicies.toast.errorVtpmEnabled'), |
| 175 | ); |
Nikhil Ashoka | aee2714 | 2022-01-27 19:10:31 +0530 | [diff] [blame] | 176 | } else { |
Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame] | 177 | throw new Error( |
| 178 | i18n.global.t('pagePolicies.toast.errorVtpmDisabled'), |
| 179 | ); |
Nikhil Ashoka | aee2714 | 2022-01-27 19:10:31 +0530 | [diff] [blame] | 180 | } |
| 181 | }); |
| 182 | }, |
kirankumarb07 | 2dabfc1 | 2023-03-29 11:19:31 +0530 | [diff] [blame] | 183 | async saveSessionTimeoutValue({ dispatch }, sessionTimeoutNewValue) { |
| 184 | const sessionValue = { |
| 185 | SessionTimeout: sessionTimeoutNewValue, |
| 186 | }; |
| 187 | return await api |
| 188 | .patch('/redfish/v1/SessionService', sessionValue) |
| 189 | .then(() => dispatch('getSessionTimeout')) |
| 190 | .then(() => { |
Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame] | 191 | return i18n.global.t('pagePolicies.toast.successSessionTimeout'); |
kirankumarb07 | 2dabfc1 | 2023-03-29 11:19:31 +0530 | [diff] [blame] | 192 | }) |
| 193 | .catch((error) => { |
| 194 | console.log(error); |
Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame] | 195 | throw new Error( |
| 196 | i18n.global.t('pagePolicies.toast.errorSessionTimeout'), |
| 197 | ); |
kirankumarb07 | 2dabfc1 | 2023-03-29 11:19:31 +0530 | [diff] [blame] | 198 | }); |
| 199 | }, |
Dixsie Wolmers | 8f030ba | 2020-12-07 13:12:53 -0600 | [diff] [blame] | 200 | }, |
| 201 | }; |
| 202 | |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 203 | export default PoliciesStore; |