blob: 077d18aeafb252dd21ff9048db7c67d8808e4282 [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
Iftekharul Islam99d199f2017-03-24 15:28:25 -05007 */
8
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07009window.angular && (function(angular) {
10 'use strict';
Andrew Geisslerd27bb132018-05-24 11:07:27 -070011 angular.module('app.common.services').factory('APIUtils', [
12 '$http', 'Constants', '$q', 'dataService',
13 function($http, Constants, $q, DataService) {
Andrew Geisslerba5e3f32018-05-24 10:58:00 -070014 var getScaledValue = function(value, scale) {
15 scale = scale + '';
16 scale = parseInt(scale, 10);
17 var power = Math.abs(parseInt(scale, 10));
CamVan Nguyen33275832018-03-13 18:38:37 -050018
Andrew Geisslerba5e3f32018-05-24 10:58:00 -070019 if (scale > 0) {
20 value = value * Math.pow(10, power);
Andrew Geisslerd27bb132018-05-24 11:07:27 -070021 } else if (scale < 0) {
Andrew Geisslerba5e3f32018-05-24 10:58:00 -070022 value = value / Math.pow(10, power);
23 }
24 return value;
25 };
26 var SERVICE = {
27 API_CREDENTIALS: Constants.API_CREDENTIALS,
28 API_RESPONSE: Constants.API_RESPONSE,
29 CHASSIS_POWER_STATE: Constants.CHASSIS_POWER_STATE,
30 HOST_STATE_TEXT: Constants.HOST_STATE,
31 HOST_STATE: Constants.HOST_STATE,
32 LED_STATE: Constants.LED_STATE,
33 LED_STATE_TEXT: Constants.LED_STATE_TEXT,
34 HOST_SESSION_STORAGE_KEY: Constants.API_CREDENTIALS.host_storage_key,
35 getChassisState: function() {
36 var deferred = $q.defer();
37 $http({
38 method: 'GET',
Andrew Geisslerd27bb132018-05-24 11:07:27 -070039 url: DataService.getHost() +
40 '/xyz/openbmc_project/state/chassis0/attr/CurrentPowerState',
Andrew Geisslerba5e3f32018-05-24 10:58:00 -070041 headers: {
42 'Accept': 'application/json',
43 'Content-Type': 'application/json'
44 },
45 withCredentials: true
Andrew Geisslerd27bb132018-05-24 11:07:27 -070046 })
47 .then(
48 function(response) {
49 var json = JSON.stringify(response.data);
50 var content = JSON.parse(json);
51 deferred.resolve(content.data);
52 },
53 function(error) {
54 console.log(error);
55 deferred.reject(error);
56 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -070057 return deferred.promise;
58 },
59 getHostState: function() {
60 var deferred = $q.defer();
61 $http({
62 method: 'GET',
Andrew Geisslerd27bb132018-05-24 11:07:27 -070063 url: DataService.getHost() +
64 '/xyz/openbmc_project/state/host0/attr/CurrentHostState',
Andrew Geisslerba5e3f32018-05-24 10:58:00 -070065 headers: {
66 'Accept': 'application/json',
67 'Content-Type': 'application/json'
68 },
69 withCredentials: true
Andrew Geisslerd27bb132018-05-24 11:07:27 -070070 })
71 .then(
72 function(response) {
73 var json = JSON.stringify(response.data);
74 var content = JSON.parse(json);
75 deferred.resolve(content.data);
76 },
77 function(error) {
78 console.log(error);
79 deferred.reject(error);
80 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -070081 return deferred.promise;
82 },
83 getNetworkInfo: function() {
84 var deferred = $q.defer();
85 $http({
86 method: 'GET',
Andrew Geisslerd27bb132018-05-24 11:07:27 -070087 url: DataService.getHost() +
88 '/xyz/openbmc_project/network/enumerate',
Andrew Geisslerba5e3f32018-05-24 10:58:00 -070089 headers: {
90 'Accept': 'application/json',
91 'Content-Type': 'application/json'
92 },
93 withCredentials: true
Andrew Geisslerd27bb132018-05-24 11:07:27 -070094 })
95 .then(
96 function(response) {
97 var json = JSON.stringify(response.data);
98 var content = JSON.parse(json);
99 var hostname = '';
Gunnar Millse9f5fe72018-05-04 13:43:10 -0500100 var defaultgateway = '';
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700101 var macAddress = '';
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700102
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700103 function parseNetworkData(content) {
104 var data = {
105 interface_ids: [],
106 interfaces: {},
107 ip_addresses: {ipv4: [], ipv6: []},
108 };
109 var interfaceId = '', keyParts = [], interfaceHash = '',
110 interfaceType = '';
111 for (var key in content.data) {
112 if (key.match(/network\/eth\d+$/ig)) {
113 interfaceId = key.split('/').pop();
114 if (data.interface_ids.indexOf(interfaceId) == -1) {
115 data.interface_ids.push(interfaceId);
116 data.interfaces[interfaceId] = {
117 interfaceIname: '',
118 DomainName: '',
119 MACAddress: '',
120 Nameservers: [],
121 DHCPEnabled: 0,
122 ipv4: {ids: [], values: []},
123 ipv6: {ids: [], values: []}
124 };
125 data.interfaces[interfaceId].MACAddress =
126 content.data[key].MACAddress;
127 data.interfaces[interfaceId].DomainName =
128 content.data[key].DomainName.join(' ');
129 data.interfaces[interfaceId].Nameservers =
130 content.data[key].Nameservers;
131 data.interfaces[interfaceId].DHCPEnabled =
132 content.data[key].DHCPEnabled;
133 }
134 } else if (
135 key.match(
136 /network\/eth\d+\/ipv[4|6]\/[a-z0-9]+$/ig)) {
137 keyParts = key.split('/');
138 interfaceHash = keyParts.pop();
139 interfaceType = keyParts.pop();
140 interfaceId = keyParts.pop();
141
142 if (data.interfaces[interfaceId][interfaceType]
143 .ids.indexOf(interfaceHash) == -1) {
144 data.interfaces[interfaceId][interfaceType]
145 .ids.push(interfaceHash);
146 data.interfaces[interfaceId][interfaceType]
147 .values.push(content.data[key]);
148 data.ip_addresses[interfaceType].push(
149 content.data[key]['Address']);
150 }
151 }
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700152 }
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700153 return data;
154 }
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700155
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700156 if (content.data.hasOwnProperty(
Gunnar Millse9f5fe72018-05-04 13:43:10 -0500157 '/xyz/openbmc_project/network/config')) {
158 if (content.data['/xyz/openbmc_project/network/config']
159 .hasOwnProperty('HostName')) {
160 hostname =
161 content.data['/xyz/openbmc_project/network/config']
162 .HostName;
163 }
164 if (content.data['/xyz/openbmc_project/network/config']
165 .hasOwnProperty('DefaultGateway')) {
166 defaultgateway =
167 content.data['/xyz/openbmc_project/network/config']
168 .DefaultGateway;
169 }
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700170 }
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700171
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700172 if (content.data.hasOwnProperty(
173 '/xyz/openbmc_project/network/eth0') &&
174 content.data['/xyz/openbmc_project/network/eth0']
175 .hasOwnProperty('MACAddress')) {
176 macAddress =
177 content.data['/xyz/openbmc_project/network/eth0']
178 .MACAddress;
179 }
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700180
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700181 deferred.resolve({
182 data: content.data,
183 hostname: hostname,
Gunnar Millse9f5fe72018-05-04 13:43:10 -0500184 defaultgateway: defaultgateway,
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700185 mac_address: macAddress,
186 formatted_data: parseNetworkData(content)
187 });
188 },
189 function(error) {
190 console.log(error);
191 deferred.reject(error);
192 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700193 return deferred.promise;
194 },
Gunnar Mills7ddc7272018-04-12 16:12:03 -0500195 setMACAddress: function(interface_name, mac_address) {
196 return $http({
197 method: 'PUT',
198 url: DataService.getHost() +
199 '/xyz/openbmc_project/network/' + interface_name +
200 '/attr/MACAddress',
201 headers: {
202 'Accept': 'application/json',
203 'Content-Type': 'application/json'
204 },
205 withCredentials: true,
206 data: JSON.stringify({'data': mac_address})
207 })
208 .then(function(response) {
209 return response.data;
210 });
211 },
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700212 getLEDState: function() {
213 var deferred = $q.defer();
214 $http({
215 method: 'GET',
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700216 url: DataService.getHost() +
217 '/xyz/openbmc_project/led/groups/enclosure_identify',
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700218 headers: {
219 'Accept': 'application/json',
220 'Content-Type': 'application/json'
221 },
222 withCredentials: true
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700223 })
224 .then(
225 function(response) {
226 var json = JSON.stringify(response.data);
227 var content = JSON.parse(json);
228 deferred.resolve(content.data.Asserted);
229 },
230 function(error) {
231 console.log(error);
232 deferred.reject(error);
233 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700234 return deferred.promise;
235 },
236 login: function(username, password, callback) {
237 $http({
238 method: 'POST',
239 url: DataService.getHost() + '/login',
240 headers: {
241 'Accept': 'application/json',
242 'Content-Type': 'application/json'
243 },
244 withCredentials: true,
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700245 data: JSON.stringify({'data': [username, password]})
246 })
247 .then(
248 function(response) {
249 if (callback) {
250 callback(response.data);
251 }
252 },
253 function(error) {
254 if (callback) {
255 if (error && error.status && error.status == 'error') {
256 callback(error);
257 } else {
258 callback(error, true);
259 }
260 }
261 console.log(error);
262 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700263 },
264 testPassword: function(username, password) {
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700265 // Calls /login without the current session to verify the given
266 // password is correct ignore the interceptor logout on a bad password
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700267 return $http({
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700268 method: 'POST',
269 url: DataService.getHost() + '/login',
270 headers: {
271 'Accept': 'application/json',
272 'Content-Type': 'application/json'
273 },
274 withCredentials: false,
275 data: JSON.stringify({'data': [username, password]})
276 })
277 .then(function(response) {
278 return response.data;
279 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700280 },
281 logout: function(callback) {
282 $http({
283 method: 'POST',
284 url: DataService.getHost() + '/logout',
285 headers: {
286 'Accept': 'application/json',
287 'Content-Type': 'application/json'
288 },
289 withCredentials: true,
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700290 data: JSON.stringify({'data': []})
291 })
292 .then(
293 function(response) {
294 if (callback) {
295 callback(response.data);
296 }
297 },
298 function(error) {
299 if (callback) {
300 callback(null, error);
301 }
302 console.log(error);
303 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700304 },
305 changePassword: function(user, newPassword) {
306 var deferred = $q.defer();
307 $http({
308 method: 'POST',
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700309 url: DataService.getHost() + '/xyz/openbmc_project/user/' + user +
310 '/action/SetPassword',
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700311 headers: {
312 'Accept': 'application/json',
313 'Content-Type': 'application/json'
314 },
315 withCredentials: true,
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700316 data: JSON.stringify({'data': [newPassword]}),
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700317 responseType: 'arraybuffer'
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700318 })
319 .then(
320 function(response, status, headers) {
321 deferred.resolve(
322 {data: response, status: status, headers: headers});
323 },
324 function(error) {
325 console.log(error);
326 deferred.reject(error);
327 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700328 return deferred.promise;
329 },
330 chassisPowerOn: function(callback) {
331 $http({
332 method: 'POST',
333 url: DataService.getHost() + '/xyz/openbmc_project/state/host0',
334 headers: {
335 'Accept': 'application/json',
336 'Content-Type': 'application/json'
337 },
338 withCredentials: true,
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700339 data: JSON.stringify({'data': []})
340 })
341 .then(
342 function(response) {
343 var json = JSON.stringify(response.data);
344 var content = JSON.parse(json);
345 if (callback) {
346 return callback(content.data.CurrentPowerState);
347 }
348 },
349 function(error) {
350 if (callback) {
351 callback(error);
352 } else {
353 console.log(error);
354 }
355 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700356 },
357 chassisPowerOff: function() {
358 var deferred = $q.defer();
359 $http({
360 method: 'PUT',
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700361 url: DataService.getHost() +
362 '/xyz/openbmc_project/state/chassis0/attr/RequestedPowerTransition',
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700363 headers: {
364 'Accept': 'application/json',
365 'Content-Type': 'application/json'
366 },
367 withCredentials: true,
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700368 data: JSON.stringify(
369 {'data': 'xyz.openbmc_project.State.Chassis.Transition.Off'})
370 })
371 .then(
372 function(response) {
373 var json = JSON.stringify(response.data);
374 var content = JSON.parse(json);
375 deferred.resolve(content.status);
376 },
377 function(error) {
378 console.log(error);
379 deferred.reject(error);
380 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700381 return deferred.promise;
382 },
383 setLEDState: function(state, callback) {
384 $http({
385 method: 'PUT',
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700386 url: DataService.getHost() +
387 '/xyz/openbmc_project/led/groups/enclosure_identify/attr/Asserted',
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700388 headers: {
389 'Accept': 'application/json',
390 'Content-Type': 'application/json'
391 },
392 withCredentials: true,
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700393 data: JSON.stringify({'data': state})
394 })
395 .then(
396 function(response) {
397 var json = JSON.stringify(response.data);
398 var content = JSON.parse(json);
399 if (callback) {
400 return callback(content.status);
401 }
402 },
403 function(error) {
404 if (callback) {
405 callback(error);
406 } else {
407 console.log(error);
408 }
409 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700410 },
411 bmcReboot: function(callback) {
412 $http({
413 method: 'PUT',
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700414 url: DataService.getHost() +
415 '/xyz/openbmc_project/state/bmc0/attr/RequestedBmcTransition',
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700416 headers: {
417 'Accept': 'application/json',
418 'Content-Type': 'application/json'
419 },
420 withCredentials: true,
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700421 data: JSON.stringify(
422 {'data': 'xyz.openbmc_project.State.BMC.Transition.Reboot'})
423 })
424 .then(
425 function(response) {
426 var json = JSON.stringify(response.data);
427 var content = JSON.parse(json);
428 if (callback) {
429 return callback(content.status);
430 }
431 },
432 function(error) {
433 if (callback) {
434 callback(error);
435 } else {
436 console.log(error);
437 }
438 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700439 },
440 hostPowerOn: function() {
441 var deferred = $q.defer();
442 $http({
443 method: 'PUT',
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700444 url: DataService.getHost() +
445 '/xyz/openbmc_project/state/host0/attr/RequestedHostTransition',
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700446 headers: {
447 'Accept': 'application/json',
448 'Content-Type': 'application/json'
449 },
450 withCredentials: true,
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700451 data: JSON.stringify(
452 {'data': 'xyz.openbmc_project.State.Host.Transition.On'})
453 })
454 .then(
455 function(response) {
456 var json = JSON.stringify(response.data);
457 var content = JSON.parse(json);
458 deferred.resolve(content.status);
459 },
460 function(error) {
461 console.log(error);
462 deferred.reject(error);
463 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700464 return deferred.promise;
465 },
466 hostPowerOff: function() {
467 var deferred = $q.defer();
468 $http({
469 method: 'PUT',
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700470 url: DataService.getHost() +
471 '/xyz/openbmc_project/state/host0/attr/RequestedHostTransition',
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700472 headers: {
473 'Accept': 'application/json',
474 'Content-Type': 'application/json'
475 },
476 withCredentials: true,
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700477 data: JSON.stringify(
478 {'data': 'xyz.openbmc_project.State.Host.Transition.Off'})
479 })
480 .then(
481 function(response) {
482 var json = JSON.stringify(response.data);
483 var content = JSON.parse(json);
484 deferred.resolve(content.status);
485 },
486 function(error) {
487 console.log(error);
488 deferred.reject(error);
489 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700490 return deferred.promise;
491 },
492 hostReboot: function() {
493 var deferred = $q.defer();
494 $http({
495 method: 'PUT',
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700496 url: DataService.getHost() +
497 '/xyz/openbmc_project/state/host0/attr/RequestedHostTransition',
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700498 headers: {
499 'Accept': 'application/json',
500 'Content-Type': 'application/json'
501 },
502 withCredentials: true,
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700503 data: JSON.stringify(
504 {'data': 'xyz.openbmc_project.State.Host.Transition.Reboot'})
505 })
506 .then(
507 function(response) {
508 var json = JSON.stringify(response.data);
509 var content = JSON.parse(json);
510 deferred.resolve(content.status);
511 },
512 function(error) {
513 console.log(error);
514 deferred.reject(error);
515 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700516
517 return deferred.promise;
518 },
519 hostShutdown: function(callback) {
520 $http({
521 method: 'POST',
522 url: DataService.getHost() + '/xyz/openbmc_project/state/host0',
523 headers: {
524 'Accept': 'application/json',
525 'Content-Type': 'application/json'
526 },
527 withCredentials: true,
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700528 data: JSON.stringify({'data': []})
529 })
530 .then(
531 function(response) {
532 var json = JSON.stringify(response.data);
533 var content = JSON.parse(json);
534 if (callback) {
535 return callback(content);
536 }
537 },
538 function(error) {
539 if (callback) {
540 callback(error);
541 } else {
542 console.log(error);
543 }
544 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700545 },
546 getLogs: function() {
547 var deferred = $q.defer();
548 $http({
549 method: 'GET',
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700550 url: DataService.getHost() +
551 '/xyz/openbmc_project/logging/enumerate',
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700552 headers: {
553 'Accept': 'application/json',
554 'Content-Type': 'application/json'
555 },
556 withCredentials: true
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700557 })
558 .then(
559 function(response) {
560 var json = JSON.stringify(response.data);
561 var content = JSON.parse(json);
562 var dataClone = JSON.parse(JSON.stringify(content.data));
563 var data = [];
564 var severityCode = '';
565 var priority = '';
566 var health = '';
567 var relatedItems = [];
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700568
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700569 for (var key in content.data) {
570 if (content.data.hasOwnProperty(key) &&
571 content.data[key].hasOwnProperty('Id')) {
572 var severityFlags = {
573 low: false,
574 medium: false,
575 high: false
576 };
577 var healthFlags = {
578 critical: false,
579 warning: false,
580 good: false
581 };
582 severityCode =
583 content.data[key].Severity.split('.').pop();
584 priority =
585 Constants.SEVERITY_TO_PRIORITY_MAP[severityCode];
586 severityFlags[priority.toLowerCase()] = true;
587 health = Constants.SEVERITY_TO_HEALTH_MAP[severityCode];
588 healthFlags[health.toLowerCase()] = true;
589 relatedItems = [];
590 content.data[key].associations.forEach(function(item) {
591 relatedItems.push(item[2]);
592 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700593
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700594 data.push(Object.assign(
595 {
596 path: key,
597 copied: false,
598 priority: priority,
599 severity_code: severityCode,
600 severity_flags: severityFlags,
601 health_flags: healthFlags,
602 additional_data:
603 content.data[key].AdditionalData.join('\n'),
604 type: content.data[key].Message,
605 selected: false,
606 search_text:
607 ('#' + content.data[key].Id + ' ' +
608 severityCode + ' ' +
609 content.data[key].Severity + ' ' +
610 content.data[key].AdditionalData.join(' '))
611 .toLowerCase(),
612 meta: false,
613 confirm: false,
614 related_items: relatedItems,
615 data: {key: key, value: content.data[key]}
616 },
617 content.data[key]));
618 }
619 }
620 deferred.resolve({data: data, original: dataClone});
621 },
622 function(error) {
623 console.log(error);
624 deferred.reject(error);
625 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700626
627 return deferred.promise;
628 },
629 getAllSensorStatus: function(callback) {
630 $http({
631 method: 'GET',
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700632 url: DataService.getHost() +
633 '/xyz/openbmc_project/sensors/enumerate',
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700634 headers: {
635 'Accept': 'application/json',
636 'Content-Type': 'application/json'
637 },
638 withCredentials: true
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700639 })
640 .then(
641 function(response) {
642 var json = JSON.stringify(response.data);
643 var content = JSON.parse(json);
644 var dataClone = JSON.parse(JSON.stringify(content.data));
645 var sensorData = [];
646 var severity = {};
647 var title = '';
648 var tempKeyParts = [];
649 var order = 0;
650 var customOrder = 0;
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700651
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700652 function getSensorStatus(reading) {
653 var severityFlags = {
654 critical: false,
655 warning: false,
656 normal: false
657 },
658 severityText = '', order = 0;
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700659
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700660 if (reading.hasOwnProperty('CriticalLow') &&
661 reading.Value < reading.CriticalLow) {
662 severityFlags.critical = true;
663 severityText = 'critical';
664 order = 2;
665 } else if (
666 reading.hasOwnProperty('CriticalHigh') &&
667 reading.Value > reading.CriticalHigh) {
668 severityFlags.critical = true;
669 severityText = 'critical';
670 order = 2;
671 } else if (
672 reading.hasOwnProperty('CriticalLow') &&
673 reading.hasOwnProperty('WarningLow') &&
674 reading.Value >= reading.CriticalLow &&
675 reading.Value <= reading.WarningLow) {
676 severityFlags.warning = true;
677 severityText = 'warning';
678 order = 1;
679 } else if (
680 reading.hasOwnProperty('WarningHigh') &&
681 reading.hasOwnProperty('CriticalHigh') &&
682 reading.Value >= reading.WarningHigh &&
683 reading.Value <= reading.CriticalHigh) {
684 severityFlags.warning = true;
685 severityText = 'warning';
686 order = 1;
687 } else {
688 severityFlags.normal = true;
689 severityText = 'normal';
690 }
691 return {
692 flags: severityFlags,
693 severityText: severityText,
694 order: order
695 };
696 }
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700697
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700698 for (var key in content.data) {
699 if (content.data.hasOwnProperty(key) &&
700 content.data[key].hasOwnProperty('Unit')) {
701 severity = getSensorStatus(content.data[key]);
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700702
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700703 if (!content.data[key].hasOwnProperty('CriticalLow')) {
704 content.data[key].CriticalLow = '--';
705 content.data[key].CriticalHigh = '--';
706 }
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700707
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700708 if (!content.data[key].hasOwnProperty('WarningLow')) {
709 content.data[key].WarningLow = '--';
710 content.data[key].WarningHigh = '--';
711 }
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700712
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700713 tempKeyParts = key.split('/');
714 title = tempKeyParts.pop();
715 title = tempKeyParts.pop() + '_' + title;
716 title = title.split('_')
717 .map(function(item) {
718 return item.toLowerCase()
719 .charAt(0)
720 .toUpperCase() +
721 item.slice(1);
722 })
723 .reduce(function(prev, el) {
724 return prev + ' ' + el;
725 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700726
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700727 content.data[key].Value = getScaledValue(
728 content.data[key].Value, content.data[key].Scale);
729 content.data[key].CriticalLow = getScaledValue(
730 content.data[key].CriticalLow,
731 content.data[key].Scale);
732 content.data[key].CriticalHigh = getScaledValue(
733 content.data[key].CriticalHigh,
734 content.data[key].Scale);
735 content.data[key].WarningLow = getScaledValue(
736 content.data[key].WarningLow,
737 content.data[key].Scale);
738 content.data[key].WarningHigh = getScaledValue(
739 content.data[key].WarningHigh,
740 content.data[key].Scale);
741 if (Constants.SENSOR_SORT_ORDER.indexOf(
742 content.data[key].Unit) > -1) {
743 customOrder = Constants.SENSOR_SORT_ORDER.indexOf(
744 content.data[key].Unit);
745 } else {
746 customOrder = Constants.SENSOR_SORT_ORDER_DEFAULT;
747 }
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700748
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700749 sensorData.push(Object.assign(
750 {
751 path: key,
752 selected: false,
753 confirm: false,
754 copied: false,
755 title: title,
756 unit:
757 Constants
758 .SENSOR_UNIT_MAP[content.data[key].Unit],
759 severity_flags: severity.flags,
760 status: severity.severityText,
761 order: severity.order,
762 custom_order: customOrder,
763 search_text:
764 (title + ' ' + content.data[key].Value + ' ' +
765 Constants.SENSOR_UNIT_MAP[content.data[key]
766 .Unit] +
767 ' ' + severity.severityText + ' ' +
768 content.data[key].CriticalLow + ' ' +
769 content.data[key].CriticalHigh + ' ' +
770 content.data[key].WarningLow + ' ' +
771 content.data[key].WarningHigh + ' ')
772 .toLowerCase(),
773 original_data:
774 {key: key, value: content.data[key]}
775 },
776 content.data[key]));
777 }
778 }
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700779
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700780 callback(sensorData, dataClone);
781 },
782 function(error) {
783 console.log(error);
784 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700785 },
786 getActivation: function(imageId) {
787 return $http({
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700788 method: 'GET',
789 url: DataService.getHost() +
790 '/xyz/openbmc_project/software/' + imageId +
791 '/attr/Activation',
792 headers: {
793 'Accept': 'application/json',
794 'Content-Type': 'application/json'
795 },
796 withCredentials: true
797 })
798 .then(function(response) {
799 return response.data;
800 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700801 },
802 getFirmwares: function() {
803 var deferred = $q.defer();
804 $http({
805 method: 'GET',
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700806 url: DataService.getHost() +
807 '/xyz/openbmc_project/software/enumerate',
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700808 headers: {
809 'Accept': 'application/json',
810 'Content-Type': 'application/json'
811 },
812 withCredentials: true
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700813 })
814 .then(
815 function(response) {
816 var json = JSON.stringify(response.data);
817 var content = JSON.parse(json);
818 var data = [];
819 var activationStatus = '';
820 var isExtended = false;
821 var bmcActiveVersion = '';
822 var hostActiveVersion = '';
823 var imageType = '';
824 var extendedVersions = [];
825 var functionalImages = [];
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700826
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700827 function getFormatedExtendedVersions(extendedVersion) {
828 var versions = [];
829 extendedVersion = extendedVersion.split(',');
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700830
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700831 extendedVersion.forEach(function(item) {
832 var parts = item.split('-');
833 var numberIndex = 0;
834 for (var i = 0; i < parts.length; i++) {
835 if (/[0-9]/.test(parts[i])) {
836 numberIndex = i;
837 break;
838 }
839 }
840 var titlePart = parts.splice(0, numberIndex);
841 titlePart = titlePart.join('');
842 titlePart = titlePart[0].toUpperCase() +
843 titlePart.substr(1, titlePart.length);
844 var versionPart = parts.join('-');
845 versions.push({title: titlePart, version: versionPart});
846 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700847
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700848 return versions;
849 }
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700850
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700851 // Get the list of functional images so we can compare
852 // later if an image is functional
853 if (content.data[Constants.FIRMWARE.FUNCTIONAL_OBJPATH]) {
854 functionalImages =
855 content.data[Constants.FIRMWARE.FUNCTIONAL_OBJPATH]
856 .endpoints;
857 }
858 for (var key in content.data) {
859 if (content.data.hasOwnProperty(key) &&
860 content.data[key].hasOwnProperty('Version')) {
861 // If the image is "Functional" use that for the
862 // activation status, else use the value of "Activation"
863 // github.com/openbmc/phosphor-dbus-interfaces/blob/master/xyz/openbmc_project/Software/Activation.interface.yaml
864 activationStatus =
865 content.data[key].Activation.split('.').pop();
866 if (functionalImages.includes(key)) {
867 activationStatus = 'Functional';
868 }
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700869
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700870 imageType = content.data[key].Purpose.split('.').pop();
871 isExtended = content.data[key].hasOwnProperty(
872 'ExtendedVersion') &&
873 content.data[key].ExtendedVersion != '';
874 if (isExtended) {
875 extendedVersions = getFormatedExtendedVersions(
876 content.data[key].ExtendedVersion);
877 }
878 data.push(Object.assign(
879 {
880 path: key,
881 activationStatus: activationStatus,
882 imageId: key.split('/').pop(),
883 imageType: imageType,
884 isExtended: isExtended,
885 extended:
886 {show: false, versions: extendedVersions},
887 data: {key: key, value: content.data[key]}
888 },
889 content.data[key]));
890
891 if (activationStatus == 'Functional' &&
892 imageType == 'BMC') {
893 bmcActiveVersion = content.data[key].Version;
894 }
895
896 if (activationStatus == 'Functional' &&
897 imageType == 'Host') {
898 hostActiveVersion = content.data[key].Version;
899 }
900 }
901 }
902
903 deferred.resolve({
904 data: data,
905 bmcActiveVersion: bmcActiveVersion,
906 hostActiveVersion: hostActiveVersion
907 });
Iftekharul Islam171c6a12017-08-11 08:35:47 -0500908 },
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700909 function(error) {
910 console.log(error);
911 deferred.reject(error);
912 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700913
914 return deferred.promise;
915 },
916 changePriority: function(imageId, priority) {
917 var deferred = $q.defer();
918 $http({
919 method: 'PUT',
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700920 url: DataService.getHost() + '/xyz/openbmc_project/software/' +
921 imageId + '/attr/Priority',
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700922 headers: {
923 'Accept': 'application/json',
924 'Content-Type': 'application/json'
925 },
926 withCredentials: true,
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700927 data: JSON.stringify({'data': priority})
928 })
929 .then(
930 function(response) {
931 var json = JSON.stringify(response.data);
932 var content = JSON.parse(json);
933 deferred.resolve(content);
934 },
935 function(error) {
936 console.log(error);
937 deferred.reject(error);
938 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700939
940 return deferred.promise;
941 },
942 deleteImage: function(imageId) {
943 var deferred = $q.defer();
944 $http({
945 method: 'POST',
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700946 url: DataService.getHost() + '/xyz/openbmc_project/software/' +
947 imageId + '/action/Delete',
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700948 headers: {
949 'Accept': 'application/json',
950 'Content-Type': 'application/json'
951 },
952 withCredentials: true,
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700953 data: JSON.stringify({'data': []})
954 })
955 .then(
956 function(response) {
957 var json = JSON.stringify(response.data);
958 var content = JSON.parse(json);
959 deferred.resolve(content);
960 },
961 function(error) {
962 console.log(error);
963 deferred.reject(error);
964 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700965
966 return deferred.promise;
967 },
968 activateImage: function(imageId) {
969 var deferred = $q.defer();
970 $http({
971 method: 'PUT',
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700972 url: DataService.getHost() + '/xyz/openbmc_project/software/' +
973 imageId + '/attr/RequestedActivation',
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700974 headers: {
975 'Accept': 'application/json',
976 'Content-Type': 'application/json'
977 },
978 withCredentials: true,
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700979 data:
980 JSON.stringify({'data': Constants.FIRMWARE.ACTIVATE_FIRMWARE})
981 })
982 .then(
983 function(response) {
984 var json = JSON.stringify(response.data);
985 var content = JSON.parse(json);
986 deferred.resolve(content);
987 },
988 function(error) {
989 console.log(error);
990 deferred.reject(error);
991 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700992
993 return deferred.promise;
994 },
995 uploadImage: function(file) {
996 return $http({
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700997 method: 'POST',
998 timeout: 5 * 60 * 1000,
999 url: DataService.getHost() + '/upload/image',
1000 headers: {'Content-Type': 'application/octet-stream'},
1001 withCredentials: true,
1002 data: file
1003 })
1004 .then(function(response) {
1005 return response.data;
1006 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001007 },
1008 downloadImage: function(host, filename) {
1009 return $http({
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001010 method: 'POST',
1011 url: DataService.getHost() +
1012 '/xyz/openbmc_project/software/action/DownloadViaTFTP',
1013 headers: {
1014 'Accept': 'application/json',
1015 'Content-Type': 'application/json'
1016 },
1017 withCredentials: true,
1018 data: JSON.stringify({'data': [filename, host]}),
1019 responseType: 'arraybuffer'
1020 })
1021 .then(function(response) {
1022 return response.data;
1023 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001024 },
1025 getBMCEthernetInfo: function() {
1026 var deferred = $q.defer();
1027 $http({
1028 method: 'GET',
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001029 url: DataService.getHost() +
1030 '/xyz/openbmc_project/inventory/system/chassis/motherboard/boxelder/bmc/ethernet',
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001031 headers: {
1032 'Accept': 'application/json',
1033 'Content-Type': 'application/json'
1034 },
1035 withCredentials: true
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001036 })
1037 .then(
1038 function(response) {
1039 var json = JSON.stringify(response.data);
1040 var content = JSON.parse(json);
1041 deferred.resolve(content.data);
1042 },
1043 function(error) {
1044 console.log(error);
1045 deferred.reject(error);
1046 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001047
1048 return deferred.promise;
1049 },
1050 getBMCInfo: function(callback) {
1051 var deferred = $q.defer();
1052 $http({
1053 method: 'GET',
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001054 url: DataService.getHost() +
1055 '/xyz/openbmc_project/inventory/system/chassis/motherboard/boxelder/bmc',
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001056 headers: {
1057 'Accept': 'application/json',
1058 'Content-Type': 'application/json'
1059 },
1060 withCredentials: true
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001061 })
1062 .then(
1063 function(response) {
1064 var json = JSON.stringify(response.data);
1065 var content = JSON.parse(json);
1066 deferred.resolve(content.data);
1067 },
1068 function(error) {
1069 console.log(error);
1070 deferred.reject(error);
1071 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001072 return deferred.promise;
1073 },
1074 getServerInfo: function() {
1075 // TODO: openbmc/openbmc#3117 Need a way via REST to get
1076 // interfaces so we can get the system object(s) by the looking
1077 // for the system interface.
1078 return $http({
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001079 method: 'GET',
1080 url: DataService.getHost() +
1081 '/xyz/openbmc_project/inventory/system',
1082 headers: {
1083 'Accept': 'application/json',
1084 'Content-Type': 'application/json'
1085 },
1086 withCredentials: true
1087 })
1088 .then(function(response) {
1089 return response.data;
1090 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001091 },
1092 getBMCTime: function() {
1093 return $http({
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001094 method: 'GET',
1095 url: DataService.getHost() + '/xyz/openbmc_project/time/bmc',
1096 headers: {
1097 'Accept': 'application/json',
1098 'Content-Type': 'application/json'
1099 },
1100 withCredentials: true
1101 })
1102 .then(function(response) {
1103 return response.data;
1104 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001105 },
1106 getHardwares: function(callback) {
1107 $http({
1108 method: 'GET',
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001109 url: DataService.getHost() +
1110 '/xyz/openbmc_project/inventory/enumerate',
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001111 headers: {
1112 'Accept': 'application/json',
1113 'Content-Type': 'application/json'
1114 },
1115 withCredentials: true
1116 }).then(function(response) {
1117 var json = JSON.stringify(response.data);
1118 var content = JSON.parse(json);
1119 var hardwareData = [];
1120 var keyIndexMap = {};
1121 var title = '';
1122 var data = [];
1123 var searchText = '';
1124 var componentIndex = -1;
1125 var tempParts = [];
1126
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001127 function isSubComponent(key) {
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001128 for (var i = 0; i < Constants.HARDWARE.parent_components.length;
1129 i++) {
1130 if (key.split(Constants.HARDWARE.parent_components[i]).length ==
1131 2)
1132 return true;
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001133 }
1134
1135 return false;
1136 }
1137
1138 function titlelize(title) {
1139 title = title.replace(/([A-Z0-9]+)/g, ' $1').replace(/^\s+/, '');
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001140 for (var i = 0; i < Constants.HARDWARE.uppercase_titles.length;
1141 i++) {
1142 if (title.toLowerCase().indexOf(
1143 (Constants.HARDWARE.uppercase_titles[i] + ' ')) > -1) {
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001144 return title.toUpperCase();
1145 }
1146 }
1147
1148 return title;
1149 }
1150
1151 function camelcaseToLabel(obj) {
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001152 var transformed = [], label = '', value = '';
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001153 for (var key in obj) {
1154 label = key.replace(/([A-Z0-9]+)/g, ' $1').replace(/^\s+/, '');
1155 if (obj[key] !== '') {
1156 value = obj[key];
1157 if (value == 1 || value == 0) {
1158 value = (value == 1) ? 'Yes' : 'No';
1159 }
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001160 transformed.push({key: label, value: value});
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001161 }
1162 }
1163
1164 return transformed;
1165 }
1166
1167 function getSearchText(data) {
1168 var searchText = '';
1169 for (var i = 0; i < data.length; i++) {
1170 searchText += ' ' + data[i].key + ' ' + data[i].value;
1171 }
1172
1173 return searchText;
1174 }
1175
1176 for (var key in content.data) {
1177 if (content.data.hasOwnProperty(key) &&
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001178 key.indexOf(Constants.HARDWARE.component_key_filter) == 0) {
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001179 data = camelcaseToLabel(content.data[key]);
1180 searchText = getSearchText(data);
1181 title = key.split('/').pop();
1182
1183 title = titlelize(title);
1184
1185 if (!isSubComponent(key)) {
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001186 hardwareData.push(Object.assign(
1187 {
1188 path: key,
1189 title: title,
1190 selected: false,
1191 expanded: false,
1192 search_text: title.toLowerCase() + ' ' +
1193 searchText.toLowerCase(),
1194 sub_components: [],
1195 original_data: {key: key, value: content.data[key]}
1196 },
1197 {items: data}));
Iftekharul Islam2a489552017-11-02 13:23:08 -05001198
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001199 keyIndexMap[key] = hardwareData.length - 1;
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001200 } else {
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001201 var tempParts = key.split('/');
1202 tempParts.pop();
1203 tempParts = tempParts.join('/');
1204 componentIndex = keyIndexMap[tempParts];
1205 data = content.data[key];
1206 data.title = title;
1207 hardwareData[componentIndex].sub_components.push(data);
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001208 hardwareData[componentIndex].search_text +=
1209 ' ' + title.toLowerCase();
Iftekharul Islam171c6a12017-08-11 08:35:47 -05001210
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001211 // Sort the subcomponents alphanumeric so they are displayed
1212 // on the inventory page in order (e.g. core 0, core 1, core
1213 // 2, ... core 12, core 13)
1214 hardwareData[componentIndex].sub_components.sort(function(
1215 a, b) {
1216 return a.title.localeCompare(
1217 b.title, 'en', {numeric: true});
Gunnar Mills55a8e392018-03-14 15:37:44 -05001218 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001219 }
1220 }
1221 }
1222
1223 if (callback) {
1224 callback(hardwareData, content.data);
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001225 } else {
1226 return {data: hardwareData, original_data: content.data};
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001227 }
1228 });
1229 },
1230 deleteLogs: function(logs) {
1231 var defer = $q.defer();
1232 var promises = [];
1233
1234 function finished() {
1235 defer.resolve();
1236 }
1237
1238 logs.forEach(function(item) {
1239 promises.push($http({
1240 method: 'POST',
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001241 url: DataService.getHost() +
1242 '/xyz/openbmc_project/logging/entry/' + item.Id +
1243 '/action/Delete',
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001244 headers: {
1245 'Accept': 'application/json',
1246 'Content-Type': 'application/json'
Gunnar Mills55a8e392018-03-14 15:37:44 -05001247 },
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001248 withCredentials: true,
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001249 data: JSON.stringify({'data': []})
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001250 }));
1251 });
1252
1253 $q.all(promises).then(finished);
1254
1255 return defer.promise;
1256 },
1257 resolveLogs: function(logs) {
1258 var defer = $q.defer();
1259 var promises = [];
1260
1261 function finished() {
1262 defer.resolve();
1263 }
1264
1265 logs.forEach(function(item) {
1266 promises.push($http({
1267 method: 'PUT',
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001268 url: DataService.getHost() +
1269 '/xyz/openbmc_project/logging/entry/' + item.Id +
1270 '/attr/Resolved',
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001271 headers: {
1272 'Accept': 'application/json',
1273 'Content-Type': 'application/json'
Iftekharul Islam99d199f2017-03-24 15:28:25 -05001274 },
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001275 withCredentials: true,
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001276 data: JSON.stringify({'data': '1'})
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001277 }));
1278 });
Iftekharul Islama1d238f2018-02-26 12:29:45 -06001279
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001280 $q.all(promises).then(finished);
Iftekharul Islamcd789502017-04-19 14:37:55 -05001281
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001282 return defer.promise;
1283 },
1284 getPowerConsumption: function() {
1285 return $http({
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001286 method: 'GET',
1287 url: DataService.getHost() +
1288 '/xyz/openbmc_project/sensors/power/total_power',
1289 headers: {
1290 'Accept': 'application/json',
1291 'Content-Type': 'application/json'
1292 },
1293 withCredentials: true
1294 })
1295 .then(
1296 function(response) {
1297 var json = JSON.stringify(response.data);
1298 var content = JSON.parse(json);
Iftekharul Islamcd789502017-04-19 14:37:55 -05001299
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001300 return getScaledValue(
1301 content.data.Value, content.data.Scale) +
1302 ' ' +
1303 Constants.POWER_CONSUMPTION_TEXT[content.data.Unit];
1304 },
1305 function(error) {
1306 if ('Not Found' == error.statusText) {
1307 return Constants.POWER_CONSUMPTION_TEXT.notavailable;
1308 } else {
1309 throw error;
1310 }
1311 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001312 },
1313 getPowerCap: function() {
1314 return $http({
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001315 method: 'GET',
1316 url: DataService.getHost() +
1317 '/xyz/openbmc_project/control/host0/power_cap',
1318 headers: {
1319 'Accept': 'application/json',
1320 'Content-Type': 'application/json'
1321 },
1322 withCredentials: true
1323 })
1324 .then(function(response) {
1325 var json = JSON.stringify(response.data);
1326 var content = JSON.parse(json);
Michael Davisdf3bd122017-08-10 11:03:42 -05001327
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001328 return (false == content.data.PowerCapEnable) ?
1329 Constants.POWER_CAP_TEXT.disabled :
1330 content.data.PowerCap + ' ' + Constants.POWER_CAP_TEXT.unit;
1331 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001332 },
1333 setHostname: function(hostname) {
1334 return $http({
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001335 method: 'PUT',
1336 url: DataService.getHost() +
1337 '/xyz/openbmc_project/network/config/attr/HostName',
1338 headers: {
1339 'Accept': 'application/json',
1340 'Content-Type': 'application/json'
1341 },
1342 withCredentials: true,
1343 data: JSON.stringify({'data': hostname})
1344 })
1345 .then(function(response) {
1346 return response.data;
1347 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001348 },
1349 };
1350 return SERVICE;
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001351 }
1352 ]);
Iftekharul Islamd2269e22017-05-02 09:32:45 -05001353
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001354})(window.angular);