Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 1 | /** |
Iftekharul Islam | cd78950 | 2017-04-19 14:37:55 -0500 | [diff] [blame] | 2 | * Controller for systemOverview |
Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 3 | * |
| 4 | * @module app/overview |
| 5 | * @exports systemOverviewController |
| 6 | * @name systemOverviewController |
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.overview').controller('systemOverviewController', [ |
Gunnar Mills | 006aaa0 | 2018-06-26 16:08:59 -0500 | [diff] [blame] | 13 | '$scope', '$window', 'APIUtils', 'dataService', 'Constants', '$q', |
| 14 | function($scope, $window, APIUtils, dataService, Constants, $q) { |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 15 | $scope.dataService = dataService; |
| 16 | $scope.dropdown_selected = false; |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 17 | $scope.logs = []; |
| 18 | $scope.server_info = {}; |
| 19 | $scope.bmc_firmware = ''; |
| 20 | $scope.bmc_time = ''; |
| 21 | $scope.server_firmware = ''; |
| 22 | $scope.power_consumption = ''; |
| 23 | $scope.power_cap = ''; |
| 24 | $scope.bmc_ip_addresses = []; |
| 25 | $scope.loading = false; |
| 26 | $scope.edit_hostname = false; |
dixsie | 565efda | 2019-04-16 13:30:30 -0500 | [diff] [blame] | 27 | $scope.newHostname = ''; |
Iftekharul Islam | 54c22e4 | 2017-06-28 11:06:16 -0500 | [diff] [blame] | 28 | |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 29 | loadOverviewData(); |
CamVan Nguyen | 7db0e9a | 2018-05-04 19:30:01 -0500 | [diff] [blame] | 30 | |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 31 | function loadOverviewData() { |
| 32 | $scope.loading = true; |
CamVan Nguyen | 7db0e9a | 2018-05-04 19:30:01 -0500 | [diff] [blame] | 33 | |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 34 | var getLogsPromise = APIUtils.getLogs().then( |
| 35 | function(data) { |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 36 | $scope.logs = data.data.filter(function(log) { |
| 37 | return log.severity_flags.high == true; |
| 38 | }); |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 39 | }, |
| 40 | function(error) { |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 41 | console.log(JSON.stringify(error)); |
| 42 | }); |
CamVan Nguyen | 7db0e9a | 2018-05-04 19:30:01 -0500 | [diff] [blame] | 43 | |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 44 | var getFirmwaresPromise = APIUtils.getFirmwares().then( |
| 45 | function(data) { |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 46 | $scope.bmc_firmware = data.bmcActiveVersion; |
| 47 | $scope.server_firmware = data.hostActiveVersion; |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 48 | }, |
| 49 | function(error) { |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 50 | console.log(JSON.stringify(error)); |
| 51 | }); |
CamVan Nguyen | 7db0e9a | 2018-05-04 19:30:01 -0500 | [diff] [blame] | 52 | |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 53 | var getLEDStatePromise = APIUtils.getLEDState().then( |
| 54 | function(data) { |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 55 | if (data == APIUtils.LED_STATE.on) { |
| 56 | dataService.LED_state = APIUtils.LED_STATE_TEXT.on; |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 57 | } else { |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 58 | dataService.LED_state = APIUtils.LED_STATE_TEXT.off; |
| 59 | } |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 60 | }, |
| 61 | function(error) { |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 62 | console.log(JSON.stringify(error)); |
| 63 | }); |
CamVan Nguyen | 7db0e9a | 2018-05-04 19:30:01 -0500 | [diff] [blame] | 64 | |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 65 | var getBMCTimePromise = APIUtils.getBMCTime().then( |
| 66 | function(data) { |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 67 | $scope.bmc_time = data.data.Elapsed / 1000; |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 68 | }, |
| 69 | function(error) { |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 70 | console.log(JSON.stringify(error)); |
| 71 | }); |
CamVan Nguyen | 7db0e9a | 2018-05-04 19:30:01 -0500 | [diff] [blame] | 72 | |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 73 | var getServerInfoPromise = APIUtils.getServerInfo().then( |
| 74 | function(data) { |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 75 | $scope.server_info = data.data; |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 76 | }, |
| 77 | function(error) { |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 78 | console.log(JSON.stringify(error)); |
| 79 | }); |
CamVan Nguyen | 7db0e9a | 2018-05-04 19:30:01 -0500 | [diff] [blame] | 80 | |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 81 | var getPowerConsumptionPromise = APIUtils.getPowerConsumption().then( |
| 82 | function(data) { |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 83 | $scope.power_consumption = data; |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 84 | }, |
| 85 | function(error) { |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 86 | console.log(JSON.stringify(error)); |
| 87 | }); |
CamVan Nguyen | 7db0e9a | 2018-05-04 19:30:01 -0500 | [diff] [blame] | 88 | |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 89 | var getPowerCapPromise = APIUtils.getPowerCap().then( |
| 90 | function(data) { |
Gunnar Mills | 006aaa0 | 2018-06-26 16:08:59 -0500 | [diff] [blame] | 91 | if (data.data.PowerCapEnable == false) { |
| 92 | $scope.power_cap = Constants.POWER_CAP_TEXT.disabled; |
| 93 | } else { |
| 94 | $scope.power_cap = |
| 95 | data.data.PowerCap + ' ' + Constants.POWER_CAP_TEXT.unit; |
| 96 | } |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 97 | }, |
| 98 | function(error) { |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 99 | console.log(JSON.stringify(error)); |
| 100 | }); |
CamVan Nguyen | 7db0e9a | 2018-05-04 19:30:01 -0500 | [diff] [blame] | 101 | |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 102 | var getNetworkInfoPromise = APIUtils.getNetworkInfo().then( |
| 103 | function(data) { |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 104 | // TODO: openbmc/openbmc#3150 Support IPV6 when |
| 105 | // officially supported by the backend |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 106 | $scope.bmc_ip_addresses = data.formatted_data.ip_addresses.ipv4; |
dixsie | 565efda | 2019-04-16 13:30:30 -0500 | [diff] [blame] | 107 | $scope.newHostname = data.hostname; |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 108 | }, |
| 109 | function(error) { |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 110 | console.log(JSON.stringify(error)); |
| 111 | }); |
CamVan Nguyen | 7db0e9a | 2018-05-04 19:30:01 -0500 | [diff] [blame] | 112 | |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 113 | var promises = [ |
| 114 | getLogsPromise, |
| 115 | getFirmwaresPromise, |
| 116 | getLEDStatePromise, |
| 117 | getBMCTimePromise, |
| 118 | getServerInfoPromise, |
| 119 | getPowerConsumptionPromise, |
| 120 | getPowerCapPromise, |
| 121 | getNetworkInfoPromise, |
| 122 | ]; |
Iftekharul Islam | 54c22e4 | 2017-06-28 11:06:16 -0500 | [diff] [blame] | 123 | |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 124 | $q.all(promises).finally(function() { |
| 125 | $scope.loading = false; |
| 126 | }); |
| 127 | } |
CamVan Nguyen | 23217da | 2018-03-22 00:22:50 -0500 | [diff] [blame] | 128 | |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 129 | $scope.toggleLED = function() { |
| 130 | var toggleState = |
| 131 | (dataService.LED_state == APIUtils.LED_STATE_TEXT.on) ? |
| 132 | APIUtils.LED_STATE.off : |
| 133 | APIUtils.LED_STATE.on; |
| 134 | dataService.LED_state = |
| 135 | (dataService.LED_state == APIUtils.LED_STATE_TEXT.on) ? |
| 136 | APIUtils.LED_STATE_TEXT.off : |
| 137 | APIUtils.LED_STATE_TEXT.on; |
| 138 | APIUtils.setLEDState(toggleState, function(status) {}); |
| 139 | }; |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 140 | |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 141 | $scope.saveHostname = function(hostname) { |
| 142 | $scope.edit_hostname = false; |
| 143 | $scope.loading = true; |
| 144 | APIUtils.setHostname(hostname).then( |
| 145 | function(data) { |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 146 | APIUtils.getNetworkInfo().then(function(data) { |
| 147 | dataService.setNetworkInfo(data); |
| 148 | }); |
| 149 | }, |
| 150 | function(error) { |
| 151 | console.log(error); |
| 152 | }); |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 153 | $scope.loading = false; |
| 154 | }; |
Matt Spinler | 845acdc | 2018-05-01 16:41:28 -0500 | [diff] [blame] | 155 | |
| 156 | $scope.getEventLogTitle = function(event) { |
| 157 | var title = event.type; |
| 158 | if ((event.eventID != 'None') && (event.description != 'None')) { |
| 159 | title = event.eventID + ': ' + event.description; |
| 160 | } |
| 161 | return title; |
| 162 | }; |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 163 | } |
| 164 | ]); |
CamVan Nguyen | 23217da | 2018-03-22 00:22:50 -0500 | [diff] [blame] | 165 | })(angular); |