Add two file firmware update

Adds the ability to upload separate Host and BMC firmware images through
the GUI. By default, the two file firmware update page will be shown.
Changes to the .env configurations will enable the single file upload
page. The IBM env is configured to allow single file firmware update.

Two file upload features:
 - File upload through local workstation or tftp server
 - Reboot from backup BMC image
 - Does not have ability to reboot from backup host image
 - Does not implement checks in GUI for host status, which is the
   same as what we have in phosphor-webui

Signed-off-by: Yoshie Muranaka <yoshiemuranaka@gmail.com>
Change-Id: Ibf2a2d9ffc3952dd5a5454c723350c61d9f91c3e
diff --git a/src/views/Configuration/Firmware/Firmware.vue b/src/views/Configuration/Firmware/Firmware.vue
index e63db51..e1f97c4 100644
--- a/src/views/Configuration/Firmware/Firmware.vue
+++ b/src/views/Configuration/Firmware/Firmware.vue
@@ -1,59 +1,69 @@
 <template>
   <b-container fluid="xl">
     <page-title :description="$t('pageFirmware.pageDescription')" />
-    <!-- Operation in progress alert -->
-    <alert v-if="isOperationInProgress" variant="info" class="mb-5">
-      <p>
-        {{ $t('pageFirmware.alert.operationInProgress') }}
-      </p>
-    </alert>
-    <!-- Shutdown server warning alert -->
-    <alert v-else-if="!isHostOff" variant="warning" class="mb-5">
-      <p class="font-weight-bold mb-1">
-        {{ $t('pageFirmware.alert.serverShutdownRequiredBeforeUpdate') }}
-      </p>
-      {{ $t('pageFirmware.alert.serverShutdownRequiredInfo') }}
-      <template v-slot:action>
-        <b-btn variant="link" class="text-nowrap" @click="onClickShutDown">
-          {{ $t('pageFirmware.alert.shutDownServer') }}
-        </b-btn>
-      </template>
-    </alert>
     <b-row class="mb-4">
-      <!-- Firmware on system -->
       <b-col md="10" lg="12" xl="8" class="pr-xl-4">
-        <page-section :section-title="$t('pageFirmware.firmwareOnSystem')">
+        <!-- Firmware on BMC -->
+        <page-section :section-title="$t('pageFirmware.firmwareOnBmc')">
           <b-card-group deck>
             <!-- Current FW -->
             <b-card header-bg-variant="success">
               <template v-slot:header>
                 <dl class="mb-0">
                   <dt>{{ $t('pageFirmware.current') }}</dt>
-                  <dd class="mb-0">{{ systemFirmwareVersion }}</dd>
+                  <dd class="mb-0">{{ bmcFirmwareCurrentVersion }}</dd>
                 </dl>
               </template>
