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