blob: e1580597925357b44efbca308f3f1529c5f76010 [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"
72 class="float-right"
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"
81 class="float-right"
82 @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
93 :connection="modalConfigureConnection"
94 @ok="saveConnection"
95 />
Mateusz Gapski75100462020-07-30 11:01:29 +020096 </b-container>
97</template>
98
99<script>
100import PageTitle from '@/components/Global/PageTitle';
101import PageSection from '@/components/Global/PageSection';
102import BVToastMixin from '@/components/Mixins/BVToastMixin';
103import LoadingBarMixin from '@/components/Mixins/LoadingBarMixin';
Mateusz Gapski2224ece2020-09-02 17:00:06 +0200104import ModalConfigureConnection from './ModalConfigureConnection';
Mateusz Gapski75100462020-07-30 11:01:29 +0200105import NbdServer from '@/utilities/NBDServer';
SurenNeware978807d2020-09-03 18:35:21 +0530106import FormFile from '@/components/Global/FormFile';
Surya Vde23ea22024-07-11 15:19:46 +0530107import { useI18n } from 'vue-i18n';
108import i18n from '@/i18n';
Mateusz Gapski75100462020-07-30 11:01:29 +0200109
110export default {
111 name: 'VirtualMedia',
SurenNeware978807d2020-09-03 18:35:21 +0530112 components: { PageTitle, PageSection, ModalConfigureConnection, FormFile },
Mateusz Gapski75100462020-07-30 11:01:29 +0200113 mixins: [BVToastMixin, LoadingBarMixin],
114 data() {
115 return {
Surya Vde23ea22024-07-11 15:19:46 +0530116 $t: useI18n().t,
Mateusz Gapski2224ece2020-09-02 17:00:06 +0200117 modalConfigureConnection: null,
Mateusz Gapski75100462020-07-30 11:01:29 +0200118 loadImageFromExternalServer:
Derick Montague602e98a2020-10-21 16:20:00 -0500119 process.env.VUE_APP_VIRTUAL_MEDIA_LIST_ENABLED === 'true'
120 ? true
121 : false,
Mateusz Gapski75100462020-07-30 11:01:29 +0200122 };
123 },
124 computed: {
125 proxyDevices() {
126 return this.$store.getters['virtualMedia/proxyDevices'];
127 },
128 legacyDevices() {
129 return this.$store.getters['virtualMedia/legacyDevices'];
Derick Montague602e98a2020-10-21 16:20:00 -0500130 },
Mateusz Gapski75100462020-07-30 11:01:29 +0200131 },
132 created() {
kirankumarb07e78d10b2023-03-03 12:10:29 +0530133 this.$store.dispatch('global/getSystemInfo');
Mateusz Gapski75100462020-07-30 11:01:29 +0200134 if (this.proxyDevices.length > 0 || this.legacyDevices.length > 0) return;
135 this.startLoader();
136 this.$store
137 .dispatch('virtualMedia/getData')
138 .finally(() => this.endLoader());
139 },
140 methods: {
141 startVM(device) {
142 const token = this.$store.getters['authentication/token'];
143 device.nbd = new NbdServer(
144 `wss://${window.location.host}${device.websocket}`,
145 device.file,
146 device.id,
Ed Tanous81323992024-02-27 11:26:24 -0800147 token,
Mateusz Gapski75100462020-07-30 11:01:29 +0200148 );
149 device.nbd.socketStarted = () =>
Surya Vde23ea22024-07-11 15:19:46 +0530150 this.successToast(
151 i18n.global.t('pageVirtualMedia.toast.serverRunning'),
152 );
Mateusz Gapski75100462020-07-30 11:01:29 +0200153 device.nbd.errorReadingFile = () =>
Surya Vde23ea22024-07-11 15:19:46 +0530154 this.errorToast(
155 i18n.global.t('pageVirtualMedia.toast.errorReadingFile'),
156 );
Derick Montague602e98a2020-10-21 16:20:00 -0500157 device.nbd.socketClosed = (code) => {
Mateusz Gapski75100462020-07-30 11:01:29 +0200158 if (code === 1000)
159 this.successToast(
Surya Vde23ea22024-07-11 15:19:46 +0530160 i18n.global.t('pageVirtualMedia.toast.serverClosedSuccessfully'),
Mateusz Gapski75100462020-07-30 11:01:29 +0200161 );
162 else
163 this.errorToast(
Surya Vde23ea22024-07-11 15:19:46 +0530164 i18n.global.t('pageVirtualMedia.toast.serverClosedWithErrors'),
Mateusz Gapski75100462020-07-30 11:01:29 +0200165 );
166 device.file = null;
167 device.isActive = false;
168 };
169
170 device.nbd.start();
171 device.isActive = true;
172 },
173 stopVM(device) {
174 device.nbd.stop();
175 },
Mateusz Gapski2224ece2020-09-02 17:00:06 +0200176 startLegacy(connectionData) {
177 var data = {};
178 data.Image = connectionData.serverUri;
179 data.UserName = connectionData.username;
180 data.Password = connectionData.password;
MichalX Szopinskif3022e52021-03-28 19:08:09 +0200181 data.WriteProtected = !connectionData.isRW;
Mateusz Gapski2224ece2020-09-02 17:00:06 +0200182 this.startLoader();
183 this.$store
184 .dispatch('virtualMedia/mountImage', {
185 id: connectionData.id,
Derick Montague602e98a2020-10-21 16:20:00 -0500186 data: data,
Mateusz Gapski2224ece2020-09-02 17:00:06 +0200187 })
188 .then(() => {
189 this.successToast(
Surya Vde23ea22024-07-11 15:19:46 +0530190 i18n.global.t('pageVirtualMedia.toast.serverConnectionEstablished'),
Mateusz Gapski2224ece2020-09-02 17:00:06 +0200191 );
192 connectionData.isActive = true;
193 })
194 .catch(() => {
Surya Vde23ea22024-07-11 15:19:46 +0530195 this.errorToast(
196 i18n.global.t('pageVirtualMedia.toast.errorMounting'),
197 );
Mateusz Gapski2224ece2020-09-02 17:00:06 +0200198 this.isActive = false;
199 })
200 .finally(() => this.endLoader());
Mateusz Gapski75100462020-07-30 11:01:29 +0200201 },
Mateusz Gapski2224ece2020-09-02 17:00:06 +0200202 stopLegacy(connectionData) {
203 this.$store
204 .dispatch('virtualMedia/unmountImage', connectionData.id)
205 .then(() => {
206 this.successToast(
Surya Vde23ea22024-07-11 15:19:46 +0530207 i18n.global.t('pageVirtualMedia.toast.serverClosedSuccessfully'),
Mateusz Gapski2224ece2020-09-02 17:00:06 +0200208 );
209 connectionData.isActive = false;
210 })
211 .catch(() =>
Surya Vde23ea22024-07-11 15:19:46 +0530212 this.errorToast(
213 i18n.global.t('pageVirtualMedia.toast.errorUnmounting'),
214 ),
Mateusz Gapski2224ece2020-09-02 17:00:06 +0200215 )
216 .finally(() => this.endLoader());
217 },
218 saveConnection(connectionData) {
219 this.modalConfigureConnection.serverUri = connectionData.serverUri;
220 this.modalConfigureConnection.username = connectionData.username;
221 this.modalConfigureConnection.password = connectionData.password;
222 this.modalConfigureConnection.isRW = connectionData.isRW;
223 },
224 configureConnection(connectionData) {
225 this.modalConfigureConnection = connectionData;
226 this.$bvModal.show('configure-connection');
Derick Montague602e98a2020-10-21 16:20:00 -0500227 },
SurenNeware978807d2020-09-03 18:35:21 +0530228 concatId(val) {
229 return val.split(' ').join('_').toLowerCase();
230 },
Derick Montague602e98a2020-10-21 16:20:00 -0500231 },
Mateusz Gapski75100462020-07-30 11:01:29 +0200232};
233</script>