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