blob: a4c77cb9d387ac4f047487e433cc12a6e405306a [file] [log] [blame]
Yoshie Muranaka54c6bfc2020-06-12 08:29:42 -07001import api from '@/store/api';
Sandeepa Singh78b6b532021-04-09 18:08:22 +05302import i18n from '@/i18n';
Yoshie Muranaka54c6bfc2020-06-12 08:29:42 -07003
Sandeepa Singh78b6b532021-04-09 18:08:22 +05304const BmcStore = {
Yoshie Muranaka54c6bfc2020-06-12 08:29:42 -07005 namespaced: true,
6 state: {
Derick Montague602e98a2020-10-21 16:20:00 -05007 bmc: null,
Yoshie Muranaka54c6bfc2020-06-12 08:29:42 -07008 },
9 getters: {
Derick Montague602e98a2020-10-21 16:20:00 -050010 bmc: (state) => state.bmc,
Yoshie Muranaka54c6bfc2020-06-12 08:29:42 -070011 },
12 mutations: {
13 setBmcInfo: (state, data) => {
14 const bmc = {};
Sandeepa Singh78b6b532021-04-09 18:08:22 +053015 bmc.dateTime = new Date(data.DateTime);
Yoshie Muranaka54c6bfc2020-06-12 08:29:42 -070016 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;
Sandeepa Singh78b6b532021-04-09 18:08:22 +053026 bmc.lastResetTime = new Date(data.LastResetTime);
27 bmc.identifyLed = data.LocationIndicatorActive;
Sneha Patel9f612342021-09-02 12:23:42 -050028 bmc.locationNumber = data.Location?.PartLocation?.ServiceLabel;
Sandeepa Singh78b6b532021-04-09 18:08:22 +053029 bmc.manufacturer = data.manufacturer;
30 bmc.managerType = data.ManagerType;
Yoshie Muranaka54c6bfc2020-06-12 08:29:42 -070031 bmc.model = data.Model;
Sandeepa Singh78b6b532021-04-09 18:08:22 +053032 bmc.name = data.Name;
Yoshie Muranaka54c6bfc2020-06-12 08:29:42 -070033 bmc.partNumber = data.PartNumber;
34 bmc.powerState = data.PowerState;
Yoshie Muranaka54c6bfc2020-06-12 08:29:42 -070035 bmc.serialNumber = data.SerialNumber;
36 bmc.serviceEntryPointUuid = data.ServiceEntryPointUUID;
Sandeepa Singh78b6b532021-04-09 18:08:22 +053037 bmc.sparePartNumber = data.SparePartNumber;
Yoshie Muranaka54c6bfc2020-06-12 08:29:42 -070038 bmc.statusState = data.Status.State;
39 bmc.uuid = data.UUID;
Sandeepa Singh78b6b532021-04-09 18:08:22 +053040 bmc.uri = data['@odata.id'];
Yoshie Muranaka54c6bfc2020-06-12 08:29:42 -070041 state.bmc = bmc;
Derick Montague602e98a2020-10-21 16:20:00 -050042 },
Yoshie Muranaka54c6bfc2020-06-12 08:29:42 -070043 },
44 actions: {
45 async getBmcInfo({ commit }) {
46 return await api
Sean Zhang8841b7d2024-06-15 08:42:41 +030047 .get(`${await this.dispatch('global/getBmcPath')}`)
Yoshie Muranaka54c6bfc2020-06-12 08:29:42 -070048 .then(({ data }) => commit('setBmcInfo', data))
Derick Montague602e98a2020-10-21 16:20:00 -050049 .catch((error) => console.log(error));
50 },
Sandeepa Singh78b6b532021-04-09 18:08:22 +053051 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)
Nikhil Ashokaf11a1902024-05-09 15:17:44 +053058 .then(() => {
59 dispatch('getBmcInfo');
60 if (led.identifyLed) {
Surya Vde23ea22024-07-11 15:19:46 +053061 return i18n.global.t(
62 'pageInventory.toast.successEnableIdentifyLed',
63 );
Nikhil Ashokaf11a1902024-05-09 15:17:44 +053064 } else {
Surya Vde23ea22024-07-11 15:19:46 +053065 return i18n.global.t(
66 'pageInventory.toast.successDisableIdentifyLed',
67 );
Nikhil Ashokaf11a1902024-05-09 15:17:44 +053068 }
69 })
Sandeepa Singh78b6b532021-04-09 18:08:22 +053070 .catch((error) => {
71 dispatch('getBmcInfo');
72 console.log('error', error);
73 if (led.identifyLed) {
74 throw new Error(
Surya Vde23ea22024-07-11 15:19:46 +053075 i18n.global.t('pageInventory.toast.errorEnableIdentifyLed'),
Sandeepa Singh78b6b532021-04-09 18:08:22 +053076 );
77 } else {
78 throw new Error(
Surya Vde23ea22024-07-11 15:19:46 +053079 i18n.global.t('pageInventory.toast.errorDisableIdentifyLed'),
Sandeepa Singh78b6b532021-04-09 18:08:22 +053080 );
81 }
82 });
83 },
Derick Montague602e98a2020-10-21 16:20:00 -050084 },
Yoshie Muranaka54c6bfc2020-06-12 08:29:42 -070085};
86
Sandeepa Singh78b6b532021-04-09 18:08:22 +053087export default BmcStore;