blob: 6f2d74a2240457b754f59c444010c9201b047fca [file] [log] [blame]
Yoshie Muranaka09e8b5d2020-06-08 07:36:59 -07001import api from '@/store/api';
Sandeepa Singh240c0562021-05-06 21:59:20 +05302import i18n from '@/i18n';
Yoshie Muranaka09e8b5d2020-06-08 07:36:59 -07003
4const ChassisStore = {
5 namespaced: true,
6 state: {
Derick Montague602e98a2020-10-21 16:20:00 -05007 chassis: [],
Yoshie Muranaka09e8b5d2020-06-08 07:36:59 -07008 },
9 getters: {
Derick Montague602e98a2020-10-21 16:20:00 -050010 chassis: (state) => state.chassis,
Yoshie Muranaka09e8b5d2020-06-08 07:36:59 -070011 },
12 mutations: {
13 setChassisInfo: (state, data) => {
Derick Montague602e98a2020-10-21 16:20:00 -050014 state.chassis = data.map((chassis) => {
Yoshie Muranaka09e8b5d2020-06-08 07:36:59 -070015 const {
16 Id,
17 Status = {},
18 PartNumber,
19 SerialNumber,
20 ChassisType,
21 Manufacturer,
Derick Montague602e98a2020-10-21 16:20:00 -050022 PowerState,
Sandeepa Singh240c0562021-05-06 21:59:20 +053023 LocationIndicatorActive,
24 AssetTag,
MichalX Szopinskifedc7342022-02-25 17:07:53 +010025 Model,
Sandeepa Singh240c0562021-05-06 21:59:20 +053026 MaxPowerWatts,
27 MinPowerWatts,
28 Name,
Sneha Patel9f612342021-09-02 12:23:42 -050029 Location,
Yoshie Muranaka09e8b5d2020-06-08 07:36:59 -070030 } = chassis;
31
32 return {
33 id: Id,
34 health: Status.Health,
35 partNumber: PartNumber,
36 serialNumber: SerialNumber,
37 chassisType: ChassisType,
38 manufacturer: Manufacturer,
39 powerState: PowerState,
40 statusState: Status.State,
Derick Montague602e98a2020-10-21 16:20:00 -050041 healthRollup: Status.HealthRollup,
Sandeepa Singh240c0562021-05-06 21:59:20 +053042 assetTag: AssetTag,
MichalX Szopinskifedc7342022-02-25 17:07:53 +010043 model: Model,
Sandeepa Singh240c0562021-05-06 21:59:20 +053044 maxPowerWatts: MaxPowerWatts,
45 minPowerWatts: MinPowerWatts,
46 name: Name,
47 identifyLed: LocationIndicatorActive,
48 uri: chassis['@odata.id'],
Sneha Patel9f612342021-09-02 12:23:42 -050049 locationNumber: Location?.PartLocation?.ServiceLabel,
Yoshie Muranaka09e8b5d2020-06-08 07:36:59 -070050 };
51 });
Derick Montague602e98a2020-10-21 16:20:00 -050052 },
Yoshie Muranaka09e8b5d2020-06-08 07:36:59 -070053 },
54 actions: {
55 async getChassisInfo({ commit }) {
56 return await api
57 .get('/redfish/v1/Chassis')
58 .then(({ data: { Members = [] } }) =>
Ed Tanous81323992024-02-27 11:26:24 -080059 Members.map((member) => api.get(member['@odata.id'])),
Yoshie Muranaka09e8b5d2020-06-08 07:36:59 -070060 )
Derick Montague602e98a2020-10-21 16:20:00 -050061 .then((promises) => api.all(promises))
62 .then((response) => {
Yoshie Muranaka09e8b5d2020-06-08 07:36:59 -070063 const data = response.map(({ data }) => data);
64 commit('setChassisInfo', data);
65 })
Derick Montague602e98a2020-10-21 16:20:00 -050066 .catch((error) => console.log(error));
67 },
Sandeepa Singh240c0562021-05-06 21:59:20 +053068 async updateIdentifyLedValue({ dispatch }, led) {
69 const uri = led.uri;
70 const updatedIdentifyLedValue = {
71 LocationIndicatorActive: led.identifyLed,
72 };
73 return await api
74 .patch(uri, updatedIdentifyLedValue)
75 .then(() => dispatch('getChassisInfo'))
76 .catch((error) => {
77 dispatch('getChassisInfo');
78 console.log('error', error);
79 if (led.identifyLed) {
80 throw new Error(
Ed Tanous81323992024-02-27 11:26:24 -080081 i18n.t('pageInventory.toast.errorEnableIdentifyLed'),
Sandeepa Singh240c0562021-05-06 21:59:20 +053082 );
83 } else {
84 throw new Error(
Ed Tanous81323992024-02-27 11:26:24 -080085 i18n.t('pageInventory.toast.errorDisableIdentifyLed'),
Sandeepa Singh240c0562021-05-06 21:59:20 +053086 );
87 }
88 });
89 },
Derick Montague602e98a2020-10-21 16:20:00 -050090 },
Yoshie Muranaka09e8b5d2020-06-08 07:36:59 -070091};
92
93export default ChassisStore;