blob: 2f37c0171072ae92a40282b169db267b22329310 [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
9window.angular && (function (angular) {
10 'use strict';
11
12 angular
13 .module('app.overview')
14 .controller('systemOverviewController', [
Gunnar Millseedefd32018-02-28 17:02:34 -060015 '$scope',
16 '$window',
17 'APIUtils',
Iftekharul Islam99d199f2017-03-24 15:28:25 -050018 'dataService',
Michael Davis428375e2017-08-01 15:48:34 -050019 '$q',
Andrew Geisslercf862002018-04-11 12:19:39 -070020 function($scope, $window, APIUtils, dataService, $q){
Iftekharul Islam99d199f2017-03-24 15:28:25 -050021 $scope.dataService = dataService;
Iftekharul Islamcd789502017-04-19 14:37:55 -050022 $scope.dropdown_selected = false;
Iftekharul Islam54c22e42017-06-28 11:06:16 -050023 $scope.tmz = 'EDT';
24 $scope.logs = [];
Gunnar Mills17708f22018-04-13 14:21:31 -050025 $scope.server_info = {};
Iftekharul Islam54c22e42017-06-28 11:06:16 -050026 $scope.bmc_firmware = "";
Gunnar Millsed96f8b2018-04-19 15:33:40 -050027 $scope.bmc_time = "";
Iftekharul Islam54c22e42017-06-28 11:06:16 -050028 $scope.server_firmware = "";
CamVan Nguyen33275832018-03-13 18:38:37 -050029 $scope.power_consumption = "";
30 $scope.power_cap = "";
CamVan Nguyenfbb63db2018-05-02 13:33:51 -050031 $scope.bmc_ip_addresses = [];
Michael Davis428375e2017-08-01 15:48:34 -050032 $scope.loading = false;
Andrew Geisslerff2313d2018-05-03 13:03:11 -070033 $scope.edit_server_name = false;
Iftekharul Islam54c22e42017-06-28 11:06:16 -050034
35 loadOverviewData();
36 function loadOverviewData(){
Michael Davis428375e2017-08-01 15:48:34 -050037 $scope.loading = true;
CamVan Nguyen7db0e9a2018-05-04 19:30:01 -050038
39 var getLogsPromise =
40 APIUtils.getLogs().then(function(data){
41 $scope.logs = data.data.filter(function(log){
42 return log.severity_flags.high == true;
43 });
44 }, function(error){
45 console.log(JSON.stringify(error));
46 })
47
48 var getFirmwaresPromise =
49 APIUtils.getFirmwares().then(function(data){
50 $scope.bmc_firmware = data.bmcActiveVersion;
51 $scope.server_firmware = data.hostActiveVersion;
52 }, function(error){
53 console.log(JSON.stringify(error));
54 })
55
56 var getLEDStatePromise =
57 APIUtils.getLEDState().then(function(data){
58 if(data == APIUtils.LED_STATE.on){
59 dataService.LED_state = APIUtils.LED_STATE_TEXT.on;
60 }else{
61 dataService.LED_state = APIUtils.LED_STATE_TEXT.off;
62 }
63 }, function(error){
64 console.log(JSON.stringify(error));
65 })
66
67 var getBMCTimePromise =
68 APIUtils.getBMCTime().then(function(data){
69 $scope.bmc_time = data.data.Elapsed / 1000;
70 }, function(error){
71 console.log(JSON.stringify(error));
72 })
73
74 var getServerInfoPromise =
75 APIUtils.getServerInfo().then(function(data){
76 $scope.server_info = data.data;
77 }, function(error){
78 console.log(JSON.stringify(error));
79 })
80
81 var getPowerConsumptionPromise =
82 APIUtils.getPowerConsumption().then(function(data){
83 $scope.power_consumption = data;
84 }, function(error){
85 console.log(JSON.stringify(error));
86 })
87
88 var getPowerCapPromise =
89 APIUtils.getPowerCap().then(function(data){
90 $scope.power_cap = data;
91 }, function(error){
92 console.log(JSON.stringify(error));
93 })
94
95 var getNetworkInfoPromise =
96 APIUtils.getNetworkInfo().then(function(data){
97 // TODO: openbmc/openbmc#3150 Support IPV6 when
98 // officially supported by the backend
99 $scope.bmc_ip_addresses =
100 data.formatted_data.ip_addresses.ipv4;
101 }, function(error){
102 console.log(JSON.stringify(error));
103 })
104
105 var promises = [
106 getLogsPromise,
107 getFirmwaresPromise,
108 getLEDStatePromise,
109 getBMCTimePromise,
110 getServerInfoPromise,
111 getPowerConsumptionPromise,
112 getPowerCapPromise,
113 getNetworkInfoPromise,
114 ];
115
116 $q.all(promises).finally(function(){
Michael Davis428375e2017-08-01 15:48:34 -0500117 $scope.loading = false;
Iftekharul Islam54c22e42017-06-28 11:06:16 -0500118 });
119 }
120
Iftekharul Islam54c22e42017-06-28 11:06:16 -0500121 $scope.toggleLED = function(){
122 var toggleState = (dataService.LED_state == APIUtils.LED_STATE_TEXT.on) ?
123 APIUtils.LED_STATE.off : APIUtils.LED_STATE.on;
124 dataService.LED_state = (dataService.LED_state == APIUtils.LED_STATE_TEXT.on) ?
125 APIUtils.LED_STATE_TEXT.off : APIUtils.LED_STATE_TEXT.on;
126 APIUtils.setLEDState(toggleState, function(status){
127 });
128 }
CamVan Nguyen23217da2018-03-22 00:22:50 -0500129
Andrew Geisslerff2313d2018-05-03 13:03:11 -0700130 $scope.saveHostname = function(hostname) {
131 $scope.edit_server_name = false;
132 $scope.loading = true;
133 APIUtils.setHostname(hostname).then(function(data){
134 APIUtils.getNetworkInfo().then(function(data){
135 dataService.setNetworkInfo(data);
136 });
137 },
138 function(error){
139 console.log(error);
140 });
141 $scope.loading = false;
142 }
Iftekharul Islam99d199f2017-03-24 15:28:25 -0500143 }
144 ]
145 );
146
CamVan Nguyen23217da2018-03-22 00:22:50 -0500147})(angular);