1import api from '@/store/api'; 2import i18n from '@/i18n'; 3 4const ProcessorStore = { 5 namespaced: true, 6 state: { 7 processors: [], 8 }, 9 getters: { 10 processors: (state) => state.processors, 11 }, 12 mutations: { 13 setProcessorsInfo: (state, data) => { 14 state.processors = data.map((processor) => { 15 const { 16 Id, 17 Status = {}, 18 PartNumber, 19 SerialNumber, 20 SparePartNumber, 21 InstructionSet, 22 Manufacturer, 23 Model, 24 Name, 25 ProcessorArchitecture, 26 ProcessorType, 27 Version, 28 AssetTag, 29 MinSpeedMHz, 30 MaxSpeedMHz, 31 TotalCores, 32 TotalThreads, 33 Location, 34 LocationIndicatorActive, 35 } = processor; 36 return { 37 id: Id, 38 health: Status.Health, 39 healthRollup: Status.HealthRollup, 40 partNumber: PartNumber, 41 sparePartNumber: SparePartNumber, 42 serialNumber: SerialNumber, 43 statusState: Status.State, 44 instructionSet: InstructionSet, 45 manufacturer: Manufacturer, 46 model: Model, 47 name: Name, 48 processorArchitecture: ProcessorArchitecture, 49 processorType: ProcessorType, 50 version: Version, 51 assetTag: AssetTag, 52 minSpeedMHz: MinSpeedMHz, 53 maxSpeedMHz: MaxSpeedMHz, 54 totalCores: TotalCores, 55 totalThreads: TotalThreads, 56 locationNumber: Location?.PartLocation?.ServiceLabel, 57 identifyLed: LocationIndicatorActive, 58 uri: processor['@odata.id'], 59 }; 60 }); 61 }, 62 }, 63 actions: { 64 async getProcessorsInfo({ commit }) { 65 return await api 66 .get('/redfish/v1/Systems/system/Processors') 67 .then(({ data: { Members = [] } }) => 68 Members.map((member) => api.get(member['@odata.id'])) 69 ) 70 .then((promises) => api.all(promises)) 71 .then((response) => { 72 const data = response.map(({ data }) => data); 73 commit('setProcessorsInfo', data); 74 }) 75 .catch((error) => console.log(error)); 76 }, 77 // Waiting for the following to be merged to test the Identify Led: 78 // https://gerrit.openbmc-project.xyz/c/openbmc/bmcweb/+/37045 79 async updateIdentifyLedValue({ dispatch }, led) { 80 const uri = led.uri; 81 const updatedIdentifyLedValue = { 82 LocationIndicatorActive: led.identifyLed, 83 }; 84 return await api.patch(uri, updatedIdentifyLedValue).catch((error) => { 85 dispatch('getProcessorsInfo'); 86 console.log('error', error); 87 if (led.identifyLed) { 88 throw new Error(i18n.t('pageInventory.toast.errorEnableIdentifyLed')); 89 } else { 90 throw new Error( 91 i18n.t('pageInventory.toast.errorDisableIdentifyLed') 92 ); 93 } 94 }); 95 }, 96 }, 97}; 98 99export default ProcessorStore; 100