blob: e9e58e721431c5cafb9840bb73694f828027fe56 [file] [log] [blame]
Yoshie Muranaka09e8b5d2020-06-08 07:36:59 -07001import api from '@/store/api';
2
3const ChassisStore = {
4 namespaced: true,
5 state: {
6 chassis: []
7 },
8 getters: {
9 chassis: state => state.chassis
10 },
11 mutations: {
12 setChassisInfo: (state, data) => {
13 state.chassis = data.map(chassis => {
14 const {
15 Id,
16 Status = {},
17 PartNumber,
18 SerialNumber,
19 ChassisType,
20 Manufacturer,
21 PowerState
22 } = chassis;
23
24 return {
25 id: Id,
26 health: Status.Health,
27 partNumber: PartNumber,
28 serialNumber: SerialNumber,
29 chassisType: ChassisType,
30 manufacturer: Manufacturer,
31 powerState: PowerState,
32 statusState: Status.State,
33 healthRollup: Status.HealthRollup
34 };
35 });
36 }
37 },
38 actions: {
39 async getChassisInfo({ commit }) {
40 return await api
41 .get('/redfish/v1/Chassis')
42 .then(({ data: { Members = [] } }) =>
43 Members.map(member => api.get(member['@odata.id']))
44 )
45 .then(promises => api.all(promises))
46 .then(response => {
47 const data = response.map(({ data }) => data);
48 commit('setChassisInfo', data);
49 })
50 .catch(error => console.log(error));
51 }
52 }
53};
54
55export default ChassisStore;