blob: 9da0cb417f6aab2e81efdcef75a87a5c806f5c48 [file] [log] [blame]
Dixsie Wolmers739e4592020-06-05 07:00:06 -05001import api from '../../api';
2import i18n from '@/i18n';
3
4const DateTimeStore = {
5 namespaced: true,
6 state: {
7 ntpServers: [],
8 isNtpProtocolEnabled: null
9 },
10 getters: {
11 ntpServers: state => state.ntpServers,
12 isNtpProtocolEnabled: state => state.isNtpProtocolEnabled
13 },
14 mutations: {
15 setNtpServers: (state, ntpServers) => (state.ntpServers = ntpServers),
16 setIsNtpProtocolEnabled: (state, isNtpProtocolEnabled) =>
17 (state.isNtpProtocolEnabled = isNtpProtocolEnabled)
18 },
19 actions: {
20 async getNtpData({ commit }) {
21 return await api
22 .get('/redfish/v1/Managers/bmc/NetworkProtocol')
23 .then(response => {
24 const ntpServers = response.data.NTP.NTPServers;
25 const isNtpProtocolEnabled = response.data.NTP.ProtocolEnabled;
26 commit('setNtpServers', ntpServers);
27 commit('setIsNtpProtocolEnabled', isNtpProtocolEnabled);
28 })
29 .catch(error => {
30 console.log(error);
31 });
32 },
33 async updateDateTimeSettings(_, dateTimeForm) {
34 const ntpData = {
35 NTP: {
36 ProtocolEnabled: dateTimeForm.ntpProtocolEnabled
37 }
38 };
39
40 if (dateTimeForm.ntpProtocolEnabled) {
41 ntpData.NTP.NTPServers = dateTimeForm.ntpServersArray;
42 }
43 return await api
44 .patch(`/redfish/v1/Managers/bmc/NetworkProtocol`, ntpData)
45 .then(() => {
46 if (!dateTimeForm.ntpProtocolEnabled) {
47 const dateTimeData = {
48 DateTime: dateTimeForm.updatedDateTime
49 };
50 api.patch(`/redfish/v1/Managers/bmc`, dateTimeData);
51 }
52 })
53 .then(() => {
54 return i18n.t(
55 'pageDateTimeSettings.toast.successSaveDateTimeSettings'
56 );
57 })
58 .catch(error => {
59 console.log(error);
60 throw new Error(
61 i18n.t('pageDateTimeSettings.toast.errorSaveDateTimeSettings')
62 );
63 });
64 }
65 }
66};
67
68export default DateTimeStore;