blob: 8a08e37061ed5ab192b30efc621846afc9a394f5 [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,
Sneha Patel9f612342021-09-02 12:23:42 -050028 Location,
Yoshie Muranaka09e8b5d2020-06-08 07:36:59 -070029 } = chassis;
30
31 return {
32 id: Id,
33 health: Status.Health,
34 partNumber: PartNumber,
35 serialNumber: SerialNumber,
36 chassisType: ChassisType,
37 manufacturer: Manufacturer,
38 powerState: PowerState,
39 statusState: Status.State,
Derick Montague602e98a2020-10-21 16:20:00 -050040 healthRollup: Status.HealthRollup,
Sandeepa Singh240c0562021-05-06 21:59:20 +053041 assetTag: AssetTag,
42 maxPowerWatts: MaxPowerWatts,
43 minPowerWatts: MinPowerWatts,
44 name: Name,
45 identifyLed: LocationIndicatorActive,
46 uri: chassis['@odata.id'],
Sneha Patel9f612342021-09-02 12:23:42 -050047 locationNumber: Location?.PartLocation?.ServiceLabel,
Yoshie Muranaka09e8b5d2020-06-08 07:36:59 -070048 };
49 });
Derick Montague602e98a2020-10-21 16:20:00 -050050 },
Yoshie Muranaka09e8b5d2020-06-08 07:36:59 -070051 },
52 actions: {
53 async getChassisInfo({ commit }) {
54 return await api
55 .get('/redfish/v1/Chassis')
56 .then(({ data: { Members = [] } }) =>
Derick Montague602e98a2020-10-21 16:20:00 -050057 Members.map((member) => api.get(member['@odata.id']))
Yoshie Muranaka09e8b5d2020-06-08 07:36:59 -070058 )
Derick Montague602e98a2020-10-21 16:20:00 -050059 .then((promises) => api.all(promises))
60 .then((response) => {
Yoshie Muranaka09e8b5d2020-06-08 07:36:59 -070061 const data = response.map(({ data }) => data);
62 commit('setChassisInfo', data);
63 })
Derick Montague602e98a2020-10-21 16:20:00 -050064 .catch((error) => console.log(error));
65 },
Sandeepa Singh240c0562021-05-06 21:59:20 +053066 async updateIdentifyLedValue({ dispatch }, led) {
67 const uri = led.uri;
68 const updatedIdentifyLedValue = {
69 LocationIndicatorActive: led.identifyLed,
70 };
71 return await api
72 .patch(uri, updatedIdentifyLedValue)
73 .then(() => dispatch('getChassisInfo'))
74 .catch((error) => {
75 dispatch('getChassisInfo');
76 console.log('error', error);
77 if (led.identifyLed) {
78 throw new Error(
Sandeepa Singh7affc522021-07-06 16:29:10 +053079 i18n.t('pageInventory.toast.errorEnableIdentifyLed')
Sandeepa Singh240c0562021-05-06 21:59:20 +053080 );
81 } else {
82 throw new Error(
Sandeepa Singh7affc522021-07-06 16:29:10 +053083 i18n.t('pageInventory.toast.errorDisableIdentifyLed')
Sandeepa Singh240c0562021-05-06 21:59:20 +053084 );
85 }
86 });
87 },
Derick Montague602e98a2020-10-21 16:20:00 -050088 },
Yoshie Muranaka09e8b5d2020-06-08 07:36:59 -070089};
90
91export default ChassisStore;