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