blob: 7c183b0e0a4e9b30d1b03d2dc67a441cb394e380 [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: [],
Derick Montague602e98a2020-10-21 16:20:00 -05009 connections: [],
Mateusz Gapski75100462020-07-30 11:01:29 +020010 },
11 getters: {
Derick Montague602e98a2020-10-21 16:20:00 -050012 proxyDevices: (state) => state.proxyDevices,
13 legacyDevices: (state) => state.legacyDevices,
Mateusz Gapski75100462020-07-30 11:01:29 +020014 },
15 mutations: {
16 setProxyDevicesData: (state, deviceData) =>
17 (state.proxyDevices = deviceData),
18 setLegacyDevicesData: (state, deviceData) =>
Derick Montague602e98a2020-10-21 16:20:00 -050019 (state.legacyDevices = deviceData),
Mateusz Gapski75100462020-07-30 11:01:29 +020020 },
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',
Derick Montague602e98a2020-10-21 16:20:00 -050033 isActive: false,
Mateusz Gapski75100462020-07-30 11:01:29 +020034 };
35 commit('setProxyDevicesData', [device]);
36 return;
37 }
38
39 return await api
40 .get('/redfish/v1/Managers/bmc/VirtualMedia')
Derick Montague602e98a2020-10-21 16:20:00 -050041 .then((response) =>
42 response.data.Members.map((virtualMedia) => virtualMedia['@odata.id'])
Mateusz Gapski75100462020-07-30 11:01:29 +020043 )
Derick Montague602e98a2020-10-21 16:20:00 -050044 .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,
Derick Montague602e98a2020-10-21 16:20:00 -050052 isActive: isActive,
Mateusz Gapski75100462020-07-30 11:01:29 +020053 };
54 });
55 const proxyDevices = deviceData
Derick Montague602e98a2020-10-21 16:20:00 -050056 .filter((d) => d.transferProtocolType === 'OEM')
57 .map((device) => {
Mateusz Gapski75100462020-07-30 11:01:29 +020058 return {
59 ...device,
Derick Montague602e98a2020-10-21 16:20:00 -050060 file: null,
Mateusz Gapski75100462020-07-30 11:01:29 +020061 };
62 });
63 const legacyDevices = deviceData
Derick Montague602e98a2020-10-21 16:20:00 -050064 .filter((d) => !d.transferProtocolType)
65 .map((device) => {
Mateusz Gapski75100462020-07-30 11:01:29 +020066 return {
67 ...device,
Mateusz Gapski2224ece2020-09-02 17:00:06 +020068 serverUri: '',
69 username: '',
70 password: '',
Derick Montague602e98a2020-10-21 16:20:00 -050071 isRW: false,
Mateusz Gapski75100462020-07-30 11:01:29 +020072 };
73 });
74 commit('setProxyDevicesData', proxyDevices);
75 commit('setLegacyDevicesData', legacyDevices);
76 })
Derick Montague602e98a2020-10-21 16:20:00 -050077 .catch((error) => {
Mateusz Gapski75100462020-07-30 11:01:29 +020078 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 )
Derick Montague602e98a2020-10-21 16:20:00 -050087 .catch((error) => {
Mateusz Gapski2224ece2020-09-02 17:00:06 +020088 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 )
Derick Montague602e98a2020-10-21 16:20:00 -050097 .catch((error) => {
Mateusz Gapski2224ece2020-09-02 17:00:06 +020098 console.log('Unmount image:', error);
99 throw new Error();
100 });
Derick Montague602e98a2020-10-21 16:20:00 -0500101 },
102 },
Mateusz Gapski75100462020-07-30 11:01:29 +0200103};
104
105export default VirtualMediaStore;