blob: 64bd33690d1fbf07424de8387dc0f3ec0c3621a2 [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',
Dixsie Wolmers8f030ba2020-12-07 13:12:53 -060011 },
12 getters: {
13 sshProtocolEnabled: (state) => state.sshProtocolEnabled,
14 ipmiProtocolEnabled: (state) => state.ipmiProtocolEnabled,
Nikhil Ashokaaee27142022-01-27 19:10:31 +053015 rtadEnabled: (state) => state.rtadEnabled,
16 vtpmEnabled: (state) => state.vtpmEnabled,
Dixsie Wolmers8f030ba2020-12-07 13:12:53 -060017 },
18 mutations: {
19 setSshProtocolEnabled: (state, sshProtocolEnabled) =>
20 (state.sshProtocolEnabled = sshProtocolEnabled),
21 setIpmiProtocolEnabled: (state, ipmiProtocolEnabled) =>
22 (state.ipmiProtocolEnabled = ipmiProtocolEnabled),
Nikhil Ashokaaee27142022-01-27 19:10:31 +053023 setRtadEnabled: (state, rtadEnabled) => (state.rtadEnabled = rtadEnabled),
24 setVtpmEnabled: (state, vtpmEnabled) => (state.vtpmEnabled = vtpmEnabled),
Dixsie Wolmers8f030ba2020-12-07 13:12:53 -060025 },
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 Ashokaaee27142022-01-27 19:10:31 +053038 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 Wolmers8f030ba2020-12-07 13:12:53 -060047 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 Singhb4406162021-07-26 15:05:39 +053058 return i18n.t('pagePolicies.toast.successIpmiEnabled');
Dixsie Wolmers8f030ba2020-12-07 13:12:53 -060059 } else {
Sandeepa Singhb4406162021-07-26 15:05:39 +053060 return i18n.t('pagePolicies.toast.successIpmiDisabled');
Dixsie Wolmers8f030ba2020-12-07 13:12:53 -060061 }
62 })
63 .catch((error) => {
64 console.log(error);
65 commit('setIpmiProtocolEnabled', !protocolEnabled);
66 if (protocolEnabled) {
Sandeepa Singhb4406162021-07-26 15:05:39 +053067 throw new Error(i18n.t('pagePolicies.toast.errorIpmiEnabled'));
Dixsie Wolmers8f030ba2020-12-07 13:12:53 -060068 } else {
Sandeepa Singhb4406162021-07-26 15:05:39 +053069 throw new Error(i18n.t('pagePolicies.toast.errorIpmiDisabled'));
Dixsie Wolmers8f030ba2020-12-07 13:12:53 -060070 }
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 Singhb4406162021-07-26 15:05:39 +053084 return i18n.t('pagePolicies.toast.successSshEnabled');
Dixsie Wolmers8f030ba2020-12-07 13:12:53 -060085 } else {
Sandeepa Singhb4406162021-07-26 15:05:39 +053086 return i18n.t('pagePolicies.toast.successSshDisabled');
Dixsie Wolmers8f030ba2020-12-07 13:12:53 -060087 }
88 })
89 .catch((error) => {
90 console.log(error);
91 commit('setSshProtocolEnabled', !protocolEnabled);
92 if (protocolEnabled) {
Sandeepa Singhb4406162021-07-26 15:05:39 +053093 throw new Error(i18n.t('pagePolicies.toast.errorSshEnabled'));
Dixsie Wolmers8f030ba2020-12-07 13:12:53 -060094 } else {
Sandeepa Singhb4406162021-07-26 15:05:39 +053095 throw new Error(i18n.t('pagePolicies.toast.errorSshDisabled'));
Dixsie Wolmers8f030ba2020-12-07 13:12:53 -060096 }
97 });
98 },
Nikhil Ashokaaee27142022-01-27 19:10:31 +053099 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 Wolmers8f030ba2020-12-07 13:12:53 -0600147 },
148};
149
Sandeepa Singhb4406162021-07-26 15:05:39 +0530150export default PoliciesStore;