blob: 503fcd1a611f4644a157b5848470fc5ece8387bc [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,
29 CHASSIS_POWER_STATE: Constants.CHASSIS_POWER_STATE,
30 HOST_STATE_TEXT: Constants.HOST_STATE,
31 HOST_STATE: Constants.HOST_STATE,
32 LED_STATE: Constants.LED_STATE,
33 LED_STATE_TEXT: Constants.LED_STATE_TEXT,
34 HOST_SESSION_STORAGE_KEY: Constants.API_CREDENTIALS.host_storage_key,
35 getChassisState: function() {
36 var deferred = $q.defer();
37 $http({
38 method: 'GET',
Andrew Geisslerd27bb132018-05-24 11:07:27 -070039 url: DataService.getHost() +
40 '/xyz/openbmc_project/state/chassis0/attr/CurrentPowerState',
Andrew Geisslerba5e3f32018-05-24 10:58:00 -070041 withCredentials: true
Andrew Geisslerd27bb132018-05-24 11:07:27 -070042 })
43 .then(
44 function(response) {
45 var json = JSON.stringify(response.data);
46 var content = JSON.parse(json);
47 deferred.resolve(content.data);
48 },
49 function(error) {
50 console.log(error);
51 deferred.reject(error);
52 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -070053 return deferred.promise;
54 },
Gunnar Mills65491142018-06-04 14:23:33 -050055 validIPV4IP: function(ip) {
56 // Checks for [0-255].[0-255].[0-255].[0-255]
57 return ip.match(
58 /\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/);
59 },
Gunnar Mills854fbba2018-09-13 15:41:30 -050060 deleteObject: function(path) {
61 return $http({
62 method: 'POST',
63 url: DataService.getHost() + path + '/action/Delete',
64 withCredentials: true,
65 data: JSON.stringify({'data': []})
66 })
67 .then(function(response) {
68 return response.data;
69 });
70 },
Andrew Geisslerba5e3f32018-05-24 10:58:00 -070071 getHostState: function() {
72 var deferred = $q.defer();
73 $http({
74 method: 'GET',
Andrew Geisslerd27bb132018-05-24 11:07:27 -070075 url: DataService.getHost() +
76 '/xyz/openbmc_project/state/host0/attr/CurrentHostState',
Andrew Geisslerba5e3f32018-05-24 10:58:00 -070077 withCredentials: true
Andrew Geisslerd27bb132018-05-24 11:07:27 -070078 })
79 .then(
80 function(response) {
81 var json = JSON.stringify(response.data);
82 var content = JSON.parse(json);
83 deferred.resolve(content.data);
84 },
85 function(error) {
86 console.log(error);
87 deferred.reject(error);
88 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -070089 return deferred.promise;
90 },
Gunnar Millsff64c542018-08-24 15:49:09 -050091 getSNMPManagers: function() {
92 return $http({
93 method: 'GET',
94 url: DataService.getHost() +
95 '/xyz/openbmc_project/network/snmp/manager/enumerate',
Gunnar Millsff64c542018-08-24 15:49:09 -050096 withCredentials: true
97 })
98 .then(function(response) {
99 return response.data;
100 });
101 },
beccabroekc3abaa92018-08-14 13:47:18 -0500102 pollHostStatusTillOn: function() {
103 var deferred = $q.defer();
104 var hostOnTimeout = setTimeout(function() {
105 ws.close();
106 deferred.reject(new Error(Constants.MESSAGES.POLL.HOST_ON_TIMEOUT));
107 }, Constants.TIMEOUT.HOST_ON);
108
109 var ws =
110 new WebSocket('wss://' + DataService.server_id + '/subscribe');
111 var data = JSON.stringify({
112 'paths': ['/xyz/openbmc_project/state/host0'],
113 'interfaces': ['xyz.openbmc_project.State.Host']
114 });
115 ws.onopen = function() {
116 ws.send(data);
117 };
118 ws.onmessage = function(evt) {
119 var content = JSON.parse(evt.data);
120 var hostState = content.properties.CurrentHostState;
121 if (hostState === Constants.HOST_STATE_TEXT.on_code) {
122 clearTimeout(hostOnTimeout);
123 ws.close();
124 deferred.resolve();
125 } else if (hostState === Constants.HOST_STATE_TEXT.error_code) {
126 clearTimeout(hostOnTimeout);
127 ws.close();
128 deferred.reject(new Error(Constants.MESSAGES.POLL.HOST_QUIESCED));
129 }
130 };
131 },
132
133 pollHostStatusTilReboot: function() {
134 var deferred = $q.defer();
135 var onState = Constants.HOST_STATE_TEXT.on_code;
136 var offState = Constants.HOST_STATE_TEXT.on_code;
137 var hostTimeout;
138 var setHostTimeout = function(message, timeout) {
139 hostTimeout = setTimeout(function() {
140 ws.close();
141 deferred.reject(new Error(message));
142 }, timeout);
143 };
144 var ws =
145 new WebSocket('wss://' + DataService.server_id + '/subscribe');
146 var data = JSON.stringify({
147 'paths': ['/xyz/openbmc_project/state/host0'],
148 'interfaces': ['xyz.openbmc_project.State.Host']
149 });
150 ws.onopen = function() {
151 ws.send(data);
152 };
153 setHostTimeout(
154 Constants.MESSAGES.POLL.HOST_OFF_TIMEOUT,
155 Constants.TIMEOUT.HOST_OFF);
156 var pollState = offState;
157 ws.onmessage = function(evt) {
158 var content = JSON.parse(evt.data);
159 var hostState = content.properties.CurrentHostState;
160 if (hostState === pollState) {
161 if (pollState === offState) {
162 clearTimeout(hostTimeout);
163 pollState = onState;
164 setHostTimeout(
165 Constants.MESSAGES.POLL.HOST_ON_TIMEOUT,
166 Constants.TIMEOUT.HOST_ON);
167 }
168 if (pollState === onState) {
169 clearTimeout(hostTimeout);
170 ws.close();
171 deferred.resolve();
172 }
173 } else if (hostState === Constants.HOST_STATE_TEXT.error_code) {
174 clearTimeout(hostTimeout);
175 ws.close();
176 deferred.reject(new Error(Constants.MESSAGES.POLL.HOST_QUIESCED));
177 }
178 };
179 },
180
181 pollHostStatusTillOff: function() {
182 var deferred = $q.defer();
183 var hostOffTimeout = setTimeout(function() {
184 ws.close();
185 deferred.reject(
186 new Error(Constants.MESSAGES.POLL.HOST_OFF_TIMEOUT));
187 }, Constants.TIMEOUT.HOST_OFF);
188
189 var ws =
190 new WebSocket('wss://' + DataService.server_id + '/subscribe');
191 var data = JSON.stringify({
192 'paths': ['/xyz/openbmc_project/state/host0'],
193 'interfaces': ['xyz.openbmc_project.State.Host']
194 });
195 ws.onopen = function() {
196 ws.send(data);
197 };
198 ws.onmessage = function(evt) {
199 var content = JSON.parse(evt.data);
200 var hostState = content.properties.CurrentHostState;
201 if (hostState === Constants.HOST_STATE_TEXT.off_code) {
202 clearTimeout(hostOffTimeout);
203 ws.close();
204 deferred.resolve();
205 }
206 };
207 },
Gunnar Mills854fbba2018-09-13 15:41:30 -0500208 addSNMPManager: function(address, port) {
209 return $http({
210 method: 'POST',
211 url: DataService.getHost() +
212 '/xyz/openbmc_project/network/snmp/manager/action/Client',
213 withCredentials: true,
214 data: JSON.stringify({'data': [address, +port]})
215 })
216 .then(function(response) {
217 return response.data;
218 });
219 },
220 setSNMPManagerPort: function(snmpManagerPath, port) {
221 return $http({
222 method: 'PUT',
223 url: DataService.getHost() + snmpManagerPath + '/attr/Port',
224 withCredentials: true,
225 data: JSON.stringify({'data': +port})
226 })
227 .then(function(response) {
228 return response.data;
229 });
230 },
231 setSNMPManagerAddress: function(snmpManagerPath, address) {
232 return $http({
233 method: 'PUT',
234 url: DataService.getHost() + snmpManagerPath +
235 '/attr/Address',
236 withCredentials: true,
237 data: JSON.stringify({'data': address})
238 })
239 .then(function(response) {
240 return response.data;
241 });
242 },
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700243 getNetworkInfo: function() {
244 var deferred = $q.defer();
245 $http({
246 method: 'GET',
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700247 url: DataService.getHost() +
248 '/xyz/openbmc_project/network/enumerate',
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700249 withCredentials: true
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700250 })
251 .then(
252 function(response) {
253 var json = JSON.stringify(response.data);
254 var content = JSON.parse(json);
255 var hostname = '';
Gunnar Millse9f5fe72018-05-04 13:43:10 -0500256 var defaultgateway = '';
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700257 var macAddress = '';
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700258
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700259 function parseNetworkData(content) {
260 var data = {
261 interface_ids: [],
262 interfaces: {},
263 ip_addresses: {ipv4: [], ipv6: []},
264 };
265 var interfaceId = '', keyParts = [], interfaceHash = '',
266 interfaceType = '';
267 for (var key in content.data) {
Gunnar Mills3efbe2d2018-06-07 14:47:19 -0500268 if (key.match(/network\/eth\d+(_\d+)?$/ig)) {
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700269 interfaceId = key.split('/').pop();
270 if (data.interface_ids.indexOf(interfaceId) == -1) {
271 data.interface_ids.push(interfaceId);
272 data.interfaces[interfaceId] = {
273 interfaceIname: '',
274 DomainName: '',
275 MACAddress: '',
276 Nameservers: [],
277 DHCPEnabled: 0,
278 ipv4: {ids: [], values: []},
279 ipv6: {ids: [], values: []}
280 };
281 data.interfaces[interfaceId].MACAddress =
282 content.data[key].MACAddress;
283 data.interfaces[interfaceId].DomainName =
284 content.data[key].DomainName.join(' ');
285 data.interfaces[interfaceId].Nameservers =
286 content.data[key].Nameservers;
287 data.interfaces[interfaceId].DHCPEnabled =
288 content.data[key].DHCPEnabled;
289 }
290 } else if (
291 key.match(
Gunnar Mills3efbe2d2018-06-07 14:47:19 -0500292 /network\/eth\d+(_\d+)?\/ipv[4|6]\/[a-z0-9]+$/ig)) {
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700293 keyParts = key.split('/');
294 interfaceHash = keyParts.pop();
295 interfaceType = keyParts.pop();
296 interfaceId = keyParts.pop();
297
298 if (data.interfaces[interfaceId][interfaceType]
299 .ids.indexOf(interfaceHash) == -1) {
300 data.interfaces[interfaceId][interfaceType]
301 .ids.push(interfaceHash);
302 data.interfaces[interfaceId][interfaceType]
303 .values.push(content.data[key]);
304 data.ip_addresses[interfaceType].push(
305 content.data[key]['Address']);
306 }
307 }
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700308 }
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700309 return data;
310 }
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700311
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700312 if (content.data.hasOwnProperty(
Gunnar Millse9f5fe72018-05-04 13:43:10 -0500313 '/xyz/openbmc_project/network/config')) {
314 if (content.data['/xyz/openbmc_project/network/config']
315 .hasOwnProperty('HostName')) {
316 hostname =
317 content.data['/xyz/openbmc_project/network/config']
318 .HostName;
319 }
320 if (content.data['/xyz/openbmc_project/network/config']
321 .hasOwnProperty('DefaultGateway')) {
322 defaultgateway =
323 content.data['/xyz/openbmc_project/network/config']
324 .DefaultGateway;
325 }
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700326 }
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700327
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700328 if (content.data.hasOwnProperty(
329 '/xyz/openbmc_project/network/eth0') &&
330 content.data['/xyz/openbmc_project/network/eth0']
331 .hasOwnProperty('MACAddress')) {
332 macAddress =
333 content.data['/xyz/openbmc_project/network/eth0']
334 .MACAddress;
335 }
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700336
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700337 deferred.resolve({
338 data: content.data,
339 hostname: hostname,
Gunnar Millse9f5fe72018-05-04 13:43:10 -0500340 defaultgateway: defaultgateway,
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700341 mac_address: macAddress,
342 formatted_data: parseNetworkData(content)
343 });
344 },
345 function(error) {
346 console.log(error);
347 deferred.reject(error);
348 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700349 return deferred.promise;
350 },
Gunnar Mills7ddc7272018-04-12 16:12:03 -0500351 setMACAddress: function(interface_name, mac_address) {
352 return $http({
353 method: 'PUT',
354 url: DataService.getHost() +
355 '/xyz/openbmc_project/network/' + interface_name +
356 '/attr/MACAddress',
Gunnar Mills7ddc7272018-04-12 16:12:03 -0500357 withCredentials: true,
358 data: JSON.stringify({'data': mac_address})
359 })
360 .then(function(response) {
361 return response.data;
362 });
363 },
Gunnar Millsdca79d72018-05-30 13:07:01 -0500364 setDefaultGateway: function(defaultGateway) {
365 return $http({
366 method: 'PUT',
367 url: DataService.getHost() +
368 '/xyz/openbmc_project/network/config/attr/DefaultGateway',
Gunnar Millsdca79d72018-05-30 13:07:01 -0500369 withCredentials: true,
370 data: JSON.stringify({'data': defaultGateway})
371 })
372 .then(function(response) {
373 return response.data;
374 });
375 },
Gunnar Millscb2c3062018-05-31 13:13:30 -0500376 setDHCPEnabled: function(interfaceName, dhcpEnabled) {
377 return $http({
378 method: 'PUT',
379 url: DataService.getHost() +
380 '/xyz/openbmc_project/network/' + interfaceName +
381 '/attr/DHCPEnabled',
Gunnar Millscb2c3062018-05-31 13:13:30 -0500382 withCredentials: true,
383 data: JSON.stringify({'data': dhcpEnabled})
384 })
385 .then(function(response) {
386 return response.data;
387 });
388 },
Gunnar Mills06467822018-06-06 15:43:18 -0500389 setNameservers: function(interfaceName, dnsServers) {
390 return $http({
391 method: 'PUT',
392 url: DataService.getHost() +
393 '/xyz/openbmc_project/network/' + interfaceName +
394 '/attr/Nameservers',
Gunnar Mills06467822018-06-06 15:43:18 -0500395 withCredentials: true,
396 data: JSON.stringify({'data': dnsServers})
397 })
398 .then(function(response) {
399 return response.data;
400 });
401 },
Gunnar Millsa45c3852018-05-30 16:18:45 -0500402 deleteIPV4: function(interfaceName, networkID) {
403 return $http({
404 method: 'POST',
405 url: DataService.getHost() +
406 '/xyz/openbmc_project/network/' + interfaceName +
407 '/ipv4/' + networkID + '/action/Delete',
Gunnar Millsa45c3852018-05-30 16:18:45 -0500408 withCredentials: true,
409 data: JSON.stringify({'data': []})
410 })
411 .then(function(response) {
412 return response.data;
413 });
414 },
415 addIPV4: function(
416 interfaceName, ipAddress, netmaskPrefixLength, gateway) {
417 return $http({
418 method: 'POST',
419 url: DataService.getHost() +
420 '/xyz/openbmc_project/network/' + interfaceName +
421 '/action/IP',
Gunnar Millsa45c3852018-05-30 16:18:45 -0500422 withCredentials: true,
423 data: JSON.stringify({
424 'data': [
425 'xyz.openbmc_project.Network.IP.Protocol.IPv4',
426 ipAddress, +netmaskPrefixLength, gateway
427 ]
428 })
429 })
430 .then(function(response) {
431 return response.data;
432 });
433 },
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700434 getLEDState: function() {
435 var deferred = $q.defer();
436 $http({
437 method: 'GET',
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700438 url: DataService.getHost() +
439 '/xyz/openbmc_project/led/groups/enclosure_identify',
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700440 withCredentials: true
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700441 })
442 .then(
443 function(response) {
444 var json = JSON.stringify(response.data);
445 var content = JSON.parse(json);
446 deferred.resolve(content.data.Asserted);
447 },
448 function(error) {
449 console.log(error);
450 deferred.reject(error);
451 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700452 return deferred.promise;
453 },
454 login: function(username, password, callback) {
455 $http({
456 method: 'POST',
457 url: DataService.getHost() + '/login',
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700458 withCredentials: true,
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700459 data: JSON.stringify({'data': [username, password]})
460 })
461 .then(
462 function(response) {
463 if (callback) {
464 callback(response.data);
465 }
466 },
467 function(error) {
468 if (callback) {
469 if (error && error.status && error.status == 'error') {
470 callback(error);
471 } else {
472 callback(error, true);
473 }
474 }
475 console.log(error);
476 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700477 },
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700478 logout: function(callback) {
479 $http({
480 method: 'POST',
481 url: DataService.getHost() + '/logout',
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700482 withCredentials: true,
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700483 data: JSON.stringify({'data': []})
484 })
485 .then(
486 function(response) {
487 if (callback) {
488 callback(response.data);
489 }
490 },
491 function(error) {
492 if (callback) {
493 callback(null, error);
494 }
495 console.log(error);
496 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700497 },
AppaRao Pulicf7219c2018-12-27 16:17:46 +0530498 getAccountServiceRoles: function() {
499 var roles = [];
500
501 if (DataService.configJson.redfishSupportEnabled == true) {
502 return $http({
503 method: 'GET',
504 url: DataService.getHost() +
505 '/redfish/v1/AccountService/Roles',
506 withCredentials: true
507 })
508 .then(
509 function(response) {
510 var members = response.data['Members'];
511 angular.forEach(members, function(member) {
512 roles.push(member['@odata.id'].split('/').pop());
513 });
514 return roles;
515 },
516 function(error) {
517 console.log(error);
518 });
519 } else {
520 return $http({
521 method: 'GET',
522 url: DataService.getHost() + '/xyz/openbmc_project/user',
523 withCredentials: true
524 })
525 .then(
526 function(response) {
527 var json = JSON.stringify(response.data);
528 var content = JSON.parse(json);
529 var privList = content.data['AllPrivileges'];
530
531 function convertPrivToRoleId(priv) {
532 if (priv == 'priv-admin') {
533 return 'Administrator';
534 } else if (priv == 'priv-user') {
535 return 'User';
536 } else if (priv == 'priv-operator') {
537 return 'Operator';
538 } else if (priv == 'priv-callback') {
539 return 'Callback';
540 }
541 return '';
542 }
543 for (var i = 0; i < privList.length; i++) {
544 roles.push(convertPrivToRoleId(privList[i]));
545 }
546 return roles;
547 },
548 function(error) {
549 console.log(error);
550 });
551 }
552 },
553 getAllUserAccounts: function() {
AppaRao Puli28711a62018-10-17 16:07:55 +0530554 var deferred = $q.defer();
555 var promises = [];
556 var users = [];
557
558 if (DataService.configJson.redfishSupportEnabled == true) {
559 $http({
560 method: 'GET',
561 url:
562 DataService.getHost() + '/redfish/v1/AccountService/Accounts',
563 withCredentials: true
564 })
565 .then(
566 function(response) {
567 var members = response.data['Members'];
568 angular.forEach(members, function(member) {
569 promises.push(
570 $http({
571 method: 'GET',
572 url: DataService.getHost() + member['@odata.id'],
573 withCredentials: true
574 }).then(function(res) {
575 return res.data;
576 }));
577 });
578
579 $q.all(promises).then(
580 function(results) {
581 deferred.resolve(results);
582 },
583 function(errors) {
584 deferred.reject(errors);
585 });
586 },
587 function(error) {
588 console.log(error);
589 deferred.reject(error);
590 });
591 } else {
592 $http({
593 method: 'GET',
594 url:
595 DataService.getHost() + '/xyz/openbmc_project/user/enumerate',
596 withCredentials: true
597 })
598 .then(
599 function(response) {
600 var json = JSON.stringify(response.data);
601 var content = JSON.parse(json);
602
603 function convertPrivToRoleId(priv) {
604 if (priv == 'priv-admin') {
605 return 'Administrator';
606 } else if (priv == 'priv-user') {
607 return 'User';
608 } else if (priv == 'priv-operator') {
609 return 'Operator';
610 } else if (priv == 'priv-callback') {
611 return 'Callback';
612 }
613 return '';
614 }
615
616 for (var key in content.data) {
617 var username = key.split('/').pop();
618 if (content.data.hasOwnProperty(key) &&
619 content.data[key].hasOwnProperty('UserPrivilege')) {
620 var val = content.data[key];
621 users.push(Object.assign({
622 Id: username,
623 UserName: username,
624 Locked: val['UserLockedForFailedAttempt'],
625 RoleId: convertPrivToRoleId(val['UserPrivilege']),
626 Enabled: val['UserEnabled'],
627 Password: null
628 }));
629 }
630 }
631 deferred.resolve(users);
632 },
633 function(error) {
634 console.log(error);
635 deferred.reject(error);
636 });
637 }
638 return deferred.promise;
639 },
640 createUser: function(user, passwd, role, enabled) {
641 if (DataService.configJson.redfishSupportEnabled == true) {
642 var data = {};
643 data['UserName'] = user;
644 data['Password'] = passwd;
645 data['RoleId'] = role;
646 data['Enabled'] = enabled;
647
648 return $http({
649 method: 'POST',
650 url:
651 DataService.getHost() + '/redfish/v1/AccountService/Accounts',
652 withCredentials: true,
653 data: data
654 });
655 } else {
656 function convertRoleIdToPriv(roleId) {
657 if (roleId == 'Administrator') {
658 return 'priv-admin';
659 } else if (roleId == 'User') {
660 return 'priv-user';
661 } else if (roleId == 'Operator') {
662 return 'priv-operator';
663 } else if (roleId == 'Callback') {
664 return 'priv-callback';
665 }
666 return '';
667 }
668 function setUserPassword(user, passwd) {
669 return $http({
670 method: 'POST',
671 url: DataService.getHost() +
672 '/xyz/openbmc_project/user/' + user +
673 '/action/SetPassword',
674 withCredentials: true,
675 data: JSON.stringify({'data': [passwd]}),
676 responseType: 'arraybuffer'
677 })
678 .then(function(response) {
679 return response.data;
680 });
681 }
682 var priv = convertRoleIdToPriv(role);
683 return $http({
684 method: 'POST',
685 url: DataService.getHost() +
686 '/xyz/openbmc_project/user/action/CreateUser',
687 withCredentials: true,
688 data: JSON.stringify({
689 'data':
690 [user, ['web', 'redfish', 'ssh'], priv, enabled]
691 }),
692 responseType: 'arraybuffer'
693 })
694 .then(function(response) {
695 return setUserPassword(user, passwd);
696 });
697 }
698 },
699 updateUser: function(user, newUser, passwd, role, enabled) {
700 if (DataService.configJson.redfishSupportEnabled == true) {
701 var data = {};
702 if ((newUser !== undefined) && (newUser != null)) {
703 data['UserName'] = newUser;
704 }
705 if ((role !== undefined) && (role != null)) {
706 data['RoleId'] = role;
707 }
708 if ((enabled !== undefined) && (enabled != null)) {
709 data['Enabled'] = enabled;
710 }
711 if ((passwd !== undefined) && (passwd != null)) {
712 data['Password'] = passwd;
713 }
714 return $http({
715 method: 'PATCH',
716 url: DataService.getHost() +
717 '/redfish/v1/AccountService/Accounts/' + user,
718 withCredentials: true,
719 data: data
720 });
721 } else {
722 var deferred = $q.defer();
723 var promises = [];
724 function convertRoleIdToPriv(roleId) {
725 if (roleId == 'Administrator') {
726 return 'priv-admin';
727 } else if (roleId == 'User') {
728 return 'priv-user';
729 } else if (roleId == 'Operator') {
730 return 'priv-operator';
731 } else if (roleId == 'Callback') {
732 return 'priv-callback';
733 }
734 return '';
735 }
736 function setUserProperty(user, propKey, propVal) {
737 return $http({
738 method: 'PUT',
739 url: DataService.getHost() +
740 '/xyz/openbmc_project/user/' + user + '/attr/' +
741 propKey,
742 withCredentials: true,
743 data: JSON.stringify({'data': propVal})
744 })
745 .then(function(response) {
746 return response.data;
747 });
748 }
749 function setUserPassword(user, passwd) {
750 return $http({
751 method: 'POST',
752 url: DataService.getHost() +
753 '/xyz/openbmc_project/user/' + user +
754 '/action/SetPassword',
755 withCredentials: true,
756 data: JSON.stringify({'data': [passwd]}),
757 responseType: 'arraybuffer'
758 })
759 .then(function(response) {
760 return response.data;
761 });
762 }
763 function renameUser(user, newUser) {
764 return $http({
765 method: 'POST',
766 url: DataService.getHost() +
767 '/xyz/openbmc_project/user/action/RenameUser',
768 withCredentials: true,
769 data: JSON.stringify({'data': [user, newUser]})
770 })
771 .then(function(response) {
772 return response.data;
773 });
774 }
775 if ((role !== undefined) && (role != null)) {
776 var priv = convertRoleIdToPriv(role);
777 promises.push(setUserProperty(user, 'UserPrivilege', priv));
778 }
779 if ((enabled !== undefined) && (enabled != null)) {
780 promises.push(setUserProperty(user, 'UserEnabled', enabled));
781 }
782 if ((passwd !== undefined) && (passwd != null)) {
783 promises.push(setUserPassword(user, passwd));
784 }
785 if ((newUser !== undefined) && (newUser != null)) {
786 promises.push(renameUser(user, newUser));
787 }
788 $q.all(promises).then(
789 function(results) {
790 deferred.resolve(results);
791 },
792 function(errors) {
793 deferred.reject(errors);
794 });
795 return deferred.promise;
796 }
797 },
798 deleteUser: function(user) {
799 if (DataService.configJson.redfishSupportEnabled == true) {
800 return $http({
801 method: 'DELETE',
802 url: DataService.getHost() +
803 '/redfish/v1/AccountService/Accounts/' + user,
804 withCredentials: true,
805 });
806 } else {
807 return $http({
808 method: 'POST',
809 url: DataService.getHost() + '/xyz/openbmc_project/user/' +
810 user + '/action/Delete',
811 withCredentials: true,
812 data: JSON.stringify({'data': []})
813 })
814 .then(function(response) {
815 return response.data;
816 });
817 }
818 },
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700819 chassisPowerOff: function() {
820 var deferred = $q.defer();
821 $http({
822 method: 'PUT',
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700823 url: DataService.getHost() +
824 '/xyz/openbmc_project/state/chassis0/attr/RequestedPowerTransition',
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700825 withCredentials: true,
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700826 data: JSON.stringify(
827 {'data': 'xyz.openbmc_project.State.Chassis.Transition.Off'})
828 })
829 .then(
830 function(response) {
831 var json = JSON.stringify(response.data);
832 var content = JSON.parse(json);
833 deferred.resolve(content.status);
834 },
835 function(error) {
836 console.log(error);
837 deferred.reject(error);
838 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700839 return deferred.promise;
840 },
beccabroekb7f0ee12019-01-10 11:15:58 -0600841 setLEDState: function(state) {
842 return $http({
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700843 method: 'PUT',
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700844 url: DataService.getHost() +
845 '/xyz/openbmc_project/led/groups/enclosure_identify/attr/Asserted',
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700846 withCredentials: true,
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700847 data: JSON.stringify({'data': state})
848 })
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700849 },
850 bmcReboot: function(callback) {
851 $http({
852 method: 'PUT',
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700853 url: DataService.getHost() +
Gunnar Mills70086982019-01-04 15:10:04 -0600854 '/xyz/openbmc_project/state/bmc0/attr/RequestedBMCTransition',
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700855 withCredentials: true,
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700856 data: JSON.stringify(
857 {'data': 'xyz.openbmc_project.State.BMC.Transition.Reboot'})
858 })
859 .then(
860 function(response) {
861 var json = JSON.stringify(response.data);
862 var content = JSON.parse(json);
863 if (callback) {
864 return callback(content.status);
865 }
866 },
867 function(error) {
868 if (callback) {
869 callback(error);
870 } else {
871 console.log(error);
872 }
873 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700874 },
beccabroekbfc99902018-07-24 15:36:33 -0500875 getLastRebootTime: function() {
876 return $http({
877 method: 'GET',
878 url: DataService.getHost() +
879 '/xyz/openbmc_project/state/bmc0/attr/LastRebootTime',
beccabroekbfc99902018-07-24 15:36:33 -0500880 withCredentials: true
881 })
882 .then(function(response) {
883 return response.data;
884 });
885 },
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700886 hostPowerOn: function() {
887 var deferred = $q.defer();
888 $http({
889 method: 'PUT',
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700890 url: DataService.getHost() +
891 '/xyz/openbmc_project/state/host0/attr/RequestedHostTransition',
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700892 withCredentials: true,
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700893 data: JSON.stringify(
894 {'data': 'xyz.openbmc_project.State.Host.Transition.On'})
895 })
896 .then(
897 function(response) {
898 var json = JSON.stringify(response.data);
899 var content = JSON.parse(json);
900 deferred.resolve(content.status);
901 },
902 function(error) {
903 console.log(error);
904 deferred.reject(error);
905 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700906 return deferred.promise;
907 },
908 hostPowerOff: function() {
909 var deferred = $q.defer();
910 $http({
911 method: 'PUT',
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700912 url: DataService.getHost() +
913 '/xyz/openbmc_project/state/host0/attr/RequestedHostTransition',
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700914 withCredentials: true,
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700915 data: JSON.stringify(
916 {'data': 'xyz.openbmc_project.State.Host.Transition.Off'})
917 })
918 .then(
919 function(response) {
920 var json = JSON.stringify(response.data);
921 var content = JSON.parse(json);
922 deferred.resolve(content.status);
923 },
924 function(error) {
925 console.log(error);
926 deferred.reject(error);
927 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700928 return deferred.promise;
929 },
930 hostReboot: function() {
931 var deferred = $q.defer();
932 $http({
933 method: 'PUT',
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700934 url: DataService.getHost() +
935 '/xyz/openbmc_project/state/host0/attr/RequestedHostTransition',
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700936 withCredentials: true,
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700937 data: JSON.stringify(
938 {'data': 'xyz.openbmc_project.State.Host.Transition.Reboot'})
939 })
940 .then(
941 function(response) {
942 var json = JSON.stringify(response.data);
943 var content = JSON.parse(json);
944 deferred.resolve(content.status);
945 },
946 function(error) {
947 console.log(error);
948 deferred.reject(error);
949 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700950
951 return deferred.promise;
952 },
953 hostShutdown: function(callback) {
954 $http({
955 method: 'POST',
956 url: DataService.getHost() + '/xyz/openbmc_project/state/host0',
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700957 withCredentials: true,
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700958 data: JSON.stringify({'data': []})
959 })
960 .then(
961 function(response) {
962 var json = JSON.stringify(response.data);
963 var content = JSON.parse(json);
964 if (callback) {
965 return callback(content);
966 }
967 },
968 function(error) {
969 if (callback) {
970 callback(error);
971 } else {
972 console.log(error);
973 }
974 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700975 },
beccabroek56744252018-08-03 11:25:11 -0500976 getLastPowerTime: function() {
977 return $http({
978 method: 'GET',
979 url: DataService.getHost() +
980 '/xyz/openbmc_project/state/chassis0/attr/LastStateChangeTime',
beccabroek56744252018-08-03 11:25:11 -0500981 withCredentials: true
982 })
983 .then(function(response) {
984 return response.data;
985 });
986 },
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700987 getLogs: function() {
988 var deferred = $q.defer();
989 $http({
990 method: 'GET',
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700991 url: DataService.getHost() +
992 '/xyz/openbmc_project/logging/enumerate',
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700993 withCredentials: true
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700994 })
995 .then(
996 function(response) {
997 var json = JSON.stringify(response.data);
998 var content = JSON.parse(json);
999 var dataClone = JSON.parse(JSON.stringify(content.data));
1000 var data = [];
1001 var severityCode = '';
1002 var priority = '';
1003 var health = '';
1004 var relatedItems = [];
Matt Spinler845acdc2018-05-01 16:41:28 -05001005 var eventID = 'None';
1006 var description = 'None';
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001007
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001008 for (var key in content.data) {
1009 if (content.data.hasOwnProperty(key) &&
1010 content.data[key].hasOwnProperty('Id')) {
1011 var severityFlags = {
1012 low: false,
1013 medium: false,
1014 high: false
1015 };
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001016 severityCode =
1017 content.data[key].Severity.split('.').pop();
1018 priority =
1019 Constants.SEVERITY_TO_PRIORITY_MAP[severityCode];
1020 severityFlags[priority.toLowerCase()] = true;
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001021 relatedItems = [];
1022 content.data[key].associations.forEach(function(item) {
1023 relatedItems.push(item[2]);
1024 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001025
Matt Spinler845acdc2018-05-01 16:41:28 -05001026 if (content.data[key].hasOwnProperty(['EventID'])) {
1027 eventID = content.data[key].EventID;
1028 }
1029
1030 if (content.data[key].hasOwnProperty(['Description'])) {
1031 description = content.data[key].Description;
1032 }
1033
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001034 data.push(Object.assign(
1035 {
1036 path: key,
1037 copied: false,
1038 priority: priority,
1039 severity_code: severityCode,
1040 severity_flags: severityFlags,
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001041 additional_data:
1042 content.data[key].AdditionalData.join('\n'),
1043 type: content.data[key].Message,
1044 selected: false,
1045 search_text:
1046 ('#' + content.data[key].Id + ' ' +
1047 severityCode + ' ' +
Gunnar Mills07876ff2018-06-28 15:21:22 -05001048 content.data[key].Message + ' ' +
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001049 content.data[key].Severity + ' ' +
1050 content.data[key].AdditionalData.join(' '))
1051 .toLowerCase(),
1052 meta: false,
1053 confirm: false,
1054 related_items: relatedItems,
Matt Spinler845acdc2018-05-01 16:41:28 -05001055 eventID: eventID,
1056 description: description,
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001057 data: {key: key, value: content.data[key]}
1058 },
1059 content.data[key]));
1060 }
1061 }
1062 deferred.resolve({data: data, original: dataClone});
1063 },
1064 function(error) {
1065 console.log(error);
1066 deferred.reject(error);
1067 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001068
1069 return deferred.promise;
1070 },
1071 getAllSensorStatus: function(callback) {
1072 $http({
1073 method: 'GET',
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001074 url: DataService.getHost() +
1075 '/xyz/openbmc_project/sensors/enumerate',
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001076 withCredentials: true
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001077 })
1078 .then(
1079 function(response) {
1080 var json = JSON.stringify(response.data);
1081 var content = JSON.parse(json);
1082 var dataClone = JSON.parse(JSON.stringify(content.data));
1083 var sensorData = [];
1084 var severity = {};
1085 var title = '';
1086 var tempKeyParts = [];
1087 var order = 0;
1088 var customOrder = 0;
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001089
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001090 function getSensorStatus(reading) {
1091 var severityFlags = {
1092 critical: false,
1093 warning: false,
1094 normal: false
1095 },
1096 severityText = '', order = 0;
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001097
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001098 if (reading.hasOwnProperty('CriticalLow') &&
1099 reading.Value < reading.CriticalLow) {
1100 severityFlags.critical = true;
1101 severityText = 'critical';
1102 order = 2;
1103 } else if (
1104 reading.hasOwnProperty('CriticalHigh') &&
1105 reading.Value > reading.CriticalHigh) {
1106 severityFlags.critical = true;
1107 severityText = 'critical';
1108 order = 2;
1109 } else if (
1110 reading.hasOwnProperty('CriticalLow') &&
1111 reading.hasOwnProperty('WarningLow') &&
1112 reading.Value >= reading.CriticalLow &&
1113 reading.Value <= reading.WarningLow) {
1114 severityFlags.warning = true;
1115 severityText = 'warning';
1116 order = 1;
1117 } else if (
1118 reading.hasOwnProperty('WarningHigh') &&
1119 reading.hasOwnProperty('CriticalHigh') &&
1120 reading.Value >= reading.WarningHigh &&
1121 reading.Value <= reading.CriticalHigh) {
1122 severityFlags.warning = true;
1123 severityText = 'warning';
1124 order = 1;
1125 } else {
1126 severityFlags.normal = true;
1127 severityText = 'normal';
1128 }
1129 return {
1130 flags: severityFlags,
1131 severityText: severityText,
1132 order: order
1133 };
1134 }
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001135
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001136 for (var key in content.data) {
1137 if (content.data.hasOwnProperty(key) &&
1138 content.data[key].hasOwnProperty('Unit')) {
1139 severity = getSensorStatus(content.data[key]);
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001140
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001141 if (!content.data[key].hasOwnProperty('CriticalLow')) {
1142 content.data[key].CriticalLow = '--';
1143 content.data[key].CriticalHigh = '--';
1144 }
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001145
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001146 if (!content.data[key].hasOwnProperty('WarningLow')) {
1147 content.data[key].WarningLow = '--';
1148 content.data[key].WarningHigh = '--';
1149 }
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001150
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001151 tempKeyParts = key.split('/');
1152 title = tempKeyParts.pop();
1153 title = tempKeyParts.pop() + '_' + title;
1154 title = title.split('_')
1155 .map(function(item) {
1156 return item.toLowerCase()
1157 .charAt(0)
1158 .toUpperCase() +
1159 item.slice(1);
1160 })
1161 .reduce(function(prev, el) {
1162 return prev + ' ' + el;
1163 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001164
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001165 content.data[key].Value = getScaledValue(
1166 content.data[key].Value, content.data[key].Scale);
1167 content.data[key].CriticalLow = getScaledValue(
1168 content.data[key].CriticalLow,
1169 content.data[key].Scale);
1170 content.data[key].CriticalHigh = getScaledValue(
1171 content.data[key].CriticalHigh,
1172 content.data[key].Scale);
1173 content.data[key].WarningLow = getScaledValue(
1174 content.data[key].WarningLow,
1175 content.data[key].Scale);
1176 content.data[key].WarningHigh = getScaledValue(
1177 content.data[key].WarningHigh,
1178 content.data[key].Scale);
1179 if (Constants.SENSOR_SORT_ORDER.indexOf(
1180 content.data[key].Unit) > -1) {
1181 customOrder = Constants.SENSOR_SORT_ORDER.indexOf(
1182 content.data[key].Unit);
1183 } else {
1184 customOrder = Constants.SENSOR_SORT_ORDER_DEFAULT;
1185 }
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001186
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001187 sensorData.push(Object.assign(
1188 {
1189 path: key,
1190 selected: false,
1191 confirm: false,
1192 copied: false,
1193 title: title,
1194 unit:
1195 Constants
1196 .SENSOR_UNIT_MAP[content.data[key].Unit],
1197 severity_flags: severity.flags,
1198 status: severity.severityText,
1199 order: severity.order,
1200 custom_order: customOrder,
1201 search_text:
1202 (title + ' ' + content.data[key].Value + ' ' +
1203 Constants.SENSOR_UNIT_MAP[content.data[key]
1204 .Unit] +
1205 ' ' + severity.severityText + ' ' +
1206 content.data[key].CriticalLow + ' ' +
1207 content.data[key].CriticalHigh + ' ' +
1208 content.data[key].WarningLow + ' ' +
1209 content.data[key].WarningHigh + ' ')
1210 .toLowerCase(),
1211 original_data:
1212 {key: key, value: content.data[key]}
1213 },
1214 content.data[key]));
1215 }
1216 }
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001217
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001218 callback(sensorData, dataClone);
1219 },
1220 function(error) {
1221 console.log(error);
1222 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001223 },
1224 getActivation: function(imageId) {
1225 return $http({
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001226 method: 'GET',
1227 url: DataService.getHost() +
1228 '/xyz/openbmc_project/software/' + imageId +
1229 '/attr/Activation',
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001230 withCredentials: true
1231 })
1232 .then(function(response) {
1233 return response.data;
1234 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001235 },
1236 getFirmwares: function() {
1237 var deferred = $q.defer();
1238 $http({
1239 method: 'GET',
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001240 url: DataService.getHost() +
1241 '/xyz/openbmc_project/software/enumerate',
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001242 withCredentials: true
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001243 })
1244 .then(
1245 function(response) {
1246 var json = JSON.stringify(response.data);
1247 var content = JSON.parse(json);
1248 var data = [];
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001249 var isExtended = false;
1250 var bmcActiveVersion = '';
1251 var hostActiveVersion = '';
1252 var imageType = '';
1253 var extendedVersions = [];
1254 var functionalImages = [];
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001255
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001256 function getFormatedExtendedVersions(extendedVersion) {
1257 var versions = [];
1258 extendedVersion = extendedVersion.split(',');
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001259
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001260 extendedVersion.forEach(function(item) {
1261 var parts = item.split('-');
1262 var numberIndex = 0;
1263 for (var i = 0; i < parts.length; i++) {
1264 if (/[0-9]/.test(parts[i])) {
1265 numberIndex = i;
1266 break;
1267 }
1268 }
1269 var titlePart = parts.splice(0, numberIndex);
1270 titlePart = titlePart.join('');
1271 titlePart = titlePart[0].toUpperCase() +
1272 titlePart.substr(1, titlePart.length);
1273 var versionPart = parts.join('-');
1274 versions.push({title: titlePart, version: versionPart});
1275 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001276
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001277 return versions;
1278 }
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001279
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001280 // Get the list of functional images so we can compare
1281 // later if an image is functional
1282 if (content.data[Constants.FIRMWARE.FUNCTIONAL_OBJPATH]) {
1283 functionalImages =
1284 content.data[Constants.FIRMWARE.FUNCTIONAL_OBJPATH]
1285 .endpoints;
1286 }
1287 for (var key in content.data) {
1288 if (content.data.hasOwnProperty(key) &&
1289 content.data[key].hasOwnProperty('Version')) {
Gunnar Millsac9131e2018-07-13 15:52:18 -05001290 var activationStatus = '';
1291
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001292 // If the image is "Functional" use that for the
AppaRao Puli28711a62018-10-17 16:07:55 +05301293 // activation status, else use the value of
1294 // "Activation"
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001295 // github.com/openbmc/phosphor-dbus-interfaces/blob/master/xyz/openbmc_project/Software/Activation.interface.yaml
Gunnar Millsac9131e2018-07-13 15:52:18 -05001296 if (content.data[key].Activation) {
1297 activationStatus =
1298 content.data[key].Activation.split('.').pop();
1299 }
1300
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001301 if (functionalImages.includes(key)) {
1302 activationStatus = 'Functional';
1303 }
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001304
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001305 imageType = content.data[key].Purpose.split('.').pop();
1306 isExtended = content.data[key].hasOwnProperty(
1307 'ExtendedVersion') &&
1308 content.data[key].ExtendedVersion != '';
1309 if (isExtended) {
1310 extendedVersions = getFormatedExtendedVersions(
1311 content.data[key].ExtendedVersion);
1312 }
1313 data.push(Object.assign(
1314 {
1315 path: key,
1316 activationStatus: activationStatus,
1317 imageId: key.split('/').pop(),
1318 imageType: imageType,
1319 isExtended: isExtended,
1320 extended:
1321 {show: false, versions: extendedVersions},
1322 data: {key: key, value: content.data[key]}
1323 },
1324 content.data[key]));
1325
1326 if (activationStatus == 'Functional' &&
1327 imageType == 'BMC') {
1328 bmcActiveVersion = content.data[key].Version;
1329 }
1330
1331 if (activationStatus == 'Functional' &&
1332 imageType == 'Host') {
1333 hostActiveVersion = content.data[key].Version;
1334 }
1335 }
1336 }
1337
1338 deferred.resolve({
1339 data: data,
1340 bmcActiveVersion: bmcActiveVersion,
1341 hostActiveVersion: hostActiveVersion
1342 });
Iftekharul Islam171c6a12017-08-11 08:35:47 -05001343 },
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001344 function(error) {
1345 console.log(error);
1346 deferred.reject(error);
1347 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001348
1349 return deferred.promise;
1350 },
1351 changePriority: function(imageId, priority) {
Gunnar Millsf7f59462018-09-20 16:02:08 -05001352 return $http({
1353 method: 'PUT',
1354 url: DataService.getHost() +
1355 '/xyz/openbmc_project/software/' + imageId +
1356 '/attr/Priority',
1357 withCredentials: true,
1358 data: JSON.stringify({'data': priority})
1359 })
1360 .then(function(response) {
1361 return response.data;
1362 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001363 },
1364 deleteImage: function(imageId) {
Gunnar Millsf7f59462018-09-20 16:02:08 -05001365 return $http({
1366 method: 'POST',
1367 url: DataService.getHost() +
1368 '/xyz/openbmc_project/software/' + imageId +
1369 '/action/Delete',
1370 withCredentials: true,
1371 data: JSON.stringify({'data': []})
1372 })
1373 .then(function(response) {
1374 return response.data;
1375 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001376 },
1377 activateImage: function(imageId) {
Gunnar Millsf7f59462018-09-20 16:02:08 -05001378 return $http({
1379 method: 'PUT',
1380 url: DataService.getHost() +
1381 '/xyz/openbmc_project/software/' + imageId +
1382 '/attr/RequestedActivation',
1383 withCredentials: true,
1384 data: JSON.stringify(
1385 {'data': Constants.FIRMWARE.ACTIVATE_FIRMWARE})
1386 })
1387 .then(function(response) {
1388 return response.data;
1389 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001390 },
1391 uploadImage: function(file) {
1392 return $http({
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001393 method: 'POST',
1394 timeout: 5 * 60 * 1000,
1395 url: DataService.getHost() + '/upload/image',
Gunnar Millsdd9d4c32018-09-10 12:59:34 -05001396 // Overwrite the default 'application/json' Content-Type
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001397 headers: {'Content-Type': 'application/octet-stream'},
1398 withCredentials: true,
1399 data: file
1400 })
1401 .then(function(response) {
1402 return response.data;
1403 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001404 },
1405 downloadImage: function(host, filename) {
1406 return $http({
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001407 method: 'POST',
1408 url: DataService.getHost() +
1409 '/xyz/openbmc_project/software/action/DownloadViaTFTP',
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001410 withCredentials: true,
1411 data: JSON.stringify({'data': [filename, host]}),
1412 responseType: 'arraybuffer'
1413 })
1414 .then(function(response) {
1415 return response.data;
1416 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001417 },
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001418 getServerInfo: function() {
1419 // TODO: openbmc/openbmc#3117 Need a way via REST to get
1420 // interfaces so we can get the system object(s) by the looking
1421 // for the system interface.
1422 return $http({
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001423 method: 'GET',
1424 url: DataService.getHost() +
1425 '/xyz/openbmc_project/inventory/system',
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001426 withCredentials: true
1427 })
1428 .then(function(response) {
1429 return response.data;
1430 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001431 },
1432 getBMCTime: function() {
1433 return $http({
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001434 method: 'GET',
1435 url: DataService.getHost() + '/xyz/openbmc_project/time/bmc',
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001436 withCredentials: true
1437 })
1438 .then(function(response) {
1439 return response.data;
1440 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001441 },
Gunnar Millsc74d4342018-07-18 14:52:02 -05001442 getTime: function() {
1443 return $http({
1444 method: 'GET',
1445 url: DataService.getHost() +
1446 '/xyz/openbmc_project/time/enumerate',
Gunnar Millsc74d4342018-07-18 14:52:02 -05001447 withCredentials: true
1448 })
1449 .then(function(response) {
1450 return response.data;
1451 });
1452 },
Gunnar Millsb7ea2792018-07-18 13:01:48 -05001453 // Even though NTPServers is a network interface specific path
1454 // (e.g. /xyz/openbmc_project/network/eth0/attr/NTPServers) it acts
1455 // like a global setting. Just use eth0 for setting and getting the
1456 // NTP Servers until it is moved to a non-network interface specific
1457 // path like it is in Redfish. TODO: openbmc/phosphor-time-manager#4
1458 getNTPServers: function() {
1459 return $http({
1460 method: 'GET',
1461 url: DataService.getHost() +
1462 '/xyz/openbmc_project/network/eth0/attr/NTPServers',
Gunnar Millsb7ea2792018-07-18 13:01:48 -05001463 withCredentials: true
1464 })
1465 .then(function(response) {
1466 return response.data;
1467 });
1468 },
1469 setNTPServers: function(ntpServers) {
1470 return $http({
1471 method: 'PUT',
1472 url: DataService.getHost() +
1473 '/xyz/openbmc_project/network/eth0/attr/NTPServers',
Gunnar Millsb7ea2792018-07-18 13:01:48 -05001474 withCredentials: true,
1475 data: JSON.stringify({'data': ntpServers})
1476 })
1477 .then(function(response) {
1478 return response.data;
1479 });
1480 },
1481 setTimeMode: function(timeMode) {
1482 return $http({
1483 method: 'PUT',
1484 url: DataService.getHost() +
1485 '/xyz/openbmc_project/time/sync_method/attr/TimeSyncMethod',
Gunnar Millsb7ea2792018-07-18 13:01:48 -05001486 withCredentials: true,
1487 data: JSON.stringify({'data': timeMode})
1488 })
1489 .then(function(response) {
1490 return response.data;
1491 });
1492 },
1493 setTimeOwner: function(timeOwner) {
1494 return $http({
1495 method: 'PUT',
1496 url: DataService.getHost() +
1497 '/xyz/openbmc_project/time/owner/attr/TimeOwner',
Gunnar Millsb7ea2792018-07-18 13:01:48 -05001498 withCredentials: true,
1499 data: JSON.stringify({'data': timeOwner})
1500 })
1501 .then(function(response) {
1502 return response.data;
1503 });
1504 },
1505 setBMCTime: function(time) {
1506 return $http({
1507 method: 'PUT',
1508 url: DataService.getHost() +
1509 '/xyz/openbmc_project/time/bmc/attr/Elapsed',
Gunnar Millsb7ea2792018-07-18 13:01:48 -05001510 withCredentials: true,
1511 data: JSON.stringify({'data': time})
1512 })
1513 .then(function(response) {
1514 return response.data;
1515 });
1516 },
1517 setHostTime: function(time) {
1518 return $http({
1519 method: 'PUT',
1520 url: DataService.getHost() +
1521 '/xyz/openbmc_project/time/host/attr/Elapsed',
Gunnar Millsb7ea2792018-07-18 13:01:48 -05001522 withCredentials: true,
1523 data: JSON.stringify({'data': time})
1524 })
1525 .then(function(response) {
1526 return response.data;
1527 });
1528 },
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001529 getHardwares: function(callback) {
1530 $http({
1531 method: 'GET',
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001532 url: DataService.getHost() +
1533 '/xyz/openbmc_project/inventory/enumerate',
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001534 withCredentials: true
1535 }).then(function(response) {
1536 var json = JSON.stringify(response.data);
1537 var content = JSON.parse(json);
1538 var hardwareData = [];
1539 var keyIndexMap = {};
1540 var title = '';
beccabroek628ba8b2018-10-01 14:12:25 -05001541 var depth = '';
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001542 var data = [];
1543 var searchText = '';
1544 var componentIndex = -1;
beccabroek628ba8b2018-10-01 14:12:25 -05001545 var parent = '';
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001546
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001547 function isSubComponent(key) {
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001548 for (var i = 0; i < Constants.HARDWARE.parent_components.length;
1549 i++) {
1550 if (key.split(Constants.HARDWARE.parent_components[i]).length ==
1551 2)
1552 return true;
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001553 }
1554
1555 return false;
1556 }
1557
1558 function titlelize(title) {
1559 title = title.replace(/([A-Z0-9]+)/g, ' $1').replace(/^\s+/, '');
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001560 for (var i = 0; i < Constants.HARDWARE.uppercase_titles.length;
1561 i++) {
1562 if (title.toLowerCase().indexOf(
1563 (Constants.HARDWARE.uppercase_titles[i] + ' ')) > -1) {
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001564 return title.toUpperCase();
1565 }
1566 }
1567
1568 return title;
1569 }
1570
1571 function camelcaseToLabel(obj) {
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001572 var transformed = [], label = '', value = '';
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001573 for (var key in obj) {
1574 label = key.replace(/([A-Z0-9]+)/g, ' $1').replace(/^\s+/, '');
1575 if (obj[key] !== '') {
1576 value = obj[key];
1577 if (value == 1 || value == 0) {
1578 value = (value == 1) ? 'Yes' : 'No';
1579 }
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001580 transformed.push({key: label, value: value});
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001581 }
1582 }
1583
1584 return transformed;
1585 }
1586
beccabroek628ba8b2018-10-01 14:12:25 -05001587 function determineParent(key) {
1588 var levels = key.split('/');
1589 levels.pop();
1590 return levels.join('/');
1591 }
1592
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001593 function getSearchText(data) {
1594 var searchText = '';
1595 for (var i = 0; i < data.length; i++) {
1596 searchText += ' ' + data[i].key + ' ' + data[i].value;
1597 }
1598
1599 return searchText;
1600 }
1601
1602 for (var key in content.data) {
1603 if (content.data.hasOwnProperty(key) &&
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001604 key.indexOf(Constants.HARDWARE.component_key_filter) == 0) {
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001605 data = camelcaseToLabel(content.data[key]);
1606 searchText = getSearchText(data);
1607 title = key.split('/').pop();
Gunnar Millseedf0b92019-02-27 10:52:01 -06001608 // All and only associations have the property "endpoints".
1609 // We don't want to show associations on the hardware page.
1610 // Example: An association from the BMC inventory item to the
1611 // BMC firmware images.
1612 if (content.data[key].hasOwnProperty('endpoints')) {
1613 continue;
1614 }
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001615
1616 title = titlelize(title);
beccabroek628ba8b2018-10-01 14:12:25 -05001617 // e.g. /xyz/openbmc_project/inventory/system and
1618 // /xyz/openbmc_project/inventory/system/chassis are depths of 5
1619 // and 6.
1620 depth = key.split('/').length;
1621 parent = determineParent(key);
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001622
1623 if (!isSubComponent(key)) {
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001624 hardwareData.push(Object.assign(
1625 {
1626 path: key,
1627 title: title,
beccabroek628ba8b2018-10-01 14:12:25 -05001628 depth: depth,
1629 parent: parent,
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001630 selected: false,
1631 expanded: false,
1632 search_text: title.toLowerCase() + ' ' +
1633 searchText.toLowerCase(),
1634 sub_components: [],
1635 original_data: {key: key, value: content.data[key]}
1636 },
1637 {items: data}));
Iftekharul Islam2a489552017-11-02 13:23:08 -05001638
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001639 keyIndexMap[key] = hardwareData.length - 1;
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001640 } else {
beccabroek628ba8b2018-10-01 14:12:25 -05001641 parent = determineParent(key)
1642 componentIndex = keyIndexMap[parent];
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001643 data = content.data[key];
1644 data.title = title;
1645 hardwareData[componentIndex].sub_components.push(data);
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001646 hardwareData[componentIndex].search_text +=
1647 ' ' + title.toLowerCase();
Iftekharul Islam171c6a12017-08-11 08:35:47 -05001648
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001649 // Sort the subcomponents alphanumeric so they are displayed
1650 // on the inventory page in order (e.g. core 0, core 1, core
1651 // 2, ... core 12, core 13)
1652 hardwareData[componentIndex].sub_components.sort(function(
1653 a, b) {
1654 return a.title.localeCompare(
1655 b.title, 'en', {numeric: true});
Gunnar Mills55a8e392018-03-14 15:37:44 -05001656 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001657 }
1658 }
1659 }
beccabroek628ba8b2018-10-01 14:12:25 -05001660 // First, order the components by depth and then place the child
1661 // components beneath their parent component alphanumerically. Can
1662 // be removed with completion of
1663 // https://github.com/openbmc/openbmc/issues/3401
1664 // TODO: Remove this once implemented in back end
1665 hardwareData.sort(function(a, b) {
1666 if (a.depth < b.depth) return -1;
1667 if (a.depth > b.depth) return 1;
1668 return b.title.localeCompare(a.title, 'en', {numeric: true});
1669 });
1670
1671 var orderedComponents = [];
1672
1673 for (var i = 0; i < hardwareData.length; i++) {
1674 if (!keyIndexMap[hardwareData[i].parent]) {
1675 orderedComponents.push(hardwareData[i]);
1676 } else {
1677 for (var j = 0; j < orderedComponents.length; j++) {
1678 if (orderedComponents[j].path === hardwareData[i].parent) {
1679 var child = hardwareData[i];
1680 orderedComponents.splice(j + 1, 0, child);
1681 }
1682 }
1683 }
1684 }
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001685
1686 if (callback) {
beccabroek628ba8b2018-10-01 14:12:25 -05001687 callback(orderedComponents, content.data);
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001688 } else {
beccabroek628ba8b2018-10-01 14:12:25 -05001689 return {data: orderedComponents, original_data: content.data};
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001690 }
1691 });
1692 },
1693 deleteLogs: function(logs) {
1694 var defer = $q.defer();
1695 var promises = [];
1696
1697 function finished() {
1698 defer.resolve();
1699 }
1700
1701 logs.forEach(function(item) {
1702 promises.push($http({
1703 method: 'POST',
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001704 url: DataService.getHost() +
1705 '/xyz/openbmc_project/logging/entry/' + item.Id +
1706 '/action/Delete',
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001707 withCredentials: true,
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001708 data: JSON.stringify({'data': []})
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001709 }));
1710 });
1711
1712 $q.all(promises).then(finished);
1713
1714 return defer.promise;
1715 },
1716 resolveLogs: function(logs) {
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001717 var promises = [];
1718
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001719 logs.forEach(function(item) {
1720 promises.push($http({
1721 method: 'PUT',
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001722 url: DataService.getHost() +
1723 '/xyz/openbmc_project/logging/entry/' + item.Id +
1724 '/attr/Resolved',
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001725 withCredentials: true,
Gunnar Mills7e48d082019-01-23 16:02:03 -06001726 data: JSON.stringify({'data': true})
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001727 }));
1728 });
Gunnar Mills7e48d082019-01-23 16:02:03 -06001729 return $q.all(promises);
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001730 },
1731 getPowerConsumption: function() {
1732 return $http({
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001733 method: 'GET',
1734 url: DataService.getHost() +
1735 '/xyz/openbmc_project/sensors/power/total_power',
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001736 withCredentials: true
1737 })
1738 .then(
1739 function(response) {
1740 var json = JSON.stringify(response.data);
1741 var content = JSON.parse(json);
Iftekharul Islamcd789502017-04-19 14:37:55 -05001742
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001743 return getScaledValue(
1744 content.data.Value, content.data.Scale) +
1745 ' ' +
1746 Constants.POWER_CONSUMPTION_TEXT[content.data.Unit];
1747 },
1748 function(error) {
1749 if ('Not Found' == error.statusText) {
1750 return Constants.POWER_CONSUMPTION_TEXT.notavailable;
1751 } else {
1752 throw error;
1753 }
1754 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001755 },
1756 getPowerCap: function() {
1757 return $http({
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001758 method: 'GET',
1759 url: DataService.getHost() +
1760 '/xyz/openbmc_project/control/host0/power_cap',
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001761 withCredentials: true
1762 })
1763 .then(function(response) {
Gunnar Mills006aaa02018-06-26 16:08:59 -05001764 return response.data;
1765 });
1766 },
1767 setPowerCapEnable: function(powerCapEnable) {
1768 return $http({
1769 method: 'PUT',
1770 url: DataService.getHost() +
1771 '/xyz/openbmc_project/control/host0/power_cap/attr/PowerCapEnable',
Gunnar Mills006aaa02018-06-26 16:08:59 -05001772 withCredentials: true,
1773 data: JSON.stringify({'data': powerCapEnable})
1774 })
1775 .then(function(response) {
1776 return response.data;
1777 });
1778 },
1779 setPowerCap: function(powerCap) {
1780 return $http({
1781 method: 'PUT',
1782 url: DataService.getHost() +
1783 '/xyz/openbmc_project/control/host0/power_cap/attr/PowerCap',
Gunnar Mills006aaa02018-06-26 16:08:59 -05001784 withCredentials: true,
1785 data: JSON.stringify({'data': powerCap})
1786 })
1787 .then(function(response) {
1788 return response.data;
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001789 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001790 },
1791 setHostname: function(hostname) {
1792 return $http({
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001793 method: 'PUT',
1794 url: DataService.getHost() +
1795 '/xyz/openbmc_project/network/config/attr/HostName',
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001796 withCredentials: true,
1797 data: JSON.stringify({'data': hostname})
1798 })
1799 .then(function(response) {
1800 return response.data;
1801 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001802 },
1803 };
1804 return SERVICE;
Andrew Geisslerd27bb132018-05-24 11:07:27 -07001805 }
1806 ]);
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07001807})(window.angular);