xref: /openbmc/webui-vue/src/views/Operations/ServerPowerOperations/ServerPowerOperations.vue (revision de23ea23d88451a2fa2774ec72053772603c23ae)
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                  {{ $filters.formatDate(lastPowerOperationTime) }}
48                  {{ $filters.formatTime(lastPowerOperationTime) }}
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';
161import { useI18n } from 'vue-i18n';
162import i18n from '@/i18n';
163
164export default {
165  name: 'ServerPowerOperations',
166  components: { PageTitle, PageSection, BootSettings, Alert },
167  mixins: [BVToastMixin, LoadingBarMixin],
168  beforeRouteLeave(to, from, next) {
169    this.hideLoader();
170    next();
171  },
172  data() {
173    return {
174      $t: useI18n().t,
175      form: {
176        rebootOption: 'orderly',
177        shutdownOption: 'orderly',
178      },
179    };
180  },
181  computed: {
182    serverStatus() {
183      return this.$store.getters['global/serverStatus'];
184    },
185    isOperationInProgress() {
186      return this.$store.getters['controls/isOperationInProgress'];
187    },
188    lastPowerOperationTime() {
189      return this.$store.getters['controls/lastPowerOperationTime'];
190    },
191    oneTimeBootEnabled() {
192      return this.$store.getters['serverBootSettings/overrideEnabled'];
193    },
194    hasBootSourceOptions() {
195      let bootOptions =
196        this.$store.getters['serverBootSettings/bootSourceOptions'];
197      return bootOptions.length !== 0;
198    },
199  },
200  created() {
201    this.startLoader();
202    const bootSettingsPromise = new Promise((resolve) => {
203      this.$root.$on('server-power-operations-boot-settings-complete', () =>
204        resolve(),
205      );
206    });
207    Promise.all([
208      this.$store.dispatch('serverBootSettings/getBootSettings'),
209      this.$store.dispatch('controls/getLastPowerOperationTime'),
210      bootSettingsPromise,
211    ]).finally(() => this.endLoader());
212  },
213  methods: {
214    powerOn() {
215      this.$store.dispatch('controls/serverPowerOn');
216    },
217    rebootServer() {
218      const modalMessage = i18n.global.t(
219        'pageServerPowerOperations.modal.confirmRebootMessage',
220      );
221      const modalOptions = {
222        title: i18n.global.t(
223          'pageServerPowerOperations.modal.confirmRebootTitle',
224        ),
225        okTitle: i18n.global.t('global.action.confirm'),
226        cancelTitle: i18n.global.t('global.action.cancel'),
227        autoFocusButton: 'ok',
228      };
229
230      if (this.form.rebootOption === 'orderly') {
231        this.$bvModal
232          .msgBoxConfirm(modalMessage, modalOptions)
233          .then((confirmed) => {
234            if (confirmed) this.$store.dispatch('controls/serverSoftReboot');
235          });
236      } else if (this.form.rebootOption === 'immediate') {
237        this.$bvModal
238          .msgBoxConfirm(modalMessage, modalOptions)
239          .then((confirmed) => {
240            if (confirmed) this.$store.dispatch('controls/serverHardReboot');
241          });
242      }
243    },
244    shutdownServer() {
245      const modalMessage = i18n.global.t(
246        'pageServerPowerOperations.modal.confirmShutdownMessage',
247      );
248      const modalOptions = {
249        title: i18n.global.t(
250          'pageServerPowerOperations.modal.confirmShutdownTitle',
251        ),
252        okTitle: i18n.global.t('global.action.confirm'),
253        cancelTitle: i18n.global.t('global.action.cancel'),
254        autoFocusButton: 'ok',
255      };
256
257      if (this.form.shutdownOption === 'orderly') {
258        this.$bvModal
259          .msgBoxConfirm(modalMessage, modalOptions)
260          .then((confirmed) => {
261            if (confirmed) this.$store.dispatch('controls/serverSoftPowerOff');
262          });
263      }
264      if (this.form.shutdownOption === 'immediate') {
265        this.$bvModal
266          .msgBoxConfirm(modalMessage, modalOptions)
267          .then((confirmed) => {
268            if (confirmed) this.$store.dispatch('controls/serverHardPowerOff');
269          });
270      }
271    },
272  },
273};
274</script>
275