blob: 6785f5fd448645e9c59b92b3b9f19cb8953588a9 [file] [log] [blame]
SurenNeware61859092020-10-01 09:37:32 +05301import api from '@/store/api';
Mateusz Gapski75100462020-07-30 11:01:29 +02002import 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 => {
Mateusz Gapski2224ece2020-09-02 17:00:06 +020047 const isActive = device.data?.Inserted === true ? true : false;
Mateusz Gapski75100462020-07-30 11:01:29 +020048 return {
49 id: device.data?.Id,
50 transferProtocolType: device.data?.TransferProtocolType,
Mateusz Gapski2224ece2020-09-02 17:00:06 +020051 websocket: device.data?.Oem?.OpenBMC?.WebSocketEndpoint,
52 isActive: isActive
Mateusz Gapski75100462020-07-30 11:01:29 +020053 };
54 });
55 const proxyDevices = deviceData
56 .filter(d => d.transferProtocolType === 'OEM')
57 .map(device => {
58 return {
59 ...device,
Mateusz Gapski2224ece2020-09-02 17:00:06 +020060 file: null
Mateusz Gapski75100462020-07-30 11:01:29 +020061 };
62 });
63 const legacyDevices = deviceData
64 .filter(d => !d.transferProtocolType)
65 .map(device => {
66 return {
67 ...device,
Mateusz Gapski2224ece2020-09-02 17:00:06 +020068 serverUri: '',
69 username: '',
70 password: '',
71 isRW: false
Mateusz Gapski75100462020-07-30 11:01:29 +020072 };
73 });
74 commit('setProxyDevicesData', proxyDevices);
75 commit('setLegacyDevicesData', legacyDevices);
76 })
77 .catch(error => {
78 console.log('Virtual Media:', error);
79 });
Mateusz Gapski2224ece2020-09-02 17:00:06 +020080 },
81 async mountImage(_, { id, data }) {
82 return await api
83 .post(
84 `/redfish/v1/Managers/bmc/VirtualMedia/${id}/Actions/VirtualMedia.InsertMedia`,
85 data
86 )
87 .catch(error => {
88 console.log('Mount image:', error);
89 throw new Error();
90 });
91 },
92 async unmountImage(_, id) {
93 return await api
94 .post(
95 `/redfish/v1/Managers/bmc/VirtualMedia/${id}/Actions/VirtualMedia.EjectMedia`
96 )
97 .catch(error => {
98 console.log('Unmount image:', error);
99 throw new Error();
100 });
Mateusz Gapski75100462020-07-30 11:01:29 +0200101 }
102 }
103};
104
105export default VirtualMediaStore;