blob: 36fb909d7291914f477f4765076f0e1bf6149f21 [file] [log] [blame]
Mateusz Gapski75100462020-07-30 11:01:29 +02001<template>
2 <b-container fluid="xl">
3 <page-title />
4 <b-row class="mb-4">
5 <b-col md="12">
6 <page-section
7 :section-title="$t('pageVirtualMedia.virtualMediaSubTitleFirst')"
8 >
9 <b-row>
10 <b-col v-for="(dev, $index) in proxyDevices" :key="$index" md="6">
SurenNeware978807d2020-09-03 18:35:21 +053011 <b-form-group :label="dev.id" label-class="bold">
12 <form-file
13 v-if="!dev.isActive"
14 :id="concatId(dev.id)"
Mateusz Gapski75100462020-07-30 11:01:29 +020015 v-model="dev.file"
SurenNeware978807d2020-09-03 18:35:21 +053016 >
17 <template #invalid>
18 <b-form-invalid-feedback role="alert">
Derick Montagued1ff01e2021-01-04 11:56:23 -060019 {{ $t('global.form.required') }}
SurenNeware978807d2020-09-03 18:35:21 +053020 </b-form-invalid-feedback>
21 </template>
22 </form-file>
Mateusz Gapski75100462020-07-30 11:01:29 +020023 </b-form-group>
24 <b-button
25 v-if="!dev.isActive"
26 variant="primary"
27 :disabled="!dev.file"
28 @click="startVM(dev)"
29 >
Mateusz Gapski2224ece2020-09-02 17:00:06 +020030 {{ $t('pageVirtualMedia.start') }}
Mateusz Gapski75100462020-07-30 11:01:29 +020031 </b-button>
32 <b-button
33 v-if="dev.isActive"
34 variant="primary"
35 :disabled="!dev.file"
36 @click="stopVM(dev)"
37 >
Mateusz Gapski2224ece2020-09-02 17:00:06 +020038 {{ $t('pageVirtualMedia.stop') }}
Mateusz Gapski75100462020-07-30 11:01:29 +020039 </b-button>
40 </b-col>
41 </b-row>
42 </page-section>
43 </b-col>
44 </b-row>
45 <b-row v-if="loadImageFromExternalServer" class="mb-4">
46 <b-col md="12">
47 <page-section
48 :section-title="$t('pageVirtualMedia.virtualMediaSubTitleSecond')"
49 >
50 <b-row>
51 <b-col
52 v-for="(device, $index) in legacyDevices"
53 :key="$index"
54 md="6"
55 >
56 <b-form-group
57 :label="device.id"
58 :label-for="device.id"
59 label-class="bold"
60 >
Mateusz Gapski2224ece2020-09-02 17:00:06 +020061 <b-button
62 variant="primary"
63 :disabled="device.isActive"
64 @click="configureConnection(device)"
65 >
Mateusz Gapski75100462020-07-30 11:01:29 +020066 {{ $t('pageVirtualMedia.configureConnection') }}
67 </b-button>
68
69 <b-button
Mateusz Gapski2224ece2020-09-02 17:00:06 +020070 v-if="!device.isActive"
Mateusz Gapski75100462020-07-30 11:01:29 +020071 variant="primary"
jason westoverd36ac8a2025-11-03 20:58:59 -060072 class="float-end"
Mateusz Gapski2224ece2020-09-02 17:00:06 +020073 :disabled="!device.serverUri"
Mateusz Gapski75100462020-07-30 11:01:29 +020074 @click="startLegacy(device)"
75 >
Mateusz Gapski2224ece2020-09-02 17:00:06 +020076 {{ $t('pageVirtualMedia.start') }}
77 </b-button>
78 <b-button
79 v-if="device.isActive"
80 variant="primary"
jason westoverd36ac8a2025-11-03 20:58:59 -060081 class="float-end"
Mateusz Gapski2224ece2020-09-02 17:00:06 +020082 @click="stopLegacy(device)"
83 >
84 {{ $t('pageVirtualMedia.stop') }}
Mateusz Gapski75100462020-07-30 11:01:29 +020085 </b-button>
86 </b-form-group>
87 </b-col>
88 </b-row>
89 </page-section>
90 </b-col>
91 </b-row>
Mateusz Gapski2224ece2020-09-02 17:00:06 +020092 <modal-configure-connection
jason westoverd36ac8a2025-11-03 20:58:59 -060093 v-model="showConfigureConnectionModal"
Mateusz Gapski2224ece2020-09-02 17:00:06 +020094 :connection="modalConfigureConnection"
95 @ok="saveConnection"
96 />
Mateusz Gapski75100462020-07-30 11:01:29 +020097 </b-container>
98</template>
99
100<script>
101import PageTitle from '@/components/Global/PageTitle';
102import PageSection from '@/components/Global/PageSection';
103import BVToastMixin from '@/components/Mixins/BVToastMixin';
104import LoadingBarMixin from '@/components/Mixins/LoadingBarMixin';
Mateusz Gapski2224ece2020-09-02 17:00:06 +0200105import ModalConfigureConnection from './ModalConfigureConnection';
Mateusz Gapski75100462020-07-30 11:01:29 +0200106import NbdServer from '@/utilities/NBDServer';
SurenNeware978807d2020-09-03 18:35:21 +0530107import FormFile from '@/components/Global/FormFile';
Surya Vde23ea22024-07-11 15:19:46 +0530108import { useI18n } from 'vue-i18n';
109import i18n from '@/i18n';
jason westoverd36ac8a2025-11-03 20:58:59 -0600110import { useModal } from 'bootstrap-vue-next';
Mateusz Gapski75100462020-07-30 11:01:29 +0200111
112export default {
113 name: 'VirtualMedia',
SurenNeware978807d2020-09-03 18:35:21 +0530114 components: { PageTitle, PageSection, ModalConfigureConnection, FormFile },
Mateusz Gapski75100462020-07-30 11:01:29 +0200115 mixins: [BVToastMixin, LoadingBarMixin],
jason westoverd36ac8a2025-11-03 20:58:59 -0600116 setup() {
117 const bvModal = useModal();
118 return { bvModal };
119 },
Mateusz Gapski75100462020-07-30 11:01:29 +0200120 data() {
121 return {
Surya Vde23ea22024-07-11 15:19:46 +0530122 $t: useI18n().t,
Mateusz Gapski2224ece2020-09-02 17:00:06 +0200123 modalConfigureConnection: null,
jason westoverd36ac8a2025-11-03 20:58:59 -0600124 showConfigureConnectionModal: false,
Mateusz Gapski75100462020-07-30 11:01:29 +0200125 loadImageFromExternalServer:
Derick Montague602e98a2020-10-21 16:20:00 -0500126 process.env.VUE_APP_VIRTUAL_MEDIA_LIST_ENABLED === 'true'
127 ? true
128 : false,
Mateusz Gapski75100462020-07-30 11:01:29 +0200129 };
130 },
131 computed: {
132 proxyDevices() {
133 return this.$store.getters['virtualMedia/proxyDevices'];
134 },
135 legacyDevices() {
136 return this.$store.getters['virtualMedia/legacyDevices'];
Derick Montague602e98a2020-10-21 16:20:00 -0500137 },
Mateusz Gapski75100462020-07-30 11:01:29 +0200138 },
139 created() {
kirankumarb07e78d10b2023-03-03 12:10:29 +0530140 this.$store.dispatch('global/getSystemInfo');
Mateusz Gapski75100462020-07-30 11:01:29 +0200141 if (this.proxyDevices.length > 0 || this.legacyDevices.length > 0) return;
142 this.startLoader();
143 this.$store
144 .dispatch('virtualMedia/getData')
145 .finally(() => this.endLoader());
146 },
147 methods: {
148 startVM(device) {
149 const token = this.$store.getters['authentication/token'];
150 device.nbd = new NbdServer(
151 `wss://${window.location.host}${device.websocket}`,
152 device.file,
153 device.id,
Ed Tanous81323992024-02-27 11:26:24 -0800154 token,
Mateusz Gapski75100462020-07-30 11:01:29 +0200155 );
156 device.nbd.socketStarted = () =>
Surya Vde23ea22024-07-11 15:19:46 +0530157 this.successToast(
158 i18n.global.t('pageVirtualMedia.toast.serverRunning'),
159 );
Mateusz Gapski75100462020-07-30 11:01:29 +0200160 device.nbd.errorReadingFile = () =>
Surya Vde23ea22024-07-11 15:19:46 +0530161 this.errorToast(
162 i18n.global.t('pageVirtualMedia.toast.errorReadingFile'),
163 );
Derick Montague602e98a2020-10-21 16:20:00 -0500164 device.nbd.socketClosed = (code) => {
Mateusz Gapski75100462020-07-30 11:01:29 +0200165 if (code === 1000)
166 this.successToast(
Surya Vde23ea22024-07-11 15:19:46 +0530167 i18n.global.t('pageVirtualMedia.toast.serverClosedSuccessfully'),
Mateusz Gapski75100462020-07-30 11:01:29 +0200168 );
169 else
170 this.errorToast(
Surya Vde23ea22024-07-11 15:19:46 +0530171 i18n.global.t('pageVirtualMedia.toast.serverClosedWithErrors'),
Mateusz Gapski75100462020-07-30 11:01:29 +0200172 );
173 device.file = null;
174 device.isActive = false;
175 };
176
177 device.nbd.start();
178 device.isActive = true;
179 },
180 stopVM(device) {
181 device.nbd.stop();
182 },
Mateusz Gapski2224ece2020-09-02 17:00:06 +0200183 startLegacy(connectionData) {
184 var data = {};
185 data.Image = connectionData.serverUri;
186 data.UserName = connectionData.username;
187 data.Password = connectionData.password;
MichalX Szopinskif3022e52021-03-28 19:08:09 +0200188 data.WriteProtected = !connectionData.isRW;
Mateusz Gapski2224ece2020-09-02 17:00:06 +0200189 this.startLoader();
190 this.$store
191 .dispatch('virtualMedia/mountImage', {
192 id: connectionData.id,
Derick Montague602e98a2020-10-21 16:20:00 -0500193 data: data,
Mateusz Gapski2224ece2020-09-02 17:00:06 +0200194 })
195 .then(() => {
196 this.successToast(
Surya Vde23ea22024-07-11 15:19:46 +0530197 i18n.global.t('pageVirtualMedia.toast.serverConnectionEstablished'),
Mateusz Gapski2224ece2020-09-02 17:00:06 +0200198 );
199 connectionData.isActive = true;
200 })
201 .catch(() => {
Surya Vde23ea22024-07-11 15:19:46 +0530202 this.errorToast(
203 i18n.global.t('pageVirtualMedia.toast.errorMounting'),
204 );
Mateusz Gapski2224ece2020-09-02 17:00:06 +0200205 this.isActive = false;
206 })
207 .finally(() => this.endLoader());
Mateusz Gapski75100462020-07-30 11:01:29 +0200208 },
Mateusz Gapski2224ece2020-09-02 17:00:06 +0200209 stopLegacy(connectionData) {
210 this.$store
211 .dispatch('virtualMedia/unmountImage', connectionData.id)
212 .then(() => {
213 this.successToast(
Surya Vde23ea22024-07-11 15:19:46 +0530214 i18n.global.t('pageVirtualMedia.toast.serverClosedSuccessfully'),
Mateusz Gapski2224ece2020-09-02 17:00:06 +0200215 );
216 connectionData.isActive = false;
217 })
218 .catch(() =>
Surya Vde23ea22024-07-11 15:19:46 +0530219 this.errorToast(
220 i18n.global.t('pageVirtualMedia.toast.errorUnmounting'),
221 ),
Mateusz Gapski2224ece2020-09-02 17:00:06 +0200222 )
223 .finally(() => this.endLoader());
224 },
225 saveConnection(connectionData) {
226 this.modalConfigureConnection.serverUri = connectionData.serverUri;
227 this.modalConfigureConnection.username = connectionData.username;
228 this.modalConfigureConnection.password = connectionData.password;
229 this.modalConfigureConnection.isRW = connectionData.isRW;
230 },
231 configureConnection(connectionData) {
232 this.modalConfigureConnection = connectionData;
jason westoverd36ac8a2025-11-03 20:58:59 -0600233 this.showConfigureConnectionModal = true;
Derick Montague602e98a2020-10-21 16:20:00 -0500234 },
SurenNeware978807d2020-09-03 18:35:21 +0530235 concatId(val) {
236 return val.split(' ').join('_').toLowerCase();
237 },
Derick Montague602e98a2020-10-21 16:20:00 -0500238 },
Mateusz Gapski75100462020-07-30 11:01:29 +0200239};
240</script>