blob: 9dbddf0593e64b062f42b3c58bc614f19b7eb9e7 [file] [log] [blame]
SurenNeware61859092020-10-01 09:37:32 +05301import api from '@/store/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,
Derick Montague602e98a2020-10-21 16:20:00 -05008 powerConsumptionValue: null,
Dixsie Wolmers4c69f5b2020-02-26 11:23:52 -06009 },
10 getters: {
Derick Montague602e98a2020-10-21 16:20:00 -050011 powerCapValue: (state) => state.powerCapValue,
12 powerConsumptionValue: (state) => state.powerConsumptionValue,
Dixsie Wolmers4c69f5b2020-02-26 11:23:52 -060013 },
14 mutations: {
15 setPowerCapValue: (state, powerCapValue) =>
16 (state.powerCapValue = powerCapValue),
17 setPowerConsumptionValue: (state, powerConsumptionValue) =>
Derick Montague602e98a2020-10-21 16:20:00 -050018 (state.powerConsumptionValue = powerConsumptionValue),
Dixsie Wolmers4c69f5b2020-02-26 11:23:52 -060019 },
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')
Derick Montague602e98a2020-10-21 16:20:00 -050027 .then((response) => {
Dixsie Wolmers4c69f5b2020-02-26 11:23:52 -060028 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 })
Derick Montague602e98a2020-10-21 16:20:00 -050036 .catch((error) => {
Dixsie Wolmers4c69f5b2020-02-26 11:23:52 -060037 console.log('Power control', error);
38 });
Sukanya Pandey9055d982020-03-31 17:37:53 +053039 },
40 async setPowerControl(_, powerCapValue) {
41 const data = {
Derick Montague602e98a2020-10-21 16:20:00 -050042 PowerControl: [{ PowerLimit: { LimitInWatts: powerCapValue } }],
Sukanya Pandey9055d982020-03-31 17:37:53 +053043 };
44
45 return await api
46 .patch('/redfish/v1/Chassis/chassis/Power', data)
47 .then(() =>
48 i18n.t('pageServerPowerOperations.toast.successSaveSettings')
49 )
Derick Montague602e98a2020-10-21 16:20:00 -050050 .catch((error) => {
Sukanya Pandey9055d982020-03-31 17:37:53 +053051 console.log(error);
52 throw new Error(
53 i18n.t('pageServerPowerOperations.toast.errorSaveSettings')
54 );
55 });
Derick Montague602e98a2020-10-21 16:20:00 -050056 },
57 },
Dixsie Wolmers4c69f5b2020-02-26 11:23:52 -060058};
59
60export default PowerControlStore;