blob: 2f038b9e4638f5e1a62d5f7fe54d85d7caa31af1 [file] [log] [blame]
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -08001<template>
2 <div>
3 <page-section :section-title="sectionTitle">
4 <b-card-group deck>
5 <!-- Running image -->
6 <b-card>
7 <template #header>
8 <p class="font-weight-bold m-0">
Yoshie Muranaka33d755f2021-02-18 15:24:14 -08009 {{ $t('pageFirmware.cardTitleRunning') }}
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -080010 </p>
11 </template>
12 <dl class="mb-0">
Yoshie Muranaka33d755f2021-02-18 15:24:14 -080013 <dt>{{ $t('pageFirmware.cardBodyVersion') }}</dt>
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -080014 <dd class="mb-0">{{ runningVersion }}</dd>
15 </dl>
16 </b-card>
17
18 <!-- Backup image -->
19 <b-card>
20 <template #header>
21 <p class="font-weight-bold m-0">
Yoshie Muranaka33d755f2021-02-18 15:24:14 -080022 {{ $t('pageFirmware.cardTitleBackup') }}
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -080023 </p>
24 </template>
25 <dl>
Yoshie Muranaka33d755f2021-02-18 15:24:14 -080026 <dt>{{ $t('pageFirmware.cardBodyVersion') }}</dt>
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -080027 <dd>
28 <status-icon v-if="showBackupImageStatus" status="danger" />
29 <span v-if="showBackupImageStatus" class="sr-only">
30 {{ backupStatus }}
31 </span>
32 {{ backupVersion }}
33 </dd>
34 </dl>
35 <b-btn
36 v-b-modal.modal-switch-to-running
37 data-test-id="firmware-button-switchToRunning"
38 variant="link"
39 size="sm"
40 class="py-0 px-1 mt-2"
41 :disabled="isPageDisabled || !backup"
42 >
43 <icon-switch class="d-none d-sm-inline-block" />
Yoshie Muranaka33d755f2021-02-18 15:24:14 -080044 {{ $t('pageFirmware.cardActionSwitchToRunning') }}
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -080045 </b-btn>
46 </b-card>
47 </b-card-group>
48 </page-section>
49 <modal-switch-to-running :backup="backupVersion" @ok="switchToRunning" />
50 </div>
51</template>
52
53<script>
54import IconSwitch from '@carbon/icons-vue/es/arrows--horizontal/20';
55import PageSection from '@/components/Global/PageSection';
56import LoadingBarMixin, { loading } from '@/components/Mixins/LoadingBarMixin';
57import BVToastMixin from '@/components/Mixins/BVToastMixin';
58
59import ModalSwitchToRunning from './FirmwareModalSwitchToRunning';
60
61export default {
62 components: { IconSwitch, ModalSwitchToRunning, PageSection },
63 mixins: [BVToastMixin, LoadingBarMixin],
64 props: {
65 isPageDisabled: {
66 required: true,
67 type: Boolean,
68 default: false,
69 },
70 },
71 data() {
72 return {
73 loading,
74 };
75 },
76 computed: {
77 isSingleFileUploadEnabled() {
Yoshie Muranaka33d755f2021-02-18 15:24:14 -080078 return this.$store.getters['firmware/isSingleFileUploadEnabled'];
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -080079 },
80 sectionTitle() {
81 if (this.isSingleFileUploadEnabled) {
Yoshie Muranaka33d755f2021-02-18 15:24:14 -080082 return this.$t('pageFirmware.sectionTitleBmcCardsCombined');
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -080083 }
Yoshie Muranaka33d755f2021-02-18 15:24:14 -080084 return this.$t('pageFirmware.sectionTitleBmcCards');
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -080085 },
86 running() {
Yoshie Muranaka33d755f2021-02-18 15:24:14 -080087 return this.$store.getters['firmware/activeBmcFirmware'];
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -080088 },
89 backup() {
Yoshie Muranaka33d755f2021-02-18 15:24:14 -080090 return this.$store.getters['firmware/backupBmcFirmware'];
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -080091 },
92 runningVersion() {
93 return this.running?.version || '--';
94 },
95 backupVersion() {
96 return this.backup?.version || '--';
97 },
98 backupStatus() {
99 return this.backup?.status || null;
100 },
101 showBackupImageStatus() {
102 return (
103 this.backupStatus === 'Critical' || this.backupStatus === 'Warning'
104 );
105 },
106 },
107 methods: {
108 switchToRunning() {
109 this.startLoader();
110 const timerId = setTimeout(() => {
111 this.endLoader();
Yoshie Muranaka33d755f2021-02-18 15:24:14 -0800112 this.infoToast(this.$t('pageFirmware.toast.verifySwitchMessage'), {
113 title: this.$t('pageFirmware.toast.verifySwitch'),
114 refreshAction: true,
115 });
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -0800116 }, 60000);
117
118 this.$store
Yoshie Muranaka33d755f2021-02-18 15:24:14 -0800119 .dispatch('firmware/switchBmcFirmwareAndReboot')
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -0800120 .then(() =>
Yoshie Muranaka33d755f2021-02-18 15:24:14 -0800121 this.infoToast(this.$t('pageFirmware.toast.rebootStartedMessage'), {
122 title: this.$t('pageFirmware.toast.rebootStarted'),
123 })
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -0800124 )
125 .catch(({ message }) => {
126 this.errorToast(message);
127 clearTimeout(timerId);
128 this.endLoader();
129 });
130 },
131 },
132};
133</script>