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 LocationNumber, 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: LocationNumber, 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 85 .patch(uri, updatedIdentifyLedValue) 86 .then(() => dispatch('getProcessorsInfo')) 87 .catch((error) => { 88 dispatch('getProcessorsInfo'); 89 console.log('error', error); 90 if (led.identifyLed) { 91 throw new Error( 92 i18n.t('pageInventory.toast.errorEnableIdentifyLed') 93 ); 94 } else { 95 throw new Error( 96 i18n.t('pageInventory.toast.errorDisableIdentifyLed') 97 ); 98 } 99 }); 100 }, 101 }, 102}; 103 104export default ProcessorStore; 105