blob: 64bd640fdb9fb5c8aad65a7218855bf32fa26c99 [file] [log] [blame]
Yoshie Muranaka92a0a4a2020-07-15 10:30:31 -07001import api from '@/store/api';
2import i18n from '@/i18n';
Dixsie Wolmersf65ee342020-01-22 19:47:56 -06003
4const FirmwareStore = {
5 namespaced: true,
6 state: {
Yoshie Muranaka33d755f2021-02-18 15:24:14 -08007 bmcFirmware: [],
8 hostFirmware: [],
9 bmcActiveFirmwareId: null,
10 hostActiveFirmwareId: null,
Derick Montague602e98a2020-10-21 16:20:00 -050011 applyTime: null,
Leo Xue2c716a2024-07-29 05:54:18 +030012 multipartHttpPushUri: null,
greenfil6b424f92023-03-10 10:47:41 +030013 httpPushUri: null,
Dixsie Wolmersf65ee342020-01-22 19:47:56 -060014 },
15 getters: {
Yoshie Muranaka33d755f2021-02-18 15:24:14 -080016 isSingleFileUploadEnabled: (state) => state.hostFirmware.length === 0,
17 activeBmcFirmware: (state) => {
18 return state.bmcFirmware.find(
Ed Tanous81323992024-02-27 11:26:24 -080019 (firmware) => firmware.id === state.bmcActiveFirmwareId,
Yoshie Muranaka33d755f2021-02-18 15:24:14 -080020 );
21 },
22 activeHostFirmware: (state) => {
23 return state.hostFirmware.find(
Ed Tanous81323992024-02-27 11:26:24 -080024 (firmware) => firmware.id === state.hostActiveFirmwareId,
Yoshie Muranaka33d755f2021-02-18 15:24:14 -080025 );
26 },
27 backupBmcFirmware: (state) => {
28 return state.bmcFirmware.find(
Ed Tanous81323992024-02-27 11:26:24 -080029 (firmware) => firmware.id !== state.bmcActiveFirmwareId,
Yoshie Muranaka33d755f2021-02-18 15:24:14 -080030 );
31 },
32 backupHostFirmware: (state) => {
33 return state.hostFirmware.find(
Ed Tanous81323992024-02-27 11:26:24 -080034 (firmware) => firmware.id !== state.hostActiveFirmwareId,
Yoshie Muranaka33d755f2021-02-18 15:24:14 -080035 );
36 },
Dixsie Wolmersf65ee342020-01-22 19:47:56 -060037 },
38 mutations: {
Yoshie Muranaka33d755f2021-02-18 15:24:14 -080039 setActiveBmcFirmwareId: (state, id) => (state.bmcActiveFirmwareId = id),
40 setActiveHostFirmwareId: (state, id) => (state.hostActiveFirmwareId = id),
41 setBmcFirmware: (state, firmware) => (state.bmcFirmware = firmware),
42 setHostFirmware: (state, firmware) => (state.hostFirmware = firmware),
Derick Montague602e98a2020-10-21 16:20:00 -050043 setApplyTime: (state, applyTime) => (state.applyTime = applyTime),
greenfil6b424f92023-03-10 10:47:41 +030044 setHttpPushUri: (state, httpPushUri) => (state.httpPushUri = httpPushUri),
Leo Xue2c716a2024-07-29 05:54:18 +030045 setMultipartHttpPushUri: (state, multipartHttpPushUri) =>
46 (state.multipartHttpPushUri = multipartHttpPushUri),
Dixsie Wolmersf65ee342020-01-22 19:47:56 -060047 },
48 actions: {
Yoshie Muranaka98bb24e2020-10-06 10:00:19 -070049 async getFirmwareInformation({ dispatch }) {
Yoshie Muranaka33d755f2021-02-18 15:24:14 -080050 dispatch('getActiveHostFirmware');
51 dispatch('getActiveBmcFirmware');
52 return await dispatch('getFirmwareInventory');
Yoshie Muranaka98bb24e2020-10-06 10:00:19 -070053 },
Sean Zhang8841b7d2024-06-15 08:42:41 +030054 async getActiveBmcFirmware({ commit }) {
Yoshie Muranaka33d755f2021-02-18 15:24:14 -080055 return api
Sean Zhang8841b7d2024-06-15 08:42:41 +030056 .get(`${await this.dispatch('global/getBmcPath')}`)
Yoshie Muranakad227f1c2020-10-06 13:46:58 -070057 .then(({ data: { Links } }) => {
Yoshie Muranaka33d755f2021-02-18 15:24:14 -080058 const id = Links?.ActiveSoftwareImage['@odata.id'].split('/').pop();
59 commit('setActiveBmcFirmwareId', id);
Yoshie Muranaka98bb24e2020-10-06 10:00:19 -070060 })
Derick Montague602e98a2020-10-21 16:20:00 -050061 .catch((error) => console.log(error));
Yoshie Muranaka98bb24e2020-10-06 10:00:19 -070062 },
Sean Zhang8841b7d2024-06-15 08:42:41 +030063 async getActiveHostFirmware({ commit }) {
Yoshie Muranaka33d755f2021-02-18 15:24:14 -080064 return api
Sean Zhang8841b7d2024-06-15 08:42:41 +030065 .get(`${await this.dispatch('global/getSystemPath')}/Bios`)
Yoshie Muranaka98bb24e2020-10-06 10:00:19 -070066 .then(({ data: { Links } }) => {
Yoshie Muranaka33d755f2021-02-18 15:24:14 -080067 const id = Links?.ActiveSoftwareImage['@odata.id'].split('/').pop();
68 commit('setActiveHostFirmwareId', id);
Yoshie Muranaka92a0a4a2020-07-15 10:30:31 -070069 })
Derick Montague602e98a2020-10-21 16:20:00 -050070 .catch((error) => console.log(error));
Yoshie Muranaka92a0a4a2020-07-15 10:30:31 -070071 },
Yoshie Muranaka33d755f2021-02-18 15:24:14 -080072 async getFirmwareInventory({ commit }) {
73 const inventoryList = await api
74 .get('/redfish/v1/UpdateService/FirmwareInventory')
75 .then(({ data: { Members = [] } = {} }) =>
Ed Tanous81323992024-02-27 11:26:24 -080076 Members.map((item) => api.get(item['@odata.id'])),
Yoshie Muranaka33d755f2021-02-18 15:24:14 -080077 )
78 .catch((error) => console.log(error));
79 await api
80 .all(inventoryList)
81 .then((response) => {
82 const bmcFirmware = [];
83 const hostFirmware = [];
84 response.forEach(({ data }) => {
85 const firmwareType = data?.RelatedItem?.[0]?.['@odata.id']
86 .split('/')
87 .pop();
88 const item = {
89 version: data?.Version,
90 id: data?.Id,
91 location: data?.['@odata.id'],
92 status: data?.Status?.Health,
93 };
94 if (firmwareType === 'bmc') {
95 bmcFirmware.push(item);
96 } else if (firmwareType === 'Bios') {
97 hostFirmware.push(item);
98 }
99 });
100 commit('setBmcFirmware', bmcFirmware);
101 commit('setHostFirmware', hostFirmware);
102 })
103 .catch((error) => {
104 console.log(error);
105 });
106 },
107 getUpdateServiceSettings({ commit }) {
Yoshie Muranaka92a0a4a2020-07-15 10:30:31 -0700108 api
109 .get('/redfish/v1/UpdateService')
110 .then(({ data }) => {
111 const applyTime =
112 data.HttpPushUriOptions.HttpPushUriApplyTime.ApplyTime;
113 commit('setApplyTime', applyTime);
greenfil6b424f92023-03-10 10:47:41 +0300114 const httpPushUri = data.HttpPushUri;
115 commit('setHttpPushUri', httpPushUri);
Leo Xue2c716a2024-07-29 05:54:18 +0300116 const multipartHttpPushUri = data.MultipartHttpPushUri;
117 commit('setMultipartHttpPushUri', multipartHttpPushUri);
Yoshie Muranaka92a0a4a2020-07-15 10:30:31 -0700118 })
Derick Montague602e98a2020-10-21 16:20:00 -0500119 .catch((error) => console.log(error));
Yoshie Muranaka92a0a4a2020-07-15 10:30:31 -0700120 },
Leo Xue2c716a2024-07-29 05:54:18 +0300121 async uploadFirmware({ state, dispatch }, params) {
122 if (state.multipartHttpPushUri != null) {
123 return dispatch('uploadFirmwareMultipartHttpPush', params);
124 } else if (state.httpPushUri != null) {
125 return dispatch('uploadFirmwareHttpPush', params);
126 } else {
127 console.log('Do not support firmware push update');
128 }
129 },
130 async uploadFirmwareHttpPush({ state }, { image }) {
Yoshie Muranaka92a0a4a2020-07-15 10:30:31 -0700131 return await api
greenfil6b424f92023-03-10 10:47:41 +0300132 .post(state.httpPushUri, image, {
Derick Montague602e98a2020-10-21 16:20:00 -0500133 headers: { 'Content-Type': 'application/octet-stream' },
Yoshie Muranaka92a0a4a2020-07-15 10:30:31 -0700134 })
Derick Montague602e98a2020-10-21 16:20:00 -0500135 .catch((error) => {
Dixsie Wolmers46a87442020-02-26 15:26:30 -0600136 console.log(error);
Yoshie Muranaka33d755f2021-02-18 15:24:14 -0800137 throw new Error(i18n.t('pageFirmware.toast.errorUpdateFirmware'));
Yoshie Muranaka92a0a4a2020-07-15 10:30:31 -0700138 });
139 },
Leo Xue2c716a2024-07-29 05:54:18 +0300140 async uploadFirmwareMultipartHttpPush({ state }, { image, targets }) {
141 const formData = new FormData();
142 formData.append('UpdateFile', image);
143 let params = {};
jason westoverccf5c5c2024-09-12 17:18:59 -0500144 if (targets != null && targets.length > 0) {
145 params.Targets = targets;
146 } else {
147 // TODO: Should be OK to leave Targets out, remove this clause
148 // when bmcweb is updated
149 params.Targets = [`${await this.dispatch('global/getBmcPath')}`];
150 }
Leo Xue2c716a2024-07-29 05:54:18 +0300151 formData.append('UpdateParameters', JSON.stringify(params));
152 return await api
153 .post(state.multipartHttpPushUri, formData, {
154 headers: { 'Content-Type': 'multipart/form-data' },
155 })
156 .catch((error) => {
157 console.log(error);
158 throw new Error(i18n.t('pageFirmware.toast.errorUpdateFirmware'));
159 });
160 },
Yoshie Muranaka33d755f2021-02-18 15:24:14 -0800161 async switchBmcFirmwareAndReboot({ getters }) {
162 const backupLocation = getters.backupBmcFirmware.location;
Yoshie Muranaka92a0a4a2020-07-15 10:30:31 -0700163 const data = {
164 Links: {
165 ActiveSoftwareImage: {
Yoshie Muranaka1dedbdf2020-11-30 07:04:01 -0800166 '@odata.id': backupLocation,
Derick Montague602e98a2020-10-21 16:20:00 -0500167 },
168 },
Yoshie Muranaka92a0a4a2020-07-15 10:30:31 -0700169 };
170 return await api
Sean Zhang8841b7d2024-06-15 08:42:41 +0300171 .patch(`${await this.dispatch('global/getBmcPath')}`, data)
Derick Montague602e98a2020-10-21 16:20:00 -0500172 .catch((error) => {
Yoshie Muranaka92a0a4a2020-07-15 10:30:31 -0700173 console.log(error);
Yoshie Muranaka33d755f2021-02-18 15:24:14 -0800174 throw new Error(i18n.t('pageFirmware.toast.errorSwitchImages'));
Dixsie Wolmers46a87442020-02-26 15:26:30 -0600175 });
Derick Montague602e98a2020-10-21 16:20:00 -0500176 },
177 },
Dixsie Wolmersf65ee342020-01-22 19:47:56 -0600178};
179
180export default FirmwareStore;