summaryrefslogtreecommitdiff
path: root/src/store/modules/ResourceManagement
diff options
context:
space:
mode:
authorDixsie Wolmers <dixsie@ibm.com>2021-08-18 21:35:54 +0300
committerDerick Montague <derick.montague@ibm.com>2021-08-20 03:01:11 +0300
commit3145d4d98b2d4646f958da8e7b409b23da4f9176 (patch)
tree6b7811ed2610c4bc44ea0b8f5715d9716d0a6ae4 /src/store/modules/ResourceManagement
parente020d5818c45d268e2ddc6d0f22af8074f90d120 (diff)
downloadwebui-vue-3145d4d98b2d4646f958da8e7b409b23da4f9176.tar.xz
Move PowerControlStore to ResourceManagement folder
Store module structure should match the view folder structure The Power page is under the Resource management section, so the store should also be in a similarly named folder. This makes it easier to find when looking for the correct store. Signed-off-by: Dixsie Wolmers <dixsie@ibm.com> Change-Id: Iada30056eb738b91f35dc4c6b9b42b6b2be8d55c
Diffstat (limited to 'src/store/modules/ResourceManagement')
-rw-r--r--src/store/modules/ResourceManagement/PowerControlStore.js60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/store/modules/ResourceManagement/PowerControlStore.js b/src/store/modules/ResourceManagement/PowerControlStore.js
new file mode 100644
index 00000000..9dbddf05
--- /dev/null
+++ b/src/store/modules/ResourceManagement/PowerControlStore.js
@@ -0,0 +1,60 @@
+import api from '@/store/api';
+import i18n from '@/i18n';
+
+const PowerControlStore = {
+ namespaced: true,
+ state: {
+ powerCapValue: null,
+ powerConsumptionValue: null,
+ },
+ getters: {
+ powerCapValue: (state) => state.powerCapValue,
+ powerConsumptionValue: (state) => state.powerConsumptionValue,
+ },
+ mutations: {
+ setPowerCapValue: (state, powerCapValue) =>
+ (state.powerCapValue = powerCapValue),
+ setPowerConsumptionValue: (state, powerConsumptionValue) =>
+ (state.powerConsumptionValue = powerConsumptionValue),
+ },
+ actions: {
+ setPowerCapUpdatedValue({ commit }, value) {
+ commit('setPowerCapValue', value);
+ },
+ async getPowerControl({ commit }) {
+ return await api
+ .get('/redfish/v1/Chassis/chassis/Power')
+ .then((response) => {
+ const powerControl = response.data.PowerControl;
+ 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('setPowerCapValue', powerCap);
+ commit('setPowerConsumptionValue', powerConsumption);
+ })
+ .catch((error) => {
+ console.log('Power control', error);
+ });
+ },
+ async setPowerControl(_, powerCapValue) {
+ const data = {
+ PowerControl: [{ PowerLimit: { LimitInWatts: powerCapValue } }],
+ };
+
+ return await api
+ .patch('/redfish/v1/Chassis/chassis/Power', data)
+ .then(() =>
+ i18n.t('pageServerPowerOperations.toast.successSaveSettings')
+ )
+ .catch((error) => {
+ console.log(error);
+ throw new Error(
+ i18n.t('pageServerPowerOperations.toast.errorSaveSettings')
+ );
+ });
+ },
+ },
+};
+
+export default PowerControlStore;