diff options
author | Yoshie Muranaka <yoshiemuranaka@gmail.com> | 2020-10-06 23:46:58 +0300 |
---|---|---|
committer | Derick Montague <derick.montague@ibm.com> | 2020-10-09 18:49:02 +0300 |
commit | d227f1cc41e13f23dcdb00e5ea551c6f36161298 (patch) | |
tree | f818f18e2327fa496c467e8e1201372fda6b3c25 /src/store/modules/Configuration/FirmwareStore.js | |
parent | 656b2ec58467192e8a41f0e573749e8ab2f7dc94 (diff) | |
download | webui-vue-d227f1cc41e13f23dcdb00e5ea551c6f36161298.tar.xz |
Refactor firmware store to get backup from SoftwareImages
Eliminates an extra call to find the system backup firmware image.
Signed-off-by: Yoshie Muranaka <yoshiemuranaka@gmail.com>
Change-Id: I82e36c6b8982dc3bfbdfb57c9ee143c1367e7c9e
Diffstat (limited to 'src/store/modules/Configuration/FirmwareStore.js')
-rw-r--r-- | src/store/modules/Configuration/FirmwareStore.js | 61 |
1 files changed, 29 insertions, 32 deletions
diff --git a/src/store/modules/Configuration/FirmwareStore.js b/src/store/modules/Configuration/FirmwareStore.js index 53865176..d9d3cfb8 100644 --- a/src/store/modules/Configuration/FirmwareStore.js +++ b/src/store/modules/Configuration/FirmwareStore.js @@ -39,43 +39,40 @@ const FirmwareStore = { setApplyTime: (state, applyTime) => (state.applyTime = applyTime) }, actions: { - async getSystemFirwareVersion({ commit, state }) { + async getSystemFirwareVersion({ commit }) { return await api .get('/redfish/v1/Managers/bmc') - .then(({ data: { Links: { ActiveSoftwareImage } } }) => { - const location = ActiveSoftwareImage['@odata.id']; - return api.get(location); + .then(({ data: { Links } }) => { + const currentLocation = Links.ActiveSoftwareImage['@odata.id']; + // Check SoftwareImages list for not ActiveSoftwareImage id + const backupLocation = Links.SoftwareImages.map( + item => item['@odata.id'] + ).find(location => { + const id = location.split('/').pop(); + const currentId = currentLocation.split('/').pop(); + return id !== currentId; + }); + return { currentLocation, backupLocation }; }) - .then(({ data }) => { - const version = data.Version; - const id = data.Id; - const location = data['@odata.id']; - commit('setActiveFirmware', { version, id, location }); - // TODO: temporary workaround to get 'Backup' Firmware - // information - return api.get('/redfish/v1/UpdateService/FirmwareInventory'); - }) - .then(({ data: { Members } }) => { - // TODO: temporary workaround to get 'Backup' Firmware - // information - // Check FirmwareInventory list for not ActiveSoftwareImage id - const backupLocation = Members.map(item => item['@odata.id']).find( - location => { - const id = location.split('/').pop(); - return id !== state.activeFirmware.id; - } - ); + .then(async ({ currentLocation, backupLocation }) => { + const currentData = await api.get(currentLocation); + let backupData = {}; + if (backupLocation) { - return api.get(backupLocation); + backupData = await api.get(backupLocation); } - }) - .then(({ data } = {}) => { - if (!data) return; - const version = data.Version; - const id = data.Id; - const location = data['@odata.id']; - const status = data.Status ? data.Status.State : '--'; - commit('setBackupFirmware', { version, id, location, status }); + + commit('setActiveFirmware', { + version: currentData?.data?.Version, + id: currentData?.data?.Id, + location: currentData?.data?.['@odata.id'] + }); + commit('setBackupFirmware', { + version: backupData.data?.Version, + id: backupData.data?.Id, + location: backupData.data?.['@odata.id'], + status: backupData.data?.Status?.State + }); }) .catch(error => console.log(error)); }, |