blob: 23355e109846cbc9aa4de02eb7e91cc61c717b9b [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', [
beccabroekc3abaa92018-08-14 13:47:18 -050012 '$http', 'Constants', '$q', 'dataService', '$interval',
13 function($http, Constants, $q, DataService, $interval) {
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,
Andrew Geisslerba5e3f32018-05-24 10:58:00 -070029 HOST_STATE_TEXT: Constants.HOST_STATE,
Andrew Geisslerba5e3f32018-05-24 10:58:00 -070030 LED_STATE: Constants.LED_STATE,
31 LED_STATE_TEXT: Constants.LED_STATE_TEXT,
32 HOST_SESSION_STORAGE_KEY: Constants.API_CREDENTIALS.host_storage_key,
Gunnar Mills65491142018-06-04 14:23:33 -050033 validIPV4IP: function(ip) {
34 // Checks for [0-255].[0-255].[0-255].[0-255]
35 return ip.match(
36 /\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b/);
37 },
AppaRao Pulib1289ec2018-11-14 20:33:30 +053038 getRedfishSysName: function() {
39 return $http({
40 method: 'GET',
41 url: DataService.getHost() + '/redfish/v1/Systems',
42 withCredentials: true
43 })
44 .then(
45 function(response) {
46 var sysUrl = response.data['Members'][0]['@odata.id'];
47 return sysUrl.split('/').pop(-1);
48 },
49 function(error) {
50 console.log(JSON.stringify(error));
51 });
52 },
53 getSystemLogs: function(recordType) {
54 var uri = '/redfish/v1/Systems/' + DataService.systemName +
55 '/LogServices/EventLog/Entries';
56 return $http({
57 method: 'GET',
58 url: DataService.getHost() + uri,
59 withCredentials: true
60 })
61 .then(
62 function(response) {
63 var logEntries = [];
64 angular.forEach(response.data['Members'], function(log) {
65 if (log.hasOwnProperty('EntryType')) {
66 if (log['EntryType'] == recordType) {
67 logEntries.push(log);
68 }
69 }
70 });
71 return logEntries;
72 },
73 function(error) {
74 console.log(JSON.stringify(error));
75 });
76 },
77 clearSystemLogs: function() {
78 var uri = '/redfish/v1/Systems/' + DataService.systemName +
79 '/LogServices/EventLog/Actions/LogService.ClearLog';
80 return $http({
81 method: 'POST',
82 url: DataService.getHost() + uri,
83 withCredentials: true
84 });
85 },
Gunnar Mills854fbba2018-09-13 15:41:30 -050086 deleteObject: function(path) {
87 return $http({
88 method: 'POST',
89 url: DataService.getHost() + path + '/action/Delete',
90 withCredentials: true,
91 data: JSON.stringify({'data': []})
92 })
93 .then(function(response) {
94 return response.data;
95 });
96 },
Andrew Geisslerba5e3f32018-05-24 10:58:00 -070097 getHostState: function() {
98 var deferred = $q.defer();
99 $http({
100 method: 'GET',
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700101 url: DataService.getHost() +
102 '/xyz/openbmc_project/state/host0/attr/CurrentHostState',
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700103 withCredentials: true
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700104 })
105 .then(
106 function(response) {
107 var json = JSON.stringify(response.data);
108 var content = JSON.parse(json);
109 deferred.resolve(content.data);
110 },
111 function(error) {
112 console.log(error);
113 deferred.reject(error);
114 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700115 return deferred.promise;
116 },
Gunnar Millsff64c542018-08-24 15:49:09 -0500117 getSNMPManagers: function() {
118 return $http({
119 method: 'GET',
120 url: DataService.getHost() +
121 '/xyz/openbmc_project/network/snmp/manager/enumerate',
Gunnar Millsff64c542018-08-24 15:49:09 -0500122 withCredentials: true
123 })
124 .then(function(response) {
125 return response.data;
126 });
127 },
beccabroekc3abaa92018-08-14 13:47:18 -0500128 pollHostStatusTillOn: function() {
129 var deferred = $q.defer();
130 var hostOnTimeout = setTimeout(function() {
131 ws.close();
132 deferred.reject(new Error(Constants.MESSAGES.POLL.HOST_ON_TIMEOUT));
133 }, Constants.TIMEOUT.HOST_ON);
134
135 var ws =
136 new WebSocket('wss://' + DataService.server_id + '/subscribe');
137 var data = JSON.stringify({
138 'paths': ['/xyz/openbmc_project/state/host0'],
139 'interfaces': ['xyz.openbmc_project.State.Host']
140 });
141 ws.onopen = function() {
142 ws.send(data);
143 };
144 ws.onmessage = function(evt) {
145 var content = JSON.parse(evt.data);
146 var hostState = content.properties.CurrentHostState;
147 if (hostState === Constants.HOST_STATE_TEXT.on_code) {
148 clearTimeout(hostOnTimeout);
149 ws.close();
150 deferred.resolve();
151 } else if (hostState === Constants.HOST_STATE_TEXT.error_code) {
152 clearTimeout(hostOnTimeout);
153 ws.close();
154 deferred.reject(new Error(Constants.MESSAGES.POLL.HOST_QUIESCED));
155 }
156 };
157 },
158
159 pollHostStatusTilReboot: function() {
160 var deferred = $q.defer();
161 var onState = Constants.HOST_STATE_TEXT.on_code;
162 var offState = Constants.HOST_STATE_TEXT.on_code;
163 var hostTimeout;
164 var setHostTimeout = function(message, timeout) {
165 hostTimeout = setTimeout(function() {
166 ws.close();
167 deferred.reject(new Error(message));
168 }, timeout);
169 };
170 var ws =
171 new WebSocket('wss://' + DataService.server_id + '/subscribe');
172 var data = JSON.stringify({
173 'paths': ['/xyz/openbmc_project/state/host0'],
174 'interfaces': ['xyz.openbmc_project.State.Host']
175 });
176 ws.onopen = function() {
177 ws.send(data);
178 };
179 setHostTimeout(
180 Constants.MESSAGES.POLL.HOST_OFF_TIMEOUT,
181 Constants.TIMEOUT.HOST_OFF);
182 var pollState = offState;
183 ws.onmessage = function(evt) {
184 var content = JSON.parse(evt.data);
185 var hostState = content.properties.CurrentHostState;
186 if (hostState === pollState) {
187 if (pollState === offState) {
188 clearTimeout(hostTimeout);
189 pollState = onState;
190 setHostTimeout(
191 Constants.MESSAGES.POLL.HOST_ON_TIMEOUT,
192 Constants.TIMEOUT.HOST_ON);
193 }
194 if (pollState === onState) {
195 clearTimeout(hostTimeout);
196 ws.close();
197 deferred.resolve();
198 }
199 } else if (hostState === Constants.HOST_STATE_TEXT.error_code) {
200 clearTimeout(hostTimeout);
201 ws.close();
202 deferred.reject(new Error(Constants.MESSAGES.POLL.HOST_QUIESCED));
203 }
204 };
205 },
206
207 pollHostStatusTillOff: function() {
208 var deferred = $q.defer();
209 var hostOffTimeout = setTimeout(function() {
210 ws.close();
211 deferred.reject(
212 new Error(Constants.MESSAGES.POLL.HOST_OFF_TIMEOUT));
213 }, Constants.TIMEOUT.HOST_OFF);
214
215 var ws =
216 new WebSocket('wss://' + DataService.server_id + '/subscribe');
217 var data = JSON.stringify({
218 'paths': ['/xyz/openbmc_project/state/host0'],
219 'interfaces': ['xyz.openbmc_project.State.Host']
220 });
221 ws.onopen = function() {
222 ws.send(data);
223 };
224 ws.onmessage = function(evt) {
225 var content = JSON.parse(evt.data);
226 var hostState = content.properties.CurrentHostState;
227 if (hostState === Constants.HOST_STATE_TEXT.off_code) {
228 clearTimeout(hostOffTimeout);
229 ws.close();
230 deferred.resolve();
231 }
232 };
233 },
Gunnar Mills854fbba2018-09-13 15:41:30 -0500234 addSNMPManager: function(address, port) {
235 return $http({
236 method: 'POST',
237 url: DataService.getHost() +
238 '/xyz/openbmc_project/network/snmp/manager/action/Client',
239 withCredentials: true,
240 data: JSON.stringify({'data': [address, +port]})
241 })
242 .then(function(response) {
243 return response.data;
244 });
245 },
246 setSNMPManagerPort: function(snmpManagerPath, port) {
247 return $http({
248 method: 'PUT',
249 url: DataService.getHost() + snmpManagerPath + '/attr/Port',
250 withCredentials: true,
251 data: JSON.stringify({'data': +port})
252 })
253 .then(function(response) {
254 return response.data;
255 });
256 },
257 setSNMPManagerAddress: function(snmpManagerPath, address) {
258 return $http({
259 method: 'PUT',
260 url: DataService.getHost() + snmpManagerPath +
261 '/attr/Address',
262 withCredentials: true,
263 data: JSON.stringify({'data': address})
264 })
265 .then(function(response) {
266 return response.data;
267 });
268 },
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700269 getNetworkInfo: function() {
270 var deferred = $q.defer();
271 $http({
272 method: 'GET',
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700273 url: DataService.getHost() +
274 '/xyz/openbmc_project/network/enumerate',
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700275 withCredentials: true
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700276 })
277 .then(
278 function(response) {
279 var json = JSON.stringify(response.data);
280 var content = JSON.parse(json);
281 var hostname = '';
Gunnar Millse9f5fe72018-05-04 13:43:10 -0500282 var defaultgateway = '';
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700283 var macAddress = '';
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700284
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700285 function parseNetworkData(content) {
286 var data = {
287 interface_ids: [],
288 interfaces: {},
289 ip_addresses: {ipv4: [], ipv6: []},
290 };
291 var interfaceId = '', keyParts = [], interfaceHash = '',
292 interfaceType = '';
293 for (var key in content.data) {
Gunnar Mills3efbe2d2018-06-07 14:47:19 -0500294 if (key.match(/network\/eth\d+(_\d+)?$/ig)) {
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700295 interfaceId = key.split('/').pop();
296 if (data.interface_ids.indexOf(interfaceId) == -1) {
297 data.interface_ids.push(interfaceId);
298 data.interfaces[interfaceId] = {
299 interfaceIname: '',
300 DomainName: '',
301 MACAddress: '',
302 Nameservers: [],
303 DHCPEnabled: 0,
304 ipv4: {ids: [], values: []},
305 ipv6: {ids: [], values: []}
306 };
307 data.interfaces[interfaceId].MACAddress =
308 content.data[key].MACAddress;
309 data.interfaces[interfaceId].DomainName =
310 content.data[key].DomainName.join(' ');
311 data.interfaces[interfaceId].Nameservers =
312 content.data[key].Nameservers;
313 data.interfaces[interfaceId].DHCPEnabled =
314 content.data[key].DHCPEnabled;
315 }
316 } else if (
317 key.match(
Gunnar Mills3efbe2d2018-06-07 14:47:19 -0500318 /network\/eth\d+(_\d+)?\/ipv[4|6]\/[a-z0-9]+$/ig)) {
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700319 keyParts = key.split('/');
320 interfaceHash = keyParts.pop();
321 interfaceType = keyParts.pop();
322 interfaceId = keyParts.pop();
323
324 if (data.interfaces[interfaceId][interfaceType]
325 .ids.indexOf(interfaceHash) == -1) {
326 data.interfaces[interfaceId][interfaceType]
327 .ids.push(interfaceHash);
328 data.interfaces[interfaceId][interfaceType]
329 .values.push(content.data[key]);
330 data.ip_addresses[interfaceType].push(
331 content.data[key]['Address']);
332 }
333 }
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700334 }
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700335 return data;
336 }
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700337
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700338 if (content.data.hasOwnProperty(
Gunnar Millse9f5fe72018-05-04 13:43:10 -0500339 '/xyz/openbmc_project/network/config')) {
340 if (content.data['/xyz/openbmc_project/network/config']
341 .hasOwnProperty('HostName')) {
342 hostname =
343 content.data['/xyz/openbmc_project/network/config']
344 .HostName;
345 }
346 if (content.data['/xyz/openbmc_project/network/config']
347 .hasOwnProperty('DefaultGateway')) {
348 defaultgateway =
349 content.data['/xyz/openbmc_project/network/config']
350 .DefaultGateway;
351 }
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700352 }
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700353
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700354 if (content.data.hasOwnProperty(
355 '/xyz/openbmc_project/network/eth0') &&
356 content.data['/xyz/openbmc_project/network/eth0']
357 .hasOwnProperty('MACAddress')) {
358 macAddress =
359 content.data['/xyz/openbmc_project/network/eth0']
360 .MACAddress;
361 }
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700362
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700363 deferred.resolve({
364 data: content.data,
365 hostname: hostname,
Gunnar Millse9f5fe72018-05-04 13:43:10 -0500366 defaultgateway: defaultgateway,
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700367 mac_address: macAddress,
368 formatted_data: parseNetworkData(content)
369 });
370 },
371 function(error) {
372 console.log(error);
373 deferred.reject(error);
374 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700375 return deferred.promise;
376 },
Gunnar Mills7ddc7272018-04-12 16:12:03 -0500377 setMACAddress: function(interface_name, mac_address) {
378 return $http({
379 method: 'PUT',
380 url: DataService.getHost() +
381 '/xyz/openbmc_project/network/' + interface_name +
382 '/attr/MACAddress',
Gunnar Mills7ddc7272018-04-12 16:12:03 -0500383 withCredentials: true,
384 data: JSON.stringify({'data': mac_address})
385 })
386 .then(function(response) {
387 return response.data;
388 });
389 },
Gunnar Millsdca79d72018-05-30 13:07:01 -0500390 setDefaultGateway: function(defaultGateway) {
391 return $http({
392 method: 'PUT',
393 url: DataService.getHost() +
394 '/xyz/openbmc_project/network/config/attr/DefaultGateway',
Gunnar Millsdca79d72018-05-30 13:07:01 -0500395 withCredentials: true,
396 data: JSON.stringify({'data': defaultGateway})
397 })
398 .then(function(response) {
399 return response.data;
400 });
401 },
Gunnar Millscb2c3062018-05-31 13:13:30 -0500402 setDHCPEnabled: function(interfaceName, dhcpEnabled) {
403 return $http({
404 method: 'PUT',
405 url: DataService.getHost() +
406 '/xyz/openbmc_project/network/' + interfaceName +
407 '/attr/DHCPEnabled',
Gunnar Millscb2c3062018-05-31 13:13:30 -0500408 withCredentials: true,
409 data: JSON.stringify({'data': dhcpEnabled})
410 })
411 .then(function(response) {
412 return response.data;
413 });
414 },
Gunnar Mills06467822018-06-06 15:43:18 -0500415 setNameservers: function(interfaceName, dnsServers) {
416 return $http({
417 method: 'PUT',
418 url: DataService.getHost() +
419 '/xyz/openbmc_project/network/' + interfaceName +
420 '/attr/Nameservers',
Gunnar Mills06467822018-06-06 15:43:18 -0500421 withCredentials: true,
422 data: JSON.stringify({'data': dnsServers})
423 })
424 .then(function(response) {
425 return response.data;
426 });
427 },
Gunnar Millsa45c3852018-05-30 16:18:45 -0500428 deleteIPV4: function(interfaceName, networkID) {
429 return $http({
430 method: 'POST',
431 url: DataService.getHost() +
432 '/xyz/openbmc_project/network/' + interfaceName +
433 '/ipv4/' + networkID + '/action/Delete',
Gunnar Millsa45c3852018-05-30 16:18:45 -0500434 withCredentials: true,
435 data: JSON.stringify({'data': []})
436 })
437 .then(function(response) {
438 return response.data;
439 });
440 },
441 addIPV4: function(
442 interfaceName, ipAddress, netmaskPrefixLength, gateway) {
443 return $http({
444 method: 'POST',
445 url: DataService.getHost() +
446 '/xyz/openbmc_project/network/' + interfaceName +
447 '/action/IP',
Gunnar Millsa45c3852018-05-30 16:18:45 -0500448 withCredentials: true,
449 data: JSON.stringify({
450 'data': [
451 'xyz.openbmc_project.Network.IP.Protocol.IPv4',
452 ipAddress, +netmaskPrefixLength, gateway
453 ]
454 })
455 })
456 .then(function(response) {
457 return response.data;
458 });
459 },
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700460 getLEDState: function() {
461 var deferred = $q.defer();
462 $http({
463 method: 'GET',
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700464 url: DataService.getHost() +
465 '/xyz/openbmc_project/led/groups/enclosure_identify',
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700466 withCredentials: true
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700467 })
468 .then(
469 function(response) {
470 var json = JSON.stringify(response.data);
471 var content = JSON.parse(json);
472 deferred.resolve(content.data.Asserted);
473 },
474 function(error) {
475 console.log(error);
476 deferred.reject(error);
477 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700478 return deferred.promise;
479 },
480 login: function(username, password, callback) {
481 $http({
482 method: 'POST',
483 url: DataService.getHost() + '/login',
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700484 withCredentials: true,
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700485 data: JSON.stringify({'data': [username, password]})
486 })
487 .then(
488 function(response) {
489 if (callback) {
490 callback(response.data);
491 }
492 },
493 function(error) {
494 if (callback) {
495 if (error && error.status && error.status == 'error') {
496 callback(error);
497 } else {
498 callback(error, true);
499 }
500 }
501 console.log(error);
502 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700503 },
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700504 logout: function(callback) {
505 $http({
506 method: 'POST',
507 url: DataService.getHost() + '/logout',
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700508 withCredentials: true,
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700509 data: JSON.stringify({'data': []})
510 })
511 .then(
512 function(response) {
513 if (callback) {
514 callback(response.data);
515 }
516 },
517 function(error) {
518 if (callback) {
519 callback(null, error);
520 }
521 console.log(error);
522 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700523 },
AppaRao Pulicf7219c2018-12-27 16:17:46 +0530524 getAccountServiceRoles: function() {
525 var roles = [];
526
Gunnar Mills4693ddb2019-03-27 15:49:40 -0500527 return $http({
528 method: 'GET',
529 url: DataService.getHost() +
530 '/redfish/v1/AccountService/Roles',
531 withCredentials: true
532 })
Yoshie Muranakafa562732019-07-17 11:23:15 -0500533 .then(function(response) {
534 var members = response.data['Members'];
535 angular.forEach(members, function(member) {
536 roles.push(member['@odata.id'].split('/').pop());
537 });
538 return roles;
539 });
AppaRao Pulicf7219c2018-12-27 16:17:46 +0530540 },
541 getAllUserAccounts: function() {
AppaRao Puli28711a62018-10-17 16:07:55 +0530542 var deferred = $q.defer();
543 var promises = [];
AppaRao Puli28711a62018-10-17 16:07:55 +0530544
Gunnar Mills4693ddb2019-03-27 15:49:40 -0500545 $http({
546 method: 'GET',
547 url: DataService.getHost() + '/redfish/v1/AccountService/Accounts',
548 withCredentials: true
549 })
550 .then(
551 function(response) {
552 var members = response.data['Members'];
553 angular.forEach(members, function(member) {
554 promises.push(
555 $http({
556 method: 'GET',
557 url: DataService.getHost() + member['@odata.id'],
558 withCredentials: true
559 }).then(function(res) {
560 return res.data;
AppaRao Puli28711a62018-10-17 16:07:55 +0530561 }));
AppaRao Puli28711a62018-10-17 16:07:55 +0530562 });
Gunnar Mills4693ddb2019-03-27 15:49:40 -0500563
564 $q.all(promises).then(
565 function(results) {
566 deferred.resolve(results);
567 },
568 function(errors) {
569 deferred.reject(errors);
570 });
571 },
572 function(error) {
573 console.log(error);
574 deferred.reject(error);
575 });
AppaRao Puli28711a62018-10-17 16:07:55 +0530576 return deferred.promise;
577 },
AppaRao Pulib1e7c862019-03-12 14:56:40 +0530578
Yoshie Muranakafa562732019-07-17 11:23:15 -0500579 getAllUserAccountProperties: function() {
AppaRao Pulib1e7c862019-03-12 14:56:40 +0530580 return $http({
581 method: 'GET',
582 url: DataService.getHost() + '/redfish/v1/AccountService',
583 withCredentials: true
584 })
Yoshie Muranakafa562732019-07-17 11:23:15 -0500585 .then(function(response) {
586 return response.data;
587 });
AppaRao Pulib1e7c862019-03-12 14:56:40 +0530588 },
589
590 saveUserAccountProperties: function(lockoutduration, lockoutthreshold) {
591 var data = {};
592 if (lockoutduration != undefined) {
593 data['AccountLockoutDuration'] = lockoutduration;
594 }
595 if (lockoutthreshold != undefined) {
596 data['AccountLockoutThreshold'] = lockoutthreshold;
597 }
598
599 return $http({
600 method: 'PATCH',
601 url: DataService.getHost() + '/redfish/v1/AccountService',
602 withCredentials: true,
603 data: data
604 });
605 },
606
beccabroek5e258e42018-11-07 12:22:31 -0600607 saveLdapProperties: function(properties) {
608 return $http({
609 method: 'PATCH',
610 url: DataService.getHost() + '/redfish/v1/AccountService',
611 withCredentials: true,
612 data: properties
613 });
614 },
AppaRao Puli28711a62018-10-17 16:07:55 +0530615 createUser: function(user, passwd, role, enabled) {
Gunnar Mills4693ddb2019-03-27 15:49:40 -0500616 var data = {};
617 data['UserName'] = user;
618 data['Password'] = passwd;
619 data['RoleId'] = role;
620 data['Enabled'] = enabled;
AppaRao Puli28711a62018-10-17 16:07:55 +0530621
Gunnar Mills4693ddb2019-03-27 15:49:40 -0500622 return $http({
623 method: 'POST',
624 url: DataService.getHost() + '/redfish/v1/AccountService/Accounts',
625 withCredentials: true,
626 data: data
627 });
AppaRao Puli28711a62018-10-17 16:07:55 +0530628 },
Yoshie Muranakab4d9c092019-08-01 16:19:40 -0500629 updateUser: function(user, newUser, passwd, role, enabled, locked) {
Gunnar Mills4693ddb2019-03-27 15:49:40 -0500630 var data = {};
631 if ((newUser !== undefined) && (newUser != null)) {
632 data['UserName'] = newUser;
AppaRao Puli28711a62018-10-17 16:07:55 +0530633 }
Gunnar Mills4693ddb2019-03-27 15:49:40 -0500634 if ((role !== undefined) && (role != null)) {
635 data['RoleId'] = role;
636 }
637 if ((enabled !== undefined) && (enabled != null)) {
638 data['Enabled'] = enabled;
639 }
640 if ((passwd !== undefined) && (passwd != null)) {
641 data['Password'] = passwd;
642 }
Yoshie Muranakab4d9c092019-08-01 16:19:40 -0500643 if ((locked !== undefined) && (locked !== null)) {
644 data['Locked'] = locked
645 }
Gunnar Mills4693ddb2019-03-27 15:49:40 -0500646 return $http({
647 method: 'PATCH',
648 url: DataService.getHost() +
649 '/redfish/v1/AccountService/Accounts/' + user,
650 withCredentials: true,
651 data: data
652 });
AppaRao Puli28711a62018-10-17 16:07:55 +0530653 },
654 deleteUser: function(user) {
Gunnar Mills4693ddb2019-03-27 15:49:40 -0500655 return $http({
656 method: 'DELETE',
657 url: DataService.getHost() +
658 '/redfish/v1/AccountService/Accounts/' + user,
659 withCredentials: true,
660 });
AppaRao Puli28711a62018-10-17 16:07:55 +0530661 },
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700662 chassisPowerOff: function() {
663 var deferred = $q.defer();
664 $http({
665 method: 'PUT',
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700666 url: DataService.getHost() +
667 '/xyz/openbmc_project/state/chassis0/attr/RequestedPowerTransition',
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700668 withCredentials: true,
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700669 data: JSON.stringify(
670 {'data': 'xyz.openbmc_project.State.Chassis.Transition.Off'})
671 })
672 .then(
673 function(response) {
674 var json = JSON.stringify(response.data);
675 var content = JSON.parse(json);
676 deferred.resolve(content.status);
677 },
678 function(error) {
679 console.log(error);
680 deferred.reject(error);
681 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700682 return deferred.promise;
683 },
beccabroekb7f0ee12019-01-10 11:15:58 -0600684 setLEDState: function(state) {
685 return $http({
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700686 method: 'PUT',
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700687 url: DataService.getHost() +
688 '/xyz/openbmc_project/led/groups/enclosure_identify/attr/Asserted',
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700689 withCredentials: true,
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700690 data: JSON.stringify({'data': state})
691 })
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700692 },
Dixsie Wolmerse3681082019-06-21 13:48:06 -0500693 getBootOptions: function() {
694 return $http({
695 method: 'GET',
696 url: DataService.getHost() + '/redfish/v1/Systems/system',
697 withCredentials: true
698 })
699 .then(function(response) {
700 return response.data;
701 });
702 },
703 saveBootSettings: function(data) {
704 return $http({
705 method: 'PATCH',
706 url: DataService.getHost() + '/redfish/v1/Systems/system',
707 withCredentials: true,
708 data: data
709 });
710 },
711 getTPMStatus: function() {
712 return $http({
713 method: 'GET',
714 url: DataService.getHost() +
715 '/xyz/openbmc_project/control/host0/TPMEnable',
716 withCredentials: true
717 })
718 .then(function(response) {
719 return response.data;
720 });
721 },
722 saveTPMEnable: function(data) {
723 return $http({
724 method: 'PUT',
725 url: DataService.getHost() +
726 '/xyz/openbmc_project/control/host0/TPMEnable/attr/TPMEnable',
727 withCredentials: true,
728 data: JSON.stringify({'data': data})
729 })
730 },
731
Dixsie Wolmersc57ec322019-04-26 12:58:51 -0500732 bmcReboot: function() {
733 return $http({
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700734 method: 'PUT',
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700735 url: DataService.getHost() +
Gunnar Mills70086982019-01-04 15:10:04 -0600736 '/xyz/openbmc_project/state/bmc0/attr/RequestedBMCTransition',
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700737 withCredentials: true,
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700738 data: JSON.stringify(
739 {'data': 'xyz.openbmc_project.State.BMC.Transition.Reboot'})
Dixsie Wolmersc57ec322019-04-26 12:58:51 -0500740 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700741 },
beccabroekbfc99902018-07-24 15:36:33 -0500742 getLastRebootTime: function() {
743 return $http({
744 method: 'GET',
745 url: DataService.getHost() +
746 '/xyz/openbmc_project/state/bmc0/attr/LastRebootTime',
beccabroekbfc99902018-07-24 15:36:33 -0500747 withCredentials: true
748 })
749 .then(function(response) {
750 return response.data;
751 });
752 },
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700753 hostPowerOn: function() {
754 var deferred = $q.defer();
755 $http({
756 method: 'PUT',
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700757 url: DataService.getHost() +
758 '/xyz/openbmc_project/state/host0/attr/RequestedHostTransition',
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700759 withCredentials: true,
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700760 data: JSON.stringify(
761 {'data': 'xyz.openbmc_project.State.Host.Transition.On'})
762 })
763 .then(
764 function(response) {
765 var json = JSON.stringify(response.data);
766 var content = JSON.parse(json);
767 deferred.resolve(content.status);
768 },
769 function(error) {
770 console.log(error);
771 deferred.reject(error);
772 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700773 return deferred.promise;
774 },
775 hostPowerOff: function() {
776 var deferred = $q.defer();
777 $http({
778 method: 'PUT',
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700779 url: DataService.getHost() +
780 '/xyz/openbmc_project/state/host0/attr/RequestedHostTransition',
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700781 withCredentials: true,
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700782 data: JSON.stringify(
783 {'data': 'xyz.openbmc_project.State.Host.Transition.Off'})
784 })
785 .then(
786 function(response) {
787 var json = JSON.stringify(response.data);
788 var content = JSON.parse(json);
789 deferred.resolve(content.status);
790 },
791 function(error) {
792 console.log(error);
793 deferred.reject(error);
794 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700795 return deferred.promise;
796 },
797 hostReboot: function() {
798 var deferred = $q.defer();
799 $http({
800 method: 'PUT',
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700801 url: DataService.getHost() +
802 '/xyz/openbmc_project/state/host0/attr/RequestedHostTransition',
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700803 withCredentials: true,
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700804 data: JSON.stringify(
805 {'data': 'xyz.openbmc_project.State.Host.Transition.Reboot'})
806 })
807 .then(
808 function(response) {
809 var json = JSON.stringify(response.data);
810 var content = JSON.parse(json);
811 deferred.resolve(content.status);
812 },
813 function(error) {
814 console.log(error);
815 deferred.reject(error);
816 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700817
818 return deferred.promise;
819 },
beccabroek56744252018-08-03 11:25:11 -0500820 getLastPowerTime: function() {
821 return $http({
822 method: 'GET',
823 url: DataService.getHost() +
824 '/xyz/openbmc_project/state/chassis0/attr/LastStateChangeTime',
beccabroek56744252018-08-03 11:25:11 -0500825 withCredentials: true
826 })
827 .then(function(response) {
828 return response.data;
829 });
830 },
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700831 getLogs: function() {
832 var deferred = $q.defer();
833 $http({
834 method: 'GET',
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700835 url: DataService.getHost() +
836 '/xyz/openbmc_project/logging/enumerate',
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700837 withCredentials: true
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700838 })
839 .then(
840 function(response) {
841 var json = JSON.stringify(response.data);
842 var content = JSON.parse(json);
843 var dataClone = JSON.parse(JSON.stringify(content.data));
844 var data = [];
845 var severityCode = '';
846 var priority = '';
847 var health = '';
848 var relatedItems = [];
Matt Spinler845acdc2018-05-01 16:41:28 -0500849 var eventID = 'None';
850 var description = 'None';
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700851
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700852 for (var key in content.data) {
853 if (content.data.hasOwnProperty(key) &&
854 content.data[key].hasOwnProperty('Id')) {
855 var severityFlags = {
856 low: false,
857 medium: false,
858 high: false
859 };
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700860 severityCode =
861 content.data[key].Severity.split('.').pop();
862 priority =
863 Constants.SEVERITY_TO_PRIORITY_MAP[severityCode];
864 severityFlags[priority.toLowerCase()] = true;
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700865 relatedItems = [];
866 content.data[key].associations.forEach(function(item) {
867 relatedItems.push(item[2]);
868 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700869
Matt Spinler845acdc2018-05-01 16:41:28 -0500870 if (content.data[key].hasOwnProperty(['EventID'])) {
871 eventID = content.data[key].EventID;
872 }
873
874 if (content.data[key].hasOwnProperty(['Description'])) {
875 description = content.data[key].Description;
876 }
877
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700878 data.push(Object.assign(
879 {
880 path: key,
881 copied: false,
882 priority: priority,
883 severity_code: severityCode,
884 severity_flags: severityFlags,
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700885 additional_data:
886 content.data[key].AdditionalData.join('\n'),
887 type: content.data[key].Message,
888 selected: false,
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700889 meta: false,
890 confirm: false,
891 related_items: relatedItems,
Matt Spinler845acdc2018-05-01 16:41:28 -0500892 eventID: eventID,
893 description: description,
Yoshie Muranakaee788622019-10-02 07:30:16 -0700894 logId: '#' + content.data[key].Id,
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700895 data: {key: key, value: content.data[key]}
896 },
897 content.data[key]));
898 }
899 }
900 deferred.resolve({data: data, original: dataClone});
901 },
902 function(error) {
903 console.log(error);
904 deferred.reject(error);
905 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700906
907 return deferred.promise;
908 },
Gunnar Mills615a2f82019-04-17 14:30:39 -0500909 getAllSensorStatus: function(callback) {
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700910 $http({
911 method: 'GET',
Gunnar Mills615a2f82019-04-17 14:30:39 -0500912 url: DataService.getHost() +
913 '/xyz/openbmc_project/sensors/enumerate',
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700914 withCredentials: true
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700915 })
916 .then(
917 function(response) {
Gunnar Mills615a2f82019-04-17 14:30:39 -0500918 var json = JSON.stringify(response.data);
919 var content = JSON.parse(json);
920 var dataClone = JSON.parse(JSON.stringify(content.data));
921 var sensorData = [];
922 var severity = {};
923 var title = '';
924 var tempKeyParts = [];
925 var order = 0;
926 var customOrder = 0;
927
928 function getSensorStatus(reading) {
929 var severityFlags = {
930 critical: false,
931 warning: false,
932 normal: false
933 },
934 severityText = '', order = 0;
935
936 if (reading.hasOwnProperty('CriticalLow') &&
937 reading.Value < reading.CriticalLow) {
938 severityFlags.critical = true;
939 severityText = 'critical';
940 order = 2;
941 } else if (
942 reading.hasOwnProperty('CriticalHigh') &&
943 reading.Value > reading.CriticalHigh) {
944 severityFlags.critical = true;
945 severityText = 'critical';
946 order = 2;
947 } else if (
948 reading.hasOwnProperty('CriticalLow') &&
949 reading.hasOwnProperty('WarningLow') &&
950 reading.Value >= reading.CriticalLow &&
951 reading.Value <= reading.WarningLow) {
952 severityFlags.warning = true;
953 severityText = 'warning';
954 order = 1;
955 } else if (
956 reading.hasOwnProperty('WarningHigh') &&
957 reading.hasOwnProperty('CriticalHigh') &&
958 reading.Value >= reading.WarningHigh &&
959 reading.Value <= reading.CriticalHigh) {
960 severityFlags.warning = true;
961 severityText = 'warning';
962 order = 1;
963 } else {
964 severityFlags.normal = true;
965 severityText = 'normal';
966 }
967 return {
968 flags: severityFlags,
969 severityText: severityText,
970 order: order
971 };
972 }
973
974 for (var key in content.data) {
975 if (content.data.hasOwnProperty(key) &&
976 content.data[key].hasOwnProperty('Unit')) {
977 severity = getSensorStatus(content.data[key]);
978
979 if (!content.data[key].hasOwnProperty('CriticalLow')) {
980 content.data[key].CriticalLow = '--';
981 content.data[key].CriticalHigh = '--';
982 }
983
984 if (!content.data[key].hasOwnProperty('WarningLow')) {
985 content.data[key].WarningLow = '--';
986 content.data[key].WarningHigh = '--';
987 }
988
989 tempKeyParts = key.split('/');
990 title = tempKeyParts.pop();
991 title = tempKeyParts.pop() + '_' + title;
992 title = title.split('_')
993 .map(function(item) {
994 return item.toLowerCase()
995 .charAt(0)
996 .toUpperCase() +
997 item.slice(1);
998 })
999 .reduce(function(prev, el) {
1000 return prev + ' ' + el;
1001 });
1002
1003 content.data[key].Value = getScaledValue(
1004 content.data[key].Value, content.data[key].Scale);
1005 content.data[key].CriticalLow = getScaledValue(
1006 content.data[key].CriticalLow,
1007 content.data[key].Scale);
1008 content.data[key].CriticalHigh = getScaledValue(
1009 content.data[key].CriticalHigh,
1010 content.data[key].Scale);
1011 content.data[key].WarningLow = getScaledValue(
1012 content.data[key].WarningLow,
1013 content.data[key].Scale);
1014 content.data[key].WarningHigh = getScaledValue(
1015 content.data[key].WarningHigh,
1016 content.data[key].Scale);
1017 if (Constants.SENSOR_SORT_ORDER.indexOf(
1018 content.data[key].Unit) > -1) {
1019 customOrder = Constants.SENSOR_SORT_ORDER.indexOf(
1020 content.data[key].Unit);
1021 } else {
1022 customOrder = Constants.SENSOR_SORT_ORDER_DEFAULT;
1023 }
1024
1025 sensorData.push(Object.assign(
1026 {
1027 path: key,
1028 selected: false,
1029 confirm: false,
1030 copied: false,
1031 title: title,
1032 unit:
1033 Constants
1034 .SENSOR_UNIT_MAP[content.data[key].Unit],
1035 severity_flags: severity.flags,
1036 status: severity.severityText,
1037 order: severity.order,
1038 custom_order: customOrder,
1039 search_text:
1040 (title + ' ' + content.data[key].Value + ' ' +
1041 Constants.SENSOR_UNIT_MAP[content.data[key]
1042 .Unit] +
1043 ' ' + severity.severityText + ' ' +
1044 content.data[key].CriticalLow + ' ' +
1045 content.data[key].CriticalHigh + ' ' +
1046 content.data[key].WarningLow + ' ' +
1047 content.data[key].WarningHigh + ' ')
1048 .toLowerCase(),
1049 original_data:
1050 {key: key, value: content.data[key]}
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001051 },
Gunnar Mills615a2f82019-04-17 14:30:39 -05001052 content.data[key]));
1053 }
1054 }
1055
Alexander Filippove4ae8542019-06-10 15:42:48 +03001056 sensorData.sort(function(a, b) {
1057 return a.title.localeCompare(
1058 b.title, 'en', {numeric: true});
1059 });
1060
Gunnar Mills615a2f82019-04-17 14:30:39 -05001061 callback(sensorData, dataClone);
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001062 },
1063 function(error) {
Gunnar Mills615a2f82019-04-17 14:30:39 -05001064 console.log(error);
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001065 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001066 },
1067 getActivation: function(imageId) {
1068 return $http({
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001069 method: 'GET',
1070 url: DataService.getHost() +
1071 '/xyz/openbmc_project/software/' + imageId +
1072 '/attr/Activation',
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001073 withCredentials: true
1074 })
1075 .then(function(response) {
1076 return response.data;
1077 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001078 },
1079 getFirmwares: function() {
1080 var deferred = $q.defer();
1081 $http({
1082 method: 'GET',
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001083 url: DataService.getHost() +
1084 '/xyz/openbmc_project/software/enumerate',
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001085 withCredentials: true
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001086 })
1087 .then(
1088 function(response) {
1089 var json = JSON.stringify(response.data);
1090 var content = JSON.parse(json);
1091 var data = [];
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001092 var isExtended = false;
1093 var bmcActiveVersion = '';
1094 var hostActiveVersion = '';
1095 var imageType = '';
1096 var extendedVersions = [];
1097 var functionalImages = [];
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001098
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001099 function getFormatedExtendedVersions(extendedVersion) {
1100 var versions = [];
1101 extendedVersion = extendedVersion.split(',');
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001102
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001103 extendedVersion.forEach(function(item) {
1104 var parts = item.split('-');
1105 var numberIndex = 0;
1106 for (var i = 0; i < parts.length; i++) {
1107 if (/[0-9]/.test(parts[i])) {
1108 numberIndex = i;
1109 break;
1110 }
1111 }
George Liu22d78222019-07-19 10:35:40 +08001112 if (numberIndex > 0) {
1113 var titlePart = parts.splice(0, numberIndex);
1114 titlePart = titlePart.join('');
1115 titlePart = titlePart[0].toUpperCase() +
1116 titlePart.substr(1, titlePart.length);
1117 var versionPart = parts.join('-');
1118 versions.push(
1119 {title: titlePart, version: versionPart});
1120 }
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001121 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001122
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001123 return versions;
1124 }
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001125
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001126 // Get the list of functional images so we can compare
1127 // later if an image is functional
1128 if (content.data[Constants.FIRMWARE.FUNCTIONAL_OBJPATH]) {
1129 functionalImages =
1130 content.data[Constants.FIRMWARE.FUNCTIONAL_OBJPATH]
1131 .endpoints;
1132 }
1133 for (var key in content.data) {
1134 if (content.data.hasOwnProperty(key) &&
1135 content.data[key].hasOwnProperty('Version')) {
Gunnar Millsac9131e2018-07-13 15:52:18 -05001136 var activationStatus = '';
1137
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001138 // If the image is "Functional" use that for the
AppaRao Puli28711a62018-10-17 16:07:55 +05301139 // activation status, else use the value of
1140 // "Activation"
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001141 // github.com/openbmc/phosphor-dbus-interfaces/blob/master/xyz/openbmc_project/Software/Activation.interface.yaml
Gunnar Millsac9131e2018-07-13 15:52:18 -05001142 if (content.data[key].Activation) {
1143 activationStatus =
1144 content.data[key].Activation.split('.').pop();
1145 }
1146
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001147 if (functionalImages.includes(key)) {
1148 activationStatus = 'Functional';
1149 }
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001150
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001151 imageType = content.data[key].Purpose.split('.').pop();
1152 isExtended = content.data[key].hasOwnProperty(
1153 'ExtendedVersion') &&
1154 content.data[key].ExtendedVersion != '';
1155 if (isExtended) {
1156 extendedVersions = getFormatedExtendedVersions(
1157 content.data[key].ExtendedVersion);
1158 }
1159 data.push(Object.assign(
1160 {
1161 path: key,
1162 activationStatus: activationStatus,
1163 imageId: key.split('/').pop(),
1164 imageType: imageType,
1165 isExtended: isExtended,
1166 extended:
1167 {show: false, versions: extendedVersions},
1168 data: {key: key, value: content.data[key]}
1169 },
1170 content.data[key]));
1171
1172 if (activationStatus == 'Functional' &&
1173 imageType == 'BMC') {
1174 bmcActiveVersion = content.data[key].Version;
1175 }
1176
1177 if (activationStatus == 'Functional' &&
1178 imageType == 'Host') {
1179 hostActiveVersion = content.data[key].Version;
1180 }
1181 }
1182 }
1183
1184 deferred.resolve({
1185 data: data,
1186 bmcActiveVersion: bmcActiveVersion,
1187 hostActiveVersion: hostActiveVersion
1188 });
Iftekharul Islam171c6a12017-08-11 08:35:47 -05001189 },
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001190 function(error) {
1191 console.log(error);
1192 deferred.reject(error);
1193 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001194
1195 return deferred.promise;
1196 },
1197 changePriority: function(imageId, priority) {
Gunnar Millsf7f59462018-09-20 16:02:08 -05001198 return $http({
1199 method: 'PUT',
1200 url: DataService.getHost() +
1201 '/xyz/openbmc_project/software/' + imageId +
1202 '/attr/Priority',
1203 withCredentials: true,
1204 data: JSON.stringify({'data': priority})
1205 })
1206 .then(function(response) {
1207 return response.data;
1208 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001209 },
1210 deleteImage: function(imageId) {
Gunnar Millsf7f59462018-09-20 16:02:08 -05001211 return $http({
1212 method: 'POST',
1213 url: DataService.getHost() +
1214 '/xyz/openbmc_project/software/' + imageId +
1215 '/action/Delete',
1216 withCredentials: true,
1217 data: JSON.stringify({'data': []})
1218 })
1219 .then(function(response) {
1220 return response.data;
1221 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001222 },
1223 activateImage: function(imageId) {
Gunnar Millsf7f59462018-09-20 16:02:08 -05001224 return $http({
1225 method: 'PUT',
1226 url: DataService.getHost() +
1227 '/xyz/openbmc_project/software/' + imageId +
1228 '/attr/RequestedActivation',
1229 withCredentials: true,
1230 data: JSON.stringify(
1231 {'data': Constants.FIRMWARE.ACTIVATE_FIRMWARE})
1232 })
1233 .then(function(response) {
1234 return response.data;
1235 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001236 },
1237 uploadImage: function(file) {
1238 return $http({
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001239 method: 'POST',
1240 timeout: 5 * 60 * 1000,
1241 url: DataService.getHost() + '/upload/image',
Gunnar Millsdd9d4c32018-09-10 12:59:34 -05001242 // Overwrite the default 'application/json' Content-Type
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001243 headers: {'Content-Type': 'application/octet-stream'},
1244 withCredentials: true,
1245 data: file
1246 })
1247 .then(function(response) {
1248 return response.data;
1249 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001250 },
1251 downloadImage: function(host, filename) {
1252 return $http({
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001253 method: 'POST',
1254 url: DataService.getHost() +
1255 '/xyz/openbmc_project/software/action/DownloadViaTFTP',
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001256 withCredentials: true,
1257 data: JSON.stringify({'data': [filename, host]}),
1258 responseType: 'arraybuffer'
1259 })
1260 .then(function(response) {
1261 return response.data;
1262 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001263 },
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001264 getServerInfo: function() {
1265 // TODO: openbmc/openbmc#3117 Need a way via REST to get
1266 // interfaces so we can get the system object(s) by the looking
1267 // for the system interface.
1268 return $http({
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001269 method: 'GET',
1270 url: DataService.getHost() +
1271 '/xyz/openbmc_project/inventory/system',
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001272 withCredentials: true
1273 })
1274 .then(function(response) {
1275 return response.data;
1276 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001277 },
1278 getBMCTime: function() {
1279 return $http({
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001280 method: 'GET',
1281 url: DataService.getHost() + '/xyz/openbmc_project/time/bmc',
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001282 withCredentials: true
1283 })
1284 .then(function(response) {
1285 return response.data;
1286 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001287 },
Gunnar Millsc74d4342018-07-18 14:52:02 -05001288 getTime: function() {
1289 return $http({
1290 method: 'GET',
1291 url: DataService.getHost() +
1292 '/xyz/openbmc_project/time/enumerate',
Gunnar Millsc74d4342018-07-18 14:52:02 -05001293 withCredentials: true
1294 })
1295 .then(function(response) {
1296 return response.data;
1297 });
1298 },
Gunnar Millsb7ea2792018-07-18 13:01:48 -05001299 // Even though NTPServers is a network interface specific path
1300 // (e.g. /xyz/openbmc_project/network/eth0/attr/NTPServers) it acts
1301 // like a global setting. Just use eth0 for setting and getting the
1302 // NTP Servers until it is moved to a non-network interface specific
1303 // path like it is in Redfish. TODO: openbmc/phosphor-time-manager#4
1304 getNTPServers: function() {
1305 return $http({
1306 method: 'GET',
1307 url: DataService.getHost() +
1308 '/xyz/openbmc_project/network/eth0/attr/NTPServers',
Gunnar Millsb7ea2792018-07-18 13:01:48 -05001309 withCredentials: true
1310 })
1311 .then(function(response) {
1312 return response.data;
1313 });
1314 },
1315 setNTPServers: function(ntpServers) {
1316 return $http({
1317 method: 'PUT',
1318 url: DataService.getHost() +
1319 '/xyz/openbmc_project/network/eth0/attr/NTPServers',
Gunnar Millsb7ea2792018-07-18 13:01:48 -05001320 withCredentials: true,
1321 data: JSON.stringify({'data': ntpServers})
1322 })
1323 .then(function(response) {
1324 return response.data;
1325 });
1326 },
1327 setTimeMode: function(timeMode) {
1328 return $http({
1329 method: 'PUT',
1330 url: DataService.getHost() +
1331 '/xyz/openbmc_project/time/sync_method/attr/TimeSyncMethod',
Gunnar Millsb7ea2792018-07-18 13:01:48 -05001332 withCredentials: true,
1333 data: JSON.stringify({'data': timeMode})
1334 })
1335 .then(function(response) {
1336 return response.data;
1337 });
1338 },
1339 setTimeOwner: function(timeOwner) {
1340 return $http({
1341 method: 'PUT',
1342 url: DataService.getHost() +
1343 '/xyz/openbmc_project/time/owner/attr/TimeOwner',
Gunnar Millsb7ea2792018-07-18 13:01:48 -05001344 withCredentials: true,
1345 data: JSON.stringify({'data': timeOwner})
1346 })
1347 .then(function(response) {
1348 return response.data;
1349 });
1350 },
1351 setBMCTime: function(time) {
1352 return $http({
1353 method: 'PUT',
1354 url: DataService.getHost() +
1355 '/xyz/openbmc_project/time/bmc/attr/Elapsed',
Gunnar Millsb7ea2792018-07-18 13:01:48 -05001356 withCredentials: true,
1357 data: JSON.stringify({'data': time})
1358 })
1359 .then(function(response) {
1360 return response.data;
1361 });
1362 },
1363 setHostTime: function(time) {
1364 return $http({
1365 method: 'PUT',
1366 url: DataService.getHost() +
1367 '/xyz/openbmc_project/time/host/attr/Elapsed',
Gunnar Millsb7ea2792018-07-18 13:01:48 -05001368 withCredentials: true,
1369 data: JSON.stringify({'data': time})
1370 })
1371 .then(function(response) {
1372 return response.data;
1373 });
1374 },
beccabroek309b5da2018-11-07 12:22:31 -06001375 getCertificateLocations: function() {
1376 return $http({
1377 method: 'GET',
1378 url: DataService.getHost() +
1379 '/redfish/v1/CertificateService/CertificateLocations',
1380 withCredentials: true
1381 })
1382 .then(function(response) {
1383 return response.data;
1384 });
1385 },
1386 getCertificate: function(location) {
1387 return $http({
1388 method: 'GET',
1389 url: DataService.getHost() + location,
1390 withCredentials: true
1391 })
1392 .then(function(response) {
1393 return response.data;
1394 });
1395 },
1396 addNewCertificate: function(file, type) {
1397 return $http({
1398 method: 'POST',
1399 url: DataService.getHost() + type.location,
1400 headers: {'Content-Type': 'application/x-pem-file'},
1401 withCredentials: true,
1402 data: file
1403 })
1404 .then(function(response) {
1405 return response.data;
1406 });
1407 },
miramurali235e8785d2019-06-10 15:09:27 -05001408 createCSRCertificate: function(data) {
1409 return $http({
1410 method: 'POST',
1411 url: DataService.getHost() +
1412 '/redfish/v1/CertificateService/Actions/CertificateService.GenerateCSR',
1413 withCredentials: true,
1414 data: data
1415 })
1416 .then(function(response) {
1417 return response.data['CSRString'];
1418 });
1419 },
beccabroek309b5da2018-11-07 12:22:31 -06001420 replaceCertificate: function(data) {
1421 return $http({
1422 method: 'POST',
1423 url: DataService.getHost() +
1424 '/redfish/v1/CertificateService/Actions/CertificateService.ReplaceCertificate',
1425 withCredentials: true,
1426 data: data
1427 })
1428 .then(function(response) {
1429 return response.data;
1430 });
1431 },
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001432 getHardwares: function(callback) {
1433 $http({
1434 method: 'GET',
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001435 url: DataService.getHost() +
1436 '/xyz/openbmc_project/inventory/enumerate',
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001437 withCredentials: true
1438 }).then(function(response) {
1439 var json = JSON.stringify(response.data);
1440 var content = JSON.parse(json);
1441 var hardwareData = [];
1442 var keyIndexMap = {};
1443 var title = '';
beccabroek628ba8b2018-10-01 14:12:25 -05001444 var depth = '';
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001445 var data = [];
1446 var searchText = '';
1447 var componentIndex = -1;
beccabroek628ba8b2018-10-01 14:12:25 -05001448 var parent = '';
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001449
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001450 function isSubComponent(key) {
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001451 for (var i = 0; i < Constants.HARDWARE.parent_components.length;
1452 i++) {
1453 if (key.split(Constants.HARDWARE.parent_components[i]).length ==
1454 2)
1455 return true;
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001456 }
1457
1458 return false;
1459 }
1460
1461 function titlelize(title) {
1462 title = title.replace(/([A-Z0-9]+)/g, ' $1').replace(/^\s+/, '');
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001463 for (var i = 0; i < Constants.HARDWARE.uppercase_titles.length;
1464 i++) {
1465 if (title.toLowerCase().indexOf(
1466 (Constants.HARDWARE.uppercase_titles[i] + ' ')) > -1) {
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001467 return title.toUpperCase();
1468 }
1469 }
1470
1471 return title;
1472 }
1473
1474 function camelcaseToLabel(obj) {
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001475 var transformed = [], label = '', value = '';
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001476 for (var key in obj) {
1477 label = key.replace(/([A-Z0-9]+)/g, ' $1').replace(/^\s+/, '');
1478 if (obj[key] !== '') {
1479 value = obj[key];
1480 if (value == 1 || value == 0) {
1481 value = (value == 1) ? 'Yes' : 'No';
1482 }
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001483 transformed.push({key: label, value: value});
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001484 }
1485 }
1486
1487 return transformed;
1488 }
1489
beccabroek628ba8b2018-10-01 14:12:25 -05001490 function determineParent(key) {
1491 var levels = key.split('/');
1492 levels.pop();
1493 return levels.join('/');
1494 }
1495
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001496 function getSearchText(data) {
1497 var searchText = '';
1498 for (var i = 0; i < data.length; i++) {
1499 searchText += ' ' + data[i].key + ' ' + data[i].value;
1500 }
1501
1502 return searchText;
1503 }
1504
1505 for (var key in content.data) {
1506 if (content.data.hasOwnProperty(key) &&
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001507 key.indexOf(Constants.HARDWARE.component_key_filter) == 0) {
Gunnar Millseedf0b92019-02-27 10:52:01 -06001508 // All and only associations have the property "endpoints".
Gunnar Millsc9c8e672019-07-24 17:08:15 -05001509 // We don't want to show forward/reverse association objects
1510 // that the mapper created on the inventory panel.
Gunnar Millseedf0b92019-02-27 10:52:01 -06001511 // Example: An association from the BMC inventory item to the
Gunnar Millsc9c8e672019-07-24 17:08:15 -05001512 // BMC firmware images. See:
1513 // https://github.com/openbmc/docs/blob/master/object-mapper.md#associations
Gunnar Millseedf0b92019-02-27 10:52:01 -06001514 if (content.data[key].hasOwnProperty('endpoints')) {
1515 continue;
1516 }
Gunnar Millsc9c8e672019-07-24 17:08:15 -05001517 // There is also an "Associations" property created by the
1518 // Association interface. These would show on the inventory
1519 // panel under the individual inventory item dropdown. There
1520 // can be a lot of associations in this property and they are
1521 // long, full D-Bus paths. Not particularly useful. Remove
1522 // for now.
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001523
Gunnar Millsc9c8e672019-07-24 17:08:15 -05001524 if (content.data[key].hasOwnProperty('Associations')) {
1525 delete content.data[key].Associations;
1526 }
1527
1528 // Support old Associations interface property
1529 // https://github.com/openbmc/phosphor-logging/blob/master/org/openbmc/Associations.interface.yaml
1530 // Remove when we move to new Associations interface
1531 // openbmc/openbmc#3584
1532 if (content.data[key].hasOwnProperty('associations')) {
1533 delete content.data[key].associations;
1534 }
1535
Gunnar Mills5ccf9e32019-09-19 16:04:46 -05001536 // Remove the Purpose property from any inventory item.
1537 // The purpose property isn't useful to a user.
1538 // E.g. in a Power Supply:
1539 // Purpose
1540 // xyz.openbmc_project.Software.Version.VersionPurpose.Other
1541 // Remove when we move inventory to Redfish
1542 if (content.data[key].hasOwnProperty('Purpose')) {
1543 delete content.data[key].Purpose;
1544 }
1545
Gunnar Millsc9c8e672019-07-24 17:08:15 -05001546 data = camelcaseToLabel(content.data[key]);
1547 searchText = getSearchText(data);
1548 title = key.split('/').pop();
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001549 title = titlelize(title);
beccabroek628ba8b2018-10-01 14:12:25 -05001550 // e.g. /xyz/openbmc_project/inventory/system and
1551 // /xyz/openbmc_project/inventory/system/chassis are depths of 5
1552 // and 6.
1553 depth = key.split('/').length;
1554 parent = determineParent(key);
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001555
1556 if (!isSubComponent(key)) {
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001557 hardwareData.push(Object.assign(
1558 {
1559 path: key,
1560 title: title,
beccabroek628ba8b2018-10-01 14:12:25 -05001561 depth: depth,
1562 parent: parent,
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001563 selected: false,
1564 expanded: false,
1565 search_text: title.toLowerCase() + ' ' +
1566 searchText.toLowerCase(),
1567 sub_components: [],
1568 original_data: {key: key, value: content.data[key]}
1569 },
1570 {items: data}));
Iftekharul Islam2a489552017-11-02 13:23:08 -05001571
Gunnar Millsc9c8e672019-07-24 17:08:15 -05001572
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001573 keyIndexMap[key] = hardwareData.length - 1;
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001574 } else {
beccabroek628ba8b2018-10-01 14:12:25 -05001575 parent = determineParent(key)
1576 componentIndex = keyIndexMap[parent];
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001577 data = content.data[key];
1578 data.title = title;
1579 hardwareData[componentIndex].sub_components.push(data);
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001580 hardwareData[componentIndex].search_text +=
1581 ' ' + title.toLowerCase();
Iftekharul Islam171c6a12017-08-11 08:35:47 -05001582
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001583 // Sort the subcomponents alphanumeric so they are displayed
1584 // on the inventory page in order (e.g. core 0, core 1, core
1585 // 2, ... core 12, core 13)
1586 hardwareData[componentIndex].sub_components.sort(function(
1587 a, b) {
1588 return a.title.localeCompare(
1589 b.title, 'en', {numeric: true});
Gunnar Mills55a8e392018-03-14 15:37:44 -05001590 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001591 }
1592 }
1593 }
beccabroek628ba8b2018-10-01 14:12:25 -05001594 // First, order the components by depth and then place the child
1595 // components beneath their parent component alphanumerically. Can
1596 // be removed with completion of
1597 // https://github.com/openbmc/openbmc/issues/3401
1598 // TODO: Remove this once implemented in back end
1599 hardwareData.sort(function(a, b) {
1600 if (a.depth < b.depth) return -1;
1601 if (a.depth > b.depth) return 1;
1602 return b.title.localeCompare(a.title, 'en', {numeric: true});
1603 });
1604
1605 var orderedComponents = [];
1606
1607 for (var i = 0; i < hardwareData.length; i++) {
1608 if (!keyIndexMap[hardwareData[i].parent]) {
1609 orderedComponents.push(hardwareData[i]);
1610 } else {
1611 for (var j = 0; j < orderedComponents.length; j++) {
1612 if (orderedComponents[j].path === hardwareData[i].parent) {
1613 var child = hardwareData[i];
1614 orderedComponents.splice(j + 1, 0, child);
1615 }
1616 }
1617 }
1618 }
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001619
1620 if (callback) {
beccabroek628ba8b2018-10-01 14:12:25 -05001621 callback(orderedComponents, content.data);
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001622 } else {
beccabroek628ba8b2018-10-01 14:12:25 -05001623 return {data: orderedComponents, original_data: content.data};
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001624 }
1625 });
1626 },
1627 deleteLogs: function(logs) {
1628 var defer = $q.defer();
1629 var promises = [];
1630
1631 function finished() {
1632 defer.resolve();
1633 }
1634
1635 logs.forEach(function(item) {
1636 promises.push($http({
1637 method: 'POST',
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001638 url: DataService.getHost() +
1639 '/xyz/openbmc_project/logging/entry/' + item.Id +
1640 '/action/Delete',
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001641 withCredentials: true,
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001642 data: JSON.stringify({'data': []})
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001643 }));
1644 });
1645
1646 $q.all(promises).then(finished);
1647
1648 return defer.promise;
1649 },
1650 resolveLogs: function(logs) {
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001651 var promises = [];
1652
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001653 logs.forEach(function(item) {
1654 promises.push($http({
1655 method: 'PUT',
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001656 url: DataService.getHost() +
1657 '/xyz/openbmc_project/logging/entry/' + item.Id +
1658 '/attr/Resolved',
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001659 withCredentials: true,
Gunnar Mills7e48d082019-01-23 16:02:03 -06001660 data: JSON.stringify({'data': true})
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001661 }));
1662 });
Gunnar Mills7e48d082019-01-23 16:02:03 -06001663 return $q.all(promises);
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001664 },
Yoshie Muranakae4194ce2019-05-24 14:33:56 -05001665 setRemoteLoggingServer: (data) => {
1666 const ip = data.hostname;
1667 const port = data.port;
1668 const setIPRequest = $http({
1669 method: 'PUT',
1670 url: DataService.getHost() +
1671 '/xyz/openbmc_project/logging/config/remote/attr/Address',
1672 withCredentials: true,
1673 data: {'data': ip}
1674 });
1675 const setPortRequest = $http({
1676 method: 'PUT',
1677 url: DataService.getHost() +
1678 '/xyz/openbmc_project/logging/config/remote/attr/Port',
1679 withCredentials: true,
1680 data: {'data': port}
1681 });
1682 const promises = [setIPRequest, setPortRequest];
1683 return $q.all(promises);
1684 },
1685 getRemoteLoggingServer: () => {
1686 return $http({
1687 method: 'GET',
1688 url: DataService.getHost() +
1689 '/xyz/openbmc_project/logging/config/remote',
1690 withCredentials: true
1691 })
1692 .then((response) => {
1693 const remoteServer = response.data.data;
1694 if (remoteServer === undefined) {
1695 return undefined;
1696 }
1697 const hostname = remoteServer.Address;
1698 const port = remoteServer.Port;
1699 if (hostname === '') {
1700 return undefined;
1701 } else {
1702 return {
1703 hostname, port
1704 }
1705 }
1706 });
1707 },
1708 disableRemoteLoggingServer: () => {
1709 return SERVICE.setRemoteLoggingServer({hostname: '', port: 0});
1710 },
1711 updateRemoteLoggingServer: (data) => {
1712 // Recommended to disable existing configuration
1713 // before updating config to new server
1714 // https://github.com/openbmc/phosphor-logging#changing-the-rsyslog-server
1715 return SERVICE.disableRemoteLoggingServer()
1716 .then(() => {
1717 return SERVICE.setRemoteLoggingServer(data);
1718 })
1719 .catch(() => {
1720 // try updating server even if initial disable attempt fails
1721 return SERVICE.setRemoteLoggingServer(data);
1722 });
1723 },
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001724 getPowerConsumption: function() {
1725 return $http({
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001726 method: 'GET',
1727 url: DataService.getHost() +
1728 '/xyz/openbmc_project/sensors/power/total_power',
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001729 withCredentials: true
1730 })
1731 .then(
1732 function(response) {
1733 var json = JSON.stringify(response.data);
1734 var content = JSON.parse(json);
Iftekharul Islamcd789502017-04-19 14:37:55 -05001735
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001736 return getScaledValue(
1737 content.data.Value, content.data.Scale) +
1738 ' ' +
1739 Constants.POWER_CONSUMPTION_TEXT[content.data.Unit];
1740 },
1741 function(error) {
1742 if ('Not Found' == error.statusText) {
1743 return Constants.POWER_CONSUMPTION_TEXT.notavailable;
1744 } else {
1745 throw error;
1746 }
1747 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001748 },
1749 getPowerCap: function() {
1750 return $http({
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001751 method: 'GET',
1752 url: DataService.getHost() +
1753 '/xyz/openbmc_project/control/host0/power_cap',
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001754 withCredentials: true
1755 })
1756 .then(function(response) {
Gunnar Mills006aaa02018-06-26 16:08:59 -05001757 return response.data;
1758 });
1759 },
1760 setPowerCapEnable: function(powerCapEnable) {
1761 return $http({
1762 method: 'PUT',
1763 url: DataService.getHost() +
1764 '/xyz/openbmc_project/control/host0/power_cap/attr/PowerCapEnable',
Gunnar Mills006aaa02018-06-26 16:08:59 -05001765 withCredentials: true,
1766 data: JSON.stringify({'data': powerCapEnable})
1767 })
1768 .then(function(response) {
1769 return response.data;
1770 });
1771 },
1772 setPowerCap: function(powerCap) {
1773 return $http({
1774 method: 'PUT',
1775 url: DataService.getHost() +
1776 '/xyz/openbmc_project/control/host0/power_cap/attr/PowerCap',
Gunnar Mills006aaa02018-06-26 16:08:59 -05001777 withCredentials: true,
1778 data: JSON.stringify({'data': powerCap})
1779 })
1780 .then(function(response) {
1781 return response.data;
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001782 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001783 },
1784 setHostname: function(hostname) {
1785 return $http({
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001786 method: 'PUT',
1787 url: DataService.getHost() +
1788 '/xyz/openbmc_project/network/config/attr/HostName',
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001789 withCredentials: true,
1790 data: JSON.stringify({'data': hostname})
1791 })
1792 .then(function(response) {
1793 return response.data;
1794 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001795 },
1796 };
1797 return SERVICE;
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001798 }
1799 ]);
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001800})(window.angular);