summaryrefslogtreecommitdiff
path: root/src/store/modules/Configuration/NetworkSettingsStore.js
blob: ee58a77bf917344b949d2c3c35f54c374c925a73 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import api from '../../api';

const NetworkSettingsStore = {
  namespaced: true,
  state: {
    networkData: null,
    ipAddress: '--',
    macAddress: '--'
  },
  getters: {
    networkData: state => state.networkData,
    ipAddress: state => state.ipAddress,
    macAddress: state => state.macAddress
  },
  mutations: {
    setNetworkData: (state, networkData) => (state.networkData = networkData),
    setIpAddress: (state, ipAddress) => (state.ipAddress = ipAddress),
    setMacAddress: (state, macAddress) => (state.macAddress = macAddress)
  },
  actions: {
    getNetworkData({ commit }) {
      api
        .get('/xyz/openbmc_project/network/enumerate')
        .then(response => {
          const networkData = response.data.data;
          const ipAddresses = [];
          const interfaceId = /eth[0-9]/;
          for (let key in networkData) {
            if (key.includes('ipv4')) {
              ipAddresses.push(networkData[key].Address);
            }
            if (
              key.match(interfaceId) &&
              networkData[key].MACAddress !== undefined
            ) {
              commit('setMacAddress', networkData[key].MACAddress);
            }
          }
          commit('setIpAddress', ipAddresses);
        })
        .catch(error => {
          console.log('Network Data:', error);
        });
    }
  }
};

export default NetworkSettingsStore;