blob: 0db0129871b42aa97cc27c6a847149f464196b3b [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 >
Yoshie Muranakac05ff642020-02-26 14:23:15 -080054 <b-alert :show="oneTimeBootEnabled" variant="warning">
55 {{ $t('pageServerPowerOperations.oneTimeBootWarning') }}
56 </b-alert>
Yoshie Muranakafa1512b2020-02-25 15:54:07 -080057 <template v-if="isOperationInProgress">
58 {{ $t('pageServerPowerOperations.operationInProgress') }}
59 </template>
60 <template v-else-if="hostStatus === 'off'">
Sukanya Pandey8d29eb42020-07-17 12:42:46 +053061 <b-button
62 variant="primary"
63 data-test-id="serverPowerOperations-button-powerOn"
64 @click="powerOn"
65 >
Yoshie Muranakafa1512b2020-02-25 15:54:07 -080066 {{ $t('pageServerPowerOperations.powerOn') }}
67 </b-button>
68 </template>
Yoshie Muranakae9fc6122020-08-10 15:12:09 -070069 <template v-else>
Yoshie Muranakafa1512b2020-02-25 15:54:07 -080070 <!-- Reboot server options -->
71 <b-form novalidate class="mb-5" @submit.prevent="rebootServer">
72 <b-form-group
73 :label="$t('pageServerPowerOperations.rebootServer')"
74 >
75 <b-form-radio
76 v-model="form.rebootOption"
77 name="reboot-option"
Sukanya Pandey8d29eb42020-07-17 12:42:46 +053078 data-test-id="serverPowerOperations-radio-rebootOrderly"
Yoshie Muranakafa1512b2020-02-25 15:54:07 -080079 value="orderly"
80 >
81 {{ $t('pageServerPowerOperations.orderlyReboot') }}
82 </b-form-radio>
83 <b-form-radio
84 v-model="form.rebootOption"
85 name="reboot-option"
Sukanya Pandey8d29eb42020-07-17 12:42:46 +053086 data-test-id="serverPowerOperations-radio-rebootImmediate"
Yoshie Muranakafa1512b2020-02-25 15:54:07 -080087 value="immediate"
88 >
89 {{ $t('pageServerPowerOperations.immediateReboot') }}
90 </b-form-radio>
91 </b-form-group>
Sukanya Pandey8d29eb42020-07-17 12:42:46 +053092 <b-button
93 variant="primary"
94 type="submit"
95 data-test-id="serverPowerOperations-button-reboot"
96 >
Yoshie Muranakafa1512b2020-02-25 15:54:07 -080097 {{ $t('pageServerPowerOperations.reboot') }}
98 </b-button>
99 </b-form>
100 <!-- Shutdown server options -->
101 <b-form novalidate @submit.prevent="shutdownServer">
102 <b-form-group
103 :label="$t('pageServerPowerOperations.shutdownServer')"
104 >
105 <b-form-radio
106 v-model="form.shutdownOption"
107 name="shutdown-option"
Sukanya Pandey8d29eb42020-07-17 12:42:46 +0530108 data-test-id="serverPowerOperations-radio-shutdownOrderly"
Yoshie Muranakafa1512b2020-02-25 15:54:07 -0800109 value="orderly"
110 >
111 {{ $t('pageServerPowerOperations.orderlyShutdown') }}
112 </b-form-radio>
113 <b-form-radio
114 v-model="form.shutdownOption"
115 name="shutdown-option"
Sukanya Pandey8d29eb42020-07-17 12:42:46 +0530116 data-test-id="serverPowerOperations-radio-shutdownImmediate"
Yoshie Muranakafa1512b2020-02-25 15:54:07 -0800117 value="immediate"
118 >
119 {{ $t('pageServerPowerOperations.immediateShutdown') }}
120 </b-form-radio>
121 </b-form-group>
Sukanya Pandey8d29eb42020-07-17 12:42:46 +0530122 <b-button
123 variant="primary"
124 type="submit"
125 data-test-id="serverPowerOperations-button-shutDown"
126 >
Yoshie Muranakafa1512b2020-02-25 15:54:07 -0800127 {{ $t('pageServerPowerOperations.shutDown') }}
128 </b-button>
129 </b-form>
130 </template>
Yoshie Muranakafa1512b2020-02-25 15:54:07 -0800131 </page-section>
132 </b-col>
133 </b-row>
134 </b-container>
135</template>
136
137<script>
138import PageTitle from '../../../components/Global/PageTitle';
139import PageSection from '../../../components/Global/PageSection';
140import BVToastMixin from '../../../components/Mixins/BVToastMixin';
Yoshie Muranakac05ff642020-02-26 14:23:15 -0800141import BootSettings from './BootSettings';
Yoshie Muranaka5c977972020-04-30 09:48:23 -0700142import LoadingBarMixin from '@/components/Mixins/LoadingBarMixin';
Yoshie Muranakafa1512b2020-02-25 15:54:07 -0800143
144export default {
145 name: 'ServerPowerOperations',
Yoshie Muranakac05ff642020-02-26 14:23:15 -0800146 components: { PageTitle, PageSection, BootSettings },
Yoshie Muranaka5c977972020-04-30 09:48:23 -0700147 mixins: [BVToastMixin, LoadingBarMixin],
Yoshie Muranakafa1512b2020-02-25 15:54:07 -0800148 data() {
149 return {
150 form: {
151 rebootOption: 'orderly',
152 shutdownOption: 'orderly'
153 }
154 };
155 },
156 computed: {
157 hostStatus() {
158 return this.$store.getters['global/hostStatus'];
159 },
Yoshie Muranakafa1512b2020-02-25 15:54:07 -0800160 isOperationInProgress() {
161 return this.$store.getters['controls/isOperationInProgress'];
Yoshie Muranakac05ff642020-02-26 14:23:15 -0800162 },
Dixsie Wolmersbb316062020-08-04 19:17:33 -0500163 lastPowerOperationTime() {
164 return this.$store.getters['controls/lastPowerOperationTime'];
165 },
Yoshie Muranakac05ff642020-02-26 14:23:15 -0800166 oneTimeBootEnabled() {
167 return this.$store.getters['hostBootSettings/overrideEnabled'];
Yoshie Muranakafa1512b2020-02-25 15:54:07 -0800168 }
169 },
Yoshie Muranaka5c977972020-04-30 09:48:23 -0700170 created() {
171 this.startLoader();
Dixsie Wolmersbb316062020-08-04 19:17:33 -0500172 const bootSettingsPromise = new Promise(resolve => {
173 this.$root.$on('serverPowerOperations::bootSettings::complete', () =>
174 resolve()
175 );
176 });
177 Promise.all([
178 this.$store.dispatch('controls/getLastPowerOperationTime'),
179 bootSettingsPromise
180 ]).finally(() => this.endLoader());
Yoshie Muranaka5c977972020-04-30 09:48:23 -0700181 },
182 beforeRouteLeave(to, from, next) {
183 this.hideLoader();
184 next();
185 },
Yoshie Muranakafa1512b2020-02-25 15:54:07 -0800186 methods: {
187 powerOn() {
188 this.$store.dispatch('controls/hostPowerOn');
189 },
190 rebootServer() {
191 const modalMessage = this.$t(
192 'pageServerPowerOperations.modal.confirmRebootMessage'
193 );
194 const modalOptions = {
195 title: this.$t('pageServerPowerOperations.modal.confirmRebootTitle'),
196 okTitle: this.$t('global.action.confirm')
197 };
198
199 if (this.form.rebootOption === 'orderly') {
200 this.$bvModal
201 .msgBoxConfirm(modalMessage, modalOptions)
202 .then(confirmed => {
203 if (confirmed) this.$store.dispatch('controls/hostSoftReboot');
204 });
205 } else if (this.form.rebootOption === 'immediate') {
206 this.$bvModal
207 .msgBoxConfirm(modalMessage, modalOptions)
208 .then(confirmed => {
209 if (confirmed) this.$store.dispatch('controls/hostHardReboot');
210 });
211 }
212 },
213 shutdownServer() {
214 const modalMessage = this.$t(
215 'pageServerPowerOperations.modal.confirmShutdownMessage'
216 );
217 const modalOptions = {
218 title: this.$t('pageServerPowerOperations.modal.confirmShutdownTitle'),
219 okTitle: this.$t('global.action.confirm')
220 };
221
222 if (this.form.shutdownOption === 'orderly') {
223 this.$bvModal
224 .msgBoxConfirm(modalMessage, modalOptions)
225 .then(confirmed => {
226 if (confirmed) this.$store.dispatch('controls/hostSoftPowerOff');
227 });
228 }
229 if (this.form.shutdownOption === 'immediate') {
230 this.$bvModal
231 .msgBoxConfirm(modalMessage, modalOptions)
232 .then(confirmed => {
233 if (confirmed) this.$store.dispatch('controls/hostHardPowerOff');
234 });
235 }
236 }
237 }
238};
239</script>