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