-              <b-row>
-                <b-col xs="6">
-                  <dl class="my-0">
-                    <dt>{{ $t('pageFirmware.bmcStatus') }}</dt>
-                    <dd>{{ $t('pageFirmware.running') }}</dd>
-                  </dl>
-                </b-col>
-                <b-col xs="6">
-                  <dl class="my-0">
-                    <dt>{{ $t('pageFirmware.hostStatus') }}</dt>
-                    <dd v-if="hostStatus === 'on'">
-                      {{ $t('global.status.on') }}
-                    </dd>
-                    <dd v-else-if="hostStatus === 'off'">
-                      {{ $t('global.status.off') }}
-                    </dd>
-                    <dd v-else>
-                      {{ $t('global.status.notAvailable') }}
-                    </dd>
-                  </dl>
-                </b-col>
-              </b-row>
+              <dl class="my-0">
+                <dt>{{ $t('pageFirmware.state') }}:</dt>
+                <dd>{{ bmcFirmwareCurrentState }}</dd>
+              </dl>
+              <template v-slot:footer></template>
+            </b-card>
+
+            <!-- Backup FW -->
+            <b-card footer-class="p-0">
+              <template v-slot:header>
+                <dl class="mb-0">
+                  <dt>{{ $t('pageFirmware.backup') }}</dt>
+                  <dd class="mb-0">{{ bmcFirmwareBackupVersion }}</dd>
+                </dl>
+              </template>
+              <dl class="my-0">
+                <dt>{{ $t('pageFirmware.state') }}:</dt>
+                <dd>{{ bmcFirmwareBackupState }}</dd>
+              </dl>
+              <template v-slot:footer>
+                <b-btn
+                  v-b-modal.modal-reboot-backup-bmc
+                  :disabled="!bmcFirmwareBackupVersion"
+                  variant="link"
+                  size="sm"
+                >
+                  <icon-switch class="d-none d-sm-inline-block" />
+                  {{ $t('pageFirmware.makeCurrentVersion') }}</b-btn
+                >
+              </template>
+            </b-card>
+          </b-card-group>
+        </page-section>
+
+        <!-- Firmware on Host -->
+        <page-section :section-title="$t('pageFirmware.firmwareOnHost')">
+          <b-card-group deck>
+            <!-- Current FW -->
+            <b-card header-bg-variant="success">
+              <template v-slot:header>
+                <dl class="mb-0">
+                  <dt>{{ $t('pageFirmware.current') }}</dt>
+                  <dd class="mb-0">{{ hostFirmwareCurrentVersion }}</dd>
+                </dl>
+              </template>
+              <!-- State -->
+              <dl class="my-0">
+                <dt>{{ $t('pageFirmware.state') }}:</dt>
+                <dd>{{ hostFirmwareCurrentState }}</dd>
+              </dl>
             </b-card>
 
             <!-- Backup FW -->
@@ -61,48 +71,24 @@
               <template v-slot:header>
                 <dl class="mb-0">
                   <dt>{{ $t('pageFirmware.backup') }}</dt>
-                  <dd class="mb-0">{{ backupFirmwareVersion }}</dd>
+                  <dd class="mb-0">{{ hostFirmwareBackupVersion }}</dd>
                 </dl>
               </template>
-              <b-row>
-                <b-col xs="6">
-                  <dl class="my-0">
-                    <dt>{{ $t('pageFirmware.state') }}</dt>
-                    <dd>{{ backupFirmwareStatus }}</dd>
-                  </dl>
-                </b-col>
-              </b-row>
+              <!-- State -->
+              <dl class="my-0">
+                <dt>{{ $t('pageFirmware.state') }}:</dt>
+                <dd>{{ hostFirmwareBackupState }}</dd>
+              </dl>
             </b-card>
           </b-card-group>
         </page-section>
-
-        <!-- Change to backup image -->
-        <page-section :section-title="$t('pageFirmware.changeToBackupImage')">
-          <dl class="mb-5">
-            <dt>
-              {{ $t('pageFirmware.backupImage') }}
-            </dt>
-            <dd>{{ backupFirmwareVersion }}</dd>
-          </dl>
-          <b-btn
-            v-b-modal.modal-reboot-backup
-            type="button"
-            variant="primary"
-            :disabled="isPageDisabled || !isRebootFromBackupAvailable"
-          >
-            {{ $t('pageFirmware.changeAndRebootBmc') }}
-          </b-btn>
-        </page-section>
       </b-col>
 
       <!-- Update code -->
       <b-col sm="8" xl="4" class="update-code pl-xl-4">
         <page-section :section-title="$t('pageFirmware.updateCode')">
           <b-form @submit.prevent="onSubmitUpload">
-            <b-form-group
-              :label="$t('pageFirmware.form.uploadLocation')"
-              :disabled="isPageDisabled"
-            >
+            <b-form-group :label="$t('pageFirmware.form.uploadLocation')">
               <b-form-radio v-model="isWorkstationSelected" :value="true">
                 {{ $t('pageFirmware.form.workstation') }}
               </b-form-radio>
@@ -128,7 +114,6 @@
                   :browse-text="$t('global.fileUpload.browseText')"
                   :drop-placeholder="$t('global.fileUpload.dropPlaceholder')"
                   :placeholder="$t('global.fileUpload.placeholder')"
