blob: 83871092ed5b90212148248c12f2e4aa44459ade [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,
greenfil6b424f92023-03-10 10:47:41 +030012 httpPushUri: null,
Dixsie Wolmersf65ee342020-01-22 19:47:56 -060013 },
14 getters: {
Yoshie Muranaka33d755f2021-02-18 15:24:14 -080015 isSingleFileUploadEnabled: (state) => state.hostFirmware.length === 0,
16 activeBmcFirmware: (state) => {
17 return state.bmcFirmware.find(
Ed Tanous81323992024-02-27 11:26:24 -080018 (firmware) => firmware.id === state.bmcActiveFirmwareId,
Yoshie Muranaka33d755f2021-02-18 15:24:14 -080019 );
20 },
21 activeHostFirmware: (state) => {
22 return state.hostFirmware.find(
Ed Tanous81323992024-02-27 11:26:24 -080023 (firmware) => firmware.id === state.hostActiveFirmwareId,
Yoshie Muranaka33d755f2021-02-18 15:24:14 -080024 );
25 },
26 backupBmcFirmware: (state) => {
27 return state.bmcFirmware.find(
Ed Tanous81323992024-02-27 11:26:24 -080028 (firmware) => firmware.id !== state.bmcActiveFirmwareId,
Yoshie Muranaka33d755f2021-02-18 15:24:14 -080029 );
30 },
31 backupHostFirmware: (state) => {
32 return state.hostFirmware.find(
Ed Tanous81323992024-02-27 11:26:24 -080033 (firmware) => firmware.id !== state.hostActiveFirmwareId,
Yoshie Muranaka33d755f2021-02-18 15:24:14 -080034 );
35 },
Dixsie Wolmersf65ee342020-01-22 19:47:56 -060036 },
37 mutations: {
Yoshie Muranaka33d755f2021-02-18 15:24:14 -080038 setActiveBmcFirmwareId: (state, id) => (state.bmcActiveFirmwareId = id),
39 setActiveHostFirmwareId: (state, id) => (state.hostActiveFirmwareId = id),
40 setBmcFirmware: (state, firmware) => (state.bmcFirmware = firmware),
41 setHostFirmware: (state, firmware) => (state.hostFirmware = firmware),
Derick Montague602e98a2020-10-21 16:20:00 -050042 setApplyTime: (state, applyTime) => (state.applyTime = applyTime),
greenfil6b424f92023-03-10 10:47:41 +030043 setHttpPushUri: (state, httpPushUri) => (state.httpPushUri = httpPushUri),
Dixsie Wolmersf65ee342020-01-22 19:47:56 -060044 },
45 actions: {
Yoshie Muranaka98bb24e2020-10-06 10:00:19 -070046 async getFirmwareInformation({ dispatch }) {
Yoshie Muranaka33d755f2021-02-18 15:24:14 -080047 dispatch('getActiveHostFirmware');
48 dispatch('getActiveBmcFirmware');
49 return await dispatch('getFirmwareInventory');
Yoshie Muranaka98bb24e2020-10-06 10:00:19 -070050 },
Sean Zhang8841b7d2024-06-15 08:42:41 +030051 async getActiveBmcFirmware({ commit }) {
Yoshie Muranaka33d755f2021-02-18 15:24:14 -080052 return api
Sean Zhang8841b7d2024-06-15 08:42:41 +030053 .get(`${await this.dispatch('global/getBmcPath')}`)
Yoshie Muranakad227f1c2020-10-06 13:46:58 -070054 .then(({ data: { Links } }) => {
Yoshie Muranaka33d755f2021-02-18 15:24:14 -080055 const id = Links?.ActiveSoftwareImage['@odata.id'].split('/').pop();
56 commit('setActiveBmcFirmwareId', id);
Yoshie Muranaka98bb24e2020-10-06 10:00:19 -070057 })
Derick Montague602e98a2020-10-21 16:20:00 -050058 .catch((error) => console.log(error));
Yoshie Muranaka98bb24e2020-10-06 10:00:19 -070059 },
Sean Zhang8841b7d2024-06-15 08:42:41 +030060 async getActiveHostFirmware({ commit }) {
Yoshie Muranaka33d755f2021-02-18 15:24:14 -080061 return api
Sean Zhang8841b7d2024-06-15 08:42:41 +030062 .get(`${await this.dispatch('global/getSystemPath')}/Bios`)
Yoshie Muranaka98bb24e2020-10-06 10:00:19 -070063 .then(({ data: { Links } }) => {
Yoshie Muranaka33d755f2021-02-18 15:24:14 -080064 const id = Links?.ActiveSoftwareImage['@odata.id'].split('/').pop();
65 commit('setActiveHostFirmwareId', id);
Yoshie Muranaka92a0a4a2020-07-15 10:30:31 -070066 })
Derick Montague602e98a2020-10-21 16:20:00 -050067 .catch((error) => console.log(error));
Yoshie Muranaka92a0a4a2020-07-15 10:30:31 -070068 },
Yoshie Muranaka33d755f2021-02-18 15:24:14 -080069 async getFirmwareInventory({ commit }) {
70 const inventoryList = await api
71 .get('/redfish/v1/UpdateService/FirmwareInventory')
72 .then(({ data: { Members = [] } = {} }) =>
Ed Tanous81323992024-02-27 11:26:24 -080073 Members.map((item) => api.get(item['@odata.id'])),
Yoshie Muranaka33d755f2021-02-18 15:24:14 -080074 )
75 .catch((error) => console.log(error));
76 await api
77 .all(inventoryList)
78 .then((response) => {
79 const bmcFirmware = [];
80 const hostFirmware = [];
81 response.forEach(({ data }) => {
82 const firmwareType = data?.RelatedItem?.[0]?.['@odata.id']
83 .split('/')
84 .pop();
85 const item = {
86 version: data?.Version,
87 id: data?.Id,
88 location: data?.['@odata.id'],
89 status: data?.Status?.Health,
90 };
91 if (firmwareType === 'bmc') {
92 bmcFirmware.push(item);
93 } else if (firmwareType === 'Bios') {
94 hostFirmware.push(item);
95 }
96 });
97 commit('setBmcFirmware', bmcFirmware);
98 commit('setHostFirmware', hostFirmware);
99 })
100 .catch((error) => {
101 console.log(error);
102 });
103 },
104 getUpdateServiceSettings({ commit }) {
Yoshie Muranaka92a0a4a2020-07-15 10:30:31 -0700105 api
106 .get('/redfish/v1/UpdateService')
107 .then(({ data }) => {
108 const applyTime =
109 data.HttpPushUriOptions.HttpPushUriApplyTime.ApplyTime;
110 commit('setApplyTime', applyTime);
greenfil6b424f92023-03-10 10:47:41 +0300111 const httpPushUri = data.HttpPushUri;
112 commit('setHttpPushUri', httpPushUri);
Yoshie Muranaka92a0a4a2020-07-15 10:30:31 -0700113 })
Derick Montague602e98a2020-10-21 16:20:00 -0500114 .catch((error) => console.log(error));
Yoshie Muranaka92a0a4a2020-07-15 10:30:31 -0700115 },
Jagpal Singh Gillccb71f02024-06-18 15:21:08 -0700116 async uploadFirmware({ state }, image) {
Yoshie Muranaka92a0a4a2020-07-15 10:30:31 -0700117 return await api
greenfil6b424f92023-03-10 10:47:41 +0300118 .post(state.httpPushUri, image, {
Derick Montague602e98a2020-10-21 16:20:00 -0500119 headers: { 'Content-Type': 'application/octet-stream' },
Yoshie Muranaka92a0a4a2020-07-15 10:30:31 -0700120 })
Derick Montague602e98a2020-10-21 16:20:00 -0500121 .catch((error) => {
Dixsie Wolmers46a87442020-02-26 15:26:30 -0600122 console.log(error);
Surya V603cfbf2024-07-11 15:19:46 +0530123 throw new Error(
124 i18n.global.t('pageFirmware.toast.errorUpdateFirmware'),
125 );
Yoshie Muranaka92a0a4a2020-07-15 10:30:31 -0700126 });
127 },
Yoshie Muranaka33d755f2021-02-18 15:24:14 -0800128 async switchBmcFirmwareAndReboot({ getters }) {
129 const backupLocation = getters.backupBmcFirmware.location;
Yoshie Muranaka92a0a4a2020-07-15 10:30:31 -0700130 const data = {
131 Links: {
132 ActiveSoftwareImage: {
Yoshie Muranaka1dedbdf2020-11-30 07:04:01 -0800133 '@odata.id': backupLocation,
Derick Montague602e98a2020-10-21 16:20:00 -0500134 },
135 },
Yoshie Muranaka92a0a4a2020-07-15 10:30:31 -0700136 };
137 return await api
Sean Zhang8841b7d2024-06-15 08:42:41 +0300138 .patch(`${await this.dispatch('global/getBmcPath')}`, data)
Derick Montague602e98a2020-10-21 16:20:00 -0500139 .catch((error) => {
Yoshie Muranaka92a0a4a2020-07-15 10:30:31 -0700140 console.log(error);
Surya V603cfbf2024-07-11 15:19:46 +0530141 throw new Error(
142 i18n.global.t('pageFirmware.toast.errorSwitchImages'),
143 );
Dixsie Wolmers46a87442020-02-26 15:26:30 -0600144 });
Derick Montague602e98a2020-10-21 16:20:00 -0500145 },
146 },
Dixsie Wolmersf65ee342020-01-22 19:47:56 -0600147};
148
149export default FirmwareStore;