blob: fe2b51f4235fc2e1cb329abb1888c7062ea3a526 [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';
Mateusz Gapski75100462020-07-30 11:01:29 +0200107
108export default {
109 name: 'VirtualMedia',
SurenNeware978807d2020-09-03 18:35:21 +0530110 components: { PageTitle, PageSection, ModalConfigureConnection, FormFile },
Mateusz Gapski75100462020-07-30 11:01:29 +0200111 mixins: [BVToastMixin, LoadingBarMixin],
112 data() {
113 return {
Mateusz Gapski2224ece2020-09-02 17:00:06 +0200114 modalConfigureConnection: null,
Mateusz Gapski75100462020-07-30 11:01:29 +0200115 loadImageFromExternalServer:
Derick Montague602e98a2020-10-21 16:20:00 -0500116 process.env.VUE_APP_VIRTUAL_MEDIA_LIST_ENABLED === 'true'
117 ? true
118 : false,
Mateusz Gapski75100462020-07-30 11:01:29 +0200119 };
120 },
121 computed: {
122 proxyDevices() {
123 return this.$store.getters['virtualMedia/proxyDevices'];
124 },
125 legacyDevices() {
126 return this.$store.getters['virtualMedia/legacyDevices'];
Derick Montague602e98a2020-10-21 16:20:00 -0500127 },
Mateusz Gapski75100462020-07-30 11:01:29 +0200128 },
129 created() {
130 if (this.proxyDevices.length > 0 || this.legacyDevices.length > 0) return;
131 this.startLoader();
132 this.$store
133 .dispatch('virtualMedia/getData')
134 .finally(() => this.endLoader());
135 },
136 methods: {
137 startVM(device) {
138 const token = this.$store.getters['authentication/token'];
139 device.nbd = new NbdServer(
140 `wss://${window.location.host}${device.websocket}`,
141 device.file,
142 device.id,
143 token
144 );
145 device.nbd.socketStarted = () =>
146 this.successToast(this.$t('pageVirtualMedia.toast.serverRunning'));
147 device.nbd.errorReadingFile = () =>
148 this.errorToast(this.$t('pageVirtualMedia.toast.errorReadingFile'));
Derick Montague602e98a2020-10-21 16:20:00 -0500149 device.nbd.socketClosed = (code) => {
Mateusz Gapski75100462020-07-30 11:01:29 +0200150 if (code === 1000)
151 this.successToast(
152 this.$t('pageVirtualMedia.toast.serverClosedSuccessfully')
153 );
154 else
155 this.errorToast(
156 this.$t('pageVirtualMedia.toast.serverClosedWithErrors')
157 );
158 device.file = null;
159 device.isActive = false;
160 };
161
162 device.nbd.start();
163 device.isActive = true;
164 },
165 stopVM(device) {
166 device.nbd.stop();
167 },
Mateusz Gapski2224ece2020-09-02 17:00:06 +0200168 startLegacy(connectionData) {
169 var data = {};
170 data.Image = connectionData.serverUri;
171 data.UserName = connectionData.username;
172 data.Password = connectionData.password;
MichalX Szopinskif3022e52021-03-28 19:08:09 +0200173 data.WriteProtected = !connectionData.isRW;
Mateusz Gapski2224ece2020-09-02 17:00:06 +0200174 this.startLoader();
175 this.$store
176 .dispatch('virtualMedia/mountImage', {
177 id: connectionData.id,
Derick Montague602e98a2020-10-21 16:20:00 -0500178 data: data,
Mateusz Gapski2224ece2020-09-02 17:00:06 +0200179 })
180 .then(() => {
181 this.successToast(
182 this.$t('pageVirtualMedia.toast.serverClosedSuccessfully')
183 );
184 connectionData.isActive = true;
185 })
186 .catch(() => {
187 this.errorToast(this.$t('pageVirtualMedia.toast.errorMounting'));
188 this.isActive = false;
189 })
190 .finally(() => this.endLoader());
Mateusz Gapski75100462020-07-30 11:01:29 +0200191 },
Mateusz Gapski2224ece2020-09-02 17:00:06 +0200192 stopLegacy(connectionData) {
193 this.$store
194 .dispatch('virtualMedia/unmountImage', connectionData.id)
195 .then(() => {
196 this.successToast(
197 this.$t('pageVirtualMedia.toast.serverClosedSuccessfully')
198 );
199 connectionData.isActive = false;
200 })
201 .catch(() =>
202 this.errorToast(this.$t('pageVirtualMedia.toast.errorUnmounting'))
203 )
204 .finally(() => this.endLoader());
205 },
206 saveConnection(connectionData) {
207 this.modalConfigureConnection.serverUri = connectionData.serverUri;
208 this.modalConfigureConnection.username = connectionData.username;
209 this.modalConfigureConnection.password = connectionData.password;
210 this.modalConfigureConnection.isRW = connectionData.isRW;
211 },
212 configureConnection(connectionData) {
213 this.modalConfigureConnection = connectionData;
214 this.$bvModal.show('configure-connection');
Derick Montague602e98a2020-10-21 16:20:00 -0500215 },
SurenNeware978807d2020-09-03 18:35:21 +0530216 concatId(val) {
217 return val.split(' ').join('_').toLowerCase();
218 },
Derick Montague602e98a2020-10-21 16:20:00 -0500219 },
Mateusz Gapski75100462020-07-30 11:01:29 +0200220};
221</script>