Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 1 | /** |
| 2 | * Controller for power-operations |
| 3 | * |
Iftekharul Islam | cd78950 | 2017-04-19 14:37:55 -0500 | [diff] [blame] | 4 | * @module app/serverControl |
Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 5 | * @exports powerOperationsController |
| 6 | * @name powerOperationsController |
Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 7 | */ |
| 8 | |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 9 | window.angular && (function(angular) { |
| 10 | 'use strict'; |
Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 11 | |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 12 | angular.module('app.serverControl').controller('powerOperationsController', [ |
Yoshie Muranaka | 5ff9878 | 2019-07-18 15:36:39 -0500 | [diff] [blame] | 13 | '$scope', 'APIUtils', 'dataService', 'Constants', '$interval', '$q', |
Dixsie Wolmers | e368108 | 2019-06-21 13:48:06 -0500 | [diff] [blame] | 14 | 'toastService', '$uibModal', |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 15 | function( |
Dixsie Wolmers | e368108 | 2019-06-21 13:48:06 -0500 | [diff] [blame] | 16 | $scope, APIUtils, dataService, Constants, $interval, $q, toastService, |
| 17 | $uibModal) { |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 18 | $scope.dataService = dataService; |
Gunnar Mills | 6add832 | 2018-09-05 15:16:12 -0500 | [diff] [blame] | 19 | $scope.loading = true; |
Dixsie Wolmers | e368108 | 2019-06-21 13:48:06 -0500 | [diff] [blame] | 20 | $scope.oneTimeBootEnabled = false; |
| 21 | $scope.bootOverrideError = false; |
| 22 | $scope.bootSources = []; |
| 23 | $scope.boot = {}; |
| 24 | $scope.defaultRebootSetting = 'warm-reboot'; |
| 25 | $scope.defaultShutdownSetting = 'warm-shutdown'; |
| 26 | |
| 27 | $scope.activeModal; |
Iftekharul Islam | a1d238f | 2018-02-26 12:29:45 -0600 | [diff] [blame] | 28 | |
Yoshie Muranaka | 5ff9878 | 2019-07-18 15:36:39 -0500 | [diff] [blame] | 29 | // When a power operation is in progress, set to true, |
| 30 | // when a power operation completes (success/fail) set to false. |
| 31 | // This property is used to show/hide the 'in progress' message |
| 32 | // in markup. |
| 33 | $scope.operationPending = false; |
Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 34 | |
Dixsie Wolmers | e368108 | 2019-06-21 13:48:06 -0500 | [diff] [blame] | 35 | const modalTemplate = require('./power-operations-modal.html'); |
| 36 | |
| 37 | const powerOperations = |
| 38 | {WARM_REBOOT: 0, COLD_REBOOT: 1, WARM_SHUTDOWN: 2, COLD_SHUTDOWN: 3}; |
| 39 | |
Yoshie Muranaka | afcfda7 | 2019-06-21 09:19:32 -0500 | [diff] [blame] | 40 | /** |
| 41 | * Checks the host status provided by the dataService using an |
| 42 | * interval timer |
| 43 | * @param {string} statusType : host status type to check for |
Yoshie Muranaka | 5ff9878 | 2019-07-18 15:36:39 -0500 | [diff] [blame] | 44 | * @param {number} timeout : timeout limit, defaults to 5 minutes |
| 45 | * @param {string} error : error message, defaults to 'Time out' |
Yoshie Muranaka | afcfda7 | 2019-06-21 09:19:32 -0500 | [diff] [blame] | 46 | * @returns {Promise} : returns a deferred promise that will be fulfilled |
| 47 | * if the status is met or be rejected if the timeout is reached |
| 48 | */ |
Dixsie Wolmers | e368108 | 2019-06-21 13:48:06 -0500 | [diff] [blame] | 49 | const checkHostStatus = |
Yoshie Muranaka | 5ff9878 | 2019-07-18 15:36:39 -0500 | [diff] [blame] | 50 | (statusType, timeout = 300000, error = 'Time out.') => { |
| 51 | const deferred = $q.defer(); |
| 52 | const start = new Date(); |
| 53 | const checkHostStatusInverval = $interval(() => { |
| 54 | let now = new Date(); |
| 55 | let timePassed = now.getTime() - start.getTime(); |
| 56 | if (timePassed > timeout) { |
| 57 | deferred.reject(error); |
| 58 | $interval.cancel(checkHostStatusInverval); |
| 59 | } |
| 60 | if (dataService.server_state === statusType) { |
| 61 | deferred.resolve(); |
| 62 | $interval.cancel(checkHostStatusInverval); |
| 63 | } |
| 64 | }, Constants.POLL_INTERVALS.POWER_OP); |
| 65 | return deferred.promise; |
| 66 | }; |
Yoshie Muranaka | afcfda7 | 2019-06-21 09:19:32 -0500 | [diff] [blame] | 67 | |
Yoshie Muranaka | 5ff9878 | 2019-07-18 15:36:39 -0500 | [diff] [blame] | 68 | /** |
| 69 | * Initiate Orderly reboot |
| 70 | * Attempts to stop all software |
| 71 | */ |
Dixsie Wolmers | e368108 | 2019-06-21 13:48:06 -0500 | [diff] [blame] | 72 | const warmReboot = () => { |
Yoshie Muranaka | 5ff9878 | 2019-07-18 15:36:39 -0500 | [diff] [blame] | 73 | $scope.operationPending = true; |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 74 | dataService.setUnreachableState(); |
| 75 | APIUtils.hostReboot() |
Yoshie Muranaka | 5ff9878 | 2019-07-18 15:36:39 -0500 | [diff] [blame] | 76 | .then(() => { |
| 77 | // Check for off state |
| 78 | return checkHostStatus( |
| 79 | Constants.HOST_STATE_TEXT.off, Constants.TIMEOUT.HOST_OFF, |
| 80 | Constants.MESSAGES.POLL.HOST_OFF_TIMEOUT); |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 81 | }) |
Yoshie Muranaka | 5ff9878 | 2019-07-18 15:36:39 -0500 | [diff] [blame] | 82 | .then(() => { |
| 83 | // Check for on state |
| 84 | return checkHostStatus( |
| 85 | Constants.HOST_STATE_TEXT.on, Constants.TIMEOUT.HOST_ON, |
| 86 | Constants.MESSAGES.POLL.HOST_ON_TIMEOUT); |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 87 | }) |
Dixsie Wolmers | e368108 | 2019-06-21 13:48:06 -0500 | [diff] [blame] | 88 | .catch(error => { |
Yoshie Muranaka | 5ff9878 | 2019-07-18 15:36:39 -0500 | [diff] [blame] | 89 | console.log(error); |
beccabroek | 27ce84d | 2019-02-05 15:43:17 -0600 | [diff] [blame] | 90 | toastService.error( |
| 91 | Constants.MESSAGES.POWER_OP.WARM_REBOOT_FAILED); |
Yoshie Muranaka | 5ff9878 | 2019-07-18 15:36:39 -0500 | [diff] [blame] | 92 | }) |
| 93 | .finally(() => { |
| 94 | $scope.operationPending = false; |
Dixsie Wolmers | e368108 | 2019-06-21 13:48:06 -0500 | [diff] [blame] | 95 | }); |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 96 | }; |
| 97 | |
Yoshie Muranaka | 5ff9878 | 2019-07-18 15:36:39 -0500 | [diff] [blame] | 98 | /** |
| 99 | * Initiate Immediate reboot |
| 100 | * Does not attempt to stop all software |
| 101 | */ |
Dixsie Wolmers | e368108 | 2019-06-21 13:48:06 -0500 | [diff] [blame] | 102 | const coldReboot = () => { |
Yoshie Muranaka | 5ff9878 | 2019-07-18 15:36:39 -0500 | [diff] [blame] | 103 | $scope.operationPending = true; |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 104 | dataService.setUnreachableState(); |
| 105 | APIUtils.chassisPowerOff() |
Yoshie Muranaka | 5ff9878 | 2019-07-18 15:36:39 -0500 | [diff] [blame] | 106 | .then(() => { |
| 107 | // Check for off state |
Yoshie Muranaka | afcfda7 | 2019-06-21 09:19:32 -0500 | [diff] [blame] | 108 | return checkHostStatus( |
| 109 | Constants.HOST_STATE_TEXT.off, |
| 110 | Constants.TIMEOUT.HOST_OFF_IMMEDIATE, |
| 111 | Constants.MESSAGES.POLL.HOST_OFF_TIMEOUT); |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 112 | }) |
Yoshie Muranaka | 5ff9878 | 2019-07-18 15:36:39 -0500 | [diff] [blame] | 113 | .then(() => { |
Yoshie Muranaka | afcfda7 | 2019-06-21 09:19:32 -0500 | [diff] [blame] | 114 | return APIUtils.hostPowerOn(); |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 115 | }) |
Yoshie Muranaka | 5ff9878 | 2019-07-18 15:36:39 -0500 | [diff] [blame] | 116 | .then(() => { |
| 117 | // Check for on state |
Yoshie Muranaka | afcfda7 | 2019-06-21 09:19:32 -0500 | [diff] [blame] | 118 | return checkHostStatus( |
| 119 | Constants.HOST_STATE_TEXT.on, Constants.TIMEOUT.HOST_ON, |
| 120 | Constants.MESSAGES.POLL.HOST_ON_TIMEOUT); |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 121 | }) |
Dixsie Wolmers | e368108 | 2019-06-21 13:48:06 -0500 | [diff] [blame] | 122 | .catch(error => { |
Yoshie Muranaka | afcfda7 | 2019-06-21 09:19:32 -0500 | [diff] [blame] | 123 | console.log(error); |
beccabroek | 27ce84d | 2019-02-05 15:43:17 -0600 | [diff] [blame] | 124 | toastService.error( |
| 125 | Constants.MESSAGES.POWER_OP.COLD_REBOOT_FAILED); |
Yoshie Muranaka | afcfda7 | 2019-06-21 09:19:32 -0500 | [diff] [blame] | 126 | }) |
Yoshie Muranaka | 5ff9878 | 2019-07-18 15:36:39 -0500 | [diff] [blame] | 127 | .finally(() => { |
| 128 | $scope.operationPending = false; |
Dixsie Wolmers | e368108 | 2019-06-21 13:48:06 -0500 | [diff] [blame] | 129 | }); |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 130 | }; |
| 131 | |
Yoshie Muranaka | 5ff9878 | 2019-07-18 15:36:39 -0500 | [diff] [blame] | 132 | /** |
| 133 | * Initiate Orderly shutdown |
| 134 | * Attempts to stop all software |
| 135 | */ |
Dixsie Wolmers | e368108 | 2019-06-21 13:48:06 -0500 | [diff] [blame] | 136 | const orderlyShutdown = () => { |
Yoshie Muranaka | 5ff9878 | 2019-07-18 15:36:39 -0500 | [diff] [blame] | 137 | $scope.operationPending = true; |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 138 | dataService.setUnreachableState(); |
| 139 | APIUtils.hostPowerOff() |
Yoshie Muranaka | 5ff9878 | 2019-07-18 15:36:39 -0500 | [diff] [blame] | 140 | .then(() => { |
| 141 | // Check for off state |
| 142 | return checkHostStatus( |
| 143 | Constants.HOST_STATE_TEXT.off, Constants.TIMEOUT.HOST_OFF, |
| 144 | Constants.MESSAGES.POLL.HOST_OFF_TIMEOUT); |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 145 | }) |
Dixsie Wolmers | e368108 | 2019-06-21 13:48:06 -0500 | [diff] [blame] | 146 | .catch(error => { |
Yoshie Muranaka | 5ff9878 | 2019-07-18 15:36:39 -0500 | [diff] [blame] | 147 | console.log(error); |
beccabroek | 27ce84d | 2019-02-05 15:43:17 -0600 | [diff] [blame] | 148 | toastService.error( |
beccabroek | 92d13b6 | 2019-01-08 14:24:29 -0600 | [diff] [blame] | 149 | Constants.MESSAGES.POWER_OP.ORDERLY_SHUTDOWN_FAILED); |
Yoshie Muranaka | 5ff9878 | 2019-07-18 15:36:39 -0500 | [diff] [blame] | 150 | }) |
| 151 | .finally(() => { |
| 152 | $scope.operationPending = false; |
Dixsie Wolmers | e368108 | 2019-06-21 13:48:06 -0500 | [diff] [blame] | 153 | }); |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 154 | }; |
| 155 | |
Yoshie Muranaka | 5ff9878 | 2019-07-18 15:36:39 -0500 | [diff] [blame] | 156 | /** |
| 157 | * Initiate Immediate shutdown |
| 158 | * Does not attempt to stop all software |
| 159 | */ |
Dixsie Wolmers | e368108 | 2019-06-21 13:48:06 -0500 | [diff] [blame] | 160 | const immediateShutdown = () => { |
Yoshie Muranaka | 5ff9878 | 2019-07-18 15:36:39 -0500 | [diff] [blame] | 161 | $scope.operationPending = true; |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 162 | dataService.setUnreachableState(); |
| 163 | APIUtils.chassisPowerOff() |
Yoshie Muranaka | 5ff9878 | 2019-07-18 15:36:39 -0500 | [diff] [blame] | 164 | .then(() => { |
| 165 | // Check for off state |
| 166 | return checkHostStatus( |
| 167 | Constants.HOST_STATE_TEXT.off, |
| 168 | Constants.TIMEOUT.HOST_OFF_IMMEDIATE, |
| 169 | Constants.MESSAGES.POLL.HOST_OFF_TIMEOUT); |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 170 | }) |
Yoshie Muranaka | 5ff9878 | 2019-07-18 15:36:39 -0500 | [diff] [blame] | 171 | .then(() => { |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 172 | dataService.setPowerOffState(); |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 173 | }) |
Dixsie Wolmers | e368108 | 2019-06-21 13:48:06 -0500 | [diff] [blame] | 174 | .catch(error => { |
Yoshie Muranaka | 5ff9878 | 2019-07-18 15:36:39 -0500 | [diff] [blame] | 175 | console.log(error); |
beccabroek | 27ce84d | 2019-02-05 15:43:17 -0600 | [diff] [blame] | 176 | toastService.error( |
beccabroek | 92d13b6 | 2019-01-08 14:24:29 -0600 | [diff] [blame] | 177 | Constants.MESSAGES.POWER_OP.IMMEDIATE_SHUTDOWN_FAILED); |
Yoshie Muranaka | 5ff9878 | 2019-07-18 15:36:39 -0500 | [diff] [blame] | 178 | }) |
| 179 | .finally(() => { |
| 180 | $scope.operationPending = false; |
Dixsie Wolmers | e368108 | 2019-06-21 13:48:06 -0500 | [diff] [blame] | 181 | }); |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 182 | }; |
Yoshie Muranaka | 5ff9878 | 2019-07-18 15:36:39 -0500 | [diff] [blame] | 183 | |
Dixsie Wolmers | e368108 | 2019-06-21 13:48:06 -0500 | [diff] [blame] | 184 | /** |
| 185 | * Initiate Power on |
| 186 | */ |
| 187 | $scope.powerOn = () => { |
| 188 | $scope.operationPending = true; |
| 189 | dataService.setUnreachableState(); |
| 190 | APIUtils.hostPowerOn() |
| 191 | .then(() => { |
| 192 | // Check for on state |
| 193 | return checkHostStatus( |
| 194 | Constants.HOST_STATE_TEXT.on, Constants.TIMEOUT.HOST_ON, |
| 195 | Constants.MESSAGES.POLL.HOST_ON_TIMEOUT); |
| 196 | }) |
| 197 | .catch(error => { |
| 198 | console.log(error); |
| 199 | toastService.error(Constants.MESSAGES.POWER_OP.POWER_ON_FAILED); |
| 200 | }) |
| 201 | .finally(() => { |
| 202 | $scope.operationPending = false; |
| 203 | }); |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 204 | }; |
Dixsie Wolmers | e368108 | 2019-06-21 13:48:06 -0500 | [diff] [blame] | 205 | |
| 206 | /* |
| 207 | * Power operations modal |
| 208 | */ |
| 209 | const initPowerOperation = function(powerOperation) { |
| 210 | switch (powerOperation) { |
| 211 | case powerOperations.WARM_REBOOT: |
| 212 | warmReboot(); |
| 213 | break; |
| 214 | case powerOperations.COLD_REBOOT: |
| 215 | coldReboot(); |
| 216 | break; |
| 217 | case powerOperations.WARM_SHUTDOWN: |
| 218 | orderlyShutdown(); |
| 219 | break; |
| 220 | case powerOperations.COLD_SHUTDOWN: |
| 221 | immediateShutdown(); |
| 222 | break; |
| 223 | default: |
| 224 | // do nothing |
| 225 | } |
| 226 | }; |
| 227 | |
| 228 | const powerOperationModal = function() { |
| 229 | $uibModal |
| 230 | .open({ |
| 231 | template: modalTemplate, |
| 232 | windowTopClass: 'uib-modal', |
| 233 | scope: $scope, |
| 234 | ariaLabelledBy: 'modal-operation' |
| 235 | }) |
| 236 | .result |
| 237 | .then(function(activeModal) { |
| 238 | initPowerOperation(activeModal); |
| 239 | }) |
| 240 | .finally(function() { |
| 241 | $scope.activeModal = undefined; |
| 242 | }); |
| 243 | }; |
| 244 | |
| 245 | $scope.rebootConfirmModal = function() { |
| 246 | if ($scope.rebootForm.radioReboot.$modelValue == 'warm-reboot') { |
| 247 | $scope.activeModal = powerOperations.WARM_REBOOT; |
| 248 | } else if ($scope.rebootForm.radioReboot.$modelValue == 'cold-reboot') { |
| 249 | $scope.activeModal = powerOperations.COLD_REBOOT; |
| 250 | } |
| 251 | powerOperationModal(); |
| 252 | }; |
| 253 | |
| 254 | $scope.shutdownConfirmModal = function() { |
| 255 | if ($scope.shutdownForm.radioShutdown.$modelValue == 'warm-shutdown') { |
| 256 | $scope.activeModal = powerOperations.WARM_SHUTDOWN; |
| 257 | } else if ( |
| 258 | $scope.shutdownForm.radioShutdown.$modelValue == 'cold-shutdown') { |
| 259 | $scope.activeModal = powerOperations.COLD_SHUTDOWN; |
| 260 | } |
| 261 | powerOperationModal(); |
| 262 | }; |
| 263 | |
| 264 | $scope.resetForm = function() { |
| 265 | $scope.boot = angular.copy($scope.originalBoot); |
| 266 | $scope.TPMToggle = angular.copy($scope.originalTPMToggle); |
| 267 | }; |
| 268 | |
| 269 | /* |
| 270 | * Get boot settings |
| 271 | */ |
| 272 | const loadBootSettings = function() { |
| 273 | APIUtils.getBootOptions() |
| 274 | .then(function(response) { |
| 275 | const boot = response.Boot; |
| 276 | const BootSourceOverrideEnabled = |
| 277 | boot['BootSourceOverrideEnabled']; |
| 278 | const BootSourceOverrideTarget = boot['BootSourceOverrideTarget']; |
| 279 | const bootSourceValues = |
| 280 | boot['BootSourceOverrideTarget@Redfish.AllowableValues']; |
| 281 | |
| 282 | $scope.bootSources = bootSourceValues; |
| 283 | |
| 284 | $scope.boot = { |
| 285 | BootSourceOverrideEnabled: BootSourceOverrideEnabled, |
| 286 | BootSourceOverrideTarget: BootSourceOverrideTarget |
| 287 | }; |
| 288 | |
| 289 | if (BootSourceOverrideEnabled == 'Once') { |
| 290 | $scope.boot.oneTimeBootEnabled = true; |
| 291 | } |
| 292 | |
| 293 | $scope.originalBoot = angular.copy($scope.boot); |
| 294 | }) |
| 295 | .catch(function(error) { |
| 296 | $scope.bootOverrideError = true; |
| 297 | toastService.error('Unable to get boot override values.'); |
| 298 | console.log( |
| 299 | 'Error loading boot settings:', JSON.stringify(error)); |
| 300 | }); |
| 301 | $scope.loading = false; |
| 302 | }; |
| 303 | |
| 304 | /* |
| 305 | * Get TPM status |
| 306 | */ |
| 307 | const loadTPMStatus = function() { |
| 308 | APIUtils.getTPMStatus() |
| 309 | .then(function(response) { |
| 310 | $scope.TPMToggle = response.data; |
| 311 | $scope.originalTPMToggle = angular.copy($scope.TPMToggle); |
| 312 | }) |
| 313 | .catch(function(error) { |
| 314 | toastService.error('Unable to get TPM policy status.'); |
| 315 | console.log('Error loading TPM status', JSON.stringify(error)); |
| 316 | }); |
| 317 | $scope.loading = false; |
| 318 | }; |
| 319 | |
| 320 | /* |
| 321 | * Save boot settings |
| 322 | */ |
| 323 | $scope.saveBootSettings = function() { |
| 324 | if ($scope.hostBootSettings.bootSelected.$dirty || |
| 325 | $scope.hostBootSettings.oneTime.$dirty) { |
| 326 | const data = {}; |
| 327 | data.Boot = {}; |
| 328 | |
| 329 | let isOneTimeBoot = $scope.boot.oneTimeBootEnabled; |
| 330 | let overrideTarget = $scope.boot.BootSourceOverrideTarget || 'None'; |
| 331 | let overrideEnabled = 'Disabled'; |
| 332 | |
| 333 | if (isOneTimeBoot) { |
| 334 | overrideEnabled = 'Once'; |
| 335 | } else if (overrideTarget !== 'None') { |
| 336 | overrideEnabled = 'Continuous'; |
| 337 | } |
| 338 | |
| 339 | data.Boot.BootSourceOverrideEnabled = overrideEnabled; |
| 340 | data.Boot.BootSourceOverrideTarget = overrideTarget; |
| 341 | |
| 342 | APIUtils.saveBootSettings(data).then( |
| 343 | function(response) { |
| 344 | $scope.originalBoot = angular.copy($scope.boot); |
| 345 | toastService.success('Successfully updated boot settings.'); |
| 346 | }, |
| 347 | function(error) { |
| 348 | toastService.error('Unable to save boot settings.'); |
| 349 | console.log(JSON.stringify(error)); |
| 350 | }); |
| 351 | } |
| 352 | }; |
| 353 | |
| 354 | /* |
| 355 | * Save TPM required policy |
| 356 | */ |
| 357 | $scope.saveTPMPolicy = function() { |
| 358 | if ($scope.hostBootSettings.toggle.$dirty) { |
| 359 | const tpmEnabled = $scope.TPMToggle.TPMEnable; |
| 360 | |
| 361 | if (tpmEnabled === undefined) { |
| 362 | return; |
| 363 | } |
| 364 | |
| 365 | APIUtils.saveTPMEnable(tpmEnabled) |
| 366 | .then( |
| 367 | function(response) { |
| 368 | $scope.originalTPMToggle = angular.copy($scope.TPMToggle); |
| 369 | toastService.success( |
| 370 | 'Sucessfully updated TPM required policy.'); |
| 371 | }, |
| 372 | function(error) { |
| 373 | toastService.error('Unable to update TPM required policy.'); |
| 374 | console.log(JSON.stringify(error)); |
| 375 | }); |
| 376 | } |
| 377 | }; |
| 378 | |
Yoshie Muranaka | 5dac9e1 | 2019-09-23 12:01:36 -0700 | [diff] [blame] | 379 | /** |
| 380 | * Callback when boot setting option changed |
| 381 | */ |
| 382 | $scope.onChangeBootSetting = function() { |
| 383 | const bootSetting = $scope.hostBootSettings.bootSelected.$viewValue; |
| 384 | if (bootSetting === 'None') { |
| 385 | $scope.boot.oneTimeBootEnabled = false; |
| 386 | } |
| 387 | }; |
| 388 | |
Dixsie Wolmers | e368108 | 2019-06-21 13:48:06 -0500 | [diff] [blame] | 389 | /* |
| 390 | * Emitted every time the view is reloaded |
| 391 | */ |
| 392 | $scope.$on('$viewContentLoaded', function() { |
| 393 | APIUtils.getLastPowerTime() |
| 394 | .then( |
| 395 | function(data) { |
| 396 | if (data.data == 0) { |
| 397 | $scope.powerTime = 'not available'; |
| 398 | } else { |
| 399 | $scope.powerTime = data.data; |
| 400 | } |
| 401 | }, |
| 402 | function(error) { |
| 403 | toastService.error( |
| 404 | 'Unable to get last power operation time.'); |
| 405 | console.log(JSON.stringify(error)); |
| 406 | }) |
| 407 | .finally(function() { |
| 408 | $scope.loading = false; |
| 409 | }); |
| 410 | |
| 411 | loadBootSettings(); |
| 412 | loadTPMStatus(); |
| 413 | }); |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 414 | } |
| 415 | ]); |
Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 416 | })(angular); |