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: [], |
| 9 | connections: [] |
| 10 | }, |
| 11 | getters: { |
| 12 | proxyDevices: state => state.proxyDevices, |
| 13 | legacyDevices: state => state.legacyDevices |
| 14 | }, |
| 15 | mutations: { |
| 16 | setProxyDevicesData: (state, deviceData) => |
| 17 | (state.proxyDevices = deviceData), |
| 18 | setLegacyDevicesData: (state, deviceData) => |
| 19 | (state.legacyDevices = deviceData) |
| 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', |
| 33 | isActive: false |
| 34 | }; |
| 35 | commit('setProxyDevicesData', [device]); |
| 36 | return; |
| 37 | } |
| 38 | |
| 39 | return await api |
| 40 | .get('/redfish/v1/Managers/bmc/VirtualMedia') |
| 41 | .then(response => |
| 42 | response.data.Members.map(virtualMedia => virtualMedia['@odata.id']) |
| 43 | ) |
| 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, |
| 52 | isActive: isActive |
Mateusz Gapski | 7510046 | 2020-07-30 11:01:29 +0200 | [diff] [blame] | 53 | }; |
| 54 | }); |
| 55 | const proxyDevices = deviceData |
| 56 | .filter(d => d.transferProtocolType === 'OEM') |
| 57 | .map(device => { |
| 58 | return { |
| 59 | ...device, |
Mateusz Gapski | 2224ece | 2020-09-02 17:00:06 +0200 | [diff] [blame] | 60 | file: null |
Mateusz Gapski | 7510046 | 2020-07-30 11:01:29 +0200 | [diff] [blame] | 61 | }; |
| 62 | }); |
| 63 | const legacyDevices = deviceData |
| 64 | .filter(d => !d.transferProtocolType) |
| 65 | .map(device => { |
| 66 | return { |
| 67 | ...device, |
Mateusz Gapski | 2224ece | 2020-09-02 17:00:06 +0200 | [diff] [blame] | 68 | serverUri: '', |
| 69 | username: '', |
| 70 | password: '', |
| 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 | }) |
| 77 | .catch(error => { |
| 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 | ) |
| 87 | .catch(error => { |
| 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 | ) |
| 97 | .catch(error => { |
| 98 | console.log('Unmount image:', error); |
| 99 | throw new Error(); |
| 100 | }); |
Mateusz Gapski | 7510046 | 2020-07-30 11:01:29 +0200 | [diff] [blame] | 101 | } |
| 102 | } |
| 103 | }; |
| 104 | |
| 105 | export default VirtualMediaStore; |