blob: cc82f2effb6746c7c90e233939ffa2dfa5718c21 [file] [log] [blame]
Yoshie Muranaka5918b482020-06-08 08:18:23 -07001import api from '@/store/api';
2
3const PowerSupplyStore = {
4 namespaced: true,
5 state: {
Derick Montague602e98a2020-10-21 16:20:00 -05006 powerSupplies: [],
Yoshie Muranaka5918b482020-06-08 08:18:23 -07007 },
8 getters: {
Derick Montague602e98a2020-10-21 16:20:00 -05009 powerSupplies: (state) => state.powerSupplies,
Yoshie Muranaka5918b482020-06-08 08:18:23 -070010 },
11 mutations: {
12 setPowerSupply: (state, data) => {
Derick Montague602e98a2020-10-21 16:20:00 -050013 state.powerSupplies = data.map((powerSupply) => {
Yoshie Muranaka5918b482020-06-08 08:18:23 -070014 const {
15 EfficiencyPercent,
16 FirmwareVersion,
17 IndicatorLED,
18 MemberId,
19 Model,
20 PartNumber,
21 PowerInputWatts,
22 SerialNumber,
Derick Montague602e98a2020-10-21 16:20:00 -050023 Status,
Yoshie Muranaka5918b482020-06-08 08:18:23 -070024 } = powerSupply;
25 return {
26 id: MemberId,
27 health: Status.Health,
28 partNumber: PartNumber,
29 serialNumber: SerialNumber,
30 efficiencyPercent: EfficiencyPercent,
31 firmwareVersion: FirmwareVersion,
32 indicatorLed: IndicatorLED,
33 model: Model,
34 powerInputWatts: PowerInputWatts,
Derick Montague602e98a2020-10-21 16:20:00 -050035 statusState: Status.State,
Yoshie Muranaka5918b482020-06-08 08:18:23 -070036 };
37 });
Derick Montague602e98a2020-10-21 16:20:00 -050038 },
Yoshie Muranaka5918b482020-06-08 08:18:23 -070039 },
40 actions: {
MichalX Szopinskidca9b0a2021-05-07 13:14:50 +020041 async getChassisCollection() {
Yoshie Muranaka5918b482020-06-08 08:18:23 -070042 return await api
MichalX Szopinskidca9b0a2021-05-07 13:14:50 +020043 .get('/redfish/v1/Chassis')
44 .then(({ data: { Members } }) =>
45 Members.map((member) => member['@odata.id'])
Yoshie Muranaka5918b482020-06-08 08:18:23 -070046 )
Derick Montague602e98a2020-10-21 16:20:00 -050047 .catch((error) => console.log(error));
48 },
MichalX Szopinskidca9b0a2021-05-07 13:14:50 +020049 async getAllPowerSupplies({ dispatch, commit }) {
50 const collection = await dispatch('getChassisCollection');
51 if (!collection) return;
52 return await api
53 .all(collection.map((chassis) => dispatch('getChassisPower', chassis)))
54 .then((supplies) => {
55 let suppliesList = [];
56 supplies.forEach(
57 (supply) => (suppliesList = [...suppliesList, ...supply])
58 );
59 commit('setPowerSupply', suppliesList);
60 })
61 .catch((error) => console.log(error));
62 },
63 async getChassisPower(_, id) {
64 return await api
65 .get(`${id}/Power`)
66 .then(({ data: { PowerSupplies } }) => PowerSupplies || [])
67 .catch((error) => console.log(error));
68 },
Derick Montague602e98a2020-10-21 16:20:00 -050069 },
Yoshie Muranaka5918b482020-06-08 08:18:23 -070070};
71
72export default PowerSupplyStore;