From f4328edf86b284fe8836717251ce6696670dbdd5 Mon Sep 17 00:00:00 2001 From: MichalX Szopinski Date: Mon, 12 Jul 2021 12:59:30 +0200 Subject: Remove hardcoded chassis in Manage power usage Simmilar modification to https://gerrit.openbmc-project.xyz/c/openbmc/webui-vue/+/42988 which removes the hardcoded chassis name from url on Manage power usage tab. With this modification we are displaying only informations about first power device. This change also fixes the overwriting existing power cap value on load. Signed-off-by: MichalX Szopinski Change-Id: Ia164db9f2c50d98bc767c0f4729e9572a2d01da1 --- .../ResourceManagement/PowerControlStore.js | 28 +++++++++++++++++----- 1 file changed, 22 insertions(+), 6 deletions(-) (limited to 'src/store/modules') diff --git a/src/store/modules/ResourceManagement/PowerControlStore.js b/src/store/modules/ResourceManagement/PowerControlStore.js index 9dbddf05..94c570f8 100644 --- a/src/store/modules/ResourceManagement/PowerControlStore.js +++ b/src/store/modules/ResourceManagement/PowerControlStore.js @@ -5,15 +5,18 @@ const PowerControlStore = { namespaced: true, state: { powerCapValue: null, + powerCapUri: '', powerConsumptionValue: null, }, getters: { powerCapValue: (state) => state.powerCapValue, + powerCapUri: (state) => state.powerCapUri, powerConsumptionValue: (state) => state.powerConsumptionValue, }, mutations: { setPowerCapValue: (state, powerCapValue) => (state.powerCapValue = powerCapValue), + setPowerCapUri: (state, powerCapUri) => (state.powerCapUri = powerCapUri), setPowerConsumptionValue: (state, powerConsumptionValue) => (state.powerConsumptionValue = powerConsumptionValue), }, @@ -21,15 +24,29 @@ const PowerControlStore = { setPowerCapUpdatedValue({ commit }, value) { commit('setPowerCapValue', value); }, - async getPowerControl({ commit }) { + async getChassisCollection() { return await api - .get('/redfish/v1/Chassis/chassis/Power') + .get('/redfish/v1/') + .then((response) => api.get(response.data.Chassis['@odata.id'])) + .then(({ data: { Members } }) => + Members.map((member) => member['@odata.id']) + ) + .catch((error) => console.log(error)); + }, + async getPowerControl({ dispatch, commit }) { + const collection = await dispatch('getChassisCollection'); + if (!collection || collection.length === 0) return; + return await api + .get(`${collection[0]}`) + .then((response) => api.get(response.data.Power['@odata.id'])) .then((response) => { const powerControl = response.data.PowerControl; + if (!powerControl || powerControl.length === 0) return; + const powerCapUri = powerControl[0]['@odata.id']; const powerCap = powerControl[0].PowerLimit.LimitInWatts; // If system is powered off, power consumption does not exist in the PowerControl const powerConsumption = powerControl[0].PowerConsumedWatts || null; - + commit('setPowerCapUri', powerCapUri); commit('setPowerCapValue', powerCap); commit('setPowerConsumptionValue', powerConsumption); }) @@ -37,13 +54,12 @@ const PowerControlStore = { console.log('Power control', error); }); }, - async setPowerControl(_, powerCapValue) { + async setPowerControl({ state }, powerCapValue) { const data = { PowerControl: [{ PowerLimit: { LimitInWatts: powerCapValue } }], }; - return await api - .patch('/redfish/v1/Chassis/chassis/Power', data) + .patch(state.powerCapUri, data) .then(() => i18n.t('pageServerPowerOperations.toast.successSaveSettings') ) -- cgit v1.2.3