blob: c6de412eb979df5f1de268d2042e790e2828bffe [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;
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;
Sandeepa Singh78b6b532021-04-09 18:08:22 +053040 bmc.sparePartNumber = data.SparePartNumber;
Yoshie Muranaka54c6bfc2020-06-12 08:29:42 -070041 bmc.statusState = data.Status.State;
42 bmc.uuid = data.UUID;
Sandeepa Singh78b6b532021-04-09 18:08:22 +053043 bmc.uri = data['@odata.id'];
Yoshie Muranaka54c6bfc2020-06-12 08:29:42 -070044 state.bmc = bmc;
Derick Montague602e98a2020-10-21 16:20:00 -050045 },
Yoshie Muranaka54c6bfc2020-06-12 08:29:42 -070046 },
47 actions: {
48 async getBmcInfo({ commit }) {
49 return await api
Sean Zhang8841b7d2024-06-15 08:42:41 +030050 .get(`${await this.dispatch('global/getBmcPath')}`)
Yoshie Muranaka54c6bfc2020-06-12 08:29:42 -070051 .then(({ data }) => commit('setBmcInfo', data))
Derick Montague602e98a2020-10-21 16:20:00 -050052 .catch((error) => console.log(error));
53 },
Sandeepa Singh78b6b532021-04-09 18:08:22 +053054 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)
Nikhil Ashokaf11a1902024-05-09 15:17:44 +053061 .then(() => {
62 dispatch('getBmcInfo');
63 if (led.identifyLed) {
Surya V603cfbf2024-07-11 15:19:46 +053064 return i18n.global.t(
65 'pageInventory.toast.successEnableIdentifyLed',
66 );
Nikhil Ashokaf11a1902024-05-09 15:17:44 +053067 } else {
Surya V603cfbf2024-07-11 15:19:46 +053068 return i18n.global.t(
69 'pageInventory.toast.successDisableIdentifyLed',
70 );
Nikhil Ashokaf11a1902024-05-09 15:17:44 +053071 }
72 })
Sandeepa Singh78b6b532021-04-09 18:08:22 +053073 .catch((error) => {
74 dispatch('getBmcInfo');
75 console.log('error', error);
76 if (led.identifyLed) {
77 throw new Error(
Surya V603cfbf2024-07-11 15:19:46 +053078 i18n.global.t('pageInventory.toast.errorEnableIdentifyLed'),
Sandeepa Singh78b6b532021-04-09 18:08:22 +053079 );
80 } else {
81 throw new Error(
Surya V603cfbf2024-07-11 15:19:46 +053082 i18n.global.t('pageInventory.toast.errorDisableIdentifyLed'),
Sandeepa Singh78b6b532021-04-09 18:08:22 +053083 );
84 }
85 });
86 },
Derick Montague602e98a2020-10-21 16:20:00 -050087 },
Yoshie Muranaka54c6bfc2020-06-12 08:29:42 -070088};
89
Sandeepa Singh78b6b532021-04-09 18:08:22 +053090export default BmcStore;