blob: f7be2809bc31c5e647eb715b27a3f67eadff6809 [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,
Dixsie Wolmers6b8aee92021-05-14 11:14:33 -050017 LocationIndicatorActive,
Yoshie Muranaka5918b482020-06-08 08:18:23 -070018 MemberId,
Dixsie Wolmers6b8aee92021-05-14 11:14:33 -050019 Manufacturer,
Yoshie Muranaka5918b482020-06-08 08:18:23 -070020 Model,
Dixsie Wolmers6b8aee92021-05-14 11:14:33 -050021 Name,
Yoshie Muranaka5918b482020-06-08 08:18:23 -070022 PartNumber,
23 PowerInputWatts,
24 SerialNumber,
Dixsie Wolmers6b8aee92021-05-14 11:14:33 -050025 SparePartNumber,
26 Status = {},
Yoshie Muranaka5918b482020-06-08 08:18:23 -070027 } = powerSupply;
28 return {
29 id: MemberId,
30 health: Status.Health,
31 partNumber: PartNumber,
32 serialNumber: SerialNumber,
33 efficiencyPercent: EfficiencyPercent,
34 firmwareVersion: FirmwareVersion,
Dixsie Wolmers6b8aee92021-05-14 11:14:33 -050035 identifyLed: LocationIndicatorActive,
36 manufacturer: Manufacturer,
Yoshie Muranaka5918b482020-06-08 08:18:23 -070037 model: Model,
38 powerInputWatts: PowerInputWatts,
Dixsie Wolmers6b8aee92021-05-14 11:14:33 -050039 name: Name,
40 sparePartNumber: SparePartNumber,
Derick Montague602e98a2020-10-21 16:20:00 -050041 statusState: Status.State,
Yoshie Muranaka5918b482020-06-08 08:18:23 -070042 };
43 });
Derick Montague602e98a2020-10-21 16:20:00 -050044 },
Yoshie Muranaka5918b482020-06-08 08:18:23 -070045 },
46 actions: {
MichalX Szopinskidca9b0a2021-05-07 13:14:50 +020047 async getChassisCollection() {
Yoshie Muranaka5918b482020-06-08 08:18:23 -070048 return await api
MichalX Szopinskidca9b0a2021-05-07 13:14:50 +020049 .get('/redfish/v1/Chassis')
50 .then(({ data: { Members } }) =>
51 Members.map((member) => member['@odata.id'])
Yoshie Muranaka5918b482020-06-08 08:18:23 -070052 )
Derick Montague602e98a2020-10-21 16:20:00 -050053 .catch((error) => console.log(error));
54 },
MichalX Szopinskidca9b0a2021-05-07 13:14:50 +020055 async getAllPowerSupplies({ dispatch, commit }) {
56 const collection = await dispatch('getChassisCollection');
57 if (!collection) return;
58 return await api
59 .all(collection.map((chassis) => dispatch('getChassisPower', chassis)))
60 .then((supplies) => {
61 let suppliesList = [];
62 supplies.forEach(
63 (supply) => (suppliesList = [...suppliesList, ...supply])
64 );
65 commit('setPowerSupply', suppliesList);
66 })
67 .catch((error) => console.log(error));
68 },
69 async getChassisPower(_, id) {
70 return await api
71 .get(`${id}/Power`)
72 .then(({ data: { PowerSupplies } }) => PowerSupplies || [])
73 .catch((error) => console.log(error));
74 },
Derick Montague602e98a2020-10-21 16:20:00 -050075 },
Yoshie Muranaka5918b482020-06-08 08:18:23 -070076};
77
78export default PowerSupplyStore;