blob: 3b91354bc5ec87999975d2536eeba2ad2314fdda [file] [log] [blame]
Yoshie Muranakaf415a082020-12-07 13:04:11 -08001import api, { getResponseCount } from '@/store/api';
2import i18n from '@/i18n';
Yoshie Muranaka22d4d522020-12-03 10:58:35 -08003
4const DumpsStore = {
5 namespaced: true,
6 state: {
7 bmcDumps: [],
8 },
9 getters: {
Yoshie Muranakaf415a082020-12-07 13:04:11 -080010 bmcDumps: (state) => state.bmcDumps,
Yoshie Muranaka22d4d522020-12-03 10:58:35 -080011 },
12 mutations: {
13 setBmcDumps: (state, dumps) => {
14 state.bmcDumps = dumps.map((dump) => ({
Yoshie Muranakaf415a082020-12-07 13:04:11 -080015 data: dump.AdditionalDataURI,
Yoshie Muranaka22d4d522020-12-03 10:58:35 -080016 dateTime: new Date(dump.Created),
17 dumpType: dump.Name,
18 id: dump.Id,
Yoshie Muranakaf415a082020-12-07 13:04:11 -080019 location: dump['@odata.id'],
Yoshie Muranaka22d4d522020-12-03 10:58:35 -080020 size: dump.AdditionalDataSizeBytes,
Yoshie Muranaka22d4d522020-12-03 10:58:35 -080021 }));
22 },
23 },
24 actions: {
25 async getBmcDumps({ commit }) {
26 return await api
27 .get('/redfish/v1/Managers/bmc/LogServices/Dump/Entries')
28 .then(({ data = {} }) => commit('setBmcDumps', data.Members || []))
29 .catch((error) => console.log(error));
30 },
Yoshie Muranakaf415a082020-12-07 13:04:11 -080031 async createBmcDump() {
32 return await api
33 .post(
34 '/redfish/v1/Managers/bmc/LogServices/Dump/Actions/LogService.CollectDiagnosticData',
35 {
36 DiagnosticDataType: 'Manager',
37 OEMDiagnosticDataType: '',
38 }
39 )
40 .catch((error) => {
41 console.log(error);
42 throw new Error(i18n.t('pageDumps.toast.errorStartBmcDump'));
43 });
44 },
45 async createSystemDump() {
46 return await api
47 .post(
48 '/redfish/v1/Systems/system/LogServices/Dump/Actions/LogService.CollectDiagnosticData',
49 {
50 DiagnosticDataType: 'OEM',
51 OEMDiagnosticDataType: 'System',
52 }
53 )
54 .catch((error) => {
55 console.log(error);
56 throw new Error(i18n.t('pageDumps.toast.errorStartSystemDump'));
57 });
58 },
59 async deleteDumps({ dispatch }, dumps) {
60 const promises = dumps.map(({ location }) =>
61 api.delete(location).catch((error) => {
62 console.log(error);
63 return error;
64 })
65 );
66 return await api
67 .all(promises)
68 .then((response) => {
69 dispatch('getBmcDumps');
70 return response;
71 })
72 .then(
73 api.spread((...responses) => {
74 const { successCount, errorCount } = getResponseCount(responses);
75 const toastMessages = [];
76
77 if (successCount) {
78 const message = i18n.tc(
79 'pageDumps.toast.successDeleteDump',
80 successCount
81 );
82 toastMessages.push({ type: 'success', message });
83 }
84
85 if (errorCount) {
86 const message = i18n.tc(
87 'pageDumps.toast.errorDeleteDump',
88 errorCount
89 );
90 toastMessages.push({ type: 'error', message });
91 }
92
93 return toastMessages;
94 })
95 );
96 },
97 async deleteAllDumps({ commit, state }) {
98 const totalDumpCount = state.bmcDumps.length;
99 return await api
100 .post(
101 '/redfish/v1/Managers/bmc/LogServices/Dump/Actions/LogService.ClearLog'
102 )
103 .then(() => {
104 commit('setBmcDumps', []);
105 return i18n.tc('pageDumps.toast.successDeleteDump', totalDumpCount);
106 })
107 .catch((error) => {
108 console.log(error);
109 throw new Error(
110 i18n.tc('pageDumps.toast.errorDeleteDump', totalDumpCount)
111 );
112 });
113 },
Yoshie Muranaka22d4d522020-12-03 10:58:35 -0800114 },
115};
116
117export default DumpsStore;