1import api from '@/store/api'; 2import i18n from '@/i18n'; 3 4const BmcStore = { 5 namespaced: true, 6 state: { 7 bmc: null, 8 }, 9 getters: { 10 bmc: (state) => state.bmc, 11 }, 12 mutations: { 13 setBmcInfo: (state, data) => { 14 const bmc = {}; 15 bmc.dateTime = new Date(data.DateTime); 16 bmc.description = data.Description; 17 bmc.firmwareVersion = data.FirmwareVersion; 18 bmc.graphicalConsoleConnectTypes = 19 data.GraphicalConsole.ConnectTypesSupported; 20 bmc.graphicalConsoleEnabled = data.GraphicalConsole.ServiceEnabled; 21 bmc.graphicalConsoleMaxSessions = 22 data.GraphicalConsole.MaxConcurrentSessions; 23 bmc.health = data.Status.Health; 24 bmc.healthRollup = data.Status.HealthRollup; 25 bmc.id = data.Id; 26 bmc.lastResetTime = new Date(data.LastResetTime); 27 bmc.identifyLed = data.LocationIndicatorActive; 28 bmc.locationNumber = data.Location?.PartLocation?.ServiceLabel; 29 bmc.manufacturer = data.manufacturer; 30 bmc.managerType = data.ManagerType; 31 bmc.model = data.Model; 32 bmc.name = data.Name; 33 bmc.partNumber = data.PartNumber; 34 bmc.powerState = data.PowerState; 35 bmc.serialNumber = data.SerialNumber; 36 bmc.serviceEntryPointUuid = data.ServiceEntryPointUUID; 37 bmc.sparePartNumber = data.SparePartNumber; 38 bmc.statusState = data.Status.State; 39 bmc.uuid = data.UUID; 40 bmc.uri = data['@odata.id']; 41 state.bmc = bmc; 42 }, 43 }, 44 actions: { 45 async getBmcInfo({ commit }) { 46 return await api 47 .get(`${await this.dispatch('global/getBmcPath')}`) 48 .then(({ data }) => commit('setBmcInfo', data)) 49 .catch((error) => console.log(error)); 50 }, 51 async updateIdentifyLedValue({ dispatch }, led) { 52 const uri = led.uri; 53 const updatedIdentifyLedValue = { 54 LocationIndicatorActive: led.identifyLed, 55 }; 56 return await api 57 .patch(uri, updatedIdentifyLedValue) 58 .then(() => { 59 dispatch('getBmcInfo'); 60 if (led.identifyLed) { 61 return i18n.global.t( 62 'pageInventory.toast.successEnableIdentifyLed', 63 ); 64 } else { 65 return i18n.global.t( 66 'pageInventory.toast.successDisableIdentifyLed', 67 ); 68 } 69 }) 70 .catch((error) => { 71 dispatch('getBmcInfo'); 72 console.log('error', error); 73 if (led.identifyLed) { 74 throw new Error( 75 i18n.global.t('pageInventory.toast.errorEnableIdentifyLed'), 76 ); 77 } else { 78 throw new Error( 79 i18n.global.t('pageInventory.toast.errorDisableIdentifyLed'), 80 ); 81 } 82 }); 83 }, 84 }, 85}; 86 87export default BmcStore; 88