blob: 6268f8c13f864c92516ea390cf509a3d57bb5027 [file] [log] [blame]
Iftekharul Islam99d199f2017-03-24 15:28:25 -05001/**
2 * API utilities service
3 *
4 * @module app/common/services/api-utils
5 * @exports APIUtils
6 * @name APIUtils
7 * @version 0.0.1
8 */
9
10window.angular && (function (angular) {
11 'use strict';
12 angular
13 .module('app.common.services')
Iftekharul Islam1acb4122017-11-02 13:20:32 -050014 .factory('APIUtils', ['$http', 'Constants', '$q', 'dataService',function($http, Constants, $q, DataService){
Iftekharul Islam99d199f2017-03-24 15:28:25 -050015 var SERVICE = {
16 LOGIN_CREDENTIALS: Constants.LOGIN_CREDENTIALS,
17 API_CREDENTIALS: Constants.API_CREDENTIALS,
18 API_RESPONSE: Constants.API_RESPONSE,
19 CHASSIS_POWER_STATE: Constants.CHASSIS_POWER_STATE,
20 HOST_STATE_TEXT: Constants.HOST_STATE,
21 HOST_STATE: Constants.HOST_STATE,
Iftekharul Islamcd789502017-04-19 14:37:55 -050022 LED_STATE: Constants.LED_STATE,
23 LED_STATE_TEXT: Constants.LED_STATE_TEXT,
Iftekharul Islam1acb4122017-11-02 13:20:32 -050024 HOST_SESSION_STORAGE_KEY: Constants.API_CREDENTIALS.host_storage_key,
Iftekharul Islam99d199f2017-03-24 15:28:25 -050025 getChassisState: function(callback){
26 $http({
27 method: 'GET',
Iftekharul Islam1acb4122017-11-02 13:20:32 -050028 url: DataService.getHost() + "/xyz/openbmc_project/state/chassis0",
Iftekharul Islam99d199f2017-03-24 15:28:25 -050029 headers: {
30 'Accept': 'application/json',
31 'Content-Type': 'application/json'
32 },
33 withCredentials: true
Ed Tanousbbcf6702017-10-06 13:53:06 -070034 }).then(function(response){
35 var json = JSON.stringify(response.data);
Iftekharul Islam99d199f2017-03-24 15:28:25 -050036 var content = JSON.parse(json);
37 callback(content.data.CurrentPowerState);
Ed Tanousbbcf6702017-10-06 13:53:06 -070038 }, function(error){
Iftekharul Islam99d199f2017-03-24 15:28:25 -050039 console.log(error);
40 });
41 },
42 getHostState: function(callback){
43 $http({
44 method: 'GET',
Iftekharul Islam1acb4122017-11-02 13:20:32 -050045 url: DataService.getHost() + "/xyz/openbmc_project/state/host0",
Iftekharul Islam99d199f2017-03-24 15:28:25 -050046 headers: {
47 'Accept': 'application/json',
48 'Content-Type': 'application/json'
49 },
50 withCredentials: true
Ed Tanousbbcf6702017-10-06 13:53:06 -070051 }).then(function(response){
52 var json = JSON.stringify(response.data);
Iftekharul Islam99d199f2017-03-24 15:28:25 -050053 var content = JSON.parse(json);
54 callback(content.data.CurrentHostState);
Ed Tanousbbcf6702017-10-06 13:53:06 -070055 }, function(error){
Iftekharul Islam99d199f2017-03-24 15:28:25 -050056 console.log(error);
57 });
58 },
Iftekharul Islam171c6a12017-08-11 08:35:47 -050059 getNetworkInfo: function(){
60 var deferred = $q.defer();
61 $http({
62 method: 'GET',
Iftekharul Islam1acb4122017-11-02 13:20:32 -050063 url: DataService.getHost() + "/xyz/openbmc_project/network/enumerate",
Iftekharul Islam171c6a12017-08-11 08:35:47 -050064 headers: {
65 'Accept': 'application/json',
66 'Content-Type': 'application/json'
67 },
68 withCredentials: true
Ed Tanousbbcf6702017-10-06 13:53:06 -070069 }).then(function(response){
70 var json = JSON.stringify(response.data);
Iftekharul Islam171c6a12017-08-11 08:35:47 -050071 var content = JSON.parse(json);
72 var hostname = "";
73 var macAddress = "";
74
Iftekharul Islam2a489552017-11-02 13:23:08 -050075 function parseNetworkData(content){
76 var data = {
77 interface_ids: [],
78 interfaces: {
79 }
80 };
81 var interfaceId = '', keyParts = [], interfaceHash = '', interfaceType = '';
82 for(var key in content.data){
83 if(key.match(/network\/eth\d+$/ig)){
84 interfaceId = key.split("/").pop();
85 if(data.interface_ids.indexOf(interfaceId) == -1){
86 data.interface_ids.push(interfaceId);
87 data.interfaces[interfaceId] = {
88 interfaceIname: '',
89 domainName:'',
90 MACAddress:'',
91 Nameservers: [],
92 DHCPEnabled: 0,
93 ipv4:
94 {
95 ids: [],
96 values: []
97 },
98 ipv6:
99 {
100 ids: [],
101 values: []
102 }
103 };
104 data.interfaces[interfaceId].MACAddress = content.data[key].MACAddress;
105 data.interfaces[interfaceId].DomainName = content.data[key].DomainName.join(" ");
106 data.interfaces[interfaceId].Nameservers = content.data[key].Nameservers;
107 data.interfaces[interfaceId].DHCPEnabled = content.data[key].DHCPEnabled;
108 }
109 }else if(key.match(/network\/eth\d+\/ipv[4|6]\/[a-z0-9]+$/ig)){
110 keyParts = key.split("/");
111 interfaceHash = keyParts.pop();
112 interfaceType = keyParts.pop();
113 interfaceId = keyParts.pop();
114
115 if(data.interfaces[interfaceId][interfaceType].ids.indexOf(interfaceHash) == -1){
116 data.interfaces[interfaceId][interfaceType].ids.push(interfaceHash);
117 data.interfaces[interfaceId][interfaceType].values.push(content.data[key]);
118 }
119 }
120 }
121 return data;
122 }
123
Iftekharul Islam171c6a12017-08-11 08:35:47 -0500124 if(content.data.hasOwnProperty('/xyz/openbmc_project/network/config') &&
125 content.data['/xyz/openbmc_project/network/config'].hasOwnProperty('HostName')
126 ){
127 hostname = content.data['/xyz/openbmc_project/network/config'].HostName;
128 }
129
130 if(content.data.hasOwnProperty('/xyz/openbmc_project/network/eth0') &&
131 content.data['/xyz/openbmc_project/network/eth0'].hasOwnProperty('MACAddress')
132 ){
133 macAddress = content.data['/xyz/openbmc_project/network/eth0'].MACAddress;
134 }
135
136 deferred.resolve({
137 data: content.data,
138 hostname: hostname,
139 mac_address: macAddress,
Iftekharul Islam2a489552017-11-02 13:23:08 -0500140 formatted_data: parseNetworkData(content)
Iftekharul Islam171c6a12017-08-11 08:35:47 -0500141 });
Ed Tanousbbcf6702017-10-06 13:53:06 -0700142 }, function(error){
Iftekharul Islam171c6a12017-08-11 08:35:47 -0500143 console.log(error);
144 deferred.reject(error);
145 });
146 return deferred.promise;
147 },
Michael Davisdf3bd122017-08-10 11:03:42 -0500148 getLEDState: function(){
149 var deferred = $q.defer();
Iftekharul Islamcd789502017-04-19 14:37:55 -0500150 $http({
151 method: 'GET',
Iftekharul Islam1acb4122017-11-02 13:20:32 -0500152 url: DataService.getHost() + "/xyz/openbmc_project/led/groups/enclosure_identify",
Iftekharul Islamcd789502017-04-19 14:37:55 -0500153 headers: {
154 'Accept': 'application/json',
155 'Content-Type': 'application/json'
156 },
157 withCredentials: true
Ed Tanousbbcf6702017-10-06 13:53:06 -0700158 }).then(function(response){
159 var json = JSON.stringify(response.data);
Michael Davisdf3bd122017-08-10 11:03:42 -0500160 var content = JSON.parse(json);
161 deferred.resolve(content.data.Asserted);
Ed Tanousbbcf6702017-10-06 13:53:06 -0700162 }, function(error){
Iftekharul Islamcd789502017-04-19 14:37:55 -0500163 console.log(error);
Michael Davisdf3bd122017-08-10 11:03:42 -0500164 deferred.reject(error);
Iftekharul Islamcd789502017-04-19 14:37:55 -0500165 });
Michael Davisdf3bd122017-08-10 11:03:42 -0500166 return deferred.promise;
Iftekharul Islamcd789502017-04-19 14:37:55 -0500167 },
Iftekharul Islam99d199f2017-03-24 15:28:25 -0500168 login: function(username, password, callback){
169 $http({
170 method: 'POST',
Iftekharul Islam1acb4122017-11-02 13:20:32 -0500171 url: DataService.getHost() + "/login",
Iftekharul Islam99d199f2017-03-24 15:28:25 -0500172 headers: {
173 'Accept': 'application/json',
174 'Content-Type': 'application/json'
175 },
176 withCredentials: true,
177 data: JSON.stringify({"data": [username, password]})
Ed Tanousbbcf6702017-10-06 13:53:06 -0700178 }).then(function(response){
Iftekharul Islam99d199f2017-03-24 15:28:25 -0500179 if(callback){
Ed Tanousbbcf6702017-10-06 13:53:06 -0700180 callback(response.data);
Iftekharul Islam99d199f2017-03-24 15:28:25 -0500181 }
Ed Tanousbbcf6702017-10-06 13:53:06 -0700182 }, function(error){
Iftekharul Islam99d199f2017-03-24 15:28:25 -0500183 if(callback){
Iftekharul Islamcd789502017-04-19 14:37:55 -0500184 if(error && error.status && error.status == 'error'){
185 callback(error);
186 }else{
187 callback(error, true);
188 }
Iftekharul Islam99d199f2017-03-24 15:28:25 -0500189 }
190 console.log(error);
191 });
192 },
193 logout: function(callback){
194 $http({
195 method: 'POST',
Iftekharul Islam1acb4122017-11-02 13:20:32 -0500196 url: DataService.getHost() + "/logout",
Iftekharul Islam99d199f2017-03-24 15:28:25 -0500197 headers: {
198 'Accept': 'application/json',
199 'Content-Type': 'application/json'
200 },
201 withCredentials: true,
202 data: JSON.stringify({"data": []})
Ed Tanousbbcf6702017-10-06 13:53:06 -0700203 }).then(function(response){
Iftekharul Islam99d199f2017-03-24 15:28:25 -0500204 if(callback){
Iftekharul Islamde883402018-02-05 11:16:21 -0600205 callback(response.data);
Iftekharul Islam99d199f2017-03-24 15:28:25 -0500206 }
Ed Tanousbbcf6702017-10-06 13:53:06 -0700207 }, function(error){
Iftekharul Islam99d199f2017-03-24 15:28:25 -0500208 if(callback){
209 callback(null, error);
210 }
211 console.log(error);
212 });
213 },
214 chassisPowerOn: function(callback){
215 $http({
216 method: 'POST',
Iftekharul Islam1acb4122017-11-02 13:20:32 -0500217 url: DataService.getHost() + "/xyz/openbmc_project/state/host0",
Iftekharul Islam99d199f2017-03-24 15:28:25 -0500218 headers: {
219 'Accept': 'application/json',
220 'Content-Type': 'application/json'
221 },
222 withCredentials: true,
223 data: JSON.stringify({"data": []})
Ed Tanousbbcf6702017-10-06 13:53:06 -0700224 }).then(function(response){
225 var json = JSON.stringify(response.data);
Iftekharul Islam99d199f2017-03-24 15:28:25 -0500226 var content = JSON.parse(json);
227 if(callback){
228 return callback(content.data.CurrentPowerState);
229 }
Ed Tanousbbcf6702017-10-06 13:53:06 -0700230 }, function(error){
Iftekharul Islam99d199f2017-03-24 15:28:25 -0500231 if(callback){
232 callback(error);
233 }else{
234 console.log(error);
235 }
236 });
237 },
238 chassisPowerOff: function(callback){
239 $http({
Gunnar Mills3aa8b532018-02-06 15:42:29 -0600240 method: 'PUT',
241 url: DataService.getHost() + "/xyz/openbmc_project/state/chassis0/attr/RequestedPowerTransition",
Iftekharul Islam99d199f2017-03-24 15:28:25 -0500242 headers: {
243 'Accept': 'application/json',
244 'Content-Type': 'application/json'
245 },
246 withCredentials: true,
Gunnar Mills3aa8b532018-02-06 15:42:29 -0600247 data: JSON.stringify({"data": "xyz.openbmc_project.State.Chassis.Transition.Off"})
Ed Tanousbbcf6702017-10-06 13:53:06 -0700248 }).then(function(response){
249 var json = JSON.stringify(response.data);
Iftekharul Islam99d199f2017-03-24 15:28:25 -0500250 var content = JSON.parse(json);
251 if(callback){
Gunnar Mills3aa8b532018-02-06 15:42:29 -0600252 return callback(content.status);
Iftekharul Islam99d199f2017-03-24 15:28:25 -0500253 }
Ed Tanousbbcf6702017-10-06 13:53:06 -0700254 }, function(error){
Iftekharul Islam99d199f2017-03-24 15:28:25 -0500255 if(callback){
256 callback(error);
257 }else{
258 console.log(error);
259 }
260 });
261 },
Iftekharul Islamcd789502017-04-19 14:37:55 -0500262 setLEDState: function(state, callback){
263 $http({
264 method: 'PUT',
Iftekharul Islam1acb4122017-11-02 13:20:32 -0500265 url: DataService.getHost() + "/xyz/openbmc_project/led/groups/enclosure_identify/attr/Asserted",
Iftekharul Islamcd789502017-04-19 14:37:55 -0500266 headers: {
267 'Accept': 'application/json',
268 'Content-Type': 'application/json'
269 },
270 withCredentials: true,
271 data: JSON.stringify({"data": state})
Ed Tanousbbcf6702017-10-06 13:53:06 -0700272 }).then(function(response){
273 var json = JSON.stringify(response.data);
Iftekharul Islamcd789502017-04-19 14:37:55 -0500274 var content = JSON.parse(json);
275 if(callback){
276 return callback(content.status);
277 }
Ed Tanousbbcf6702017-10-06 13:53:06 -0700278 }, function(error){
Iftekharul Islamcd789502017-04-19 14:37:55 -0500279 if(callback){
280 callback(error);
281 }else{
282 console.log(error);
283 }
284 });
285 },
Iftekharul Islam55368122017-03-27 09:46:50 -0500286 bmcReboot: function(callback){
287 $http({
288 method: 'PUT',
Iftekharul Islam1acb4122017-11-02 13:20:32 -0500289 url: DataService.getHost() + "/xyz/openbmc_project/state/bmc0/attr/RequestedBmcTransition",
Iftekharul Islam55368122017-03-27 09:46:50 -0500290 headers: {
291 'Accept': 'application/json',
292 'Content-Type': 'application/json'
293 },
294 withCredentials: true,
295 data: JSON.stringify({"data": "xyz.openbmc_project.State.BMC.Transition.Reboot"})
Ed Tanousbbcf6702017-10-06 13:53:06 -0700296 }).then(function(response){
297 var json = JSON.stringify(response.data);
Iftekharul Islam55368122017-03-27 09:46:50 -0500298 var content = JSON.parse(json);
299 if(callback){
300 return callback(content.status);
301 }
Ed Tanousbbcf6702017-10-06 13:53:06 -0700302 }, function(error){
Iftekharul Islam55368122017-03-27 09:46:50 -0500303 if(callback){
304 callback(error);
305 }else{
306 console.log(error);
307 }
308 });
309 },
Iftekharul Islam99d199f2017-03-24 15:28:25 -0500310 hostPowerOn: function(callback){
Iftekharul Islam99d199f2017-03-24 15:28:25 -0500311 $http({
312 method: 'PUT',
Iftekharul Islam1acb4122017-11-02 13:20:32 -0500313 url: DataService.getHost() + "/xyz/openbmc_project/state/host0/attr/RequestedHostTransition",
Iftekharul Islam99d199f2017-03-24 15:28:25 -0500314 headers: {
315 'Accept': 'application/json',
316 'Content-Type': 'application/json'
317 },
318 withCredentials: true,
319 data: JSON.stringify({"data": "xyz.openbmc_project.State.Host.Transition.On"})
Ed Tanousbbcf6702017-10-06 13:53:06 -0700320 }).then(function(response){
321 var json = JSON.stringify(response.data);
Iftekharul Islam99d199f2017-03-24 15:28:25 -0500322 var content = JSON.parse(json);
323 if(callback){
324 return callback(content.status);
325 }
Ed Tanousbbcf6702017-10-06 13:53:06 -0700326 }, function(error){
Iftekharul Islam99d199f2017-03-24 15:28:25 -0500327 if(callback){
328 callback(error);
329 }else{
330 console.log(error);
331 }
332 });
333 },
334 hostPowerOff: function(callback){
335 $http({
336 method: 'PUT',
Iftekharul Islam1acb4122017-11-02 13:20:32 -0500337 url: DataService.getHost() + "/xyz/openbmc_project/state/host0/attr/RequestedHostTransition",
Iftekharul Islam99d199f2017-03-24 15:28:25 -0500338 headers: {
339 'Accept': 'application/json',
340 'Content-Type': 'application/json'
341 },
342 withCredentials: true,
343 data: JSON.stringify({"data": "xyz.openbmc_project.State.Host.Transition.Off"})
Ed Tanousbbcf6702017-10-06 13:53:06 -0700344 }).then(function(response){
345 var json = JSON.stringify(response.data);
Iftekharul Islam99d199f2017-03-24 15:28:25 -0500346 var content = JSON.parse(json);
347 if(callback){
348 return callback(content.status);
349 }
Ed Tanousbbcf6702017-10-06 13:53:06 -0700350 }, function(error){
Iftekharul Islam99d199f2017-03-24 15:28:25 -0500351 if(callback){
352 callback(error);
353 }else{
354 console.log(error);
355 }
356 });
357 },
358 hostReboot: function(callback){
359 $http({
Gunnar Millscacfa6d2018-02-07 12:09:02 -0600360 method: 'PUT',
361 url: DataService.getHost() + "/xyz/openbmc_project/state/host0/attr/RequestedHostTransition",
Iftekharul Islam99d199f2017-03-24 15:28:25 -0500362 headers: {
363 'Accept': 'application/json',
364 'Content-Type': 'application/json'
365 },
366 withCredentials: true,
Gunnar Millscacfa6d2018-02-07 12:09:02 -0600367 data: JSON.stringify({"data": "xyz.openbmc_project.State.Host.Transition.Reboot"})
Ed Tanousbbcf6702017-10-06 13:53:06 -0700368 }).then(function(response){
369 var json = JSON.stringify(response.data);
Iftekharul Islam99d199f2017-03-24 15:28:25 -0500370 var content = JSON.parse(json);
371 if(callback){
Gunnar Millscacfa6d2018-02-07 12:09:02 -0600372 return callback(content.status);
Iftekharul Islam99d199f2017-03-24 15:28:25 -0500373 }
Ed Tanousbbcf6702017-10-06 13:53:06 -0700374 }, function(error){
Iftekharul Islam99d199f2017-03-24 15:28:25 -0500375 if(callback){
376 callback(error);
377 }else{
378 console.log(error);
379 }
380 });
381 },
382 hostShutdown: function(callback){
383 $http({
384 method: 'POST',
Iftekharul Islam1acb4122017-11-02 13:20:32 -0500385 url: DataService.getHost() + "/xyz/openbmc_project/state/host0",
Iftekharul Islam99d199f2017-03-24 15:28:25 -0500386 headers: {
387 'Accept': 'application/json',
388 'Content-Type': 'application/json'
389 },
390 withCredentials: true,
391 data: JSON.stringify({"data": []})
Ed Tanousbbcf6702017-10-06 13:53:06 -0700392 }).then(function(response){
393 var json = JSON.stringify(response.data);
Iftekharul Islam99d199f2017-03-24 15:28:25 -0500394 var content = JSON.parse(json);
395 if(callback){
396 return callback(content);
397 }
Ed Tanousbbcf6702017-10-06 13:53:06 -0700398 }, function(error){
Iftekharul Islam99d199f2017-03-24 15:28:25 -0500399 if(callback){
400 callback(error);
401 }else{
402 console.log(error);
403 }
404 });
Iftekharul Islamcd789502017-04-19 14:37:55 -0500405 },
Michael Davisdf3bd122017-08-10 11:03:42 -0500406 getLogs: function(){
407 var deferred = $q.defer();
Iftekharul Islamcd789502017-04-19 14:37:55 -0500408 $http({
409 method: 'GET',
Iftekharul Islam1acb4122017-11-02 13:20:32 -0500410 url: DataService.getHost() + "/xyz/openbmc_project/logging/enumerate",
Iftekharul Islamcd789502017-04-19 14:37:55 -0500411 headers: {
412 'Accept': 'application/json',
413 'Content-Type': 'application/json'
414 },
415 withCredentials: true
Ed Tanousbbcf6702017-10-06 13:53:06 -0700416 }).then(function(response){
417 var json = JSON.stringify(response.data);
Iftekharul Islamcd789502017-04-19 14:37:55 -0500418 var content = JSON.parse(json);
419 var dataClone = JSON.parse(JSON.stringify(content.data));
420 var data = [];
421 var severityCode = '';
422 var priority = '';
Iftekharul Islamec6bcd12017-09-06 10:49:07 -0500423 var health = '';
Iftekharul Islamcd789502017-04-19 14:37:55 -0500424 var relatedItems = [];
425
426 for(var key in content.data){
427 if(content.data.hasOwnProperty(key) && content.data[key].hasOwnProperty('Id')){
428 var severityFlags = {low: false, medium: false, high: false};
Iftekharul Islamec6bcd12017-09-06 10:49:07 -0500429 var healthFlags = {critical: false, warning: false, good: false};
Iftekharul Islamcd789502017-04-19 14:37:55 -0500430 severityCode = content.data[key].Severity.split(".").pop();
431 priority = Constants.SEVERITY_TO_PRIORITY_MAP[severityCode];
432 severityFlags[priority.toLowerCase()] = true;
Iftekharul Islamec6bcd12017-09-06 10:49:07 -0500433 health = Constants.SEVERITY_TO_HEALTH_MAP[severityCode];
434 healthFlags[health.toLowerCase()] = true;
Iftekharul Islamcd789502017-04-19 14:37:55 -0500435 relatedItems = [];
436 content.data[key].associations.forEach(function(item){
Iftekharul Islam532763f2017-04-25 09:44:40 -0500437 relatedItems.push(item[2]);
Iftekharul Islamcd789502017-04-19 14:37:55 -0500438 });
439
440 data.push(Object.assign({
441 path: key,
442 copied: false,
443 priority: priority,
444 severity_code: severityCode,
445 severity_flags: severityFlags,
Iftekharul Islamec6bcd12017-09-06 10:49:07 -0500446 health_flags: healthFlags,
Iftekharul Islamcd789502017-04-19 14:37:55 -0500447 additional_data: content.data[key].AdditionalData.join("\n"),
Gunnar Mills43a2ed12018-02-08 15:42:30 -0600448 type: content.data[key].Message,
Iftekharul Islamcd789502017-04-19 14:37:55 -0500449 selected: false,
Iftekharul Islam8b4828a2017-04-19 14:37:55 -0500450 search_text: ("#" + content.data[key].Id + " " + severityCode + " " + content.data[key].Severity + " " + content.data[key].AdditionalData.join(" ")).toLowerCase(),
Iftekharul Islamcd789502017-04-19 14:37:55 -0500451 meta: false,
452 confirm: false,
453 related_items: relatedItems,
454 data: {key: key, value: content.data[key]}
455 }, content.data[key]));
456 }
457 }
Michael Davisdf3bd122017-08-10 11:03:42 -0500458 deferred.resolve({data: data, original: dataClone});
Ed Tanousbbcf6702017-10-06 13:53:06 -0700459 }, function(error){
Iftekharul Islamcd789502017-04-19 14:37:55 -0500460 console.log(error);
Michael Davisdf3bd122017-08-10 11:03:42 -0500461 deferred.reject(error);
Iftekharul Islamcd789502017-04-19 14:37:55 -0500462 });
Michael Davisdf3bd122017-08-10 11:03:42 -0500463
464 return deferred.promise;
Iftekharul Islamd2269e22017-05-02 09:32:45 -0500465 },
466 getAllSensorStatus: function(callback){
Iftekharul Islamd2269e22017-05-02 09:32:45 -0500467 $http({
468 method: 'GET',
Iftekharul Islam1acb4122017-11-02 13:20:32 -0500469 url: DataService.getHost() + "/xyz/openbmc_project/sensors/enumerate",
Iftekharul Islamd2269e22017-05-02 09:32:45 -0500470 headers: {
471 'Accept': 'application/json',
472 'Content-Type': 'application/json'
473 },
474 withCredentials: true
Ed Tanousbbcf6702017-10-06 13:53:06 -0700475 }).then(function(response){
476 var json = JSON.stringify(response.data);
Iftekharul Islamd2269e22017-05-02 09:32:45 -0500477 var content = JSON.parse(json);
478 var dataClone = JSON.parse(JSON.stringify(content.data));
479 var sensorData = [];
Iftekharul Islam8947e702017-07-27 10:28:07 -0500480 var severity = {};
481 var title = "";
482 var tempKeyParts = [];
483 var order = 0;
Iftekharul Islam8a122842017-09-11 10:58:16 -0500484 var customOrder = 0;
Iftekharul Islamd2269e22017-05-02 09:32:45 -0500485
Iftekharul Islam96bbf312017-08-22 13:44:38 -0500486 function getScaledValue(value, scale){
487 scale = scale + "";
Iftekharul Islamec6bcd12017-09-06 10:49:07 -0500488 scale = parseInt(scale, 10);
489 var power = Math.abs(parseInt(scale,10));
Iftekharul Islam96bbf312017-08-22 13:44:38 -0500490
Iftekharul Islamec6bcd12017-09-06 10:49:07 -0500491 if(scale > 0){
Iftekharul Islam96bbf312017-08-22 13:44:38 -0500492 value = value * Math.pow(10, power);
Iftekharul Islamec6bcd12017-09-06 10:49:07 -0500493 }else if(scale < 0){
Iftekharul Islam96bbf312017-08-22 13:44:38 -0500494 value = value / Math.pow(10, power);
495 }
496 return value;
497 }
498
Iftekharul Islamd2269e22017-05-02 09:32:45 -0500499 function getSensorStatus(reading){
Iftekharul Islam8947e702017-07-27 10:28:07 -0500500 var severityFlags = {critical: false, warning: false, normal: false}, severityText = '', order = 0;
501
502 if(reading.hasOwnProperty('CriticalLow') &&
503 reading.Value < reading.CriticalLow
504 ){
Iftekharul Islamd2269e22017-05-02 09:32:45 -0500505 severityFlags.critical = true;
506 severityText = 'critical';
Iftekharul Islam8947e702017-07-27 10:28:07 -0500507 order = 2;
508 }else if(reading.hasOwnProperty('CriticalHigh') &&
509 reading.Value > reading.CriticalHigh
510 ){
511 severityFlags.critical = true;
512 severityText = 'critical';
513 order = 2;
514 }else if(reading.hasOwnProperty('CriticalLow') &&
515 reading.hasOwnProperty('WarningLow') &&
516 reading.Value >= reading.CriticalLow && reading.Value <= reading.WarningLow){
Iftekharul Islamd2269e22017-05-02 09:32:45 -0500517 severityFlags.warning = true;
518 severityText = 'warning';
Iftekharul Islam8947e702017-07-27 10:28:07 -0500519 order = 1;
520 }else if(reading.hasOwnProperty('WarningHigh') &&
521 reading.hasOwnProperty('CriticalHigh') &&
522 reading.Value >= reading.WarningHigh && reading.Value <= reading.CriticalHigh){
523 severityFlags.warning = true;
524 severityText = 'warning';
525 order = 1;
Iftekharul Islamd2269e22017-05-02 09:32:45 -0500526 }else{
527 severityFlags.normal = true;
528 severityText = 'normal';
529 }
Iftekharul Islam8947e702017-07-27 10:28:07 -0500530 return { flags: severityFlags, severityText: severityText, order: order};
Iftekharul Islamd2269e22017-05-02 09:32:45 -0500531 }
532
533 for(var key in content.data){
534 if(content.data.hasOwnProperty(key) && content.data[key].hasOwnProperty('Unit')){
Iftekharul Islam8947e702017-07-27 10:28:07 -0500535
536 severity = getSensorStatus(content.data[key]);
537
538 if(!content.data[key].hasOwnProperty('CriticalLow')){
539 content.data[key].CriticalLow = "--";
540 content.data[key].CriticalHigh = "--";
541 }
542
543 if(!content.data[key].hasOwnProperty('WarningLow')){
544 content.data[key].WarningLow = "--";
545 content.data[key].WarningHigh = "--";
546 }
547
548 tempKeyParts = key.split("/");
549 title = tempKeyParts.pop();
550 title = tempKeyParts.pop() + '_' + title;
551 title = title.split("_").map(function(item){
552 return item.toLowerCase().charAt(0).toUpperCase() + item.slice(1);
553 }).reduce(function(prev, el){
554 return prev + " " + el;
555 });
556
Iftekharul Islam96bbf312017-08-22 13:44:38 -0500557 content.data[key].Value = getScaledValue(content.data[key].Value, content.data[key].Scale);
Gunnar Mills022f5642018-02-07 14:30:17 -0600558 content.data[key].CriticalLow = getScaledValue(content.data[key].CriticalLow, content.data[key].Scale);
559 content.data[key].CriticalHigh = getScaledValue(content.data[key].CriticalHigh, content.data[key].Scale);
560 content.data[key].WarningLow = getScaledValue(content.data[key].WarningLow, content.data[key].Scale);
561 content.data[key].WarningHigh = getScaledValue(content.data[key].WarningHigh, content.data[key].Scale);
Iftekharul Islam8a122842017-09-11 10:58:16 -0500562 if(Constants.SENSOR_SORT_ORDER.indexOf(content.data[key].Unit) > -1){
563 customOrder = Constants.SENSOR_SORT_ORDER.indexOf(content.data[key].Unit);
564 }else{
565 customOrder = Constants.SENSOR_SORT_ORDER_DEFAULT;
566 }
567
Iftekharul Islamd2269e22017-05-02 09:32:45 -0500568 sensorData.push(Object.assign({
569 path: key,
570 selected: false,
571 confirm: false,
572 copied: false,
Iftekharul Islam8947e702017-07-27 10:28:07 -0500573 title: title,
574 unit: Constants.SENSOR_UNIT_MAP[content.data[key].Unit],
575 severity_flags: severity.flags,
576 status: severity.severityText,
577 order: severity.order,
Iftekharul Islam8a122842017-09-11 10:58:16 -0500578 custom_order: customOrder,
Iftekharul Islam8947e702017-07-27 10:28:07 -0500579 search_text: (title + " " + content.data[key].Value + " " +
580 Constants.SENSOR_UNIT_MAP[content.data[key].Unit] + " " +
581 severity.severityText + " " +
582 content.data[key].CriticalLow + " " +
583 content.data[key].CriticalHigh + " " +
584 content.data[key].WarningLow + " " +
585 content.data[key].WarningHigh + " "
586 ).toLowerCase(),
Iftekharul Islamd2269e22017-05-02 09:32:45 -0500587 original_data: {key: key, value: content.data[key]}
588 }, content.data[key]));
589 }
590 }
591
Iftekharul Islam8947e702017-07-27 10:28:07 -0500592 callback(sensorData, dataClone);
Ed Tanousbbcf6702017-10-06 13:53:06 -0700593 }, function(error){
Iftekharul Islamd2269e22017-05-02 09:32:45 -0500594 console.log(error);
595 });
Iftekharul Islamc0161392017-06-14 15:46:15 -0500596 },
Michael Davisdf3bd122017-08-10 11:03:42 -0500597 getFirmwares: function(){
598 var deferred = $q.defer();
Iftekharul Islamc0161392017-06-14 15:46:15 -0500599 $http({
600 method: 'GET',
Iftekharul Islam1acb4122017-11-02 13:20:32 -0500601 url: DataService.getHost() + "/xyz/openbmc_project/software/enumerate",
Iftekharul Islamc0161392017-06-14 15:46:15 -0500602 headers: {
603 'Accept': 'application/json',
604 'Content-Type': 'application/json'
605 },
606 withCredentials: true
Ed Tanousbbcf6702017-10-06 13:53:06 -0700607 }).then(function(response){
608 var json = JSON.stringify(response.data);
Iftekharul Islamc0161392017-06-14 15:46:15 -0500609 var content = JSON.parse(json);
610 var data = [];
Gunnar Mills902c38c2018-02-23 10:12:39 -0600611 var activationStatus = "";
Iftekharul Islamc0161392017-06-14 15:46:15 -0500612 var isExtended = false;
613 var bmcActiveVersion = "";
614 var hostActiveVersion = "";
615 var imageType = "";
616 var extendedVersions = [];
617
618 function getFormatedExtendedVersions(extendedVersion){
619 var versions = [];
620 extendedVersion = extendedVersion.split(",");
621
622 extendedVersion.forEach(function(item){
623 var parts = item.split("-");
624 var numberIndex = 0;
625 for(var i = 0; i < parts.length; i++){
626 if(/[0-9]/.test(parts[i])){
627 numberIndex = i;
628 break;
629 }
630 }
631 var titlePart = parts.splice(0, numberIndex);
632 titlePart = titlePart.join("");
633 titlePart = titlePart[0].toUpperCase() + titlePart.substr(1, titlePart.length);
634 var versionPart = parts.join("-");
635 versions.push({
636 title: titlePart,
637 version: versionPart
638 });
639 });
640
641 return versions;
642 }
643
644 for(var key in content.data){
645 if(content.data.hasOwnProperty(key) && content.data[key].hasOwnProperty('Version')){
Gunnar Mills902c38c2018-02-23 10:12:39 -0600646 // If the image is "Functional" use that for the
647 // activation status, else use the value of "Activation"
648 // github.com/openbmc/phosphor-dbus-interfaces/blob/master/xyz/openbmc_project/Software/Activation.interface.yaml
649 activationStatus = content.data[key].Activation.split(".").pop();
650 if (content.data[key].Priority == 0)
651 {
652 activationStatus = "Functional";
653 }
Iftekharul Islamc0161392017-06-14 15:46:15 -0500654 imageType = content.data[key].Purpose.split(".").pop();
655 isExtended = content.data[key].hasOwnProperty('ExtendedVersion') && content.data[key].ExtendedVersion != "";
656 if(isExtended){
657 extendedVersions = getFormatedExtendedVersions(content.data[key].ExtendedVersion);
658 }
659 data.push(Object.assign({
660 path: key,
Gunnar Mills902c38c2018-02-23 10:12:39 -0600661 activationStatus: activationStatus,
Iftekharul Islamc0161392017-06-14 15:46:15 -0500662 imageId: key.split("/").pop(),
663 imageType: imageType,
664 isExtended: isExtended,
665 extended: {
666 show: false,
667 versions: extendedVersions
668 },
669 data: {key: key, value: content.data[key]}
670 }, content.data[key]));
671
Gunnar Mills902c38c2018-02-23 10:12:39 -0600672 if(activationStatus == 'Functional' && imageType == 'BMC'){
Iftekharul Islamc0161392017-06-14 15:46:15 -0500673 bmcActiveVersion = content.data[key].Version;
674 }
675
Gunnar Mills902c38c2018-02-23 10:12:39 -0600676 if(activationStatus == 'Functional' && imageType == 'Host'){
Iftekharul Islamc0161392017-06-14 15:46:15 -0500677 hostActiveVersion = content.data[key].Version;
678 }
679 }
680 }
Michael Davisdf3bd122017-08-10 11:03:42 -0500681
682 deferred.resolve({
683 data: data,
684 bmcActiveVersion: bmcActiveVersion,
685 hostActiveVersion: hostActiveVersion
686 });
Ed Tanousbbcf6702017-10-06 13:53:06 -0700687 }, function(error){
Iftekharul Islamc0161392017-06-14 15:46:15 -0500688 console.log(error);
Michael Davisdf3bd122017-08-10 11:03:42 -0500689 deferred.reject(error);
Iftekharul Islamc0161392017-06-14 15:46:15 -0500690 });
Michael Davisdf3bd122017-08-10 11:03:42 -0500691
692 return deferred.promise;
Iftekharul Islamc0161392017-06-14 15:46:15 -0500693 },
Iftekharul Islam1acb4122017-11-02 13:20:32 -0500694 changePriority: function(imageId, priority){
695 var deferred = $q.defer();
696 $http({
697 method: 'PUT',
698 url: DataService.getHost() + "/xyz/openbmc_project/software/" + imageId + "/attr/Priority",
699 headers: {
Iftekharul Islam2a489552017-11-02 13:23:08 -0500700 'Accept': 'application/json',
701 'Content-Type': 'application/json'
Iftekharul Islam1acb4122017-11-02 13:20:32 -0500702 },
703 withCredentials: true,
704 data: JSON.stringify({"data": priority})
Ed Tanousbbcf6702017-10-06 13:53:06 -0700705 }).then(function(response){
706 var json = JSON.stringify(response.data);
Iftekharul Islam1acb4122017-11-02 13:20:32 -0500707 var content = JSON.parse(json);
708 deferred.resolve(content);
Ed Tanousbbcf6702017-10-06 13:53:06 -0700709 }, function(error){
Iftekharul Islam1acb4122017-11-02 13:20:32 -0500710 console.log(error);
711 deferred.reject(error);
712 });
713
714 return deferred.promise;
715 },
Iftekharul Islam2a489552017-11-02 13:23:08 -0500716 deleteImage: function(imageId){
717 var deferred = $q.defer();
718 $http({
719 method: 'POST',
720 url: DataService.getHost() + "/xyz/openbmc_project/software/" + imageId + "/action/Delete",
721 headers: {
722 'Accept': 'application/json',
723 'Content-Type': 'application/json'
724 },
725 withCredentials: true,
726 data: JSON.stringify({"data": []})
Ed Tanousbbcf6702017-10-06 13:53:06 -0700727 }).then(function(response){
728 var json = JSON.stringify(response.data);
Iftekharul Islam2a489552017-11-02 13:23:08 -0500729 var content = JSON.parse(json);
730 deferred.resolve(content);
Ed Tanousbbcf6702017-10-06 13:53:06 -0700731 }, function(error){
Iftekharul Islam2a489552017-11-02 13:23:08 -0500732 console.log(error);
733 deferred.reject(error);
734 });
735
736 return deferred.promise;
737 },
738 activateImage: function(imageId){
Iftekharul Islam1acb4122017-11-02 13:20:32 -0500739 var deferred = $q.defer();
Iftekharul Islamc0161392017-06-14 15:46:15 -0500740 $http({
741 method: 'PUT',
Iftekharul Islam2a489552017-11-02 13:23:08 -0500742 url: DataService.getHost() + "/xyz/openbmc_project/software/" + imageId + "/attr/RequestedActivation",
743 headers: {
744 'Accept': 'application/json',
745 'Content-Type': 'application/json'
746 },
747 withCredentials: true,
748 data: JSON.stringify({"data": Constants.FIRMWARE.ACTIVATE_FIRMWARE})
Ed Tanousbbcf6702017-10-06 13:53:06 -0700749 }).then(function(response){
750 var json = JSON.stringify(response.data);
Iftekharul Islam2a489552017-11-02 13:23:08 -0500751 var content = JSON.parse(json);
752 deferred.resolve(content);
Ed Tanousbbcf6702017-10-06 13:53:06 -0700753 }, function(error){
Iftekharul Islam2a489552017-11-02 13:23:08 -0500754 console.log(error);
755 deferred.reject(error);
756 });
757
758 return deferred.promise;
759 },
760 uploadImage: function(file){
761 var deferred = $q.defer();
762 $http({
763 method: 'POST',
Iftekharul Islamc0161392017-06-14 15:46:15 -0500764 timeout: 5 * 60 * 1000,
Gunnar Millsdddb1492018-02-19 16:27:27 -0600765 url: DataService.getHost() + "/upload/image",
Iftekharul Islamc0161392017-06-14 15:46:15 -0500766 headers: {
Iftekharul Islam2a489552017-11-02 13:23:08 -0500767 'Content-Type': 'application/octet-stream'
Iftekharul Islamc0161392017-06-14 15:46:15 -0500768 },
769 withCredentials: true,
770 data: file
Ed Tanousbbcf6702017-10-06 13:53:06 -0700771 }).then(function(response){
772 var json = JSON.stringify(response.data);
Iftekharul Islamc0161392017-06-14 15:46:15 -0500773 var content = JSON.parse(json);
Iftekharul Islam1acb4122017-11-02 13:20:32 -0500774 deferred.resolve(content);
Ed Tanousbbcf6702017-10-06 13:53:06 -0700775 }, function(error){
Iftekharul Islam1acb4122017-11-02 13:20:32 -0500776 console.log(error);
777 deferred.reject(error);
Iftekharul Islamc0161392017-06-14 15:46:15 -0500778 });
Iftekharul Islam1acb4122017-11-02 13:20:32 -0500779
780 return deferred.promise;
781 },
782 downloadImage: function(host, filename){
783 var deferred = $q.defer();
784 $http({
785 method: 'POST',
Gunnar Millse345cac2018-02-20 11:16:53 -0600786 url: DataService.getHost() + "/xyz/openbmc_project/software/action/DownloadViaTFTP",
Iftekharul Islam1acb4122017-11-02 13:20:32 -0500787 headers: {
788 'Accept': 'application/json',
789 'Content-Type': 'application/json'
790 },
791 withCredentials: true,
Gunnar Millse345cac2018-02-20 11:16:53 -0600792 data: JSON.stringify({"data": [filename, host]}),
Iftekharul Islam1acb4122017-11-02 13:20:32 -0500793 responseType: 'arraybuffer'
Ed Tanousbbcf6702017-10-06 13:53:06 -0700794 }).then(function(response, status, headers){
Iftekharul Islam1acb4122017-11-02 13:20:32 -0500795 deferred.resolve({
796 data: response,
797 status: status,
798 headers: headers
799 });
Ed Tanousbbcf6702017-10-06 13:53:06 -0700800 }, function(error){
Iftekharul Islam1acb4122017-11-02 13:20:32 -0500801 console.log(error);
802 deferred.reject(error);
803 });
804
805 return deferred.promise;
Iftekharul Islamc0161392017-06-14 15:46:15 -0500806 },
Michael Davisdf3bd122017-08-10 11:03:42 -0500807 getBMCEthernetInfo: function(){
808 var deferred = $q.defer();
Iftekharul Islam54c22e42017-06-28 11:06:16 -0500809 $http({
810 method: 'GET',
Iftekharul Islam1acb4122017-11-02 13:20:32 -0500811 url: DataService.getHost() + "/xyz/openbmc_project/inventory/system/chassis/motherboard/boxelder/bmc/ethernet",
Iftekharul Islam54c22e42017-06-28 11:06:16 -0500812 headers: {
813 'Accept': 'application/json',
814 'Content-Type': 'application/json'
815 },
816 withCredentials: true
Ed Tanousbbcf6702017-10-06 13:53:06 -0700817 }).then(function(response){
818 var json = JSON.stringify(response.data);
Michael Davisdf3bd122017-08-10 11:03:42 -0500819 var content = JSON.parse(json);
820 deferred.resolve(content.data);
Ed Tanousbbcf6702017-10-06 13:53:06 -0700821 }, function(error){
Iftekharul Islam54c22e42017-06-28 11:06:16 -0500822 console.log(error);
Michael Davisdf3bd122017-08-10 11:03:42 -0500823 deferred.reject(error);
Iftekharul Islam54c22e42017-06-28 11:06:16 -0500824 });
Michael Davisdf3bd122017-08-10 11:03:42 -0500825
826 return deferred.promise;
Iftekharul Islam54c22e42017-06-28 11:06:16 -0500827 },
828 getBMCInfo: function(callback){
Michael Davisdf3bd122017-08-10 11:03:42 -0500829 var deferred = $q.defer();
Iftekharul Islam54c22e42017-06-28 11:06:16 -0500830 $http({
831 method: 'GET',
Iftekharul Islam1acb4122017-11-02 13:20:32 -0500832 url: DataService.getHost() + "/xyz/openbmc_project/inventory/system/chassis/motherboard/boxelder/bmc",
Iftekharul Islam54c22e42017-06-28 11:06:16 -0500833 headers: {
834 'Accept': 'application/json',
835 'Content-Type': 'application/json'
836 },
837 withCredentials: true
Ed Tanousbbcf6702017-10-06 13:53:06 -0700838 }).then(function(response){
839 var json = JSON.stringify(response.data);
Michael Davisdf3bd122017-08-10 11:03:42 -0500840 var content = JSON.parse(json);
841 deferred.resolve(content.data);
Ed Tanousbbcf6702017-10-06 13:53:06 -0700842 }, function(error){
Iftekharul Islam54c22e42017-06-28 11:06:16 -0500843 console.log(error);
Michael Davisdf3bd122017-08-10 11:03:42 -0500844 deferred.reject(error);
Iftekharul Islam54c22e42017-06-28 11:06:16 -0500845 });
Michael Davisdf3bd122017-08-10 11:03:42 -0500846 return deferred.promise;
Iftekharul Islam54c22e42017-06-28 11:06:16 -0500847 },
Iftekharul Islamee27d752017-07-05 15:54:31 -0500848 getHardwares: function(callback){
849 $http({
850 method: 'GET',
Iftekharul Islam1acb4122017-11-02 13:20:32 -0500851 url: DataService.getHost() + "/xyz/openbmc_project/inventory/enumerate",
Iftekharul Islamee27d752017-07-05 15:54:31 -0500852 headers: {
853 'Accept': 'application/json',
854 'Content-Type': 'application/json'
855 },
856 withCredentials: true
Ed Tanousbbcf6702017-10-06 13:53:06 -0700857 }).then(function(response){
858 var json = JSON.stringify(response.data);
Iftekharul Islamee27d752017-07-05 15:54:31 -0500859 var content = JSON.parse(json);
860 var hardwareData = [];
861 var keyIndexMap = {};
862 var title = "";
863 var data = [];
864 var searchText = "";
865 var componentIndex = -1;
866 var tempParts = [];
867
868
869 function isSubComponent(key){
870
871 for(var i = 0; i < Constants.HARDWARE.parent_components.length; i++){
872 if(key.split(Constants.HARDWARE.parent_components[i]).length == 2) return true;
873 }
874
875 return false;
876 }
877
878 function titlelize(title){
879 title = title.replace(/([A-Z0-9]+)/g, " $1").replace(/^\s+/, "");
880 for(var i = 0; i < Constants.HARDWARE.uppercase_titles.length; i++){
881 if(title.toLowerCase().indexOf((Constants.HARDWARE.uppercase_titles[i] + " ")) > -1){
882 return title.toUpperCase();
883 }
884 }
885
886 return title;
887 }
888
889 function camelcaseToLabel(obj){
Iftekharul Islam8947e702017-07-27 10:28:07 -0500890 var transformed = [], label = "", value = "";
Iftekharul Islamee27d752017-07-05 15:54:31 -0500891 for(var key in obj){
892 label = key.replace(/([A-Z0-9]+)/g, " $1").replace(/^\s+/, "");
893 if(obj[key] !== ""){
Iftekharul Islam8947e702017-07-27 10:28:07 -0500894 value = obj[key];
895 if(value == 1 || value == 0){
896 value = (value == 1) ? 'Yes' : 'No';
897 }
898 transformed.push({key:label, value: value});
Iftekharul Islamee27d752017-07-05 15:54:31 -0500899 }
900 }
901
902 return transformed;
903 }
904
905 function getSearchText(data){
906 var searchText = "";
907 for(var i = 0; i < data.length; i++){
908 searchText += " " + data[i].key + " " + data[i].value;
909 }
910
911 return searchText;
912 }
913
914 for(var key in content.data){
915 if(content.data.hasOwnProperty(key) &&
916 key.indexOf(Constants.HARDWARE.component_key_filter) == 0){
917
918 data = camelcaseToLabel(content.data[key]);
919 searchText = getSearchText(data);
920 title = key.split("/").pop();
921
922 title = titlelize(title);
923
924 if(!isSubComponent(key)){
925 hardwareData.push(Object.assign({
926 path: key,
927 title: title,
928 selected: false,
929 expanded: false,
930 search_text: title.toLowerCase() + " " + searchText.toLowerCase(),
931 sub_components: [],
932 original_data: {key: key, value: content.data[key]}
933 }, {items: data}));
934
935 keyIndexMap[key] = hardwareData.length - 1;
936 }else{
937 var tempParts = key.split("/");
938 tempParts.pop();
939 tempParts = tempParts.join("/");
940 componentIndex = keyIndexMap[tempParts];
941 data = content.data[key];
942 data.title = title;
943 hardwareData[componentIndex].sub_components.push(data);
944 hardwareData[componentIndex].search_text += " " + title.toLowerCase();
945 }
946 }
947 }
948
949 if(callback){
950 callback(hardwareData, content.data);
951 }else{
952 return { data: hardwareData, original_data: content.data};
953 }
954 });
955 },
Iftekharul Islamf2d74642017-07-10 16:42:14 -0500956 deleteLogs: function(logs) {
957 var defer = $q.defer();
958 var promises = [];
959
960 function finished(){
961 defer.resolve();
962 }
963
964 logs.forEach(function(item){
965 promises.push($http({
966 method: 'POST',
Iftekharul Islam1acb4122017-11-02 13:20:32 -0500967 url: DataService.getHost() + "/xyz/openbmc_project/logging/entry/"+item.Id+"/action/Delete",
Iftekharul Islamf2d74642017-07-10 16:42:14 -0500968 headers: {
969 'Accept': 'application/json',
970 'Content-Type': 'application/json'
971 },
972 withCredentials: true,
973 data: JSON.stringify({"data": []})
974 }));
975 });
976
977 $q.all(promises).then(finished);
978
979 return defer.promise;
980 },
981 resolveLogs: function(logs) {
982 var defer = $q.defer();
983 var promises = [];
984
985 function finished(){
986 defer.resolve();
987 }
988
989 logs.forEach(function(item){
990 promises.push($http({
991 method: 'PUT',
Iftekharul Islam1acb4122017-11-02 13:20:32 -0500992 url: DataService.getHost() + "/xyz/openbmc_project/logging/entry/"+item.Id+"/attr/Resolved",
Iftekharul Islamf2d74642017-07-10 16:42:14 -0500993 headers: {
994 'Accept': 'application/json',
995 'Content-Type': 'application/json'
996 },
997 withCredentials: true,
998 data: JSON.stringify({"data": "1"})
999 }));
1000 });
1001
1002 $q.all(promises).then(finished);
1003
1004 return defer.promise;
1005 },
Iftekharul Islam99d199f2017-03-24 15:28:25 -05001006 };
1007 return SERVICE;
1008 }]);
1009
1010 })(window.angular);