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 | |
Grzegorz Raguza | c9cb8d4 | 2021-09-03 17:56:54 +0000 | [diff] [blame] | 4 | const 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 Gapski | 7510046 | 2020-07-30 11:01:29 +0200 | [diff] [blame] | 16 | const VirtualMediaStore = { |
| 17 | namespaced: true, |
| 18 | state: { |
| 19 | proxyDevices: [], |
| 20 | legacyDevices: [], |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 21 | connections: [], |
Mateusz Gapski | 7510046 | 2020-07-30 11:01:29 +0200 | [diff] [blame] | 22 | }, |
| 23 | getters: { |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 24 | proxyDevices: (state) => state.proxyDevices, |
| 25 | legacyDevices: (state) => state.legacyDevices, |
Mateusz Gapski | 7510046 | 2020-07-30 11:01:29 +0200 | [diff] [blame] | 26 | }, |
| 27 | mutations: { |
| 28 | setProxyDevicesData: (state, deviceData) => |
| 29 | (state.proxyDevices = deviceData), |
| 30 | setLegacyDevicesData: (state, deviceData) => |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 31 | (state.legacyDevices = deviceData), |
Mateusz Gapski | 7510046 | 2020-07-30 11:01:29 +0200 | [diff] [blame] | 32 | }, |
| 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 Raguza | c9cb8d4 | 2021-09-03 17:56:54 +0000 | [diff] [blame] | 44 | transferProtocolType: transferProtocolType.OEM, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 45 | isActive: false, |
Mateusz Gapski | 7510046 | 2020-07-30 11:01:29 +0200 | [diff] [blame] | 46 | }; |
| 47 | commit('setProxyDevicesData', [device]); |
| 48 | return; |
| 49 | } |
| 50 | |
| 51 | return await api |
| 52 | .get('/redfish/v1/Managers/bmc/VirtualMedia') |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 53 | .then((response) => |
| 54 | response.data.Members.map((virtualMedia) => virtualMedia['@odata.id']) |
Mateusz Gapski | 7510046 | 2020-07-30 11:01:29 +0200 | [diff] [blame] | 55 | ) |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 56 | .then((devices) => api.all(devices.map((device) => api.get(device)))) |
| 57 | .then((devices) => { |
| 58 | const deviceData = devices.map((device) => { |
Mateusz Gapski | 2224ece | 2020-09-02 17:00:06 +0200 | [diff] [blame] | 59 | const isActive = device.data?.Inserted === true ? true : false; |
Mateusz Gapski | 7510046 | 2020-07-30 11:01:29 +0200 | [diff] [blame] | 60 | return { |
| 61 | id: device.data?.Id, |
| 62 | transferProtocolType: device.data?.TransferProtocolType, |
Mateusz Gapski | 2224ece | 2020-09-02 17:00:06 +0200 | [diff] [blame] | 63 | websocket: device.data?.Oem?.OpenBMC?.WebSocketEndpoint, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 64 | isActive: isActive, |
Mateusz Gapski | 7510046 | 2020-07-30 11:01:29 +0200 | [diff] [blame] | 65 | }; |
| 66 | }); |
| 67 | const proxyDevices = deviceData |
Grzegorz Raguza | c9cb8d4 | 2021-09-03 17:56:54 +0000 | [diff] [blame] | 68 | .filter((d) => d.transferProtocolType === transferProtocolType.OEM) |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 69 | .map((device) => { |
Mateusz Gapski | 7510046 | 2020-07-30 11:01:29 +0200 | [diff] [blame] | 70 | return { |
| 71 | ...device, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 72 | file: null, |
Mateusz Gapski | 7510046 | 2020-07-30 11:01:29 +0200 | [diff] [blame] | 73 | }; |
| 74 | }); |
| 75 | const legacyDevices = deviceData |
Grzegorz Raguza | c9cb8d4 | 2021-09-03 17:56:54 +0000 | [diff] [blame] | 76 | .filter((d) => d.transferProtocolType !== transferProtocolType.OEM) |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 77 | .map((device) => { |
Mateusz Gapski | 7510046 | 2020-07-30 11:01:29 +0200 | [diff] [blame] | 78 | return { |
| 79 | ...device, |
Mateusz Gapski | 2224ece | 2020-09-02 17:00:06 +0200 | [diff] [blame] | 80 | serverUri: '', |
| 81 | username: '', |
| 82 | password: '', |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 83 | isRW: false, |
Mateusz Gapski | 7510046 | 2020-07-30 11:01:29 +0200 | [diff] [blame] | 84 | }; |
| 85 | }); |
| 86 | commit('setProxyDevicesData', proxyDevices); |
| 87 | commit('setLegacyDevicesData', legacyDevices); |
| 88 | }) |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 89 | .catch((error) => { |
Mateusz Gapski | 7510046 | 2020-07-30 11:01:29 +0200 | [diff] [blame] | 90 | console.log('Virtual Media:', error); |
| 91 | }); |
Mateusz Gapski | 2224ece | 2020-09-02 17:00:06 +0200 | [diff] [blame] | 92 | }, |
| 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 Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 99 | .catch((error) => { |
Mateusz Gapski | 2224ece | 2020-09-02 17:00:06 +0200 | [diff] [blame] | 100 | 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 Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 109 | .catch((error) => { |
Mateusz Gapski | 2224ece | 2020-09-02 17:00:06 +0200 | [diff] [blame] | 110 | console.log('Unmount image:', error); |
| 111 | throw new Error(); |
| 112 | }); |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 113 | }, |
| 114 | }, |
Mateusz Gapski | 7510046 | 2020-07-30 11:01:29 +0200 | [diff] [blame] | 115 | }; |
| 116 | |
| 117 | export default VirtualMediaStore; |