Dixsie Wolmers | f65ee34 | 2020-01-22 19:47:56 -0600 | [diff] [blame] | 1 | import api from '../../api'; |
| 2 | |
| 3 | const FirmwareStore = { |
| 4 | namespaced: true, |
| 5 | state: { |
| 6 | firmwareInfo: null, |
| 7 | bmcActiveVersion: '--', |
| 8 | hostActiveVersion: '--' |
| 9 | }, |
| 10 | getters: { |
| 11 | firmwareInfo: state => state.firmwareInfo, |
| 12 | bmcActiveVersion: state => state.bmcActiveVersion, |
| 13 | hostActiveVersion: state => state.hostActiveVersion |
| 14 | }, |
| 15 | mutations: { |
| 16 | setFirmwareInfo: (state, firmwareInfo) => |
| 17 | (state.firmwareInfo = firmwareInfo), |
| 18 | setBmcActiveVersion: (state, bmcActiveVersion) => |
| 19 | (state.bmcActiveVersion = bmcActiveVersion), |
| 20 | setHostActiveVersion: (state, hostActiveVersion) => |
| 21 | (state.hostActiveVersion = hostActiveVersion) |
| 22 | }, |
| 23 | actions: { |
| 24 | getFirmwareInfo({ commit }) { |
| 25 | api |
| 26 | .get('/xyz/openbmc_project/software/enumerate') |
| 27 | .then(response => { |
| 28 | const firmwareInfo = response.data.data; |
| 29 | const functionalImages = |
| 30 | firmwareInfo['/xyz/openbmc_project/software/functional'].endpoints; |
| 31 | for (let key in firmwareInfo) { |
| 32 | /** |
| 33 | * If "Functional" activation status is |
| 34 | * functional, else it is "activation" |
| 35 | * github.com/openbmc/phosphor-dbus-interfaces/blob/master/xyz/openbmc_project/Software/Activation.interface.yaml |
| 36 | */ |
| 37 | if (firmwareInfo[key].hasOwnProperty('Version')) { |
| 38 | let activationStatus = ''; |
| 39 | const imageType = firmwareInfo[key].Purpose.split('.').pop(); |
| 40 | if (functionalImages.includes(key)) { |
| 41 | activationStatus = 'Functional'; |
| 42 | } |
| 43 | // Get BMC and Host active Versions |
| 44 | if (activationStatus == 'Functional' && imageType == 'BMC') { |
| 45 | commit('setBmcActiveVersion', firmwareInfo[key].Version); |
| 46 | } |
| 47 | if (activationStatus == 'Functional' && imageType == 'Host') { |
| 48 | commit('setHostActiveVersion', firmwareInfo[key].Version); |
| 49 | } |
| 50 | } |
| 51 | } |
| 52 | }) |
| 53 | .catch(error => { |
| 54 | console.log(error); |
| 55 | }); |
| 56 | } |
| 57 | } |
| 58 | }; |
| 59 | |
| 60 | export default FirmwareStore; |