1<template> 2 <b-container fluid="xl"> 3 <page-title /> 4 <b-row class="mb-4"> 5 <b-col md="8" xl="6"> 6 <page-section 7 :section-title="$t('pageServerPowerOperations.currentStatus')" 8 > 9 <b-row> 10 <b-col> 11 <dl> 12 <dt>{{ $t('pageServerPowerOperations.serverStatus') }}</dt> 13 <dd 14 v-if="serverStatus === 'on'" 15 data-test-id="powerServerOps-text-hostStatus" 16 > 17 {{ $t('global.status.on') }} 18 </dd> 19 <dd 20 v-else-if="serverStatus === 'off'" 21 data-test-id="powerServerOps-text-hostStatus" 22 > 23 {{ $t('global.status.off') }} 24 </dd> 25 <dd 26 v-else-if="serverStatus === 'diagnosticMode'" 27 data-test-id="powerServerOps-text-hostStatus" 28 > 29 {{ $t('global.status.diagnosticMode') }} 30 </dd> 31 <dd v-else> 32 {{ $t('global.status.notAvailable') }} 33 </dd> 34 </dl> 35 </b-col> 36 </b-row> 37 <b-row> 38 <b-col> 39 <dl> 40 <dt> 41 {{ $t('pageServerPowerOperations.lastPowerOperation') }} 42 </dt> 43 <dd 44 v-if="lastPowerOperationTime" 45 data-test-id="powerServerOps-text-lastPowerOp" 46 > 47 {{ lastPowerOperationTime | formatDate }} 48 {{ lastPowerOperationTime | formatTime }} 49 </dd> 50 <dd v-else>--</dd> 51 </dl> 52 </b-col> 53 </b-row> 54 </page-section> 55 </b-col> 56 </b-row> 57 <b-row> 58 <b-col v-if="hasBootSourceOptions" sm="8" md="6" xl="4"> 59 <page-section 60 :section-title="$t('pageServerPowerOperations.serverBootSettings')" 61 > 62 <boot-settings /> 63 </page-section> 64 </b-col> 65 <b-col sm="8" md="6" xl="7"> 66 <page-section 67 :section-title="$t('pageServerPowerOperations.operations')" 68 > 69 <alert :show="oneTimeBootEnabled" variant="warning"> 70 {{ $t('pageServerPowerOperations.oneTimeBootWarning') }} 71 </alert> 72 <template v-if="isOperationInProgress"> 73 <alert variant="info"> 74 {{ $t('pageServerPowerOperations.operationInProgress') }} 75 </alert> 76 </template> 77 <template v-else-if="serverStatus === 'off'"> 78 <b-button 79 variant="primary" 80 data-test-id="serverPowerOperations-button-powerOn" 81 @click="powerOn" 82 > 83 {{ $t('pageServerPowerOperations.powerOn') }} 84 </b-button> 85 </template> 86 <template v-else> 87 <!-- Reboot server options --> 88 <b-form novalidate class="mb-5" @submit.prevent="rebootServer"> 89 <b-form-group 90 :label="$t('pageServerPowerOperations.rebootServer')" 91 > 92 <b-form-radio 93 v-model="form.rebootOption" 94 name="reboot-option" 95 data-test-id="serverPowerOperations-radio-rebootOrderly" 96 value="orderly" 97 > 98 {{ $t('pageServerPowerOperations.orderlyReboot') }} 99 </b-form-radio> 100 <b-form-radio 101 v-model="form.rebootOption" 102 name="reboot-option" 103 data-test-id="serverPowerOperations-radio-rebootImmediate" 104 value="immediate" 105 > 106 {{ $t('pageServerPowerOperations.immediateReboot') }} 107 </b-form-radio> 108 </b-form-group> 109 <b-button 110 variant="primary" 111 type="submit" 112 data-test-id="serverPowerOperations-button-reboot" 113 > 114 {{ $t('pageServerPowerOperations.reboot') }} 115 </b-button> 116 </b-form> 117 <!-- Shutdown server options --> 118 <b-form novalidate @submit.prevent="shutdownServer"> 119 <b-form-group 120 :label="$t('pageServerPowerOperations.shutdownServer')" 121 > 122 <b-form-radio 123 v-model="form.shutdownOption" 124 name="shutdown-option" 125 data-test-id="serverPowerOperations-radio-shutdownOrderly" 126 value="orderly" 127 > 128 {{ $t('pageServerPowerOperations.orderlyShutdown') }} 129 </b-form-radio> 130 <b-form-radio 131 v-model="form.shutdownOption" 132 name="shutdown-option" 133 data-test-id="serverPowerOperations-radio-shutdownImmediate" 134 value="immediate" 135 > 136 {{ $t('pageServerPowerOperations.immediateShutdown') }} 137 </b-form-radio> 138 </b-form-group> 139 <b-button 140 variant="primary" 141 type="submit" 142 data-test-id="serverPowerOperations-button-shutDown" 143 > 144 {{ $t('pageServerPowerOperations.shutDown') }} 145 </b-button> 146 </b-form> 147 </template> 148 </page-section> 149 </b-col> 150 </b-row> 151 </b-container> 152</template> 153 154<script> 155import PageTitle from '@/components/Global/PageTitle'; 156import PageSection from '@/components/Global/PageSection'; 157import BVToastMixin from '@/components/Mixins/BVToastMixin'; 158import BootSettings from './BootSettings'; 159import LoadingBarMixin from '@/components/Mixins/LoadingBarMixin'; 160import Alert from '@/components/Global/Alert'; 161 162export default { 163 name: 'ServerPowerOperations', 164 components: { PageTitle, PageSection, BootSettings, Alert }, 165 mixins: [BVToastMixin, LoadingBarMixin], 166 beforeRouteLeave(to, from, next) { 167 this.hideLoader(); 168 next(); 169 }, 170 data() { 171 return { 172 form: { 173 rebootOption: 'orderly', 174 shutdownOption: 'orderly', 175 }, 176 }; 177 }, 178 computed: { 179 serverStatus() { 180 return this.$store.getters['global/serverStatus']; 181 }, 182 isOperationInProgress() { 183 return this.$store.getters['controls/isOperationInProgress']; 184 }, 185 lastPowerOperationTime() { 186 return this.$store.getters['controls/lastPowerOperationTime']; 187 }, 188 oneTimeBootEnabled() { 189 return this.$store.getters['serverBootSettings/overrideEnabled']; 190 }, 191 hasBootSourceOptions() { 192 let bootOptions = 193 this.$store.getters['serverBootSettings/bootSourceOptions']; 194 return bootOptions.length !== 0; 195 }, 196 }, 197 created() { 198 this.startLoader(); 199 const bootSettingsPromise = new Promise((resolve) => { 200 this.$root.$on('server-power-operations-boot-settings-complete', () => 201 resolve(), 202 ); 203 }); 204 Promise.all([ 205 this.$store.dispatch('serverBootSettings/getBootSettings'), 206 this.$store.dispatch('controls/getLastPowerOperationTime'), 207 bootSettingsPromise, 208 ]).finally(() => this.endLoader()); 209 }, 210 methods: { 211 powerOn() { 212 this.$store.dispatch('controls/serverPowerOn'); 213 }, 214 rebootServer() { 215 const modalMessage = this.$t( 216 'pageServerPowerOperations.modal.confirmRebootMessage', 217 ); 218 const modalOptions = { 219 title: this.$t('pageServerPowerOperations.modal.confirmRebootTitle'), 220 okTitle: this.$t('global.action.confirm'), 221 cancelTitle: this.$t('global.action.cancel'), 222 autoFocusButton: 'ok', 223 }; 224 225 if (this.form.rebootOption === 'orderly') { 226 this.$bvModal 227 .msgBoxConfirm(modalMessage, modalOptions) 228 .then((confirmed) => { 229 if (confirmed) this.$store.dispatch('controls/serverSoftReboot'); 230 }); 231 } else if (this.form.rebootOption === 'immediate') { 232 this.$bvModal 233 .msgBoxConfirm(modalMessage, modalOptions) 234 .then((confirmed) => { 235 if (confirmed) this.$store.dispatch('controls/serverHardReboot'); 236 }); 237 } 238 }, 239 shutdownServer() { 240 const modalMessage = this.$t( 241 'pageServerPowerOperations.modal.confirmShutdownMessage', 242 ); 243 const modalOptions = { 244 title: this.$t('pageServerPowerOperations.modal.confirmShutdownTitle'), 245 okTitle: this.$t('global.action.confirm'), 246 cancelTitle: this.$t('global.action.cancel'), 247 autoFocusButton: 'ok', 248 }; 249 250 if (this.form.shutdownOption === 'orderly') { 251 this.$bvModal 252 .msgBoxConfirm(modalMessage, modalOptions) 253 .then((confirmed) => { 254 if (confirmed) this.$store.dispatch('controls/serverSoftPowerOff'); 255 }); 256 } 257 if (this.form.shutdownOption === 'immediate') { 258 this.$bvModal 259 .msgBoxConfirm(modalMessage, modalOptions) 260 .then((confirmed) => { 261 if (confirmed) this.$store.dispatch('controls/serverHardPowerOff'); 262 }); 263 } 264 }, 265 }, 266}; 267</script> 268