xref: /openbmc/webui-vue/src/views/Operations/ServerPowerOperations/ServerPowerOperations.vue (revision 918526f20c16a05c261a56814657942a707323dd)
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
59        v-if="hasBootSourceOptions && oneTimeBootEnabled"
60        sm="8"
61        md="6"
62        xl="4"
63      >
64        <page-section
65          :section-title="$t('pageServerPowerOperations.serverBootSettings')"
66        >
67          <boot-settings />
68        </page-section>
69      </b-col>
70      <b-col sm="8" md="6" xl="7">
71        <page-section
72          :section-title="$t('pageServerPowerOperations.operations')"
73        >
74          <alert :show="oneTimeBootEnabled" variant="warning">
75            {{ $t('pageServerPowerOperations.oneTimeBootWarning') }}
76          </alert>
77          <template v-if="isOperationInProgress">
78            <alert variant="info">
79              {{ $t('pageServerPowerOperations.operationInProgress') }}
80            </alert>
81          </template>
82          <template v-else-if="serverStatus === 'off'">
83            <b-button
84              variant="primary"
85              data-test-id="serverPowerOperations-button-powerOn"
86              @click="powerOn"
87            >
88              {{ $t('pageServerPowerOperations.powerOn') }}
89            </b-button>
90          </template>
91          <template v-else>
92            <!-- Reboot server options -->
93            <b-form novalidate class="mb-5" @submit.prevent="rebootServer">
94              <b-form-group
95                :label="$t('pageServerPowerOperations.rebootServer')"
96              >
97                <b-form-radio
98                  v-model="form.rebootOption"
99                  name="reboot-option"
100                  data-test-id="serverPowerOperations-radio-rebootOrderly"
101                  value="orderly"
102                >
103                  {{ $t('pageServerPowerOperations.gracefulRestart') }}
104                  <info-tooltip
105                    :title="$t('pageServerPowerOperations.gracefulRestartInfo')"
106                  />
107                </b-form-radio>
108                <b-form-radio
109                  v-model="form.rebootOption"
110                  name="reboot-option"
111                  data-test-id="serverPowerOperations-radio-rebootImmediate"
112                  value="immediate"
113                >
114                  {{ $t('pageServerPowerOperations.forceRestart') }}
115                  <info-tooltip
116                    :title="$t('pageServerPowerOperations.forceRestartInfo')"
117                  />
118                </b-form-radio>
119              </b-form-group>
120              <b-button
121                variant="primary"
122                type="submit"
123                data-test-id="serverPowerOperations-button-reboot"
124              >
125                {{ $t('pageServerPowerOperations.reboot') }}
126              </b-button>
127            </b-form>
128            <!-- Shutdown server options -->
129            <b-form novalidate @submit.prevent="shutdownServer">
130              <b-form-group
131                :label="$t('pageServerPowerOperations.shutdownServer')"
132              >
133                <b-form-radio
134                  v-model="form.shutdownOption"
135                  name="shutdown-option"
136                  data-test-id="serverPowerOperations-radio-shutdownOrderly"
137                  value="orderly"
138                >
139                  {{ $t('pageServerPowerOperations.gracefulShutdown') }}
140                  <info-tooltip
141                    :title="
142                      $t('pageServerPowerOperations.gracefulShutdownInfo')
143                    "
144                  />
145                </b-form-radio>
146                <b-form-radio
147                  v-model="form.shutdownOption"
148                  name="shutdown-option"
149                  data-test-id="serverPowerOperations-radio-shutdownImmediate"
150                  value="immediate"
151                >
152                  {{ $t('pageServerPowerOperations.forceOff') }}
153                  <info-tooltip
154                    :title="$t('pageServerPowerOperations.forceOffInfo')"
155                  />
156                </b-form-radio>
157              </b-form-group>
158              <b-button
159                variant="primary"
160                type="submit"
161                data-test-id="serverPowerOperations-button-shutDown"
162              >
163                {{ $t('pageServerPowerOperations.shutDown') }}
164              </b-button>
165            </b-form>
166          </template>
167        </page-section>
168      </b-col>
169    </b-row>
170  </b-container>
171</template>
172
173<script>
174import PageTitle from '@/components/Global/PageTitle';
175import PageSection from '@/components/Global/PageSection';
176import BVToastMixin from '@/components/Mixins/BVToastMixin';
177import BootSettings from './BootSettings';
178import LoadingBarMixin from '@/components/Mixins/LoadingBarMixin';
179import Alert from '@/components/Global/Alert';
180import InfoTooltip from '@/components/Global/InfoTooltip';
181import { useI18n } from 'vue-i18n';
182import i18n from '@/i18n';
183
184export default {
185  name: 'ServerPowerOperations',
186  components: { PageTitle, PageSection, BootSettings, Alert, InfoTooltip },
187  mixins: [BVToastMixin, LoadingBarMixin],
188  beforeRouteLeave(to, from, next) {
189    this.hideLoader();
190    next();
191  },
192  data() {
193    return {
194      $t: useI18n().t,
195      form: {
196        rebootOption: 'orderly',
197        shutdownOption: 'orderly',
198      },
199    };
200  },
201  computed: {
202    serverStatus() {
203      return this.$store.getters['global/serverStatus'];
204    },
205    isOperationInProgress() {
206      return this.$store.getters['controls/isOperationInProgress'];
207    },
208    lastPowerOperationTime() {
209      return this.$store.getters['controls/lastPowerOperationTime'];
210    },
211    oneTimeBootEnabled() {
212      return this.$store.getters['serverBootSettings/overrideEnabled'];
213    },
214    hasBootSourceOptions() {
215      let bootOptions =
216        this.$store.getters['serverBootSettings/bootSourceOptions'];
217      return bootOptions.length !== 0;
218    },
219  },
220  created() {
221    this.startLoader();
222    const bootSettingsPromise = new Promise((resolve) => {
223      this.$root.$on('server-power-operations-boot-settings-complete', () =>
224        resolve(),
225      );
226    });
227    Promise.all([
228      this.$store.dispatch('serverBootSettings/getBootSettings'),
229      this.$store.dispatch('controls/getLastPowerOperationTime'),
230      bootSettingsPromise,
231    ]).finally(() => this.endLoader());
232  },
233  methods: {
234    powerOn() {
235      this.$store.dispatch('controls/serverPowerOn');
236    },
237    rebootServer() {
238      const modalMessage = i18n.global.t(
239        'pageServerPowerOperations.modal.confirmRebootMessage',
240      );
241      const modalOptions = {
242        title: i18n.global.t(
243          'pageServerPowerOperations.modal.confirmRebootTitle',
244        ),
245        okTitle: i18n.global.t('global.action.confirm'),
246        cancelTitle: i18n.global.t('global.action.cancel'),
247        autoFocusButton: 'ok',
248      };
249
250      if (this.form.rebootOption === 'orderly') {
251        this.$bvModal
252          .msgBoxConfirm(modalMessage, modalOptions)
253          .then((confirmed) => {
254            if (confirmed) this.$store.dispatch('controls/serverSoftReboot');
255          });
256      } else if (this.form.rebootOption === 'immediate') {
257        this.$bvModal
258          .msgBoxConfirm(modalMessage, modalOptions)
259          .then((confirmed) => {
260            if (confirmed) this.$store.dispatch('controls/serverHardReboot');
261          });
262      }
263    },
264    shutdownServer() {
265      const modalMessage = i18n.global.t(
266        'pageServerPowerOperations.modal.confirmShutdownMessage',
267      );
268      const modalOptions = {
269        title: i18n.global.t(
270          'pageServerPowerOperations.modal.confirmShutdownTitle',
271        ),
272        okTitle: i18n.global.t('global.action.confirm'),
273        cancelTitle: i18n.global.t('global.action.cancel'),
274        autoFocusButton: 'ok',
275      };
276
277      if (this.form.shutdownOption === 'orderly') {
278        this.$bvModal
279          .msgBoxConfirm(modalMessage, modalOptions)
280          .then((confirmed) => {
281            if (confirmed) this.$store.dispatch('controls/serverSoftPowerOff');
282          });
283      }
284      if (this.form.shutdownOption === 'immediate') {
285        this.$bvModal
286          .msgBoxConfirm(modalMessage, modalOptions)
287          .then((confirmed) => {
288            if (confirmed) this.$store.dispatch('controls/serverHardPowerOff');
289          });
290      }
291    },
292  },
293};
294</script>
295