blob: 85d69633d041464060cac575ca2338abe90a11ba [file] [log] [blame]
Dixsie Wolmers4c69f5b2020-02-26 11:23:52 -06001import api from '../../api';
Sukanya Pandey9055d982020-03-31 17:37:53 +05302import i18n from '@/i18n';
Dixsie Wolmers4c69f5b2020-02-26 11:23:52 -06003
4const PowerControlStore = {
5 namespaced: true,
6 state: {
7 powerCapValue: null,
8 powerConsumptionValue: null
9 },
10 getters: {
11 powerCapValue: state => state.powerCapValue,
12 powerConsumptionValue: state => state.powerConsumptionValue
13 },
14 mutations: {
15 setPowerCapValue: (state, powerCapValue) =>
16 (state.powerCapValue = powerCapValue),
17 setPowerConsumptionValue: (state, powerConsumptionValue) =>
18 (state.powerConsumptionValue = powerConsumptionValue)
19 },
20 actions: {
Sukanya Pandey9055d982020-03-31 17:37:53 +053021 setPowerCapUpdatedValue({ commit }, value) {
22 commit('setPowerCapValue', value);
23 },
Yoshie Muranaka598bf7e2020-05-01 12:26:00 -070024 async getPowerControl({ commit }) {
25 return await api
Dixsie Wolmers4c69f5b2020-02-26 11:23:52 -060026 .get('/redfish/v1/Chassis/chassis/Power')
27 .then(response => {
28 const powerControl = response.data.PowerControl;
29 const powerCap = powerControl[0].PowerLimit.LimitInWatts;
30 // If system is powered off, power consumption does not exist in the PowerControl
31 const powerConsumption = powerControl[0].PowerConsumedWatts || null;
32
33 commit('setPowerCapValue', powerCap);
34 commit('setPowerConsumptionValue', powerConsumption);
35 })
36 .catch(error => {
37 console.log('Power control', error);
38 });
Sukanya Pandey9055d982020-03-31 17:37:53 +053039 },
40 async setPowerControl(_, powerCapValue) {
41 const data = {
42 PowerControl: [{ PowerLimit: { LimitInWatts: powerCapValue } }]
43 };
44
45 return await api
46 .patch('/redfish/v1/Chassis/chassis/Power', data)
47 .then(() =>
48 i18n.t('pageServerPowerOperations.toast.successSaveSettings')
49 )
50 .catch(error => {
51 console.log(error);
52 throw new Error(
53 i18n.t('pageServerPowerOperations.toast.errorSaveSettings')
54 );
55 });
Dixsie Wolmers4c69f5b2020-02-26 11:23:52 -060056 }
57 }
58};
59
60export default PowerControlStore;