blob: e7d9c6b081a9cbb58c32c95500d5179617da637c [file] [log] [blame]
Iftekharul Islam99d199f2017-03-24 15:28:25 -05001/**
Iftekharul Islamcd789502017-04-19 14:37:55 -05002 * Controller for systemOverview
Iftekharul Islam99d199f2017-03-24 15:28:25 -05003 *
4 * @module app/overview
5 * @exports systemOverviewController
6 * @name systemOverviewController
Iftekharul Islam99d199f2017-03-24 15:28:25 -05007 */
8
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07009window.angular && (function(angular) {
10 'use strict';
Iftekharul Islam99d199f2017-03-24 15:28:25 -050011
Andrew Geisslerd27bb132018-05-24 11:07:27 -070012 angular.module('app.overview').controller('systemOverviewController', [
Gunnar Mills006aaa02018-06-26 16:08:59 -050013 '$scope', '$window', 'APIUtils', 'dataService', 'Constants', '$q',
14 function($scope, $window, APIUtils, dataService, Constants, $q) {
Andrew Geisslerd27bb132018-05-24 11:07:27 -070015 $scope.dataService = dataService;
16 $scope.dropdown_selected = false;
17 $scope.tmz = 'EDT';
18 $scope.logs = [];
19 $scope.server_info = {};
20 $scope.bmc_firmware = '';
21 $scope.bmc_time = '';
22 $scope.server_firmware = '';
23 $scope.power_consumption = '';
24 $scope.power_cap = '';
25 $scope.bmc_ip_addresses = [];
26 $scope.loading = false;
27 $scope.edit_hostname = false;
Iftekharul Islam54c22e42017-06-28 11:06:16 -050028
Andrew Geisslerd27bb132018-05-24 11:07:27 -070029 loadOverviewData();
CamVan Nguyen7db0e9a2018-05-04 19:30:01 -050030
Andrew Geisslerd27bb132018-05-24 11:07:27 -070031 function loadOverviewData() {
32 $scope.loading = true;
CamVan Nguyen7db0e9a2018-05-04 19:30:01 -050033
Andrew Geisslerd27bb132018-05-24 11:07:27 -070034 var getLogsPromise = APIUtils.getLogs().then(
35 function(data) {
Andrew Geisslerba5e3f32018-05-24 10:58:00 -070036 $scope.logs = data.data.filter(function(log) {
37 return log.severity_flags.high == true;
38 });
Andrew Geisslerd27bb132018-05-24 11:07:27 -070039 },
40 function(error) {
Andrew Geisslerba5e3f32018-05-24 10:58:00 -070041 console.log(JSON.stringify(error));
42 });
CamVan Nguyen7db0e9a2018-05-04 19:30:01 -050043
Andrew Geisslerd27bb132018-05-24 11:07:27 -070044 var getFirmwaresPromise = APIUtils.getFirmwares().then(
45 function(data) {
Andrew Geisslerba5e3f32018-05-24 10:58:00 -070046 $scope.bmc_firmware = data.bmcActiveVersion;
47 $scope.server_firmware = data.hostActiveVersion;
Andrew Geisslerd27bb132018-05-24 11:07:27 -070048 },
49 function(error) {
Andrew Geisslerba5e3f32018-05-24 10:58:00 -070050 console.log(JSON.stringify(error));
51 });
CamVan Nguyen7db0e9a2018-05-04 19:30:01 -050052
Andrew Geisslerd27bb132018-05-24 11:07:27 -070053 var getLEDStatePromise = APIUtils.getLEDState().then(
54 function(data) {
Andrew Geisslerba5e3f32018-05-24 10:58:00 -070055 if (data == APIUtils.LED_STATE.on) {
56 dataService.LED_state = APIUtils.LED_STATE_TEXT.on;
Andrew Geisslerd27bb132018-05-24 11:07:27 -070057 } else {
Andrew Geisslerba5e3f32018-05-24 10:58:00 -070058 dataService.LED_state = APIUtils.LED_STATE_TEXT.off;
59 }
Andrew Geisslerd27bb132018-05-24 11:07:27 -070060 },
61 function(error) {
Andrew Geisslerba5e3f32018-05-24 10:58:00 -070062 console.log(JSON.stringify(error));
63 });
CamVan Nguyen7db0e9a2018-05-04 19:30:01 -050064
Andrew Geisslerd27bb132018-05-24 11:07:27 -070065 var getBMCTimePromise = APIUtils.getBMCTime().then(
66 function(data) {
Andrew Geisslerba5e3f32018-05-24 10:58:00 -070067 $scope.bmc_time = data.data.Elapsed / 1000;
Andrew Geisslerd27bb132018-05-24 11:07:27 -070068 },
69 function(error) {
Andrew Geisslerba5e3f32018-05-24 10:58:00 -070070 console.log(JSON.stringify(error));
71 });
CamVan Nguyen7db0e9a2018-05-04 19:30:01 -050072
Andrew Geisslerd27bb132018-05-24 11:07:27 -070073 var getServerInfoPromise = APIUtils.getServerInfo().then(
74 function(data) {
Andrew Geisslerba5e3f32018-05-24 10:58:00 -070075 $scope.server_info = data.data;
Andrew Geisslerd27bb132018-05-24 11:07:27 -070076 },
77 function(error) {
Andrew Geisslerba5e3f32018-05-24 10:58:00 -070078 console.log(JSON.stringify(error));
79 });
CamVan Nguyen7db0e9a2018-05-04 19:30:01 -050080
Andrew Geisslerd27bb132018-05-24 11:07:27 -070081 var getPowerConsumptionPromise = APIUtils.getPowerConsumption().then(
82 function(data) {
Andrew Geisslerba5e3f32018-05-24 10:58:00 -070083 $scope.power_consumption = data;
Andrew Geisslerd27bb132018-05-24 11:07:27 -070084 },
85 function(error) {
Andrew Geisslerba5e3f32018-05-24 10:58:00 -070086 console.log(JSON.stringify(error));
87 });
CamVan Nguyen7db0e9a2018-05-04 19:30:01 -050088
Andrew Geisslerd27bb132018-05-24 11:07:27 -070089 var getPowerCapPromise = APIUtils.getPowerCap().then(
90 function(data) {
Gunnar Mills006aaa02018-06-26 16:08:59 -050091 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 Geisslerd27bb132018-05-24 11:07:27 -070097 },
98 function(error) {
Andrew Geisslerba5e3f32018-05-24 10:58:00 -070099 console.log(JSON.stringify(error));
100 });
CamVan Nguyen7db0e9a2018-05-04 19:30:01 -0500101
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700102 var getNetworkInfoPromise = APIUtils.getNetworkInfo().then(
103 function(data) {
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700104 // TODO: openbmc/openbmc#3150 Support IPV6 when
105 // officially supported by the backend
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700106 $scope.bmc_ip_addresses = data.formatted_data.ip_addresses.ipv4;
107 },
108 function(error) {
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700109 console.log(JSON.stringify(error));
110 });
CamVan Nguyen7db0e9a2018-05-04 19:30:01 -0500111
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700112 var promises = [
113 getLogsPromise,
114 getFirmwaresPromise,
115 getLEDStatePromise,
116 getBMCTimePromise,
117 getServerInfoPromise,
118 getPowerConsumptionPromise,
119 getPowerCapPromise,
120 getNetworkInfoPromise,
121 ];
Iftekharul Islam54c22e42017-06-28 11:06:16 -0500122
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700123 $q.all(promises).finally(function() {
124 $scope.loading = false;
125 });
126 }
CamVan Nguyen23217da2018-03-22 00:22:50 -0500127
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700128 $scope.toggleLED = function() {
129 var toggleState =
130 (dataService.LED_state == APIUtils.LED_STATE_TEXT.on) ?
131 APIUtils.LED_STATE.off :
132 APIUtils.LED_STATE.on;
133 dataService.LED_state =
134 (dataService.LED_state == APIUtils.LED_STATE_TEXT.on) ?
135 APIUtils.LED_STATE_TEXT.off :
136 APIUtils.LED_STATE_TEXT.on;
137 APIUtils.setLEDState(toggleState, function(status) {});
138 };
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700139
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700140 $scope.saveHostname = function(hostname) {
141 $scope.edit_hostname = false;
142 $scope.loading = true;
143 APIUtils.setHostname(hostname).then(
144 function(data) {
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700145 APIUtils.getNetworkInfo().then(function(data) {
146 dataService.setNetworkInfo(data);
147 });
148 },
149 function(error) {
150 console.log(error);
151 });
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700152 $scope.loading = false;
153 };
Matt Spinler845acdc2018-05-01 16:41:28 -0500154
155 $scope.getEventLogTitle = function(event) {
156 var title = event.type;
157 if ((event.eventID != 'None') && (event.description != 'None')) {
158 title = event.eventID + ': ' + event.description;
159 }
160 return title;
161 };
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700162 }
163 ]);
CamVan Nguyen23217da2018-03-22 00:22:50 -0500164})(angular);