blob: 82b717463dad68877f5c53460d9a5ddc3d7595c3 [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,
Sneha Patel9f612342021-09-02 12:23:42 -050026 Location,
Dixsie Wolmers6b8aee92021-05-14 11:14:33 -050027 Status = {},
Yoshie Muranaka5918b482020-06-08 08:18:23 -070028 } = powerSupply;
29 return {
30 id: MemberId,
31 health: Status.Health,
32 partNumber: PartNumber,
33 serialNumber: SerialNumber,
34 efficiencyPercent: EfficiencyPercent,
35 firmwareVersion: FirmwareVersion,
Dixsie Wolmers6b8aee92021-05-14 11:14:33 -050036 identifyLed: LocationIndicatorActive,
37 manufacturer: Manufacturer,
Yoshie Muranaka5918b482020-06-08 08:18:23 -070038 model: Model,
39 powerInputWatts: PowerInputWatts,
Dixsie Wolmers6b8aee92021-05-14 11:14:33 -050040 name: Name,
41 sparePartNumber: SparePartNumber,
Sneha Patel9f612342021-09-02 12:23:42 -050042 locationNumber: Location?.PartLocation?.ServiceLabel,
Derick Montague602e98a2020-10-21 16:20:00 -050043 statusState: Status.State,
Yoshie Muranaka5918b482020-06-08 08:18:23 -070044 };
45 });
Derick Montague602e98a2020-10-21 16:20:00 -050046 },
Yoshie Muranaka5918b482020-06-08 08:18:23 -070047 },
48 actions: {
MichalX Szopinskidca9b0a2021-05-07 13:14:50 +020049 async getChassisCollection() {
Yoshie Muranaka5918b482020-06-08 08:18:23 -070050 return await api
MichalX Szopinskidca9b0a2021-05-07 13:14:50 +020051 .get('/redfish/v1/Chassis')
52 .then(({ data: { Members } }) =>
Ed Tanous81323992024-02-27 11:26:24 -080053 Members.map((member) => member['@odata.id']),
Yoshie Muranaka5918b482020-06-08 08:18:23 -070054 )
Derick Montague602e98a2020-10-21 16:20:00 -050055 .catch((error) => console.log(error));
56 },
MichalX Szopinskidca9b0a2021-05-07 13:14:50 +020057 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 Tanous81323992024-02-27 11:26:24 -080065 (supply) => (suppliesList = [...suppliesList, ...supply]),
MichalX Szopinskidca9b0a2021-05-07 13:14:50 +020066 );
67 commit('setPowerSupply', suppliesList);
68 })
69 .catch((error) => console.log(error));
70 },
71 async getChassisPower(_, id) {
72 return await api
73 .get(`${id}/Power`)
74 .then(({ data: { PowerSupplies } }) => PowerSupplies || [])
75 .catch((error) => console.log(error));
76 },
Derick Montague602e98a2020-10-21 16:20:00 -050077 },
Yoshie Muranaka5918b482020-06-08 08:18:23 -070078};
79
80export default PowerSupplyStore;