blob: 1d27e21577164427f6d94160f5c996667c2ec70b [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
Grzegorz Raguzac9cb8d42021-09-03 17:56:54 +00004const transferProtocolType = {
5 CIFS: 'CIFS',
6 FTP: 'FTP',
7 SFTP: 'SFTP',
8 HTTP: 'HTTP',
9 HTTPS: 'HTTPS',
10 NFS: 'NFS',
11 SCP: 'SCP',
12 TFTP: 'TFTP',
13 OEM: 'OEM',
14};
15
Mateusz Gapski75100462020-07-30 11:01:29 +020016const VirtualMediaStore = {
17 namespaced: true,
18 state: {
19 proxyDevices: [],
20 legacyDevices: [],
Derick Montague602e98a2020-10-21 16:20:00 -050021 connections: [],
Mateusz Gapski75100462020-07-30 11:01:29 +020022 },
23 getters: {
Derick Montague602e98a2020-10-21 16:20:00 -050024 proxyDevices: (state) => state.proxyDevices,
25 legacyDevices: (state) => state.legacyDevices,
Mateusz Gapski75100462020-07-30 11:01:29 +020026 },
27 mutations: {
28 setProxyDevicesData: (state, deviceData) =>
29 (state.proxyDevices = deviceData),
30 setLegacyDevicesData: (state, deviceData) =>
Derick Montague602e98a2020-10-21 16:20:00 -050031 (state.legacyDevices = deviceData),
Mateusz Gapski75100462020-07-30 11:01:29 +020032 },
33 actions: {
34 async getData({ commit }) {
35 const virtualMediaListEnabled =
36 process.env.VUE_APP_VIRTUAL_MEDIA_LIST_ENABLED === 'true'
37 ? true
38 : false;
39 if (!virtualMediaListEnabled) {
40 const device = {
41 id: i18n.t('pageVirtualMedia.defaultDeviceName'),
42 websocket: '/vm/0/0',
43 file: null,
Grzegorz Raguzac9cb8d42021-09-03 17:56:54 +000044 transferProtocolType: transferProtocolType.OEM,
Derick Montague602e98a2020-10-21 16:20:00 -050045 isActive: false,
Mateusz Gapski75100462020-07-30 11:01:29 +020046 };
47 commit('setProxyDevicesData', [device]);
48 return;
49 }
50
51 return await api
52 .get('/redfish/v1/Managers/bmc/VirtualMedia')
Derick Montague602e98a2020-10-21 16:20:00 -050053 .then((response) =>
Ed Tanous81323992024-02-27 11:26:24 -080054 response.data.Members.map(
55 (virtualMedia) => virtualMedia['@odata.id'],
56 ),
Mateusz Gapski75100462020-07-30 11:01:29 +020057 )
Derick Montague602e98a2020-10-21 16:20:00 -050058 .then((devices) => api.all(devices.map((device) => api.get(device))))
59 .then((devices) => {
60 const deviceData = devices.map((device) => {
Mateusz Gapski2224ece2020-09-02 17:00:06 +020061 const isActive = device.data?.Inserted === true ? true : false;
Mateusz Gapski75100462020-07-30 11:01:29 +020062 return {
63 id: device.data?.Id,
64 transferProtocolType: device.data?.TransferProtocolType,
Mateusz Gapski2224ece2020-09-02 17:00:06 +020065 websocket: device.data?.Oem?.OpenBMC?.WebSocketEndpoint,
Derick Montague602e98a2020-10-21 16:20:00 -050066 isActive: isActive,
Mateusz Gapski75100462020-07-30 11:01:29 +020067 };
68 });
69 const proxyDevices = deviceData
Grzegorz Raguzac9cb8d42021-09-03 17:56:54 +000070 .filter((d) => d.transferProtocolType === transferProtocolType.OEM)
Derick Montague602e98a2020-10-21 16:20:00 -050071 .map((device) => {
Mateusz Gapski75100462020-07-30 11:01:29 +020072 return {
73 ...device,
Derick Montague602e98a2020-10-21 16:20:00 -050074 file: null,
Mateusz Gapski75100462020-07-30 11:01:29 +020075 };
76 });
77 const legacyDevices = deviceData
Grzegorz Raguzac9cb8d42021-09-03 17:56:54 +000078 .filter((d) => d.transferProtocolType !== transferProtocolType.OEM)
Derick Montague602e98a2020-10-21 16:20:00 -050079 .map((device) => {
Mateusz Gapski75100462020-07-30 11:01:29 +020080 return {
81 ...device,
Mateusz Gapski2224ece2020-09-02 17:00:06 +020082 serverUri: '',
83 username: '',
84 password: '',
Derick Montague602e98a2020-10-21 16:20:00 -050085 isRW: false,
Mateusz Gapski75100462020-07-30 11:01:29 +020086 };
87 });
88 commit('setProxyDevicesData', proxyDevices);
89 commit('setLegacyDevicesData', legacyDevices);
90 })
Derick Montague602e98a2020-10-21 16:20:00 -050091 .catch((error) => {
Mateusz Gapski75100462020-07-30 11:01:29 +020092 console.log('Virtual Media:', error);
93 });
Mateusz Gapski2224ece2020-09-02 17:00:06 +020094 },
95 async mountImage(_, { id, data }) {
96 return await api
97 .post(
98 `/redfish/v1/Managers/bmc/VirtualMedia/${id}/Actions/VirtualMedia.InsertMedia`,
Ed Tanous81323992024-02-27 11:26:24 -080099 data,
Mateusz Gapski2224ece2020-09-02 17:00:06 +0200100 )
Derick Montague602e98a2020-10-21 16:20:00 -0500101 .catch((error) => {
Mateusz Gapski2224ece2020-09-02 17:00:06 +0200102 console.log('Mount image:', error);
103 throw new Error();
104 });
105 },
106 async unmountImage(_, id) {
107 return await api
108 .post(
Ed Tanous81323992024-02-27 11:26:24 -0800109 `/redfish/v1/Managers/bmc/VirtualMedia/${id}/Actions/VirtualMedia.EjectMedia`,
Mateusz Gapski2224ece2020-09-02 17:00:06 +0200110 )
Derick Montague602e98a2020-10-21 16:20:00 -0500111 .catch((error) => {
Mateusz Gapski2224ece2020-09-02 17:00:06 +0200112 console.log('Unmount image:', error);
113 throw new Error();
114 });
Derick Montague602e98a2020-10-21 16:20:00 -0500115 },
116 },
Mateusz Gapski75100462020-07-30 11:01:29 +0200117};
118
119export default VirtualMediaStore;