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, |
Yoshie Muranaka | 33d755f | 2021-02-18 15:24:14 -0800 | [diff] [blame] | 13 | tftpAvailable: false, |
Dixsie Wolmers | f65ee34 | 2020-01-22 19:47:56 -0600 | [diff] [blame] | 14 | }, |
| 15 | getters: { |
Yoshie Muranaka | 33d755f | 2021-02-18 15:24:14 -0800 | [diff] [blame] | 16 | isTftpUploadAvailable: (state) => state.tftpAvailable, |
| 17 | isSingleFileUploadEnabled: (state) => state.hostFirmware.length === 0, |
| 18 | activeBmcFirmware: (state) => { |
| 19 | return state.bmcFirmware.find( |
Ed Tanous | 8132399 | 2024-02-27 11:26:24 -0800 | [diff] [blame] | 20 | (firmware) => firmware.id === state.bmcActiveFirmwareId, |
Yoshie Muranaka | 33d755f | 2021-02-18 15:24:14 -0800 | [diff] [blame] | 21 | ); |
| 22 | }, |
| 23 | activeHostFirmware: (state) => { |
| 24 | return state.hostFirmware.find( |
Ed Tanous | 8132399 | 2024-02-27 11:26:24 -0800 | [diff] [blame] | 25 | (firmware) => firmware.id === state.hostActiveFirmwareId, |
Yoshie Muranaka | 33d755f | 2021-02-18 15:24:14 -0800 | [diff] [blame] | 26 | ); |
| 27 | }, |
| 28 | backupBmcFirmware: (state) => { |
| 29 | return state.bmcFirmware.find( |
Ed Tanous | 8132399 | 2024-02-27 11:26:24 -0800 | [diff] [blame] | 30 | (firmware) => firmware.id !== state.bmcActiveFirmwareId, |
Yoshie Muranaka | 33d755f | 2021-02-18 15:24:14 -0800 | [diff] [blame] | 31 | ); |
| 32 | }, |
| 33 | backupHostFirmware: (state) => { |
| 34 | return state.hostFirmware.find( |
Ed Tanous | 8132399 | 2024-02-27 11:26:24 -0800 | [diff] [blame] | 35 | (firmware) => firmware.id !== state.hostActiveFirmwareId, |
Yoshie Muranaka | 33d755f | 2021-02-18 15:24:14 -0800 | [diff] [blame] | 36 | ); |
| 37 | }, |
Dixsie Wolmers | f65ee34 | 2020-01-22 19:47:56 -0600 | [diff] [blame] | 38 | }, |
| 39 | mutations: { |
Yoshie Muranaka | 33d755f | 2021-02-18 15:24:14 -0800 | [diff] [blame] | 40 | setActiveBmcFirmwareId: (state, id) => (state.bmcActiveFirmwareId = id), |
| 41 | setActiveHostFirmwareId: (state, id) => (state.hostActiveFirmwareId = id), |
| 42 | setBmcFirmware: (state, firmware) => (state.bmcFirmware = firmware), |
| 43 | setHostFirmware: (state, firmware) => (state.hostFirmware = firmware), |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 44 | setApplyTime: (state, applyTime) => (state.applyTime = applyTime), |
greenfil | 6b424f9 | 2023-03-10 10:47:41 +0300 | [diff] [blame] | 45 | setHttpPushUri: (state, httpPushUri) => (state.httpPushUri = httpPushUri), |
Yoshie Muranaka | 33d755f | 2021-02-18 15:24:14 -0800 | [diff] [blame] | 46 | setTftpUploadAvailable: (state, tftpAvailable) => |
| 47 | (state.tftpAvailable = tftpAvailable), |
Dixsie Wolmers | f65ee34 | 2020-01-22 19:47:56 -0600 | [diff] [blame] | 48 | }, |
| 49 | actions: { |
Yoshie Muranaka | 98bb24e | 2020-10-06 10:00:19 -0700 | [diff] [blame] | 50 | async getFirmwareInformation({ dispatch }) { |
Yoshie Muranaka | 33d755f | 2021-02-18 15:24:14 -0800 | [diff] [blame] | 51 | dispatch('getActiveHostFirmware'); |
| 52 | dispatch('getActiveBmcFirmware'); |
| 53 | return await dispatch('getFirmwareInventory'); |
Yoshie Muranaka | 98bb24e | 2020-10-06 10:00:19 -0700 | [diff] [blame] | 54 | }, |
Yoshie Muranaka | 33d755f | 2021-02-18 15:24:14 -0800 | [diff] [blame] | 55 | getActiveBmcFirmware({ commit }) { |
| 56 | return api |
Dixsie Wolmers | 46a8744 | 2020-02-26 15:26:30 -0600 | [diff] [blame] | 57 | .get('/redfish/v1/Managers/bmc') |
Yoshie Muranaka | d227f1c | 2020-10-06 13:46:58 -0700 | [diff] [blame] | 58 | .then(({ data: { Links } }) => { |
Yoshie Muranaka | 33d755f | 2021-02-18 15:24:14 -0800 | [diff] [blame] | 59 | const id = Links?.ActiveSoftwareImage['@odata.id'].split('/').pop(); |
| 60 | commit('setActiveBmcFirmwareId', id); |
Yoshie Muranaka | 98bb24e | 2020-10-06 10:00:19 -0700 | [diff] [blame] | 61 | }) |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 62 | .catch((error) => console.log(error)); |
Yoshie Muranaka | 98bb24e | 2020-10-06 10:00:19 -0700 | [diff] [blame] | 63 | }, |
Yoshie Muranaka | 33d755f | 2021-02-18 15:24:14 -0800 | [diff] [blame] | 64 | getActiveHostFirmware({ commit }) { |
| 65 | return api |
Yoshie Muranaka | 98bb24e | 2020-10-06 10:00:19 -0700 | [diff] [blame] | 66 | .get('/redfish/v1/Systems/system/Bios') |
| 67 | .then(({ data: { Links } }) => { |
Yoshie Muranaka | 33d755f | 2021-02-18 15:24:14 -0800 | [diff] [blame] | 68 | const id = Links?.ActiveSoftwareImage['@odata.id'].split('/').pop(); |
| 69 | commit('setActiveHostFirmwareId', id); |
Yoshie Muranaka | 92a0a4a | 2020-07-15 10:30:31 -0700 | [diff] [blame] | 70 | }) |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 71 | .catch((error) => console.log(error)); |
Yoshie Muranaka | 92a0a4a | 2020-07-15 10:30:31 -0700 | [diff] [blame] | 72 | }, |
Yoshie Muranaka | 33d755f | 2021-02-18 15:24:14 -0800 | [diff] [blame] | 73 | async getFirmwareInventory({ commit }) { |
| 74 | const inventoryList = await api |
| 75 | .get('/redfish/v1/UpdateService/FirmwareInventory') |
| 76 | .then(({ data: { Members = [] } = {} }) => |
Ed Tanous | 8132399 | 2024-02-27 11:26:24 -0800 | [diff] [blame] | 77 | Members.map((item) => api.get(item['@odata.id'])), |
Yoshie Muranaka | 33d755f | 2021-02-18 15:24:14 -0800 | [diff] [blame] | 78 | ) |
| 79 | .catch((error) => console.log(error)); |
| 80 | await api |
| 81 | .all(inventoryList) |
| 82 | .then((response) => { |
| 83 | const bmcFirmware = []; |
| 84 | const hostFirmware = []; |
| 85 | response.forEach(({ data }) => { |
| 86 | const firmwareType = data?.RelatedItem?.[0]?.['@odata.id'] |
| 87 | .split('/') |
| 88 | .pop(); |
| 89 | const item = { |
| 90 | version: data?.Version, |
| 91 | id: data?.Id, |
| 92 | location: data?.['@odata.id'], |
| 93 | status: data?.Status?.Health, |
| 94 | }; |
| 95 | if (firmwareType === 'bmc') { |
| 96 | bmcFirmware.push(item); |
| 97 | } else if (firmwareType === 'Bios') { |
| 98 | hostFirmware.push(item); |
| 99 | } |
| 100 | }); |
| 101 | commit('setBmcFirmware', bmcFirmware); |
| 102 | commit('setHostFirmware', hostFirmware); |
| 103 | }) |
| 104 | .catch((error) => { |
| 105 | console.log(error); |
| 106 | }); |
| 107 | }, |
| 108 | getUpdateServiceSettings({ commit }) { |
Yoshie Muranaka | 92a0a4a | 2020-07-15 10:30:31 -0700 | [diff] [blame] | 109 | api |
| 110 | .get('/redfish/v1/UpdateService') |
| 111 | .then(({ data }) => { |
| 112 | const applyTime = |
| 113 | data.HttpPushUriOptions.HttpPushUriApplyTime.ApplyTime; |
Yoshie Muranaka | 33d755f | 2021-02-18 15:24:14 -0800 | [diff] [blame] | 114 | const allowableActions = |
| 115 | data?.Actions?.['#UpdateService.SimpleUpdate']?.[ |
| 116 | 'TransferProtocol@Redfish.AllowableValues' |
| 117 | ]; |
Yoshie Muranaka | 92a0a4a | 2020-07-15 10:30:31 -0700 | [diff] [blame] | 118 | commit('setApplyTime', applyTime); |
greenfil | 6b424f9 | 2023-03-10 10:47:41 +0300 | [diff] [blame] | 119 | const httpPushUri = data.HttpPushUri; |
| 120 | commit('setHttpPushUri', httpPushUri); |
Derick Montague | f7cd5e0 | 2021-05-11 17:02:00 -0500 | [diff] [blame] | 121 | if (allowableActions?.includes('TFTP')) { |
Yoshie Muranaka | 33d755f | 2021-02-18 15:24:14 -0800 | [diff] [blame] | 122 | commit('setTftpUploadAvailable', true); |
| 123 | } |
Yoshie Muranaka | 92a0a4a | 2020-07-15 10:30:31 -0700 | [diff] [blame] | 124 | }) |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 125 | .catch((error) => console.log(error)); |
Yoshie Muranaka | 92a0a4a | 2020-07-15 10:30:31 -0700 | [diff] [blame] | 126 | }, |
Jagpal Singh Gill | ccb71f0 | 2024-06-18 15:21:08 -0700 | [diff] [blame^] | 127 | async uploadFirmware({ state }, image) { |
Yoshie Muranaka | 92a0a4a | 2020-07-15 10:30:31 -0700 | [diff] [blame] | 128 | return await api |
greenfil | 6b424f9 | 2023-03-10 10:47:41 +0300 | [diff] [blame] | 129 | .post(state.httpPushUri, image, { |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 130 | headers: { 'Content-Type': 'application/octet-stream' }, |
Yoshie Muranaka | 92a0a4a | 2020-07-15 10:30:31 -0700 | [diff] [blame] | 131 | }) |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 132 | .catch((error) => { |
Dixsie Wolmers | 46a8744 | 2020-02-26 15:26:30 -0600 | [diff] [blame] | 133 | console.log(error); |
Yoshie Muranaka | 33d755f | 2021-02-18 15:24:14 -0800 | [diff] [blame] | 134 | throw new Error(i18n.t('pageFirmware.toast.errorUpdateFirmware')); |
Yoshie Muranaka | 92a0a4a | 2020-07-15 10:30:31 -0700 | [diff] [blame] | 135 | }); |
| 136 | }, |
Jagpal Singh Gill | ccb71f0 | 2024-06-18 15:21:08 -0700 | [diff] [blame^] | 137 | async uploadFirmwareTFTP(fileAddress) { |
Yoshie Muranaka | 92a0a4a | 2020-07-15 10:30:31 -0700 | [diff] [blame] | 138 | const data = { |
| 139 | TransferProtocol: 'TFTP', |
Yoshie Muranaka | 33d755f | 2021-02-18 15:24:14 -0800 | [diff] [blame] | 140 | ImageURI: fileAddress, |
Yoshie Muranaka | 92a0a4a | 2020-07-15 10:30:31 -0700 | [diff] [blame] | 141 | }; |
Yoshie Muranaka | 92a0a4a | 2020-07-15 10:30:31 -0700 | [diff] [blame] | 142 | return await api |
Gunnar Mills | 60713b0 | 2020-08-18 10:21:05 -0500 | [diff] [blame] | 143 | .post( |
| 144 | '/redfish/v1/UpdateService/Actions/UpdateService.SimpleUpdate', |
Ed Tanous | 8132399 | 2024-02-27 11:26:24 -0800 | [diff] [blame] | 145 | data, |
Gunnar Mills | 60713b0 | 2020-08-18 10:21:05 -0500 | [diff] [blame] | 146 | ) |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 147 | .catch((error) => { |
Yoshie Muranaka | 92a0a4a | 2020-07-15 10:30:31 -0700 | [diff] [blame] | 148 | console.log(error); |
Yoshie Muranaka | 33d755f | 2021-02-18 15:24:14 -0800 | [diff] [blame] | 149 | throw new Error(i18n.t('pageFirmware.toast.errorUpdateFirmware')); |
Yoshie Muranaka | 92a0a4a | 2020-07-15 10:30:31 -0700 | [diff] [blame] | 150 | }); |
| 151 | }, |
Yoshie Muranaka | 33d755f | 2021-02-18 15:24:14 -0800 | [diff] [blame] | 152 | async switchBmcFirmwareAndReboot({ getters }) { |
| 153 | const backupLocation = getters.backupBmcFirmware.location; |
Yoshie Muranaka | 92a0a4a | 2020-07-15 10:30:31 -0700 | [diff] [blame] | 154 | const data = { |
| 155 | Links: { |
| 156 | ActiveSoftwareImage: { |
Yoshie Muranaka | 1dedbdf | 2020-11-30 07:04:01 -0800 | [diff] [blame] | 157 | '@odata.id': backupLocation, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 158 | }, |
| 159 | }, |
Yoshie Muranaka | 92a0a4a | 2020-07-15 10:30:31 -0700 | [diff] [blame] | 160 | }; |
| 161 | return await api |
| 162 | .patch('/redfish/v1/Managers/bmc', data) |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 163 | .catch((error) => { |
Yoshie Muranaka | 92a0a4a | 2020-07-15 10:30:31 -0700 | [diff] [blame] | 164 | console.log(error); |
Yoshie Muranaka | 33d755f | 2021-02-18 15:24:14 -0800 | [diff] [blame] | 165 | throw new Error(i18n.t('pageFirmware.toast.errorSwitchImages')); |
Dixsie Wolmers | 46a8744 | 2020-02-26 15:26:30 -0600 | [diff] [blame] | 166 | }); |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 167 | }, |
| 168 | }, |
Dixsie Wolmers | f65ee34 | 2020-01-22 19:47:56 -0600 | [diff] [blame] | 169 | }; |
| 170 | |
| 171 | export default FirmwareStore; |