Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 1 | /** |
| 2 | * API utilities service |
| 3 | * |
| 4 | * @module app/common/services/api-utils |
| 5 | * @exports APIUtils |
| 6 | * @name APIUtils |
Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 7 | */ |
| 8 | |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 9 | window.angular && (function(angular) { |
| 10 | 'use strict'; |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 11 | angular.module('app.common.services').factory('APIUtils', [ |
| 12 | '$http', 'Constants', '$q', 'dataService', |
| 13 | function($http, Constants, $q, DataService) { |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 14 | var getScaledValue = function(value, scale) { |
| 15 | scale = scale + ''; |
| 16 | scale = parseInt(scale, 10); |
| 17 | var power = Math.abs(parseInt(scale, 10)); |
CamVan Nguyen | 3327583 | 2018-03-13 18:38:37 -0500 | [diff] [blame] | 18 | |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 19 | if (scale > 0) { |
| 20 | value = value * Math.pow(10, power); |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 21 | } else if (scale < 0) { |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 22 | 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 Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 39 | url: DataService.getHost() + |
| 40 | '/xyz/openbmc_project/state/chassis0/attr/CurrentPowerState', |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 41 | headers: { |
| 42 | 'Accept': 'application/json', |
| 43 | 'Content-Type': 'application/json' |
| 44 | }, |
| 45 | withCredentials: true |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 46 | }) |
| 47 | .then( |
| 48 | function(response) { |
| 49 | var json = JSON.stringify(response.data); |
| 50 | var content = JSON.parse(json); |
| 51 | deferred.resolve(content.data); |
| 52 | }, |
| 53 | function(error) { |
| 54 | console.log(error); |
| 55 | deferred.reject(error); |
| 56 | }); |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 57 | return deferred.promise; |
| 58 | }, |
Gunnar Mills | 6549114 | 2018-06-04 14:23:33 -0500 | [diff] [blame^] | 59 | validIPV4IP: function(ip) { |
| 60 | // Checks for [0-255].[0-255].[0-255].[0-255] |
| 61 | return ip.match( |
| 62 | /\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/); |
| 63 | }, |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 64 | getHostState: function() { |
| 65 | var deferred = $q.defer(); |
| 66 | $http({ |
| 67 | method: 'GET', |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 68 | url: DataService.getHost() + |
| 69 | '/xyz/openbmc_project/state/host0/attr/CurrentHostState', |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 70 | headers: { |
| 71 | 'Accept': 'application/json', |
| 72 | 'Content-Type': 'application/json' |
| 73 | }, |
| 74 | withCredentials: true |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 75 | }) |
| 76 | .then( |
| 77 | function(response) { |
| 78 | var json = JSON.stringify(response.data); |
| 79 | var content = JSON.parse(json); |
| 80 | deferred.resolve(content.data); |
| 81 | }, |
| 82 | function(error) { |
| 83 | console.log(error); |
| 84 | deferred.reject(error); |
| 85 | }); |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 86 | return deferred.promise; |
| 87 | }, |
| 88 | getNetworkInfo: function() { |
| 89 | var deferred = $q.defer(); |
| 90 | $http({ |
| 91 | method: 'GET', |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 92 | url: DataService.getHost() + |
| 93 | '/xyz/openbmc_project/network/enumerate', |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 94 | headers: { |
| 95 | 'Accept': 'application/json', |
| 96 | 'Content-Type': 'application/json' |
| 97 | }, |
| 98 | withCredentials: true |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 99 | }) |
| 100 | .then( |
| 101 | function(response) { |
| 102 | var json = JSON.stringify(response.data); |
| 103 | var content = JSON.parse(json); |
| 104 | var hostname = ''; |
Gunnar Mills | e9f5fe7 | 2018-05-04 13:43:10 -0500 | [diff] [blame] | 105 | var defaultgateway = ''; |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 106 | var macAddress = ''; |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 107 | |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 108 | function parseNetworkData(content) { |
| 109 | var data = { |
| 110 | interface_ids: [], |
| 111 | interfaces: {}, |
| 112 | ip_addresses: {ipv4: [], ipv6: []}, |
| 113 | }; |
| 114 | var interfaceId = '', keyParts = [], interfaceHash = '', |
| 115 | interfaceType = ''; |
| 116 | for (var key in content.data) { |
Gunnar Mills | 3efbe2d | 2018-06-07 14:47:19 -0500 | [diff] [blame] | 117 | if (key.match(/network\/eth\d+(_\d+)?$/ig)) { |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 118 | interfaceId = key.split('/').pop(); |
| 119 | if (data.interface_ids.indexOf(interfaceId) == -1) { |
| 120 | data.interface_ids.push(interfaceId); |
| 121 | data.interfaces[interfaceId] = { |
| 122 | interfaceIname: '', |
| 123 | DomainName: '', |
| 124 | MACAddress: '', |
| 125 | Nameservers: [], |
| 126 | DHCPEnabled: 0, |
| 127 | ipv4: {ids: [], values: []}, |
| 128 | ipv6: {ids: [], values: []} |
| 129 | }; |
| 130 | data.interfaces[interfaceId].MACAddress = |
| 131 | content.data[key].MACAddress; |
| 132 | data.interfaces[interfaceId].DomainName = |
| 133 | content.data[key].DomainName.join(' '); |
| 134 | data.interfaces[interfaceId].Nameservers = |
| 135 | content.data[key].Nameservers; |
| 136 | data.interfaces[interfaceId].DHCPEnabled = |
| 137 | content.data[key].DHCPEnabled; |
| 138 | } |
| 139 | } else if ( |
| 140 | key.match( |
Gunnar Mills | 3efbe2d | 2018-06-07 14:47:19 -0500 | [diff] [blame] | 141 | /network\/eth\d+(_\d+)?\/ipv[4|6]\/[a-z0-9]+$/ig)) { |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 142 | keyParts = key.split('/'); |
| 143 | interfaceHash = keyParts.pop(); |
| 144 | interfaceType = keyParts.pop(); |
| 145 | interfaceId = keyParts.pop(); |
| 146 | |
| 147 | if (data.interfaces[interfaceId][interfaceType] |
| 148 | .ids.indexOf(interfaceHash) == -1) { |
| 149 | data.interfaces[interfaceId][interfaceType] |
| 150 | .ids.push(interfaceHash); |
| 151 | data.interfaces[interfaceId][interfaceType] |
| 152 | .values.push(content.data[key]); |
| 153 | data.ip_addresses[interfaceType].push( |
| 154 | content.data[key]['Address']); |
| 155 | } |
| 156 | } |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 157 | } |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 158 | return data; |
| 159 | } |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 160 | |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 161 | if (content.data.hasOwnProperty( |
Gunnar Mills | e9f5fe7 | 2018-05-04 13:43:10 -0500 | [diff] [blame] | 162 | '/xyz/openbmc_project/network/config')) { |
| 163 | if (content.data['/xyz/openbmc_project/network/config'] |
| 164 | .hasOwnProperty('HostName')) { |
| 165 | hostname = |
| 166 | content.data['/xyz/openbmc_project/network/config'] |
| 167 | .HostName; |
| 168 | } |
| 169 | if (content.data['/xyz/openbmc_project/network/config'] |
| 170 | .hasOwnProperty('DefaultGateway')) { |
| 171 | defaultgateway = |
| 172 | content.data['/xyz/openbmc_project/network/config'] |
| 173 | .DefaultGateway; |
| 174 | } |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 175 | } |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 176 | |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 177 | if (content.data.hasOwnProperty( |
| 178 | '/xyz/openbmc_project/network/eth0') && |
| 179 | content.data['/xyz/openbmc_project/network/eth0'] |
| 180 | .hasOwnProperty('MACAddress')) { |
| 181 | macAddress = |
| 182 | content.data['/xyz/openbmc_project/network/eth0'] |
| 183 | .MACAddress; |
| 184 | } |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 185 | |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 186 | deferred.resolve({ |
| 187 | data: content.data, |
| 188 | hostname: hostname, |
Gunnar Mills | e9f5fe7 | 2018-05-04 13:43:10 -0500 | [diff] [blame] | 189 | defaultgateway: defaultgateway, |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 190 | mac_address: macAddress, |
| 191 | formatted_data: parseNetworkData(content) |
| 192 | }); |
| 193 | }, |
| 194 | function(error) { |
| 195 | console.log(error); |
| 196 | deferred.reject(error); |
| 197 | }); |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 198 | return deferred.promise; |
| 199 | }, |
Gunnar Mills | 7ddc727 | 2018-04-12 16:12:03 -0500 | [diff] [blame] | 200 | setMACAddress: function(interface_name, mac_address) { |
| 201 | return $http({ |
| 202 | method: 'PUT', |
| 203 | url: DataService.getHost() + |
| 204 | '/xyz/openbmc_project/network/' + interface_name + |
| 205 | '/attr/MACAddress', |
| 206 | headers: { |
| 207 | 'Accept': 'application/json', |
| 208 | 'Content-Type': 'application/json' |
| 209 | }, |
| 210 | withCredentials: true, |
| 211 | data: JSON.stringify({'data': mac_address}) |
| 212 | }) |
| 213 | .then(function(response) { |
| 214 | return response.data; |
| 215 | }); |
| 216 | }, |
Gunnar Mills | dca79d7 | 2018-05-30 13:07:01 -0500 | [diff] [blame] | 217 | setDefaultGateway: function(defaultGateway) { |
| 218 | return $http({ |
| 219 | method: 'PUT', |
| 220 | url: DataService.getHost() + |
| 221 | '/xyz/openbmc_project/network/config/attr/DefaultGateway', |
| 222 | headers: { |
| 223 | 'Accept': 'application/json', |
| 224 | 'Content-Type': 'application/json' |
| 225 | }, |
| 226 | withCredentials: true, |
| 227 | data: JSON.stringify({'data': defaultGateway}) |
| 228 | }) |
| 229 | .then(function(response) { |
| 230 | return response.data; |
| 231 | }); |
| 232 | }, |
Gunnar Mills | cb2c306 | 2018-05-31 13:13:30 -0500 | [diff] [blame] | 233 | setDHCPEnabled: function(interfaceName, dhcpEnabled) { |
| 234 | return $http({ |
| 235 | method: 'PUT', |
| 236 | url: DataService.getHost() + |
| 237 | '/xyz/openbmc_project/network/' + interfaceName + |
| 238 | '/attr/DHCPEnabled', |
| 239 | headers: { |
| 240 | 'Accept': 'application/json', |
| 241 | 'Content-Type': 'application/json' |
| 242 | }, |
| 243 | withCredentials: true, |
| 244 | data: JSON.stringify({'data': dhcpEnabled}) |
| 245 | }) |
| 246 | .then(function(response) { |
| 247 | return response.data; |
| 248 | }); |
| 249 | }, |
Gunnar Mills | a45c385 | 2018-05-30 16:18:45 -0500 | [diff] [blame] | 250 | deleteIPV4: function(interfaceName, networkID) { |
| 251 | return $http({ |
| 252 | method: 'POST', |
| 253 | url: DataService.getHost() + |
| 254 | '/xyz/openbmc_project/network/' + interfaceName + |
| 255 | '/ipv4/' + networkID + '/action/Delete', |
| 256 | headers: { |
| 257 | 'Accept': 'application/json', |
| 258 | 'Content-Type': 'application/json' |
| 259 | }, |
| 260 | withCredentials: true, |
| 261 | data: JSON.stringify({'data': []}) |
| 262 | }) |
| 263 | .then(function(response) { |
| 264 | return response.data; |
| 265 | }); |
| 266 | }, |
| 267 | addIPV4: function( |
| 268 | interfaceName, ipAddress, netmaskPrefixLength, gateway) { |
| 269 | return $http({ |
| 270 | method: 'POST', |
| 271 | url: DataService.getHost() + |
| 272 | '/xyz/openbmc_project/network/' + interfaceName + |
| 273 | '/action/IP', |
| 274 | headers: { |
| 275 | 'Accept': 'application/json', |
| 276 | 'Content-Type': 'application/json' |
| 277 | }, |
| 278 | withCredentials: true, |
| 279 | data: JSON.stringify({ |
| 280 | 'data': [ |
| 281 | 'xyz.openbmc_project.Network.IP.Protocol.IPv4', |
| 282 | ipAddress, +netmaskPrefixLength, gateway |
| 283 | ] |
| 284 | }) |
| 285 | }) |
| 286 | .then(function(response) { |
| 287 | return response.data; |
| 288 | }); |
| 289 | }, |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 290 | getLEDState: function() { |
| 291 | var deferred = $q.defer(); |
| 292 | $http({ |
| 293 | method: 'GET', |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 294 | url: DataService.getHost() + |
| 295 | '/xyz/openbmc_project/led/groups/enclosure_identify', |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 296 | headers: { |
| 297 | 'Accept': 'application/json', |
| 298 | 'Content-Type': 'application/json' |
| 299 | }, |
| 300 | withCredentials: true |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 301 | }) |
| 302 | .then( |
| 303 | function(response) { |
| 304 | var json = JSON.stringify(response.data); |
| 305 | var content = JSON.parse(json); |
| 306 | deferred.resolve(content.data.Asserted); |
| 307 | }, |
| 308 | function(error) { |
| 309 | console.log(error); |
| 310 | deferred.reject(error); |
| 311 | }); |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 312 | return deferred.promise; |
| 313 | }, |
| 314 | login: function(username, password, callback) { |
| 315 | $http({ |
| 316 | method: 'POST', |
| 317 | url: DataService.getHost() + '/login', |
| 318 | headers: { |
| 319 | 'Accept': 'application/json', |
| 320 | 'Content-Type': 'application/json' |
| 321 | }, |
| 322 | withCredentials: true, |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 323 | data: JSON.stringify({'data': [username, password]}) |
| 324 | }) |
| 325 | .then( |
| 326 | function(response) { |
| 327 | if (callback) { |
| 328 | callback(response.data); |
| 329 | } |
| 330 | }, |
| 331 | function(error) { |
| 332 | if (callback) { |
| 333 | if (error && error.status && error.status == 'error') { |
| 334 | callback(error); |
| 335 | } else { |
| 336 | callback(error, true); |
| 337 | } |
| 338 | } |
| 339 | console.log(error); |
| 340 | }); |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 341 | }, |
| 342 | testPassword: function(username, password) { |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 343 | // Calls /login without the current session to verify the given |
| 344 | // password is correct ignore the interceptor logout on a bad password |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 345 | return $http({ |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 346 | method: 'POST', |
| 347 | url: DataService.getHost() + '/login', |
| 348 | headers: { |
| 349 | 'Accept': 'application/json', |
| 350 | 'Content-Type': 'application/json' |
| 351 | }, |
| 352 | withCredentials: false, |
| 353 | data: JSON.stringify({'data': [username, password]}) |
| 354 | }) |
| 355 | .then(function(response) { |
| 356 | return response.data; |
| 357 | }); |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 358 | }, |
| 359 | logout: function(callback) { |
| 360 | $http({ |
| 361 | method: 'POST', |
| 362 | url: DataService.getHost() + '/logout', |
| 363 | headers: { |
| 364 | 'Accept': 'application/json', |
| 365 | 'Content-Type': 'application/json' |
| 366 | }, |
| 367 | withCredentials: true, |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 368 | data: JSON.stringify({'data': []}) |
| 369 | }) |
| 370 | .then( |
| 371 | function(response) { |
| 372 | if (callback) { |
| 373 | callback(response.data); |
| 374 | } |
| 375 | }, |
| 376 | function(error) { |
| 377 | if (callback) { |
| 378 | callback(null, error); |
| 379 | } |
| 380 | console.log(error); |
| 381 | }); |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 382 | }, |
| 383 | changePassword: function(user, newPassword) { |
| 384 | var deferred = $q.defer(); |
| 385 | $http({ |
| 386 | method: 'POST', |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 387 | url: DataService.getHost() + '/xyz/openbmc_project/user/' + user + |
| 388 | '/action/SetPassword', |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 389 | headers: { |
| 390 | 'Accept': 'application/json', |
| 391 | 'Content-Type': 'application/json' |
| 392 | }, |
| 393 | withCredentials: true, |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 394 | data: JSON.stringify({'data': [newPassword]}), |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 395 | responseType: 'arraybuffer' |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 396 | }) |
| 397 | .then( |
| 398 | function(response, status, headers) { |
| 399 | deferred.resolve( |
| 400 | {data: response, status: status, headers: headers}); |
| 401 | }, |
| 402 | function(error) { |
| 403 | console.log(error); |
| 404 | deferred.reject(error); |
| 405 | }); |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 406 | return deferred.promise; |
| 407 | }, |
| 408 | chassisPowerOn: function(callback) { |
| 409 | $http({ |
| 410 | method: 'POST', |
| 411 | url: DataService.getHost() + '/xyz/openbmc_project/state/host0', |
| 412 | headers: { |
| 413 | 'Accept': 'application/json', |
| 414 | 'Content-Type': 'application/json' |
| 415 | }, |
| 416 | withCredentials: true, |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 417 | data: JSON.stringify({'data': []}) |
| 418 | }) |
| 419 | .then( |
| 420 | function(response) { |
| 421 | var json = JSON.stringify(response.data); |
| 422 | var content = JSON.parse(json); |
| 423 | if (callback) { |
| 424 | return callback(content.data.CurrentPowerState); |
| 425 | } |
| 426 | }, |
| 427 | function(error) { |
| 428 | if (callback) { |
| 429 | callback(error); |
| 430 | } else { |
| 431 | console.log(error); |
| 432 | } |
| 433 | }); |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 434 | }, |
| 435 | chassisPowerOff: function() { |
| 436 | var deferred = $q.defer(); |
| 437 | $http({ |
| 438 | method: 'PUT', |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 439 | url: DataService.getHost() + |
| 440 | '/xyz/openbmc_project/state/chassis0/attr/RequestedPowerTransition', |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 441 | headers: { |
| 442 | 'Accept': 'application/json', |
| 443 | 'Content-Type': 'application/json' |
| 444 | }, |
| 445 | withCredentials: true, |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 446 | data: JSON.stringify( |
| 447 | {'data': 'xyz.openbmc_project.State.Chassis.Transition.Off'}) |
| 448 | }) |
| 449 | .then( |
| 450 | function(response) { |
| 451 | var json = JSON.stringify(response.data); |
| 452 | var content = JSON.parse(json); |
| 453 | deferred.resolve(content.status); |
| 454 | }, |
| 455 | function(error) { |
| 456 | console.log(error); |
| 457 | deferred.reject(error); |
| 458 | }); |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 459 | return deferred.promise; |
| 460 | }, |
| 461 | setLEDState: function(state, callback) { |
| 462 | $http({ |
| 463 | method: 'PUT', |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 464 | url: DataService.getHost() + |
| 465 | '/xyz/openbmc_project/led/groups/enclosure_identify/attr/Asserted', |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 466 | headers: { |
| 467 | 'Accept': 'application/json', |
| 468 | 'Content-Type': 'application/json' |
| 469 | }, |
| 470 | withCredentials: true, |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 471 | data: JSON.stringify({'data': state}) |
| 472 | }) |
| 473 | .then( |
| 474 | function(response) { |
| 475 | var json = JSON.stringify(response.data); |
| 476 | var content = JSON.parse(json); |
| 477 | if (callback) { |
| 478 | return callback(content.status); |
| 479 | } |
| 480 | }, |
| 481 | function(error) { |
| 482 | if (callback) { |
| 483 | callback(error); |
| 484 | } else { |
| 485 | console.log(error); |
| 486 | } |
| 487 | }); |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 488 | }, |
| 489 | bmcReboot: function(callback) { |
| 490 | $http({ |
| 491 | method: 'PUT', |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 492 | url: DataService.getHost() + |
| 493 | '/xyz/openbmc_project/state/bmc0/attr/RequestedBmcTransition', |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 494 | headers: { |
| 495 | 'Accept': 'application/json', |
| 496 | 'Content-Type': 'application/json' |
| 497 | }, |
| 498 | withCredentials: true, |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 499 | data: JSON.stringify( |
| 500 | {'data': 'xyz.openbmc_project.State.BMC.Transition.Reboot'}) |
| 501 | }) |
| 502 | .then( |
| 503 | function(response) { |
| 504 | var json = JSON.stringify(response.data); |
| 505 | var content = JSON.parse(json); |
| 506 | if (callback) { |
| 507 | return callback(content.status); |
| 508 | } |
| 509 | }, |
| 510 | function(error) { |
| 511 | if (callback) { |
| 512 | callback(error); |
| 513 | } else { |
| 514 | console.log(error); |
| 515 | } |
| 516 | }); |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 517 | }, |
| 518 | hostPowerOn: function() { |
| 519 | var deferred = $q.defer(); |
| 520 | $http({ |
| 521 | method: 'PUT', |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 522 | url: DataService.getHost() + |
| 523 | '/xyz/openbmc_project/state/host0/attr/RequestedHostTransition', |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 524 | headers: { |
| 525 | 'Accept': 'application/json', |
| 526 | 'Content-Type': 'application/json' |
| 527 | }, |
| 528 | withCredentials: true, |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 529 | data: JSON.stringify( |
| 530 | {'data': 'xyz.openbmc_project.State.Host.Transition.On'}) |
| 531 | }) |
| 532 | .then( |
| 533 | function(response) { |
| 534 | var json = JSON.stringify(response.data); |
| 535 | var content = JSON.parse(json); |
| 536 | deferred.resolve(content.status); |
| 537 | }, |
| 538 | function(error) { |
| 539 | console.log(error); |
| 540 | deferred.reject(error); |
| 541 | }); |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 542 | return deferred.promise; |
| 543 | }, |
| 544 | hostPowerOff: function() { |
| 545 | var deferred = $q.defer(); |
| 546 | $http({ |
| 547 | method: 'PUT', |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 548 | url: DataService.getHost() + |
| 549 | '/xyz/openbmc_project/state/host0/attr/RequestedHostTransition', |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 550 | headers: { |
| 551 | 'Accept': 'application/json', |
| 552 | 'Content-Type': 'application/json' |
| 553 | }, |
| 554 | withCredentials: true, |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 555 | data: JSON.stringify( |
| 556 | {'data': 'xyz.openbmc_project.State.Host.Transition.Off'}) |
| 557 | }) |
| 558 | .then( |
| 559 | function(response) { |
| 560 | var json = JSON.stringify(response.data); |
| 561 | var content = JSON.parse(json); |
| 562 | deferred.resolve(content.status); |
| 563 | }, |
| 564 | function(error) { |
| 565 | console.log(error); |
| 566 | deferred.reject(error); |
| 567 | }); |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 568 | return deferred.promise; |
| 569 | }, |
| 570 | hostReboot: function() { |
| 571 | var deferred = $q.defer(); |
| 572 | $http({ |
| 573 | method: 'PUT', |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 574 | url: DataService.getHost() + |
| 575 | '/xyz/openbmc_project/state/host0/attr/RequestedHostTransition', |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 576 | headers: { |
| 577 | 'Accept': 'application/json', |
| 578 | 'Content-Type': 'application/json' |
| 579 | }, |
| 580 | withCredentials: true, |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 581 | data: JSON.stringify( |
| 582 | {'data': 'xyz.openbmc_project.State.Host.Transition.Reboot'}) |
| 583 | }) |
| 584 | .then( |
| 585 | function(response) { |
| 586 | var json = JSON.stringify(response.data); |
| 587 | var content = JSON.parse(json); |
| 588 | deferred.resolve(content.status); |
| 589 | }, |
| 590 | function(error) { |
| 591 | console.log(error); |
| 592 | deferred.reject(error); |
| 593 | }); |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 594 | |
| 595 | return deferred.promise; |
| 596 | }, |
| 597 | hostShutdown: function(callback) { |
| 598 | $http({ |
| 599 | method: 'POST', |
| 600 | url: DataService.getHost() + '/xyz/openbmc_project/state/host0', |
| 601 | headers: { |
| 602 | 'Accept': 'application/json', |
| 603 | 'Content-Type': 'application/json' |
| 604 | }, |
| 605 | withCredentials: true, |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 606 | data: JSON.stringify({'data': []}) |
| 607 | }) |
| 608 | .then( |
| 609 | function(response) { |
| 610 | var json = JSON.stringify(response.data); |
| 611 | var content = JSON.parse(json); |
| 612 | if (callback) { |
| 613 | return callback(content); |
| 614 | } |
| 615 | }, |
| 616 | function(error) { |
| 617 | if (callback) { |
| 618 | callback(error); |
| 619 | } else { |
| 620 | console.log(error); |
| 621 | } |
| 622 | }); |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 623 | }, |
| 624 | getLogs: function() { |
| 625 | var deferred = $q.defer(); |
| 626 | $http({ |
| 627 | method: 'GET', |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 628 | url: DataService.getHost() + |
| 629 | '/xyz/openbmc_project/logging/enumerate', |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 630 | headers: { |
| 631 | 'Accept': 'application/json', |
| 632 | 'Content-Type': 'application/json' |
| 633 | }, |
| 634 | withCredentials: true |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 635 | }) |
| 636 | .then( |
| 637 | function(response) { |
| 638 | var json = JSON.stringify(response.data); |
| 639 | var content = JSON.parse(json); |
| 640 | var dataClone = JSON.parse(JSON.stringify(content.data)); |
| 641 | var data = []; |
| 642 | var severityCode = ''; |
| 643 | var priority = ''; |
| 644 | var health = ''; |
| 645 | var relatedItems = []; |
Matt Spinler | 845acdc | 2018-05-01 16:41:28 -0500 | [diff] [blame] | 646 | var eventID = 'None'; |
| 647 | var description = 'None'; |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 648 | |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 649 | for (var key in content.data) { |
| 650 | if (content.data.hasOwnProperty(key) && |
| 651 | content.data[key].hasOwnProperty('Id')) { |
| 652 | var severityFlags = { |
| 653 | low: false, |
| 654 | medium: false, |
| 655 | high: false |
| 656 | }; |
| 657 | var healthFlags = { |
| 658 | critical: false, |
| 659 | warning: false, |
| 660 | good: false |
| 661 | }; |
| 662 | severityCode = |
| 663 | content.data[key].Severity.split('.').pop(); |
| 664 | priority = |
| 665 | Constants.SEVERITY_TO_PRIORITY_MAP[severityCode]; |
| 666 | severityFlags[priority.toLowerCase()] = true; |
| 667 | health = Constants.SEVERITY_TO_HEALTH_MAP[severityCode]; |
| 668 | healthFlags[health.toLowerCase()] = true; |
| 669 | relatedItems = []; |
| 670 | content.data[key].associations.forEach(function(item) { |
| 671 | relatedItems.push(item[2]); |
| 672 | }); |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 673 | |
Matt Spinler | 845acdc | 2018-05-01 16:41:28 -0500 | [diff] [blame] | 674 | if (content.data[key].hasOwnProperty(['EventID'])) { |
| 675 | eventID = content.data[key].EventID; |
| 676 | } |
| 677 | |
| 678 | if (content.data[key].hasOwnProperty(['Description'])) { |
| 679 | description = content.data[key].Description; |
| 680 | } |
| 681 | |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 682 | data.push(Object.assign( |
| 683 | { |
| 684 | path: key, |
| 685 | copied: false, |
| 686 | priority: priority, |
| 687 | severity_code: severityCode, |
| 688 | severity_flags: severityFlags, |
| 689 | health_flags: healthFlags, |
| 690 | additional_data: |
| 691 | content.data[key].AdditionalData.join('\n'), |
| 692 | type: content.data[key].Message, |
| 693 | selected: false, |
| 694 | search_text: |
| 695 | ('#' + content.data[key].Id + ' ' + |
| 696 | severityCode + ' ' + |
| 697 | content.data[key].Severity + ' ' + |
| 698 | content.data[key].AdditionalData.join(' ')) |
| 699 | .toLowerCase(), |
| 700 | meta: false, |
| 701 | confirm: false, |
| 702 | related_items: relatedItems, |
Matt Spinler | 845acdc | 2018-05-01 16:41:28 -0500 | [diff] [blame] | 703 | eventID: eventID, |
| 704 | description: description, |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 705 | data: {key: key, value: content.data[key]} |
| 706 | }, |
| 707 | content.data[key])); |
| 708 | } |
| 709 | } |
| 710 | deferred.resolve({data: data, original: dataClone}); |
| 711 | }, |
| 712 | function(error) { |
| 713 | console.log(error); |
| 714 | deferred.reject(error); |
| 715 | }); |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 716 | |
| 717 | return deferred.promise; |
| 718 | }, |
| 719 | getAllSensorStatus: function(callback) { |
| 720 | $http({ |
| 721 | method: 'GET', |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 722 | url: DataService.getHost() + |
| 723 | '/xyz/openbmc_project/sensors/enumerate', |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 724 | headers: { |
| 725 | 'Accept': 'application/json', |
| 726 | 'Content-Type': 'application/json' |
| 727 | }, |
| 728 | withCredentials: true |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 729 | }) |
| 730 | .then( |
| 731 | function(response) { |
| 732 | var json = JSON.stringify(response.data); |
| 733 | var content = JSON.parse(json); |
| 734 | var dataClone = JSON.parse(JSON.stringify(content.data)); |
| 735 | var sensorData = []; |
| 736 | var severity = {}; |
| 737 | var title = ''; |
| 738 | var tempKeyParts = []; |
| 739 | var order = 0; |
| 740 | var customOrder = 0; |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 741 | |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 742 | function getSensorStatus(reading) { |
| 743 | var severityFlags = { |
| 744 | critical: false, |
| 745 | warning: false, |
| 746 | normal: false |
| 747 | }, |
| 748 | severityText = '', order = 0; |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 749 | |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 750 | if (reading.hasOwnProperty('CriticalLow') && |
| 751 | reading.Value < reading.CriticalLow) { |
| 752 | severityFlags.critical = true; |
| 753 | severityText = 'critical'; |
| 754 | order = 2; |
| 755 | } else if ( |
| 756 | reading.hasOwnProperty('CriticalHigh') && |
| 757 | reading.Value > reading.CriticalHigh) { |
| 758 | severityFlags.critical = true; |
| 759 | severityText = 'critical'; |
| 760 | order = 2; |
| 761 | } else if ( |
| 762 | reading.hasOwnProperty('CriticalLow') && |
| 763 | reading.hasOwnProperty('WarningLow') && |
| 764 | reading.Value >= reading.CriticalLow && |
| 765 | reading.Value <= reading.WarningLow) { |
| 766 | severityFlags.warning = true; |
| 767 | severityText = 'warning'; |
| 768 | order = 1; |
| 769 | } else if ( |
| 770 | reading.hasOwnProperty('WarningHigh') && |
| 771 | reading.hasOwnProperty('CriticalHigh') && |
| 772 | reading.Value >= reading.WarningHigh && |
| 773 | reading.Value <= reading.CriticalHigh) { |
| 774 | severityFlags.warning = true; |
| 775 | severityText = 'warning'; |
| 776 | order = 1; |
| 777 | } else { |
| 778 | severityFlags.normal = true; |
| 779 | severityText = 'normal'; |
| 780 | } |
| 781 | return { |
| 782 | flags: severityFlags, |
| 783 | severityText: severityText, |
| 784 | order: order |
| 785 | }; |
| 786 | } |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 787 | |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 788 | for (var key in content.data) { |
| 789 | if (content.data.hasOwnProperty(key) && |
| 790 | content.data[key].hasOwnProperty('Unit')) { |
| 791 | severity = getSensorStatus(content.data[key]); |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 792 | |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 793 | if (!content.data[key].hasOwnProperty('CriticalLow')) { |
| 794 | content.data[key].CriticalLow = '--'; |
| 795 | content.data[key].CriticalHigh = '--'; |
| 796 | } |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 797 | |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 798 | if (!content.data[key].hasOwnProperty('WarningLow')) { |
| 799 | content.data[key].WarningLow = '--'; |
| 800 | content.data[key].WarningHigh = '--'; |
| 801 | } |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 802 | |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 803 | tempKeyParts = key.split('/'); |
| 804 | title = tempKeyParts.pop(); |
| 805 | title = tempKeyParts.pop() + '_' + title; |
| 806 | title = title.split('_') |
| 807 | .map(function(item) { |
| 808 | return item.toLowerCase() |
| 809 | .charAt(0) |
| 810 | .toUpperCase() + |
| 811 | item.slice(1); |
| 812 | }) |
| 813 | .reduce(function(prev, el) { |
| 814 | return prev + ' ' + el; |
| 815 | }); |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 816 | |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 817 | content.data[key].Value = getScaledValue( |
| 818 | content.data[key].Value, content.data[key].Scale); |
| 819 | content.data[key].CriticalLow = getScaledValue( |
| 820 | content.data[key].CriticalLow, |
| 821 | content.data[key].Scale); |
| 822 | content.data[key].CriticalHigh = getScaledValue( |
| 823 | content.data[key].CriticalHigh, |
| 824 | content.data[key].Scale); |
| 825 | content.data[key].WarningLow = getScaledValue( |
| 826 | content.data[key].WarningLow, |
| 827 | content.data[key].Scale); |
| 828 | content.data[key].WarningHigh = getScaledValue( |
| 829 | content.data[key].WarningHigh, |
| 830 | content.data[key].Scale); |
| 831 | if (Constants.SENSOR_SORT_ORDER.indexOf( |
| 832 | content.data[key].Unit) > -1) { |
| 833 | customOrder = Constants.SENSOR_SORT_ORDER.indexOf( |
| 834 | content.data[key].Unit); |
| 835 | } else { |
| 836 | customOrder = Constants.SENSOR_SORT_ORDER_DEFAULT; |
| 837 | } |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 838 | |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 839 | sensorData.push(Object.assign( |
| 840 | { |
| 841 | path: key, |
| 842 | selected: false, |
| 843 | confirm: false, |
| 844 | copied: false, |
| 845 | title: title, |
| 846 | unit: |
| 847 | Constants |
| 848 | .SENSOR_UNIT_MAP[content.data[key].Unit], |
| 849 | severity_flags: severity.flags, |
| 850 | status: severity.severityText, |
| 851 | order: severity.order, |
| 852 | custom_order: customOrder, |
| 853 | search_text: |
| 854 | (title + ' ' + content.data[key].Value + ' ' + |
| 855 | Constants.SENSOR_UNIT_MAP[content.data[key] |
| 856 | .Unit] + |
| 857 | ' ' + severity.severityText + ' ' + |
| 858 | content.data[key].CriticalLow + ' ' + |
| 859 | content.data[key].CriticalHigh + ' ' + |
| 860 | content.data[key].WarningLow + ' ' + |
| 861 | content.data[key].WarningHigh + ' ') |
| 862 | .toLowerCase(), |
| 863 | original_data: |
| 864 | {key: key, value: content.data[key]} |
| 865 | }, |
| 866 | content.data[key])); |
| 867 | } |
| 868 | } |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 869 | |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 870 | callback(sensorData, dataClone); |
| 871 | }, |
| 872 | function(error) { |
| 873 | console.log(error); |
| 874 | }); |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 875 | }, |
| 876 | getActivation: function(imageId) { |
| 877 | return $http({ |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 878 | method: 'GET', |
| 879 | url: DataService.getHost() + |
| 880 | '/xyz/openbmc_project/software/' + imageId + |
| 881 | '/attr/Activation', |
| 882 | headers: { |
| 883 | 'Accept': 'application/json', |
| 884 | 'Content-Type': 'application/json' |
| 885 | }, |
| 886 | withCredentials: true |
| 887 | }) |
| 888 | .then(function(response) { |
| 889 | return response.data; |
| 890 | }); |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 891 | }, |
| 892 | getFirmwares: function() { |
| 893 | var deferred = $q.defer(); |
| 894 | $http({ |
| 895 | method: 'GET', |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 896 | url: DataService.getHost() + |
| 897 | '/xyz/openbmc_project/software/enumerate', |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 898 | headers: { |
| 899 | 'Accept': 'application/json', |
| 900 | 'Content-Type': 'application/json' |
| 901 | }, |
| 902 | withCredentials: true |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 903 | }) |
| 904 | .then( |
| 905 | function(response) { |
| 906 | var json = JSON.stringify(response.data); |
| 907 | var content = JSON.parse(json); |
| 908 | var data = []; |
| 909 | var activationStatus = ''; |
| 910 | var isExtended = false; |
| 911 | var bmcActiveVersion = ''; |
| 912 | var hostActiveVersion = ''; |
| 913 | var imageType = ''; |
| 914 | var extendedVersions = []; |
| 915 | var functionalImages = []; |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 916 | |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 917 | function getFormatedExtendedVersions(extendedVersion) { |
| 918 | var versions = []; |
| 919 | extendedVersion = extendedVersion.split(','); |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 920 | |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 921 | extendedVersion.forEach(function(item) { |
| 922 | var parts = item.split('-'); |
| 923 | var numberIndex = 0; |
| 924 | for (var i = 0; i < parts.length; i++) { |
| 925 | if (/[0-9]/.test(parts[i])) { |
| 926 | numberIndex = i; |
| 927 | break; |
| 928 | } |
| 929 | } |
| 930 | var titlePart = parts.splice(0, numberIndex); |
| 931 | titlePart = titlePart.join(''); |
| 932 | titlePart = titlePart[0].toUpperCase() + |
| 933 | titlePart.substr(1, titlePart.length); |
| 934 | var versionPart = parts.join('-'); |
| 935 | versions.push({title: titlePart, version: versionPart}); |
| 936 | }); |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 937 | |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 938 | return versions; |
| 939 | } |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 940 | |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 941 | // Get the list of functional images so we can compare |
| 942 | // later if an image is functional |
| 943 | if (content.data[Constants.FIRMWARE.FUNCTIONAL_OBJPATH]) { |
| 944 | functionalImages = |
| 945 | content.data[Constants.FIRMWARE.FUNCTIONAL_OBJPATH] |
| 946 | .endpoints; |
| 947 | } |
| 948 | for (var key in content.data) { |
| 949 | if (content.data.hasOwnProperty(key) && |
| 950 | content.data[key].hasOwnProperty('Version')) { |
| 951 | // If the image is "Functional" use that for the |
| 952 | // activation status, else use the value of "Activation" |
| 953 | // github.com/openbmc/phosphor-dbus-interfaces/blob/master/xyz/openbmc_project/Software/Activation.interface.yaml |
| 954 | activationStatus = |
| 955 | content.data[key].Activation.split('.').pop(); |
| 956 | if (functionalImages.includes(key)) { |
| 957 | activationStatus = 'Functional'; |
| 958 | } |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 959 | |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 960 | imageType = content.data[key].Purpose.split('.').pop(); |
| 961 | isExtended = content.data[key].hasOwnProperty( |
| 962 | 'ExtendedVersion') && |
| 963 | content.data[key].ExtendedVersion != ''; |
| 964 | if (isExtended) { |
| 965 | extendedVersions = getFormatedExtendedVersions( |
| 966 | content.data[key].ExtendedVersion); |
| 967 | } |
| 968 | data.push(Object.assign( |
| 969 | { |
| 970 | path: key, |
| 971 | activationStatus: activationStatus, |
| 972 | imageId: key.split('/').pop(), |
| 973 | imageType: imageType, |
| 974 | isExtended: isExtended, |
| 975 | extended: |
| 976 | {show: false, versions: extendedVersions}, |
| 977 | data: {key: key, value: content.data[key]} |
| 978 | }, |
| 979 | content.data[key])); |
| 980 | |
| 981 | if (activationStatus == 'Functional' && |
| 982 | imageType == 'BMC') { |
| 983 | bmcActiveVersion = content.data[key].Version; |
| 984 | } |
| 985 | |
| 986 | if (activationStatus == 'Functional' && |
| 987 | imageType == 'Host') { |
| 988 | hostActiveVersion = content.data[key].Version; |
| 989 | } |
| 990 | } |
| 991 | } |
| 992 | |
| 993 | deferred.resolve({ |
| 994 | data: data, |
| 995 | bmcActiveVersion: bmcActiveVersion, |
| 996 | hostActiveVersion: hostActiveVersion |
| 997 | }); |
Iftekharul Islam | 171c6a1 | 2017-08-11 08:35:47 -0500 | [diff] [blame] | 998 | }, |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 999 | function(error) { |
| 1000 | console.log(error); |
| 1001 | deferred.reject(error); |
| 1002 | }); |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 1003 | |
| 1004 | return deferred.promise; |
| 1005 | }, |
| 1006 | changePriority: function(imageId, priority) { |
| 1007 | var deferred = $q.defer(); |
| 1008 | $http({ |
| 1009 | method: 'PUT', |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 1010 | url: DataService.getHost() + '/xyz/openbmc_project/software/' + |
| 1011 | imageId + '/attr/Priority', |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 1012 | headers: { |
| 1013 | 'Accept': 'application/json', |
| 1014 | 'Content-Type': 'application/json' |
| 1015 | }, |
| 1016 | withCredentials: true, |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 1017 | data: JSON.stringify({'data': priority}) |
| 1018 | }) |
| 1019 | .then( |
| 1020 | function(response) { |
| 1021 | var json = JSON.stringify(response.data); |
| 1022 | var content = JSON.parse(json); |
| 1023 | deferred.resolve(content); |
| 1024 | }, |
| 1025 | function(error) { |
| 1026 | console.log(error); |
| 1027 | deferred.reject(error); |
| 1028 | }); |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 1029 | |
| 1030 | return deferred.promise; |
| 1031 | }, |
| 1032 | deleteImage: function(imageId) { |
| 1033 | var deferred = $q.defer(); |
| 1034 | $http({ |
| 1035 | method: 'POST', |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 1036 | url: DataService.getHost() + '/xyz/openbmc_project/software/' + |
| 1037 | imageId + '/action/Delete', |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 1038 | headers: { |
| 1039 | 'Accept': 'application/json', |
| 1040 | 'Content-Type': 'application/json' |
| 1041 | }, |
| 1042 | withCredentials: true, |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 1043 | data: JSON.stringify({'data': []}) |
| 1044 | }) |
| 1045 | .then( |
| 1046 | function(response) { |
| 1047 | var json = JSON.stringify(response.data); |
| 1048 | var content = JSON.parse(json); |
| 1049 | deferred.resolve(content); |
| 1050 | }, |
| 1051 | function(error) { |
| 1052 | console.log(error); |
| 1053 | deferred.reject(error); |
| 1054 | }); |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 1055 | |
| 1056 | return deferred.promise; |
| 1057 | }, |
| 1058 | activateImage: function(imageId) { |
| 1059 | var deferred = $q.defer(); |
| 1060 | $http({ |
| 1061 | method: 'PUT', |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 1062 | url: DataService.getHost() + '/xyz/openbmc_project/software/' + |
| 1063 | imageId + '/attr/RequestedActivation', |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 1064 | headers: { |
| 1065 | 'Accept': 'application/json', |
| 1066 | 'Content-Type': 'application/json' |
| 1067 | }, |
| 1068 | withCredentials: true, |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 1069 | data: |
| 1070 | JSON.stringify({'data': Constants.FIRMWARE.ACTIVATE_FIRMWARE}) |
| 1071 | }) |
| 1072 | .then( |
| 1073 | function(response) { |
| 1074 | var json = JSON.stringify(response.data); |
| 1075 | var content = JSON.parse(json); |
| 1076 | deferred.resolve(content); |
| 1077 | }, |
| 1078 | function(error) { |
| 1079 | console.log(error); |
| 1080 | deferred.reject(error); |
| 1081 | }); |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 1082 | |
| 1083 | return deferred.promise; |
| 1084 | }, |
| 1085 | uploadImage: function(file) { |
| 1086 | return $http({ |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 1087 | method: 'POST', |
| 1088 | timeout: 5 * 60 * 1000, |
| 1089 | url: DataService.getHost() + '/upload/image', |
| 1090 | headers: {'Content-Type': 'application/octet-stream'}, |
| 1091 | withCredentials: true, |
| 1092 | data: file |
| 1093 | }) |
| 1094 | .then(function(response) { |
| 1095 | return response.data; |
| 1096 | }); |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 1097 | }, |
| 1098 | downloadImage: function(host, filename) { |
| 1099 | return $http({ |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 1100 | method: 'POST', |
| 1101 | url: DataService.getHost() + |
| 1102 | '/xyz/openbmc_project/software/action/DownloadViaTFTP', |
| 1103 | headers: { |
| 1104 | 'Accept': 'application/json', |
| 1105 | 'Content-Type': 'application/json' |
| 1106 | }, |
| 1107 | withCredentials: true, |
| 1108 | data: JSON.stringify({'data': [filename, host]}), |
| 1109 | responseType: 'arraybuffer' |
| 1110 | }) |
| 1111 | .then(function(response) { |
| 1112 | return response.data; |
| 1113 | }); |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 1114 | }, |
| 1115 | getBMCEthernetInfo: function() { |
| 1116 | var deferred = $q.defer(); |
| 1117 | $http({ |
| 1118 | method: 'GET', |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 1119 | url: DataService.getHost() + |
| 1120 | '/xyz/openbmc_project/inventory/system/chassis/motherboard/boxelder/bmc/ethernet', |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 1121 | headers: { |
| 1122 | 'Accept': 'application/json', |
| 1123 | 'Content-Type': 'application/json' |
| 1124 | }, |
| 1125 | withCredentials: true |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 1126 | }) |
| 1127 | .then( |
| 1128 | function(response) { |
| 1129 | var json = JSON.stringify(response.data); |
| 1130 | var content = JSON.parse(json); |
| 1131 | deferred.resolve(content.data); |
| 1132 | }, |
| 1133 | function(error) { |
| 1134 | console.log(error); |
| 1135 | deferred.reject(error); |
| 1136 | }); |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 1137 | |
| 1138 | return deferred.promise; |
| 1139 | }, |
| 1140 | getBMCInfo: function(callback) { |
| 1141 | var deferred = $q.defer(); |
| 1142 | $http({ |
| 1143 | method: 'GET', |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 1144 | url: DataService.getHost() + |
| 1145 | '/xyz/openbmc_project/inventory/system/chassis/motherboard/boxelder/bmc', |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 1146 | headers: { |
| 1147 | 'Accept': 'application/json', |
| 1148 | 'Content-Type': 'application/json' |
| 1149 | }, |
| 1150 | withCredentials: true |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 1151 | }) |
| 1152 | .then( |
| 1153 | function(response) { |
| 1154 | var json = JSON.stringify(response.data); |
| 1155 | var content = JSON.parse(json); |
| 1156 | deferred.resolve(content.data); |
| 1157 | }, |
| 1158 | function(error) { |
| 1159 | console.log(error); |
| 1160 | deferred.reject(error); |
| 1161 | }); |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 1162 | return deferred.promise; |
| 1163 | }, |
| 1164 | getServerInfo: function() { |
| 1165 | // TODO: openbmc/openbmc#3117 Need a way via REST to get |
| 1166 | // interfaces so we can get the system object(s) by the looking |
| 1167 | // for the system interface. |
| 1168 | return $http({ |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 1169 | method: 'GET', |
| 1170 | url: DataService.getHost() + |
| 1171 | '/xyz/openbmc_project/inventory/system', |
| 1172 | headers: { |
| 1173 | 'Accept': 'application/json', |
| 1174 | 'Content-Type': 'application/json' |
| 1175 | }, |
| 1176 | withCredentials: true |
| 1177 | }) |
| 1178 | .then(function(response) { |
| 1179 | return response.data; |
| 1180 | }); |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 1181 | }, |
| 1182 | getBMCTime: function() { |
| 1183 | return $http({ |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 1184 | method: 'GET', |
| 1185 | url: DataService.getHost() + '/xyz/openbmc_project/time/bmc', |
| 1186 | headers: { |
| 1187 | 'Accept': 'application/json', |
| 1188 | 'Content-Type': 'application/json' |
| 1189 | }, |
| 1190 | withCredentials: true |
| 1191 | }) |
| 1192 | .then(function(response) { |
| 1193 | return response.data; |
| 1194 | }); |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 1195 | }, |
| 1196 | getHardwares: function(callback) { |
| 1197 | $http({ |
| 1198 | method: 'GET', |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 1199 | url: DataService.getHost() + |
| 1200 | '/xyz/openbmc_project/inventory/enumerate', |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 1201 | headers: { |
| 1202 | 'Accept': 'application/json', |
| 1203 | 'Content-Type': 'application/json' |
| 1204 | }, |
| 1205 | withCredentials: true |
| 1206 | }).then(function(response) { |
| 1207 | var json = JSON.stringify(response.data); |
| 1208 | var content = JSON.parse(json); |
| 1209 | var hardwareData = []; |
| 1210 | var keyIndexMap = {}; |
| 1211 | var title = ''; |
| 1212 | var data = []; |
| 1213 | var searchText = ''; |
| 1214 | var componentIndex = -1; |
| 1215 | var tempParts = []; |
| 1216 | |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 1217 | function isSubComponent(key) { |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 1218 | for (var i = 0; i < Constants.HARDWARE.parent_components.length; |
| 1219 | i++) { |
| 1220 | if (key.split(Constants.HARDWARE.parent_components[i]).length == |
| 1221 | 2) |
| 1222 | return true; |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 1223 | } |
| 1224 | |
| 1225 | return false; |
| 1226 | } |
| 1227 | |
| 1228 | function titlelize(title) { |
| 1229 | title = title.replace(/([A-Z0-9]+)/g, ' $1').replace(/^\s+/, ''); |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 1230 | for (var i = 0; i < Constants.HARDWARE.uppercase_titles.length; |
| 1231 | i++) { |
| 1232 | if (title.toLowerCase().indexOf( |
| 1233 | (Constants.HARDWARE.uppercase_titles[i] + ' ')) > -1) { |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 1234 | return title.toUpperCase(); |
| 1235 | } |
| 1236 | } |
| 1237 | |
| 1238 | return title; |
| 1239 | } |
| 1240 | |
| 1241 | function camelcaseToLabel(obj) { |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 1242 | var transformed = [], label = '', value = ''; |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 1243 | for (var key in obj) { |
| 1244 | label = key.replace(/([A-Z0-9]+)/g, ' $1').replace(/^\s+/, ''); |
| 1245 | if (obj[key] !== '') { |
| 1246 | value = obj[key]; |
| 1247 | if (value == 1 || value == 0) { |
| 1248 | value = (value == 1) ? 'Yes' : 'No'; |
| 1249 | } |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 1250 | transformed.push({key: label, value: value}); |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 1251 | } |
| 1252 | } |
| 1253 | |
| 1254 | return transformed; |
| 1255 | } |
| 1256 | |
| 1257 | function getSearchText(data) { |
| 1258 | var searchText = ''; |
| 1259 | for (var i = 0; i < data.length; i++) { |
| 1260 | searchText += ' ' + data[i].key + ' ' + data[i].value; |
| 1261 | } |
| 1262 | |
| 1263 | return searchText; |
| 1264 | } |
| 1265 | |
| 1266 | for (var key in content.data) { |
| 1267 | if (content.data.hasOwnProperty(key) && |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 1268 | key.indexOf(Constants.HARDWARE.component_key_filter) == 0) { |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 1269 | data = camelcaseToLabel(content.data[key]); |
| 1270 | searchText = getSearchText(data); |
| 1271 | title = key.split('/').pop(); |
| 1272 | |
| 1273 | title = titlelize(title); |
| 1274 | |
| 1275 | if (!isSubComponent(key)) { |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 1276 | hardwareData.push(Object.assign( |
| 1277 | { |
| 1278 | path: key, |
| 1279 | title: title, |
| 1280 | selected: false, |
| 1281 | expanded: false, |
| 1282 | search_text: title.toLowerCase() + ' ' + |
| 1283 | searchText.toLowerCase(), |
| 1284 | sub_components: [], |
| 1285 | original_data: {key: key, value: content.data[key]} |
| 1286 | }, |
| 1287 | {items: data})); |
Iftekharul Islam | 2a48955 | 2017-11-02 13:23:08 -0500 | [diff] [blame] | 1288 | |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 1289 | keyIndexMap[key] = hardwareData.length - 1; |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 1290 | } else { |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 1291 | var tempParts = key.split('/'); |
| 1292 | tempParts.pop(); |
| 1293 | tempParts = tempParts.join('/'); |
| 1294 | componentIndex = keyIndexMap[tempParts]; |
| 1295 | data = content.data[key]; |
| 1296 | data.title = title; |
| 1297 | hardwareData[componentIndex].sub_components.push(data); |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 1298 | hardwareData[componentIndex].search_text += |
| 1299 | ' ' + title.toLowerCase(); |
Iftekharul Islam | 171c6a1 | 2017-08-11 08:35:47 -0500 | [diff] [blame] | 1300 | |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 1301 | // Sort the subcomponents alphanumeric so they are displayed |
| 1302 | // on the inventory page in order (e.g. core 0, core 1, core |
| 1303 | // 2, ... core 12, core 13) |
| 1304 | hardwareData[componentIndex].sub_components.sort(function( |
| 1305 | a, b) { |
| 1306 | return a.title.localeCompare( |
| 1307 | b.title, 'en', {numeric: true}); |
Gunnar Mills | 55a8e39 | 2018-03-14 15:37:44 -0500 | [diff] [blame] | 1308 | }); |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 1309 | } |
| 1310 | } |
| 1311 | } |
| 1312 | |
| 1313 | if (callback) { |
| 1314 | callback(hardwareData, content.data); |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 1315 | } else { |
| 1316 | return {data: hardwareData, original_data: content.data}; |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 1317 | } |
| 1318 | }); |
| 1319 | }, |
| 1320 | deleteLogs: function(logs) { |
| 1321 | var defer = $q.defer(); |
| 1322 | var promises = []; |
| 1323 | |
| 1324 | function finished() { |
| 1325 | defer.resolve(); |
| 1326 | } |
| 1327 | |
| 1328 | logs.forEach(function(item) { |
| 1329 | promises.push($http({ |
| 1330 | method: 'POST', |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 1331 | url: DataService.getHost() + |
| 1332 | '/xyz/openbmc_project/logging/entry/' + item.Id + |
| 1333 | '/action/Delete', |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 1334 | headers: { |
| 1335 | 'Accept': 'application/json', |
| 1336 | 'Content-Type': 'application/json' |
Gunnar Mills | 55a8e39 | 2018-03-14 15:37:44 -0500 | [diff] [blame] | 1337 | }, |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 1338 | withCredentials: true, |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 1339 | data: JSON.stringify({'data': []}) |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 1340 | })); |
| 1341 | }); |
| 1342 | |
| 1343 | $q.all(promises).then(finished); |
| 1344 | |
| 1345 | return defer.promise; |
| 1346 | }, |
| 1347 | resolveLogs: function(logs) { |
| 1348 | var defer = $q.defer(); |
| 1349 | var promises = []; |
| 1350 | |
| 1351 | function finished() { |
| 1352 | defer.resolve(); |
| 1353 | } |
| 1354 | |
| 1355 | logs.forEach(function(item) { |
| 1356 | promises.push($http({ |
| 1357 | method: 'PUT', |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 1358 | url: DataService.getHost() + |
| 1359 | '/xyz/openbmc_project/logging/entry/' + item.Id + |
| 1360 | '/attr/Resolved', |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 1361 | headers: { |
| 1362 | 'Accept': 'application/json', |
| 1363 | 'Content-Type': 'application/json' |
Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 1364 | }, |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 1365 | withCredentials: true, |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 1366 | data: JSON.stringify({'data': '1'}) |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 1367 | })); |
| 1368 | }); |
Iftekharul Islam | a1d238f | 2018-02-26 12:29:45 -0600 | [diff] [blame] | 1369 | |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 1370 | $q.all(promises).then(finished); |
Iftekharul Islam | cd78950 | 2017-04-19 14:37:55 -0500 | [diff] [blame] | 1371 | |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 1372 | return defer.promise; |
| 1373 | }, |
| 1374 | getPowerConsumption: function() { |
| 1375 | return $http({ |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 1376 | method: 'GET', |
| 1377 | url: DataService.getHost() + |
| 1378 | '/xyz/openbmc_project/sensors/power/total_power', |
| 1379 | headers: { |
| 1380 | 'Accept': 'application/json', |
| 1381 | 'Content-Type': 'application/json' |
| 1382 | }, |
| 1383 | withCredentials: true |
| 1384 | }) |
| 1385 | .then( |
| 1386 | function(response) { |
| 1387 | var json = JSON.stringify(response.data); |
| 1388 | var content = JSON.parse(json); |
Iftekharul Islam | cd78950 | 2017-04-19 14:37:55 -0500 | [diff] [blame] | 1389 | |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 1390 | return getScaledValue( |
| 1391 | content.data.Value, content.data.Scale) + |
| 1392 | ' ' + |
| 1393 | Constants.POWER_CONSUMPTION_TEXT[content.data.Unit]; |
| 1394 | }, |
| 1395 | function(error) { |
| 1396 | if ('Not Found' == error.statusText) { |
| 1397 | return Constants.POWER_CONSUMPTION_TEXT.notavailable; |
| 1398 | } else { |
| 1399 | throw error; |
| 1400 | } |
| 1401 | }); |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 1402 | }, |
| 1403 | getPowerCap: function() { |
| 1404 | return $http({ |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 1405 | method: 'GET', |
| 1406 | url: DataService.getHost() + |
| 1407 | '/xyz/openbmc_project/control/host0/power_cap', |
| 1408 | headers: { |
| 1409 | 'Accept': 'application/json', |
| 1410 | 'Content-Type': 'application/json' |
| 1411 | }, |
| 1412 | withCredentials: true |
| 1413 | }) |
| 1414 | .then(function(response) { |
| 1415 | var json = JSON.stringify(response.data); |
| 1416 | var content = JSON.parse(json); |
Michael Davis | df3bd12 | 2017-08-10 11:03:42 -0500 | [diff] [blame] | 1417 | |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 1418 | return (false == content.data.PowerCapEnable) ? |
| 1419 | Constants.POWER_CAP_TEXT.disabled : |
| 1420 | content.data.PowerCap + ' ' + Constants.POWER_CAP_TEXT.unit; |
| 1421 | }); |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 1422 | }, |
| 1423 | setHostname: function(hostname) { |
| 1424 | return $http({ |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 1425 | method: 'PUT', |
| 1426 | url: DataService.getHost() + |
| 1427 | '/xyz/openbmc_project/network/config/attr/HostName', |
| 1428 | headers: { |
| 1429 | 'Accept': 'application/json', |
| 1430 | 'Content-Type': 'application/json' |
| 1431 | }, |
| 1432 | withCredentials: true, |
| 1433 | data: JSON.stringify({'data': hostname}) |
| 1434 | }) |
| 1435 | .then(function(response) { |
| 1436 | return response.data; |
| 1437 | }); |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 1438 | }, |
| 1439 | }; |
| 1440 | return SERVICE; |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 1441 | } |
| 1442 | ]); |
Iftekharul Islam | d2269e2 | 2017-05-02 09:32:45 -0500 | [diff] [blame] | 1443 | |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 1444 | })(window.angular); |