blob: 202a4328fd34defd833f80f7ce770e6c306b3e03 [file] [log] [blame]
Yoshie Muranakab89a53c2020-06-15 13:25:46 -07001import api from '@/store/api';
2
3const FanStore = {
4 namespaced: true,
5 state: {
Derick Montague602e98a2020-10-21 16:20:00 -05006 fans: [],
Yoshie Muranakab89a53c2020-06-15 13:25:46 -07007 },
8 getters: {
Derick Montague602e98a2020-10-21 16:20:00 -05009 fans: (state) => state.fans,
Yoshie Muranakab89a53c2020-06-15 13:25:46 -070010 },
11 mutations: {
12 setFanInfo: (state, data) => {
Derick Montague602e98a2020-10-21 16:20:00 -050013 state.fans = data.map((fan) => {
Gunnar Mills2e6c7cc2024-03-05 02:01:35 -070014 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 Muranakab89a53c2020-06-15 13:25:46 -070032 });
Derick Montague602e98a2020-10-21 16:20:00 -050033 },
Yoshie Muranakab89a53c2020-06-15 13:25:46 -070034 },
35 actions: {
MichalX Szopinski6c5418f2022-02-25 13:13:27 +010036 async getChassisCollection() {
Yoshie Muranakab89a53c2020-06-15 13:25:46 -070037 return await api
MichalX Szopinski6c5418f2022-02-25 13:13:27 +010038 .get('/redfish/v1/Chassis')
39 .then(({ data: { Members } }) =>
40 api.all(
41 Members.map((member) =>
Ed Tanous81323992024-02-27 11:26:24 -080042 api.get(member['@odata.id']).then((response) => response.data),
43 ),
44 ),
MichalX Szopinski6c5418f2022-02-25 13:13:27 +010045 )
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 Mills2e6c7cc2024-03-05 02:01:35 -070057 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 Montague602e98a2020-10-21 16:20:00 -050073 },
74 },
Yoshie Muranakab89a53c2020-06-15 13:25:46 -070075};
76
77export default FanStore;