blob: 8264c5a2a49862d0adc17edd867963563ddaf8f4 [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">
19 <template>
20 {{ $t('global.form.required') }}
21 </template>
22 </b-form-invalid-feedback>
23 </template>
24 </form-file>
Mateusz Gapski75100462020-07-30 11:01:29 +020025 </b-form-group>
26 <b-button
27 v-if="!dev.isActive"
28 variant="primary"
29 :disabled="!dev.file"
30 @click="startVM(dev)"
31 >
Mateusz Gapski2224ece2020-09-02 17:00:06 +020032 {{ $t('pageVirtualMedia.start') }}
Mateusz Gapski75100462020-07-30 11:01:29 +020033 </b-button>
34 <b-button
35 v-if="dev.isActive"
36 variant="primary"
37 :disabled="!dev.file"
38 @click="stopVM(dev)"
39 >
Mateusz Gapski2224ece2020-09-02 17:00:06 +020040 {{ $t('pageVirtualMedia.stop') }}
Mateusz Gapski75100462020-07-30 11:01:29 +020041 </b-button>
42 </b-col>
43 </b-row>
44 </page-section>
45 </b-col>
46 </b-row>
47 <b-row v-if="loadImageFromExternalServer" class="mb-4">
48 <b-col md="12">
49 <page-section
50 :section-title="$t('pageVirtualMedia.virtualMediaSubTitleSecond')"
51 >
52 <b-row>
53 <b-col
54 v-for="(device, $index) in legacyDevices"
55 :key="$index"
56 md="6"
57 >
58 <b-form-group
59 :label="device.id"
60 :label-for="device.id"
61 label-class="bold"
62 >
Mateusz Gapski2224ece2020-09-02 17:00:06 +020063 <b-button
64 variant="primary"
65 :disabled="device.isActive"
66 @click="configureConnection(device)"
67 >
Mateusz Gapski75100462020-07-30 11:01:29 +020068 {{ $t('pageVirtualMedia.configureConnection') }}
69 </b-button>
70
71 <b-button
Mateusz Gapski2224ece2020-09-02 17:00:06 +020072 v-if="!device.isActive"
Mateusz Gapski75100462020-07-30 11:01:29 +020073 variant="primary"
74 class="float-right"
Mateusz Gapski2224ece2020-09-02 17:00:06 +020075 :disabled="!device.serverUri"
Mateusz Gapski75100462020-07-30 11:01:29 +020076 @click="startLegacy(device)"
77 >
Mateusz Gapski2224ece2020-09-02 17:00:06 +020078 {{ $t('pageVirtualMedia.start') }}
79 </b-button>
80 <b-button
81 v-if="device.isActive"
82 variant="primary"
83 class="float-right"
84 @click="stopLegacy(device)"
85 >
86 {{ $t('pageVirtualMedia.stop') }}
Mateusz Gapski75100462020-07-30 11:01:29 +020087 </b-button>
88 </b-form-group>
89 </b-col>
90 </b-row>
91 </page-section>
92 </b-col>
93 </b-row>
Mateusz Gapski2224ece2020-09-02 17:00:06 +020094 <modal-configure-connection
95 :connection="modalConfigureConnection"
96 @ok="saveConnection"
97 />
Mateusz Gapski75100462020-07-30 11:01:29 +020098 </b-container>
99</template>
100
101<script>
102import PageTitle from '@/components/Global/PageTitle';
103import PageSection from '@/components/Global/PageSection';
104import BVToastMixin from '@/components/Mixins/BVToastMixin';
105import LoadingBarMixin from '@/components/Mixins/LoadingBarMixin';
Mateusz Gapski2224ece2020-09-02 17:00:06 +0200106import ModalConfigureConnection from './ModalConfigureConnection';
Mateusz Gapski75100462020-07-30 11:01:29 +0200107import NbdServer from '@/utilities/NBDServer';
SurenNeware978807d2020-09-03 18:35:21 +0530108import FormFile from '@/components/Global/FormFile';
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 {
Mateusz Gapski2224ece2020-09-02 17:00:06 +0200116 modalConfigureConnection: null,
Mateusz Gapski75100462020-07-30 11:01:29 +0200117 loadImageFromExternalServer:
Derick Montague602e98a2020-10-21 16:20:00 -0500118 process.env.VUE_APP_VIRTUAL_MEDIA_LIST_ENABLED === 'true'
119 ? true
120 : false,
Mateusz Gapski75100462020-07-30 11:01:29 +0200121 };
122 },
123 computed: {
124 proxyDevices() {
125 return this.$store.getters['virtualMedia/proxyDevices'];
126 },
127 legacyDevices() {
128 return this.$store.getters['virtualMedia/legacyDevices'];
Derick Montague602e98a2020-10-21 16:20:00 -0500129 },
Mateusz Gapski75100462020-07-30 11:01:29 +0200130 },
131 created() {
132 if (this.proxyDevices.length > 0 || this.legacyDevices.length > 0) return;
133 this.startLoader();
134 this.$store
135 .dispatch('virtualMedia/getData')
136 .finally(() => this.endLoader());
137 },
138 methods: {
139 startVM(device) {
140 const token = this.$store.getters['authentication/token'];
141 device.nbd = new NbdServer(
142 `wss://${window.location.host}${device.websocket}`,
143 device.file,
144 device.id,
145 token
146 );
147 device.nbd.socketStarted = () =>
148 this.successToast(this.$t('pageVirtualMedia.toast.serverRunning'));
149 device.nbd.errorReadingFile = () =>
150 this.errorToast(this.$t('pageVirtualMedia.toast.errorReadingFile'));
Derick Montague602e98a2020-10-21 16:20:00 -0500151 device.nbd.socketClosed = (code) => {
Mateusz Gapski75100462020-07-30 11:01:29 +0200152 if (code === 1000)
153 this.successToast(
154 this.$t('pageVirtualMedia.toast.serverClosedSuccessfully')
155 );
156 else
157 this.errorToast(
158 this.$t('pageVirtualMedia.toast.serverClosedWithErrors')
159 );
160 device.file = null;
161 device.isActive = false;
162 };
163
164 device.nbd.start();
165 device.isActive = true;
166 },
167 stopVM(device) {
168 device.nbd.stop();
169 },
Mateusz Gapski2224ece2020-09-02 17:00:06 +0200170 startLegacy(connectionData) {
171 var data = {};
172 data.Image = connectionData.serverUri;
173 data.UserName = connectionData.username;
174 data.Password = connectionData.password;
175 data.WriteProtected = connectionData.isRW;
176 this.startLoader();
177 this.$store
178 .dispatch('virtualMedia/mountImage', {
179 id: connectionData.id,
Derick Montague602e98a2020-10-21 16:20:00 -0500180 data: data,
Mateusz Gapski2224ece2020-09-02 17:00:06 +0200181 })
182 .then(() => {
183 this.successToast(
184 this.$t('pageVirtualMedia.toast.serverClosedSuccessfully')
185 );
186 connectionData.isActive = true;
187 })
188 .catch(() => {
189 this.errorToast(this.$t('pageVirtualMedia.toast.errorMounting'));
190 this.isActive = false;
191 })
192 .finally(() => this.endLoader());
Mateusz Gapski75100462020-07-30 11:01:29 +0200193 },
Mateusz Gapski2224ece2020-09-02 17:00:06 +0200194 stopLegacy(connectionData) {
195 this.$store
196 .dispatch('virtualMedia/unmountImage', connectionData.id)
197 .then(() => {
198 this.successToast(
199 this.$t('pageVirtualMedia.toast.serverClosedSuccessfully')
200 );
201 connectionData.isActive = false;
202 })
203 .catch(() =>
204 this.errorToast(this.$t('pageVirtualMedia.toast.errorUnmounting'))
205 )
206 .finally(() => this.endLoader());
207 },
208 saveConnection(connectionData) {
209 this.modalConfigureConnection.serverUri = connectionData.serverUri;
210 this.modalConfigureConnection.username = connectionData.username;
211 this.modalConfigureConnection.password = connectionData.password;
212 this.modalConfigureConnection.isRW = connectionData.isRW;
213 },
214 configureConnection(connectionData) {
215 this.modalConfigureConnection = connectionData;
216 this.$bvModal.show('configure-connection');
Derick Montague602e98a2020-10-21 16:20:00 -0500217 },
SurenNeware978807d2020-09-03 18:35:21 +0530218 concatId(val) {
219 return val.split(' ').join('_').toLowerCase();
220 },
Derick Montague602e98a2020-10-21 16:20:00 -0500221 },
Mateusz Gapski75100462020-07-30 11:01:29 +0200222};
223</script>