-                  :disabled="isPageDisabled"
                   :state="getValidationState($v.file)"
                   @input="$v.file.$touch()"
                 />
@@ -169,7 +154,6 @@
                   v-model="tftpFileName"
                   type="text"
                   :state="getValidationState($v.tftpFileName)"
-                  :disabled="isPageDisabled"
                   @input="$v.tftpFileName.$touch()"
                 />
                 <b-form-invalid-feedback role="alert">
@@ -186,8 +170,8 @@
               <p>{{ $t('pageFirmware.alert.updateProcessInfo') }}</p>
             </alert>
             <b-form-group>
-              <b-btn type="submit" variant="primary" :disabled="isPageDisabled">
-                {{ $t('pageFirmware.form.uploadAndRebootBmc') }}
+              <b-btn type="submit" variant="primary">
+                {{ $t('pageFirmware.form.uploadAndRebootBmcOrHost') }}
               </b-btn>
             </b-form-group>
           </b-form>
@@ -197,10 +181,10 @@
 
     <!-- Modals -->
     <modal-upload @ok="uploadFirmware" />
-    <modal-reboot-backup
-      :current="systemFirmwareVersion"
-      :backup="backupFirmwareVersion"
-      @ok="rebootFromBackup"
+    <modal-reboot-backup-bmc
+      :current="bmcFirmwareCurrentVersion || '--'"
+      :backup="bmcFirmwareBackupVersion || '--'"
+      @ok="switchBmcFirmware"
     />
   </b-container>
 </template>
@@ -208,12 +192,13 @@
 <script>
 import { requiredIf } from 'vuelidate/lib/validators';
 import { mapGetters } from 'vuex';
+import IconSwitch from '@carbon/icons-vue/es/arrows--horizontal/20';
 
 import PageSection from '@/components/Global/PageSection';
 import PageTitle from '@/components/Global/PageTitle';
 import Alert from '@/components/Global/Alert';
 import ModalUpload from './FirmwareModalUpload';
-import ModalRebootBackup from './FirmwareModalRebootBackup';
+import ModalRebootBackupBmc from './FirmwareModalRebootBackupBmc';
 
 import VuelidateMixin from '@/components/Mixins/VuelidateMixin.js';
 import LoadingBarMixin from '@/components/Mixins/LoadingBarMixin';
@@ -223,7 +208,8 @@
   name: 'Firmware',
   components: {
     Alert,
-    ModalRebootBackup,
+    IconSwitch,
+    ModalRebootBackupBmc,
     ModalUpload,
     PageSection,
     PageTitle
@@ -239,24 +225,16 @@
     };
   },
   computed: {
-    hostStatus() {
-      return this.$store.getters['global/hostStatus'];
-    },
-    isHostOff() {
-      return this.hostStatus === 'off' ? true : false;
-    },
-    isOperationInProgress() {
-      return this.$store.getters['controls/isOperationInProgress'];
-    },
     ...mapGetters('firmware', [
-      'backupFirmwareStatus',
-      'backupFirmwareVersion',
-      'isRebootFromBackupAvailable',
-      'systemFirmwareVersion'
-    ]),
-    isPageDisabled() {
-      return !this.isHostOff || this.loading || this.isOperationInProgress;
-    }
+      'bmcFirmwareCurrentVersion',
+      'bmcFirmwareCurrentState',
+      'bmcFirmwareBackupVersion',
+      'bmcFirmwareBackupState',
+      'hostFirmwareCurrentVersion',
+      'hostFirmwareCurrentState',
+      'hostFirmwareBackupVersion',
+      'hostFirmwareBackupState'
+    ])
   },
   watch: {
     isWorkstationSelected: function() {
@@ -269,10 +247,9 @@
   created() {
     this.startLoader();
     this.$store.dispatch('firmware/getUpdateServiceApplyTime');
-    Promise.all([
-      this.$store.dispatch('global/getHostStatus'),
-      this.$store.dispatch('firmware/getSystemFirwareVersion')
-    ]).finally(() => this.endLoader());
+    this.$store
+      .dispatch('firmware/getFirmwareInformation')
+      .finally(() => this.endLoader());
   },
   beforeRouteLeave(to, from, next) {
     this.hideLoader();
@@ -344,10 +321,10 @@
           this.clearRebootTimeout();
         });
     },
