summaryrefslogtreecommitdiff
path: root/src/store/modules/Settings/DateTimeStore.js
diff options
context:
space:
mode:
authorSandeepa Singh <sandeepa.singh@ibm.com>2021-07-19 15:34:18 +0300
committerDerick Montague <derick.montague@ibm.com>2021-08-10 22:20:42 +0300
commitf67f769f2304bca64d2b9758e22c21203960eef9 (patch)
tree167d6ac96a90b098887f9cf1dc4e96a895e2754c /src/store/modules/Settings/DateTimeStore.js
parent68cbbe9014cbdcf7229a878f564d38f6d6199f25 (diff)
downloadwebui-vue-f67f769f2304bca64d2b9758e22c21203960eef9.tar.xz
IA update: Update configuration to settings
This is the fourth update to information architecture changes and has the following changes: - The configuration section is updated to settings - The date and time settings page is updated to date and time - The network settings page is updated to network - The power restore policy page in operations section is moved to settings section Signed-off-by: Sandeepa Singh <sandeepa.singh@ibm.com> Change-Id: I6f5ab25f5227530be430bd39a4d9629b3bf09d8b
Diffstat (limited to 'src/store/modules/Settings/DateTimeStore.js')
-rw-r--r--src/store/modules/Settings/DateTimeStore.js81
1 files changed, 81 insertions, 0 deletions
diff --git a/src/store/modules/Settings/DateTimeStore.js b/src/store/modules/Settings/DateTimeStore.js
new file mode 100644
index 00000000..51b722a8
--- /dev/null
+++ b/src/store/modules/Settings/DateTimeStore.js
@@ -0,0 +1,81 @@
+import api from '@/store/api';
+import i18n from '@/i18n';
+
+const DateTimeStore = {
+ namespaced: true,
+ state: {
+ ntpServers: [],
+ isNtpProtocolEnabled: null,
+ },
+ getters: {
+ ntpServers: (state) => state.ntpServers,
+ isNtpProtocolEnabled: (state) => state.isNtpProtocolEnabled,
+ },
+ mutations: {
+ setNtpServers: (state, ntpServers) => (state.ntpServers = ntpServers),
+ setIsNtpProtocolEnabled: (state, isNtpProtocolEnabled) =>
+ (state.isNtpProtocolEnabled = isNtpProtocolEnabled),
+ },
+ actions: {
+ async getNtpData({ commit }) {
+ return await api
+ .get('/redfish/v1/Managers/bmc/NetworkProtocol')
+ .then((response) => {
+ const ntpServers = response.data.NTP.NTPServers;
+ const isNtpProtocolEnabled = response.data.NTP.ProtocolEnabled;
+ commit('setNtpServers', ntpServers);
+ commit('setIsNtpProtocolEnabled', isNtpProtocolEnabled);
+ })
+ .catch((error) => {
+ console.log(error);
+ });
+ },
+ async updateDateTime({ state }, dateTimeForm) {
+ const ntpData = {
+ NTP: {
+ ProtocolEnabled: dateTimeForm.ntpProtocolEnabled,
+ },
+ };
+ if (dateTimeForm.ntpProtocolEnabled) {
+ ntpData.NTP.NTPServers = dateTimeForm.ntpServersArray;
+ }
+ return await api
+ .patch(`/redfish/v1/Managers/bmc/NetworkProtocol`, ntpData)
+ .then(async () => {
+ if (!dateTimeForm.ntpProtocolEnabled) {
+ const dateTimeData = {
+ DateTime: dateTimeForm.updatedDateTime,
+ };
+ /**
+ * https://github.com/openbmc/phosphor-time-manager/blob/master/README.md#special-note-on-changing-ntp-setting
+ * When time mode is initially set to Manual from NTP,
+ * NTP service is disabled and the NTP service is
+ * stopping but not stopped, setting time will return an error.
+ * There are no responses from backend to notify when NTP is stopped.
+ * To work around, a timeout is set to allow NTP to fully stop
+ * TODO: remove timeout if backend solves
+ * https://github.com/openbmc/openbmc/issues/3459
+ */
+ const timeoutVal = state.isNtpProtocolEnabled ? 20000 : 0;
+ return await new Promise((resolve, reject) => {
+ setTimeout(() => {
+ return api
+ .patch(`/redfish/v1/Managers/bmc`, dateTimeData)
+ .then(() => resolve())
+ .catch(() => reject());
+ }, timeoutVal);
+ });
+ }
+ })
+ .then(() => {
+ return i18n.t('pageDateTime.toast.successSaveDateTime');
+ })
+ .catch((error) => {
+ console.log(error);
+ throw new Error(i18n.t('pageDateTime.toast.errorSaveDateTime'));
+ });
+ },
+ },
+};
+
+export default DateTimeStore;