From 5a6e97bdca6db517eabb94a926623e2f662b1315 Mon Sep 17 00:00:00 2001 From: Kuiying Wang Date: Thu, 1 Aug 2019 17:37:17 +0800 Subject: [PATCH] force to bios fix bump fail Signed-off-by: Kuiying Wang --- app/common/services/api-utils.js | 30 ++++++++++++++++++ app/common/services/constants.js | 4 +++ app/common/services/dataService.js | 1 + .../controllers/power-operations-controller.html | 11 +++++++ .../controllers/power-operations-controller.js | 36 ++++++++++++++++++++-- 5 files changed, 80 insertions(+), 2 deletions(-) diff --git a/app/common/services/api-utils.js b/app/common/services/api-utils.js index d485016..3d64406 100644 --- a/app/common/services/api-utils.js +++ b/app/common/services/api-utils.js @@ -29,12 +29,42 @@ window.angular && (function(angular) { HOST_STATE_TEXT: Constants.HOST_STATE, LED_STATE: Constants.LED_STATE, LED_STATE_TEXT: Constants.LED_STATE_TEXT, + FORCE_TO_BIOS_STATE_TEXT: Constants.FORCE_TO_BIOS_STATE_TEXT, HOST_SESSION_STORAGE_KEY: Constants.API_CREDENTIALS.host_storage_key, validIPV4IP: function(ip) { // Checks for [0-255].[0-255].[0-255].[0-255] return ip.match( /\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b/); }, + setForceToBIOSState: function(state) { + console.log(state); + var data = JSON.stringify({'Boot': + { + 'BootSourceOverrideTarget': state + } + }); + return $http({ + method: 'PATCH', + url: DataService.getHost() + '/redfish/v1/Systems/system', + withCredentials: true, + data: data + }); + }, + getForceToBIOSState: function() { + + return $http({ + method: 'GET', + url: DataService.getHost() + '/redfish/v1/Systems/system', + withCredentials: true + }).then( + function(response) { + console.log(JSON.stringify(response.data.Boot.BootSourceOverrideTarget)); + return response.data.Boot.BootSourceOverrideTarget; + }, + function(error) { + console.log(error); + }); + }, getRedfishSysName: function() { return $http({ method: 'GET', diff --git a/app/common/services/constants.js b/app/common/services/constants.js index ae82e76..e594570 100644 --- a/app/common/services/constants.js +++ b/app/common/services/constants.js @@ -42,6 +42,10 @@ window.angular && (function(angular) { }, LED_STATE: {on: true, off: false}, LED_STATE_TEXT: {on: 'on', off: 'off'}, + FORCE_TO_BIOS_STATE_TEXT: { + on: 'BiosSetup', + off: 'None' + }, SEVERITY_TO_PRIORITY_MAP: { Emergency: 'High', Alert: 'High', diff --git a/app/common/services/dataService.js b/app/common/services/dataService.js index 87fddba..cc9c0b3 100644 --- a/app/common/services/dataService.js +++ b/app/common/services/dataService.js @@ -16,6 +16,7 @@ window.angular && (function(angular) { this.server_health = Constants.SERVER_HEALTH.unknown; this.server_state = 'Unreachable'; this.LED_state = Constants.LED_STATE_TEXT.off; + this.ForceToBIOS_state = Constants.FORCE_TO_BIOS_STATE_TEXT.off; this.last_updated = new Date(); this.loading = false; diff --git a/app/server-control/controllers/power-operations-controller.html b/app/server-control/controllers/power-operations-controller.html index ddf8bda..ea46e00 100644 --- a/app/server-control/controllers/power-operations-controller.html +++ b/app/server-control/controllers/power-operations-controller.html @@ -10,6 +10,17 @@

{{dataService.hostname}} - {{dataService.server_id}}

+
+ + +

Boot to BIOS

+

{{dataService.server_state | quiescedToError}}

diff --git a/app/server-control/controllers/power-operations-controller.js b/app/server-control/controllers/power-operations-controller.js index 986ac3b..2c29093 100644 --- a/app/server-control/controllers/power-operations-controller.js +++ b/app/server-control/controllers/power-operations-controller.js @@ -10,10 +10,10 @@ window.angular && (function(angular) { 'use strict'; angular.module('app.serverControl').controller('powerOperationsController', [ - '$scope', 'APIUtils', 'dataService', 'Constants', '$interval', '$q', + '$route', '$scope', 'APIUtils', 'dataService', 'Constants', '$interval', '$q', 'toastService', function( - $scope, APIUtils, dataService, Constants, $interval, $q, toastService) { + $route, $scope, APIUtils, dataService, Constants, $interval, $q, toastService) { $scope.dataService = dataService; // Is a || of the other 4 "confirm" variables to ensure only // one confirm is shown at a time. @@ -57,6 +57,17 @@ window.angular && (function(angular) { }, Constants.POLL_INTERVALS.POWER_OP); return deferred.promise; }; + APIUtils.getForceToBIOSState().then( + function(data) { + if (data == APIUtils.FORCE_TO_BIOS_STATE_TEXT.on) { + dataService.ForceToBIOS_state = APIUtils.FORCE_TO_BIOS_STATE_TEXT.on; + } else { + dataService.ForceToBIOS_state = APIUtils.FORCE_TO_BIOS_STATE_TEXT.off; + } + }, + function(error) { + console.log(JSON.stringify(error)); + }); APIUtils.getLastPowerTime() .then( @@ -74,6 +85,27 @@ window.angular && (function(angular) { $scope.loading = false; }); + $scope.toggleForceToBIOS = function() { + var toggleState = + (dataService.ForceToBIOS_state == APIUtils.FORCE_TO_BIOS_STATE_TEXT.on) ? + APIUtils.FORCE_TO_BIOS_STATE_TEXT.off : + APIUtils.FORCE_TO_BIOS_STATE_TEXT.on; + dataService.ForceToBIOS_state = + (dataService.ForceToBIOS_state == APIUtils.FORCE_TO_BIOS_STATE_TEXT.on) ? + APIUtils.FORCE_TO_BIOS_STATE_TEXT.off : + APIUtils.FORCE_TO_BIOS_STATE_TEXT.on; + APIUtils.setForceToBIOSState(toggleState) + .then( + function(response) {}, + function(errors) { + toastService.error( + 'Failed to set Boot to BIOS '); + console.log(JSON.stringify(errors)); + // Reload to get correct current state + $route.reload(); + }) + }; + $scope.toggleState = function() { dataService.server_state = (dataService.server_state == 'Running') ? 'Off' : 'Running'; -- 2.7.4