blob: 54efa2c1c774f76c0548ef2fdeb8c0a5db14b12e [file] [log] [blame]
Sukanya Pandeybe6858c2020-12-16 20:08:01 +05301import api from '@/store/api';
2import i18n from '@/i18n';
3
Kenneth Fullbright80a87852022-01-07 13:12:30 -06004const PowerPolicyStore = {
Sukanya Pandeybe6858c2020-12-16 20:08:01 +05305 namespaced: true,
6 state: {
7 powerRestoreCurrentPolicy: null,
8 powerRestorePolicies: [],
9 },
10 getters: {
11 powerRestoreCurrentPolicy: (state) => state.powerRestoreCurrentPolicy,
12 powerRestorePolicies: (state) => state.powerRestorePolicies,
13 },
14 mutations: {
15 setPowerRestoreCurrentPolicy: (state, powerRestoreCurrentPolicy) =>
16 (state.powerRestoreCurrentPolicy = powerRestoreCurrentPolicy),
17 setPowerRestorePolicies: (state, powerRestorePolicies) =>
18 (state.powerRestorePolicies = powerRestorePolicies),
19 },
20 actions: {
21 async getPowerRestorePolicies({ commit }) {
22 return await api
23 .get('/redfish/v1/JsonSchemas/ComputerSystem/ComputerSystem.json')
24 .then(
25 ({
26 data: {
27 definitions: { PowerRestorePolicyTypes = {} },
28 },
29 }) => {
30 let powerPoliciesData = PowerRestorePolicyTypes.enum.map(
31 (powerState) => {
32 let desc = `${i18n.t(
33 `pagePowerRestorePolicy.policies.${powerState}`
34 )} - ${PowerRestorePolicyTypes.enumDescriptions[powerState]}`;
35 return {
36 state: powerState,
37 desc,
38 };
39 }
40 );
41 commit('setPowerRestorePolicies', powerPoliciesData);
42 }
43 );
44 },
45 async getPowerRestoreCurrentPolicy({ commit }) {
Kenneth Fullbright80a87852022-01-07 13:12:30 -060046 return await api
Sukanya Pandeybe6858c2020-12-16 20:08:01 +053047 .get('/redfish/v1/Systems/system')
48 .then(({ data: { PowerRestorePolicy } }) => {
49 commit('setPowerRestoreCurrentPolicy', PowerRestorePolicy);
50 })
51 .catch((error) => console.log(error));
52 },
Kenneth Fullbright80a87852022-01-07 13:12:30 -060053 async setPowerRestorePolicy({ dispatch }, powerPolicy) {
Sukanya Pandeybe6858c2020-12-16 20:08:01 +053054 const data = { PowerRestorePolicy: powerPolicy };
55
56 return await api
57 .patch('/redfish/v1/Systems/system', data)
Kenneth Fullbright80a87852022-01-07 13:12:30 -060058 .then(() => {
59 dispatch('getPowerRestoreCurrentPolicy');
60 return i18n.t('pagePowerRestorePolicy.toast.successSaveSettings');
61 })
Sukanya Pandeybe6858c2020-12-16 20:08:01 +053062 .catch((error) => {
63 console.log(error);
64 throw new Error(
65 i18n.t('pagePowerRestorePolicy.toast.errorSaveSettings')
66 );
67 });
68 },
69 },
70};
71
Kenneth Fullbright80a87852022-01-07 13:12:30 -060072export default PowerPolicyStore;