blob: 3ae08a11e3cde5fbfe0c0fa56b5dcc9478d03446 [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) =>
54 response.data.Members.map((virtualMedia) => virtualMedia['@odata.id'])
Mateusz Gapski75100462020-07-30 11:01:29 +020055 )
Derick Montague602e98a2020-10-21 16:20:00 -050056 .then((devices) => api.all(devices.map((device) => api.get(device))))
57 .then((devices) => {
58 const deviceData = devices.map((device) => {
Mateusz Gapski2224ece2020-09-02 17:00:06 +020059 const isActive = device.data?.Inserted === true ? true : false;
Mateusz Gapski75100462020-07-30 11:01:29 +020060 return {
61 id: device.data?.Id,
62 transferProtocolType: device.data?.TransferProtocolType,
Mateusz Gapski2224ece2020-09-02 17:00:06 +020063 websocket: device.data?.Oem?.OpenBMC?.WebSocketEndpoint,
Derick Montague602e98a2020-10-21 16:20:00 -050064 isActive: isActive,
Mateusz Gapski75100462020-07-30 11:01:29 +020065 };
66 });
67 const proxyDevices = deviceData
Grzegorz Raguzac9cb8d42021-09-03 17:56:54 +000068 .filter((d) => d.transferProtocolType === transferProtocolType.OEM)
Derick Montague602e98a2020-10-21 16:20:00 -050069 .map((device) => {
Mateusz Gapski75100462020-07-30 11:01:29 +020070 return {
71 ...device,
Derick Montague602e98a2020-10-21 16:20:00 -050072 file: null,
Mateusz Gapski75100462020-07-30 11:01:29 +020073 };
74 });
75 const legacyDevices = deviceData
Grzegorz Raguzac9cb8d42021-09-03 17:56:54 +000076 .filter((d) => d.transferProtocolType !== transferProtocolType.OEM)
Derick Montague602e98a2020-10-21 16:20:00 -050077 .map((device) => {
Mateusz Gapski75100462020-07-30 11:01:29 +020078 return {
79 ...device,
Mateusz Gapski2224ece2020-09-02 17:00:06 +020080 serverUri: '',
81 username: '',
82 password: '',
Derick Montague602e98a2020-10-21 16:20:00 -050083 isRW: false,
Mateusz Gapski75100462020-07-30 11:01:29 +020084 };
85 });
86 commit('setProxyDevicesData', proxyDevices);
87 commit('setLegacyDevicesData', legacyDevices);
88 })
Derick Montague602e98a2020-10-21 16:20:00 -050089 .catch((error) => {
Mateusz Gapski75100462020-07-30 11:01:29 +020090 console.log('Virtual Media:', error);
91 });
Mateusz Gapski2224ece2020-09-02 17:00:06 +020092 },
93 async mountImage(_, { id, data }) {
94 return await api
95 .post(
96 `/redfish/v1/Managers/bmc/VirtualMedia/${id}/Actions/VirtualMedia.InsertMedia`,
97 data
98 )
Derick Montague602e98a2020-10-21 16:20:00 -050099 .catch((error) => {
Mateusz Gapski2224ece2020-09-02 17:00:06 +0200100 console.log('Mount image:', error);
101 throw new Error();
102 });
103 },
104 async unmountImage(_, id) {
105 return await api
106 .post(
107 `/redfish/v1/Managers/bmc/VirtualMedia/${id}/Actions/VirtualMedia.EjectMedia`
108 )
Derick Montague602e98a2020-10-21 16:20:00 -0500109 .catch((error) => {
Mateusz Gapski2224ece2020-09-02 17:00:06 +0200110 console.log('Unmount image:', error);
111 throw new Error();
112 });
Derick Montague602e98a2020-10-21 16:20:00 -0500113 },
114 },
Mateusz Gapski75100462020-07-30 11:01:29 +0200115};
116
117export default VirtualMediaStore;