blob: a15f2cd9668e61a88fa84e6479bce0c6f2240db4 [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">
11 <b-form-group
12 :label="dev.id"
13 :label-for="dev.id"
14 label-class="bold"
15 >
16 <b-form-file
17 v-show="!dev.isActive"
18 :id="dev.id"
19 v-model="dev.file"
20 />
21 <p v-if="dev.isActive">{{ dev.file.name }}</p>
22 </b-form-group>
23 <b-button
24 v-if="!dev.isActive"
25 variant="primary"
26 :disabled="!dev.file"
27 @click="startVM(dev)"
28 >
Mateusz Gapski2224ece2020-09-02 17:00:06 +020029 {{ $t('pageVirtualMedia.start') }}
Mateusz Gapski75100462020-07-30 11:01:29 +020030 </b-button>
31 <b-button
32 v-if="dev.isActive"
33 variant="primary"
34 :disabled="!dev.file"
35 @click="stopVM(dev)"
36 >
Mateusz Gapski2224ece2020-09-02 17:00:06 +020037 {{ $t('pageVirtualMedia.stop') }}
Mateusz Gapski75100462020-07-30 11:01:29 +020038 </b-button>
39 </b-col>
40 </b-row>
41 </page-section>
42 </b-col>
43 </b-row>
44 <b-row v-if="loadImageFromExternalServer" class="mb-4">
45 <b-col md="12">
46 <page-section
47 :section-title="$t('pageVirtualMedia.virtualMediaSubTitleSecond')"
48 >
49 <b-row>
50 <b-col
51 v-for="(device, $index) in legacyDevices"
52 :key="$index"
53 md="6"
54 >
55 <b-form-group
56 :label="device.id"
57 :label-for="device.id"
58 label-class="bold"
59 >
Mateusz Gapski2224ece2020-09-02 17:00:06 +020060 <b-button
61 variant="primary"
62 :disabled="device.isActive"
63 @click="configureConnection(device)"
64 >
Mateusz Gapski75100462020-07-30 11:01:29 +020065 {{ $t('pageVirtualMedia.configureConnection') }}
66 </b-button>
67
68 <b-button
Mateusz Gapski2224ece2020-09-02 17:00:06 +020069 v-if="!device.isActive"
Mateusz Gapski75100462020-07-30 11:01:29 +020070 variant="primary"
71 class="float-right"
Mateusz Gapski2224ece2020-09-02 17:00:06 +020072 :disabled="!device.serverUri"
Mateusz Gapski75100462020-07-30 11:01:29 +020073 @click="startLegacy(device)"
74 >
Mateusz Gapski2224ece2020-09-02 17:00:06 +020075 {{ $t('pageVirtualMedia.start') }}
76 </b-button>
77 <b-button
78 v-if="device.isActive"
79 variant="primary"
80 class="float-right"
81 @click="stopLegacy(device)"
82 >
83 {{ $t('pageVirtualMedia.stop') }}
Mateusz Gapski75100462020-07-30 11:01:29 +020084 </b-button>
85 </b-form-group>
86 </b-col>
87 </b-row>
88 </page-section>
89 </b-col>
90 </b-row>
Mateusz Gapski2224ece2020-09-02 17:00:06 +020091 <modal-configure-connection
92 :connection="modalConfigureConnection"
93 @ok="saveConnection"
94 />
Mateusz Gapski75100462020-07-30 11:01:29 +020095 </b-container>
96</template>
97
98<script>
99import PageTitle from '@/components/Global/PageTitle';
100import PageSection from '@/components/Global/PageSection';
101import BVToastMixin from '@/components/Mixins/BVToastMixin';
102import LoadingBarMixin from '@/components/Mixins/LoadingBarMixin';
Mateusz Gapski2224ece2020-09-02 17:00:06 +0200103import ModalConfigureConnection from './ModalConfigureConnection';
Mateusz Gapski75100462020-07-30 11:01:29 +0200104import NbdServer from '@/utilities/NBDServer';
105
106export default {
107 name: 'VirtualMedia',
Mateusz Gapski2224ece2020-09-02 17:00:06 +0200108 components: { PageTitle, PageSection, ModalConfigureConnection },
Mateusz Gapski75100462020-07-30 11:01:29 +0200109 mixins: [BVToastMixin, LoadingBarMixin],
110 data() {
111 return {
Mateusz Gapski2224ece2020-09-02 17:00:06 +0200112 modalConfigureConnection: null,
Mateusz Gapski75100462020-07-30 11:01:29 +0200113 loadImageFromExternalServer:
Derick Montague602e98a2020-10-21 16:20:00 -0500114 process.env.VUE_APP_VIRTUAL_MEDIA_LIST_ENABLED === 'true'
115 ? true
116 : false,
Mateusz Gapski75100462020-07-30 11:01:29 +0200117 };
118 },
119 computed: {
120 proxyDevices() {
121 return this.$store.getters['virtualMedia/proxyDevices'];
122 },
123 legacyDevices() {
124 return this.$store.getters['virtualMedia/legacyDevices'];
Derick Montague602e98a2020-10-21 16:20:00 -0500125 },
Mateusz Gapski75100462020-07-30 11:01:29 +0200126 },
127 created() {
128 if (this.proxyDevices.length > 0 || this.legacyDevices.length > 0) return;
129 this.startLoader();
130 this.$store
131 .dispatch('virtualMedia/getData')
132 .finally(() => this.endLoader());
133 },
134 methods: {
135 startVM(device) {
136 const token = this.$store.getters['authentication/token'];
137 device.nbd = new NbdServer(
138 `wss://${window.location.host}${device.websocket}`,
139 device.file,
140 device.id,
141 token
142 );
143 device.nbd.socketStarted = () =>
144 this.successToast(this.$t('pageVirtualMedia.toast.serverRunning'));
145 device.nbd.errorReadingFile = () =>
146 this.errorToast(this.$t('pageVirtualMedia.toast.errorReadingFile'));
Derick Montague602e98a2020-10-21 16:20:00 -0500147 device.nbd.socketClosed = (code) => {
Mateusz Gapski75100462020-07-30 11:01:29 +0200148 if (code === 1000)
149 this.successToast(
150 this.$t('pageVirtualMedia.toast.serverClosedSuccessfully')
151 );
152 else
153 this.errorToast(
154 this.$t('pageVirtualMedia.toast.serverClosedWithErrors')
155 );
156 device.file = null;
157 device.isActive = false;
158 };
159
160 device.nbd.start();
161 device.isActive = true;
162 },
163 stopVM(device) {
164 device.nbd.stop();
165 },
Mateusz Gapski2224ece2020-09-02 17:00:06 +0200166 startLegacy(connectionData) {
167 var data = {};
168 data.Image = connectionData.serverUri;
169 data.UserName = connectionData.username;
170 data.Password = connectionData.password;
171 data.WriteProtected = connectionData.isRW;
172 this.startLoader();
173 this.$store
174 .dispatch('virtualMedia/mountImage', {
175 id: connectionData.id,
Derick Montague602e98a2020-10-21 16:20:00 -0500176 data: data,
Mateusz Gapski2224ece2020-09-02 17:00:06 +0200177 })
178 .then(() => {
179 this.successToast(
180 this.$t('pageVirtualMedia.toast.serverClosedSuccessfully')
181 );
182 connectionData.isActive = true;
183 })
184 .catch(() => {
185 this.errorToast(this.$t('pageVirtualMedia.toast.errorMounting'));
186 this.isActive = false;
187 })
188 .finally(() => this.endLoader());
Mateusz Gapski75100462020-07-30 11:01:29 +0200189 },
Mateusz Gapski2224ece2020-09-02 17:00:06 +0200190 stopLegacy(connectionData) {
191 this.$store
192 .dispatch('virtualMedia/unmountImage', connectionData.id)
193 .then(() => {
194 this.successToast(
195 this.$t('pageVirtualMedia.toast.serverClosedSuccessfully')
196 );
197 connectionData.isActive = false;
198 })
199 .catch(() =>
200 this.errorToast(this.$t('pageVirtualMedia.toast.errorUnmounting'))
201 )
202 .finally(() => this.endLoader());
203 },
204 saveConnection(connectionData) {
205 this.modalConfigureConnection.serverUri = connectionData.serverUri;
206 this.modalConfigureConnection.username = connectionData.username;
207 this.modalConfigureConnection.password = connectionData.password;
208 this.modalConfigureConnection.isRW = connectionData.isRW;
209 },
210 configureConnection(connectionData) {
211 this.modalConfigureConnection = connectionData;
212 this.$bvModal.show('configure-connection');
Derick Montague602e98a2020-10-21 16:20:00 -0500213 },
214 },
Mateusz Gapski75100462020-07-30 11:01:29 +0200215};
216</script>