summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaksim Zakharov <m.zakharov@IBS.RU>2022-09-02 15:39:37 +0300
committerMaksim Zakharov <m.zakharov@IBS.RU>2022-09-02 15:39:37 +0300
commit23f1872e87fe65f2cea1ebcef3b544421be09e03 (patch)
tree92cd5adacfc17ab2f8d9438bf6e97fb537ae171e
parent3682e47e5cec528bc9ba1e487f1002fa1a6f786e (diff)
downloadwebui-vue-23f1872e87fe65f2cea1ebcef3b544421be09e03.tar.xz
fix for pci
-rw-r--r--src/store/modules/HardwareStatus/PciStore.js162
-rw-r--r--src/views/_sila/Overview/Inventory/InventoryPciDevices.vue43
2 files changed, 66 insertions, 139 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));
},
},
diff --git a/src/views/_sila/Overview/Inventory/InventoryPciDevices.vue b/src/views/_sila/Overview/Inventory/InventoryPciDevices.vue
index 74858649..9e5ec4d4 100644
--- a/src/views/_sila/Overview/Inventory/InventoryPciDevices.vue
+++ b/src/views/_sila/Overview/Inventory/InventoryPciDevices.vue
@@ -4,7 +4,7 @@
responsive="md"
show-empty
hover
- :items="items"
+ :items="pci"
:fields="fields"
:empty-text="$t('global.table.emptyMessage')"
:busy="isBusy"
@@ -12,8 +12,8 @@
<template #cell(expandRow)="row">
<b-button
v-if="
- items[row.index].DeviceType !== 'SingleFunction' &&
- items[row.index].Functions
+ pci[row.index].DeviceType !== 'SingleFunction' &&
+ pci[row.index].Functions
"
variant="link"
:title="expandRowLabel"
@@ -24,30 +24,18 @@
<span class="sr-only">{{ expandRowLabel }}</span>
</b-button>
</template>
- <template #cell(DeviceName)="data">
- <span v-if="items[data.index].DeviceType === 'SingleFunction'">
- {{ data.value }}</span
- >
- <span v-else>
- {{
- items[data.index].Functions
- ? items[data.index].Functions[0].DeviceName
- : '--'
- }}</span
- >
- </template>
<template #cell(health)>
<status-icon :status="statusIcon('OK')" />
{{ $t('pagePci.table.health_d') }}
</template>
<template #cell(deviceClass)="data">
- <span v-if="items[data.index].DeviceType === 'SingleFunction'">
+ <span v-if="pci[data.index].DeviceType === 'SingleFunction'">
{{ data.value }}</span
>
<span v-else>
{{
- items[data.index].Functions
- ? items[data.index].Functions[0].deviceClass
+ pci[data.index].Functions
+ ? pci[data.index].Functions[0].deviceClass
: '--'
}}</span
>
@@ -81,6 +69,8 @@
</template>
<script>
+import { mapState } from 'vuex';
+
import PageSection from '@/components/_sila/Global/PageSection';
import IconChevron from '@carbon/icons-vue/es/chevron--down/20';
import StatusIcon from '@/components/_sila/Global/StatusIcon';
@@ -136,21 +126,14 @@ export default {
},
computed: {
- items() {
- return this.$store.getters['pci/pciDevices'];
- },
+ ...mapState('pciStore', ['pci']),
},
created() {
- return this.$store
- .dispatch('pci/getDevices')
- .then(() => {
- this.$store.dispatch('pci/getDevicesMembers');
- })
- .finally(() => {
- this.$root.$emit('hardware-status-pci-complete');
- this.isBusy = false;
- });
+ return this.$store.dispatch('pciStore/getDevices').finally(() => {
+ this.$root.$emit('hardware-status-pci-complete');
+ this.isBusy = false;
+ });
},
};
</script>