blob: 32b2ea86f6cf5dc06952bf518ca642838858152a [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>
13 <dd v-if="hostStatus === 'on'">
14 {{ $t('global.status.on') }}
15 </dd>
16 <dd v-else-if="hostStatus === 'off'">
17 {{ $t('global.status.off') }}
18 </dd>
19 <dd v-else>
20 {{ $t('global.status.notAvailable') }}
21 </dd>
22 </dl>
23 </b-col>
24 </b-row>
25 <b-row>
26 <b-col>
27 <dl>
28 <dt>
29 {{ $t('pageServerPowerOperations.lastPowerOperation') }}
30 </dt>
31 <dd v-if="lastPowerOperationTime">
32 {{ lastPowerOperationTime | formatDate }}
33 {{ lastPowerOperationTime | formatTime }}
34 </dd>
35 <dd v-else>--</dd>
36 </dl>
37 </b-col>
38 </b-row>
Yoshie Muranakafa1512b2020-02-25 15:54:07 -080039 </page-section>
40 </b-col>
41 </b-row>
42 <b-row>
Yoshie Muranakac05ff642020-02-26 14:23:15 -080043 <b-col sm="8" md="6" xl="4">
44 <page-section
45 :section-title="$t('pageServerPowerOperations.hostOsBootSettings')"
46 >
47 <boot-settings />
48 </page-section>
49 </b-col>
50 <b-col sm="8" md="6" xl="7">
Yoshie Muranakafa1512b2020-02-25 15:54:07 -080051 <page-section
52 :section-title="$t('pageServerPowerOperations.operations')"
53 >
SurenNewaread8438b2020-08-20 18:32:28 +053054 <alert :show="oneTimeBootEnabled" variant="warning">
Yoshie Muranakac05ff642020-02-26 14:23:15 -080055 {{ $t('pageServerPowerOperations.oneTimeBootWarning') }}
SurenNewaread8438b2020-08-20 18:32:28 +053056 </alert>
Yoshie Muranakafa1512b2020-02-25 15:54:07 -080057 <template v-if="isOperationInProgress">
SurenNewaread8438b2020-08-20 18:32:28 +053058 <alert variant="info">
59 {{ $t('pageServerPowerOperations.operationInProgress') }}
60 </alert>
Yoshie Muranakafa1512b2020-02-25 15:54:07 -080061 </template>
62 <template v-else-if="hostStatus === 'off'">
Sukanya Pandey8d29eb42020-07-17 12:42:46 +053063 <b-button
64 variant="primary"
65 data-test-id="serverPowerOperations-button-powerOn"
66 @click="powerOn"
67 >
Yoshie Muranakafa1512b2020-02-25 15:54:07 -080068 {{ $t('pageServerPowerOperations.powerOn') }}
69 </b-button>
70 </template>
Yoshie Muranakae9fc6122020-08-10 15:12:09 -070071 <template v-else>
Yoshie Muranakafa1512b2020-02-25 15:54:07 -080072 <!-- Reboot server options -->
73 <b-form novalidate class="mb-5" @submit.prevent="rebootServer">
74 <b-form-group
75 :label="$t('pageServerPowerOperations.rebootServer')"
76 >
77 <b-form-radio
78 v-model="form.rebootOption"
79 name="reboot-option"
Sukanya Pandey8d29eb42020-07-17 12:42:46 +053080 data-test-id="serverPowerOperations-radio-rebootOrderly"
Yoshie Muranakafa1512b2020-02-25 15:54:07 -080081 value="orderly"
82 >
83 {{ $t('pageServerPowerOperations.orderlyReboot') }}
84 </b-form-radio>
85 <b-form-radio
86 v-model="form.rebootOption"
87 name="reboot-option"
Sukanya Pandey8d29eb42020-07-17 12:42:46 +053088 data-test-id="serverPowerOperations-radio-rebootImmediate"
Yoshie Muranakafa1512b2020-02-25 15:54:07 -080089 value="immediate"
90 >
91 {{ $t('pageServerPowerOperations.immediateReboot') }}
92 </b-form-radio>
93 </b-form-group>
Sukanya Pandey8d29eb42020-07-17 12:42:46 +053094 <b-button
95 variant="primary"
96 type="submit"
97 data-test-id="serverPowerOperations-button-reboot"
98 >
Yoshie Muranakafa1512b2020-02-25 15:54:07 -080099 {{ $t('pageServerPowerOperations.reboot') }}
100 </b-button>
101 </b-form>
102 <!-- Shutdown server options -->
103 <b-form novalidate @submit.prevent="shutdownServer">
104 <b-form-group
105 :label="$t('pageServerPowerOperations.shutdownServer')"
106 >
107 <b-form-radio
108 v-model="form.shutdownOption"
109 name="shutdown-option"
Sukanya Pandey8d29eb42020-07-17 12:42:46 +0530110 data-test-id="serverPowerOperations-radio-shutdownOrderly"
Yoshie Muranakafa1512b2020-02-25 15:54:07 -0800111 value="orderly"
112 >
113 {{ $t('pageServerPowerOperations.orderlyShutdown') }}
114 </b-form-radio>
115 <b-form-radio
116 v-model="form.shutdownOption"
117 name="shutdown-option"
Sukanya Pandey8d29eb42020-07-17 12:42:46 +0530118 data-test-id="serverPowerOperations-radio-shutdownImmediate"
Yoshie Muranakafa1512b2020-02-25 15:54:07 -0800119 value="immediate"
120 >
121 {{ $t('pageServerPowerOperations.immediateShutdown') }}
122 </b-form-radio>
123 </b-form-group>
Sukanya Pandey8d29eb42020-07-17 12:42:46 +0530124 <b-button
125 variant="primary"
126 type="submit"
127 data-test-id="serverPowerOperations-button-shutDown"
128 >
Yoshie Muranakafa1512b2020-02-25 15:54:07 -0800129 {{ $t('pageServerPowerOperations.shutDown') }}
130 </b-button>
131 </b-form>
132 </template>
Yoshie Muranakafa1512b2020-02-25 15:54:07 -0800133 </page-section>
134 </b-col>
135 </b-row>
136 </b-container>
137</template>
138
139<script>
SurenNewaread8438b2020-08-20 18:32:28 +0530140import PageTitle from '@/components/Global/PageTitle';
141import PageSection from '@/components/Global/PageSection';
142import BVToastMixin from '@/components/Mixins/BVToastMixin';
Yoshie Muranakac05ff642020-02-26 14:23:15 -0800143import BootSettings from './BootSettings';
Yoshie Muranaka5c977972020-04-30 09:48:23 -0700144import LoadingBarMixin from '@/components/Mixins/LoadingBarMixin';
SurenNewaread8438b2020-08-20 18:32:28 +0530145import Alert from '@/components/Global/Alert';
Yoshie Muranakafa1512b2020-02-25 15:54:07 -0800146
147export default {
148 name: 'ServerPowerOperations',
SurenNewaread8438b2020-08-20 18:32:28 +0530149 components: { PageTitle, PageSection, BootSettings, Alert },
Yoshie Muranaka5c977972020-04-30 09:48:23 -0700150 mixins: [BVToastMixin, LoadingBarMixin],
Yoshie Muranakafa1512b2020-02-25 15:54:07 -0800151 data() {
152 return {
153 form: {
154 rebootOption: 'orderly',
155 shutdownOption: 'orderly'
156 }
157 };
158 },
159 computed: {
160 hostStatus() {
161 return this.$store.getters['global/hostStatus'];
162 },
Yoshie Muranakafa1512b2020-02-25 15:54:07 -0800163 isOperationInProgress() {
164 return this.$store.getters['controls/isOperationInProgress'];
Yoshie Muranakac05ff642020-02-26 14:23:15 -0800165 },
Dixsie Wolmersbb316062020-08-04 19:17:33 -0500166 lastPowerOperationTime() {
167 return this.$store.getters['controls/lastPowerOperationTime'];
168 },
Yoshie Muranakac05ff642020-02-26 14:23:15 -0800169 oneTimeBootEnabled() {
170 return this.$store.getters['hostBootSettings/overrideEnabled'];
Yoshie Muranakafa1512b2020-02-25 15:54:07 -0800171 }
172 },
Yoshie Muranaka5c977972020-04-30 09:48:23 -0700173 created() {
174 this.startLoader();
Dixsie Wolmersbb316062020-08-04 19:17:33 -0500175 const bootSettingsPromise = new Promise(resolve => {
176 this.$root.$on('serverPowerOperations::bootSettings::complete', () =>
177 resolve()
178 );
179 });
180 Promise.all([
181 this.$store.dispatch('controls/getLastPowerOperationTime'),
182 bootSettingsPromise
183 ]).finally(() => this.endLoader());
Yoshie Muranaka5c977972020-04-30 09:48:23 -0700184 },
185 beforeRouteLeave(to, from, next) {
186 this.hideLoader();
187 next();
188 },
Yoshie Muranakafa1512b2020-02-25 15:54:07 -0800189 methods: {
190 powerOn() {
191 this.$store.dispatch('controls/hostPowerOn');
192 },
193 rebootServer() {
194 const modalMessage = this.$t(
195 'pageServerPowerOperations.modal.confirmRebootMessage'
196 );
197 const modalOptions = {
198 title: this.$t('pageServerPowerOperations.modal.confirmRebootTitle'),
199 okTitle: this.$t('global.action.confirm')
200 };
201
202 if (this.form.rebootOption === 'orderly') {
203 this.$bvModal
204 .msgBoxConfirm(modalMessage, modalOptions)
205 .then(confirmed => {
206 if (confirmed) this.$store.dispatch('controls/hostSoftReboot');
207 });
208 } else if (this.form.rebootOption === 'immediate') {
209 this.$bvModal
210 .msgBoxConfirm(modalMessage, modalOptions)
211 .then(confirmed => {
212 if (confirmed) this.$store.dispatch('controls/hostHardReboot');
213 });
214 }
215 },
216 shutdownServer() {
217 const modalMessage = this.$t(
218 'pageServerPowerOperations.modal.confirmShutdownMessage'
219 );
220 const modalOptions = {
221 title: this.$t('pageServerPowerOperations.modal.confirmShutdownTitle'),
222 okTitle: this.$t('global.action.confirm')
223 };
224
225 if (this.form.shutdownOption === 'orderly') {
226 this.$bvModal
227 .msgBoxConfirm(modalMessage, modalOptions)
228 .then(confirmed => {
229 if (confirmed) this.$store.dispatch('controls/hostSoftPowerOff');
230 });
231 }
232 if (this.form.shutdownOption === 'immediate') {
233 this.$bvModal
234 .msgBoxConfirm(modalMessage, modalOptions)
235 .then(confirmed => {
236 if (confirmed) this.$store.dispatch('controls/hostHardPowerOff');
237 });
238 }
239 }
240 }
241};
242</script>