blob: b5edef5668fbea6a79b96d4274103bae8c8225cf [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,
25 MaxPowerWatts,
26 MinPowerWatts,
27 Name,
Yoshie Muranaka09e8b5d2020-06-08 07:36:59 -070028 } = chassis;
29
30 return {
31 id: Id,
32 health: Status.Health,
33 partNumber: PartNumber,
34 serialNumber: SerialNumber,
35 chassisType: ChassisType,
36 manufacturer: Manufacturer,
37 powerState: PowerState,
38 statusState: Status.State,
Derick Montague602e98a2020-10-21 16:20:00 -050039 healthRollup: Status.HealthRollup,
Sandeepa Singh240c0562021-05-06 21:59:20 +053040 assetTag: AssetTag,
41 maxPowerWatts: MaxPowerWatts,
42 minPowerWatts: MinPowerWatts,
43 name: Name,
44 identifyLed: LocationIndicatorActive,
45 uri: chassis['@odata.id'],
Yoshie Muranaka09e8b5d2020-06-08 07:36:59 -070046 };
47 });
Derick Montague602e98a2020-10-21 16:20:00 -050048 },
Yoshie Muranaka09e8b5d2020-06-08 07:36:59 -070049 },
50 actions: {
51 async getChassisInfo({ commit }) {
52 return await api
53 .get('/redfish/v1/Chassis')
54 .then(({ data: { Members = [] } }) =>
Derick Montague602e98a2020-10-21 16:20:00 -050055 Members.map((member) => api.get(member['@odata.id']))
Yoshie Muranaka09e8b5d2020-06-08 07:36:59 -070056 )
Derick Montague602e98a2020-10-21 16:20:00 -050057 .then((promises) => api.all(promises))
58 .then((response) => {
Yoshie Muranaka09e8b5d2020-06-08 07:36:59 -070059 const data = response.map(({ data }) => data);
60 commit('setChassisInfo', data);
61 })
Derick Montague602e98a2020-10-21 16:20:00 -050062 .catch((error) => console.log(error));
63 },
Sandeepa Singh240c0562021-05-06 21:59:20 +053064 async updateIdentifyLedValue({ dispatch }, led) {
65 const uri = led.uri;
66 const updatedIdentifyLedValue = {
67 LocationIndicatorActive: led.identifyLed,
68 };
69 return await api
70 .patch(uri, updatedIdentifyLedValue)
71 .then(() => dispatch('getChassisInfo'))
72 .catch((error) => {
73 dispatch('getChassisInfo');
74 console.log('error', error);
75 if (led.identifyLed) {
76 throw new Error(
Sandeepa Singh7affc522021-07-06 16:29:10 +053077 i18n.t('pageInventory.toast.errorEnableIdentifyLed')
Sandeepa Singh240c0562021-05-06 21:59:20 +053078 );
79 } else {
80 throw new Error(
Sandeepa Singh7affc522021-07-06 16:29:10 +053081 i18n.t('pageInventory.toast.errorDisableIdentifyLed')
Sandeepa Singh240c0562021-05-06 21:59:20 +053082 );
83 }
84 });
85 },
Derick Montague602e98a2020-10-21 16:20:00 -050086 },
Yoshie Muranaka09e8b5d2020-06-08 07:36:59 -070087};
88
89export default ChassisStore;