SurenNeware | 6185909 | 2020-10-01 09:37:32 +0530 | [diff] [blame] | 1 | import api from '@/store/api'; |
Mateusz Gapski | 7510046 | 2020-07-30 11:01:29 +0200 | [diff] [blame] | 2 | import i18n from '@/i18n'; |
| 3 | |
| 4 | const VirtualMediaStore = { |
| 5 | namespaced: true, |
| 6 | state: { |
| 7 | proxyDevices: [], |
| 8 | legacyDevices: [], |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 9 | connections: [], |
Mateusz Gapski | 7510046 | 2020-07-30 11:01:29 +0200 | [diff] [blame] | 10 | }, |
| 11 | getters: { |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 12 | proxyDevices: (state) => state.proxyDevices, |
| 13 | legacyDevices: (state) => state.legacyDevices, |
Mateusz Gapski | 7510046 | 2020-07-30 11:01:29 +0200 | [diff] [blame] | 14 | }, |
| 15 | mutations: { |
| 16 | setProxyDevicesData: (state, deviceData) => |
| 17 | (state.proxyDevices = deviceData), |
| 18 | setLegacyDevicesData: (state, deviceData) => |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 19 | (state.legacyDevices = deviceData), |
Mateusz Gapski | 7510046 | 2020-07-30 11:01:29 +0200 | [diff] [blame] | 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', |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 33 | isActive: false, |
Mateusz Gapski | 7510046 | 2020-07-30 11:01:29 +0200 | [diff] [blame] | 34 | }; |
| 35 | commit('setProxyDevicesData', [device]); |
| 36 | return; |
| 37 | } |
| 38 | |
| 39 | return await api |
| 40 | .get('/redfish/v1/Managers/bmc/VirtualMedia') |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 41 | .then((response) => |
| 42 | response.data.Members.map((virtualMedia) => virtualMedia['@odata.id']) |
Mateusz Gapski | 7510046 | 2020-07-30 11:01:29 +0200 | [diff] [blame] | 43 | ) |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 44 | .then((devices) => api.all(devices.map((device) => api.get(device)))) |
| 45 | .then((devices) => { |
| 46 | const deviceData = devices.map((device) => { |
Mateusz Gapski | 2224ece | 2020-09-02 17:00:06 +0200 | [diff] [blame] | 47 | const isActive = device.data?.Inserted === true ? true : false; |
Mateusz Gapski | 7510046 | 2020-07-30 11:01:29 +0200 | [diff] [blame] | 48 | return { |
| 49 | id: device.data?.Id, |
| 50 | transferProtocolType: device.data?.TransferProtocolType, |
Mateusz Gapski | 2224ece | 2020-09-02 17:00:06 +0200 | [diff] [blame] | 51 | websocket: device.data?.Oem?.OpenBMC?.WebSocketEndpoint, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 52 | isActive: isActive, |
Mateusz Gapski | 7510046 | 2020-07-30 11:01:29 +0200 | [diff] [blame] | 53 | }; |
| 54 | }); |
| 55 | const proxyDevices = deviceData |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 56 | .filter((d) => d.transferProtocolType === 'OEM') |
| 57 | .map((device) => { |
Mateusz Gapski | 7510046 | 2020-07-30 11:01:29 +0200 | [diff] [blame] | 58 | return { |
| 59 | ...device, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 60 | file: null, |
Mateusz Gapski | 7510046 | 2020-07-30 11:01:29 +0200 | [diff] [blame] | 61 | }; |
| 62 | }); |
| 63 | const legacyDevices = deviceData |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 64 | .filter((d) => !d.transferProtocolType) |
| 65 | .map((device) => { |
Mateusz Gapski | 7510046 | 2020-07-30 11:01:29 +0200 | [diff] [blame] | 66 | return { |
| 67 | ...device, |
Mateusz Gapski | 2224ece | 2020-09-02 17:00:06 +0200 | [diff] [blame] | 68 | serverUri: '', |
| 69 | username: '', |
| 70 | password: '', |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 71 | isRW: false, |
Mateusz Gapski | 7510046 | 2020-07-30 11:01:29 +0200 | [diff] [blame] | 72 | }; |
| 73 | }); |
| 74 | commit('setProxyDevicesData', proxyDevices); |
| 75 | commit('setLegacyDevicesData', legacyDevices); |
| 76 | }) |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 77 | .catch((error) => { |
Mateusz Gapski | 7510046 | 2020-07-30 11:01:29 +0200 | [diff] [blame] | 78 | console.log('Virtual Media:', error); |
| 79 | }); |
Mateusz Gapski | 2224ece | 2020-09-02 17:00:06 +0200 | [diff] [blame] | 80 | }, |
| 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 Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 87 | .catch((error) => { |
Mateusz Gapski | 2224ece | 2020-09-02 17:00:06 +0200 | [diff] [blame] | 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 | ) |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 97 | .catch((error) => { |
Mateusz Gapski | 2224ece | 2020-09-02 17:00:06 +0200 | [diff] [blame] | 98 | console.log('Unmount image:', error); |
| 99 | throw new Error(); |
| 100 | }); |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 101 | }, |
| 102 | }, |
Mateusz Gapski | 7510046 | 2020-07-30 11:01:29 +0200 | [diff] [blame] | 103 | }; |
| 104 | |
| 105 | export default VirtualMediaStore; |