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.serialConsoleConnectTypes = data.SerialConsole.ConnectTypesSupported; 36 bmc.serialConsoleEnabled = data.SerialConsole.ServiceEnabled; 37 bmc.serialConsoleMaxSessions = data.SerialConsole.MaxConcurrentSessions; 38 bmc.serialNumber = data.SerialNumber; 39 bmc.serviceEntryPointUuid = data.ServiceEntryPointUUID; 40 bmc.sparePartNumber = data.SparePartNumber; 41 bmc.statusState = data.Status.State; 42 bmc.uuid = data.UUID; 43 bmc.uri = data['@odata.id']; 44 state.bmc = bmc; 45 }, 46 }, 47 actions: { 48 async getBmcInfo({ commit }) { 49 return await api 50 .get(`${await this.dispatch('global/getBmcPath')}`) 51 .then(({ data }) => commit('setBmcInfo', data)) 52 .catch((error) => console.log(error)); 53 }, 54 async updateIdentifyLedValue({ dispatch }, led) { 55 const uri = led.uri; 56 const updatedIdentifyLedValue = { 57 LocationIndicatorActive: led.identifyLed, 58 }; 59 return await api 60 .patch(uri, updatedIdentifyLedValue) 61 .then(() => { 62 dispatch('getBmcInfo'); 63 if (led.identifyLed) { 64 return i18n.global.t( 65 'pageInventory.toast.successEnableIdentifyLed', 66 ); 67 } else { 68 return i18n.global.t( 69 'pageInventory.toast.successDisableIdentifyLed', 70 ); 71 } 72 }) 73 .catch((error) => { 74 dispatch('getBmcInfo'); 75 console.log('error', error); 76 if (led.identifyLed) { 77 throw new Error( 78 i18n.global.t('pageInventory.toast.errorEnableIdentifyLed'), 79 ); 80 } else { 81 throw new Error( 82 i18n.global.t('pageInventory.toast.errorDisableIdentifyLed'), 83 ); 84 } 85 }); 86 }, 87 }, 88}; 89 90export default BmcStore; 91