blob: 4ea776554836df6a4beffd62ac6cdf25c6272c87 [file] [log] [blame]
Yoshie Muranakafa1512b2020-02-25 15:54:07 -08001<template>
Yoshie Muranaka3111b6f2020-04-21 19:48:38 -07002 <b-container fluid="xl">
Yoshie Muranakafa1512b2020-02-25 15:54:07 -08003 <page-title />
Yoshie Muranakaf7aa7f92020-04-27 10:12:15 -07004 <b-row class="mb-4">
Yoshie Muranakac05ff642020-02-26 14:23:15 -08005 <b-col md="8" xl="6">
Yoshie Muranakafa1512b2020-02-25 15:54:07 -08006 <page-section
7 :section-title="$t('pageServerPowerOperations.currentStatus')"
8 >
Dixsie Wolmersbb316062020-08-04 19:17:33 -05009 <b-row>
10 <b-col>
11 <dl>
12 <dt>{{ $t('pageServerPowerOperations.hostStatus') }}</dt>
SurenNeware84ea7ab2021-02-17 19:06:06 +053013 <dd
14 v-if="hostStatus === 'on'"
15 data-test-id="powerServerOps-text-hostStatus"
16 >
Dixsie Wolmersbb316062020-08-04 19:17:33 -050017 {{ $t('global.status.on') }}
18 </dd>
SurenNeware84ea7ab2021-02-17 19:06:06 +053019 <dd
20 v-else-if="hostStatus === 'off'"
21 data-test-id="powerServerOps-text-hostStatus"
22 >
Dixsie Wolmersbb316062020-08-04 19:17:33 -050023 {{ $t('global.status.off') }}
24 </dd>
25 <dd v-else>
26 {{ $t('global.status.notAvailable') }}
27 </dd>
28 </dl>
29 </b-col>
30 </b-row>
31 <b-row>
32 <b-col>
33 <dl>
34 <dt>
35 {{ $t('pageServerPowerOperations.lastPowerOperation') }}
36 </dt>
SurenNeware84ea7ab2021-02-17 19:06:06 +053037 <dd
38 v-if="lastPowerOperationTime"
39 data-test-id="powerServerOps-text-lastPowerOp"
40 >
Dixsie Wolmersbb316062020-08-04 19:17:33 -050041 {{ lastPowerOperationTime | formatDate }}
42 {{ lastPowerOperationTime | formatTime }}
43 </dd>
44 <dd v-else>--</dd>
45 </dl>
46 </b-col>
47 </b-row>
Yoshie Muranakafa1512b2020-02-25 15:54:07 -080048 </page-section>
49 </b-col>
50 </b-row>
51 <b-row>
Sukanya Pandey7f6edb62021-03-30 19:49:08 +053052 <b-col v-if="hasBootSourceOptions" sm="8" md="6" xl="4">
Yoshie Muranakac05ff642020-02-26 14:23:15 -080053 <page-section
54 :section-title="$t('pageServerPowerOperations.hostOsBootSettings')"
55 >
56 <boot-settings />
57 </page-section>
58 </b-col>
59 <b-col sm="8" md="6" xl="7">
Yoshie Muranakafa1512b2020-02-25 15:54:07 -080060 <page-section
61 :section-title="$t('pageServerPowerOperations.operations')"
62 >
SurenNewaread8438b2020-08-20 18:32:28 +053063 <alert :show="oneTimeBootEnabled" variant="warning">
Yoshie Muranakac05ff642020-02-26 14:23:15 -080064 {{ $t('pageServerPowerOperations.oneTimeBootWarning') }}
SurenNewaread8438b2020-08-20 18:32:28 +053065 </alert>
Yoshie Muranakafa1512b2020-02-25 15:54:07 -080066 <template v-if="isOperationInProgress">
SurenNewaread8438b2020-08-20 18:32:28 +053067 <alert variant="info">
68 {{ $t('pageServerPowerOperations.operationInProgress') }}
69 </alert>
Yoshie Muranakafa1512b2020-02-25 15:54:07 -080070 </template>
71 <template v-else-if="hostStatus === 'off'">
Sukanya Pandey8d29eb42020-07-17 12:42:46 +053072 <b-button
73 variant="primary"
74 data-test-id="serverPowerOperations-button-powerOn"
75 @click="powerOn"
76 >
Yoshie Muranakafa1512b2020-02-25 15:54:07 -080077 {{ $t('pageServerPowerOperations.powerOn') }}
78 </b-button>
79 </template>
Yoshie Muranakae9fc6122020-08-10 15:12:09 -070080 <template v-else>
Yoshie Muranakafa1512b2020-02-25 15:54:07 -080081 <!-- Reboot server options -->
82 <b-form novalidate class="mb-5" @submit.prevent="rebootServer">
83 <b-form-group
84 :label="$t('pageServerPowerOperations.rebootServer')"
85 >
86 <b-form-radio
87 v-model="form.rebootOption"
88 name="reboot-option"
Sukanya Pandey8d29eb42020-07-17 12:42:46 +053089 data-test-id="serverPowerOperations-radio-rebootOrderly"
Yoshie Muranakafa1512b2020-02-25 15:54:07 -080090 value="orderly"
91 >
92 {{ $t('pageServerPowerOperations.orderlyReboot') }}
93 </b-form-radio>
94 <b-form-radio
95 v-model="form.rebootOption"
96 name="reboot-option"
Sukanya Pandey8d29eb42020-07-17 12:42:46 +053097 data-test-id="serverPowerOperations-radio-rebootImmediate"
Yoshie Muranakafa1512b2020-02-25 15:54:07 -080098 value="immediate"
99 >
100 {{ $t('pageServerPowerOperations.immediateReboot') }}
101 </b-form-radio>
102 </b-form-group>
Sukanya Pandey8d29eb42020-07-17 12:42:46 +0530103 <b-button
104 variant="primary"
105 type="submit"
106 data-test-id="serverPowerOperations-button-reboot"
107 >
Yoshie Muranakafa1512b2020-02-25 15:54:07 -0800108 {{ $t('pageServerPowerOperations.reboot') }}
109 </b-button>
110 </b-form>
111 <!-- Shutdown server options -->
112 <b-form novalidate @submit.prevent="shutdownServer">
113 <b-form-group
114 :label="$t('pageServerPowerOperations.shutdownServer')"
115 >
116 <b-form-radio
117 v-model="form.shutdownOption"
118 name="shutdown-option"
Sukanya Pandey8d29eb42020-07-17 12:42:46 +0530119 data-test-id="serverPowerOperations-radio-shutdownOrderly"
Yoshie Muranakafa1512b2020-02-25 15:54:07 -0800120 value="orderly"
121 >
122 {{ $t('pageServerPowerOperations.orderlyShutdown') }}
123 </b-form-radio>
124 <b-form-radio
125 v-model="form.shutdownOption"
126 name="shutdown-option"
Sukanya Pandey8d29eb42020-07-17 12:42:46 +0530127 data-test-id="serverPowerOperations-radio-shutdownImmediate"
Yoshie Muranakafa1512b2020-02-25 15:54:07 -0800128 value="immediate"
129 >
130 {{ $t('pageServerPowerOperations.immediateShutdown') }}
131 </b-form-radio>
132 </b-form-group>
Sukanya Pandey8d29eb42020-07-17 12:42:46 +0530133 <b-button
134 variant="primary"
135 type="submit"
136 data-test-id="serverPowerOperations-button-shutDown"
137 >
Yoshie Muranakafa1512b2020-02-25 15:54:07 -0800138 {{ $t('pageServerPowerOperations.shutDown') }}
139 </b-button>
140 </b-form>
141 </template>
Yoshie Muranakafa1512b2020-02-25 15:54:07 -0800142 </page-section>
143 </b-col>
144 </b-row>
145 </b-container>
146</template>
147
148<script>
SurenNewaread8438b2020-08-20 18:32:28 +0530149import PageTitle from '@/components/Global/PageTitle';
150import PageSection from '@/components/Global/PageSection';
151import BVToastMixin from '@/components/Mixins/BVToastMixin';
Yoshie Muranakac05ff642020-02-26 14:23:15 -0800152import BootSettings from './BootSettings';
Yoshie Muranaka5c977972020-04-30 09:48:23 -0700153import LoadingBarMixin from '@/components/Mixins/LoadingBarMixin';
SurenNewaread8438b2020-08-20 18:32:28 +0530154import Alert from '@/components/Global/Alert';
Yoshie Muranakafa1512b2020-02-25 15:54:07 -0800155
156export default {
157 name: 'ServerPowerOperations',
SurenNewaread8438b2020-08-20 18:32:28 +0530158 components: { PageTitle, PageSection, BootSettings, Alert },
Yoshie Muranaka5c977972020-04-30 09:48:23 -0700159 mixins: [BVToastMixin, LoadingBarMixin],
Derick Montague602e98a2020-10-21 16:20:00 -0500160 beforeRouteLeave(to, from, next) {
161 this.hideLoader();
162 next();
163 },
Yoshie Muranakafa1512b2020-02-25 15:54:07 -0800164 data() {
165 return {
166 form: {
167 rebootOption: 'orderly',
Derick Montague602e98a2020-10-21 16:20:00 -0500168 shutdownOption: 'orderly',
169 },
Yoshie Muranakafa1512b2020-02-25 15:54:07 -0800170 };
171 },
172 computed: {
173 hostStatus() {
174 return this.$store.getters['global/hostStatus'];
175 },
Yoshie Muranakafa1512b2020-02-25 15:54:07 -0800176 isOperationInProgress() {
177 return this.$store.getters['controls/isOperationInProgress'];
Yoshie Muranakac05ff642020-02-26 14:23:15 -0800178 },
Dixsie Wolmersbb316062020-08-04 19:17:33 -0500179 lastPowerOperationTime() {
180 return this.$store.getters['controls/lastPowerOperationTime'];
181 },
Yoshie Muranakac05ff642020-02-26 14:23:15 -0800182 oneTimeBootEnabled() {
183 return this.$store.getters['hostBootSettings/overrideEnabled'];
Derick Montague602e98a2020-10-21 16:20:00 -0500184 },
Sukanya Pandey7f6edb62021-03-30 19:49:08 +0530185 hasBootSourceOptions() {
186 let bootOptions = this.$store.getters[
187 'hostBootSettings/bootSourceOptions'
188 ];
189 return bootOptions.length !== 0;
190 },
Yoshie Muranakafa1512b2020-02-25 15:54:07 -0800191 },
Yoshie Muranaka5c977972020-04-30 09:48:23 -0700192 created() {
193 this.startLoader();
Derick Montague602e98a2020-10-21 16:20:00 -0500194 const bootSettingsPromise = new Promise((resolve) => {
Sukanya Pandeyedb8a772020-10-29 11:33:42 +0530195 this.$root.$on('server-power-operations-boot-settings-complete', () =>
Dixsie Wolmersbb316062020-08-04 19:17:33 -0500196 resolve()
197 );
198 });
199 Promise.all([
Sukanya Pandey7f6edb62021-03-30 19:49:08 +0530200 this.$store.dispatch('hostBootSettings/getBootSettings'),
Dixsie Wolmersbb316062020-08-04 19:17:33 -0500201 this.$store.dispatch('controls/getLastPowerOperationTime'),
Derick Montague602e98a2020-10-21 16:20:00 -0500202 bootSettingsPromise,
Dixsie Wolmersbb316062020-08-04 19:17:33 -0500203 ]).finally(() => this.endLoader());
Yoshie Muranaka5c977972020-04-30 09:48:23 -0700204 },
Yoshie Muranakafa1512b2020-02-25 15:54:07 -0800205 methods: {
206 powerOn() {
207 this.$store.dispatch('controls/hostPowerOn');
208 },
209 rebootServer() {
210 const modalMessage = this.$t(
211 'pageServerPowerOperations.modal.confirmRebootMessage'
212 );
213 const modalOptions = {
214 title: this.$t('pageServerPowerOperations.modal.confirmRebootTitle'),
Derick Montague602e98a2020-10-21 16:20:00 -0500215 okTitle: this.$t('global.action.confirm'),
Sukanya Pandey38357132020-12-22 13:40:59 +0530216 cancelTitle: this.$t('global.action.cancel'),
Yoshie Muranakafa1512b2020-02-25 15:54:07 -0800217 };
218
219 if (this.form.rebootOption === 'orderly') {
220 this.$bvModal
221 .msgBoxConfirm(modalMessage, modalOptions)
Derick Montague602e98a2020-10-21 16:20:00 -0500222 .then((confirmed) => {
Yoshie Muranakafa1512b2020-02-25 15:54:07 -0800223 if (confirmed) this.$store.dispatch('controls/hostSoftReboot');
224 });
225 } else if (this.form.rebootOption === 'immediate') {
226 this.$bvModal
227 .msgBoxConfirm(modalMessage, modalOptions)
Derick Montague602e98a2020-10-21 16:20:00 -0500228 .then((confirmed) => {
Yoshie Muranakafa1512b2020-02-25 15:54:07 -0800229 if (confirmed) this.$store.dispatch('controls/hostHardReboot');
230 });
231 }
232 },
233 shutdownServer() {
234 const modalMessage = this.$t(
235 'pageServerPowerOperations.modal.confirmShutdownMessage'
236 );
237 const modalOptions = {
238 title: this.$t('pageServerPowerOperations.modal.confirmShutdownTitle'),
Derick Montague602e98a2020-10-21 16:20:00 -0500239 okTitle: this.$t('global.action.confirm'),
Sukanya Pandey38357132020-12-22 13:40:59 +0530240 cancelTitle: this.$t('global.action.cancel'),
Yoshie Muranakafa1512b2020-02-25 15:54:07 -0800241 };
242
243 if (this.form.shutdownOption === 'orderly') {
244 this.$bvModal
245 .msgBoxConfirm(modalMessage, modalOptions)
Derick Montague602e98a2020-10-21 16:20:00 -0500246 .then((confirmed) => {
Yoshie Muranakafa1512b2020-02-25 15:54:07 -0800247 if (confirmed) this.$store.dispatch('controls/hostSoftPowerOff');
248 });
249 }
250 if (this.form.shutdownOption === 'immediate') {
251 this.$bvModal
252 .msgBoxConfirm(modalMessage, modalOptions)
Derick Montague602e98a2020-10-21 16:20:00 -0500253 .then((confirmed) => {
Yoshie Muranakafa1512b2020-02-25 15:54:07 -0800254 if (confirmed) this.$store.dispatch('controls/hostHardPowerOff');
255 });
256 }
Derick Montague602e98a2020-10-21 16:20:00 -0500257 },
258 },
Yoshie Muranakafa1512b2020-02-25 15:54:07 -0800259};
260</script>