summaryrefslogtreecommitdiff
path: root/src/store
diff options
context:
space:
mode:
authorYoshie Muranaka <yoshiemuranaka@gmail.com>2020-02-27 01:23:15 +0300
committerDerick Montague <derick.montague@ibm.com>2020-03-10 22:50:39 +0300
commitc05ff648da07d8e2221d67eac83b6c6581d371a0 (patch)
tree5acf2746cf1551b36df57421f167a0e9b6100095 /src/store
parenta4b9e40a15cefe8bf4c48bf994ac91ea5ee94ef6 (diff)
downloadwebui-vue-c05ff648da07d8e2221d67eac83b6c6581d371a0.tar.xz
Add host boot settings to power operations page
Added BootSettingsStore and component to handle changing boot source, boot override option and TPM required option. Signed-off-by: Yoshie Muranaka <yoshiemuranaka@gmail.com> Change-Id: I885dd6008aceb34b319953a2e9b6416d848baf16
Diffstat (limited to 'src/store')
-rw-r--r--src/store/index.js2
-rw-r--r--src/store/modules/Control/BootSettingsStore.js136
2 files changed, 138 insertions, 0 deletions
diff --git a/src/store/index.js b/src/store/index.js
index 6bad517c..27216990 100644
--- a/src/store/index.js
+++ b/src/store/index.js
@@ -6,6 +6,7 @@ import AuthenticationStore from './modules/Authentication/AuthenticanStore';
import LocalUserManagementStore from './modules/AccessControl/LocalUserMangementStore';
import OverviewStore from './modules/Overview/OverviewStore';
import FirmwareStore from './modules/Configuration/FirmwareStore';
+import BootSettingsStore from './modules/Control/BootSettingsStore';
import ControlStore from './modules/Control/ControlStore';
import PowerControlStore from './modules/Control/PowerControlStore';
import NetworkSettingStore from './modules/Configuration/NetworkSettingsStore';
@@ -25,6 +26,7 @@ export default new Vuex.Store({
localUsers: LocalUserManagementStore,
overview: OverviewStore,
firmware: FirmwareStore,
+ hostBootSettings: BootSettingsStore,
controls: ControlStore,
powerControl: PowerControlStore,
networkSettings: NetworkSettingStore,
diff --git a/src/store/modules/Control/BootSettingsStore.js b/src/store/modules/Control/BootSettingsStore.js
new file mode 100644
index 00000000..8da586aa
--- /dev/null
+++ b/src/store/modules/Control/BootSettingsStore.js
@@ -0,0 +1,136 @@
+import api from '../../api';
+import i18n from '../../../i18n';
+
+const BootSettingsStore = {
+ namespaced: true,
+ state: {
+ bootSourceOptions: [],
+ bootSource: null,
+ overrideEnabled: null,
+ tpmEnabled: null
+ },
+ getters: {
+ bootSourceOptions: state => state.bootSourceOptions,
+ bootSource: state => state.bootSource,
+ overrideEnabled: state => state.overrideEnabled,
+ tpmEnabled: state => state.tpmEnabled
+ },
+ mutations: {
+ setBootSourceOptions: (state, bootSourceOptions) =>
+ (state.bootSourceOptions = bootSourceOptions),
+ setBootSource: (state, bootSource) => (state.bootSource = bootSource),
+ setOverrideEnabled: (state, overrideEnabled) => {
+ if (overrideEnabled === 'Once') {
+ state.overrideEnabled = true;
+ } else {
+ // 'Continuous' or 'Disabled'
+ state.overrideEnabled = false;
+ }
+ },
+ setTpmPolicy: (state, tpmEnabled) => (state.tpmEnabled = tpmEnabled)
+ },
+ actions: {
+ getBootSettings({ commit }) {
+ api
+ .get('/redfish/v1/Systems/system/')
+ .then(({ data: { Boot } }) => {
+ commit(
+ 'setBootSourceOptions',
+ Boot['BootSourceOverrideTarget@Redfish.AllowableValues']
+ );
+ commit('setOverrideEnabled', Boot.BootSourceOverrideEnabled);
+ commit('setBootSource', Boot.BootSourceOverrideTarget);
+ })
+ .catch(error => console.log(error));
+ },
+ saveBootSettings({ commit, dispatch }, { bootSource, overrideEnabled }) {
+ const data = { Boot: {} };
+ data.Boot.BootSourceOverrideTarget = bootSource;
+
+ if (overrideEnabled) {
+ data.Boot.BootSourceOverrideEnabled = 'Once';
+ } else if (bootSource === 'None') {
+ data.Boot.BootSourceOverrideEnabled = 'Disabled';
+ } else {
+ data.Boot.BootSourceOverrideEnabled = 'Continuous';
+ }
+
+ return api
+ .patch('/redfish/v1/Systems/system', data)
+ .then(response => {
+ // If request success, commit the values
+ commit('setBootSource', data.Boot.BootSourceOverrideTarget);
+ commit('setOverrideEnabled', data.Boot.BootSourceOverrideEnabled);
+ return response;
+ })
+ .catch(error => {
+ console.log(error);
+ // If request error, GET saved options
+ dispatch('getBootSettings');
+ return error;
+ });
+ },
+ getTpmPolicy({ commit }) {
+ // TODO: switch to Redfish when available
+ api
+ .get('/xyz/openbmc_project/control/host0/TPMEnable')
+ .then(({ data: { data: { TPMEnable } } }) =>
+ commit('setTpmPolicy', TPMEnable)
+ )
+ .catch(error => console.log(error));
+ },
+ saveTpmPolicy({ commit, dispatch }, tpmEnabled) {
+ // TODO: switch to Redfish when available
+ const data = { data: tpmEnabled };
+ return api
+ .put(
+ '/xyz/openbmc_project/control/host0/TPMEnable/attr/TPMEnable',
+ data
+ )
+ .then(response => {
+ // If request success, commit the values
+ commit('setTpmPolicy', tpmEnabled);
+ return response;
+ })
+ .catch(error => {
+ console.log(error);
+ // If request error, GET saved policy
+ dispatch('getTpmPolicy');
+ return error;
+ });
+ },
+ async saveSettings(
+ { dispatch },
+ { bootSource, overrideEnabled, tpmEnabled }
+ ) {
+ const promises = [];
+
+ if (bootSource !== null || overrideEnabled !== null) {
+ promises.push(
+ dispatch('saveBootSettings', { bootSource, overrideEnabled })
+ );
+ }
+ if (tpmEnabled !== null) {
+ promises.push(dispatch('saveTpmPolicy', tpmEnabled));
+ }
+
+ return await api.all(promises).then(
+ api.spread((...responses) => {
+ let message = i18n.t(
+ 'pageServerPowerOperations.toast.successSaveSettings'
+ );
+ responses.forEach(response => {
+ if (response instanceof Error) {
+ throw new Error(
+ i18n.t('pageServerPowerOperations.toast.errorSaveSettings')
+ );
+ }
+ });
+ return message;
+ })
+ );
+ }
+ }
+};
+
+export default BootSettingsStore;