xref: /openbmc/webui-vue/src/store/modules/HardwareStatus/SystemStore.js (revision b325541c0a76e04eff8d48e2dce1b0592e2632bc)
1import api from '@/store/api';
2import i18n from '@/i18n';
3
4const SystemStore = {
5  namespaced: true,
6  state: {
7    systems: [],
8  },
9  getters: {
10    systems: (state) => state.systems,
11  },
12  mutations: {
13    setSystemInfo: (state, data) => {
14      const system = {};
15      system.assetTag = data.AssetTag;
16      system.description = data.Description;
17      system.firmwareVersion = data.BiosVersion;
18      system.hardwareType = data.Name;
19      system.health = data.Status?.Health;
20      system.totalSystemMemoryGiB = data.MemorySummary?.TotalSystemMemoryGiB;
21      system.id = data.Id;
22      system.locationIndicatorActive = data.LocationIndicatorActive;
23      system.locationNumber = data.Location?.PartLocation?.ServiceLabel;
24      system.manufacturer = data.Manufacturer;
25      system.model = data.Model;
26      system.processorSummaryCount = data.ProcessorSummary?.Count;
27      system.processorSummaryCoreCount = data.ProcessorSummary?.CoreCount;
28      system.powerState = data.PowerState;
29      system.serialNumber = data.SerialNumber;
30      system.healthRollup = data.Status?.HealthRollup;
31      system.subModel = data.SubModel;
32      system.statusState = data.Status?.State;
33      system.systemType = data.SystemType;
34      state.systems = [system];
35    },
36  },
37  actions: {
38    async getSystem({ commit }) {
39      return await api
40        .get('/redfish/v1')
41        .then((response) =>
42          api.get(`${response.data.Systems['@odata.id']}/system`),
43        )
44        .then(({ data }) => commit('setSystemInfo', data))
45        .catch((error) => console.log(error));
46    },
47    async changeIdentifyLedState({ commit }, ledState) {
48      return await api
49        .patch('/redfish/v1/Systems/system', {
50          LocationIndicatorActive: ledState,
51        })
52        .then(() => {
53          if (ledState) {
54            return i18n.t('pageInventory.toast.successEnableIdentifyLed');
55          } else {
56            return i18n.t('pageInventory.toast.successDisableIdentifyLed');
57          }
58        })
59        .catch((error) => {
60          commit('setSystemInfo', this.state.system.systems[0]);
61          console.log('error', error);
62          if (ledState) {
63            throw new Error(
64              i18n.t('pageInventory.toast.errorEnableIdentifyLed'),
65            );
66          } else {
67            throw new Error(
68              i18n.t('pageInventory.toast.errorDisableIdentifyLed'),
69            );
70          }
71        });
72    },
73  },
74};
75
76export default SystemStore;
77