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 |
| 7 | * @version 0.0.1 |
| 8 | */ |
| 9 | |
| 10 | window.angular && (function (angular) { |
| 11 | 'use strict'; |
| 12 | angular |
| 13 | .module('app.common.services') |
Iftekharul Islam | 1acb412 | 2017-11-02 13:20:32 -0500 | [diff] [blame] | 14 | .factory('APIUtils', ['$http', 'Constants', '$q', 'dataService',function($http, Constants, $q, DataService){ |
CamVan Nguyen | 3327583 | 2018-03-13 18:38:37 -0500 | [diff] [blame] | 15 | var getScaledValue = function(value, scale){ |
| 16 | scale = scale + ""; |
| 17 | scale = parseInt(scale, 10); |
| 18 | var power = Math.abs(parseInt(scale,10)); |
| 19 | |
| 20 | if(scale > 0){ |
| 21 | value = value * Math.pow(10, power); |
| 22 | }else if(scale < 0){ |
| 23 | value = value / Math.pow(10, power); |
| 24 | } |
| 25 | return value; |
| 26 | }; |
Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 27 | var SERVICE = { |
Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 28 | API_CREDENTIALS: Constants.API_CREDENTIALS, |
| 29 | API_RESPONSE: Constants.API_RESPONSE, |
| 30 | CHASSIS_POWER_STATE: Constants.CHASSIS_POWER_STATE, |
| 31 | HOST_STATE_TEXT: Constants.HOST_STATE, |
| 32 | HOST_STATE: Constants.HOST_STATE, |
Iftekharul Islam | cd78950 | 2017-04-19 14:37:55 -0500 | [diff] [blame] | 33 | LED_STATE: Constants.LED_STATE, |
| 34 | LED_STATE_TEXT: Constants.LED_STATE_TEXT, |
Iftekharul Islam | 1acb412 | 2017-11-02 13:20:32 -0500 | [diff] [blame] | 35 | HOST_SESSION_STORAGE_KEY: Constants.API_CREDENTIALS.host_storage_key, |
Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 36 | getChassisState: function(callback){ |
| 37 | $http({ |
| 38 | method: 'GET', |
Iftekharul Islam | 1acb412 | 2017-11-02 13:20:32 -0500 | [diff] [blame] | 39 | url: DataService.getHost() + "/xyz/openbmc_project/state/chassis0", |
Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 40 | headers: { |
| 41 | 'Accept': 'application/json', |
| 42 | 'Content-Type': 'application/json' |
| 43 | }, |
| 44 | withCredentials: true |
Ed Tanous | bbcf670 | 2017-10-06 13:53:06 -0700 | [diff] [blame] | 45 | }).then(function(response){ |
| 46 | var json = JSON.stringify(response.data); |
Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 47 | var content = JSON.parse(json); |
| 48 | callback(content.data.CurrentPowerState); |
Ed Tanous | bbcf670 | 2017-10-06 13:53:06 -0700 | [diff] [blame] | 49 | }, function(error){ |
Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 50 | console.log(error); |
| 51 | }); |
| 52 | }, |
| 53 | getHostState: function(callback){ |
| 54 | $http({ |
| 55 | method: 'GET', |
Iftekharul Islam | 1acb412 | 2017-11-02 13:20:32 -0500 | [diff] [blame] | 56 | url: DataService.getHost() + "/xyz/openbmc_project/state/host0", |
Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 57 | headers: { |
| 58 | 'Accept': 'application/json', |
| 59 | 'Content-Type': 'application/json' |
| 60 | }, |
| 61 | withCredentials: true |
Ed Tanous | bbcf670 | 2017-10-06 13:53:06 -0700 | [diff] [blame] | 62 | }).then(function(response){ |
| 63 | var json = JSON.stringify(response.data); |
Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 64 | var content = JSON.parse(json); |
| 65 | callback(content.data.CurrentHostState); |
Ed Tanous | bbcf670 | 2017-10-06 13:53:06 -0700 | [diff] [blame] | 66 | }, function(error){ |
Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 67 | console.log(error); |
| 68 | }); |
| 69 | }, |
Iftekharul Islam | 171c6a1 | 2017-08-11 08:35:47 -0500 | [diff] [blame] | 70 | getNetworkInfo: function(){ |
| 71 | var deferred = $q.defer(); |
| 72 | $http({ |
| 73 | method: 'GET', |
Iftekharul Islam | 1acb412 | 2017-11-02 13:20:32 -0500 | [diff] [blame] | 74 | url: DataService.getHost() + "/xyz/openbmc_project/network/enumerate", |
Iftekharul Islam | 171c6a1 | 2017-08-11 08:35:47 -0500 | [diff] [blame] | 75 | headers: { |
| 76 | 'Accept': 'application/json', |
| 77 | 'Content-Type': 'application/json' |
| 78 | }, |
| 79 | withCredentials: true |
Ed Tanous | bbcf670 | 2017-10-06 13:53:06 -0700 | [diff] [blame] | 80 | }).then(function(response){ |
| 81 | var json = JSON.stringify(response.data); |
Iftekharul Islam | 171c6a1 | 2017-08-11 08:35:47 -0500 | [diff] [blame] | 82 | var content = JSON.parse(json); |
| 83 | var hostname = ""; |
| 84 | var macAddress = ""; |
| 85 | |
Iftekharul Islam | 2a48955 | 2017-11-02 13:23:08 -0500 | [diff] [blame] | 86 | function parseNetworkData(content){ |
| 87 | var data = { |
| 88 | interface_ids: [], |
| 89 | interfaces: { |
| 90 | } |
| 91 | }; |
| 92 | var interfaceId = '', keyParts = [], interfaceHash = '', interfaceType = ''; |
| 93 | for(var key in content.data){ |
| 94 | if(key.match(/network\/eth\d+$/ig)){ |
| 95 | interfaceId = key.split("/").pop(); |
| 96 | if(data.interface_ids.indexOf(interfaceId) == -1){ |
| 97 | data.interface_ids.push(interfaceId); |
| 98 | data.interfaces[interfaceId] = { |
| 99 | interfaceIname: '', |
| 100 | domainName:'', |
| 101 | MACAddress:'', |
| 102 | Nameservers: [], |
| 103 | DHCPEnabled: 0, |
| 104 | ipv4: |
| 105 | { |
| 106 | ids: [], |
| 107 | values: [] |
| 108 | }, |
| 109 | ipv6: |
| 110 | { |
| 111 | ids: [], |
| 112 | values: [] |
| 113 | } |
| 114 | }; |
| 115 | data.interfaces[interfaceId].MACAddress = content.data[key].MACAddress; |
| 116 | data.interfaces[interfaceId].DomainName = content.data[key].DomainName.join(" "); |
| 117 | data.interfaces[interfaceId].Nameservers = content.data[key].Nameservers; |
| 118 | data.interfaces[interfaceId].DHCPEnabled = content.data[key].DHCPEnabled; |
| 119 | } |
| 120 | }else if(key.match(/network\/eth\d+\/ipv[4|6]\/[a-z0-9]+$/ig)){ |
| 121 | keyParts = key.split("/"); |
| 122 | interfaceHash = keyParts.pop(); |
| 123 | interfaceType = keyParts.pop(); |
| 124 | interfaceId = keyParts.pop(); |
| 125 | |
| 126 | if(data.interfaces[interfaceId][interfaceType].ids.indexOf(interfaceHash) == -1){ |
| 127 | data.interfaces[interfaceId][interfaceType].ids.push(interfaceHash); |
| 128 | data.interfaces[interfaceId][interfaceType].values.push(content.data[key]); |
| 129 | } |
| 130 | } |
| 131 | } |
| 132 | return data; |
| 133 | } |
| 134 | |
Iftekharul Islam | 171c6a1 | 2017-08-11 08:35:47 -0500 | [diff] [blame] | 135 | if(content.data.hasOwnProperty('/xyz/openbmc_project/network/config') && |
| 136 | content.data['/xyz/openbmc_project/network/config'].hasOwnProperty('HostName') |
| 137 | ){ |
| 138 | hostname = content.data['/xyz/openbmc_project/network/config'].HostName; |
| 139 | } |
| 140 | |
| 141 | if(content.data.hasOwnProperty('/xyz/openbmc_project/network/eth0') && |
| 142 | content.data['/xyz/openbmc_project/network/eth0'].hasOwnProperty('MACAddress') |
| 143 | ){ |
| 144 | macAddress = content.data['/xyz/openbmc_project/network/eth0'].MACAddress; |
| 145 | } |
| 146 | |
| 147 | deferred.resolve({ |
| 148 | data: content.data, |
| 149 | hostname: hostname, |
| 150 | mac_address: macAddress, |
Iftekharul Islam | 2a48955 | 2017-11-02 13:23:08 -0500 | [diff] [blame] | 151 | formatted_data: parseNetworkData(content) |
Iftekharul Islam | 171c6a1 | 2017-08-11 08:35:47 -0500 | [diff] [blame] | 152 | }); |
Ed Tanous | bbcf670 | 2017-10-06 13:53:06 -0700 | [diff] [blame] | 153 | }, function(error){ |
Iftekharul Islam | 171c6a1 | 2017-08-11 08:35:47 -0500 | [diff] [blame] | 154 | console.log(error); |
| 155 | deferred.reject(error); |
| 156 | }); |
| 157 | return deferred.promise; |
| 158 | }, |
Michael Davis | df3bd12 | 2017-08-10 11:03:42 -0500 | [diff] [blame] | 159 | getLEDState: function(){ |
| 160 | var deferred = $q.defer(); |
Iftekharul Islam | cd78950 | 2017-04-19 14:37:55 -0500 | [diff] [blame] | 161 | $http({ |
| 162 | method: 'GET', |
Iftekharul Islam | 1acb412 | 2017-11-02 13:20:32 -0500 | [diff] [blame] | 163 | url: DataService.getHost() + "/xyz/openbmc_project/led/groups/enclosure_identify", |
Iftekharul Islam | cd78950 | 2017-04-19 14:37:55 -0500 | [diff] [blame] | 164 | headers: { |
| 165 | 'Accept': 'application/json', |
| 166 | 'Content-Type': 'application/json' |
| 167 | }, |
| 168 | withCredentials: true |
Ed Tanous | bbcf670 | 2017-10-06 13:53:06 -0700 | [diff] [blame] | 169 | }).then(function(response){ |
| 170 | var json = JSON.stringify(response.data); |
Michael Davis | df3bd12 | 2017-08-10 11:03:42 -0500 | [diff] [blame] | 171 | var content = JSON.parse(json); |
| 172 | deferred.resolve(content.data.Asserted); |
Ed Tanous | bbcf670 | 2017-10-06 13:53:06 -0700 | [diff] [blame] | 173 | }, function(error){ |
Iftekharul Islam | cd78950 | 2017-04-19 14:37:55 -0500 | [diff] [blame] | 174 | console.log(error); |
Michael Davis | df3bd12 | 2017-08-10 11:03:42 -0500 | [diff] [blame] | 175 | deferred.reject(error); |
Iftekharul Islam | cd78950 | 2017-04-19 14:37:55 -0500 | [diff] [blame] | 176 | }); |
Michael Davis | df3bd12 | 2017-08-10 11:03:42 -0500 | [diff] [blame] | 177 | return deferred.promise; |
Iftekharul Islam | cd78950 | 2017-04-19 14:37:55 -0500 | [diff] [blame] | 178 | }, |
Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 179 | login: function(username, password, callback){ |
| 180 | $http({ |
| 181 | method: 'POST', |
Iftekharul Islam | 1acb412 | 2017-11-02 13:20:32 -0500 | [diff] [blame] | 182 | url: DataService.getHost() + "/login", |
Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 183 | headers: { |
| 184 | 'Accept': 'application/json', |
| 185 | 'Content-Type': 'application/json' |
| 186 | }, |
| 187 | withCredentials: true, |
| 188 | data: JSON.stringify({"data": [username, password]}) |
Ed Tanous | bbcf670 | 2017-10-06 13:53:06 -0700 | [diff] [blame] | 189 | }).then(function(response){ |
Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 190 | if(callback){ |
Ed Tanous | bbcf670 | 2017-10-06 13:53:06 -0700 | [diff] [blame] | 191 | callback(response.data); |
Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 192 | } |
Ed Tanous | bbcf670 | 2017-10-06 13:53:06 -0700 | [diff] [blame] | 193 | }, function(error){ |
Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 194 | if(callback){ |
Iftekharul Islam | cd78950 | 2017-04-19 14:37:55 -0500 | [diff] [blame] | 195 | if(error && error.status && error.status == 'error'){ |
| 196 | callback(error); |
| 197 | }else{ |
| 198 | callback(error, true); |
| 199 | } |
Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 200 | } |
| 201 | console.log(error); |
| 202 | }); |
| 203 | }, |
Gunnar Mills | 32581cf | 2018-03-16 15:52:54 -0500 | [diff] [blame] | 204 | testPassword: function(username, password){ |
| 205 | // Calls /login without the current session to verify the given password is correct |
| 206 | // ignore the interceptor logout on a bad password |
| 207 | DataService.ignoreHttpError = true; |
Gunnar Mills | 7c3e8c1 | 2018-03-28 16:16:58 -0500 | [diff] [blame] | 208 | return $http({ |
Gunnar Mills | 32581cf | 2018-03-16 15:52:54 -0500 | [diff] [blame] | 209 | method: 'POST', |
| 210 | url: DataService.getHost() + "/login", |
| 211 | headers: { |
| 212 | 'Accept': 'application/json', |
| 213 | 'Content-Type': 'application/json' |
| 214 | }, |
| 215 | withCredentials: false, |
| 216 | data: JSON.stringify({"data": [username, password]}) |
| 217 | }).then(function(response){ |
Gunnar Mills | 7c3e8c1 | 2018-03-28 16:16:58 -0500 | [diff] [blame] | 218 | return response.data; |
Gunnar Mills | 32581cf | 2018-03-16 15:52:54 -0500 | [diff] [blame] | 219 | }); |
Gunnar Mills | 32581cf | 2018-03-16 15:52:54 -0500 | [diff] [blame] | 220 | }, |
Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 221 | logout: function(callback){ |
| 222 | $http({ |
| 223 | method: 'POST', |
Iftekharul Islam | 1acb412 | 2017-11-02 13:20:32 -0500 | [diff] [blame] | 224 | url: DataService.getHost() + "/logout", |
Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 225 | headers: { |
| 226 | 'Accept': 'application/json', |
| 227 | 'Content-Type': 'application/json' |
| 228 | }, |
| 229 | withCredentials: true, |
| 230 | data: JSON.stringify({"data": []}) |
Ed Tanous | bbcf670 | 2017-10-06 13:53:06 -0700 | [diff] [blame] | 231 | }).then(function(response){ |
Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 232 | if(callback){ |
Iftekharul Islam | de88340 | 2018-02-05 11:16:21 -0600 | [diff] [blame] | 233 | callback(response.data); |
Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 234 | } |
Ed Tanous | bbcf670 | 2017-10-06 13:53:06 -0700 | [diff] [blame] | 235 | }, function(error){ |
Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 236 | if(callback){ |
| 237 | callback(null, error); |
| 238 | } |
| 239 | console.log(error); |
| 240 | }); |
| 241 | }, |
Gunnar Mills | 55a8e39 | 2018-03-14 15:37:44 -0500 | [diff] [blame] | 242 | changePassword: function(user, newPassword){ |
| 243 | var deferred = $q.defer(); |
| 244 | $http({ |
| 245 | method: 'POST', |
| 246 | url: DataService.getHost() + "/xyz/openbmc_project/user/" + user + "/action/SetPassword", |
| 247 | headers: { |
| 248 | 'Accept': 'application/json', |
| 249 | 'Content-Type': 'application/json' |
| 250 | }, |
| 251 | withCredentials: true, |
| 252 | data: JSON.stringify({"data": [newPassword]}), |
| 253 | responseType: 'arraybuffer' |
| 254 | }).then(function(response, status, headers){ |
| 255 | deferred.resolve({ |
| 256 | data: response, |
| 257 | status: status, |
| 258 | headers: headers |
| 259 | }); |
| 260 | }, function(error){ |
| 261 | console.log(error); |
| 262 | deferred.reject(error); |
| 263 | }); |
| 264 | return deferred.promise; |
| 265 | }, |
Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 266 | chassisPowerOn: function(callback){ |
| 267 | $http({ |
| 268 | method: 'POST', |
Iftekharul Islam | 1acb412 | 2017-11-02 13:20:32 -0500 | [diff] [blame] | 269 | url: DataService.getHost() + "/xyz/openbmc_project/state/host0", |
Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 270 | headers: { |
| 271 | 'Accept': 'application/json', |
| 272 | 'Content-Type': 'application/json' |
| 273 | }, |
| 274 | withCredentials: true, |
| 275 | data: JSON.stringify({"data": []}) |
Ed Tanous | bbcf670 | 2017-10-06 13:53:06 -0700 | [diff] [blame] | 276 | }).then(function(response){ |
| 277 | var json = JSON.stringify(response.data); |
Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 278 | var content = JSON.parse(json); |
| 279 | if(callback){ |
| 280 | return callback(content.data.CurrentPowerState); |
| 281 | } |
Ed Tanous | bbcf670 | 2017-10-06 13:53:06 -0700 | [diff] [blame] | 282 | }, function(error){ |
Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 283 | if(callback){ |
| 284 | callback(error); |
| 285 | }else{ |
| 286 | console.log(error); |
| 287 | } |
| 288 | }); |
| 289 | }, |
| 290 | chassisPowerOff: function(callback){ |
| 291 | $http({ |
Gunnar Mills | 3aa8b53 | 2018-02-06 15:42:29 -0600 | [diff] [blame] | 292 | method: 'PUT', |
| 293 | url: DataService.getHost() + "/xyz/openbmc_project/state/chassis0/attr/RequestedPowerTransition", |
Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 294 | headers: { |
| 295 | 'Accept': 'application/json', |
| 296 | 'Content-Type': 'application/json' |
| 297 | }, |
| 298 | withCredentials: true, |
Gunnar Mills | 3aa8b53 | 2018-02-06 15:42:29 -0600 | [diff] [blame] | 299 | data: JSON.stringify({"data": "xyz.openbmc_project.State.Chassis.Transition.Off"}) |
Ed Tanous | bbcf670 | 2017-10-06 13:53:06 -0700 | [diff] [blame] | 300 | }).then(function(response){ |
| 301 | var json = JSON.stringify(response.data); |
Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 302 | var content = JSON.parse(json); |
| 303 | if(callback){ |
Gunnar Mills | 3aa8b53 | 2018-02-06 15:42:29 -0600 | [diff] [blame] | 304 | return callback(content.status); |
Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 305 | } |
Ed Tanous | bbcf670 | 2017-10-06 13:53:06 -0700 | [diff] [blame] | 306 | }, function(error){ |
Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 307 | if(callback){ |
| 308 | callback(error); |
| 309 | }else{ |
| 310 | console.log(error); |
| 311 | } |
| 312 | }); |
| 313 | }, |
Iftekharul Islam | cd78950 | 2017-04-19 14:37:55 -0500 | [diff] [blame] | 314 | setLEDState: function(state, callback){ |
| 315 | $http({ |
| 316 | method: 'PUT', |
Iftekharul Islam | 1acb412 | 2017-11-02 13:20:32 -0500 | [diff] [blame] | 317 | url: DataService.getHost() + "/xyz/openbmc_project/led/groups/enclosure_identify/attr/Asserted", |
Iftekharul Islam | cd78950 | 2017-04-19 14:37:55 -0500 | [diff] [blame] | 318 | headers: { |
| 319 | 'Accept': 'application/json', |
| 320 | 'Content-Type': 'application/json' |
| 321 | }, |
| 322 | withCredentials: true, |
| 323 | data: JSON.stringify({"data": state}) |
Ed Tanous | bbcf670 | 2017-10-06 13:53:06 -0700 | [diff] [blame] | 324 | }).then(function(response){ |
| 325 | var json = JSON.stringify(response.data); |
Iftekharul Islam | cd78950 | 2017-04-19 14:37:55 -0500 | [diff] [blame] | 326 | var content = JSON.parse(json); |
| 327 | if(callback){ |
| 328 | return callback(content.status); |
| 329 | } |
Ed Tanous | bbcf670 | 2017-10-06 13:53:06 -0700 | [diff] [blame] | 330 | }, function(error){ |
Iftekharul Islam | cd78950 | 2017-04-19 14:37:55 -0500 | [diff] [blame] | 331 | if(callback){ |
| 332 | callback(error); |
| 333 | }else{ |
| 334 | console.log(error); |
| 335 | } |
| 336 | }); |
| 337 | }, |
Iftekharul Islam | 5536812 | 2017-03-27 09:46:50 -0500 | [diff] [blame] | 338 | bmcReboot: function(callback){ |
| 339 | $http({ |
| 340 | method: 'PUT', |
Iftekharul Islam | 1acb412 | 2017-11-02 13:20:32 -0500 | [diff] [blame] | 341 | url: DataService.getHost() + "/xyz/openbmc_project/state/bmc0/attr/RequestedBmcTransition", |
Iftekharul Islam | 5536812 | 2017-03-27 09:46:50 -0500 | [diff] [blame] | 342 | headers: { |
| 343 | 'Accept': 'application/json', |
| 344 | 'Content-Type': 'application/json' |
| 345 | }, |
| 346 | withCredentials: true, |
| 347 | data: JSON.stringify({"data": "xyz.openbmc_project.State.BMC.Transition.Reboot"}) |
Ed Tanous | bbcf670 | 2017-10-06 13:53:06 -0700 | [diff] [blame] | 348 | }).then(function(response){ |
| 349 | var json = JSON.stringify(response.data); |
Iftekharul Islam | 5536812 | 2017-03-27 09:46:50 -0500 | [diff] [blame] | 350 | var content = JSON.parse(json); |
| 351 | if(callback){ |
| 352 | return callback(content.status); |
| 353 | } |
Ed Tanous | bbcf670 | 2017-10-06 13:53:06 -0700 | [diff] [blame] | 354 | }, function(error){ |
Iftekharul Islam | 5536812 | 2017-03-27 09:46:50 -0500 | [diff] [blame] | 355 | if(callback){ |
| 356 | callback(error); |
| 357 | }else{ |
| 358 | console.log(error); |
| 359 | } |
| 360 | }); |
| 361 | }, |
Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 362 | hostPowerOn: function(callback){ |
Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 363 | $http({ |
| 364 | method: 'PUT', |
Iftekharul Islam | 1acb412 | 2017-11-02 13:20:32 -0500 | [diff] [blame] | 365 | url: DataService.getHost() + "/xyz/openbmc_project/state/host0/attr/RequestedHostTransition", |
Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 366 | headers: { |
| 367 | 'Accept': 'application/json', |
| 368 | 'Content-Type': 'application/json' |
| 369 | }, |
| 370 | withCredentials: true, |
| 371 | data: JSON.stringify({"data": "xyz.openbmc_project.State.Host.Transition.On"}) |
Ed Tanous | bbcf670 | 2017-10-06 13:53:06 -0700 | [diff] [blame] | 372 | }).then(function(response){ |
| 373 | var json = JSON.stringify(response.data); |
Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 374 | var content = JSON.parse(json); |
| 375 | if(callback){ |
| 376 | return callback(content.status); |
| 377 | } |
Ed Tanous | bbcf670 | 2017-10-06 13:53:06 -0700 | [diff] [blame] | 378 | }, function(error){ |
Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 379 | if(callback){ |
| 380 | callback(error); |
| 381 | }else{ |
| 382 | console.log(error); |
| 383 | } |
| 384 | }); |
| 385 | }, |
| 386 | hostPowerOff: function(callback){ |
| 387 | $http({ |
| 388 | method: 'PUT', |
Iftekharul Islam | 1acb412 | 2017-11-02 13:20:32 -0500 | [diff] [blame] | 389 | url: DataService.getHost() + "/xyz/openbmc_project/state/host0/attr/RequestedHostTransition", |
Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 390 | headers: { |
| 391 | 'Accept': 'application/json', |
| 392 | 'Content-Type': 'application/json' |
| 393 | }, |
| 394 | withCredentials: true, |
| 395 | data: JSON.stringify({"data": "xyz.openbmc_project.State.Host.Transition.Off"}) |
Ed Tanous | bbcf670 | 2017-10-06 13:53:06 -0700 | [diff] [blame] | 396 | }).then(function(response){ |
| 397 | var json = JSON.stringify(response.data); |
Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 398 | var content = JSON.parse(json); |
| 399 | if(callback){ |
| 400 | return callback(content.status); |
| 401 | } |
Ed Tanous | bbcf670 | 2017-10-06 13:53:06 -0700 | [diff] [blame] | 402 | }, function(error){ |
Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 403 | if(callback){ |
| 404 | callback(error); |
| 405 | }else{ |
| 406 | console.log(error); |
| 407 | } |
| 408 | }); |
| 409 | }, |
| 410 | hostReboot: function(callback){ |
| 411 | $http({ |
Gunnar Mills | cacfa6d | 2018-02-07 12:09:02 -0600 | [diff] [blame] | 412 | method: 'PUT', |
| 413 | url: DataService.getHost() + "/xyz/openbmc_project/state/host0/attr/RequestedHostTransition", |
Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 414 | headers: { |
| 415 | 'Accept': 'application/json', |
| 416 | 'Content-Type': 'application/json' |
| 417 | }, |
| 418 | withCredentials: true, |
Gunnar Mills | cacfa6d | 2018-02-07 12:09:02 -0600 | [diff] [blame] | 419 | data: JSON.stringify({"data": "xyz.openbmc_project.State.Host.Transition.Reboot"}) |
Ed Tanous | bbcf670 | 2017-10-06 13:53:06 -0700 | [diff] [blame] | 420 | }).then(function(response){ |
| 421 | var json = JSON.stringify(response.data); |
Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 422 | var content = JSON.parse(json); |
| 423 | if(callback){ |
Gunnar Mills | cacfa6d | 2018-02-07 12:09:02 -0600 | [diff] [blame] | 424 | return callback(content.status); |
Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 425 | } |
Ed Tanous | bbcf670 | 2017-10-06 13:53:06 -0700 | [diff] [blame] | 426 | }, function(error){ |
Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 427 | if(callback){ |
| 428 | callback(error); |
| 429 | }else{ |
| 430 | console.log(error); |
| 431 | } |
| 432 | }); |
| 433 | }, |
| 434 | hostShutdown: function(callback){ |
| 435 | $http({ |
| 436 | method: 'POST', |
Iftekharul Islam | 1acb412 | 2017-11-02 13:20:32 -0500 | [diff] [blame] | 437 | url: DataService.getHost() + "/xyz/openbmc_project/state/host0", |
Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 438 | headers: { |
| 439 | 'Accept': 'application/json', |
| 440 | 'Content-Type': 'application/json' |
| 441 | }, |
| 442 | withCredentials: true, |
| 443 | data: JSON.stringify({"data": []}) |
Ed Tanous | bbcf670 | 2017-10-06 13:53:06 -0700 | [diff] [blame] | 444 | }).then(function(response){ |
| 445 | var json = JSON.stringify(response.data); |
Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 446 | var content = JSON.parse(json); |
| 447 | if(callback){ |
| 448 | return callback(content); |
| 449 | } |
Ed Tanous | bbcf670 | 2017-10-06 13:53:06 -0700 | [diff] [blame] | 450 | }, function(error){ |
Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 451 | if(callback){ |
| 452 | callback(error); |
| 453 | }else{ |
| 454 | console.log(error); |
| 455 | } |
| 456 | }); |
Iftekharul Islam | cd78950 | 2017-04-19 14:37:55 -0500 | [diff] [blame] | 457 | }, |
Michael Davis | df3bd12 | 2017-08-10 11:03:42 -0500 | [diff] [blame] | 458 | getLogs: function(){ |
| 459 | var deferred = $q.defer(); |
Iftekharul Islam | cd78950 | 2017-04-19 14:37:55 -0500 | [diff] [blame] | 460 | $http({ |
| 461 | method: 'GET', |
Iftekharul Islam | 1acb412 | 2017-11-02 13:20:32 -0500 | [diff] [blame] | 462 | url: DataService.getHost() + "/xyz/openbmc_project/logging/enumerate", |
Iftekharul Islam | cd78950 | 2017-04-19 14:37:55 -0500 | [diff] [blame] | 463 | headers: { |
| 464 | 'Accept': 'application/json', |
| 465 | 'Content-Type': 'application/json' |
| 466 | }, |
| 467 | withCredentials: true |
Ed Tanous | bbcf670 | 2017-10-06 13:53:06 -0700 | [diff] [blame] | 468 | }).then(function(response){ |
| 469 | var json = JSON.stringify(response.data); |
Iftekharul Islam | cd78950 | 2017-04-19 14:37:55 -0500 | [diff] [blame] | 470 | var content = JSON.parse(json); |
| 471 | var dataClone = JSON.parse(JSON.stringify(content.data)); |
| 472 | var data = []; |
| 473 | var severityCode = ''; |
| 474 | var priority = ''; |
Iftekharul Islam | ec6bcd1 | 2017-09-06 10:49:07 -0500 | [diff] [blame] | 475 | var health = ''; |
Iftekharul Islam | cd78950 | 2017-04-19 14:37:55 -0500 | [diff] [blame] | 476 | var relatedItems = []; |
| 477 | |
| 478 | for(var key in content.data){ |
| 479 | if(content.data.hasOwnProperty(key) && content.data[key].hasOwnProperty('Id')){ |
| 480 | var severityFlags = {low: false, medium: false, high: false}; |
Iftekharul Islam | ec6bcd1 | 2017-09-06 10:49:07 -0500 | [diff] [blame] | 481 | var healthFlags = {critical: false, warning: false, good: false}; |
Iftekharul Islam | cd78950 | 2017-04-19 14:37:55 -0500 | [diff] [blame] | 482 | severityCode = content.data[key].Severity.split(".").pop(); |
| 483 | priority = Constants.SEVERITY_TO_PRIORITY_MAP[severityCode]; |
| 484 | severityFlags[priority.toLowerCase()] = true; |
Iftekharul Islam | ec6bcd1 | 2017-09-06 10:49:07 -0500 | [diff] [blame] | 485 | health = Constants.SEVERITY_TO_HEALTH_MAP[severityCode]; |
| 486 | healthFlags[health.toLowerCase()] = true; |
Iftekharul Islam | cd78950 | 2017-04-19 14:37:55 -0500 | [diff] [blame] | 487 | relatedItems = []; |
| 488 | content.data[key].associations.forEach(function(item){ |
Iftekharul Islam | 532763f | 2017-04-25 09:44:40 -0500 | [diff] [blame] | 489 | relatedItems.push(item[2]); |
Iftekharul Islam | cd78950 | 2017-04-19 14:37:55 -0500 | [diff] [blame] | 490 | }); |
| 491 | |
| 492 | data.push(Object.assign({ |
| 493 | path: key, |
| 494 | copied: false, |
| 495 | priority: priority, |
| 496 | severity_code: severityCode, |
| 497 | severity_flags: severityFlags, |
Iftekharul Islam | ec6bcd1 | 2017-09-06 10:49:07 -0500 | [diff] [blame] | 498 | health_flags: healthFlags, |
Iftekharul Islam | cd78950 | 2017-04-19 14:37:55 -0500 | [diff] [blame] | 499 | additional_data: content.data[key].AdditionalData.join("\n"), |
Gunnar Mills | 43a2ed1 | 2018-02-08 15:42:30 -0600 | [diff] [blame] | 500 | type: content.data[key].Message, |
Iftekharul Islam | cd78950 | 2017-04-19 14:37:55 -0500 | [diff] [blame] | 501 | selected: false, |
Iftekharul Islam | 8b4828a | 2017-04-19 14:37:55 -0500 | [diff] [blame] | 502 | search_text: ("#" + content.data[key].Id + " " + severityCode + " " + content.data[key].Severity + " " + content.data[key].AdditionalData.join(" ")).toLowerCase(), |
Iftekharul Islam | cd78950 | 2017-04-19 14:37:55 -0500 | [diff] [blame] | 503 | meta: false, |
| 504 | confirm: false, |
| 505 | related_items: relatedItems, |
| 506 | data: {key: key, value: content.data[key]} |
| 507 | }, content.data[key])); |
| 508 | } |
| 509 | } |
Michael Davis | df3bd12 | 2017-08-10 11:03:42 -0500 | [diff] [blame] | 510 | deferred.resolve({data: data, original: dataClone}); |
Ed Tanous | bbcf670 | 2017-10-06 13:53:06 -0700 | [diff] [blame] | 511 | }, function(error){ |
Iftekharul Islam | cd78950 | 2017-04-19 14:37:55 -0500 | [diff] [blame] | 512 | console.log(error); |
Michael Davis | df3bd12 | 2017-08-10 11:03:42 -0500 | [diff] [blame] | 513 | deferred.reject(error); |
Iftekharul Islam | cd78950 | 2017-04-19 14:37:55 -0500 | [diff] [blame] | 514 | }); |
Michael Davis | df3bd12 | 2017-08-10 11:03:42 -0500 | [diff] [blame] | 515 | |
| 516 | return deferred.promise; |
Iftekharul Islam | d2269e2 | 2017-05-02 09:32:45 -0500 | [diff] [blame] | 517 | }, |
| 518 | getAllSensorStatus: function(callback){ |
Iftekharul Islam | d2269e2 | 2017-05-02 09:32:45 -0500 | [diff] [blame] | 519 | $http({ |
| 520 | method: 'GET', |
Iftekharul Islam | 1acb412 | 2017-11-02 13:20:32 -0500 | [diff] [blame] | 521 | url: DataService.getHost() + "/xyz/openbmc_project/sensors/enumerate", |
Iftekharul Islam | d2269e2 | 2017-05-02 09:32:45 -0500 | [diff] [blame] | 522 | headers: { |
| 523 | 'Accept': 'application/json', |
| 524 | 'Content-Type': 'application/json' |
| 525 | }, |
| 526 | withCredentials: true |
Ed Tanous | bbcf670 | 2017-10-06 13:53:06 -0700 | [diff] [blame] | 527 | }).then(function(response){ |
| 528 | var json = JSON.stringify(response.data); |
Iftekharul Islam | d2269e2 | 2017-05-02 09:32:45 -0500 | [diff] [blame] | 529 | var content = JSON.parse(json); |
| 530 | var dataClone = JSON.parse(JSON.stringify(content.data)); |
| 531 | var sensorData = []; |
Iftekharul Islam | 8947e70 | 2017-07-27 10:28:07 -0500 | [diff] [blame] | 532 | var severity = {}; |
| 533 | var title = ""; |
| 534 | var tempKeyParts = []; |
| 535 | var order = 0; |
Iftekharul Islam | 8a12284 | 2017-09-11 10:58:16 -0500 | [diff] [blame] | 536 | var customOrder = 0; |
Iftekharul Islam | d2269e2 | 2017-05-02 09:32:45 -0500 | [diff] [blame] | 537 | |
| 538 | function getSensorStatus(reading){ |
Iftekharul Islam | 8947e70 | 2017-07-27 10:28:07 -0500 | [diff] [blame] | 539 | var severityFlags = {critical: false, warning: false, normal: false}, severityText = '', order = 0; |
| 540 | |
Gunnar Mills | eedefd3 | 2018-02-28 17:02:34 -0600 | [diff] [blame] | 541 | if(reading.hasOwnProperty('CriticalLow') && |
Iftekharul Islam | 8947e70 | 2017-07-27 10:28:07 -0500 | [diff] [blame] | 542 | reading.Value < reading.CriticalLow |
| 543 | ){ |
Iftekharul Islam | d2269e2 | 2017-05-02 09:32:45 -0500 | [diff] [blame] | 544 | severityFlags.critical = true; |
| 545 | severityText = 'critical'; |
Iftekharul Islam | 8947e70 | 2017-07-27 10:28:07 -0500 | [diff] [blame] | 546 | order = 2; |
Gunnar Mills | eedefd3 | 2018-02-28 17:02:34 -0600 | [diff] [blame] | 547 | }else if(reading.hasOwnProperty('CriticalHigh') && |
| 548 | reading.Value > reading.CriticalHigh |
Iftekharul Islam | 8947e70 | 2017-07-27 10:28:07 -0500 | [diff] [blame] | 549 | ){ |
| 550 | severityFlags.critical = true; |
| 551 | severityText = 'critical'; |
| 552 | order = 2; |
Gunnar Mills | eedefd3 | 2018-02-28 17:02:34 -0600 | [diff] [blame] | 553 | }else if(reading.hasOwnProperty('CriticalLow') && |
| 554 | reading.hasOwnProperty('WarningLow') && |
Iftekharul Islam | 8947e70 | 2017-07-27 10:28:07 -0500 | [diff] [blame] | 555 | reading.Value >= reading.CriticalLow && reading.Value <= reading.WarningLow){ |
Iftekharul Islam | d2269e2 | 2017-05-02 09:32:45 -0500 | [diff] [blame] | 556 | severityFlags.warning = true; |
| 557 | severityText = 'warning'; |
Iftekharul Islam | 8947e70 | 2017-07-27 10:28:07 -0500 | [diff] [blame] | 558 | order = 1; |
Gunnar Mills | eedefd3 | 2018-02-28 17:02:34 -0600 | [diff] [blame] | 559 | }else if(reading.hasOwnProperty('WarningHigh') && |
| 560 | reading.hasOwnProperty('CriticalHigh') && |
Iftekharul Islam | 8947e70 | 2017-07-27 10:28:07 -0500 | [diff] [blame] | 561 | reading.Value >= reading.WarningHigh && reading.Value <= reading.CriticalHigh){ |
| 562 | severityFlags.warning = true; |
| 563 | severityText = 'warning'; |
| 564 | order = 1; |
Iftekharul Islam | d2269e2 | 2017-05-02 09:32:45 -0500 | [diff] [blame] | 565 | }else{ |
| 566 | severityFlags.normal = true; |
| 567 | severityText = 'normal'; |
| 568 | } |
Iftekharul Islam | 8947e70 | 2017-07-27 10:28:07 -0500 | [diff] [blame] | 569 | return { flags: severityFlags, severityText: severityText, order: order}; |
Iftekharul Islam | d2269e2 | 2017-05-02 09:32:45 -0500 | [diff] [blame] | 570 | } |
| 571 | |
| 572 | for(var key in content.data){ |
| 573 | if(content.data.hasOwnProperty(key) && content.data[key].hasOwnProperty('Unit')){ |
Iftekharul Islam | 8947e70 | 2017-07-27 10:28:07 -0500 | [diff] [blame] | 574 | |
| 575 | severity = getSensorStatus(content.data[key]); |
| 576 | |
| 577 | if(!content.data[key].hasOwnProperty('CriticalLow')){ |
| 578 | content.data[key].CriticalLow = "--"; |
| 579 | content.data[key].CriticalHigh = "--"; |
| 580 | } |
| 581 | |
| 582 | if(!content.data[key].hasOwnProperty('WarningLow')){ |
| 583 | content.data[key].WarningLow = "--"; |
| 584 | content.data[key].WarningHigh = "--"; |
| 585 | } |
| 586 | |
| 587 | tempKeyParts = key.split("/"); |
| 588 | title = tempKeyParts.pop(); |
| 589 | title = tempKeyParts.pop() + '_' + title; |
| 590 | title = title.split("_").map(function(item){ |
| 591 | return item.toLowerCase().charAt(0).toUpperCase() + item.slice(1); |
| 592 | }).reduce(function(prev, el){ |
| 593 | return prev + " " + el; |
| 594 | }); |
| 595 | |
Iftekharul Islam | 96bbf31 | 2017-08-22 13:44:38 -0500 | [diff] [blame] | 596 | content.data[key].Value = getScaledValue(content.data[key].Value, content.data[key].Scale); |
Gunnar Mills | 022f564 | 2018-02-07 14:30:17 -0600 | [diff] [blame] | 597 | content.data[key].CriticalLow = getScaledValue(content.data[key].CriticalLow, content.data[key].Scale); |
| 598 | content.data[key].CriticalHigh = getScaledValue(content.data[key].CriticalHigh, content.data[key].Scale); |
| 599 | content.data[key].WarningLow = getScaledValue(content.data[key].WarningLow, content.data[key].Scale); |
| 600 | content.data[key].WarningHigh = getScaledValue(content.data[key].WarningHigh, content.data[key].Scale); |
Iftekharul Islam | 8a12284 | 2017-09-11 10:58:16 -0500 | [diff] [blame] | 601 | if(Constants.SENSOR_SORT_ORDER.indexOf(content.data[key].Unit) > -1){ |
| 602 | customOrder = Constants.SENSOR_SORT_ORDER.indexOf(content.data[key].Unit); |
| 603 | }else{ |
| 604 | customOrder = Constants.SENSOR_SORT_ORDER_DEFAULT; |
| 605 | } |
| 606 | |
Iftekharul Islam | d2269e2 | 2017-05-02 09:32:45 -0500 | [diff] [blame] | 607 | sensorData.push(Object.assign({ |
| 608 | path: key, |
| 609 | selected: false, |
| 610 | confirm: false, |
| 611 | copied: false, |
Iftekharul Islam | 8947e70 | 2017-07-27 10:28:07 -0500 | [diff] [blame] | 612 | title: title, |
| 613 | unit: Constants.SENSOR_UNIT_MAP[content.data[key].Unit], |
| 614 | severity_flags: severity.flags, |
| 615 | status: severity.severityText, |
| 616 | order: severity.order, |
Iftekharul Islam | 8a12284 | 2017-09-11 10:58:16 -0500 | [diff] [blame] | 617 | custom_order: customOrder, |
Gunnar Mills | eedefd3 | 2018-02-28 17:02:34 -0600 | [diff] [blame] | 618 | search_text: (title + " " + content.data[key].Value + " " + |
| 619 | Constants.SENSOR_UNIT_MAP[content.data[key].Unit] + " " + |
| 620 | severity.severityText + " " + |
Iftekharul Islam | 8947e70 | 2017-07-27 10:28:07 -0500 | [diff] [blame] | 621 | content.data[key].CriticalLow + " " + |
| 622 | content.data[key].CriticalHigh + " " + |
| 623 | content.data[key].WarningLow + " " + |
| 624 | content.data[key].WarningHigh + " " |
| 625 | ).toLowerCase(), |
Iftekharul Islam | d2269e2 | 2017-05-02 09:32:45 -0500 | [diff] [blame] | 626 | original_data: {key: key, value: content.data[key]} |
| 627 | }, content.data[key])); |
| 628 | } |
| 629 | } |
| 630 | |
Iftekharul Islam | 8947e70 | 2017-07-27 10:28:07 -0500 | [diff] [blame] | 631 | callback(sensorData, dataClone); |
Ed Tanous | bbcf670 | 2017-10-06 13:53:06 -0700 | [diff] [blame] | 632 | }, function(error){ |
Iftekharul Islam | d2269e2 | 2017-05-02 09:32:45 -0500 | [diff] [blame] | 633 | console.log(error); |
| 634 | }); |
Iftekharul Islam | c016139 | 2017-06-14 15:46:15 -0500 | [diff] [blame] | 635 | }, |
Gunnar Mills | 033025f | 2018-03-06 14:49:40 -0600 | [diff] [blame] | 636 | getActivation: function(imageId){ |
| 637 | return $http({ |
| 638 | method: 'GET', |
| 639 | url: DataService.getHost() + "/xyz/openbmc_project/software/" + imageId + "/attr/Activation", |
| 640 | headers: { |
| 641 | 'Accept': 'application/json', |
| 642 | 'Content-Type': 'application/json' |
| 643 | }, |
| 644 | withCredentials: true |
| 645 | }).then(function(response){ |
| 646 | return response.data; |
| 647 | }); |
| 648 | }, |
Michael Davis | df3bd12 | 2017-08-10 11:03:42 -0500 | [diff] [blame] | 649 | getFirmwares: function(){ |
| 650 | var deferred = $q.defer(); |
Iftekharul Islam | c016139 | 2017-06-14 15:46:15 -0500 | [diff] [blame] | 651 | $http({ |
| 652 | method: 'GET', |
Iftekharul Islam | 1acb412 | 2017-11-02 13:20:32 -0500 | [diff] [blame] | 653 | url: DataService.getHost() + "/xyz/openbmc_project/software/enumerate", |
Iftekharul Islam | c016139 | 2017-06-14 15:46:15 -0500 | [diff] [blame] | 654 | headers: { |
| 655 | 'Accept': 'application/json', |
| 656 | 'Content-Type': 'application/json' |
| 657 | }, |
| 658 | withCredentials: true |
Ed Tanous | bbcf670 | 2017-10-06 13:53:06 -0700 | [diff] [blame] | 659 | }).then(function(response){ |
| 660 | var json = JSON.stringify(response.data); |
Iftekharul Islam | c016139 | 2017-06-14 15:46:15 -0500 | [diff] [blame] | 661 | var content = JSON.parse(json); |
| 662 | var data = []; |
Gunnar Mills | 902c38c | 2018-02-23 10:12:39 -0600 | [diff] [blame] | 663 | var activationStatus = ""; |
Iftekharul Islam | c016139 | 2017-06-14 15:46:15 -0500 | [diff] [blame] | 664 | var isExtended = false; |
| 665 | var bmcActiveVersion = ""; |
| 666 | var hostActiveVersion = ""; |
| 667 | var imageType = ""; |
| 668 | var extendedVersions = []; |
Gunnar Mills | 9b733bd | 2018-02-23 21:16:20 -0600 | [diff] [blame] | 669 | var functionalImages = []; |
Iftekharul Islam | c016139 | 2017-06-14 15:46:15 -0500 | [diff] [blame] | 670 | |
| 671 | function getFormatedExtendedVersions(extendedVersion){ |
| 672 | var versions = []; |
| 673 | extendedVersion = extendedVersion.split(","); |
| 674 | |
| 675 | extendedVersion.forEach(function(item){ |
| 676 | var parts = item.split("-"); |
| 677 | var numberIndex = 0; |
| 678 | for(var i = 0; i < parts.length; i++){ |
| 679 | if(/[0-9]/.test(parts[i])){ |
| 680 | numberIndex = i; |
| 681 | break; |
| 682 | } |
| 683 | } |
| 684 | var titlePart = parts.splice(0, numberIndex); |
| 685 | titlePart = titlePart.join(""); |
| 686 | titlePart = titlePart[0].toUpperCase() + titlePart.substr(1, titlePart.length); |
| 687 | var versionPart = parts.join("-"); |
| 688 | versions.push({ |
| 689 | title: titlePart, |
| 690 | version: versionPart |
| 691 | }); |
| 692 | }); |
| 693 | |
| 694 | return versions; |
| 695 | } |
| 696 | |
Gunnar Mills | 9b733bd | 2018-02-23 21:16:20 -0600 | [diff] [blame] | 697 | // Get the list of functional images so we can compare |
| 698 | // later if an image is functional |
| 699 | if (content.data[Constants.FIRMWARE.FUNCTIONAL_OBJPATH]) |
| 700 | { |
| 701 | functionalImages = content.data[Constants.FIRMWARE.FUNCTIONAL_OBJPATH].endpoints; |
| 702 | } |
Iftekharul Islam | c016139 | 2017-06-14 15:46:15 -0500 | [diff] [blame] | 703 | for(var key in content.data){ |
| 704 | if(content.data.hasOwnProperty(key) && content.data[key].hasOwnProperty('Version')){ |
Gunnar Mills | 902c38c | 2018-02-23 10:12:39 -0600 | [diff] [blame] | 705 | // If the image is "Functional" use that for the |
| 706 | // activation status, else use the value of "Activation" |
| 707 | // github.com/openbmc/phosphor-dbus-interfaces/blob/master/xyz/openbmc_project/Software/Activation.interface.yaml |
| 708 | activationStatus = content.data[key].Activation.split(".").pop(); |
Gunnar Mills | 9b733bd | 2018-02-23 21:16:20 -0600 | [diff] [blame] | 709 | if (functionalImages.includes(key)) |
Gunnar Mills | 902c38c | 2018-02-23 10:12:39 -0600 | [diff] [blame] | 710 | { |
| 711 | activationStatus = "Functional"; |
| 712 | } |
Gunnar Mills | 9b733bd | 2018-02-23 21:16:20 -0600 | [diff] [blame] | 713 | |
Iftekharul Islam | c016139 | 2017-06-14 15:46:15 -0500 | [diff] [blame] | 714 | imageType = content.data[key].Purpose.split(".").pop(); |
| 715 | isExtended = content.data[key].hasOwnProperty('ExtendedVersion') && content.data[key].ExtendedVersion != ""; |
| 716 | if(isExtended){ |
| 717 | extendedVersions = getFormatedExtendedVersions(content.data[key].ExtendedVersion); |
| 718 | } |
| 719 | data.push(Object.assign({ |
| 720 | path: key, |
Gunnar Mills | 902c38c | 2018-02-23 10:12:39 -0600 | [diff] [blame] | 721 | activationStatus: activationStatus, |
Iftekharul Islam | c016139 | 2017-06-14 15:46:15 -0500 | [diff] [blame] | 722 | imageId: key.split("/").pop(), |
| 723 | imageType: imageType, |
| 724 | isExtended: isExtended, |
| 725 | extended: { |
| 726 | show: false, |
| 727 | versions: extendedVersions |
| 728 | }, |
| 729 | data: {key: key, value: content.data[key]} |
| 730 | }, content.data[key])); |
| 731 | |
Gunnar Mills | 902c38c | 2018-02-23 10:12:39 -0600 | [diff] [blame] | 732 | if(activationStatus == 'Functional' && imageType == 'BMC'){ |
Iftekharul Islam | c016139 | 2017-06-14 15:46:15 -0500 | [diff] [blame] | 733 | bmcActiveVersion = content.data[key].Version; |
| 734 | } |
| 735 | |
Gunnar Mills | 902c38c | 2018-02-23 10:12:39 -0600 | [diff] [blame] | 736 | if(activationStatus == 'Functional' && imageType == 'Host'){ |
Iftekharul Islam | c016139 | 2017-06-14 15:46:15 -0500 | [diff] [blame] | 737 | hostActiveVersion = content.data[key].Version; |
| 738 | } |
| 739 | } |
| 740 | } |
Michael Davis | df3bd12 | 2017-08-10 11:03:42 -0500 | [diff] [blame] | 741 | |
| 742 | deferred.resolve({ |
Gunnar Mills | eedefd3 | 2018-02-28 17:02:34 -0600 | [diff] [blame] | 743 | data: data, |
| 744 | bmcActiveVersion: bmcActiveVersion, |
Michael Davis | df3bd12 | 2017-08-10 11:03:42 -0500 | [diff] [blame] | 745 | hostActiveVersion: hostActiveVersion |
| 746 | }); |
Ed Tanous | bbcf670 | 2017-10-06 13:53:06 -0700 | [diff] [blame] | 747 | }, function(error){ |
Iftekharul Islam | c016139 | 2017-06-14 15:46:15 -0500 | [diff] [blame] | 748 | console.log(error); |
Michael Davis | df3bd12 | 2017-08-10 11:03:42 -0500 | [diff] [blame] | 749 | deferred.reject(error); |
Iftekharul Islam | c016139 | 2017-06-14 15:46:15 -0500 | [diff] [blame] | 750 | }); |
Michael Davis | df3bd12 | 2017-08-10 11:03:42 -0500 | [diff] [blame] | 751 | |
| 752 | return deferred.promise; |
Iftekharul Islam | c016139 | 2017-06-14 15:46:15 -0500 | [diff] [blame] | 753 | }, |
Iftekharul Islam | 1acb412 | 2017-11-02 13:20:32 -0500 | [diff] [blame] | 754 | changePriority: function(imageId, priority){ |
| 755 | var deferred = $q.defer(); |
| 756 | $http({ |
| 757 | method: 'PUT', |
| 758 | url: DataService.getHost() + "/xyz/openbmc_project/software/" + imageId + "/attr/Priority", |
| 759 | headers: { |
Iftekharul Islam | 2a48955 | 2017-11-02 13:23:08 -0500 | [diff] [blame] | 760 | 'Accept': 'application/json', |
| 761 | 'Content-Type': 'application/json' |
Iftekharul Islam | 1acb412 | 2017-11-02 13:20:32 -0500 | [diff] [blame] | 762 | }, |
| 763 | withCredentials: true, |
| 764 | data: JSON.stringify({"data": priority}) |
Ed Tanous | bbcf670 | 2017-10-06 13:53:06 -0700 | [diff] [blame] | 765 | }).then(function(response){ |
| 766 | var json = JSON.stringify(response.data); |
Iftekharul Islam | 1acb412 | 2017-11-02 13:20:32 -0500 | [diff] [blame] | 767 | var content = JSON.parse(json); |
| 768 | deferred.resolve(content); |
Ed Tanous | bbcf670 | 2017-10-06 13:53:06 -0700 | [diff] [blame] | 769 | }, function(error){ |
Iftekharul Islam | 1acb412 | 2017-11-02 13:20:32 -0500 | [diff] [blame] | 770 | console.log(error); |
| 771 | deferred.reject(error); |
| 772 | }); |
| 773 | |
| 774 | return deferred.promise; |
| 775 | }, |
Iftekharul Islam | 2a48955 | 2017-11-02 13:23:08 -0500 | [diff] [blame] | 776 | deleteImage: function(imageId){ |
| 777 | var deferred = $q.defer(); |
| 778 | $http({ |
| 779 | method: 'POST', |
| 780 | url: DataService.getHost() + "/xyz/openbmc_project/software/" + imageId + "/action/Delete", |
| 781 | headers: { |
| 782 | 'Accept': 'application/json', |
| 783 | 'Content-Type': 'application/json' |
| 784 | }, |
| 785 | withCredentials: true, |
| 786 | data: JSON.stringify({"data": []}) |
Ed Tanous | bbcf670 | 2017-10-06 13:53:06 -0700 | [diff] [blame] | 787 | }).then(function(response){ |
| 788 | var json = JSON.stringify(response.data); |
Iftekharul Islam | 2a48955 | 2017-11-02 13:23:08 -0500 | [diff] [blame] | 789 | var content = JSON.parse(json); |
| 790 | deferred.resolve(content); |
Ed Tanous | bbcf670 | 2017-10-06 13:53:06 -0700 | [diff] [blame] | 791 | }, function(error){ |
Iftekharul Islam | 2a48955 | 2017-11-02 13:23:08 -0500 | [diff] [blame] | 792 | console.log(error); |
| 793 | deferred.reject(error); |
| 794 | }); |
| 795 | |
| 796 | return deferred.promise; |
| 797 | }, |
| 798 | activateImage: function(imageId){ |
Iftekharul Islam | 1acb412 | 2017-11-02 13:20:32 -0500 | [diff] [blame] | 799 | var deferred = $q.defer(); |
Iftekharul Islam | c016139 | 2017-06-14 15:46:15 -0500 | [diff] [blame] | 800 | $http({ |
| 801 | method: 'PUT', |
Iftekharul Islam | 2a48955 | 2017-11-02 13:23:08 -0500 | [diff] [blame] | 802 | url: DataService.getHost() + "/xyz/openbmc_project/software/" + imageId + "/attr/RequestedActivation", |
| 803 | headers: { |
| 804 | 'Accept': 'application/json', |
| 805 | 'Content-Type': 'application/json' |
| 806 | }, |
| 807 | withCredentials: true, |
| 808 | data: JSON.stringify({"data": Constants.FIRMWARE.ACTIVATE_FIRMWARE}) |
Ed Tanous | bbcf670 | 2017-10-06 13:53:06 -0700 | [diff] [blame] | 809 | }).then(function(response){ |
| 810 | var json = JSON.stringify(response.data); |
Iftekharul Islam | 2a48955 | 2017-11-02 13:23:08 -0500 | [diff] [blame] | 811 | var content = JSON.parse(json); |
| 812 | deferred.resolve(content); |
Ed Tanous | bbcf670 | 2017-10-06 13:53:06 -0700 | [diff] [blame] | 813 | }, function(error){ |
Iftekharul Islam | 2a48955 | 2017-11-02 13:23:08 -0500 | [diff] [blame] | 814 | console.log(error); |
| 815 | deferred.reject(error); |
| 816 | }); |
| 817 | |
| 818 | return deferred.promise; |
| 819 | }, |
| 820 | uploadImage: function(file){ |
Gunnar Mills | 87c3db6 | 2018-04-13 16:14:41 -0500 | [diff] [blame^] | 821 | return $http({ |
Iftekharul Islam | 2a48955 | 2017-11-02 13:23:08 -0500 | [diff] [blame] | 822 | method: 'POST', |
Iftekharul Islam | c016139 | 2017-06-14 15:46:15 -0500 | [diff] [blame] | 823 | timeout: 5 * 60 * 1000, |
Gunnar Mills | dddb149 | 2018-02-19 16:27:27 -0600 | [diff] [blame] | 824 | url: DataService.getHost() + "/upload/image", |
Iftekharul Islam | c016139 | 2017-06-14 15:46:15 -0500 | [diff] [blame] | 825 | headers: { |
Iftekharul Islam | 2a48955 | 2017-11-02 13:23:08 -0500 | [diff] [blame] | 826 | 'Content-Type': 'application/octet-stream' |
Iftekharul Islam | c016139 | 2017-06-14 15:46:15 -0500 | [diff] [blame] | 827 | }, |
| 828 | withCredentials: true, |
| 829 | data: file |
Ed Tanous | bbcf670 | 2017-10-06 13:53:06 -0700 | [diff] [blame] | 830 | }).then(function(response){ |
Gunnar Mills | 87c3db6 | 2018-04-13 16:14:41 -0500 | [diff] [blame^] | 831 | return response.data; |
Iftekharul Islam | c016139 | 2017-06-14 15:46:15 -0500 | [diff] [blame] | 832 | }); |
Iftekharul Islam | 1acb412 | 2017-11-02 13:20:32 -0500 | [diff] [blame] | 833 | }, |
| 834 | downloadImage: function(host, filename){ |
Gunnar Mills | 36379b9 | 2018-04-02 16:53:53 -0500 | [diff] [blame] | 835 | return $http({ |
Iftekharul Islam | 1acb412 | 2017-11-02 13:20:32 -0500 | [diff] [blame] | 836 | method: 'POST', |
Gunnar Mills | e345cac | 2018-02-20 11:16:53 -0600 | [diff] [blame] | 837 | url: DataService.getHost() + "/xyz/openbmc_project/software/action/DownloadViaTFTP", |
Iftekharul Islam | 1acb412 | 2017-11-02 13:20:32 -0500 | [diff] [blame] | 838 | headers: { |
Gunnar Mills | 36379b9 | 2018-04-02 16:53:53 -0500 | [diff] [blame] | 839 | 'Accept': 'application/json', |
| 840 | 'Content-Type': 'application/json' |
Iftekharul Islam | 1acb412 | 2017-11-02 13:20:32 -0500 | [diff] [blame] | 841 | }, |
| 842 | withCredentials: true, |
Gunnar Mills | e345cac | 2018-02-20 11:16:53 -0600 | [diff] [blame] | 843 | data: JSON.stringify({"data": [filename, host]}), |
Iftekharul Islam | 1acb412 | 2017-11-02 13:20:32 -0500 | [diff] [blame] | 844 | responseType: 'arraybuffer' |
Gunnar Mills | 36379b9 | 2018-04-02 16:53:53 -0500 | [diff] [blame] | 845 | }).then(function(response){ |
| 846 | return response.data; |
Iftekharul Islam | 1acb412 | 2017-11-02 13:20:32 -0500 | [diff] [blame] | 847 | }); |
Iftekharul Islam | c016139 | 2017-06-14 15:46:15 -0500 | [diff] [blame] | 848 | }, |
Michael Davis | df3bd12 | 2017-08-10 11:03:42 -0500 | [diff] [blame] | 849 | getBMCEthernetInfo: function(){ |
| 850 | var deferred = $q.defer(); |
Iftekharul Islam | 54c22e4 | 2017-06-28 11:06:16 -0500 | [diff] [blame] | 851 | $http({ |
| 852 | method: 'GET', |
Iftekharul Islam | 1acb412 | 2017-11-02 13:20:32 -0500 | [diff] [blame] | 853 | url: DataService.getHost() + "/xyz/openbmc_project/inventory/system/chassis/motherboard/boxelder/bmc/ethernet", |
Iftekharul Islam | 54c22e4 | 2017-06-28 11:06:16 -0500 | [diff] [blame] | 854 | headers: { |
| 855 | 'Accept': 'application/json', |
| 856 | 'Content-Type': 'application/json' |
| 857 | }, |
| 858 | withCredentials: true |
Ed Tanous | bbcf670 | 2017-10-06 13:53:06 -0700 | [diff] [blame] | 859 | }).then(function(response){ |
| 860 | var json = JSON.stringify(response.data); |
Michael Davis | df3bd12 | 2017-08-10 11:03:42 -0500 | [diff] [blame] | 861 | var content = JSON.parse(json); |
| 862 | deferred.resolve(content.data); |
Ed Tanous | bbcf670 | 2017-10-06 13:53:06 -0700 | [diff] [blame] | 863 | }, function(error){ |
Iftekharul Islam | 54c22e4 | 2017-06-28 11:06:16 -0500 | [diff] [blame] | 864 | console.log(error); |
Michael Davis | df3bd12 | 2017-08-10 11:03:42 -0500 | [diff] [blame] | 865 | deferred.reject(error); |
Iftekharul Islam | 54c22e4 | 2017-06-28 11:06:16 -0500 | [diff] [blame] | 866 | }); |
Michael Davis | df3bd12 | 2017-08-10 11:03:42 -0500 | [diff] [blame] | 867 | |
| 868 | return deferred.promise; |
Iftekharul Islam | 54c22e4 | 2017-06-28 11:06:16 -0500 | [diff] [blame] | 869 | }, |
| 870 | getBMCInfo: function(callback){ |
Michael Davis | df3bd12 | 2017-08-10 11:03:42 -0500 | [diff] [blame] | 871 | var deferred = $q.defer(); |
Iftekharul Islam | 54c22e4 | 2017-06-28 11:06:16 -0500 | [diff] [blame] | 872 | $http({ |
| 873 | method: 'GET', |
Iftekharul Islam | 1acb412 | 2017-11-02 13:20:32 -0500 | [diff] [blame] | 874 | url: DataService.getHost() + "/xyz/openbmc_project/inventory/system/chassis/motherboard/boxelder/bmc", |
Iftekharul Islam | 54c22e4 | 2017-06-28 11:06:16 -0500 | [diff] [blame] | 875 | headers: { |
| 876 | 'Accept': 'application/json', |
| 877 | 'Content-Type': 'application/json' |
| 878 | }, |
| 879 | withCredentials: true |
Ed Tanous | bbcf670 | 2017-10-06 13:53:06 -0700 | [diff] [blame] | 880 | }).then(function(response){ |
| 881 | var json = JSON.stringify(response.data); |
Michael Davis | df3bd12 | 2017-08-10 11:03:42 -0500 | [diff] [blame] | 882 | var content = JSON.parse(json); |
| 883 | deferred.resolve(content.data); |
Ed Tanous | bbcf670 | 2017-10-06 13:53:06 -0700 | [diff] [blame] | 884 | }, function(error){ |
Iftekharul Islam | 54c22e4 | 2017-06-28 11:06:16 -0500 | [diff] [blame] | 885 | console.log(error); |
Michael Davis | df3bd12 | 2017-08-10 11:03:42 -0500 | [diff] [blame] | 886 | deferred.reject(error); |
Iftekharul Islam | 54c22e4 | 2017-06-28 11:06:16 -0500 | [diff] [blame] | 887 | }); |
Michael Davis | df3bd12 | 2017-08-10 11:03:42 -0500 | [diff] [blame] | 888 | return deferred.promise; |
Iftekharul Islam | 54c22e4 | 2017-06-28 11:06:16 -0500 | [diff] [blame] | 889 | }, |
Iftekharul Islam | ee27d75 | 2017-07-05 15:54:31 -0500 | [diff] [blame] | 890 | getHardwares: function(callback){ |
| 891 | $http({ |
| 892 | method: 'GET', |
Iftekharul Islam | 1acb412 | 2017-11-02 13:20:32 -0500 | [diff] [blame] | 893 | url: DataService.getHost() + "/xyz/openbmc_project/inventory/enumerate", |
Iftekharul Islam | ee27d75 | 2017-07-05 15:54:31 -0500 | [diff] [blame] | 894 | headers: { |
| 895 | 'Accept': 'application/json', |
| 896 | 'Content-Type': 'application/json' |
| 897 | }, |
| 898 | withCredentials: true |
Ed Tanous | bbcf670 | 2017-10-06 13:53:06 -0700 | [diff] [blame] | 899 | }).then(function(response){ |
| 900 | var json = JSON.stringify(response.data); |
Iftekharul Islam | ee27d75 | 2017-07-05 15:54:31 -0500 | [diff] [blame] | 901 | var content = JSON.parse(json); |
| 902 | var hardwareData = []; |
| 903 | var keyIndexMap = {}; |
| 904 | var title = ""; |
| 905 | var data = []; |
| 906 | var searchText = ""; |
| 907 | var componentIndex = -1; |
| 908 | var tempParts = []; |
| 909 | |
| 910 | |
| 911 | function isSubComponent(key){ |
| 912 | |
| 913 | for(var i = 0; i < Constants.HARDWARE.parent_components.length; i++){ |
| 914 | if(key.split(Constants.HARDWARE.parent_components[i]).length == 2) return true; |
| 915 | } |
| 916 | |
| 917 | return false; |
| 918 | } |
| 919 | |
| 920 | function titlelize(title){ |
| 921 | title = title.replace(/([A-Z0-9]+)/g, " $1").replace(/^\s+/, ""); |
| 922 | for(var i = 0; i < Constants.HARDWARE.uppercase_titles.length; i++){ |
| 923 | if(title.toLowerCase().indexOf((Constants.HARDWARE.uppercase_titles[i] + " ")) > -1){ |
| 924 | return title.toUpperCase(); |
| 925 | } |
| 926 | } |
| 927 | |
| 928 | return title; |
| 929 | } |
| 930 | |
| 931 | function camelcaseToLabel(obj){ |
Iftekharul Islam | 8947e70 | 2017-07-27 10:28:07 -0500 | [diff] [blame] | 932 | var transformed = [], label = "", value = ""; |
Iftekharul Islam | ee27d75 | 2017-07-05 15:54:31 -0500 | [diff] [blame] | 933 | for(var key in obj){ |
| 934 | label = key.replace(/([A-Z0-9]+)/g, " $1").replace(/^\s+/, ""); |
| 935 | if(obj[key] !== ""){ |
Iftekharul Islam | 8947e70 | 2017-07-27 10:28:07 -0500 | [diff] [blame] | 936 | value = obj[key]; |
| 937 | if(value == 1 || value == 0){ |
| 938 | value = (value == 1) ? 'Yes' : 'No'; |
| 939 | } |
| 940 | transformed.push({key:label, value: value}); |
Iftekharul Islam | ee27d75 | 2017-07-05 15:54:31 -0500 | [diff] [blame] | 941 | } |
| 942 | } |
| 943 | |
| 944 | return transformed; |
| 945 | } |
| 946 | |
| 947 | function getSearchText(data){ |
| 948 | var searchText = ""; |
| 949 | for(var i = 0; i < data.length; i++){ |
| 950 | searchText += " " + data[i].key + " " + data[i].value; |
| 951 | } |
| 952 | |
Gunnar Mills | eedefd3 | 2018-02-28 17:02:34 -0600 | [diff] [blame] | 953 | return searchText; |
Iftekharul Islam | ee27d75 | 2017-07-05 15:54:31 -0500 | [diff] [blame] | 954 | } |
| 955 | |
| 956 | for(var key in content.data){ |
Gunnar Mills | eedefd3 | 2018-02-28 17:02:34 -0600 | [diff] [blame] | 957 | if(content.data.hasOwnProperty(key) && |
Iftekharul Islam | ee27d75 | 2017-07-05 15:54:31 -0500 | [diff] [blame] | 958 | key.indexOf(Constants.HARDWARE.component_key_filter) == 0){ |
| 959 | |
| 960 | data = camelcaseToLabel(content.data[key]); |
| 961 | searchText = getSearchText(data); |
| 962 | title = key.split("/").pop(); |
| 963 | |
| 964 | title = titlelize(title); |
| 965 | |
| 966 | if(!isSubComponent(key)){ |
| 967 | hardwareData.push(Object.assign({ |
| 968 | path: key, |
| 969 | title: title, |
| 970 | selected: false, |
| 971 | expanded: false, |
| 972 | search_text: title.toLowerCase() + " " + searchText.toLowerCase(), |
Gunnar Mills | eedefd3 | 2018-02-28 17:02:34 -0600 | [diff] [blame] | 973 | sub_components: [], |
Iftekharul Islam | ee27d75 | 2017-07-05 15:54:31 -0500 | [diff] [blame] | 974 | original_data: {key: key, value: content.data[key]} |
| 975 | }, {items: data})); |
| 976 | |
| 977 | keyIndexMap[key] = hardwareData.length - 1; |
| 978 | }else{ |
| 979 | var tempParts = key.split("/"); |
| 980 | tempParts.pop(); |
| 981 | tempParts = tempParts.join("/"); |
| 982 | componentIndex = keyIndexMap[tempParts]; |
| 983 | data = content.data[key]; |
| 984 | data.title = title; |
| 985 | hardwareData[componentIndex].sub_components.push(data); |
| 986 | hardwareData[componentIndex].search_text += " " + title.toLowerCase(); |
Gunnar Mills | cdd9d6b | 2018-03-09 11:57:06 -0600 | [diff] [blame] | 987 | |
| 988 | // Sort the subcomponents alphanumeric so they are displayed on the |
| 989 | // inventory page in order (e.g. core 0, core 1, core 2, ... core 12, core 13) |
| 990 | hardwareData[componentIndex].sub_components.sort(function (a, b) { |
| 991 | return a.title.localeCompare(b.title, 'en', { numeric: true }); |
| 992 | }); |
Iftekharul Islam | ee27d75 | 2017-07-05 15:54:31 -0500 | [diff] [blame] | 993 | } |
| 994 | } |
| 995 | } |
| 996 | |
| 997 | if(callback){ |
| 998 | callback(hardwareData, content.data); |
| 999 | }else{ |
| 1000 | return { data: hardwareData, original_data: content.data}; |
| 1001 | } |
| 1002 | }); |
| 1003 | }, |
Iftekharul Islam | f2d7464 | 2017-07-10 16:42:14 -0500 | [diff] [blame] | 1004 | deleteLogs: function(logs) { |
| 1005 | var defer = $q.defer(); |
| 1006 | var promises = []; |
| 1007 | |
| 1008 | function finished(){ |
| 1009 | defer.resolve(); |
| 1010 | } |
| 1011 | |
| 1012 | logs.forEach(function(item){ |
| 1013 | promises.push($http({ |
| 1014 | method: 'POST', |
Iftekharul Islam | 1acb412 | 2017-11-02 13:20:32 -0500 | [diff] [blame] | 1015 | url: DataService.getHost() + "/xyz/openbmc_project/logging/entry/"+item.Id+"/action/Delete", |
Iftekharul Islam | f2d7464 | 2017-07-10 16:42:14 -0500 | [diff] [blame] | 1016 | headers: { |
| 1017 | 'Accept': 'application/json', |
| 1018 | 'Content-Type': 'application/json' |
| 1019 | }, |
| 1020 | withCredentials: true, |
| 1021 | data: JSON.stringify({"data": []}) |
| 1022 | })); |
| 1023 | }); |
| 1024 | |
| 1025 | $q.all(promises).then(finished); |
| 1026 | |
| 1027 | return defer.promise; |
| 1028 | }, |
| 1029 | resolveLogs: function(logs) { |
| 1030 | var defer = $q.defer(); |
| 1031 | var promises = []; |
| 1032 | |
| 1033 | function finished(){ |
| 1034 | defer.resolve(); |
| 1035 | } |
| 1036 | |
| 1037 | logs.forEach(function(item){ |
| 1038 | promises.push($http({ |
| 1039 | method: 'PUT', |
Iftekharul Islam | 1acb412 | 2017-11-02 13:20:32 -0500 | [diff] [blame] | 1040 | url: DataService.getHost() + "/xyz/openbmc_project/logging/entry/"+item.Id+"/attr/Resolved", |
Iftekharul Islam | f2d7464 | 2017-07-10 16:42:14 -0500 | [diff] [blame] | 1041 | headers: { |
| 1042 | 'Accept': 'application/json', |
| 1043 | 'Content-Type': 'application/json' |
| 1044 | }, |
| 1045 | withCredentials: true, |
| 1046 | data: JSON.stringify({"data": "1"}) |
| 1047 | })); |
| 1048 | }); |
| 1049 | |
| 1050 | $q.all(promises).then(finished); |
| 1051 | |
| 1052 | return defer.promise; |
| 1053 | }, |
CamVan Nguyen | 3327583 | 2018-03-13 18:38:37 -0500 | [diff] [blame] | 1054 | getPowerConsumption: function(){ |
| 1055 | return $http({ |
| 1056 | method: 'GET', |
| 1057 | url: DataService.getHost() + "/xyz/openbmc_project/sensors/power/total_power", |
| 1058 | headers: { |
| 1059 | 'Accept': 'application/json', |
| 1060 | 'Content-Type': 'application/json' |
| 1061 | }, |
| 1062 | withCredentials: true |
| 1063 | }).then(function(response){ |
| 1064 | var json = JSON.stringify(response.data); |
| 1065 | var content = JSON.parse(json); |
| 1066 | |
| 1067 | return getScaledValue(content.data.Value, |
| 1068 | content.data.Scale) + ' ' + |
| 1069 | Constants.POWER_CONSUMPTION_TEXT[content.data.Unit]; |
| 1070 | }, function(error){ |
| 1071 | if ('Not Found' == error.statusText) { |
| 1072 | return Constants.POWER_CONSUMPTION_TEXT.notavailable; |
| 1073 | } else { |
| 1074 | console.log(error); |
| 1075 | } |
| 1076 | }); |
| 1077 | }, |
| 1078 | getPowerCap: function(){ |
| 1079 | return $http({ |
| 1080 | method: 'GET', |
| 1081 | url: DataService.getHost() + "/xyz/openbmc_project/control/host0/power_cap", |
| 1082 | headers: { |
| 1083 | 'Accept': 'application/json', |
| 1084 | 'Content-Type': 'application/json' |
| 1085 | }, |
| 1086 | withCredentials: true |
| 1087 | }).then(function(response){ |
| 1088 | var json = JSON.stringify(response.data); |
| 1089 | var content = JSON.parse(json); |
| 1090 | |
| 1091 | return (false == content.data.PowerCapEnable) ? |
| 1092 | Constants.POWER_CAP_TEXT.disabled : |
| 1093 | content.data.PowerCap + ' ' + Constants.POWER_CAP_TEXT.unit; |
| 1094 | }, function(error){ |
| 1095 | console.log(error); |
| 1096 | }); |
| 1097 | }, |
Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 1098 | }; |
| 1099 | return SERVICE; |
| 1100 | }]); |
| 1101 | |
| 1102 | })(window.angular); |