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