From bb81d55c5cd9db01ad4f7949bc3fb80426570914 Mon Sep 17 00:00:00 2001 From: Dixsie Wolmers Date: Wed, 26 Feb 2020 19:52:28 -0600 Subject: 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 Change-Id: I122034ae0ef3a8c08e5599ee3eca66e8d0d59f67 --- src/components/AppNavigation/AppNavigation.vue | 2 +- src/router/index.js | 8 + .../modules/Configuration/NetworkSettingsStore.js | 71 ++- .../NetworkSettings/NetworkSettings.vue | 492 +++++++++++++++++++++ src/views/Configuration/NetworkSettings/index.js | 2 + 5 files changed, 571 insertions(+), 4 deletions(-) create mode 100644 src/views/Configuration/NetworkSettings/NetworkSettings.vue create mode 100644 src/views/Configuration/NetworkSettings/index.js (limited to 'src') diff --git a/src/components/AppNavigation/AppNavigation.vue b/src/components/AppNavigation/AppNavigation.vue index b7a3e071..8103558e 100644 --- a/src/components/AppNavigation/AppNavigation.vue +++ b/src/components/AppNavigation/AppNavigation.vue @@ -59,7 +59,7 @@ {{ $t('appNavigation.firmware') }} - + {{ $t('appNavigation.networkSettings') }} diff --git a/src/router/index.js b/src/router/index.js index 30532a5f..e35e0f59 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -71,6 +71,14 @@ const routes = [ title: 'appPageTitle.managePowerUsage' } }, + { + path: '/configuration/network-settings', + name: 'network-settings', + component: () => import('@/views/Configuration/NetworkSettings'), + meta: { + title: 'appPageTitle.networkSettings' + } + }, { path: '/control/reboot-bmc', name: 'reboot-bmc', 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.'); + }); } } }; diff --git a/src/views/Configuration/NetworkSettings/NetworkSettings.vue b/src/views/Configuration/NetworkSettings/NetworkSettings.vue new file mode 100644 index 00000000..18e73a04 --- /dev/null +++ b/src/views/Configuration/NetworkSettings/NetworkSettings.vue @@ -0,0 +1,492 @@ + + + diff --git a/src/views/Configuration/NetworkSettings/index.js b/src/views/Configuration/NetworkSettings/index.js new file mode 100644 index 00000000..1215e1c1 --- /dev/null +++ b/src/views/Configuration/NetworkSettings/index.js @@ -0,0 +1,2 @@ +import NetworkSettings from './NetworkSettings.vue'; +export default NetworkSettings; -- cgit v1.2.3