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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
import api from '@/store/api';
import i18n from '@/i18n';
const transferProtocolType = {
CIFS: 'CIFS',
FTP: 'FTP',
SFTP: 'SFTP',
HTTP: 'HTTP',
HTTPS: 'HTTPS',
NFS: 'NFS',
SCP: 'SCP',
TFTP: 'TFTP',
OEM: 'OEM',
};
const VirtualMediaStore = {
namespaced: true,
state: {
proxyDevices: [],
legacyDevices: [],
connections: [],
},
getters: {
proxyDevices: (state) => state.proxyDevices,
legacyDevices: (state) => state.legacyDevices,
},
mutations: {
setProxyDevicesData: (state, deviceData) =>
(state.proxyDevices = deviceData),
setLegacyDevicesData: (state, deviceData) =>
(state.legacyDevices = deviceData),
},
actions: {
async getData({ commit }) {
const virtualMediaListEnabled =
process.env.VUE_APP_VIRTUAL_MEDIA_LIST_ENABLED === 'true'
? true
: false;
if (!virtualMediaListEnabled) {
const device = {
id: i18n.t('pageVirtualMedia.defaultDeviceName'),
websocket: '/vm/0/0',
file: null,
transferProtocolType: transferProtocolType.OEM,
isActive: false,
};
commit('setProxyDevicesData', [device]);
return;
}
return await api
.get(`${await this.dispatch('global/getBmcPath')}/VirtualMedia`)
.then((response) =>
response.data.Members.map(
(virtualMedia) => virtualMedia['@odata.id'],
),
)
.then((devices) => api.all(devices.map((device) => api.get(device))))
.then((devices) => {
const deviceData = devices.map((device) => {
const isActive = device.data?.Inserted === true ? true : false;
return {
id: device.data?.Id,
transferProtocolType: device.data?.TransferProtocolType,
websocket: device.data?.Oem?.OpenBMC?.WebSocketEndpoint,
isActive: isActive,
};
});
const proxyDevices = deviceData
.filter((d) => d.transferProtocolType === transferProtocolType.OEM)
.map((device) => {
return {
...device,
file: null,
};
});
const legacyDevices = deviceData
.filter((d) => d.transferProtocolType !== transferProtocolType.OEM)
.map((device) => {
return {
...device,
serverUri: '',
username: '',
password: '',
isRW: false,
};
});
commit('setProxyDevicesData', proxyDevices);
commit('setLegacyDevicesData', legacyDevices);
})
.catch((error) => {
console.log('Virtual Media:', error);
});
},
async mountImage(_, { id, data }) {
return await api
.post(
`${await this.dispatch('global/getBmcPath')}/VirtualMedia/${id}/Actions/VirtualMedia.InsertMedia`,
data,
)
.catch((error) => {
console.log('Mount image:', error);
throw new Error();
});
},
async unmountImage(_, id) {
return await api
.post(
`${await this.dispatch('global/getBmcPath')}/VirtualMedia/${id}/Actions/VirtualMedia.EjectMedia`,
)
.catch((error) => {
console.log('Unmount image:', error);
throw new Error();
});
},
},
};
export default VirtualMediaStore;
|