Yoshie Muranaka | b89a53c | 2020-06-15 13:25:46 -0700 | [diff] [blame] | 1 | import api from '@/store/api'; |
| 2 | |
| 3 | const FanStore = { |
| 4 | namespaced: true, |
| 5 | state: { |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 6 | fans: [], |
Yoshie Muranaka | b89a53c | 2020-06-15 13:25:46 -0700 | [diff] [blame] | 7 | }, |
| 8 | getters: { |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 9 | fans: (state) => state.fans, |
Yoshie Muranaka | b89a53c | 2020-06-15 13:25:46 -0700 | [diff] [blame] | 10 | }, |
| 11 | mutations: { |
| 12 | setFanInfo: (state, data) => { |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 13 | state.fans = data.map((fan) => { |
Gunnar Mills | 2e6c7cc | 2024-03-05 02:01:35 -0700 | [diff] [blame^] | 14 | const { |
| 15 | Id, |
| 16 | Name, |
| 17 | PartNumber, |
| 18 | SerialNumber, |
| 19 | SpeedPercent = {}, |
| 20 | Status = {}, |
| 21 | } = fan; |
| 22 | return { |
| 23 | id: Id, |
| 24 | health: Status.Health, |
| 25 | name: Name, |
| 26 | speed: SpeedPercent.Reading, |
| 27 | statusState: Status.State, |
| 28 | healthRollup: Status.HealthRollup, |
| 29 | partNumber: PartNumber, |
| 30 | serialNumber: SerialNumber, |
| 31 | }; |
Yoshie Muranaka | b89a53c | 2020-06-15 13:25:46 -0700 | [diff] [blame] | 32 | }); |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 33 | }, |
Yoshie Muranaka | b89a53c | 2020-06-15 13:25:46 -0700 | [diff] [blame] | 34 | }, |
| 35 | actions: { |
MichalX Szopinski | 6c5418f | 2022-02-25 13:13:27 +0100 | [diff] [blame] | 36 | async getChassisCollection() { |
Yoshie Muranaka | b89a53c | 2020-06-15 13:25:46 -0700 | [diff] [blame] | 37 | return await api |
MichalX Szopinski | 6c5418f | 2022-02-25 13:13:27 +0100 | [diff] [blame] | 38 | .get('/redfish/v1/Chassis') |
| 39 | .then(({ data: { Members } }) => |
| 40 | api.all( |
| 41 | Members.map((member) => |
Ed Tanous | 8132399 | 2024-02-27 11:26:24 -0800 | [diff] [blame] | 42 | api.get(member['@odata.id']).then((response) => response.data), |
| 43 | ), |
| 44 | ), |
MichalX Szopinski | 6c5418f | 2022-02-25 13:13:27 +0100 | [diff] [blame] | 45 | ) |
| 46 | .catch((error) => console.log(error)); |
| 47 | }, |
| 48 | async getFanInfo({ dispatch, commit }) { |
| 49 | const collection = await dispatch('getChassisCollection'); |
| 50 | if (!collection || collection.length === 0) return; |
| 51 | return await api |
| 52 | .all(collection.map((chassis) => dispatch('getChassisFans', chassis))) |
| 53 | .then((fansFromChassis) => commit('setFanInfo', fansFromChassis.flat())) |
| 54 | .catch((error) => console.log(error)); |
| 55 | }, |
| 56 | async getChassisFans(_, chassis) { |
Gunnar Mills | 2e6c7cc | 2024-03-05 02:01:35 -0700 | [diff] [blame^] | 57 | return await api |
| 58 | .get(chassis.ThermalSubsystem['@odata.id']) |
| 59 | .then((response) => { |
| 60 | return api.get(`${response.data.Fans['@odata.id']}`); |
| 61 | }) |
| 62 | .then(({ data: { Members } }) => { |
| 63 | const promises = Members.map((member) => |
| 64 | api.get(member['@odata.id']), |
| 65 | ); |
| 66 | return api.all(promises); |
| 67 | }) |
| 68 | .then((response) => { |
| 69 | const data = response.map(({ data }) => data); |
| 70 | return data; |
| 71 | }) |
| 72 | .catch((error) => console.log(error)); |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 73 | }, |
| 74 | }, |
Yoshie Muranaka | b89a53c | 2020-06-15 13:25:46 -0700 | [diff] [blame] | 75 | }; |
| 76 | |
| 77 | export default FanStore; |