blob: e01cfce1aaa92a8ee77d94594803e75dcaf09dd9 [file] [log] [blame]
Mateusz Gapski75100462020-07-30 11:01:29 +02001import api from '../../api';
2import i18n from '@/i18n';
3
4const VirtualMediaStore = {
5 namespaced: true,
6 state: {
7 proxyDevices: [],
8 legacyDevices: [],
9 connections: []
10 },
11 getters: {
12 proxyDevices: state => state.proxyDevices,
13 legacyDevices: state => state.legacyDevices
14 },
15 mutations: {
16 setProxyDevicesData: (state, deviceData) =>
17 (state.proxyDevices = deviceData),
18 setLegacyDevicesData: (state, deviceData) =>
19 (state.legacyDevices = deviceData)
20 },
21 actions: {
22 async getData({ commit }) {
23 const virtualMediaListEnabled =
24 process.env.VUE_APP_VIRTUAL_MEDIA_LIST_ENABLED === 'true'
25 ? true
26 : false;
27 if (!virtualMediaListEnabled) {
28 const device = {
29 id: i18n.t('pageVirtualMedia.defaultDeviceName'),
30 websocket: '/vm/0/0',
31 file: null,
32 transferProtocolType: 'OEM',
33 isActive: false
34 };
35 commit('setProxyDevicesData', [device]);
36 return;
37 }
38
39 return await api
40 .get('/redfish/v1/Managers/bmc/VirtualMedia')
41 .then(response =>
42 response.data.Members.map(virtualMedia => virtualMedia['@odata.id'])
43 )
44 .then(devices => api.all(devices.map(device => api.get(device))))
45 .then(devices => {
46 const deviceData = devices.map(device => {
47 return {
48 id: device.data?.Id,
49 transferProtocolType: device.data?.TransferProtocolType,
50 websocket: device.data?.Oem?.OpenBMC?.WebSocketEndpoint
51 };
52 });
53 const proxyDevices = deviceData
54 .filter(d => d.transferProtocolType === 'OEM')
55 .map(device => {
56 return {
57 ...device,
58 file: null,
59 isActive: false
60 };
61 });
62 const legacyDevices = deviceData
63 .filter(d => !d.transferProtocolType)
64 .map(device => {
65 return {
66 ...device,
67 address: ''
68 };
69 });
70 commit('setProxyDevicesData', proxyDevices);
71 commit('setLegacyDevicesData', legacyDevices);
72 })
73 .catch(error => {
74 console.log('Virtual Media:', error);
75 });
76 }
77 }
78};
79
80export default VirtualMediaStore;