Yoshie Muranaka | 5918b48 | 2020-06-08 08:18:23 -0700 | [diff] [blame] | 1 | import api from '@/store/api'; |
| 2 | |
| 3 | const PowerSupplyStore = { |
| 4 | namespaced: true, |
| 5 | state: { |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 6 | powerSupplies: [], |
Yoshie Muranaka | 5918b48 | 2020-06-08 08:18:23 -0700 | [diff] [blame] | 7 | }, |
| 8 | getters: { |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 9 | powerSupplies: (state) => state.powerSupplies, |
Yoshie Muranaka | 5918b48 | 2020-06-08 08:18:23 -0700 | [diff] [blame] | 10 | }, |
| 11 | mutations: { |
| 12 | setPowerSupply: (state, data) => { |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 13 | state.powerSupplies = data.map((powerSupply) => { |
Yoshie Muranaka | 5918b48 | 2020-06-08 08:18:23 -0700 | [diff] [blame] | 14 | const { |
| 15 | EfficiencyPercent, |
| 16 | FirmwareVersion, |
| 17 | IndicatorLED, |
| 18 | MemberId, |
| 19 | Model, |
| 20 | PartNumber, |
| 21 | PowerInputWatts, |
| 22 | SerialNumber, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 23 | Status, |
Yoshie Muranaka | 5918b48 | 2020-06-08 08:18:23 -0700 | [diff] [blame] | 24 | } = powerSupply; |
| 25 | return { |
| 26 | id: MemberId, |
| 27 | health: Status.Health, |
| 28 | partNumber: PartNumber, |
| 29 | serialNumber: SerialNumber, |
| 30 | efficiencyPercent: EfficiencyPercent, |
| 31 | firmwareVersion: FirmwareVersion, |
| 32 | indicatorLed: IndicatorLED, |
| 33 | model: Model, |
| 34 | powerInputWatts: PowerInputWatts, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 35 | statusState: Status.State, |
Yoshie Muranaka | 5918b48 | 2020-06-08 08:18:23 -0700 | [diff] [blame] | 36 | }; |
| 37 | }); |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 38 | }, |
Yoshie Muranaka | 5918b48 | 2020-06-08 08:18:23 -0700 | [diff] [blame] | 39 | }, |
| 40 | actions: { |
MichalX Szopinski | dca9b0a | 2021-05-07 13:14:50 +0200 | [diff] [blame^] | 41 | async getChassisCollection() { |
Yoshie Muranaka | 5918b48 | 2020-06-08 08:18:23 -0700 | [diff] [blame] | 42 | return await api |
MichalX Szopinski | dca9b0a | 2021-05-07 13:14:50 +0200 | [diff] [blame^] | 43 | .get('/redfish/v1/Chassis') |
| 44 | .then(({ data: { Members } }) => |
| 45 | Members.map((member) => member['@odata.id']) |
Yoshie Muranaka | 5918b48 | 2020-06-08 08:18:23 -0700 | [diff] [blame] | 46 | ) |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 47 | .catch((error) => console.log(error)); |
| 48 | }, |
MichalX Szopinski | dca9b0a | 2021-05-07 13:14:50 +0200 | [diff] [blame^] | 49 | async getAllPowerSupplies({ dispatch, commit }) { |
| 50 | const collection = await dispatch('getChassisCollection'); |
| 51 | if (!collection) return; |
| 52 | return await api |
| 53 | .all(collection.map((chassis) => dispatch('getChassisPower', chassis))) |
| 54 | .then((supplies) => { |
| 55 | let suppliesList = []; |
| 56 | supplies.forEach( |
| 57 | (supply) => (suppliesList = [...suppliesList, ...supply]) |
| 58 | ); |
| 59 | commit('setPowerSupply', suppliesList); |
| 60 | }) |
| 61 | .catch((error) => console.log(error)); |
| 62 | }, |
| 63 | async getChassisPower(_, id) { |
| 64 | return await api |
| 65 | .get(`${id}/Power`) |
| 66 | .then(({ data: { PowerSupplies } }) => PowerSupplies || []) |
| 67 | .catch((error) => console.log(error)); |
| 68 | }, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 69 | }, |
Yoshie Muranaka | 5918b48 | 2020-06-08 08:18:23 -0700 | [diff] [blame] | 70 | }; |
| 71 | |
| 72 | export default PowerSupplyStore; |