diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/store/modules/ResourceManagement/PowerControlStore.js | 28 | ||||
-rw-r--r-- | src/views/ResourceManagement/Power.vue | 9 |
2 files changed, 30 insertions, 7 deletions
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') ) diff --git a/src/views/ResourceManagement/Power.vue b/src/views/ResourceManagement/Power.vue index 8e4acdd3..cc0cc993 100644 --- a/src/views/ResourceManagement/Power.vue +++ b/src/views/ResourceManagement/Power.vue @@ -118,8 +118,15 @@ export default { return this.powerCapValue !== null; }, set(value) { - let newValue = value ? '' : null; this.$v.$reset(); + let newValue = null; + if (value) { + if (this.powerCapValue) { + newValue = this.powerCapValue; + } else { + newValue = ''; + } + } this.$store.dispatch('powerControl/setPowerCapUpdatedValue', newValue); }, }, |