blob: 2393ba0af62ed50affe40faf6110277ce48a2b29 [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 {
HuyLe59a732b2023-10-09 13:58:33 +070015 EfficiencyRatings = [],
Yoshie Muranaka5918b482020-06-08 08:18:23 -070016 FirmwareVersion,
Dixsie Wolmers6b8aee92021-05-14 11:14:33 -050017 LocationIndicatorActive,
HuyLe59a732b2023-10-09 13:58:33 +070018 Id,
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 {
HuyLe59a732b2023-10-09 13:58:33 +070030 id: Id,
Yoshie Muranaka5918b482020-06-08 08:18:23 -070031 health: Status.Health,
32 partNumber: PartNumber,
33 serialNumber: SerialNumber,
HuyLe59a732b2023-10-09 13:58:33 +070034 efficiencyPercent: EfficiencyRatings[0].EfficiencyPercent,
Yoshie Muranaka5918b482020-06-08 08:18:23 -070035 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
HuyLe59a732b2023-10-09 13:58:33 +070073 .get(`${id}/PowerSubsystem`)
74 .then((response) => {
75 return api.get(`${response.data.PowerSupplies['@odata.id']}`);
76 })
77 .then(({ data: { Members } }) => {
78 const promises = Members.map((member) =>
79 api.get(member['@odata.id']),
80 );
81 return api.all(promises);
82 })
83 .then((response) => {
84 const data = response.map(({ data }) => data);
85 return data;
86 })
MichalX Szopinskidca9b0a2021-05-07 13:14:50 +020087 .catch((error) => console.log(error));
88 },
Derick Montague602e98a2020-10-21 16:20:00 -050089 },
Yoshie Muranaka5918b482020-06-08 08:18:23 -070090};
91
92export default PowerSupplyStore;