From b34349d4139230fb4ca99bf89a6b0e1f707e58e2 Mon Sep 17 00:00:00 2001 From: Dixsie Wolmers Date: Tue, 2 Nov 2021 22:06:35 -0500 Subject: Network Settings: Add and Delete IPV4 and DNS address Adds ability to add or delete static ipv4 and dns addesses per interface. Signed-off-by: Dixsie Wolmers Change-Id: Ie143ded2f173dd48f137471a684ba0d35ab0bf69 --- src/store/modules/Settings/NetworkStore.js | 119 +++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) (limited to 'src/store/modules/Settings') diff --git a/src/store/modules/Settings/NetworkStore.js b/src/store/modules/Settings/NetworkStore.js index 5b95cb00..176fcd74 100644 --- a/src/store/modules/Settings/NetworkStore.js +++ b/src/store/modules/Settings/NetworkStore.js @@ -7,13 +7,20 @@ const NetworkStore = { ethernetData: [], firstInterfaceId: '', //used for setting global DHCP settings globalNetworkSettings: [], + selectedInterfaceId: '', // which tab is selected + selectedInterfaceIndex: 0, // which tab is selected }, getters: { ethernetData: (state) => state.ethernetData, firstInterfaceId: (state) => state.firstInterfaceId, globalNetworkSettings: (state) => state.globalNetworkSettings, + selectedInterfaceId: (state) => state.selectedInterfaceId, + selectedInterfaceIndex: (state) => state.selectedInterfaceIndex, }, mutations: { + setDomainNameState: (state, domainState) => + (state.domainState = domainState), + setDnsState: (state, dnsState) => (state.dnsState = dnsState), setEthernetData: (state, ethernetData) => (state.ethernetData = ethernetData), setFirstInterfaceId: (state, firstInterfaceId) => @@ -28,6 +35,7 @@ const NetworkStore = { LinkStatus, } = data; return { + defaultGateway: IPv4StaticAddresses[0]?.Gateway, //First static gateway is the default gateway dhcpAddress: IPv4Addresses.filter( (ipv4) => ipv4.AddressOrigin === 'DHCP' ), @@ -40,6 +48,11 @@ const NetworkStore = { }; }); }, + setNtpState: (state, ntpState) => (state.ntpState = ntpState), + setSelectedInterfaceId: (state, selectedInterfaceId) => + (state.selectedInterfaceId = selectedInterfaceId), + setSelectedInterfaceIndex: (state, selectedInterfaceIndex) => + (state.selectedInterfaceIndex = selectedInterfaceIndex), }, actions: { async getEthernetData({ commit }) { @@ -65,6 +78,7 @@ const NetworkStore = { commit('setEthernetData', ethernetData); commit('setFirstInterfaceId', firstInterfaceId); + commit('setSelectedInterfaceId', firstInterfaceId); commit('setGlobalNetworkSettings', ethernetInterfaces); }) .catch((error) => { @@ -158,6 +172,111 @@ const NetworkStore = { ); }); }, + async setSelectedTabIndex({ commit }, tabIndex) { + commit('setSelectedInterfaceIndex', tabIndex); + }, + async setSelectedTabId({ commit }, tabId) { + commit('setSelectedInterfaceId', tabId); + }, + async saveIpv4Address({ dispatch, state }, ipv4Form) { + const originalAddresses = state.ethernetData[ + state.selectedInterfaceIndex + ].IPv4StaticAddresses.map((ipv4) => { + const { Address, SubnetMask, Gateway } = ipv4; + return { + Address, + SubnetMask, + Gateway, + }; + }); + const newAddress = [ipv4Form]; + return api + .patch( + `/redfish/v1/Managers/bmc/EthernetInterfaces/${state.selectedInterfaceId}`, + { IPv4StaticAddresses: originalAddresses.concat(newAddress) } + ) + .then(dispatch('getEthernetData')) + .then(() => { + return i18n.t('pageNetwork.toast.successSaveNetworkSettings', { + setting: i18n.t('pageNetwork.ipv4'), + }); + }) + .catch((error) => { + console.log(error); + throw new Error( + i18n.t('pageNetwork.toast.errorSaveNetworkSettings', { + setting: i18n.t('pageNetwork.ipv4'), + }) + ); + }); + }, + async editIpv4Address({ dispatch, state }, ipv4TableData) { + return api + .patch( + `/redfish/v1/Managers/bmc/EthernetInterfaces/${state.selectedInterfaceId}`, + { IPv4StaticAddresses: ipv4TableData } + ) + .then(dispatch('getEthernetData')) + .then(() => { + return i18n.t('pageNetwork.toast.successSaveNetworkSettings', { + setting: i18n.t('pageNetwork.ipv4'), + }); + }) + .catch((error) => { + console.log(error); + throw new Error( + i18n.t('pageNetwork.toast.errorSaveNetworkSettings', { + setting: i18n.t('pageNetwork.ipv4'), + }) + ); + }); + }, + async saveDnsAddress({ dispatch, state }, dnsForm) { + const newAddress = dnsForm; + const originalAddresses = + state.ethernetData[state.selectedInterfaceIndex].StaticNameServers; + const newDnsArray = originalAddresses.concat(newAddress); + return api + .patch( + `/redfish/v1/Managers/bmc/EthernetInterfaces/${state.selectedInterfaceId}`, + { StaticNameServers: newDnsArray } + ) + .then(dispatch('getEthernetData')) + .then(() => { + return i18n.t('pageNetwork.toast.successSaveNetworkSettings', { + setting: i18n.t('pageNetwork.dns'), + }); + }) + .catch((error) => { + console.log(error); + throw new Error( + i18n.t('pageNetwork.toast.errorSaveNetworkSettings', { + setting: i18n.t('pageNetwork.dns'), + }) + ); + }); + }, + async editDnsAddress({ dispatch, state }, dnsTableData) { + return api + .patch( + `/redfish/v1/Managers/bmc/EthernetInterfaces/${state.selectedInterfaceId}`, + { StaticNameServers: dnsTableData } + ) + .then(dispatch('getEthernetData')) + .then(() => { + return i18n.t('pageNetwork.toast.successSaveNetworkSettings', { + setting: i18n.t('pageNetwork.dns'), + }); + }) + .catch((error) => { + console.log(error); + throw new Error( + i18n.t('pageNetwork.toast.errorSaveNetworkSettings', { + setting: i18n.t('pageNetwork.dns'), + }) + ); + }); + }, }, }; -- cgit v1.2.3