199d199f3SIftekharul Islam/** 299d199f3SIftekharul Islam * API utilities service 399d199f3SIftekharul Islam * 499d199f3SIftekharul Islam * @module app/common/services/api-utils 599d199f3SIftekharul Islam * @exports APIUtils 699d199f3SIftekharul Islam * @name APIUtils 799d199f3SIftekharul Islam * @version 0.0.1 899d199f3SIftekharul Islam */ 999d199f3SIftekharul Islam 1099d199f3SIftekharul Islamwindow.angular && (function (angular) { 1199d199f3SIftekharul Islam 'use strict'; 1299d199f3SIftekharul Islam angular 1399d199f3SIftekharul Islam .module('app.common.services') 14f2d74644SIftekharul Islam .factory('APIUtils', ['$http', 'Constants', '$q', function($http, Constants, $q){ 1599d199f3SIftekharul Islam var SERVICE = { 1699d199f3SIftekharul Islam LOGIN_CREDENTIALS: Constants.LOGIN_CREDENTIALS, 1799d199f3SIftekharul Islam API_CREDENTIALS: Constants.API_CREDENTIALS, 1899d199f3SIftekharul Islam API_RESPONSE: Constants.API_RESPONSE, 1999d199f3SIftekharul Islam CHASSIS_POWER_STATE: Constants.CHASSIS_POWER_STATE, 2099d199f3SIftekharul Islam HOST_STATE_TEXT: Constants.HOST_STATE, 2199d199f3SIftekharul Islam HOST_STATE: Constants.HOST_STATE, 22cd789508SIftekharul Islam LED_STATE: Constants.LED_STATE, 23cd789508SIftekharul Islam LED_STATE_TEXT: Constants.LED_STATE_TEXT, 2499d199f3SIftekharul Islam getChassisState: function(callback){ 2599d199f3SIftekharul Islam $http({ 2699d199f3SIftekharul Islam method: 'GET', 2799d199f3SIftekharul Islam url: SERVICE.API_CREDENTIALS.host + "/xyz/openbmc_project/state/chassis0", 2899d199f3SIftekharul Islam headers: { 2999d199f3SIftekharul Islam 'Accept': 'application/json', 3099d199f3SIftekharul Islam 'Content-Type': 'application/json' 3199d199f3SIftekharul Islam }, 3299d199f3SIftekharul Islam withCredentials: true 3399d199f3SIftekharul Islam }).success(function(response){ 3499d199f3SIftekharul Islam var json = JSON.stringify(response); 3599d199f3SIftekharul Islam var content = JSON.parse(json); 3699d199f3SIftekharul Islam callback(content.data.CurrentPowerState); 3799d199f3SIftekharul Islam }).error(function(error){ 3899d199f3SIftekharul Islam console.log(error); 3999d199f3SIftekharul Islam }); 4099d199f3SIftekharul Islam }, 4199d199f3SIftekharul Islam getHostState: function(callback){ 4299d199f3SIftekharul Islam $http({ 4399d199f3SIftekharul Islam method: 'GET', 4499d199f3SIftekharul Islam url: SERVICE.API_CREDENTIALS.host + "/xyz/openbmc_project/state/host0", 4599d199f3SIftekharul Islam headers: { 4699d199f3SIftekharul Islam 'Accept': 'application/json', 4799d199f3SIftekharul Islam 'Content-Type': 'application/json' 4899d199f3SIftekharul Islam }, 4999d199f3SIftekharul Islam withCredentials: true 5099d199f3SIftekharul Islam }).success(function(response){ 5199d199f3SIftekharul Islam var json = JSON.stringify(response); 5299d199f3SIftekharul Islam var content = JSON.parse(json); 5399d199f3SIftekharul Islam callback(content.data.CurrentHostState); 5499d199f3SIftekharul Islam }).error(function(error){ 5599d199f3SIftekharul Islam console.log(error); 5699d199f3SIftekharul Islam }); 5799d199f3SIftekharul Islam }, 58171c6a1eSIftekharul Islam getNetworkInfo: function(){ 59171c6a1eSIftekharul Islam var deferred = $q.defer(); 60171c6a1eSIftekharul Islam $http({ 61171c6a1eSIftekharul Islam method: 'GET', 62171c6a1eSIftekharul Islam url: SERVICE.API_CREDENTIALS.host + "/xyz/openbmc_project/network/enumerate", 63171c6a1eSIftekharul Islam headers: { 64171c6a1eSIftekharul Islam 'Accept': 'application/json', 65171c6a1eSIftekharul Islam 'Content-Type': 'application/json' 66171c6a1eSIftekharul Islam }, 67171c6a1eSIftekharul Islam withCredentials: true 68171c6a1eSIftekharul Islam }).success(function(response){ 69171c6a1eSIftekharul Islam var json = JSON.stringify(response); 70171c6a1eSIftekharul Islam var content = JSON.parse(json); 71171c6a1eSIftekharul Islam var hostname = ""; 72171c6a1eSIftekharul Islam var macAddress = ""; 73171c6a1eSIftekharul Islam 74171c6a1eSIftekharul Islam if(content.data.hasOwnProperty('/xyz/openbmc_project/network/config') && 75171c6a1eSIftekharul Islam content.data['/xyz/openbmc_project/network/config'].hasOwnProperty('HostName') 76171c6a1eSIftekharul Islam ){ 77171c6a1eSIftekharul Islam hostname = content.data['/xyz/openbmc_project/network/config'].HostName; 78171c6a1eSIftekharul Islam } 79171c6a1eSIftekharul Islam 80171c6a1eSIftekharul Islam if(content.data.hasOwnProperty('/xyz/openbmc_project/network/eth0') && 81171c6a1eSIftekharul Islam content.data['/xyz/openbmc_project/network/eth0'].hasOwnProperty('MACAddress') 82171c6a1eSIftekharul Islam ){ 83171c6a1eSIftekharul Islam macAddress = content.data['/xyz/openbmc_project/network/eth0'].MACAddress; 84171c6a1eSIftekharul Islam } 85171c6a1eSIftekharul Islam 86171c6a1eSIftekharul Islam deferred.resolve({ 87171c6a1eSIftekharul Islam data: content.data, 88171c6a1eSIftekharul Islam hostname: hostname, 89171c6a1eSIftekharul Islam mac_address: macAddress, 90171c6a1eSIftekharul Islam }); 91171c6a1eSIftekharul Islam }).error(function(error){ 92171c6a1eSIftekharul Islam console.log(error); 93171c6a1eSIftekharul Islam deferred.reject(error); 94171c6a1eSIftekharul Islam }); 95171c6a1eSIftekharul Islam return deferred.promise; 96171c6a1eSIftekharul Islam }, 97df3bd124SMichael Davis getLEDState: function(){ 98df3bd124SMichael Davis var deferred = $q.defer(); 99cd789508SIftekharul Islam $http({ 100cd789508SIftekharul Islam method: 'GET', 101cd789508SIftekharul Islam url: SERVICE.API_CREDENTIALS.host + "/xyz/openbmc_project/led/groups/enclosure_identify", 102cd789508SIftekharul Islam headers: { 103cd789508SIftekharul Islam 'Accept': 'application/json', 104cd789508SIftekharul Islam 'Content-Type': 'application/json' 105cd789508SIftekharul Islam }, 106cd789508SIftekharul Islam withCredentials: true 107cd789508SIftekharul Islam }).success(function(response){ 108cd789508SIftekharul Islam var json = JSON.stringify(response); 109cd789508SIftekharul Islam var content = JSON.parse(json); 110df3bd124SMichael Davis deferred.resolve(content.data.Asserted); 111cd789508SIftekharul Islam }).error(function(error){ 112cd789508SIftekharul Islam console.log(error); 113df3bd124SMichael Davis deferred.reject(error); 114cd789508SIftekharul Islam }); 115df3bd124SMichael Davis return deferred.promise; 116cd789508SIftekharul Islam }, 11799d199f3SIftekharul Islam login: function(username, password, callback){ 11899d199f3SIftekharul Islam $http({ 11999d199f3SIftekharul Islam method: 'POST', 12099d199f3SIftekharul Islam url: SERVICE.API_CREDENTIALS.host + "/login", 12199d199f3SIftekharul Islam headers: { 12299d199f3SIftekharul Islam 'Accept': 'application/json', 12399d199f3SIftekharul Islam 'Content-Type': 'application/json' 12499d199f3SIftekharul Islam }, 12599d199f3SIftekharul Islam withCredentials: true, 12699d199f3SIftekharul Islam data: JSON.stringify({"data": [username, password]}) 12799d199f3SIftekharul Islam }).success(function(response){ 12899d199f3SIftekharul Islam if(callback){ 12999d199f3SIftekharul Islam callback(response); 13099d199f3SIftekharul Islam } 13199d199f3SIftekharul Islam }).error(function(error){ 13299d199f3SIftekharul Islam if(callback){ 133cd789508SIftekharul Islam if(error && error.status && error.status == 'error'){ 134cd789508SIftekharul Islam callback(error); 135cd789508SIftekharul Islam }else{ 136cd789508SIftekharul Islam callback(error, true); 137cd789508SIftekharul Islam } 13899d199f3SIftekharul Islam } 13999d199f3SIftekharul Islam console.log(error); 14099d199f3SIftekharul Islam }); 14199d199f3SIftekharul Islam }, 14299d199f3SIftekharul Islam logout: function(callback){ 14399d199f3SIftekharul Islam $http({ 14499d199f3SIftekharul Islam method: 'POST', 14599d199f3SIftekharul Islam url: SERVICE.API_CREDENTIALS.host + "/logout", 14699d199f3SIftekharul Islam headers: { 14799d199f3SIftekharul Islam 'Accept': 'application/json', 14899d199f3SIftekharul Islam 'Content-Type': 'application/json' 14999d199f3SIftekharul Islam }, 15099d199f3SIftekharul Islam withCredentials: true, 15199d199f3SIftekharul Islam data: JSON.stringify({"data": []}) 15299d199f3SIftekharul Islam }).success(function(response){ 15399d199f3SIftekharul Islam if(callback){ 15499d199f3SIftekharul Islam callback(response); 15599d199f3SIftekharul Islam } 15699d199f3SIftekharul Islam }).error(function(error){ 15799d199f3SIftekharul Islam if(callback){ 15899d199f3SIftekharul Islam callback(null, error); 15999d199f3SIftekharul Islam } 16099d199f3SIftekharul Islam console.log(error); 16199d199f3SIftekharul Islam }); 16299d199f3SIftekharul Islam }, 16399d199f3SIftekharul Islam chassisPowerOn: function(callback){ 16499d199f3SIftekharul Islam $http({ 16599d199f3SIftekharul Islam method: 'POST', 16699d199f3SIftekharul Islam url: SERVICE.API_CREDENTIALS.host + "/xyz/openbmc_project/state/host0", 16799d199f3SIftekharul Islam headers: { 16899d199f3SIftekharul Islam 'Accept': 'application/json', 16999d199f3SIftekharul Islam 'Content-Type': 'application/json' 17099d199f3SIftekharul Islam }, 17199d199f3SIftekharul Islam withCredentials: true, 17299d199f3SIftekharul Islam data: JSON.stringify({"data": []}) 17399d199f3SIftekharul Islam }).success(function(response){ 17499d199f3SIftekharul Islam var json = JSON.stringify(response); 17599d199f3SIftekharul Islam var content = JSON.parse(json); 17699d199f3SIftekharul Islam if(callback){ 17799d199f3SIftekharul Islam return callback(content.data.CurrentPowerState); 17899d199f3SIftekharul Islam } 17999d199f3SIftekharul Islam }).error(function(error){ 18099d199f3SIftekharul Islam if(callback){ 18199d199f3SIftekharul Islam callback(error); 18299d199f3SIftekharul Islam }else{ 18399d199f3SIftekharul Islam console.log(error); 18499d199f3SIftekharul Islam } 18599d199f3SIftekharul Islam }); 18699d199f3SIftekharul Islam }, 18799d199f3SIftekharul Islam chassisPowerOff: function(callback){ 18899d199f3SIftekharul Islam $http({ 18999d199f3SIftekharul Islam method: 'POST', 19099d199f3SIftekharul Islam url: SERVICE.API_CREDENTIALS.host + "/xyz/openbmc_project/state/host0", 19199d199f3SIftekharul Islam headers: { 19299d199f3SIftekharul Islam 'Accept': 'application/json', 19399d199f3SIftekharul Islam 'Content-Type': 'application/json' 19499d199f3SIftekharul Islam }, 19599d199f3SIftekharul Islam withCredentials: true, 19699d199f3SIftekharul Islam data: JSON.stringify({"data": []}) 19799d199f3SIftekharul Islam }).success(function(response){ 19899d199f3SIftekharul Islam var json = JSON.stringify(response); 19999d199f3SIftekharul Islam var content = JSON.parse(json); 20099d199f3SIftekharul Islam if(callback){ 20199d199f3SIftekharul Islam return callback(content.data.CurrentPowerState); 20299d199f3SIftekharul Islam } 20399d199f3SIftekharul Islam }).error(function(error){ 20499d199f3SIftekharul Islam if(callback){ 20599d199f3SIftekharul Islam callback(error); 20699d199f3SIftekharul Islam }else{ 20799d199f3SIftekharul Islam console.log(error); 20899d199f3SIftekharul Islam } 20999d199f3SIftekharul Islam }); 21099d199f3SIftekharul Islam }, 211cd789508SIftekharul Islam setLEDState: function(state, callback){ 212cd789508SIftekharul Islam $http({ 213cd789508SIftekharul Islam method: 'PUT', 214cd789508SIftekharul Islam url: SERVICE.API_CREDENTIALS.host + "/xyz/openbmc_project/led/groups/enclosure_identify/attr/Asserted", 215cd789508SIftekharul Islam headers: { 216cd789508SIftekharul Islam 'Accept': 'application/json', 217cd789508SIftekharul Islam 'Content-Type': 'application/json' 218cd789508SIftekharul Islam }, 219cd789508SIftekharul Islam withCredentials: true, 220cd789508SIftekharul Islam data: JSON.stringify({"data": state}) 221cd789508SIftekharul Islam }).success(function(response){ 222cd789508SIftekharul Islam var json = JSON.stringify(response); 223cd789508SIftekharul Islam var content = JSON.parse(json); 224cd789508SIftekharul Islam if(callback){ 225cd789508SIftekharul Islam return callback(content.status); 226cd789508SIftekharul Islam } 227cd789508SIftekharul Islam }).error(function(error){ 228cd789508SIftekharul Islam if(callback){ 229cd789508SIftekharul Islam callback(error); 230cd789508SIftekharul Islam }else{ 231cd789508SIftekharul Islam console.log(error); 232cd789508SIftekharul Islam } 233cd789508SIftekharul Islam }); 234cd789508SIftekharul Islam }, 23555368129SIftekharul Islam bmcReboot: function(callback){ 23655368129SIftekharul Islam $http({ 23755368129SIftekharul Islam method: 'PUT', 23855368129SIftekharul Islam url: SERVICE.API_CREDENTIALS.host + "/xyz/openbmc_project/state/bmc0/attr/RequestedBmcTransition", 23955368129SIftekharul Islam headers: { 24055368129SIftekharul Islam 'Accept': 'application/json', 24155368129SIftekharul Islam 'Content-Type': 'application/json' 24255368129SIftekharul Islam }, 24355368129SIftekharul Islam withCredentials: true, 24455368129SIftekharul Islam data: JSON.stringify({"data": "xyz.openbmc_project.State.BMC.Transition.Reboot"}) 24555368129SIftekharul Islam }).success(function(response){ 24655368129SIftekharul Islam var json = JSON.stringify(response); 24755368129SIftekharul Islam var content = JSON.parse(json); 24855368129SIftekharul Islam if(callback){ 24955368129SIftekharul Islam return callback(content.status); 25055368129SIftekharul Islam } 25155368129SIftekharul Islam }).error(function(error){ 25255368129SIftekharul Islam if(callback){ 25355368129SIftekharul Islam callback(error); 25455368129SIftekharul Islam }else{ 25555368129SIftekharul Islam console.log(error); 25655368129SIftekharul Islam } 25755368129SIftekharul Islam }); 25855368129SIftekharul Islam }, 25999d199f3SIftekharul Islam hostPowerOn: function(callback){ 26099d199f3SIftekharul Islam $http({ 26199d199f3SIftekharul Islam method: 'PUT', 26299d199f3SIftekharul Islam url: SERVICE.API_CREDENTIALS.host + "/xyz/openbmc_project/state/host0/attr/RequestedHostTransition", 26399d199f3SIftekharul Islam headers: { 26499d199f3SIftekharul Islam 'Accept': 'application/json', 26599d199f3SIftekharul Islam 'Content-Type': 'application/json' 26699d199f3SIftekharul Islam }, 26799d199f3SIftekharul Islam withCredentials: true, 26899d199f3SIftekharul Islam data: JSON.stringify({"data": "xyz.openbmc_project.State.Host.Transition.On"}) 26999d199f3SIftekharul Islam }).success(function(response){ 27099d199f3SIftekharul Islam var json = JSON.stringify(response); 27199d199f3SIftekharul Islam var content = JSON.parse(json); 27299d199f3SIftekharul Islam if(callback){ 27399d199f3SIftekharul Islam return callback(content.status); 27499d199f3SIftekharul Islam } 27599d199f3SIftekharul Islam }).error(function(error){ 27699d199f3SIftekharul Islam if(callback){ 27799d199f3SIftekharul Islam callback(error); 27899d199f3SIftekharul Islam }else{ 27999d199f3SIftekharul Islam console.log(error); 28099d199f3SIftekharul Islam } 28199d199f3SIftekharul Islam }); 28299d199f3SIftekharul Islam }, 28399d199f3SIftekharul Islam hostPowerOff: function(callback){ 28499d199f3SIftekharul Islam $http({ 28599d199f3SIftekharul Islam method: 'PUT', 28699d199f3SIftekharul Islam url: SERVICE.API_CREDENTIALS.host + "/xyz/openbmc_project/state/host0/attr/RequestedHostTransition", 28799d199f3SIftekharul Islam headers: { 28899d199f3SIftekharul Islam 'Accept': 'application/json', 28999d199f3SIftekharul Islam 'Content-Type': 'application/json' 29099d199f3SIftekharul Islam }, 29199d199f3SIftekharul Islam withCredentials: true, 29299d199f3SIftekharul Islam data: JSON.stringify({"data": "xyz.openbmc_project.State.Host.Transition.Off"}) 29399d199f3SIftekharul Islam }).success(function(response){ 29499d199f3SIftekharul Islam var json = JSON.stringify(response); 29599d199f3SIftekharul Islam var content = JSON.parse(json); 29699d199f3SIftekharul Islam if(callback){ 29799d199f3SIftekharul Islam return callback(content.status); 29899d199f3SIftekharul Islam } 29999d199f3SIftekharul Islam }).error(function(error){ 30099d199f3SIftekharul Islam if(callback){ 30199d199f3SIftekharul Islam callback(error); 30299d199f3SIftekharul Islam }else{ 30399d199f3SIftekharul Islam console.log(error); 30499d199f3SIftekharul Islam } 30599d199f3SIftekharul Islam }); 30699d199f3SIftekharul Islam }, 30799d199f3SIftekharul Islam hostReboot: function(callback){ 30899d199f3SIftekharul Islam $http({ 30999d199f3SIftekharul Islam method: 'POST', 31099d199f3SIftekharul Islam url: SERVICE.API_CREDENTIALS.host + "/xyz/openbmc_project/state/host0", 31199d199f3SIftekharul Islam headers: { 31299d199f3SIftekharul Islam 'Accept': 'application/json', 31399d199f3SIftekharul Islam 'Content-Type': 'application/json' 31499d199f3SIftekharul Islam }, 31599d199f3SIftekharul Islam withCredentials: true, 31699d199f3SIftekharul Islam data: JSON.stringify({"data": []}), 31799d199f3SIftekharul Islam }).success(function(response){ 31899d199f3SIftekharul Islam var json = JSON.stringify(response); 31999d199f3SIftekharul Islam var content = JSON.parse(json); 32099d199f3SIftekharul Islam if(callback){ 32199d199f3SIftekharul Islam return callback(content); 32299d199f3SIftekharul Islam } 32399d199f3SIftekharul Islam }).error(function(error){ 32499d199f3SIftekharul Islam if(callback){ 32599d199f3SIftekharul Islam callback(error); 32699d199f3SIftekharul Islam }else{ 32799d199f3SIftekharul Islam console.log(error); 32899d199f3SIftekharul Islam } 32999d199f3SIftekharul Islam }); 33099d199f3SIftekharul Islam }, 33199d199f3SIftekharul Islam hostShutdown: function(callback){ 33299d199f3SIftekharul Islam $http({ 33399d199f3SIftekharul Islam method: 'POST', 33499d199f3SIftekharul Islam url: SERVICE.API_CREDENTIALS.host + "/xyz/openbmc_project/state/host0", 33599d199f3SIftekharul Islam headers: { 33699d199f3SIftekharul Islam 'Accept': 'application/json', 33799d199f3SIftekharul Islam 'Content-Type': 'application/json' 33899d199f3SIftekharul Islam }, 33999d199f3SIftekharul Islam withCredentials: true, 34099d199f3SIftekharul Islam data: JSON.stringify({"data": []}) 34199d199f3SIftekharul Islam }).success(function(response){ 34299d199f3SIftekharul Islam var json = JSON.stringify(response); 34399d199f3SIftekharul Islam var content = JSON.parse(json); 34499d199f3SIftekharul Islam if(callback){ 34599d199f3SIftekharul Islam return callback(content); 34699d199f3SIftekharul Islam } 34799d199f3SIftekharul Islam }).error(function(error){ 34899d199f3SIftekharul Islam if(callback){ 34999d199f3SIftekharul Islam callback(error); 35099d199f3SIftekharul Islam }else{ 35199d199f3SIftekharul Islam console.log(error); 35299d199f3SIftekharul Islam } 35399d199f3SIftekharul Islam }); 354cd789508SIftekharul Islam }, 355df3bd124SMichael Davis getLogs: function(){ 356df3bd124SMichael Davis var deferred = $q.defer(); 357cd789508SIftekharul Islam $http({ 358cd789508SIftekharul Islam method: 'GET', 359cd789508SIftekharul Islam url: SERVICE.API_CREDENTIALS.host + "/xyz/openbmc_project/logging/enumerate", 360cd789508SIftekharul Islam headers: { 361cd789508SIftekharul Islam 'Accept': 'application/json', 362cd789508SIftekharul Islam 'Content-Type': 'application/json' 363cd789508SIftekharul Islam }, 364cd789508SIftekharul Islam withCredentials: true 365cd789508SIftekharul Islam }).success(function(response){ 366cd789508SIftekharul Islam var json = JSON.stringify(response); 367cd789508SIftekharul Islam var content = JSON.parse(json); 368cd789508SIftekharul Islam var dataClone = JSON.parse(JSON.stringify(content.data)); 369cd789508SIftekharul Islam var data = []; 370cd789508SIftekharul Islam var severityCode = ''; 371cd789508SIftekharul Islam var priority = ''; 372*ec6bcd10SIftekharul Islam var health = ''; 373cd789508SIftekharul Islam var relatedItems = []; 374cd789508SIftekharul Islam 375cd789508SIftekharul Islam for(var key in content.data){ 376cd789508SIftekharul Islam if(content.data.hasOwnProperty(key) && content.data[key].hasOwnProperty('Id')){ 377cd789508SIftekharul Islam var severityFlags = {low: false, medium: false, high: false}; 378*ec6bcd10SIftekharul Islam var healthFlags = {critical: false, warning: false, good: false}; 379cd789508SIftekharul Islam severityCode = content.data[key].Severity.split(".").pop(); 380cd789508SIftekharul Islam priority = Constants.SEVERITY_TO_PRIORITY_MAP[severityCode]; 381cd789508SIftekharul Islam severityFlags[priority.toLowerCase()] = true; 382*ec6bcd10SIftekharul Islam health = Constants.SEVERITY_TO_HEALTH_MAP[severityCode]; 383*ec6bcd10SIftekharul Islam healthFlags[health.toLowerCase()] = true; 384cd789508SIftekharul Islam relatedItems = []; 385cd789508SIftekharul Islam content.data[key].associations.forEach(function(item){ 386532763f4SIftekharul Islam relatedItems.push(item[2]); 387cd789508SIftekharul Islam }); 388cd789508SIftekharul Islam 389cd789508SIftekharul Islam data.push(Object.assign({ 390cd789508SIftekharul Islam path: key, 391cd789508SIftekharul Islam copied: false, 392cd789508SIftekharul Islam priority: priority, 393cd789508SIftekharul Islam severity_code: severityCode, 394cd789508SIftekharul Islam severity_flags: severityFlags, 395*ec6bcd10SIftekharul Islam health_flags: healthFlags, 396cd789508SIftekharul Islam additional_data: content.data[key].AdditionalData.join("\n"), 397cd789508SIftekharul Islam selected: false, 3988b4828a6SIftekharul Islam search_text: ("#" + content.data[key].Id + " " + severityCode + " " + content.data[key].Severity + " " + content.data[key].AdditionalData.join(" ")).toLowerCase(), 399cd789508SIftekharul Islam meta: false, 400cd789508SIftekharul Islam confirm: false, 401cd789508SIftekharul Islam related_items: relatedItems, 402cd789508SIftekharul Islam data: {key: key, value: content.data[key]} 403cd789508SIftekharul Islam }, content.data[key])); 404cd789508SIftekharul Islam } 405cd789508SIftekharul Islam } 406df3bd124SMichael Davis deferred.resolve({data: data, original: dataClone}); 407cd789508SIftekharul Islam }).error(function(error){ 408cd789508SIftekharul Islam console.log(error); 409df3bd124SMichael Davis deferred.reject(error); 410cd789508SIftekharul Islam }); 411df3bd124SMichael Davis 412df3bd124SMichael Davis return deferred.promise; 413d2269e22SIftekharul Islam }, 414d2269e22SIftekharul Islam getAllSensorStatus: function(callback){ 415d2269e22SIftekharul Islam $http({ 416d2269e22SIftekharul Islam method: 'GET', 4178947e701SIftekharul Islam url: SERVICE.API_CREDENTIALS.host + "/xyz/openbmc_project/sensors/enumerate", 418d2269e22SIftekharul Islam headers: { 419d2269e22SIftekharul Islam 'Accept': 'application/json', 420d2269e22SIftekharul Islam 'Content-Type': 'application/json' 421d2269e22SIftekharul Islam }, 422d2269e22SIftekharul Islam withCredentials: true 423d2269e22SIftekharul Islam }).success(function(response){ 424d2269e22SIftekharul Islam var json = JSON.stringify(response); 425d2269e22SIftekharul Islam var content = JSON.parse(json); 426d2269e22SIftekharul Islam var dataClone = JSON.parse(JSON.stringify(content.data)); 427d2269e22SIftekharul Islam var sensorData = []; 4288947e701SIftekharul Islam var severity = {}; 4298947e701SIftekharul Islam var title = ""; 4308947e701SIftekharul Islam var tempKeyParts = []; 4318947e701SIftekharul Islam var order = 0; 432d2269e22SIftekharul Islam 43396bbf310SIftekharul Islam function getScaledValue(value, scale){ 43496bbf310SIftekharul Islam scale = scale + ""; 435*ec6bcd10SIftekharul Islam scale = parseInt(scale, 10); 436*ec6bcd10SIftekharul Islam var power = Math.abs(parseInt(scale,10)); 43796bbf310SIftekharul Islam 438*ec6bcd10SIftekharul Islam if(scale > 0){ 43996bbf310SIftekharul Islam value = value * Math.pow(10, power); 440*ec6bcd10SIftekharul Islam }else if(scale < 0){ 44196bbf310SIftekharul Islam value = value / Math.pow(10, power); 44296bbf310SIftekharul Islam } 44396bbf310SIftekharul Islam return value; 44496bbf310SIftekharul Islam } 44596bbf310SIftekharul Islam 446d2269e22SIftekharul Islam function getSensorStatus(reading){ 4478947e701SIftekharul Islam var severityFlags = {critical: false, warning: false, normal: false}, severityText = '', order = 0; 4488947e701SIftekharul Islam 4498947e701SIftekharul Islam if(reading.hasOwnProperty('CriticalLow') && 4508947e701SIftekharul Islam reading.Value < reading.CriticalLow 4518947e701SIftekharul Islam ){ 452d2269e22SIftekharul Islam severityFlags.critical = true; 453d2269e22SIftekharul Islam severityText = 'critical'; 4548947e701SIftekharul Islam order = 2; 4558947e701SIftekharul Islam }else if(reading.hasOwnProperty('CriticalHigh') && 4568947e701SIftekharul Islam reading.Value > reading.CriticalHigh 4578947e701SIftekharul Islam ){ 4588947e701SIftekharul Islam severityFlags.critical = true; 4598947e701SIftekharul Islam severityText = 'critical'; 4608947e701SIftekharul Islam order = 2; 4618947e701SIftekharul Islam }else if(reading.hasOwnProperty('CriticalLow') && 4628947e701SIftekharul Islam reading.hasOwnProperty('WarningLow') && 4638947e701SIftekharul Islam reading.Value >= reading.CriticalLow && reading.Value <= reading.WarningLow){ 464d2269e22SIftekharul Islam severityFlags.warning = true; 465d2269e22SIftekharul Islam severityText = 'warning'; 4668947e701SIftekharul Islam order = 1; 4678947e701SIftekharul Islam }else if(reading.hasOwnProperty('WarningHigh') && 4688947e701SIftekharul Islam reading.hasOwnProperty('CriticalHigh') && 4698947e701SIftekharul Islam reading.Value >= reading.WarningHigh && reading.Value <= reading.CriticalHigh){ 4708947e701SIftekharul Islam severityFlags.warning = true; 4718947e701SIftekharul Islam severityText = 'warning'; 4728947e701SIftekharul Islam order = 1; 473d2269e22SIftekharul Islam }else{ 474d2269e22SIftekharul Islam severityFlags.normal = true; 475d2269e22SIftekharul Islam severityText = 'normal'; 476d2269e22SIftekharul Islam } 4778947e701SIftekharul Islam return { flags: severityFlags, severityText: severityText, order: order}; 478d2269e22SIftekharul Islam } 479d2269e22SIftekharul Islam 480d2269e22SIftekharul Islam for(var key in content.data){ 481d2269e22SIftekharul Islam if(content.data.hasOwnProperty(key) && content.data[key].hasOwnProperty('Unit')){ 4828947e701SIftekharul Islam 4838947e701SIftekharul Islam severity = getSensorStatus(content.data[key]); 4848947e701SIftekharul Islam 4858947e701SIftekharul Islam if(!content.data[key].hasOwnProperty('CriticalLow')){ 4868947e701SIftekharul Islam content.data[key].CriticalLow = "--"; 4878947e701SIftekharul Islam content.data[key].CriticalHigh = "--"; 4888947e701SIftekharul Islam } 4898947e701SIftekharul Islam 4908947e701SIftekharul Islam if(!content.data[key].hasOwnProperty('WarningLow')){ 4918947e701SIftekharul Islam content.data[key].WarningLow = "--"; 4928947e701SIftekharul Islam content.data[key].WarningHigh = "--"; 4938947e701SIftekharul Islam } 4948947e701SIftekharul Islam 4958947e701SIftekharul Islam tempKeyParts = key.split("/"); 4968947e701SIftekharul Islam title = tempKeyParts.pop(); 4978947e701SIftekharul Islam title = tempKeyParts.pop() + '_' + title; 4988947e701SIftekharul Islam title = title.split("_").map(function(item){ 4998947e701SIftekharul Islam return item.toLowerCase().charAt(0).toUpperCase() + item.slice(1); 5008947e701SIftekharul Islam }).reduce(function(prev, el){ 5018947e701SIftekharul Islam return prev + " " + el; 5028947e701SIftekharul Islam }); 5038947e701SIftekharul Islam 50496bbf310SIftekharul Islam content.data[key].Value = getScaledValue(content.data[key].Value, content.data[key].Scale); 50596bbf310SIftekharul Islam 506d2269e22SIftekharul Islam sensorData.push(Object.assign({ 507d2269e22SIftekharul Islam path: key, 508d2269e22SIftekharul Islam selected: false, 509d2269e22SIftekharul Islam confirm: false, 510d2269e22SIftekharul Islam copied: false, 5118947e701SIftekharul Islam title: title, 5128947e701SIftekharul Islam unit: Constants.SENSOR_UNIT_MAP[content.data[key].Unit], 5138947e701SIftekharul Islam severity_flags: severity.flags, 5148947e701SIftekharul Islam status: severity.severityText, 5158947e701SIftekharul Islam order: severity.order, 5168947e701SIftekharul Islam search_text: (title + " " + content.data[key].Value + " " + 5178947e701SIftekharul Islam Constants.SENSOR_UNIT_MAP[content.data[key].Unit] + " " + 5188947e701SIftekharul Islam severity.severityText + " " + 5198947e701SIftekharul Islam content.data[key].CriticalLow + " " + 5208947e701SIftekharul Islam content.data[key].CriticalHigh + " " + 5218947e701SIftekharul Islam content.data[key].WarningLow + " " + 5228947e701SIftekharul Islam content.data[key].WarningHigh + " " 5238947e701SIftekharul Islam ).toLowerCase(), 524d2269e22SIftekharul Islam original_data: {key: key, value: content.data[key]} 525d2269e22SIftekharul Islam }, content.data[key])); 526d2269e22SIftekharul Islam } 527d2269e22SIftekharul Islam } 528d2269e22SIftekharul Islam 5298947e701SIftekharul Islam callback(sensorData, dataClone); 530d2269e22SIftekharul Islam }).error(function(error){ 531d2269e22SIftekharul Islam console.log(error); 532d2269e22SIftekharul Islam }); 533c016139fSIftekharul Islam }, 534df3bd124SMichael Davis getFirmwares: function(){ 535df3bd124SMichael Davis var deferred = $q.defer(); 536c016139fSIftekharul Islam $http({ 537c016139fSIftekharul Islam method: 'GET', 538c016139fSIftekharul Islam url: SERVICE.API_CREDENTIALS.host + "/xyz/openbmc_project/software/enumerate", 539c016139fSIftekharul Islam headers: { 540c016139fSIftekharul Islam 'Accept': 'application/json', 541c016139fSIftekharul Islam 'Content-Type': 'application/json' 542c016139fSIftekharul Islam }, 543c016139fSIftekharul Islam withCredentials: true 544c016139fSIftekharul Islam }).success(function(response){ 545c016139fSIftekharul Islam var json = JSON.stringify(response); 546c016139fSIftekharul Islam var content = JSON.parse(json); 547c016139fSIftekharul Islam var data = []; 548c016139fSIftekharul Islam var active = false; 549c016139fSIftekharul Islam var isExtended = false; 550c016139fSIftekharul Islam var bmcActiveVersion = ""; 551c016139fSIftekharul Islam var hostActiveVersion = ""; 552c016139fSIftekharul Islam var imageType = ""; 553c016139fSIftekharul Islam var extendedVersions = []; 554c016139fSIftekharul Islam 555c016139fSIftekharul Islam function getFormatedExtendedVersions(extendedVersion){ 556c016139fSIftekharul Islam var versions = []; 557c016139fSIftekharul Islam extendedVersion = extendedVersion.split(","); 558c016139fSIftekharul Islam 559c016139fSIftekharul Islam extendedVersion.forEach(function(item){ 560c016139fSIftekharul Islam var parts = item.split("-"); 561c016139fSIftekharul Islam var numberIndex = 0; 562c016139fSIftekharul Islam for(var i = 0; i < parts.length; i++){ 563c016139fSIftekharul Islam if(/[0-9]/.test(parts[i])){ 564c016139fSIftekharul Islam numberIndex = i; 565c016139fSIftekharul Islam break; 56699d199f3SIftekharul Islam } 567c016139fSIftekharul Islam } 568c016139fSIftekharul Islam var titlePart = parts.splice(0, numberIndex); 569c016139fSIftekharul Islam titlePart = titlePart.join(""); 570c016139fSIftekharul Islam titlePart = titlePart[0].toUpperCase() + titlePart.substr(1, titlePart.length); 571c016139fSIftekharul Islam var versionPart = parts.join("-"); 572c016139fSIftekharul Islam versions.push({ 573c016139fSIftekharul Islam title: titlePart, 574c016139fSIftekharul Islam version: versionPart 575c016139fSIftekharul Islam }); 576c016139fSIftekharul Islam }); 577c016139fSIftekharul Islam 578c016139fSIftekharul Islam return versions; 579c016139fSIftekharul Islam } 580c016139fSIftekharul Islam 581c016139fSIftekharul Islam for(var key in content.data){ 582c016139fSIftekharul Islam if(content.data.hasOwnProperty(key) && content.data[key].hasOwnProperty('Version')){ 583c016139fSIftekharul Islam active = (/\.Active$/).test(content.data[key].Activation); 584c016139fSIftekharul Islam imageType = content.data[key].Purpose.split(".").pop(); 585c016139fSIftekharul Islam isExtended = content.data[key].hasOwnProperty('ExtendedVersion') && content.data[key].ExtendedVersion != ""; 586c016139fSIftekharul Islam if(isExtended){ 587c016139fSIftekharul Islam extendedVersions = getFormatedExtendedVersions(content.data[key].ExtendedVersion); 588c016139fSIftekharul Islam } 589c016139fSIftekharul Islam data.push(Object.assign({ 590c016139fSIftekharul Islam path: key, 591c016139fSIftekharul Islam active: active, 592c016139fSIftekharul Islam imageId: key.split("/").pop(), 593c016139fSIftekharul Islam imageType: imageType, 594c016139fSIftekharul Islam isExtended: isExtended, 595c016139fSIftekharul Islam extended: { 596c016139fSIftekharul Islam show: false, 597c016139fSIftekharul Islam versions: extendedVersions 598c016139fSIftekharul Islam }, 599c016139fSIftekharul Islam data: {key: key, value: content.data[key]} 600c016139fSIftekharul Islam }, content.data[key])); 601c016139fSIftekharul Islam 602c016139fSIftekharul Islam if(active && imageType == 'BMC'){ 603c016139fSIftekharul Islam bmcActiveVersion = content.data[key].Version; 604c016139fSIftekharul Islam } 605c016139fSIftekharul Islam 606c016139fSIftekharul Islam if(active && imageType == 'Host'){ 607c016139fSIftekharul Islam hostActiveVersion = content.data[key].Version; 608c016139fSIftekharul Islam } 609c016139fSIftekharul Islam } 610c016139fSIftekharul Islam } 611df3bd124SMichael Davis 612df3bd124SMichael Davis deferred.resolve({ 613df3bd124SMichael Davis data: data, 614df3bd124SMichael Davis bmcActiveVersion: bmcActiveVersion, 615df3bd124SMichael Davis hostActiveVersion: hostActiveVersion 616df3bd124SMichael Davis }); 617c016139fSIftekharul Islam }).error(function(error){ 618c016139fSIftekharul Islam console.log(error); 619df3bd124SMichael Davis deferred.reject(error); 620c016139fSIftekharul Islam }); 621df3bd124SMichael Davis 622df3bd124SMichael Davis return deferred.promise; 623c016139fSIftekharul Islam }, 624c016139fSIftekharul Islam uploadImage: function(file, callback){ 625c016139fSIftekharul Islam $http({ 626c016139fSIftekharul Islam method: 'PUT', 627c016139fSIftekharul Islam timeout: 5 * 60 * 1000, 628c016139fSIftekharul Islam //url: 'http://localhost:3002/upload', 629c016139fSIftekharul Islam url: SERVICE.API_CREDENTIALS.host + "/upload/image/", 630c016139fSIftekharul Islam headers: { 631c016139fSIftekharul Islam 'Accept': 'application/octet-stream', 632c016139fSIftekharul Islam 'Content-Type': 'application/octet-stream' 633c016139fSIftekharul Islam }, 634c016139fSIftekharul Islam withCredentials: true, 635c016139fSIftekharul Islam data: file 636c016139fSIftekharul Islam }).success(function(response){ 637c016139fSIftekharul Islam var json = JSON.stringify(response); 638c016139fSIftekharul Islam var content = JSON.parse(json); 639c016139fSIftekharul Islam if(callback){ 640c016139fSIftekharul Islam return callback(content); 641c016139fSIftekharul Islam } 642c016139fSIftekharul Islam }).error(function(error){ 643c016139fSIftekharul Islam if(callback){ 644c016139fSIftekharul Islam callback(error); 645c016139fSIftekharul Islam }else{ 646c016139fSIftekharul Islam console.log(error); 647c016139fSIftekharul Islam } 648c016139fSIftekharul Islam }); 649c016139fSIftekharul Islam }, 650df3bd124SMichael Davis getBMCEthernetInfo: function(){ 651df3bd124SMichael Davis var deferred = $q.defer(); 65254c22e4fSIftekharul Islam $http({ 65354c22e4fSIftekharul Islam method: 'GET', 654f2d74644SIftekharul Islam url: SERVICE.API_CREDENTIALS.host + "/xyz/openbmc_project/inventory/system/chassis/motherboard/boxelder/bmc/ethernet", 65554c22e4fSIftekharul Islam headers: { 65654c22e4fSIftekharul Islam 'Accept': 'application/json', 65754c22e4fSIftekharul Islam 'Content-Type': 'application/json' 65854c22e4fSIftekharul Islam }, 65954c22e4fSIftekharul Islam withCredentials: true 66054c22e4fSIftekharul Islam }).success(function(response){ 66154c22e4fSIftekharul Islam var json = JSON.stringify(response); 66254c22e4fSIftekharul Islam var content = JSON.parse(json); 663df3bd124SMichael Davis deferred.resolve(content.data); 66454c22e4fSIftekharul Islam }).error(function(error){ 66554c22e4fSIftekharul Islam console.log(error); 666df3bd124SMichael Davis deferred.reject(error); 66754c22e4fSIftekharul Islam }); 668df3bd124SMichael Davis 669df3bd124SMichael Davis return deferred.promise; 67054c22e4fSIftekharul Islam }, 67154c22e4fSIftekharul Islam getBMCInfo: function(callback){ 672df3bd124SMichael Davis var deferred = $q.defer(); 67354c22e4fSIftekharul Islam $http({ 67454c22e4fSIftekharul Islam method: 'GET', 675f2d74644SIftekharul Islam url: SERVICE.API_CREDENTIALS.host + "/xyz/openbmc_project/inventory/system/chassis/motherboard/boxelder/bmc", 67654c22e4fSIftekharul Islam headers: { 67754c22e4fSIftekharul Islam 'Accept': 'application/json', 67854c22e4fSIftekharul Islam 'Content-Type': 'application/json' 67954c22e4fSIftekharul Islam }, 68054c22e4fSIftekharul Islam withCredentials: true 68154c22e4fSIftekharul Islam }).success(function(response){ 68254c22e4fSIftekharul Islam var json = JSON.stringify(response); 68354c22e4fSIftekharul Islam var content = JSON.parse(json); 684df3bd124SMichael Davis deferred.resolve(content.data); 68554c22e4fSIftekharul Islam }).error(function(error){ 68654c22e4fSIftekharul Islam console.log(error); 687df3bd124SMichael Davis deferred.reject(error); 68854c22e4fSIftekharul Islam }); 689df3bd124SMichael Davis return deferred.promise; 69054c22e4fSIftekharul Islam }, 691ee27d754SIftekharul Islam getHardwares: function(callback){ 692ee27d754SIftekharul Islam $http({ 693ee27d754SIftekharul Islam method: 'GET', 694f2d74644SIftekharul Islam url: SERVICE.API_CREDENTIALS.host + "/xyz/openbmc_project/inventory/enumerate", 695ee27d754SIftekharul Islam headers: { 696ee27d754SIftekharul Islam 'Accept': 'application/json', 697ee27d754SIftekharul Islam 'Content-Type': 'application/json' 698ee27d754SIftekharul Islam }, 699ee27d754SIftekharul Islam withCredentials: true 700ee27d754SIftekharul Islam }).success(function(response){ 701ee27d754SIftekharul Islam var json = JSON.stringify(response); 702ee27d754SIftekharul Islam var content = JSON.parse(json); 703ee27d754SIftekharul Islam var hardwareData = []; 704ee27d754SIftekharul Islam var keyIndexMap = {}; 705ee27d754SIftekharul Islam var title = ""; 706ee27d754SIftekharul Islam var data = []; 707ee27d754SIftekharul Islam var searchText = ""; 708ee27d754SIftekharul Islam var componentIndex = -1; 709ee27d754SIftekharul Islam var tempParts = []; 710ee27d754SIftekharul Islam 711ee27d754SIftekharul Islam 712ee27d754SIftekharul Islam function isSubComponent(key){ 713ee27d754SIftekharul Islam 714ee27d754SIftekharul Islam for(var i = 0; i < Constants.HARDWARE.parent_components.length; i++){ 715ee27d754SIftekharul Islam if(key.split(Constants.HARDWARE.parent_components[i]).length == 2) return true; 716ee27d754SIftekharul Islam } 717ee27d754SIftekharul Islam 718ee27d754SIftekharul Islam return false; 719ee27d754SIftekharul Islam } 720ee27d754SIftekharul Islam 721ee27d754SIftekharul Islam function titlelize(title){ 722ee27d754SIftekharul Islam title = title.replace(/([A-Z0-9]+)/g, " $1").replace(/^\s+/, ""); 723ee27d754SIftekharul Islam for(var i = 0; i < Constants.HARDWARE.uppercase_titles.length; i++){ 724ee27d754SIftekharul Islam if(title.toLowerCase().indexOf((Constants.HARDWARE.uppercase_titles[i] + " ")) > -1){ 725ee27d754SIftekharul Islam return title.toUpperCase(); 726ee27d754SIftekharul Islam } 727ee27d754SIftekharul Islam } 728ee27d754SIftekharul Islam 729ee27d754SIftekharul Islam return title; 730ee27d754SIftekharul Islam } 731ee27d754SIftekharul Islam 732ee27d754SIftekharul Islam function camelcaseToLabel(obj){ 7338947e701SIftekharul Islam var transformed = [], label = "", value = ""; 734ee27d754SIftekharul Islam for(var key in obj){ 735ee27d754SIftekharul Islam label = key.replace(/([A-Z0-9]+)/g, " $1").replace(/^\s+/, ""); 736ee27d754SIftekharul Islam if(obj[key] !== ""){ 7378947e701SIftekharul Islam value = obj[key]; 7388947e701SIftekharul Islam if(value == 1 || value == 0){ 7398947e701SIftekharul Islam value = (value == 1) ? 'Yes' : 'No'; 7408947e701SIftekharul Islam } 7418947e701SIftekharul Islam transformed.push({key:label, value: value}); 742ee27d754SIftekharul Islam } 743ee27d754SIftekharul Islam } 744ee27d754SIftekharul Islam 745ee27d754SIftekharul Islam return transformed; 746ee27d754SIftekharul Islam } 747ee27d754SIftekharul Islam 748ee27d754SIftekharul Islam function getSearchText(data){ 749ee27d754SIftekharul Islam var searchText = ""; 750ee27d754SIftekharul Islam for(var i = 0; i < data.length; i++){ 751ee27d754SIftekharul Islam searchText += " " + data[i].key + " " + data[i].value; 752ee27d754SIftekharul Islam } 753ee27d754SIftekharul Islam 754ee27d754SIftekharul Islam return searchText; 755ee27d754SIftekharul Islam } 756ee27d754SIftekharul Islam 757ee27d754SIftekharul Islam for(var key in content.data){ 758ee27d754SIftekharul Islam if(content.data.hasOwnProperty(key) && 759ee27d754SIftekharul Islam key.indexOf(Constants.HARDWARE.component_key_filter) == 0){ 760ee27d754SIftekharul Islam 761ee27d754SIftekharul Islam data = camelcaseToLabel(content.data[key]); 762ee27d754SIftekharul Islam searchText = getSearchText(data); 763ee27d754SIftekharul Islam title = key.split("/").pop(); 764ee27d754SIftekharul Islam 765ee27d754SIftekharul Islam title = titlelize(title); 766ee27d754SIftekharul Islam 767ee27d754SIftekharul Islam if(!isSubComponent(key)){ 768ee27d754SIftekharul Islam hardwareData.push(Object.assign({ 769ee27d754SIftekharul Islam path: key, 770ee27d754SIftekharul Islam title: title, 771ee27d754SIftekharul Islam selected: false, 772ee27d754SIftekharul Islam expanded: false, 773ee27d754SIftekharul Islam search_text: title.toLowerCase() + " " + searchText.toLowerCase(), 774ee27d754SIftekharul Islam sub_components: [], 775ee27d754SIftekharul Islam original_data: {key: key, value: content.data[key]} 776ee27d754SIftekharul Islam }, {items: data})); 777ee27d754SIftekharul Islam 778ee27d754SIftekharul Islam keyIndexMap[key] = hardwareData.length - 1; 779ee27d754SIftekharul Islam }else{ 780ee27d754SIftekharul Islam var tempParts = key.split("/"); 781ee27d754SIftekharul Islam tempParts.pop(); 782ee27d754SIftekharul Islam tempParts = tempParts.join("/"); 783ee27d754SIftekharul Islam componentIndex = keyIndexMap[tempParts]; 784ee27d754SIftekharul Islam data = content.data[key]; 785ee27d754SIftekharul Islam data.title = title; 786ee27d754SIftekharul Islam hardwareData[componentIndex].sub_components.push(data); 787ee27d754SIftekharul Islam hardwareData[componentIndex].search_text += " " + title.toLowerCase(); 788ee27d754SIftekharul Islam } 789ee27d754SIftekharul Islam } 790ee27d754SIftekharul Islam } 791ee27d754SIftekharul Islam 792ee27d754SIftekharul Islam if(callback){ 793ee27d754SIftekharul Islam callback(hardwareData, content.data); 794ee27d754SIftekharul Islam }else{ 795ee27d754SIftekharul Islam return { data: hardwareData, original_data: content.data}; 796ee27d754SIftekharul Islam } 797ee27d754SIftekharul Islam }); 798ee27d754SIftekharul Islam }, 799f2d74644SIftekharul Islam deleteLogs: function(logs) { 800f2d74644SIftekharul Islam var defer = $q.defer(); 801f2d74644SIftekharul Islam var promises = []; 802f2d74644SIftekharul Islam 803f2d74644SIftekharul Islam function finished(){ 804f2d74644SIftekharul Islam defer.resolve(); 805f2d74644SIftekharul Islam } 806f2d74644SIftekharul Islam 807f2d74644SIftekharul Islam logs.forEach(function(item){ 808f2d74644SIftekharul Islam promises.push($http({ 809f2d74644SIftekharul Islam method: 'POST', 810f2d74644SIftekharul Islam url: SERVICE.API_CREDENTIALS.host + "/xyz/openbmc_project/logging/entry/"+item.Id+"/action/Delete", 811f2d74644SIftekharul Islam headers: { 812f2d74644SIftekharul Islam 'Accept': 'application/json', 813f2d74644SIftekharul Islam 'Content-Type': 'application/json' 814f2d74644SIftekharul Islam }, 815f2d74644SIftekharul Islam withCredentials: true, 816f2d74644SIftekharul Islam data: JSON.stringify({"data": []}) 817f2d74644SIftekharul Islam })); 818f2d74644SIftekharul Islam }); 819f2d74644SIftekharul Islam 820f2d74644SIftekharul Islam $q.all(promises).then(finished); 821f2d74644SIftekharul Islam 822f2d74644SIftekharul Islam return defer.promise; 823f2d74644SIftekharul Islam }, 824f2d74644SIftekharul Islam resolveLogs: function(logs) { 825f2d74644SIftekharul Islam var defer = $q.defer(); 826f2d74644SIftekharul Islam var promises = []; 827f2d74644SIftekharul Islam 828f2d74644SIftekharul Islam function finished(){ 829f2d74644SIftekharul Islam defer.resolve(); 830f2d74644SIftekharul Islam } 831f2d74644SIftekharul Islam 832f2d74644SIftekharul Islam logs.forEach(function(item){ 833f2d74644SIftekharul Islam promises.push($http({ 834f2d74644SIftekharul Islam method: 'PUT', 835f2d74644SIftekharul Islam url: SERVICE.API_CREDENTIALS.host + "/xyz/openbmc_project/logging/entry/"+item.Id+"/attr/Resolved", 836f2d74644SIftekharul Islam headers: { 837f2d74644SIftekharul Islam 'Accept': 'application/json', 838f2d74644SIftekharul Islam 'Content-Type': 'application/json' 839f2d74644SIftekharul Islam }, 840f2d74644SIftekharul Islam withCredentials: true, 841f2d74644SIftekharul Islam data: JSON.stringify({"data": "1"}) 842f2d74644SIftekharul Islam })); 843f2d74644SIftekharul Islam }); 844f2d74644SIftekharul Islam 845f2d74644SIftekharul Islam $q.all(promises).then(finished); 846f2d74644SIftekharul Islam 847f2d74644SIftekharul Islam return defer.promise; 848f2d74644SIftekharul Islam }, 84999d199f3SIftekharul Islam }; 85099d199f3SIftekharul Islam return SERVICE; 85199d199f3SIftekharul Islam }]); 85299d199f3SIftekharul Islam 85399d199f3SIftekharul Islam })(window.angular); 854