summaryrefslogtreecommitdiff
path: root/src/store
diff options
context:
space:
mode:
authorDixsie Wolmers <dixsie@ibm.com>2020-02-27 04:52:28 +0300
committerDerick Montague <derick.montague@ibm.com>2020-06-05 20:39:25 +0300
commitbb81d55c5cd9db01ad4f7949bc3fb80426570914 (patch)
tree015aeda354f407a0ce1e1d054baa6c6790e8c093 /src/store
parent304095d60a270a311d7e081313ccada27cc2d3cd (diff)
downloadwebui-vue-bb81d55c5cd9db01ad4f7949bc3fb80426570914.tar.xz
Add network settings page
- Adds ability to configure newtowrk settings by selected ethernet interface - Default gateway is currently unavailable in redfish, to work around, grabbed gateway from first static ipv4 configuration and assigned to new static ipv4 configurations - Adds ability to add, modify and delete static ipv4 configs - Adds ability to add, modify and delete static dns - Adds ability to edit gateway, hostname and mac address - Form validations include regex for ip, mac address, and hostname - Language translations to be addressed in separate commit - Enabling DHCP and configuring DHCP settings to be addressed in separate commit Signed-off-by: Dixsie Wolmers <dixsie@ibm.com> Change-Id: I122034ae0ef3a8c08e5599ee3eca66e8d0d59f67
Diffstat (limited to 'src/store')
-rw-r--r--src/store/modules/Configuration/NetworkSettingsStore.js71
1 files changed, 68 insertions, 3 deletions
diff --git a/src/store/modules/Configuration/NetworkSettingsStore.js b/src/store/modules/Configuration/NetworkSettingsStore.js
index f6912c87..524ad342 100644
--- a/src/store/modules/Configuration/NetworkSettingsStore.js
+++ b/src/store/modules/Configuration/NetworkSettingsStore.js
@@ -1,16 +1,25 @@
import api from '../../api';
+import { find, remove } from 'lodash';
const NetworkSettingsStore = {
namespaced: true,
state: {
- ethernetData: []
+ defaultGateway: '',
+ ethernetData: [],
+ interfaceOptions: []
},
getters: {
- ethernetData: state => state.ethernetData
+ defaultGateway: state => state.defaultGateway,
+ ethernetData: state => state.ethernetData,
+ interfaceOptions: state => state.interfaceOptions
},
mutations: {
+ setDefaultGateway: (state, defaultGateway) =>
+ (state.defaultGateway = defaultGateway),
setEthernetData: (state, ethernetData) =>
- (state.ethernetData = ethernetData)
+ (state.ethernetData = ethernetData),
+ setInterfaceOptions: (state, interfaceOptions) =>
+ (state.interfaceOptions = interfaceOptions)
},
actions: {
async getEthernetData({ commit }) {
@@ -32,11 +41,67 @@ const NetworkSettingsStore = {
const ethernetData = ethernetInterfaces.map(
ethernetInterface => ethernetInterface.data
);
+ const interfaceOptions = ethernetInterfaces.map(
+ ethernetName => ethernetName.data.Id
+ );
+ const addresses = ethernetData[0].IPv4StaticAddresses;
+
+ // Default gateway manually set to first gateway saved on the first interface. Default gateway property is WIP on backend
+ const defaultGateway = addresses.map(ipv4 => {
+ return ipv4.Gateway;
+ });
+
+ commit('setDefaultGateway', defaultGateway[0]);
commit('setEthernetData', ethernetData);
+ commit('setInterfaceOptions', interfaceOptions);
})
.catch(error => {
console.log('Network Data:', error);
});
+ },
+
+ async updateInterfaceSettings({ dispatch, state }, networkSettingsForm) {
+ const updatedAddresses = networkSettingsForm.staticIpv4;
+ const originalAddresses =
+ state.ethernetData[networkSettingsForm.selectedInterfaceIndex]
+ .IPv4StaticAddresses;
+
+ const addressArray = originalAddresses.map(item => {
+ const address = item.Address;
+ if (find(updatedAddresses, { Address: address })) {
+ remove(updatedAddresses, item => {
+ return item.Address === address;
+ });
+ return {};
+ } else {
+ return null;
+ }
+ });
+
+ const data = {
+ HostName: networkSettingsForm.hostname,
+ MACAddress: networkSettingsForm.macAddress
+ };
+
+ // If DHCP disabled, update static DNS or static ipv4
+ if (!networkSettingsForm.isDhcpEnabled) {
+ data.IPv4StaticAddresses = [...addressArray, ...updatedAddresses];
+ data.StaticNameServers = networkSettingsForm.staticNameServers;
+ }
+
+ return await api
+ .patch(
+ `/redfish/v1/Managers/bmc/EthernetInterfaces/${networkSettingsForm.interfaceId}`,
+ data
+ )
+ .then(() => dispatch('getEthernetData'))
+ .then(() => {
+ return 'Successfully configured network settings.';
+ })
+ .catch(error => {
+ console.log(error);
+ throw new Error('Error configuring network settings.');
+ });
}
}
};