summaryrefslogtreecommitdiff
path: root/src/store/modules/HardwareStatus/PciStore.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/store/modules/HardwareStatus/PciStore.js')
-rw-r--r--src/store/modules/HardwareStatus/PciStore.js162
1 files changed, 53 insertions, 109 deletions
diff --git a/src/store/modules/HardwareStatus/PciStore.js b/src/store/modules/HardwareStatus/PciStore.js
index dcc7c175..9f76e69d 100644
--- a/src/store/modules/HardwareStatus/PciStore.js
+++ b/src/store/modules/HardwareStatus/PciStore.js
@@ -9,134 +9,78 @@ const PciStore = {
pciDevices: (state) => state.pci,
},
mutations: {
- setPciDevises: (state, data) => {
- state.pci = data.map((item) => {
- const {
- value: {
- data: { Id, Name, Manufacturer, DeviceType, PCIeFunctions },
- },
- } = item;
- return {
- id: Id,
- name: Name,
- DeviceType: DeviceType,
- manufacturer: Manufacturer,
- PCIeFunction: PCIeFunctions,
- };
- });
+ resetState: (state) => {
+ state.pci = [];
},
- setPciDevisesMembers: (state, data) => {
- state.pci = data.map((item, index) => {
- const {
- value: {
- data: { Members },
- },
- } = item;
- return {
- ...state.pci[index],
- Members: Members,
- };
- });
+ setPciDevises: (state, data) => {
+ const device = {
+ id: data.data.Id,
+ device: data.data.Device,
+ name: data.data.Name,
+ DeviceType: data.data.DeviceType,
+ manufacturer: data.data.Manufacturer,
+ PCIeFunction: data.data.PCIeFunctions,
+ };
+ state.pci.push(device);
},
- setFunctionDevices: (state, data) => {
- let count = 0;
- const newData = state.pci.map((item) => {
- const result = data.slice(count, count + item.Members.length);
- count += item.Members.length;
- return result;
- });
- state.pci = newData.map((item, index) => {
- const functions = item.map((item) => {
- const {
- value: {
- data: {
- ClassCode,
- DeviceClass,
- DeviceId,
- FunctionType,
- DeviceName,
- },
- },
- } = item;
- return {
- classCode: ClassCode,
- deviceClass: DeviceClass,
- deviceId: DeviceId,
- functionType: FunctionType,
- DeviceName: DeviceName,
- };
- });
-
- if (item.length > 1) {
- return {
- ...state.pci[index],
- Functions: functions,
- };
- }
-
+ setPciFunctions: (state, data) => {
+ const index = state.pci.length - 1;
+ console.log(index);
+ const functions = data.map((item) => {
return {
- ...state.pci[index],
- ...functions[0],
+ classCode: item.value.data.ClassCode,
+ deviceClass: item.value.data.DeviceClass,
+ deviceId: item.value.data.DeviceId,
+ functionType: item.value.data.FunctionType,
+ DeviceName: item.value.data.DeviceName,
};
});
+ if (data.length > 1) {
+ state.pci[index].Functions = functions;
+ } else {
+ console.log('state.inedex', state.pci[index]);
+ state.pci[index].Functions = functions[0];
+ state.pci[index].DeviceName = functions[0].DeviceName;
+ }
},
},
actions: {
async getDevices({ commit }) {
+ commit('resetState');
+
return await api
.get('/redfish/v1/Systems/system/PCIeDevices')
// get all pci devices
.then(({ data: { Members = [] } }) => {
+ // get for each device
const devices = Members.map((item) => async () =>
- api.get(item['@odata.id'])
+ api
+ .get(item['@odata.id'])
+ .then((response) => {
+ commit('setPciDevises', response);
+ return response;
+ })
+ .then((res) => {
+ // get functions data
+ api
+ .get(res.data.PCIeFunctions['@odata.id'])
+ .then((res) => {
+ const responses = res.data.Members.map((item) => {
+ return api.get(item['@odata.id']);
+ });
+ return Promise.allSettled(responses);
+ })
+ .then((res) => commit('setPciFunctions', res))
+ .catch((error) => console.log(error));
+ })
);
- // create an array of async functions to get all devices
return devices;
})
- .then(async (response) => {
- // calling functions one by one to avoid errors
- const results = [];
- for (let request of response) {
- const reponse = await request();
- results.push(reponse);
- }
- // return successful requests
- return Promise.allSettled(results);
- })
- .then((response) => {
- commit('setPciDevises', response);
- })
- .catch((error) => console.log(error));
- },
- async getDevicesMembers({ commit, state }) {
- // the same logic as in getDevices
- const Members = state.pci.map((item) => async () =>
- api.get(item.PCIeFunction['@odata.id'])
- );
- const results = [];
- for (let request of Members) {
- const reponse = await request();
- results.push(reponse);
- }
- return Promise.allSettled(results)
- .then((response) => {
- commit('setPciDevisesMembers', response);
- const Functions = response
- // can return an array of routes
- .map((item) => item.value.data.Members)
- .flat(Infinity)
- .map((item) => async () => api.get(item['@odata.id']));
- return Functions;
- })
- .then(async (response) => {
- const results = [];
- for (let request of response) {
- const reponse = await request();
- results.push(reponse);
+ .then(async (devices) => {
+ for (let request of devices) {
+ await request();
}
- return Promise.allSettled(results);
})
- .then((response) => commit('setFunctionDevices', response))
.catch((error) => console.log(error));
},
},