blob: 8d43613f9aafedae50d173a633f45bf53d58df04 [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;
Andrew Geisslerd27bb132018-05-24 11:07:27 -070017 $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;
dixsie565efda2019-04-16 13:30:30 -050027 $scope.newHostname = '';
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;
dixsie565efda2019-04-16 13:30:30 -0500107 $scope.newHostname = data.hostname;
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700108 },
109 function(error) {
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700110 console.log(JSON.stringify(error));
111 });
CamVan Nguyen7db0e9a2018-05-04 19:30:01 -0500112
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700113 var promises = [
114 getLogsPromise,
115 getFirmwaresPromise,
116 getLEDStatePromise,
117 getBMCTimePromise,
118 getServerInfoPromise,
119 getPowerConsumptionPromise,
120 getPowerCapPromise,
121 getNetworkInfoPromise,
122 ];
Iftekharul Islam54c22e42017-06-28 11:06:16 -0500123
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700124 $q.all(promises).finally(function() {
125 $scope.loading = false;
126 });
127 }
CamVan Nguyen23217da2018-03-22 00:22:50 -0500128
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700129 $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 Geisslerba5e3f32018-05-24 10:58:00 -0700140
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700141 $scope.saveHostname = function(hostname) {
142 $scope.edit_hostname = false;
143 $scope.loading = true;
144 APIUtils.setHostname(hostname).then(
145 function(data) {
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700146 APIUtils.getNetworkInfo().then(function(data) {
147 dataService.setNetworkInfo(data);
148 });
149 },
150 function(error) {
151 console.log(error);
152 });
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700153 $scope.loading = false;
154 };
Matt Spinler845acdc2018-05-01 16:41:28 -0500155
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 Geisslerd27bb132018-05-24 11:07:27 -0700163 }
164 ]);
CamVan Nguyen23217da2018-03-22 00:22:50 -0500165})(angular);