-    rebootFromBackup() {
+    switchBmcFirmware() {
       this.setRebootTimeout();
       this.$store
-        .dispatch('firmware/switchFirmwareAndReboot')
+        .dispatch('firmware/switchBmcFirmware')
         .then(success =>
           this.infoToast(success, this.$t('global.status.success'))
         )
@@ -378,18 +355,6 @@
       this.$v.$touch();
       if (this.$v.$invalid) return;
       this.$bvModal.show('modal-upload');
-    },
-    onClickShutDown() {
-      this.$bvModal
-        .msgBoxConfirm(this.$t('pageFirmware.modal.serverShutdownMessage'), {
-          title: this.$t('pageFirmware.modal.serverShutdownWillCauseOutage'),
-          okTitle: this.$t('pageFirmware.modal.shutDownServer'),
-          okVariant: 'danger'
-        })
-        .then(shutdownConfirmed => {
-          if (shutdownConfirmed)
-            this.$store.dispatch('controls/hostSoftPowerOff');
-        });
     }
   }
 };
@@ -402,4 +367,10 @@
     border-left: 1px solid gray('300');
   }
 }
+.card-footer {
+  height: 41px;
+}
+.card-body {
+  padding: 0.75rem 1.25rem;
+}
 </style>
diff --git a/src/views/Configuration/Firmware/FirmwareModalRebootBackup.vue b/src/views/Configuration/Firmware/FirmwareModalRebootBackupBmc.vue
similarity index 95%
rename from src/views/Configuration/Firmware/FirmwareModalRebootBackup.vue
rename to src/views/Configuration/Firmware/FirmwareModalRebootBackupBmc.vue
index a8fb3ad..06ab65d 100644
--- a/src/views/Configuration/Firmware/FirmwareModalRebootBackup.vue
+++ b/src/views/Configuration/Firmware/FirmwareModalRebootBackupBmc.vue
@@ -1,6 +1,6 @@
 <template>
   <b-modal
-    id="modal-reboot-backup"
+    id="modal-reboot-backup-bmc"
     :ok-title="$t('pageFirmware.modal.rebootFromBackup.primaryAction')"
     :title="$t('pageFirmware.modal.rebootFromBackup.title')"
     @ok="$emit('ok')"
diff --git a/src/views/Configuration/Firmware/FirmwareModalUpload.vue b/src/views/Configuration/Firmware/FirmwareModalUpload.vue
index d092bec..d7ff05b 100644
--- a/src/views/Configuration/Firmware/FirmwareModalUpload.vue
+++ b/src/views/Configuration/Firmware/FirmwareModalUpload.vue
@@ -1,18 +1,19 @@
 <template>
   <b-modal
     id="modal-upload"
-    :title="$t('pageFirmware.modal.uploadAndReboot.title')"
-    :ok-title="$t('pageFirmware.modal.uploadAndReboot.primaryAction')"
+    ok-variant="danger"
+    :title="$t('pageFirmware.modal.uploadAndRebootBmcOrHost.title')"
+    :ok-title="$t('pageFirmware.modal.uploadAndRebootBmcOrHost.primaryAction')"
     @ok="$emit('ok')"
   >
     <p>
-      {{ $t('pageFirmware.modal.uploadAndReboot.message1') }}
+      {{ $t('pageFirmware.modal.uploadAndRebootBmcOrHost.message1') }}
     </p>
     <p>
-      {{ $t('pageFirmware.modal.uploadAndReboot.message2') }}
+      {{ $t('pageFirmware.modal.uploadAndRebootBmcOrHost.message2') }}
     </p>
     <p class="font-weight-bold">
-      {{ $t('pageFirmware.modal.uploadAndReboot.message3') }}
+      {{ $t('pageFirmware.modal.uploadAndRebootBmcOrHost.message3') }}
     </p>
   </b-modal>
 </template>