| 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 { | 
| HuyLe | 59a732b | 2023-10-09 13:58:33 +0700 | [diff] [blame] | 15 |           EfficiencyRatings = [], | 
| Yoshie Muranaka | 5918b48 | 2020-06-08 08:18:23 -0700 | [diff] [blame] | 16 |           FirmwareVersion, | 
| Dixsie Wolmers | 6b8aee9 | 2021-05-14 11:14:33 -0500 | [diff] [blame] | 17 |           LocationIndicatorActive, | 
| HuyLe | 59a732b | 2023-10-09 13:58:33 +0700 | [diff] [blame] | 18 |           Id, | 
| 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 { | 
| HuyLe | 59a732b | 2023-10-09 13:58:33 +0700 | [diff] [blame] | 30 |           id: Id, | 
| Yoshie Muranaka | 5918b48 | 2020-06-08 08:18:23 -0700 | [diff] [blame] | 31 |           health: Status.Health, | 
 | 32 |           partNumber: PartNumber, | 
 | 33 |           serialNumber: SerialNumber, | 
| HuyLe | 59a732b | 2023-10-09 13:58:33 +0700 | [diff] [blame] | 34 |           efficiencyPercent: EfficiencyRatings[0].EfficiencyPercent, | 
| Yoshie Muranaka | 5918b48 | 2020-06-08 08:18:23 -0700 | [diff] [blame] | 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 | 
| HuyLe | 59a732b | 2023-10-09 13:58:33 +0700 | [diff] [blame] | 73 |         .get(`${id}/PowerSubsystem`) | 
 | 74 |         .then((response) => { | 
 | 75 |           return api.get(`${response.data.PowerSupplies['@odata.id']}`); | 
 | 76 |         }) | 
 | 77 |         .then(({ data: { Members } }) => { | 
 | 78 |           const promises = Members.map((member) => | 
 | 79 |             api.get(member['@odata.id']), | 
 | 80 |           ); | 
 | 81 |           return api.all(promises); | 
 | 82 |         }) | 
 | 83 |         .then((response) => { | 
 | 84 |           const data = response.map(({ data }) => data); | 
 | 85 |           return data; | 
 | 86 |         }) | 
| MichalX Szopinski | dca9b0a | 2021-05-07 13:14:50 +0200 | [diff] [blame] | 87 |         .catch((error) => console.log(error)); | 
 | 88 |     }, | 
| Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 89 |   }, | 
| Yoshie Muranaka | 5918b48 | 2020-06-08 08:18:23 -0700 | [diff] [blame] | 90 | }; | 
 | 91 |  | 
 | 92 | export default PowerSupplyStore; |