Yoshie Muranaka | 92a0a4a | 2020-07-15 10:30:31 -0700 | [diff] [blame] | 1 | import api from '@/store/api'; |
| 2 | import i18n from '@/i18n'; |
Dixsie Wolmers | f65ee34 | 2020-01-22 19:47:56 -0600 | [diff] [blame] | 3 | |
| 4 | const FirmwareStore = { |
| 5 | namespaced: true, |
| 6 | state: { |
Yoshie Muranaka | 33d755f | 2021-02-18 15:24:14 -0800 | [diff] [blame] | 7 | bmcFirmware: [], |
| 8 | hostFirmware: [], |
| 9 | bmcActiveFirmwareId: null, |
| 10 | hostActiveFirmwareId: null, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 11 | applyTime: null, |
greenfil | 6b424f9 | 2023-03-10 10:47:41 +0300 | [diff] [blame] | 12 | httpPushUri: null, |
Dixsie Wolmers | f65ee34 | 2020-01-22 19:47:56 -0600 | [diff] [blame] | 13 | }, |
| 14 | getters: { |
Yoshie Muranaka | 33d755f | 2021-02-18 15:24:14 -0800 | [diff] [blame] | 15 | isSingleFileUploadEnabled: (state) => state.hostFirmware.length === 0, |
| 16 | activeBmcFirmware: (state) => { |
| 17 | return state.bmcFirmware.find( |
Ed Tanous | 8132399 | 2024-02-27 11:26:24 -0800 | [diff] [blame] | 18 | (firmware) => firmware.id === state.bmcActiveFirmwareId, |
Yoshie Muranaka | 33d755f | 2021-02-18 15:24:14 -0800 | [diff] [blame] | 19 | ); |
| 20 | }, |
| 21 | activeHostFirmware: (state) => { |
| 22 | return state.hostFirmware.find( |
Ed Tanous | 8132399 | 2024-02-27 11:26:24 -0800 | [diff] [blame] | 23 | (firmware) => firmware.id === state.hostActiveFirmwareId, |
Yoshie Muranaka | 33d755f | 2021-02-18 15:24:14 -0800 | [diff] [blame] | 24 | ); |
| 25 | }, |
| 26 | backupBmcFirmware: (state) => { |
| 27 | return state.bmcFirmware.find( |
Ed Tanous | 8132399 | 2024-02-27 11:26:24 -0800 | [diff] [blame] | 28 | (firmware) => firmware.id !== state.bmcActiveFirmwareId, |
Yoshie Muranaka | 33d755f | 2021-02-18 15:24:14 -0800 | [diff] [blame] | 29 | ); |
| 30 | }, |
| 31 | backupHostFirmware: (state) => { |
| 32 | return state.hostFirmware.find( |
Ed Tanous | 8132399 | 2024-02-27 11:26:24 -0800 | [diff] [blame] | 33 | (firmware) => firmware.id !== state.hostActiveFirmwareId, |
Yoshie Muranaka | 33d755f | 2021-02-18 15:24:14 -0800 | [diff] [blame] | 34 | ); |
| 35 | }, |
Dixsie Wolmers | f65ee34 | 2020-01-22 19:47:56 -0600 | [diff] [blame] | 36 | }, |
| 37 | mutations: { |
Yoshie Muranaka | 33d755f | 2021-02-18 15:24:14 -0800 | [diff] [blame] | 38 | 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 Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 42 | setApplyTime: (state, applyTime) => (state.applyTime = applyTime), |
greenfil | 6b424f9 | 2023-03-10 10:47:41 +0300 | [diff] [blame] | 43 | setHttpPushUri: (state, httpPushUri) => (state.httpPushUri = httpPushUri), |
Dixsie Wolmers | f65ee34 | 2020-01-22 19:47:56 -0600 | [diff] [blame] | 44 | }, |
| 45 | actions: { |
Yoshie Muranaka | 98bb24e | 2020-10-06 10:00:19 -0700 | [diff] [blame] | 46 | async getFirmwareInformation({ dispatch }) { |
Yoshie Muranaka | 33d755f | 2021-02-18 15:24:14 -0800 | [diff] [blame] | 47 | dispatch('getActiveHostFirmware'); |
| 48 | dispatch('getActiveBmcFirmware'); |
| 49 | return await dispatch('getFirmwareInventory'); |
Yoshie Muranaka | 98bb24e | 2020-10-06 10:00:19 -0700 | [diff] [blame] | 50 | }, |
Sean Zhang | 8841b7d | 2024-06-15 08:42:41 +0300 | [diff] [blame] | 51 | async getActiveBmcFirmware({ commit }) { |
Yoshie Muranaka | 33d755f | 2021-02-18 15:24:14 -0800 | [diff] [blame] | 52 | return api |
Sean Zhang | 8841b7d | 2024-06-15 08:42:41 +0300 | [diff] [blame] | 53 | .get(`${await this.dispatch('global/getBmcPath')}`) |
Yoshie Muranaka | d227f1c | 2020-10-06 13:46:58 -0700 | [diff] [blame] | 54 | .then(({ data: { Links } }) => { |
Yoshie Muranaka | 33d755f | 2021-02-18 15:24:14 -0800 | [diff] [blame] | 55 | const id = Links?.ActiveSoftwareImage['@odata.id'].split('/').pop(); |
| 56 | commit('setActiveBmcFirmwareId', id); |
Yoshie Muranaka | 98bb24e | 2020-10-06 10:00:19 -0700 | [diff] [blame] | 57 | }) |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 58 | .catch((error) => console.log(error)); |
Yoshie Muranaka | 98bb24e | 2020-10-06 10:00:19 -0700 | [diff] [blame] | 59 | }, |
Sean Zhang | 8841b7d | 2024-06-15 08:42:41 +0300 | [diff] [blame] | 60 | async getActiveHostFirmware({ commit }) { |
Yoshie Muranaka | 33d755f | 2021-02-18 15:24:14 -0800 | [diff] [blame] | 61 | return api |
Sean Zhang | 8841b7d | 2024-06-15 08:42:41 +0300 | [diff] [blame] | 62 | .get(`${await this.dispatch('global/getSystemPath')}/Bios`) |
Yoshie Muranaka | 98bb24e | 2020-10-06 10:00:19 -0700 | [diff] [blame] | 63 | .then(({ data: { Links } }) => { |
Yoshie Muranaka | 33d755f | 2021-02-18 15:24:14 -0800 | [diff] [blame] | 64 | const id = Links?.ActiveSoftwareImage['@odata.id'].split('/').pop(); |
| 65 | commit('setActiveHostFirmwareId', id); |
Yoshie Muranaka | 92a0a4a | 2020-07-15 10:30:31 -0700 | [diff] [blame] | 66 | }) |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 67 | .catch((error) => console.log(error)); |
Yoshie Muranaka | 92a0a4a | 2020-07-15 10:30:31 -0700 | [diff] [blame] | 68 | }, |
Yoshie Muranaka | 33d755f | 2021-02-18 15:24:14 -0800 | [diff] [blame] | 69 | async getFirmwareInventory({ commit }) { |
| 70 | const inventoryList = await api |
| 71 | .get('/redfish/v1/UpdateService/FirmwareInventory') |
| 72 | .then(({ data: { Members = [] } = {} }) => |
Ed Tanous | 8132399 | 2024-02-27 11:26:24 -0800 | [diff] [blame] | 73 | Members.map((item) => api.get(item['@odata.id'])), |
Yoshie Muranaka | 33d755f | 2021-02-18 15:24:14 -0800 | [diff] [blame] | 74 | ) |
| 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 Muranaka | 92a0a4a | 2020-07-15 10:30:31 -0700 | [diff] [blame] | 105 | api |
| 106 | .get('/redfish/v1/UpdateService') |
| 107 | .then(({ data }) => { |
| 108 | const applyTime = |
| 109 | data.HttpPushUriOptions.HttpPushUriApplyTime.ApplyTime; |
| 110 | commit('setApplyTime', applyTime); |
greenfil | 6b424f9 | 2023-03-10 10:47:41 +0300 | [diff] [blame] | 111 | const httpPushUri = data.HttpPushUri; |
| 112 | commit('setHttpPushUri', httpPushUri); |
Yoshie Muranaka | 92a0a4a | 2020-07-15 10:30:31 -0700 | [diff] [blame] | 113 | }) |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 114 | .catch((error) => console.log(error)); |
Yoshie Muranaka | 92a0a4a | 2020-07-15 10:30:31 -0700 | [diff] [blame] | 115 | }, |
Jagpal Singh Gill | ccb71f0 | 2024-06-18 15:21:08 -0700 | [diff] [blame] | 116 | async uploadFirmware({ state }, image) { |
Yoshie Muranaka | 92a0a4a | 2020-07-15 10:30:31 -0700 | [diff] [blame] | 117 | return await api |
greenfil | 6b424f9 | 2023-03-10 10:47:41 +0300 | [diff] [blame] | 118 | .post(state.httpPushUri, image, { |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 119 | headers: { 'Content-Type': 'application/octet-stream' }, |
Yoshie Muranaka | 92a0a4a | 2020-07-15 10:30:31 -0700 | [diff] [blame] | 120 | }) |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 121 | .catch((error) => { |
Dixsie Wolmers | 46a8744 | 2020-02-26 15:26:30 -0600 | [diff] [blame] | 122 | console.log(error); |
Surya V | 603cfbf | 2024-07-11 15:19:46 +0530 | [diff] [blame] | 123 | throw new Error( |
| 124 | i18n.global.t('pageFirmware.toast.errorUpdateFirmware'), |
| 125 | ); |
Yoshie Muranaka | 92a0a4a | 2020-07-15 10:30:31 -0700 | [diff] [blame] | 126 | }); |
| 127 | }, |
Yoshie Muranaka | 33d755f | 2021-02-18 15:24:14 -0800 | [diff] [blame] | 128 | async switchBmcFirmwareAndReboot({ getters }) { |
| 129 | const backupLocation = getters.backupBmcFirmware.location; |
Yoshie Muranaka | 92a0a4a | 2020-07-15 10:30:31 -0700 | [diff] [blame] | 130 | const data = { |
| 131 | Links: { |
| 132 | ActiveSoftwareImage: { |
Yoshie Muranaka | 1dedbdf | 2020-11-30 07:04:01 -0800 | [diff] [blame] | 133 | '@odata.id': backupLocation, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 134 | }, |
| 135 | }, |
Yoshie Muranaka | 92a0a4a | 2020-07-15 10:30:31 -0700 | [diff] [blame] | 136 | }; |
| 137 | return await api |
Sean Zhang | 8841b7d | 2024-06-15 08:42:41 +0300 | [diff] [blame] | 138 | .patch(`${await this.dispatch('global/getBmcPath')}`, data) |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 139 | .catch((error) => { |
Yoshie Muranaka | 92a0a4a | 2020-07-15 10:30:31 -0700 | [diff] [blame] | 140 | console.log(error); |
Surya V | 603cfbf | 2024-07-11 15:19:46 +0530 | [diff] [blame] | 141 | throw new Error( |
| 142 | i18n.global.t('pageFirmware.toast.errorSwitchImages'), |
| 143 | ); |
Dixsie Wolmers | 46a8744 | 2020-02-26 15:26:30 -0600 | [diff] [blame] | 144 | }); |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 145 | }, |
| 146 | }, |
Dixsie Wolmers | f65ee34 | 2020-01-22 19:47:56 -0600 | [diff] [blame] | 147 | }; |
| 148 | |
| 149 | export default FirmwareStore; |