blob: ba48a493673738eb1467391185bbc83fadad948b [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
AppaRao Puli28711a62018-10-17 16:07:55 +0530607 createUser: function(user, passwd, role, enabled) {
Gunnar Mills4693ddb2019-03-27 15:49:40 -0500608 var data = {};
609 data['UserName'] = user;
610 data['Password'] = passwd;
611 data['RoleId'] = role;
612 data['Enabled'] = enabled;
AppaRao Puli28711a62018-10-17 16:07:55 +0530613
Gunnar Mills4693ddb2019-03-27 15:49:40 -0500614 return $http({
615 method: 'POST',
616 url: DataService.getHost() + '/redfish/v1/AccountService/Accounts',
617 withCredentials: true,
618 data: data
619 });
AppaRao Puli28711a62018-10-17 16:07:55 +0530620 },
621 updateUser: function(user, newUser, passwd, role, enabled) {
Gunnar Mills4693ddb2019-03-27 15:49:40 -0500622 var data = {};
623 if ((newUser !== undefined) && (newUser != null)) {
624 data['UserName'] = newUser;
AppaRao Puli28711a62018-10-17 16:07:55 +0530625 }
Gunnar Mills4693ddb2019-03-27 15:49:40 -0500626 if ((role !== undefined) && (role != null)) {
627 data['RoleId'] = role;
628 }
629 if ((enabled !== undefined) && (enabled != null)) {
630 data['Enabled'] = enabled;
631 }
632 if ((passwd !== undefined) && (passwd != null)) {
633 data['Password'] = passwd;
634 }
635 return $http({
636 method: 'PATCH',
637 url: DataService.getHost() +
638 '/redfish/v1/AccountService/Accounts/' + user,
639 withCredentials: true,
640 data: data
641 });
AppaRao Puli28711a62018-10-17 16:07:55 +0530642 },
643 deleteUser: function(user) {
Gunnar Mills4693ddb2019-03-27 15:49:40 -0500644 return $http({
645 method: 'DELETE',
646 url: DataService.getHost() +
647 '/redfish/v1/AccountService/Accounts/' + user,
648 withCredentials: true,
649 });
AppaRao Puli28711a62018-10-17 16:07:55 +0530650 },
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700651 chassisPowerOff: function() {
652 var deferred = $q.defer();
653 $http({
654 method: 'PUT',
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700655 url: DataService.getHost() +
656 '/xyz/openbmc_project/state/chassis0/attr/RequestedPowerTransition',
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700657 withCredentials: true,
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700658 data: JSON.stringify(
659 {'data': 'xyz.openbmc_project.State.Chassis.Transition.Off'})
660 })
661 .then(
662 function(response) {
663 var json = JSON.stringify(response.data);
664 var content = JSON.parse(json);
665 deferred.resolve(content.status);
666 },
667 function(error) {
668 console.log(error);
669 deferred.reject(error);
670 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700671 return deferred.promise;
672 },
beccabroekb7f0ee12019-01-10 11:15:58 -0600673 setLEDState: function(state) {
674 return $http({
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700675 method: 'PUT',
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700676 url: DataService.getHost() +
677 '/xyz/openbmc_project/led/groups/enclosure_identify/attr/Asserted',
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700678 withCredentials: true,
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700679 data: JSON.stringify({'data': state})
680 })
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700681 },
Dixsie Wolmerse3681082019-06-21 13:48:06 -0500682 getBootOptions: function() {
683 return $http({
684 method: 'GET',
685 url: DataService.getHost() + '/redfish/v1/Systems/system',
686 withCredentials: true
687 })
688 .then(function(response) {
689 return response.data;
690 });
691 },
692 saveBootSettings: function(data) {
693 return $http({
694 method: 'PATCH',
695 url: DataService.getHost() + '/redfish/v1/Systems/system',
696 withCredentials: true,
697 data: data
698 });
699 },
700 getTPMStatus: function() {
701 return $http({
702 method: 'GET',
703 url: DataService.getHost() +
704 '/xyz/openbmc_project/control/host0/TPMEnable',
705 withCredentials: true
706 })
707 .then(function(response) {
708 return response.data;
709 });
710 },
711 saveTPMEnable: function(data) {
712 return $http({
713 method: 'PUT',
714 url: DataService.getHost() +
715 '/xyz/openbmc_project/control/host0/TPMEnable/attr/TPMEnable',
716 withCredentials: true,
717 data: JSON.stringify({'data': data})
718 })
719 },
720
Dixsie Wolmersc57ec322019-04-26 12:58:51 -0500721 bmcReboot: function() {
722 return $http({
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700723 method: 'PUT',
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700724 url: DataService.getHost() +
Gunnar Mills70086982019-01-04 15:10:04 -0600725 '/xyz/openbmc_project/state/bmc0/attr/RequestedBMCTransition',
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700726 withCredentials: true,
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700727 data: JSON.stringify(
728 {'data': 'xyz.openbmc_project.State.BMC.Transition.Reboot'})
Dixsie Wolmersc57ec322019-04-26 12:58:51 -0500729 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700730 },
beccabroekbfc99902018-07-24 15:36:33 -0500731 getLastRebootTime: function() {
732 return $http({
733 method: 'GET',
734 url: DataService.getHost() +
735 '/xyz/openbmc_project/state/bmc0/attr/LastRebootTime',
beccabroekbfc99902018-07-24 15:36:33 -0500736 withCredentials: true
737 })
738 .then(function(response) {
739 return response.data;
740 });
741 },
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700742 hostPowerOn: function() {
743 var deferred = $q.defer();
744 $http({
745 method: 'PUT',
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700746 url: DataService.getHost() +
747 '/xyz/openbmc_project/state/host0/attr/RequestedHostTransition',
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700748 withCredentials: true,
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700749 data: JSON.stringify(
750 {'data': 'xyz.openbmc_project.State.Host.Transition.On'})
751 })
752 .then(
753 function(response) {
754 var json = JSON.stringify(response.data);
755 var content = JSON.parse(json);
756 deferred.resolve(content.status);
757 },
758 function(error) {
759 console.log(error);
760 deferred.reject(error);
761 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700762 return deferred.promise;
763 },
764 hostPowerOff: function() {
765 var deferred = $q.defer();
766 $http({
767 method: 'PUT',
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700768 url: DataService.getHost() +
769 '/xyz/openbmc_project/state/host0/attr/RequestedHostTransition',
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700770 withCredentials: true,
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700771 data: JSON.stringify(
772 {'data': 'xyz.openbmc_project.State.Host.Transition.Off'})
773 })
774 .then(
775 function(response) {
776 var json = JSON.stringify(response.data);
777 var content = JSON.parse(json);
778 deferred.resolve(content.status);
779 },
780 function(error) {
781 console.log(error);
782 deferred.reject(error);
783 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700784 return deferred.promise;
785 },
786 hostReboot: function() {
787 var deferred = $q.defer();
788 $http({
789 method: 'PUT',
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700790 url: DataService.getHost() +
791 '/xyz/openbmc_project/state/host0/attr/RequestedHostTransition',
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700792 withCredentials: true,
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700793 data: JSON.stringify(
794 {'data': 'xyz.openbmc_project.State.Host.Transition.Reboot'})
795 })
796 .then(
797 function(response) {
798 var json = JSON.stringify(response.data);
799 var content = JSON.parse(json);
800 deferred.resolve(content.status);
801 },
802 function(error) {
803 console.log(error);
804 deferred.reject(error);
805 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700806
807 return deferred.promise;
808 },
beccabroek56744252018-08-03 11:25:11 -0500809 getLastPowerTime: function() {
810 return $http({
811 method: 'GET',
812 url: DataService.getHost() +
813 '/xyz/openbmc_project/state/chassis0/attr/LastStateChangeTime',
beccabroek56744252018-08-03 11:25:11 -0500814 withCredentials: true
815 })
816 .then(function(response) {
817 return response.data;
818 });
819 },
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700820 getLogs: function() {
821 var deferred = $q.defer();
822 $http({
823 method: 'GET',
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700824 url: DataService.getHost() +
825 '/xyz/openbmc_project/logging/enumerate',
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700826 withCredentials: true
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700827 })
828 .then(
829 function(response) {
830 var json = JSON.stringify(response.data);
831 var content = JSON.parse(json);
832 var dataClone = JSON.parse(JSON.stringify(content.data));
833 var data = [];
834 var severityCode = '';
835 var priority = '';
836 var health = '';
837 var relatedItems = [];
Matt Spinler845acdc2018-05-01 16:41:28 -0500838 var eventID = 'None';
839 var description = 'None';
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700840
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700841 for (var key in content.data) {
842 if (content.data.hasOwnProperty(key) &&
843 content.data[key].hasOwnProperty('Id')) {
844 var severityFlags = {
845 low: false,
846 medium: false,
847 high: false
848 };
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700849 severityCode =
850 content.data[key].Severity.split('.').pop();
851 priority =
852 Constants.SEVERITY_TO_PRIORITY_MAP[severityCode];
853 severityFlags[priority.toLowerCase()] = true;
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700854 relatedItems = [];
855 content.data[key].associations.forEach(function(item) {
856 relatedItems.push(item[2]);
857 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700858
Matt Spinler845acdc2018-05-01 16:41:28 -0500859 if (content.data[key].hasOwnProperty(['EventID'])) {
860 eventID = content.data[key].EventID;
861 }
862
863 if (content.data[key].hasOwnProperty(['Description'])) {
864 description = content.data[key].Description;
865 }
866
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700867 data.push(Object.assign(
868 {
869 path: key,
870 copied: false,
871 priority: priority,
872 severity_code: severityCode,
873 severity_flags: severityFlags,
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700874 additional_data:
875 content.data[key].AdditionalData.join('\n'),
876 type: content.data[key].Message,
877 selected: false,
878 search_text:
879 ('#' + content.data[key].Id + ' ' +
880 severityCode + ' ' +
Gunnar Mills07876ff2018-06-28 15:21:22 -0500881 content.data[key].Message + ' ' +
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700882 content.data[key].Severity + ' ' +
883 content.data[key].AdditionalData.join(' '))
884 .toLowerCase(),
885 meta: false,
886 confirm: false,
887 related_items: relatedItems,
Matt Spinler845acdc2018-05-01 16:41:28 -0500888 eventID: eventID,
889 description: description,
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700890 data: {key: key, value: content.data[key]}
891 },
892 content.data[key]));
893 }
894 }
895 deferred.resolve({data: data, original: dataClone});
896 },
897 function(error) {
898 console.log(error);
899 deferred.reject(error);
900 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700901
902 return deferred.promise;
903 },
Gunnar Mills615a2f82019-04-17 14:30:39 -0500904 getAllSensorStatus: function(callback) {
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700905 $http({
906 method: 'GET',
Gunnar Mills615a2f82019-04-17 14:30:39 -0500907 url: DataService.getHost() +
908 '/xyz/openbmc_project/sensors/enumerate',
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700909 withCredentials: true
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700910 })
911 .then(
912 function(response) {
Gunnar Mills615a2f82019-04-17 14:30:39 -0500913 var json = JSON.stringify(response.data);
914 var content = JSON.parse(json);
915 var dataClone = JSON.parse(JSON.stringify(content.data));
916 var sensorData = [];
917 var severity = {};
918 var title = '';
919 var tempKeyParts = [];
920 var order = 0;
921 var customOrder = 0;
922
923 function getSensorStatus(reading) {
924 var severityFlags = {
925 critical: false,
926 warning: false,
927 normal: false
928 },
929 severityText = '', order = 0;
930
931 if (reading.hasOwnProperty('CriticalLow') &&
932 reading.Value < reading.CriticalLow) {
933 severityFlags.critical = true;
934 severityText = 'critical';
935 order = 2;
936 } else if (
937 reading.hasOwnProperty('CriticalHigh') &&
938 reading.Value > reading.CriticalHigh) {
939 severityFlags.critical = true;
940 severityText = 'critical';
941 order = 2;
942 } else if (
943 reading.hasOwnProperty('CriticalLow') &&
944 reading.hasOwnProperty('WarningLow') &&
945 reading.Value >= reading.CriticalLow &&
946 reading.Value <= reading.WarningLow) {
947 severityFlags.warning = true;
948 severityText = 'warning';
949 order = 1;
950 } else if (
951 reading.hasOwnProperty('WarningHigh') &&
952 reading.hasOwnProperty('CriticalHigh') &&
953 reading.Value >= reading.WarningHigh &&
954 reading.Value <= reading.CriticalHigh) {
955 severityFlags.warning = true;
956 severityText = 'warning';
957 order = 1;
958 } else {
959 severityFlags.normal = true;
960 severityText = 'normal';
961 }
962 return {
963 flags: severityFlags,
964 severityText: severityText,
965 order: order
966 };
967 }
968
969 for (var key in content.data) {
970 if (content.data.hasOwnProperty(key) &&
971 content.data[key].hasOwnProperty('Unit')) {
972 severity = getSensorStatus(content.data[key]);
973
974 if (!content.data[key].hasOwnProperty('CriticalLow')) {
975 content.data[key].CriticalLow = '--';
976 content.data[key].CriticalHigh = '--';
977 }
978
979 if (!content.data[key].hasOwnProperty('WarningLow')) {
980 content.data[key].WarningLow = '--';
981 content.data[key].WarningHigh = '--';
982 }
983
984 tempKeyParts = key.split('/');
985 title = tempKeyParts.pop();
986 title = tempKeyParts.pop() + '_' + title;
987 title = title.split('_')
988 .map(function(item) {
989 return item.toLowerCase()
990 .charAt(0)
991 .toUpperCase() +
992 item.slice(1);
993 })
994 .reduce(function(prev, el) {
995 return prev + ' ' + el;
996 });
997
998 content.data[key].Value = getScaledValue(
999 content.data[key].Value, content.data[key].Scale);
1000 content.data[key].CriticalLow = getScaledValue(
1001 content.data[key].CriticalLow,
1002 content.data[key].Scale);
1003 content.data[key].CriticalHigh = getScaledValue(
1004 content.data[key].CriticalHigh,
1005 content.data[key].Scale);
1006 content.data[key].WarningLow = getScaledValue(
1007 content.data[key].WarningLow,
1008 content.data[key].Scale);
1009 content.data[key].WarningHigh = getScaledValue(
1010 content.data[key].WarningHigh,
1011 content.data[key].Scale);
1012 if (Constants.SENSOR_SORT_ORDER.indexOf(
1013 content.data[key].Unit) > -1) {
1014 customOrder = Constants.SENSOR_SORT_ORDER.indexOf(
1015 content.data[key].Unit);
1016 } else {
1017 customOrder = Constants.SENSOR_SORT_ORDER_DEFAULT;
1018 }
1019
1020 sensorData.push(Object.assign(
1021 {
1022 path: key,
1023 selected: false,
1024 confirm: false,
1025 copied: false,
1026 title: title,
1027 unit:
1028 Constants
1029 .SENSOR_UNIT_MAP[content.data[key].Unit],
1030 severity_flags: severity.flags,
1031 status: severity.severityText,
1032 order: severity.order,
1033 custom_order: customOrder,
1034 search_text:
1035 (title + ' ' + content.data[key].Value + ' ' +
1036 Constants.SENSOR_UNIT_MAP[content.data[key]
1037 .Unit] +
1038 ' ' + severity.severityText + ' ' +
1039 content.data[key].CriticalLow + ' ' +
1040 content.data[key].CriticalHigh + ' ' +
1041 content.data[key].WarningLow + ' ' +
1042 content.data[key].WarningHigh + ' ')
1043 .toLowerCase(),
1044 original_data:
1045 {key: key, value: content.data[key]}
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001046 },
Gunnar Mills615a2f82019-04-17 14:30:39 -05001047 content.data[key]));
1048 }
1049 }
1050
Alexander Filippove4ae8542019-06-10 15:42:48 +03001051 sensorData.sort(function(a, b) {
1052 return a.title.localeCompare(
1053 b.title, 'en', {numeric: true});
1054 });
1055
Gunnar Mills615a2f82019-04-17 14:30:39 -05001056 callback(sensorData, dataClone);
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001057 },
1058 function(error) {
Gunnar Mills615a2f82019-04-17 14:30:39 -05001059 console.log(error);
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001060 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001061 },
1062 getActivation: function(imageId) {
1063 return $http({
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001064 method: 'GET',
1065 url: DataService.getHost() +
1066 '/xyz/openbmc_project/software/' + imageId +
1067 '/attr/Activation',
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001068 withCredentials: true
1069 })
1070 .then(function(response) {
1071 return response.data;
1072 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001073 },
1074 getFirmwares: function() {
1075 var deferred = $q.defer();
1076 $http({
1077 method: 'GET',
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001078 url: DataService.getHost() +
1079 '/xyz/openbmc_project/software/enumerate',
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001080 withCredentials: true
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001081 })
1082 .then(
1083 function(response) {
1084 var json = JSON.stringify(response.data);
1085 var content = JSON.parse(json);
1086 var data = [];
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001087 var isExtended = false;
1088 var bmcActiveVersion = '';
1089 var hostActiveVersion = '';
1090 var imageType = '';
1091 var extendedVersions = [];
1092 var functionalImages = [];
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001093
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001094 function getFormatedExtendedVersions(extendedVersion) {
1095 var versions = [];
1096 extendedVersion = extendedVersion.split(',');
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001097
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001098 extendedVersion.forEach(function(item) {
1099 var parts = item.split('-');
1100 var numberIndex = 0;
1101 for (var i = 0; i < parts.length; i++) {
1102 if (/[0-9]/.test(parts[i])) {
1103 numberIndex = i;
1104 break;
1105 }
1106 }
George Liu22d78222019-07-19 10:35:40 +08001107 if (numberIndex > 0) {
1108 var titlePart = parts.splice(0, numberIndex);
1109 titlePart = titlePart.join('');
1110 titlePart = titlePart[0].toUpperCase() +
1111 titlePart.substr(1, titlePart.length);
1112 var versionPart = parts.join('-');
1113 versions.push(
1114 {title: titlePart, version: versionPart});
1115 }
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001116 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001117
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001118 return versions;
1119 }
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001120
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001121 // Get the list of functional images so we can compare
1122 // later if an image is functional
1123 if (content.data[Constants.FIRMWARE.FUNCTIONAL_OBJPATH]) {
1124 functionalImages =
1125 content.data[Constants.FIRMWARE.FUNCTIONAL_OBJPATH]
1126 .endpoints;
1127 }
1128 for (var key in content.data) {
1129 if (content.data.hasOwnProperty(key) &&
1130 content.data[key].hasOwnProperty('Version')) {
Gunnar Millsac9131e2018-07-13 15:52:18 -05001131 var activationStatus = '';
1132
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001133 // If the image is "Functional" use that for the
AppaRao Puli28711a62018-10-17 16:07:55 +05301134 // activation status, else use the value of
1135 // "Activation"
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001136 // github.com/openbmc/phosphor-dbus-interfaces/blob/master/xyz/openbmc_project/Software/Activation.interface.yaml
Gunnar Millsac9131e2018-07-13 15:52:18 -05001137 if (content.data[key].Activation) {
1138 activationStatus =
1139 content.data[key].Activation.split('.').pop();
1140 }
1141
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001142 if (functionalImages.includes(key)) {
1143 activationStatus = 'Functional';
1144 }
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001145
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001146 imageType = content.data[key].Purpose.split('.').pop();
1147 isExtended = content.data[key].hasOwnProperty(
1148 'ExtendedVersion') &&
1149 content.data[key].ExtendedVersion != '';
1150 if (isExtended) {
1151 extendedVersions = getFormatedExtendedVersions(
1152 content.data[key].ExtendedVersion);
1153 }
1154 data.push(Object.assign(
1155 {
1156 path: key,
1157 activationStatus: activationStatus,
1158 imageId: key.split('/').pop(),
1159 imageType: imageType,
1160 isExtended: isExtended,
1161 extended:
1162 {show: false, versions: extendedVersions},
1163 data: {key: key, value: content.data[key]}
1164 },
1165 content.data[key]));
1166
1167 if (activationStatus == 'Functional' &&
1168 imageType == 'BMC') {
1169 bmcActiveVersion = content.data[key].Version;
1170 }
1171
1172 if (activationStatus == 'Functional' &&
1173 imageType == 'Host') {
1174 hostActiveVersion = content.data[key].Version;
1175 }
1176 }
1177 }
1178
1179 deferred.resolve({
1180 data: data,
1181 bmcActiveVersion: bmcActiveVersion,
1182 hostActiveVersion: hostActiveVersion
1183 });
Iftekharul Islam171c6a12017-08-11 08:35:47 -05001184 },
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001185 function(error) {
1186 console.log(error);
1187 deferred.reject(error);
1188 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001189
1190 return deferred.promise;
1191 },
1192 changePriority: function(imageId, priority) {
Gunnar Millsf7f59462018-09-20 16:02:08 -05001193 return $http({
1194 method: 'PUT',
1195 url: DataService.getHost() +
1196 '/xyz/openbmc_project/software/' + imageId +
1197 '/attr/Priority',
1198 withCredentials: true,
1199 data: JSON.stringify({'data': priority})
1200 })
1201 .then(function(response) {
1202 return response.data;
1203 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001204 },
1205 deleteImage: function(imageId) {
Gunnar Millsf7f59462018-09-20 16:02:08 -05001206 return $http({
1207 method: 'POST',
1208 url: DataService.getHost() +
1209 '/xyz/openbmc_project/software/' + imageId +
1210 '/action/Delete',
1211 withCredentials: true,
1212 data: JSON.stringify({'data': []})
1213 })
1214 .then(function(response) {
1215 return response.data;
1216 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001217 },
1218 activateImage: function(imageId) {
Gunnar Millsf7f59462018-09-20 16:02:08 -05001219 return $http({
1220 method: 'PUT',
1221 url: DataService.getHost() +
1222 '/xyz/openbmc_project/software/' + imageId +
1223 '/attr/RequestedActivation',
1224 withCredentials: true,
1225 data: JSON.stringify(
1226 {'data': Constants.FIRMWARE.ACTIVATE_FIRMWARE})
1227 })
1228 .then(function(response) {
1229 return response.data;
1230 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001231 },
1232 uploadImage: function(file) {
1233 return $http({
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001234 method: 'POST',
1235 timeout: 5 * 60 * 1000,
1236 url: DataService.getHost() + '/upload/image',
Gunnar Millsdd9d4c32018-09-10 12:59:34 -05001237 // Overwrite the default 'application/json' Content-Type
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001238 headers: {'Content-Type': 'application/octet-stream'},
1239 withCredentials: true,
1240 data: file
1241 })
1242 .then(function(response) {
1243 return response.data;
1244 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001245 },
1246 downloadImage: function(host, filename) {
1247 return $http({
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001248 method: 'POST',
1249 url: DataService.getHost() +
1250 '/xyz/openbmc_project/software/action/DownloadViaTFTP',
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001251 withCredentials: true,
1252 data: JSON.stringify({'data': [filename, host]}),
1253 responseType: 'arraybuffer'
1254 })
1255 .then(function(response) {
1256 return response.data;
1257 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001258 },
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001259 getServerInfo: function() {
1260 // TODO: openbmc/openbmc#3117 Need a way via REST to get
1261 // interfaces so we can get the system object(s) by the looking
1262 // for the system interface.
1263 return $http({
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001264 method: 'GET',
1265 url: DataService.getHost() +
1266 '/xyz/openbmc_project/inventory/system',
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001267 withCredentials: true
1268 })
1269 .then(function(response) {
1270 return response.data;
1271 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001272 },
1273 getBMCTime: function() {
1274 return $http({
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001275 method: 'GET',
1276 url: DataService.getHost() + '/xyz/openbmc_project/time/bmc',
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001277 withCredentials: true
1278 })
1279 .then(function(response) {
1280 return response.data;
1281 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001282 },
Gunnar Millsc74d4342018-07-18 14:52:02 -05001283 getTime: function() {
1284 return $http({
1285 method: 'GET',
1286 url: DataService.getHost() +
1287 '/xyz/openbmc_project/time/enumerate',
Gunnar Millsc74d4342018-07-18 14:52:02 -05001288 withCredentials: true
1289 })
1290 .then(function(response) {
1291 return response.data;
1292 });
1293 },
Gunnar Millsb7ea2792018-07-18 13:01:48 -05001294 // Even though NTPServers is a network interface specific path
1295 // (e.g. /xyz/openbmc_project/network/eth0/attr/NTPServers) it acts
1296 // like a global setting. Just use eth0 for setting and getting the
1297 // NTP Servers until it is moved to a non-network interface specific
1298 // path like it is in Redfish. TODO: openbmc/phosphor-time-manager#4
1299 getNTPServers: function() {
1300 return $http({
1301 method: 'GET',
1302 url: DataService.getHost() +
1303 '/xyz/openbmc_project/network/eth0/attr/NTPServers',
Gunnar Millsb7ea2792018-07-18 13:01:48 -05001304 withCredentials: true
1305 })
1306 .then(function(response) {
1307 return response.data;
1308 });
1309 },
1310 setNTPServers: function(ntpServers) {
1311 return $http({
1312 method: 'PUT',
1313 url: DataService.getHost() +
1314 '/xyz/openbmc_project/network/eth0/attr/NTPServers',
Gunnar Millsb7ea2792018-07-18 13:01:48 -05001315 withCredentials: true,
1316 data: JSON.stringify({'data': ntpServers})
1317 })
1318 .then(function(response) {
1319 return response.data;
1320 });
1321 },
1322 setTimeMode: function(timeMode) {
1323 return $http({
1324 method: 'PUT',
1325 url: DataService.getHost() +
1326 '/xyz/openbmc_project/time/sync_method/attr/TimeSyncMethod',
Gunnar Millsb7ea2792018-07-18 13:01:48 -05001327 withCredentials: true,
1328 data: JSON.stringify({'data': timeMode})
1329 })
1330 .then(function(response) {
1331 return response.data;
1332 });
1333 },
1334 setTimeOwner: function(timeOwner) {
1335 return $http({
1336 method: 'PUT',
1337 url: DataService.getHost() +
1338 '/xyz/openbmc_project/time/owner/attr/TimeOwner',
Gunnar Millsb7ea2792018-07-18 13:01:48 -05001339 withCredentials: true,
1340 data: JSON.stringify({'data': timeOwner})
1341 })
1342 .then(function(response) {
1343 return response.data;
1344 });
1345 },
1346 setBMCTime: function(time) {
1347 return $http({
1348 method: 'PUT',
1349 url: DataService.getHost() +
1350 '/xyz/openbmc_project/time/bmc/attr/Elapsed',
Gunnar Millsb7ea2792018-07-18 13:01:48 -05001351 withCredentials: true,
1352 data: JSON.stringify({'data': time})
1353 })
1354 .then(function(response) {
1355 return response.data;
1356 });
1357 },
1358 setHostTime: function(time) {
1359 return $http({
1360 method: 'PUT',
1361 url: DataService.getHost() +
1362 '/xyz/openbmc_project/time/host/attr/Elapsed',
Gunnar Millsb7ea2792018-07-18 13:01:48 -05001363 withCredentials: true,
1364 data: JSON.stringify({'data': time})
1365 })
1366 .then(function(response) {
1367 return response.data;
1368 });
1369 },
beccabroek309b5da2018-11-07 12:22:31 -06001370 getCertificateLocations: function() {
1371 return $http({
1372 method: 'GET',
1373 url: DataService.getHost() +
1374 '/redfish/v1/CertificateService/CertificateLocations',
1375 withCredentials: true
1376 })
1377 .then(function(response) {
1378 return response.data;
1379 });
1380 },
1381 getCertificate: function(location) {
1382 return $http({
1383 method: 'GET',
1384 url: DataService.getHost() + location,
1385 withCredentials: true
1386 })
1387 .then(function(response) {
1388 return response.data;
1389 });
1390 },
1391 addNewCertificate: function(file, type) {
1392 return $http({
1393 method: 'POST',
1394 url: DataService.getHost() + type.location,
1395 headers: {'Content-Type': 'application/x-pem-file'},
1396 withCredentials: true,
1397 data: file
1398 })
1399 .then(function(response) {
1400 return response.data;
1401 });
1402 },
1403 replaceCertificate: function(data) {
1404 return $http({
1405 method: 'POST',
1406 url: DataService.getHost() +
1407 '/redfish/v1/CertificateService/Actions/CertificateService.ReplaceCertificate',
1408 withCredentials: true,
1409 data: data
1410 })
1411 .then(function(response) {
1412 return response.data;
1413 });
1414 },
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001415 getHardwares: function(callback) {
1416 $http({
1417 method: 'GET',
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001418 url: DataService.getHost() +
1419 '/xyz/openbmc_project/inventory/enumerate',
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001420 withCredentials: true
1421 }).then(function(response) {
1422 var json = JSON.stringify(response.data);
1423 var content = JSON.parse(json);
1424 var hardwareData = [];
1425 var keyIndexMap = {};
1426 var title = '';
beccabroek628ba8b2018-10-01 14:12:25 -05001427 var depth = '';
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001428 var data = [];
1429 var searchText = '';
1430 var componentIndex = -1;
beccabroek628ba8b2018-10-01 14:12:25 -05001431 var parent = '';
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001432
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001433 function isSubComponent(key) {
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001434 for (var i = 0; i < Constants.HARDWARE.parent_components.length;
1435 i++) {
1436 if (key.split(Constants.HARDWARE.parent_components[i]).length ==
1437 2)
1438 return true;
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001439 }
1440
1441 return false;
1442 }
1443
1444 function titlelize(title) {
1445 title = title.replace(/([A-Z0-9]+)/g, ' $1').replace(/^\s+/, '');
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001446 for (var i = 0; i < Constants.HARDWARE.uppercase_titles.length;
1447 i++) {
1448 if (title.toLowerCase().indexOf(
1449 (Constants.HARDWARE.uppercase_titles[i] + ' ')) > -1) {
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001450 return title.toUpperCase();
1451 }
1452 }
1453
1454 return title;
1455 }
1456
1457 function camelcaseToLabel(obj) {
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001458 var transformed = [], label = '', value = '';
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001459 for (var key in obj) {
1460 label = key.replace(/([A-Z0-9]+)/g, ' $1').replace(/^\s+/, '');
1461 if (obj[key] !== '') {
1462 value = obj[key];
1463 if (value == 1 || value == 0) {
1464 value = (value == 1) ? 'Yes' : 'No';
1465 }
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001466 transformed.push({key: label, value: value});
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001467 }
1468 }
1469
1470 return transformed;
1471 }
1472
beccabroek628ba8b2018-10-01 14:12:25 -05001473 function determineParent(key) {
1474 var levels = key.split('/');
1475 levels.pop();
1476 return levels.join('/');
1477 }
1478
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001479 function getSearchText(data) {
1480 var searchText = '';
1481 for (var i = 0; i < data.length; i++) {
1482 searchText += ' ' + data[i].key + ' ' + data[i].value;
1483 }
1484
1485 return searchText;
1486 }
1487
1488 for (var key in content.data) {
1489 if (content.data.hasOwnProperty(key) &&
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001490 key.indexOf(Constants.HARDWARE.component_key_filter) == 0) {
Gunnar Millseedf0b92019-02-27 10:52:01 -06001491 // All and only associations have the property "endpoints".
Gunnar Millsc9c8e672019-07-24 17:08:15 -05001492 // We don't want to show forward/reverse association objects
1493 // that the mapper created on the inventory panel.
Gunnar Millseedf0b92019-02-27 10:52:01 -06001494 // Example: An association from the BMC inventory item to the
Gunnar Millsc9c8e672019-07-24 17:08:15 -05001495 // BMC firmware images. See:
1496 // https://github.com/openbmc/docs/blob/master/object-mapper.md#associations
Gunnar Millseedf0b92019-02-27 10:52:01 -06001497 if (content.data[key].hasOwnProperty('endpoints')) {
1498 continue;
1499 }
Gunnar Millsc9c8e672019-07-24 17:08:15 -05001500 // There is also an "Associations" property created by the
1501 // Association interface. These would show on the inventory
1502 // panel under the individual inventory item dropdown. There
1503 // can be a lot of associations in this property and they are
1504 // long, full D-Bus paths. Not particularly useful. Remove
1505 // for now.
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001506
Gunnar Millsc9c8e672019-07-24 17:08:15 -05001507 if (content.data[key].hasOwnProperty('Associations')) {
1508 delete content.data[key].Associations;
1509 }
1510
1511 // Support old Associations interface property
1512 // https://github.com/openbmc/phosphor-logging/blob/master/org/openbmc/Associations.interface.yaml
1513 // Remove when we move to new Associations interface
1514 // openbmc/openbmc#3584
1515 if (content.data[key].hasOwnProperty('associations')) {
1516 delete content.data[key].associations;
1517 }
1518
1519 data = camelcaseToLabel(content.data[key]);
1520 searchText = getSearchText(data);
1521 title = key.split('/').pop();
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001522 title = titlelize(title);
beccabroek628ba8b2018-10-01 14:12:25 -05001523 // e.g. /xyz/openbmc_project/inventory/system and
1524 // /xyz/openbmc_project/inventory/system/chassis are depths of 5
1525 // and 6.
1526 depth = key.split('/').length;
1527 parent = determineParent(key);
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001528
1529 if (!isSubComponent(key)) {
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001530 hardwareData.push(Object.assign(
1531 {
1532 path: key,
1533 title: title,
beccabroek628ba8b2018-10-01 14:12:25 -05001534 depth: depth,
1535 parent: parent,
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001536 selected: false,
1537 expanded: false,
1538 search_text: title.toLowerCase() + ' ' +
1539 searchText.toLowerCase(),
1540 sub_components: [],
1541 original_data: {key: key, value: content.data[key]}
1542 },
1543 {items: data}));
Iftekharul Islam2a489552017-11-02 13:23:08 -05001544
Gunnar Millsc9c8e672019-07-24 17:08:15 -05001545
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001546 keyIndexMap[key] = hardwareData.length - 1;
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001547 } else {
beccabroek628ba8b2018-10-01 14:12:25 -05001548 parent = determineParent(key)
1549 componentIndex = keyIndexMap[parent];
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001550 data = content.data[key];
1551 data.title = title;
1552 hardwareData[componentIndex].sub_components.push(data);
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001553 hardwareData[componentIndex].search_text +=
1554 ' ' + title.toLowerCase();
Iftekharul Islam171c6a12017-08-11 08:35:47 -05001555
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001556 // Sort the subcomponents alphanumeric so they are displayed
1557 // on the inventory page in order (e.g. core 0, core 1, core
1558 // 2, ... core 12, core 13)
1559 hardwareData[componentIndex].sub_components.sort(function(
1560 a, b) {
1561 return a.title.localeCompare(
1562 b.title, 'en', {numeric: true});
Gunnar Mills55a8e392018-03-14 15:37:44 -05001563 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001564 }
1565 }
1566 }
beccabroek628ba8b2018-10-01 14:12:25 -05001567 // First, order the components by depth and then place the child
1568 // components beneath their parent component alphanumerically. Can
1569 // be removed with completion of
1570 // https://github.com/openbmc/openbmc/issues/3401
1571 // TODO: Remove this once implemented in back end
1572 hardwareData.sort(function(a, b) {
1573 if (a.depth < b.depth) return -1;
1574 if (a.depth > b.depth) return 1;
1575 return b.title.localeCompare(a.title, 'en', {numeric: true});
1576 });
1577
1578 var orderedComponents = [];
1579
1580 for (var i = 0; i < hardwareData.length; i++) {
1581 if (!keyIndexMap[hardwareData[i].parent]) {
1582 orderedComponents.push(hardwareData[i]);
1583 } else {
1584 for (var j = 0; j < orderedComponents.length; j++) {
1585 if (orderedComponents[j].path === hardwareData[i].parent) {
1586 var child = hardwareData[i];
1587 orderedComponents.splice(j + 1, 0, child);
1588 }
1589 }
1590 }
1591 }
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001592
1593 if (callback) {
beccabroek628ba8b2018-10-01 14:12:25 -05001594 callback(orderedComponents, content.data);
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001595 } else {
beccabroek628ba8b2018-10-01 14:12:25 -05001596 return {data: orderedComponents, original_data: content.data};
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001597 }
1598 });
1599 },
1600 deleteLogs: function(logs) {
1601 var defer = $q.defer();
1602 var promises = [];
1603
1604 function finished() {
1605 defer.resolve();
1606 }
1607
1608 logs.forEach(function(item) {
1609 promises.push($http({
1610 method: 'POST',
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001611 url: DataService.getHost() +
1612 '/xyz/openbmc_project/logging/entry/' + item.Id +
1613 '/action/Delete',
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001614 withCredentials: true,
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001615 data: JSON.stringify({'data': []})
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001616 }));
1617 });
1618
1619 $q.all(promises).then(finished);
1620
1621 return defer.promise;
1622 },
1623 resolveLogs: function(logs) {
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001624 var promises = [];
1625
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001626 logs.forEach(function(item) {
1627 promises.push($http({
1628 method: 'PUT',
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001629 url: DataService.getHost() +
1630 '/xyz/openbmc_project/logging/entry/' + item.Id +
1631 '/attr/Resolved',
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001632 withCredentials: true,
Gunnar Mills7e48d082019-01-23 16:02:03 -06001633 data: JSON.stringify({'data': true})
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001634 }));
1635 });
Gunnar Mills7e48d082019-01-23 16:02:03 -06001636 return $q.all(promises);
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001637 },
Yoshie Muranakae4194ce2019-05-24 14:33:56 -05001638 setRemoteLoggingServer: (data) => {
1639 const ip = data.hostname;
1640 const port = data.port;
1641 const setIPRequest = $http({
1642 method: 'PUT',
1643 url: DataService.getHost() +
1644 '/xyz/openbmc_project/logging/config/remote/attr/Address',
1645 withCredentials: true,
1646 data: {'data': ip}
1647 });
1648 const setPortRequest = $http({
1649 method: 'PUT',
1650 url: DataService.getHost() +
1651 '/xyz/openbmc_project/logging/config/remote/attr/Port',
1652 withCredentials: true,
1653 data: {'data': port}
1654 });
1655 const promises = [setIPRequest, setPortRequest];
1656 return $q.all(promises);
1657 },
1658 getRemoteLoggingServer: () => {
1659 return $http({
1660 method: 'GET',
1661 url: DataService.getHost() +
1662 '/xyz/openbmc_project/logging/config/remote',
1663 withCredentials: true
1664 })
1665 .then((response) => {
1666 const remoteServer = response.data.data;
1667 if (remoteServer === undefined) {
1668 return undefined;
1669 }
1670 const hostname = remoteServer.Address;
1671 const port = remoteServer.Port;
1672 if (hostname === '') {
1673 return undefined;
1674 } else {
1675 return {
1676 hostname, port
1677 }
1678 }
1679 });
1680 },
1681 disableRemoteLoggingServer: () => {
1682 return SERVICE.setRemoteLoggingServer({hostname: '', port: 0});
1683 },
1684 updateRemoteLoggingServer: (data) => {
1685 // Recommended to disable existing configuration
1686 // before updating config to new server
1687 // https://github.com/openbmc/phosphor-logging#changing-the-rsyslog-server
1688 return SERVICE.disableRemoteLoggingServer()
1689 .then(() => {
1690 return SERVICE.setRemoteLoggingServer(data);
1691 })
1692 .catch(() => {
1693 // try updating server even if initial disable attempt fails
1694 return SERVICE.setRemoteLoggingServer(data);
1695 });
1696 },
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001697 getPowerConsumption: function() {
1698 return $http({
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001699 method: 'GET',
1700 url: DataService.getHost() +
1701 '/xyz/openbmc_project/sensors/power/total_power',
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001702 withCredentials: true
1703 })
1704 .then(
1705 function(response) {
1706 var json = JSON.stringify(response.data);
1707 var content = JSON.parse(json);
Iftekharul Islamcd789502017-04-19 14:37:55 -05001708
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001709 return getScaledValue(
1710 content.data.Value, content.data.Scale) +
1711 ' ' +
1712 Constants.POWER_CONSUMPTION_TEXT[content.data.Unit];
1713 },
1714 function(error) {
1715 if ('Not Found' == error.statusText) {
1716 return Constants.POWER_CONSUMPTION_TEXT.notavailable;
1717 } else {
1718 throw error;
1719 }
1720 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001721 },
1722 getPowerCap: function() {
1723 return $http({
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001724 method: 'GET',
1725 url: DataService.getHost() +
1726 '/xyz/openbmc_project/control/host0/power_cap',
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001727 withCredentials: true
1728 })
1729 .then(function(response) {
Gunnar Mills006aaa02018-06-26 16:08:59 -05001730 return response.data;
1731 });
1732 },
1733 setPowerCapEnable: function(powerCapEnable) {
1734 return $http({
1735 method: 'PUT',
1736 url: DataService.getHost() +
1737 '/xyz/openbmc_project/control/host0/power_cap/attr/PowerCapEnable',
Gunnar Mills006aaa02018-06-26 16:08:59 -05001738 withCredentials: true,
1739 data: JSON.stringify({'data': powerCapEnable})
1740 })
1741 .then(function(response) {
1742 return response.data;
1743 });
1744 },
1745 setPowerCap: function(powerCap) {
1746 return $http({
1747 method: 'PUT',
1748 url: DataService.getHost() +
1749 '/xyz/openbmc_project/control/host0/power_cap/attr/PowerCap',
Gunnar Mills006aaa02018-06-26 16:08:59 -05001750 withCredentials: true,
1751 data: JSON.stringify({'data': powerCap})
1752 })
1753 .then(function(response) {
1754 return response.data;
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001755 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001756 },
1757 setHostname: function(hostname) {
1758 return $http({
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001759 method: 'PUT',
1760 url: DataService.getHost() +
1761 '/xyz/openbmc_project/network/config/attr/HostName',
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001762 withCredentials: true,
1763 data: JSON.stringify({'data': hostname})
1764 })
1765 .then(function(response) {
1766 return response.data;
1767 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001768 },
1769 };
1770 return SERVICE;
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001771 }
1772 ]);
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001773})(window.angular);