1import api from '@/store/api'; 2import i18n from '@/i18n'; 3 4const PoliciesStore = { 5 namespaced: true, 6 state: { 7 sshProtocolEnabled: false, 8 ipmiProtocolEnabled: false, 9 rtadEnabled: 'Disabled', 10 vtpmEnabled: 'Disabled', 11 sessionTimeoutValue: null, 12 }, 13 getters: { 14 sshProtocolEnabled: (state) => state.sshProtocolEnabled, 15 ipmiProtocolEnabled: (state) => state.ipmiProtocolEnabled, 16 rtadEnabled: (state) => state.rtadEnabled, 17 vtpmEnabled: (state) => state.vtpmEnabled, 18 getSessionTimeoutValue: (state) => state.sessionTimeoutValue, 19 }, 20 mutations: { 21 setSshProtocolEnabled: (state, sshProtocolEnabled) => 22 (state.sshProtocolEnabled = sshProtocolEnabled), 23 setIpmiProtocolEnabled: (state, ipmiProtocolEnabled) => 24 (state.ipmiProtocolEnabled = ipmiProtocolEnabled), 25 setRtadEnabled: (state, rtadEnabled) => (state.rtadEnabled = rtadEnabled), 26 setVtpmEnabled: (state, vtpmEnabled) => (state.vtpmEnabled = vtpmEnabled), 27 setSessionTimeoutValue(state, sessionTimeoutValue) { 28 state.sessionTimeoutValue = sessionTimeoutValue; 29 }, 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 }, 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 }, 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 }, 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) { 72 return i18n.t('pagePolicies.toast.successIpmiEnabled'); 73 } else { 74 return i18n.t('pagePolicies.toast.successIpmiDisabled'); 75 } 76 }) 77 .catch((error) => { 78 console.log(error); 79 commit('setIpmiProtocolEnabled', !protocolEnabled); 80 if (protocolEnabled) { 81 throw new Error(i18n.t('pagePolicies.toast.errorIpmiEnabled')); 82 } else { 83 throw new Error(i18n.t('pagePolicies.toast.errorIpmiDisabled')); 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) { 98 return i18n.t('pagePolicies.toast.successSshEnabled'); 99 } else { 100 return i18n.t('pagePolicies.toast.successSshDisabled'); 101 } 102 }) 103 .catch((error) => { 104 console.log(error); 105 commit('setSshProtocolEnabled', !protocolEnabled); 106 if (protocolEnabled) { 107 throw new Error(i18n.t('pagePolicies.toast.errorSshEnabled')); 108 } else { 109 throw new Error(i18n.t('pagePolicies.toast.errorSshDisabled')); 110 } 111 }); 112 }, 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 }, 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 }, 176 }, 177}; 178 179export default PoliciesStore; 180