Dixsie Wolmers | 4c69f5b | 2020-02-26 11:23:52 -0600 | [diff] [blame] | 1 | import api from '../../api'; |
Sukanya Pandey | 9055d98 | 2020-03-31 17:37:53 +0530 | [diff] [blame] | 2 | import i18n from '@/i18n'; |
Dixsie Wolmers | 4c69f5b | 2020-02-26 11:23:52 -0600 | [diff] [blame] | 3 | |
| 4 | const 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 Pandey | 9055d98 | 2020-03-31 17:37:53 +0530 | [diff] [blame] | 21 | setPowerCapUpdatedValue({ commit }, value) { |
| 22 | commit('setPowerCapValue', value); |
| 23 | }, |
Yoshie Muranaka | 598bf7e | 2020-05-01 12:26:00 -0700 | [diff] [blame] | 24 | async getPowerControl({ commit }) { |
| 25 | return await api |
Dixsie Wolmers | 4c69f5b | 2020-02-26 11:23:52 -0600 | [diff] [blame] | 26 | .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 Pandey | 9055d98 | 2020-03-31 17:37:53 +0530 | [diff] [blame] | 39 | }, |
| 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 Wolmers | 4c69f5b | 2020-02-26 11:23:52 -0600 | [diff] [blame] | 56 | } |
| 57 | } |
| 58 | }; |
| 59 | |
| 60 | export default PowerControlStore; |