blob: f1e98b27c0bd3514247030f53f5ba0c68307f9fc [file] [log] [blame]
Dixsie Wolmers8f030ba2020-12-07 13:12:53 -06001import api from '@/store/api';
2import i18n from '@/i18n';
3
Sandeepa Singhb4406162021-07-26 15:05:39 +05304const PoliciesStore = {
Dixsie Wolmers8f030ba2020-12-07 13:12:53 -06005 namespaced: true,
6 state: {
7 sshProtocolEnabled: false,
8 ipmiProtocolEnabled: false,
Nikhil Ashokaaee27142022-01-27 19:10:31 +05309 rtadEnabled: 'Disabled',
10 vtpmEnabled: 'Disabled',
kirankumarb072dabfc12023-03-29 11:19:31 +053011 sessionTimeoutValue: null,
Dixsie Wolmers8f030ba2020-12-07 13:12:53 -060012 },
13 getters: {
14 sshProtocolEnabled: (state) => state.sshProtocolEnabled,
15 ipmiProtocolEnabled: (state) => state.ipmiProtocolEnabled,
Nikhil Ashokaaee27142022-01-27 19:10:31 +053016 rtadEnabled: (state) => state.rtadEnabled,
17 vtpmEnabled: (state) => state.vtpmEnabled,
kirankumarb072dabfc12023-03-29 11:19:31 +053018 getSessionTimeoutValue: (state) => state.sessionTimeoutValue,
Dixsie Wolmers8f030ba2020-12-07 13:12:53 -060019 },
20 mutations: {
21 setSshProtocolEnabled: (state, sshProtocolEnabled) =>
22 (state.sshProtocolEnabled = sshProtocolEnabled),
23 setIpmiProtocolEnabled: (state, ipmiProtocolEnabled) =>
24 (state.ipmiProtocolEnabled = ipmiProtocolEnabled),
Nikhil Ashokaaee27142022-01-27 19:10:31 +053025 setRtadEnabled: (state, rtadEnabled) => (state.rtadEnabled = rtadEnabled),
26 setVtpmEnabled: (state, vtpmEnabled) => (state.vtpmEnabled = vtpmEnabled),
kirankumarb072dabfc12023-03-29 11:19:31 +053027 setSessionTimeoutValue(state, sessionTimeoutValue) {
28 state.sessionTimeoutValue = sessionTimeoutValue;
29 },
Dixsie Wolmers8f030ba2020-12-07 13:12:53 -060030 },
31 actions: {
32 async getNetworkProtocolStatus({ commit }) {
33 return await api
Sean Zhang8841b7d2024-06-15 08:42:41 +030034 .get(`${await this.dispatch('global/getBmcPath')}/NetworkProtocol`)
Dixsie Wolmers8f030ba2020-12-07 13:12:53 -060035 .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 Ashokaaee27142022-01-27 19:10:31 +053043 async getBiosStatus({ commit }) {
44 return await api
Sean Zhang8841b7d2024-06-15 08:42:41 +030045 .get(`${await this.dispatch('global/getSystemPath')}/Bios`)
Nikhil Ashokaaee27142022-01-27 19:10:31 +053046 .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 },
kirankumarb072dabfc12023-03-29 11:19:31 +053052 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 Wolmers8f030ba2020-12-07 13:12:53 -060061 async saveIpmiProtocolState({ commit }, protocolEnabled) {
62 commit('setIpmiProtocolEnabled', protocolEnabled);
63 const ipmi = {
64 IPMI: {
65 ProtocolEnabled: protocolEnabled,
66 },
67 };
68 return await api
Sean Zhang8841b7d2024-06-15 08:42:41 +030069 .patch(
70 `${await this.dispatch('global/getBmcPath')}/NetworkProtocol`,
71 ipmi,
72 )
Dixsie Wolmers8f030ba2020-12-07 13:12:53 -060073 .then(() => {
74 if (protocolEnabled) {
Sandeepa Singhb4406162021-07-26 15:05:39 +053075 return i18n.t('pagePolicies.toast.successIpmiEnabled');
Dixsie Wolmers8f030ba2020-12-07 13:12:53 -060076 } else {
Sandeepa Singhb4406162021-07-26 15:05:39 +053077 return i18n.t('pagePolicies.toast.successIpmiDisabled');
Dixsie Wolmers8f030ba2020-12-07 13:12:53 -060078 }
79 })
80 .catch((error) => {
81 console.log(error);
82 commit('setIpmiProtocolEnabled', !protocolEnabled);
83 if (protocolEnabled) {
Sandeepa Singhb4406162021-07-26 15:05:39 +053084 throw new Error(i18n.t('pagePolicies.toast.errorIpmiEnabled'));
Dixsie Wolmers8f030ba2020-12-07 13:12:53 -060085 } else {
Sandeepa Singhb4406162021-07-26 15:05:39 +053086 throw new Error(i18n.t('pagePolicies.toast.errorIpmiDisabled'));
Dixsie Wolmers8f030ba2020-12-07 13:12:53 -060087 }
88 });
89 },
90 async saveSshProtocolState({ commit }, protocolEnabled) {
91 commit('setSshProtocolEnabled', protocolEnabled);
92 const ssh = {
93 SSH: {
94 ProtocolEnabled: protocolEnabled,
95 },
96 };
97 return await api
Sean Zhang8841b7d2024-06-15 08:42:41 +030098 .patch(
99 `${await this.dispatch('global/getBmcPath')}/NetworkProtocol`,
100 ssh,
101 )
Dixsie Wolmers8f030ba2020-12-07 13:12:53 -0600102 .then(() => {
103 if (protocolEnabled) {
Sandeepa Singhb4406162021-07-26 15:05:39 +0530104 return i18n.t('pagePolicies.toast.successSshEnabled');
Dixsie Wolmers8f030ba2020-12-07 13:12:53 -0600105 } else {
Sandeepa Singhb4406162021-07-26 15:05:39 +0530106 return i18n.t('pagePolicies.toast.successSshDisabled');
Dixsie Wolmers8f030ba2020-12-07 13:12:53 -0600107 }
108 })
109 .catch((error) => {
110 console.log(error);
111 commit('setSshProtocolEnabled', !protocolEnabled);
112 if (protocolEnabled) {
Sandeepa Singhb4406162021-07-26 15:05:39 +0530113 throw new Error(i18n.t('pagePolicies.toast.errorSshEnabled'));
Dixsie Wolmers8f030ba2020-12-07 13:12:53 -0600114 } else {
Sandeepa Singhb4406162021-07-26 15:05:39 +0530115 throw new Error(i18n.t('pagePolicies.toast.errorSshDisabled'));
Dixsie Wolmers8f030ba2020-12-07 13:12:53 -0600116 }
117 });
118 },
Nikhil Ashokaaee27142022-01-27 19:10:31 +0530119 async saveRtadState({ commit }, updatedRtad) {
120 commit('setRtadEnabled', updatedRtad);
121 return await api
Sean Zhang8841b7d2024-06-15 08:42:41 +0300122 .patch(`${await this.dispatch('global/getSystemPath')}/Bios/Settings`, {
Nikhil Ashokaaee27142022-01-27 19:10:31 +0530123 Attributes: {
124 pvm_rtad: updatedRtad,
125 },
126 })
127 .then(() => {
128 if (updatedRtad === 'Enabled') {
129 return i18n.t('pagePolicies.toast.successRtadEnabled');
130 } else {
131 return i18n.t('pagePolicies.toast.successRtadDisabled');
132 }
133 })
134 .catch((error) => {
135 console.log(error);
136 if (updatedRtad === 'Enabled') {
137 throw new Error(i18n.t('pagePolicies.toast.errorRtadEnabled'));
138 } else {
139 throw new Error(i18n.t('pagePolicies.toast.errorRtadDisabled'));
140 }
141 });
142 },
143 async saveVtpmState({ commit }, updatedVtpm) {
144 commit('setVtpmEnabled', updatedVtpm);
145 return await api
Sean Zhang8841b7d2024-06-15 08:42:41 +0300146 .patch(`${await this.dispatch('global/getSystemPath')}/Bios/Settings`, {
Nikhil Ashokaaee27142022-01-27 19:10:31 +0530147 Attributes: {
148 pvm_vtpm: updatedVtpm,
149 },
150 })
151 .then(() => {
152 if (updatedVtpm === 'Enabled') {
153 return i18n.t('pagePolicies.toast.successVtpmEnabled');
154 } else {
155 return i18n.t('pagePolicies.toast.successVtpmDisabled');
156 }
157 })
158 .catch((error) => {
159 console.log(error);
160 if (updatedVtpm === 'Enabled') {
161 throw new Error(i18n.t('pagePolicies.toast.errorVtpmEnabled'));
162 } else {
163 throw new Error(i18n.t('pagePolicies.toast.errorVtpmDisabled'));
164 }
165 });
166 },
kirankumarb072dabfc12023-03-29 11:19:31 +0530167 async saveSessionTimeoutValue({ dispatch }, sessionTimeoutNewValue) {
168 const sessionValue = {
169 SessionTimeout: sessionTimeoutNewValue,
170 };
171 return await api
172 .patch('/redfish/v1/SessionService', sessionValue)
173 .then(() => dispatch('getSessionTimeout'))
174 .then(() => {
175 return i18n.t('pagePolicies.toast.successSessionTimeout');
176 })
177 .catch((error) => {
178 console.log(error);
179 throw new Error(i18n.t('pagePolicies.toast.errorSessionTimeout'));
180 });
181 },
Dixsie Wolmers8f030ba2020-12-07 13:12:53 -0600182 },
183};
184
Sandeepa Singhb4406162021-07-26 15:05:39 +0530185export default PoliciesStore;