SurenNeware | 6185909 | 2020-10-01 09:37:32 +0530 | [diff] [blame] | 1 | import api from '@/store/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, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame^] | 8 | powerConsumptionValue: null, |
Dixsie Wolmers | 4c69f5b | 2020-02-26 11:23:52 -0600 | [diff] [blame] | 9 | }, |
| 10 | getters: { |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame^] | 11 | powerCapValue: (state) => state.powerCapValue, |
| 12 | powerConsumptionValue: (state) => state.powerConsumptionValue, |
Dixsie Wolmers | 4c69f5b | 2020-02-26 11:23:52 -0600 | [diff] [blame] | 13 | }, |
| 14 | mutations: { |
| 15 | setPowerCapValue: (state, powerCapValue) => |
| 16 | (state.powerCapValue = powerCapValue), |
| 17 | setPowerConsumptionValue: (state, powerConsumptionValue) => |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame^] | 18 | (state.powerConsumptionValue = powerConsumptionValue), |
Dixsie Wolmers | 4c69f5b | 2020-02-26 11:23:52 -0600 | [diff] [blame] | 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') |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame^] | 27 | .then((response) => { |
Dixsie Wolmers | 4c69f5b | 2020-02-26 11:23:52 -0600 | [diff] [blame] | 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 | }) |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame^] | 36 | .catch((error) => { |
Dixsie Wolmers | 4c69f5b | 2020-02-26 11:23:52 -0600 | [diff] [blame] | 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 = { |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame^] | 42 | PowerControl: [{ PowerLimit: { LimitInWatts: powerCapValue } }], |
Sukanya Pandey | 9055d98 | 2020-03-31 17:37:53 +0530 | [diff] [blame] | 43 | }; |
| 44 | |
| 45 | return await api |
| 46 | .patch('/redfish/v1/Chassis/chassis/Power', data) |
| 47 | .then(() => |
| 48 | i18n.t('pageServerPowerOperations.toast.successSaveSettings') |
| 49 | ) |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame^] | 50 | .catch((error) => { |
Sukanya Pandey | 9055d98 | 2020-03-31 17:37:53 +0530 | [diff] [blame] | 51 | console.log(error); |
| 52 | throw new Error( |
| 53 | i18n.t('pageServerPowerOperations.toast.errorSaveSettings') |
| 54 | ); |
| 55 | }); |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame^] | 56 | }, |
| 57 | }, |
Dixsie Wolmers | 4c69f5b | 2020-02-26 11:23:52 -0600 | [diff] [blame] | 58 | }; |
| 59 | |
| 60 | export default PowerControlStore; |