diff options
| author | Andrew Geissler <geissonator@yahoo.com> | 2018-05-24 10:58:00 -0700 |
|---|---|---|
| committer | Andrew Geissler <geissonator@yahoo.com> | 2018-05-24 10:58:00 -0700 |
| commit | ba5e3f3484c0de46f4f5fc5baf5804648179a9eb (patch) | |
| tree | 5bfff42d64b4aac4339fc76a5b6e76f2556b723c /app/common/services | |
| parent | 13251a8e57f3c5bd200ddd7dd42ef4e9af110429 (diff) | |
| download | phosphor-webui-ba5e3f3484c0de46f4f5fc5baf5804648179a9eb.tar.gz phosphor-webui-ba5e3f3484c0de46f4f5fc5baf5804648179a9eb.zip | |
Run js-beautify and fixjsstyle on code
Found this pointer on stackoverflow:
https://stackoverflow.com/a/31660434/5508494
End goal is to get the code formatted well enough that
clang format will run correctly against it.
Change-Id: I80053e78d253d8eee49233e42d55e5807ae8fdc8
Signed-off-by: Andrew Geissler <geissonator@yahoo.com>
Diffstat (limited to 'app/common/services')
| -rw-r--r-- | app/common/services/api-utils.js | 2231 | ||||
| -rw-r--r-- | app/common/services/apiInterceptor.js | 99 | ||||
| -rw-r--r-- | app/common/services/constants.js | 310 | ||||
| -rw-r--r-- | app/common/services/dataService.js | 275 | ||||
| -rw-r--r-- | app/common/services/index.js | 14 | ||||
| -rw-r--r-- | app/common/services/userModel.js | 100 |
6 files changed, 1569 insertions, 1460 deletions
diff --git a/app/common/services/api-utils.js b/app/common/services/api-utils.js index 13f1406..a024142 100644 --- a/app/common/services/api-utils.js +++ b/app/common/services/api-utils.js @@ -6,1134 +6,1233 @@ * @name APIUtils */ -window.angular && (function (angular) { - 'use strict'; - angular - .module('app.common.services') - .factory('APIUtils', ['$http', 'Constants', '$q', 'dataService',function($http, Constants, $q, DataService){ - var getScaledValue = function(value, scale){ - scale = scale + ""; - scale = parseInt(scale, 10); - var power = Math.abs(parseInt(scale,10)); +window.angular && (function(angular) { + 'use strict'; + angular + .module('app.common.services') + .factory('APIUtils', ['$http', 'Constants', '$q', 'dataService', function($http, Constants, $q, DataService) { + var getScaledValue = function(value, scale) { + scale = scale + ''; + scale = parseInt(scale, 10); + var power = Math.abs(parseInt(scale, 10)); - if(scale > 0){ - value = value * Math.pow(10, power); - }else if(scale < 0){ - value = value / Math.pow(10, power); - } - return value; - }; - var SERVICE = { - API_CREDENTIALS: Constants.API_CREDENTIALS, - API_RESPONSE: Constants.API_RESPONSE, - CHASSIS_POWER_STATE: Constants.CHASSIS_POWER_STATE, - HOST_STATE_TEXT: Constants.HOST_STATE, - HOST_STATE: Constants.HOST_STATE, - LED_STATE: Constants.LED_STATE, - LED_STATE_TEXT: Constants.LED_STATE_TEXT, - HOST_SESSION_STORAGE_KEY: Constants.API_CREDENTIALS.host_storage_key, - getChassisState: function(){ - var deferred = $q.defer(); - $http({ - method: 'GET', - url: DataService.getHost() + "/xyz/openbmc_project/state/chassis0/attr/CurrentPowerState", - headers: { - 'Accept': 'application/json', - 'Content-Type': 'application/json' - }, - withCredentials: true - }).then(function(response){ - var json = JSON.stringify(response.data); - var content = JSON.parse(json); - deferred.resolve(content.data); - }, function(error){ - console.log(error); - deferred.reject(error); - }); - return deferred.promise; - }, - getHostState: function(){ - var deferred = $q.defer(); - $http({ - method: 'GET', - url: DataService.getHost() + "/xyz/openbmc_project/state/host0/attr/CurrentHostState", - headers: { - 'Accept': 'application/json', - 'Content-Type': 'application/json' - }, - withCredentials: true - }).then(function(response){ - var json = JSON.stringify(response.data); - var content = JSON.parse(json); - deferred.resolve(content.data); - }, function(error){ - console.log(error); - deferred.reject(error); - }); - return deferred.promise; - }, - getNetworkInfo: function(){ - var deferred = $q.defer(); - $http({ - method: 'GET', - url: DataService.getHost() + "/xyz/openbmc_project/network/enumerate", - headers: { - 'Accept': 'application/json', - 'Content-Type': 'application/json' - }, - withCredentials: true - }).then(function(response){ - var json = JSON.stringify(response.data); - var content = JSON.parse(json); - var hostname = ""; - var macAddress = ""; - - function parseNetworkData(content){ - var data = { - interface_ids: [], - interfaces: {}, - ip_addresses: {ipv4 : [], - ipv6 : []}, - }; - var interfaceId = '', keyParts = [], interfaceHash = '', interfaceType = ''; - for(var key in content.data){ - if(key.match(/network\/eth\d+$/ig)){ - interfaceId = key.split("/").pop(); - if(data.interface_ids.indexOf(interfaceId) == -1){ - data.interface_ids.push(interfaceId); - data.interfaces[interfaceId] = { - interfaceIname: '', - DomainName:'', - MACAddress:'', - Nameservers: [], - DHCPEnabled: 0, - ipv4: - { - ids: [], - values: [] - }, - ipv6: - { - ids: [], - values: [] - } - }; - data.interfaces[interfaceId].MACAddress = content.data[key].MACAddress; - data.interfaces[interfaceId].DomainName = content.data[key].DomainName.join(" "); - data.interfaces[interfaceId].Nameservers = content.data[key].Nameservers; - data.interfaces[interfaceId].DHCPEnabled = content.data[key].DHCPEnabled; - } - }else if(key.match(/network\/eth\d+\/ipv[4|6]\/[a-z0-9]+$/ig)){ - keyParts = key.split("/"); - interfaceHash = keyParts.pop(); - interfaceType = keyParts.pop(); - interfaceId = keyParts.pop(); - - if(data.interfaces[interfaceId][interfaceType].ids.indexOf(interfaceHash) == -1){ - data.interfaces[interfaceId][interfaceType].ids.push(interfaceHash); - data.interfaces[interfaceId][interfaceType].values.push(content.data[key]); - data.ip_addresses[interfaceType].push(content.data[key]['Address']); - } - } - } - return data; - } + if (scale > 0) { + value = value * Math.pow(10, power); + } + else if (scale < 0) { + value = value / Math.pow(10, power); + } + return value; + }; + var SERVICE = { + API_CREDENTIALS: Constants.API_CREDENTIALS, + API_RESPONSE: Constants.API_RESPONSE, + CHASSIS_POWER_STATE: Constants.CHASSIS_POWER_STATE, + HOST_STATE_TEXT: Constants.HOST_STATE, + HOST_STATE: Constants.HOST_STATE, + LED_STATE: Constants.LED_STATE, + LED_STATE_TEXT: Constants.LED_STATE_TEXT, + HOST_SESSION_STORAGE_KEY: Constants.API_CREDENTIALS.host_storage_key, + getChassisState: function() { + var deferred = $q.defer(); + $http({ + method: 'GET', + url: DataService.getHost() + '/xyz/openbmc_project/state/chassis0/attr/CurrentPowerState', + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json' + }, + withCredentials: true + }).then(function(response) { + var json = JSON.stringify(response.data); + var content = JSON.parse(json); + deferred.resolve(content.data); + }, function(error) { + console.log(error); + deferred.reject(error); + }); + return deferred.promise; + }, + getHostState: function() { + var deferred = $q.defer(); + $http({ + method: 'GET', + url: DataService.getHost() + '/xyz/openbmc_project/state/host0/attr/CurrentHostState', + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json' + }, + withCredentials: true + }).then(function(response) { + var json = JSON.stringify(response.data); + var content = JSON.parse(json); + deferred.resolve(content.data); + }, function(error) { + console.log(error); + deferred.reject(error); + }); + return deferred.promise; + }, + getNetworkInfo: function() { + var deferred = $q.defer(); + $http({ + method: 'GET', + url: DataService.getHost() + '/xyz/openbmc_project/network/enumerate', + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json' + }, + withCredentials: true + }).then(function(response) { + var json = JSON.stringify(response.data); + var content = JSON.parse(json); + var hostname = ''; + var macAddress = ''; - if(content.data.hasOwnProperty('/xyz/openbmc_project/network/config') && - content.data['/xyz/openbmc_project/network/config'].hasOwnProperty('HostName') - ){ - hostname = content.data['/xyz/openbmc_project/network/config'].HostName; - } - - if(content.data.hasOwnProperty('/xyz/openbmc_project/network/eth0') && - content.data['/xyz/openbmc_project/network/eth0'].hasOwnProperty('MACAddress') - ){ - macAddress = content.data['/xyz/openbmc_project/network/eth0'].MACAddress; - } - - deferred.resolve({ - data: content.data, - hostname: hostname, - mac_address: macAddress, - formatted_data: parseNetworkData(content) - }); - }, function(error){ - console.log(error); - deferred.reject(error); - }); - return deferred.promise; - }, - getLEDState: function(){ - var deferred = $q.defer(); - $http({ - method: 'GET', - url: DataService.getHost() + "/xyz/openbmc_project/led/groups/enclosure_identify", - headers: { - 'Accept': 'application/json', - 'Content-Type': 'application/json' - }, - withCredentials: true - }).then(function(response){ - var json = JSON.stringify(response.data); - var content = JSON.parse(json); - deferred.resolve(content.data.Asserted); - }, function(error){ - console.log(error); - deferred.reject(error); - }); - return deferred.promise; - }, - login: function(username, password, callback){ - $http({ - method: 'POST', - url: DataService.getHost() + "/login", - headers: { - 'Accept': 'application/json', - 'Content-Type': 'application/json' - }, - withCredentials: true, - data: JSON.stringify({"data": [username, password]}) - }).then(function(response){ - if(callback){ - callback(response.data); - } - }, function(error){ - if(callback){ - if(error && error.status && error.status == 'error'){ - callback(error); - }else{ - callback(error, true); - } - } - console.log(error); - }); - }, - testPassword: function(username, password){ - // Calls /login without the current session to verify the given password is correct - // ignore the interceptor logout on a bad password - DataService.ignoreHttpError = true; - return $http({ - method: 'POST', - url: DataService.getHost() + "/login", - headers: { - 'Accept': 'application/json', - 'Content-Type': 'application/json' - }, - withCredentials: false, - data: JSON.stringify({"data": [username, password]}) - }).then(function(response){ - return response.data; - }); - }, - logout: function(callback){ - $http({ - method: 'POST', - url: DataService.getHost() + "/logout", - headers: { - 'Accept': 'application/json', - 'Content-Type': 'application/json' - }, - withCredentials: true, - data: JSON.stringify({"data": []}) - }).then(function(response){ - if(callback){ - callback(response.data); - } - }, function(error){ - if(callback){ - callback(null, error); - } - console.log(error); - }); - }, - changePassword: function(user, newPassword){ - var deferred = $q.defer(); - $http({ - method: 'POST', - url: DataService.getHost() + "/xyz/openbmc_project/user/" + user + "/action/SetPassword", - headers: { - 'Accept': 'application/json', - 'Content-Type': 'application/json' - }, - withCredentials: true, - data: JSON.stringify({"data": [newPassword]}), - responseType: 'arraybuffer' - }).then(function(response, status, headers){ - deferred.resolve({ - data: response, - status: status, - headers: headers - }); - }, function(error){ - console.log(error); - deferred.reject(error); - }); - return deferred.promise; - }, - chassisPowerOn: function(callback){ - $http({ - method: 'POST', - url: DataService.getHost() + "/xyz/openbmc_project/state/host0", - headers: { - 'Accept': 'application/json', - 'Content-Type': 'application/json' - }, - withCredentials: true, - data: JSON.stringify({"data": []}) - }).then(function(response){ - var json = JSON.stringify(response.data); - var content = JSON.parse(json); - if(callback){ - return callback(content.data.CurrentPowerState); - } - }, function(error){ - if(callback){ - callback(error); - }else{ - console.log(error); - } - }); - }, - chassisPowerOff: function(){ - var deferred = $q.defer(); - $http({ - method: 'PUT', - url: DataService.getHost() + "/xyz/openbmc_project/state/chassis0/attr/RequestedPowerTransition", - headers: { - 'Accept': 'application/json', - 'Content-Type': 'application/json' - }, - withCredentials: true, - data: JSON.stringify({"data": "xyz.openbmc_project.State.Chassis.Transition.Off"}) - }).then(function(response){ - var json = JSON.stringify(response.data); - var content = JSON.parse(json); - deferred.resolve(content.status); - }, function(error){ - console.log(error); - deferred.reject(error); - }); - return deferred.promise; - }, - setLEDState: function(state, callback){ - $http({ - method: 'PUT', - url: DataService.getHost() + "/xyz/openbmc_project/led/groups/enclosure_identify/attr/Asserted", - headers: { - 'Accept': 'application/json', - 'Content-Type': 'application/json' - }, - withCredentials: true, - data: JSON.stringify({"data": state}) - }).then(function(response){ - var json = JSON.stringify(response.data); - var content = JSON.parse(json); - if(callback){ - return callback(content.status); - } - }, function(error){ - if(callback){ - callback(error); - }else{ - console.log(error); - } - }); - }, - bmcReboot: function(callback){ - $http({ - method: 'PUT', - url: DataService.getHost() + "/xyz/openbmc_project/state/bmc0/attr/RequestedBmcTransition", - headers: { - 'Accept': 'application/json', - 'Content-Type': 'application/json' - }, - withCredentials: true, - data: JSON.stringify({"data": "xyz.openbmc_project.State.BMC.Transition.Reboot"}) - }).then(function(response){ - var json = JSON.stringify(response.data); - var content = JSON.parse(json); - if(callback){ - return callback(content.status); + function parseNetworkData(content) { + var data = { + interface_ids: [], + interfaces: {}, + ip_addresses: { + ipv4: [], + ipv6: [] + }, + }; + var interfaceId = '', + keyParts = [], + interfaceHash = '', + interfaceType = ''; + for (var key in content.data) { + if (key.match(/network\/eth\d+$/ig)) { + interfaceId = key.split('/').pop(); + if (data.interface_ids.indexOf(interfaceId) == -1) { + data.interface_ids.push(interfaceId); + data.interfaces[interfaceId] = { + interfaceIname: '', + DomainName: '', + MACAddress: '', + Nameservers: [], + DHCPEnabled: 0, + ipv4: { + ids: [], + values: [] + }, + ipv6: { + ids: [], + values: [] } - }, function(error){ - if(callback){ - callback(error); - }else{ - console.log(error); + }; + data.interfaces[interfaceId].MACAddress = content.data[key].MACAddress; + data.interfaces[interfaceId].DomainName = content.data[key].DomainName.join(' '); + data.interfaces[interfaceId].Nameservers = content.data[key].Nameservers; + data.interfaces[interfaceId].DHCPEnabled = content.data[key].DHCPEnabled; } - }); - }, - hostPowerOn: function(){ - var deferred = $q.defer(); - $http({ - method: 'PUT', - url: DataService.getHost() + "/xyz/openbmc_project/state/host0/attr/RequestedHostTransition", - headers: { - 'Accept': 'application/json', - 'Content-Type': 'application/json' - }, - withCredentials: true, - data: JSON.stringify({"data": "xyz.openbmc_project.State.Host.Transition.On"}) - }).then(function(response){ - var json = JSON.stringify(response.data); - var content = JSON.parse(json); - deferred.resolve(content.status); - }, function(error){ - console.log(error); - deferred.reject(error); - }); - return deferred.promise; - }, - hostPowerOff: function(){ - var deferred = $q.defer(); - $http({ - method: 'PUT', - url: DataService.getHost() + "/xyz/openbmc_project/state/host0/attr/RequestedHostTransition", - headers: { - 'Accept': 'application/json', - 'Content-Type': 'application/json' - }, - withCredentials: true, - data: JSON.stringify({"data": "xyz.openbmc_project.State.Host.Transition.Off"}) - }).then(function(response){ - var json = JSON.stringify(response.data); - var content = JSON.parse(json); - deferred.resolve(content.status); - }, function(error){ - console.log(error); - deferred.reject(error); - }); - return deferred.promise; - }, - hostReboot: function(){ - var deferred = $q.defer(); - $http({ - method: 'PUT', - url: DataService.getHost() + "/xyz/openbmc_project/state/host0/attr/RequestedHostTransition", - headers: { - 'Accept': 'application/json', - 'Content-Type': 'application/json' - }, - withCredentials: true, - data: JSON.stringify({"data": "xyz.openbmc_project.State.Host.Transition.Reboot"}) - }).then(function(response){ - var json = JSON.stringify(response.data); - var content = JSON.parse(json); - deferred.resolve(content.status); - }, function(error){ - console.log(error); - deferred.reject(error); - }); + } + else if (key.match(/network\/eth\d+\/ipv[4|6]\/[a-z0-9]+$/ig)) { + keyParts = key.split('/'); + interfaceHash = keyParts.pop(); + interfaceType = keyParts.pop(); + interfaceId = keyParts.pop(); - return deferred.promise; - }, - hostShutdown: function(callback){ - $http({ - method: 'POST', - url: DataService.getHost() + "/xyz/openbmc_project/state/host0", - headers: { - 'Accept': 'application/json', - 'Content-Type': 'application/json' - }, - withCredentials: true, - data: JSON.stringify({"data": []}) - }).then(function(response){ - var json = JSON.stringify(response.data); - var content = JSON.parse(json); - if(callback){ - return callback(content); - } - }, function(error){ - if(callback){ - callback(error); - }else{ - console.log(error); + if (data.interfaces[interfaceId][interfaceType].ids.indexOf(interfaceHash) == -1) { + data.interfaces[interfaceId][interfaceType].ids.push(interfaceHash); + data.interfaces[interfaceId][interfaceType].values.push(content.data[key]); + data.ip_addresses[interfaceType].push(content.data[key]['Address']); } - }); - }, - getLogs: function(){ - var deferred = $q.defer(); - $http({ - method: 'GET', - url: DataService.getHost() + "/xyz/openbmc_project/logging/enumerate", - headers: { - 'Accept': 'application/json', - 'Content-Type': 'application/json' - }, - withCredentials: true - }).then(function(response){ - var json = JSON.stringify(response.data); - var content = JSON.parse(json); - var dataClone = JSON.parse(JSON.stringify(content.data)); - var data = []; - var severityCode = ''; - var priority = ''; - var health = ''; - var relatedItems = []; + } + } + return data; + } - for(var key in content.data){ - if(content.data.hasOwnProperty(key) && content.data[key].hasOwnProperty('Id')){ - var severityFlags = {low: false, medium: false, high: false}; - var healthFlags = {critical: false, warning: false, good: false}; - severityCode = content.data[key].Severity.split(".").pop(); - priority = Constants.SEVERITY_TO_PRIORITY_MAP[severityCode]; - severityFlags[priority.toLowerCase()] = true; - health = Constants.SEVERITY_TO_HEALTH_MAP[severityCode]; - healthFlags[health.toLowerCase()] = true; - relatedItems = []; - content.data[key].associations.forEach(function(item){ - relatedItems.push(item[2]); - }); + if (content.data.hasOwnProperty('/xyz/openbmc_project/network/config') && + content.data['/xyz/openbmc_project/network/config'].hasOwnProperty('HostName') + ) { + hostname = content.data['/xyz/openbmc_project/network/config'].HostName; + } - data.push(Object.assign({ - path: key, - copied: false, - priority: priority, - severity_code: severityCode, - severity_flags: severityFlags, - health_flags: healthFlags, - additional_data: content.data[key].AdditionalData.join("\n"), - type: content.data[key].Message, - selected: false, - search_text: ("#" + content.data[key].Id + " " + severityCode + " " + content.data[key].Severity + " " + content.data[key].AdditionalData.join(" ")).toLowerCase(), - meta: false, - confirm: false, - related_items: relatedItems, - data: {key: key, value: content.data[key]} - }, content.data[key])); - } - } - deferred.resolve({data: data, original: dataClone}); - }, function(error){ - console.log(error); - deferred.reject(error); - }); + if (content.data.hasOwnProperty('/xyz/openbmc_project/network/eth0') && + content.data['/xyz/openbmc_project/network/eth0'].hasOwnProperty('MACAddress') + ) { + macAddress = content.data['/xyz/openbmc_project/network/eth0'].MACAddress; + } - return deferred.promise; - }, - getAllSensorStatus: function(callback){ - $http({ - method: 'GET', - url: DataService.getHost() + "/xyz/openbmc_project/sensors/enumerate", - headers: { - 'Accept': 'application/json', - 'Content-Type': 'application/json' - }, - withCredentials: true - }).then(function(response){ - var json = JSON.stringify(response.data); - var content = JSON.parse(json); - var dataClone = JSON.parse(JSON.stringify(content.data)); - var sensorData = []; - var severity = {}; - var title = ""; - var tempKeyParts = []; - var order = 0; - var customOrder = 0; + deferred.resolve({ + data: content.data, + hostname: hostname, + mac_address: macAddress, + formatted_data: parseNetworkData(content) + }); + }, function(error) { + console.log(error); + deferred.reject(error); + }); + return deferred.promise; + }, + getLEDState: function() { + var deferred = $q.defer(); + $http({ + method: 'GET', + url: DataService.getHost() + '/xyz/openbmc_project/led/groups/enclosure_identify', + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json' + }, + withCredentials: true + }).then(function(response) { + var json = JSON.stringify(response.data); + var content = JSON.parse(json); + deferred.resolve(content.data.Asserted); + }, function(error) { + console.log(error); + deferred.reject(error); + }); + return deferred.promise; + }, + login: function(username, password, callback) { + $http({ + method: 'POST', + url: DataService.getHost() + '/login', + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json' + }, + withCredentials: true, + data: JSON.stringify({ + 'data': [username, password] + }) + }).then(function(response) { + if (callback) { + callback(response.data); + } + }, function(error) { + if (callback) { + if (error && error.status && error.status == 'error') { + callback(error); + } + else { + callback(error, true); + } + } + console.log(error); + }); + }, + testPassword: function(username, password) { + // Calls /login without the current session to verify the given password is correct + // ignore the interceptor logout on a bad password + DataService.ignoreHttpError = true; + return $http({ + method: 'POST', + url: DataService.getHost() + '/login', + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json' + }, + withCredentials: false, + data: JSON.stringify({ + 'data': [username, password] + }) + }).then(function(response) { + return response.data; + }); + }, + logout: function(callback) { + $http({ + method: 'POST', + url: DataService.getHost() + '/logout', + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json' + }, + withCredentials: true, + data: JSON.stringify({ + 'data': [] + }) + }).then(function(response) { + if (callback) { + callback(response.data); + } + }, function(error) { + if (callback) { + callback(null, error); + } + console.log(error); + }); + }, + changePassword: function(user, newPassword) { + var deferred = $q.defer(); + $http({ + method: 'POST', + url: DataService.getHost() + '/xyz/openbmc_project/user/' + user + '/action/SetPassword', + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json' + }, + withCredentials: true, + data: JSON.stringify({ + 'data': [newPassword] + }), + responseType: 'arraybuffer' + }).then(function(response, status, headers) { + deferred.resolve({ + data: response, + status: status, + headers: headers + }); + }, function(error) { + console.log(error); + deferred.reject(error); + }); + return deferred.promise; + }, + chassisPowerOn: function(callback) { + $http({ + method: 'POST', + url: DataService.getHost() + '/xyz/openbmc_project/state/host0', + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json' + }, + withCredentials: true, + data: JSON.stringify({ + 'data': [] + }) + }).then(function(response) { + var json = JSON.stringify(response.data); + var content = JSON.parse(json); + if (callback) { + return callback(content.data.CurrentPowerState); + } + }, function(error) { + if (callback) { + callback(error); + } + else { + console.log(error); + } + }); + }, + chassisPowerOff: function() { + var deferred = $q.defer(); + $http({ + method: 'PUT', + url: DataService.getHost() + '/xyz/openbmc_project/state/chassis0/attr/RequestedPowerTransition', + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json' + }, + withCredentials: true, + data: JSON.stringify({ + 'data': 'xyz.openbmc_project.State.Chassis.Transition.Off' + }) + }).then(function(response) { + var json = JSON.stringify(response.data); + var content = JSON.parse(json); + deferred.resolve(content.status); + }, function(error) { + console.log(error); + deferred.reject(error); + }); + return deferred.promise; + }, + setLEDState: function(state, callback) { + $http({ + method: 'PUT', + url: DataService.getHost() + '/xyz/openbmc_project/led/groups/enclosure_identify/attr/Asserted', + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json' + }, + withCredentials: true, + data: JSON.stringify({ + 'data': state + }) + }).then(function(response) { + var json = JSON.stringify(response.data); + var content = JSON.parse(json); + if (callback) { + return callback(content.status); + } + }, function(error) { + if (callback) { + callback(error); + } + else { + console.log(error); + } + }); + }, + bmcReboot: function(callback) { + $http({ + method: 'PUT', + url: DataService.getHost() + '/xyz/openbmc_project/state/bmc0/attr/RequestedBmcTransition', + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json' + }, + withCredentials: true, + data: JSON.stringify({ + 'data': 'xyz.openbmc_project.State.BMC.Transition.Reboot' + }) + }).then(function(response) { + var json = JSON.stringify(response.data); + var content = JSON.parse(json); + if (callback) { + return callback(content.status); + } + }, function(error) { + if (callback) { + callback(error); + } + else { + console.log(error); + } + }); + }, + hostPowerOn: function() { + var deferred = $q.defer(); + $http({ + method: 'PUT', + url: DataService.getHost() + '/xyz/openbmc_project/state/host0/attr/RequestedHostTransition', + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json' + }, + withCredentials: true, + data: JSON.stringify({ + 'data': 'xyz.openbmc_project.State.Host.Transition.On' + }) + }).then(function(response) { + var json = JSON.stringify(response.data); + var content = JSON.parse(json); + deferred.resolve(content.status); + }, function(error) { + console.log(error); + deferred.reject(error); + }); + return deferred.promise; + }, + hostPowerOff: function() { + var deferred = $q.defer(); + $http({ + method: 'PUT', + url: DataService.getHost() + '/xyz/openbmc_project/state/host0/attr/RequestedHostTransition', + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json' + }, + withCredentials: true, + data: JSON.stringify({ + 'data': 'xyz.openbmc_project.State.Host.Transition.Off' + }) + }).then(function(response) { + var json = JSON.stringify(response.data); + var content = JSON.parse(json); + deferred.resolve(content.status); + }, function(error) { + console.log(error); + deferred.reject(error); + }); + return deferred.promise; + }, + hostReboot: function() { + var deferred = $q.defer(); + $http({ + method: 'PUT', + url: DataService.getHost() + '/xyz/openbmc_project/state/host0/attr/RequestedHostTransition', + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json' + }, + withCredentials: true, + data: JSON.stringify({ + 'data': 'xyz.openbmc_project.State.Host.Transition.Reboot' + }) + }).then(function(response) { + var json = JSON.stringify(response.data); + var content = JSON.parse(json); + deferred.resolve(content.status); + }, function(error) { + console.log(error); + deferred.reject(error); + }); - function getSensorStatus(reading){ - var severityFlags = {critical: false, warning: false, normal: false}, severityText = '', order = 0; + return deferred.promise; + }, + hostShutdown: function(callback) { + $http({ + method: 'POST', + url: DataService.getHost() + '/xyz/openbmc_project/state/host0', + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json' + }, + withCredentials: true, + data: JSON.stringify({ + 'data': [] + }) + }).then(function(response) { + var json = JSON.stringify(response.data); + var content = JSON.parse(json); + if (callback) { + return callback(content); + } + }, function(error) { + if (callback) { + callback(error); + } + else { + console.log(error); + } + }); + }, + getLogs: function() { + var deferred = $q.defer(); + $http({ + method: 'GET', + url: DataService.getHost() + '/xyz/openbmc_project/logging/enumerate', + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json' + }, + withCredentials: true + }).then(function(response) { + var json = JSON.stringify(response.data); + var content = JSON.parse(json); + var dataClone = JSON.parse(JSON.stringify(content.data)); + var data = []; + var severityCode = ''; + var priority = ''; + var health = ''; + var relatedItems = []; - if(reading.hasOwnProperty('CriticalLow') && - reading.Value < reading.CriticalLow - ){ - severityFlags.critical = true; - severityText = 'critical'; - order = 2; - }else if(reading.hasOwnProperty('CriticalHigh') && - reading.Value > reading.CriticalHigh - ){ - severityFlags.critical = true; - severityText = 'critical'; - order = 2; - }else if(reading.hasOwnProperty('CriticalLow') && - reading.hasOwnProperty('WarningLow') && - reading.Value >= reading.CriticalLow && reading.Value <= reading.WarningLow){ - severityFlags.warning = true; - severityText = 'warning'; - order = 1; - }else if(reading.hasOwnProperty('WarningHigh') && - reading.hasOwnProperty('CriticalHigh') && - reading.Value >= reading.WarningHigh && reading.Value <= reading.CriticalHigh){ - severityFlags.warning = true; - severityText = 'warning'; - order = 1; - }else{ - severityFlags.normal = true; - severityText = 'normal'; - } - return { flags: severityFlags, severityText: severityText, order: order}; - } + for (var key in content.data) { + if (content.data.hasOwnProperty(key) && content.data[key].hasOwnProperty('Id')) { + var severityFlags = { + low: false, + medium: false, + high: false + }; + var healthFlags = { + critical: false, + warning: false, + good: false + }; + severityCode = content.data[key].Severity.split('.').pop(); + priority = Constants.SEVERITY_TO_PRIORITY_MAP[severityCode]; + severityFlags[priority.toLowerCase()] = true; + health = Constants.SEVERITY_TO_HEALTH_MAP[severityCode]; + healthFlags[health.toLowerCase()] = true; + relatedItems = []; + content.data[key].associations.forEach(function(item) { + relatedItems.push(item[2]); + }); - for(var key in content.data){ - if(content.data.hasOwnProperty(key) && content.data[key].hasOwnProperty('Unit')){ + data.push(Object.assign({ + path: key, + copied: false, + priority: priority, + severity_code: severityCode, + severity_flags: severityFlags, + health_flags: healthFlags, + additional_data: content.data[key].AdditionalData.join('\n'), + type: content.data[key].Message, + selected: false, + search_text: ('#' + content.data[key].Id + ' ' + severityCode + ' ' + content.data[key].Severity + ' ' + content.data[key].AdditionalData.join(' ')).toLowerCase(), + meta: false, + confirm: false, + related_items: relatedItems, + data: { + key: key, + value: content.data[key] + } + }, content.data[key])); + } + } + deferred.resolve({ + data: data, + original: dataClone + }); + }, function(error) { + console.log(error); + deferred.reject(error); + }); - severity = getSensorStatus(content.data[key]); + return deferred.promise; + }, + getAllSensorStatus: function(callback) { + $http({ + method: 'GET', + url: DataService.getHost() + '/xyz/openbmc_project/sensors/enumerate', + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json' + }, + withCredentials: true + }).then(function(response) { + var json = JSON.stringify(response.data); + var content = JSON.parse(json); + var dataClone = JSON.parse(JSON.stringify(content.data)); + var sensorData = []; + var severity = {}; + var title = ''; + var tempKeyParts = []; + var order = 0; + var customOrder = 0; - if(!content.data[key].hasOwnProperty('CriticalLow')){ - content.data[key].CriticalLow = "--"; - content.data[key].CriticalHigh = "--"; - } + function getSensorStatus(reading) { + var severityFlags = { + critical: false, + warning: false, + normal: false + }, + severityText = '', + order = 0; - if(!content.data[key].hasOwnProperty('WarningLow')){ - content.data[key].WarningLow = "--"; - content.data[key].WarningHigh = "--"; - } + if (reading.hasOwnProperty('CriticalLow') && + reading.Value < reading.CriticalLow + ) { + severityFlags.critical = true; + severityText = 'critical'; + order = 2; + } + else if (reading.hasOwnProperty('CriticalHigh') && + reading.Value > reading.CriticalHigh + ) { + severityFlags.critical = true; + severityText = 'critical'; + order = 2; + } + else if (reading.hasOwnProperty('CriticalLow') && + reading.hasOwnProperty('WarningLow') && + reading.Value >= reading.CriticalLow && reading.Value <= reading.WarningLow) { + severityFlags.warning = true; + severityText = 'warning'; + order = 1; + } + else if (reading.hasOwnProperty('WarningHigh') && + reading.hasOwnProperty('CriticalHigh') && + reading.Value >= reading.WarningHigh && reading.Value <= reading.CriticalHigh) { + severityFlags.warning = true; + severityText = 'warning'; + order = 1; + } + else { + severityFlags.normal = true; + severityText = 'normal'; + } + return { + flags: severityFlags, + severityText: severityText, + order: order + }; + } - tempKeyParts = key.split("/"); - title = tempKeyParts.pop(); - title = tempKeyParts.pop() + '_' + title; - title = title.split("_").map(function(item){ - return item.toLowerCase().charAt(0).toUpperCase() + item.slice(1); - }).reduce(function(prev, el){ - return prev + " " + el; - }); + for (var key in content.data) { + if (content.data.hasOwnProperty(key) && content.data[key].hasOwnProperty('Unit')) { - content.data[key].Value = getScaledValue(content.data[key].Value, content.data[key].Scale); - content.data[key].CriticalLow = getScaledValue(content.data[key].CriticalLow, content.data[key].Scale); - content.data[key].CriticalHigh = getScaledValue(content.data[key].CriticalHigh, content.data[key].Scale); - content.data[key].WarningLow = getScaledValue(content.data[key].WarningLow, content.data[key].Scale); - content.data[key].WarningHigh = getScaledValue(content.data[key].WarningHigh, content.data[key].Scale); - if(Constants.SENSOR_SORT_ORDER.indexOf(content.data[key].Unit) > -1){ - customOrder = Constants.SENSOR_SORT_ORDER.indexOf(content.data[key].Unit); - }else{ - customOrder = Constants.SENSOR_SORT_ORDER_DEFAULT; - } + severity = getSensorStatus(content.data[key]); - sensorData.push(Object.assign({ - path: key, - selected: false, - confirm: false, - copied: false, - title: title, - unit: Constants.SENSOR_UNIT_MAP[content.data[key].Unit], - severity_flags: severity.flags, - status: severity.severityText, - order: severity.order, - custom_order: customOrder, - search_text: (title + " " + content.data[key].Value + " " + - Constants.SENSOR_UNIT_MAP[content.data[key].Unit] + " " + - severity.severityText + " " + - content.data[key].CriticalLow + " " + - content.data[key].CriticalHigh + " " + - content.data[key].WarningLow + " " + - content.data[key].WarningHigh + " " - ).toLowerCase(), - original_data: {key: key, value: content.data[key]} - }, content.data[key])); - } - } + if (!content.data[key].hasOwnProperty('CriticalLow')) { + content.data[key].CriticalLow = '--'; + content.data[key].CriticalHigh = '--'; + } - callback(sensorData, dataClone); - }, function(error){ - console.log(error); - }); - }, - getActivation: function(imageId){ - return $http({ - method: 'GET', - url: DataService.getHost() + "/xyz/openbmc_project/software/" + imageId + "/attr/Activation", - headers: { - 'Accept': 'application/json', - 'Content-Type': 'application/json' - }, - withCredentials: true - }).then(function(response){ - return response.data; - }); - }, - getFirmwares: function(){ - var deferred = $q.defer(); - $http({ - method: 'GET', - url: DataService.getHost() + "/xyz/openbmc_project/software/enumerate", - headers: { - 'Accept': 'application/json', - 'Content-Type': 'application/json' - }, - withCredentials: true - }).then(function(response){ - var json = JSON.stringify(response.data); - var content = JSON.parse(json); - var data = []; - var activationStatus = ""; - var isExtended = false; - var bmcActiveVersion = ""; - var hostActiveVersion = ""; - var imageType = ""; - var extendedVersions = []; - var functionalImages = []; + if (!content.data[key].hasOwnProperty('WarningLow')) { + content.data[key].WarningLow = '--'; + content.data[key].WarningHigh = '--'; + } - function getFormatedExtendedVersions(extendedVersion){ - var versions = []; - extendedVersion = extendedVersion.split(","); + tempKeyParts = key.split('/'); + title = tempKeyParts.pop(); + title = tempKeyParts.pop() + '_' + title; + title = title.split('_').map(function(item) { + return item.toLowerCase().charAt(0).toUpperCase() + item.slice(1); + }).reduce(function(prev, el) { + return prev + ' ' + el; + }); - extendedVersion.forEach(function(item){ - var parts = item.split("-"); - var numberIndex = 0; - for(var i = 0; i < parts.length; i++){ - if(/[0-9]/.test(parts[i])){ - numberIndex = i; - break; - } - } - var titlePart = parts.splice(0, numberIndex); - titlePart = titlePart.join(""); - titlePart = titlePart[0].toUpperCase() + titlePart.substr(1, titlePart.length); - var versionPart = parts.join("-"); - versions.push({ - title: titlePart, - version: versionPart - }); - }); + content.data[key].Value = getScaledValue(content.data[key].Value, content.data[key].Scale); + content.data[key].CriticalLow = getScaledValue(content.data[key].CriticalLow, content.data[key].Scale); + content.data[key].CriticalHigh = getScaledValue(content.data[key].CriticalHigh, content.data[key].Scale); + content.data[key].WarningLow = getScaledValue(content.data[key].WarningLow, content.data[key].Scale); + content.data[key].WarningHigh = getScaledValue(content.data[key].WarningHigh, content.data[key].Scale); + if (Constants.SENSOR_SORT_ORDER.indexOf(content.data[key].Unit) > -1) { + customOrder = Constants.SENSOR_SORT_ORDER.indexOf(content.data[key].Unit); + } + else { + customOrder = Constants.SENSOR_SORT_ORDER_DEFAULT; + } - return versions; - } + sensorData.push(Object.assign({ + path: key, + selected: false, + confirm: false, + copied: false, + title: title, + unit: Constants.SENSOR_UNIT_MAP[content.data[key].Unit], + severity_flags: severity.flags, + status: severity.severityText, + order: severity.order, + custom_order: customOrder, + search_text: (title + ' ' + content.data[key].Value + ' ' + + Constants.SENSOR_UNIT_MAP[content.data[key].Unit] + ' ' + + severity.severityText + ' ' + + content.data[key].CriticalLow + ' ' + + content.data[key].CriticalHigh + ' ' + + content.data[key].WarningLow + ' ' + + content.data[key].WarningHigh + ' ' + ).toLowerCase(), + original_data: { + key: key, + value: content.data[key] + } + }, content.data[key])); + } + } - // Get the list of functional images so we can compare - // later if an image is functional - if (content.data[Constants.FIRMWARE.FUNCTIONAL_OBJPATH]) - { - functionalImages = content.data[Constants.FIRMWARE.FUNCTIONAL_OBJPATH].endpoints; - } - for(var key in content.data){ - if(content.data.hasOwnProperty(key) && content.data[key].hasOwnProperty('Version')){ - // If the image is "Functional" use that for the - // activation status, else use the value of "Activation" - // github.com/openbmc/phosphor-dbus-interfaces/blob/master/xyz/openbmc_project/Software/Activation.interface.yaml - activationStatus = content.data[key].Activation.split(".").pop(); - if (functionalImages.includes(key)) - { - activationStatus = "Functional"; - } + callback(sensorData, dataClone); + }, function(error) { + console.log(error); + }); + }, + getActivation: function(imageId) { + return $http({ + method: 'GET', + url: DataService.getHost() + '/xyz/openbmc_project/software/' + imageId + '/attr/Activation', + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json' + }, + withCredentials: true + }).then(function(response) { + return response.data; + }); + }, + getFirmwares: function() { + var deferred = $q.defer(); + $http({ + method: 'GET', + url: DataService.getHost() + '/xyz/openbmc_project/software/enumerate', + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json' + }, + withCredentials: true + }).then(function(response) { + var json = JSON.stringify(response.data); + var content = JSON.parse(json); + var data = []; + var activationStatus = ''; + var isExtended = false; + var bmcActiveVersion = ''; + var hostActiveVersion = ''; + var imageType = ''; + var extendedVersions = []; + var functionalImages = []; - imageType = content.data[key].Purpose.split(".").pop(); - isExtended = content.data[key].hasOwnProperty('ExtendedVersion') && content.data[key].ExtendedVersion != ""; - if(isExtended){ - extendedVersions = getFormatedExtendedVersions(content.data[key].ExtendedVersion); - } - data.push(Object.assign({ - path: key, - activationStatus: activationStatus, - imageId: key.split("/").pop(), - imageType: imageType, - isExtended: isExtended, - extended: { - show: false, - versions: extendedVersions - }, - data: {key: key, value: content.data[key]} - }, content.data[key])); + function getFormatedExtendedVersions(extendedVersion) { + var versions = []; + extendedVersion = extendedVersion.split(','); - if(activationStatus == 'Functional' && imageType == 'BMC'){ - bmcActiveVersion = content.data[key].Version; - } + extendedVersion.forEach(function(item) { + var parts = item.split('-'); + var numberIndex = 0; + for (var i = 0; i < parts.length; i++) { + if (/[0-9]/.test(parts[i])) { + numberIndex = i; + break; + } + } + var titlePart = parts.splice(0, numberIndex); + titlePart = titlePart.join(''); + titlePart = titlePart[0].toUpperCase() + titlePart.substr(1, titlePart.length); + var versionPart = parts.join('-'); + versions.push({ + title: titlePart, + version: versionPart + }); + }); - if(activationStatus == 'Functional' && imageType == 'Host'){ - hostActiveVersion = content.data[key].Version; - } - } - } + return versions; + } - deferred.resolve({ - data: data, - bmcActiveVersion: bmcActiveVersion, - hostActiveVersion: hostActiveVersion - }); - }, function(error){ - console.log(error); - deferred.reject(error); - }); + // Get the list of functional images so we can compare + // later if an image is functional + if (content.data[Constants.FIRMWARE.FUNCTIONAL_OBJPATH]) { + functionalImages = content.data[Constants.FIRMWARE.FUNCTIONAL_OBJPATH].endpoints; + } + for (var key in content.data) { + if (content.data.hasOwnProperty(key) && content.data[key].hasOwnProperty('Version')) { + // If the image is "Functional" use that for the + // activation status, else use the value of "Activation" + // github.com/openbmc/phosphor-dbus-interfaces/blob/master/xyz/openbmc_project/Software/Activation.interface.yaml + activationStatus = content.data[key].Activation.split('.').pop(); + if (functionalImages.includes(key)) { + activationStatus = 'Functional'; + } - return deferred.promise; - }, - changePriority: function(imageId, priority){ - var deferred = $q.defer(); - $http({ - method: 'PUT', - url: DataService.getHost() + "/xyz/openbmc_project/software/" + imageId + "/attr/Priority", - headers: { - 'Accept': 'application/json', - 'Content-Type': 'application/json' + imageType = content.data[key].Purpose.split('.').pop(); + isExtended = content.data[key].hasOwnProperty('ExtendedVersion') && content.data[key].ExtendedVersion != ''; + if (isExtended) { + extendedVersions = getFormatedExtendedVersions(content.data[key].ExtendedVersion); + } + data.push(Object.assign({ + path: key, + activationStatus: activationStatus, + imageId: key.split('/').pop(), + imageType: imageType, + isExtended: isExtended, + extended: { + show: false, + versions: extendedVersions }, - withCredentials: true, - data: JSON.stringify({"data": priority}) - }).then(function(response){ - var json = JSON.stringify(response.data); - var content = JSON.parse(json); - deferred.resolve(content); - }, function(error){ - console.log(error); - deferred.reject(error); - }); + data: { + key: key, + value: content.data[key] + } + }, content.data[key])); - return deferred.promise; - }, - deleteImage: function(imageId){ - var deferred = $q.defer(); - $http({ - method: 'POST', - url: DataService.getHost() + "/xyz/openbmc_project/software/" + imageId + "/action/Delete", - headers: { - 'Accept': 'application/json', - 'Content-Type': 'application/json' - }, - withCredentials: true, - data: JSON.stringify({"data": []}) - }).then(function(response){ - var json = JSON.stringify(response.data); - var content = JSON.parse(json); - deferred.resolve(content); - }, function(error){ - console.log(error); - deferred.reject(error); - }); + if (activationStatus == 'Functional' && imageType == 'BMC') { + bmcActiveVersion = content.data[key].Version; + } - return deferred.promise; - }, - activateImage: function(imageId){ - var deferred = $q.defer(); - $http({ - method: 'PUT', - url: DataService.getHost() + "/xyz/openbmc_project/software/" + imageId + "/attr/RequestedActivation", - headers: { - 'Accept': 'application/json', - 'Content-Type': 'application/json' - }, - withCredentials: true, - data: JSON.stringify({"data": Constants.FIRMWARE.ACTIVATE_FIRMWARE}) - }).then(function(response){ - var json = JSON.stringify(response.data); - var content = JSON.parse(json); - deferred.resolve(content); - }, function(error){ - console.log(error); - deferred.reject(error); - }); + if (activationStatus == 'Functional' && imageType == 'Host') { + hostActiveVersion = content.data[key].Version; + } + } + } - return deferred.promise; - }, - uploadImage: function(file){ - return $http({ - method: 'POST', - timeout: 5 * 60 * 1000, - url: DataService.getHost() + "/upload/image", - headers: { - 'Content-Type': 'application/octet-stream' - }, - withCredentials: true, - data: file - }).then(function(response){ - return response.data; - }); - }, - downloadImage: function(host, filename){ - return $http({ - method: 'POST', - url: DataService.getHost() + "/xyz/openbmc_project/software/action/DownloadViaTFTP", - headers: { - 'Accept': 'application/json', - 'Content-Type': 'application/json' - }, - withCredentials: true, - data: JSON.stringify({"data": [filename, host]}), - responseType: 'arraybuffer' - }).then(function(response){ - return response.data; - }); - }, - getBMCEthernetInfo: function(){ - var deferred = $q.defer(); - $http({ - method: 'GET', - url: DataService.getHost() + "/xyz/openbmc_project/inventory/system/chassis/motherboard/boxelder/bmc/ethernet", - headers: { - 'Accept': 'application/json', - 'Content-Type': 'application/json' - }, - withCredentials: true - }).then(function(response){ - var json = JSON.stringify(response.data); - var content = JSON.parse(json); - deferred.resolve(content.data); - }, function(error){ - console.log(error); - deferred.reject(error); - }); + deferred.resolve({ + data: data, + bmcActiveVersion: bmcActiveVersion, + hostActiveVersion: hostActiveVersion + }); + }, function(error) { + console.log(error); + deferred.reject(error); + }); - return deferred.promise; - }, - getBMCInfo: function(callback){ - var deferred = $q.defer(); - $http({ - method: 'GET', - url: DataService.getHost() + "/xyz/openbmc_project/inventory/system/chassis/motherboard/boxelder/bmc", - headers: { - 'Accept': 'application/json', - 'Content-Type': 'application/json' - }, - withCredentials: true - }).then(function(response){ - var json = JSON.stringify(response.data); - var content = JSON.parse(json); - deferred.resolve(content.data); - }, function(error){ - console.log(error); - deferred.reject(error); - }); - return deferred.promise; - }, - getServerInfo: function(){ - // TODO: openbmc/openbmc#3117 Need a way via REST to get - // interfaces so we can get the system object(s) by the looking - // for the system interface. - return $http({ - method: 'GET', - url: DataService.getHost() + "/xyz/openbmc_project/inventory/system", - headers: { - 'Accept': 'application/json', - 'Content-Type': 'application/json' - }, - withCredentials: true - }).then(function(response){ - return response.data; - }); - }, - getBMCTime: function(){ - return $http({ - method: 'GET', - url: DataService.getHost() + "/xyz/openbmc_project/time/bmc", - headers: { - 'Accept': 'application/json', - 'Content-Type': 'application/json' - }, - withCredentials: true - }).then(function(response){ - return response.data; - }); - }, - getHardwares: function(callback){ - $http({ - method: 'GET', - url: DataService.getHost() + "/xyz/openbmc_project/inventory/enumerate", - headers: { - 'Accept': 'application/json', - 'Content-Type': 'application/json' - }, - withCredentials: true - }).then(function(response){ - var json = JSON.stringify(response.data); - var content = JSON.parse(json); - var hardwareData = []; - var keyIndexMap = {}; - var title = ""; - var data = []; - var searchText = ""; - var componentIndex = -1; - var tempParts = []; + return deferred.promise; + }, + changePriority: function(imageId, priority) { + var deferred = $q.defer(); + $http({ + method: 'PUT', + url: DataService.getHost() + '/xyz/openbmc_project/software/' + imageId + '/attr/Priority', + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json' + }, + withCredentials: true, + data: JSON.stringify({ + 'data': priority + }) + }).then(function(response) { + var json = JSON.stringify(response.data); + var content = JSON.parse(json); + deferred.resolve(content); + }, function(error) { + console.log(error); + deferred.reject(error); + }); + return deferred.promise; + }, + deleteImage: function(imageId) { + var deferred = $q.defer(); + $http({ + method: 'POST', + url: DataService.getHost() + '/xyz/openbmc_project/software/' + imageId + '/action/Delete', + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json' + }, + withCredentials: true, + data: JSON.stringify({ + 'data': [] + }) + }).then(function(response) { + var json = JSON.stringify(response.data); + var content = JSON.parse(json); + deferred.resolve(content); + }, function(error) { + console.log(error); + deferred.reject(error); + }); - function isSubComponent(key){ + return deferred.promise; + }, + activateImage: function(imageId) { + var deferred = $q.defer(); + $http({ + method: 'PUT', + url: DataService.getHost() + '/xyz/openbmc_project/software/' + imageId + '/attr/RequestedActivation', + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json' + }, + withCredentials: true, + data: JSON.stringify({ + 'data': Constants.FIRMWARE.ACTIVATE_FIRMWARE + }) + }).then(function(response) { + var json = JSON.stringify(response.data); + var content = JSON.parse(json); + deferred.resolve(content); + }, function(error) { + console.log(error); + deferred.reject(error); + }); - for(var i = 0; i < Constants.HARDWARE.parent_components.length; i++){ - if(key.split(Constants.HARDWARE.parent_components[i]).length == 2) return true; - } + return deferred.promise; + }, + uploadImage: function(file) { + return $http({ + method: 'POST', + timeout: 5 * 60 * 1000, + url: DataService.getHost() + '/upload/image', + headers: { + 'Content-Type': 'application/octet-stream' + }, + withCredentials: true, + data: file + }).then(function(response) { + return response.data; + }); + }, + downloadImage: function(host, filename) { + return $http({ + method: 'POST', + url: DataService.getHost() + '/xyz/openbmc_project/software/action/DownloadViaTFTP', + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json' + }, + withCredentials: true, + data: JSON.stringify({ + 'data': [filename, host] + }), + responseType: 'arraybuffer' + }).then(function(response) { + return response.data; + }); + }, + getBMCEthernetInfo: function() { + var deferred = $q.defer(); + $http({ + method: 'GET', + url: DataService.getHost() + '/xyz/openbmc_project/inventory/system/chassis/motherboard/boxelder/bmc/ethernet', + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json' + }, + withCredentials: true + }).then(function(response) { + var json = JSON.stringify(response.data); + var content = JSON.parse(json); + deferred.resolve(content.data); + }, function(error) { + console.log(error); + deferred.reject(error); + }); - return false; - } + return deferred.promise; + }, + getBMCInfo: function(callback) { + var deferred = $q.defer(); + $http({ + method: 'GET', + url: DataService.getHost() + '/xyz/openbmc_project/inventory/system/chassis/motherboard/boxelder/bmc', + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json' + }, + withCredentials: true + }).then(function(response) { + var json = JSON.stringify(response.data); + var content = JSON.parse(json); + deferred.resolve(content.data); + }, function(error) { + console.log(error); + deferred.reject(error); + }); + return deferred.promise; + }, + getServerInfo: function() { + // TODO: openbmc/openbmc#3117 Need a way via REST to get + // interfaces so we can get the system object(s) by the looking + // for the system interface. + return $http({ + method: 'GET', + url: DataService.getHost() + '/xyz/openbmc_project/inventory/system', + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json' + }, + withCredentials: true + }).then(function(response) { + return response.data; + }); + }, + getBMCTime: function() { + return $http({ + method: 'GET', + url: DataService.getHost() + '/xyz/openbmc_project/time/bmc', + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json' + }, + withCredentials: true + }).then(function(response) { + return response.data; + }); + }, + getHardwares: function(callback) { + $http({ + method: 'GET', + url: DataService.getHost() + '/xyz/openbmc_project/inventory/enumerate', + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json' + }, + withCredentials: true + }).then(function(response) { + var json = JSON.stringify(response.data); + var content = JSON.parse(json); + var hardwareData = []; + var keyIndexMap = {}; + var title = ''; + var data = []; + var searchText = ''; + var componentIndex = -1; + var tempParts = []; - function titlelize(title){ - title = title.replace(/([A-Z0-9]+)/g, " $1").replace(/^\s+/, ""); - for(var i = 0; i < Constants.HARDWARE.uppercase_titles.length; i++){ - if(title.toLowerCase().indexOf((Constants.HARDWARE.uppercase_titles[i] + " ")) > -1){ - return title.toUpperCase(); - } - } - return title; - } + function isSubComponent(key) { - function camelcaseToLabel(obj){ - var transformed = [], label = "", value = ""; - for(var key in obj){ - label = key.replace(/([A-Z0-9]+)/g, " $1").replace(/^\s+/, ""); - if(obj[key] !== ""){ - value = obj[key]; - if(value == 1 || value == 0){ - value = (value == 1) ? 'Yes' : 'No'; - } - transformed.push({key:label, value: value}); - } - } + for (var i = 0; i < Constants.HARDWARE.parent_components.length; i++) { + if (key.split(Constants.HARDWARE.parent_components[i]).length == 2) return true; + } - return transformed; - } + return false; + } - function getSearchText(data){ - var searchText = ""; - for(var i = 0; i < data.length; i++){ - searchText += " " + data[i].key + " " + data[i].value; - } + function titlelize(title) { + title = title.replace(/([A-Z0-9]+)/g, ' $1').replace(/^\s+/, ''); + for (var i = 0; i < Constants.HARDWARE.uppercase_titles.length; i++) { + if (title.toLowerCase().indexOf((Constants.HARDWARE.uppercase_titles[i] + ' ')) > -1) { + return title.toUpperCase(); + } + } - return searchText; - } + return title; + } - for(var key in content.data){ - if(content.data.hasOwnProperty(key) && - key.indexOf(Constants.HARDWARE.component_key_filter) == 0){ + function camelcaseToLabel(obj) { + var transformed = [], + label = '', + value = ''; + for (var key in obj) { + label = key.replace(/([A-Z0-9]+)/g, ' $1').replace(/^\s+/, ''); + if (obj[key] !== '') { + value = obj[key]; + if (value == 1 || value == 0) { + value = (value == 1) ? 'Yes' : 'No'; + } + transformed.push({ + key: label, + value: value + }); + } + } - data = camelcaseToLabel(content.data[key]); - searchText = getSearchText(data); - title = key.split("/").pop(); + return transformed; + } - title = titlelize(title); + function getSearchText(data) { + var searchText = ''; + for (var i = 0; i < data.length; i++) { + searchText += ' ' + data[i].key + ' ' + data[i].value; + } - if(!isSubComponent(key)){ - hardwareData.push(Object.assign({ - path: key, - title: title, - selected: false, - expanded: false, - search_text: title.toLowerCase() + " " + searchText.toLowerCase(), - sub_components: [], - original_data: {key: key, value: content.data[key]} - }, {items: data})); + return searchText; + } - keyIndexMap[key] = hardwareData.length - 1; - }else{ - var tempParts = key.split("/"); - tempParts.pop(); - tempParts = tempParts.join("/"); - componentIndex = keyIndexMap[tempParts]; - data = content.data[key]; - data.title = title; - hardwareData[componentIndex].sub_components.push(data); - hardwareData[componentIndex].search_text += " " + title.toLowerCase(); + for (var key in content.data) { + if (content.data.hasOwnProperty(key) && + key.indexOf(Constants.HARDWARE.component_key_filter) == 0) { - // Sort the subcomponents alphanumeric so they are displayed on the - // inventory page in order (e.g. core 0, core 1, core 2, ... core 12, core 13) - hardwareData[componentIndex].sub_components.sort(function (a, b) { - return a.title.localeCompare(b.title, 'en', { numeric: true }); - }); - } - } - } + data = camelcaseToLabel(content.data[key]); + searchText = getSearchText(data); + title = key.split('/').pop(); + + title = titlelize(title); - if(callback){ - callback(hardwareData, content.data); - }else{ - return { data: hardwareData, original_data: content.data}; + if (!isSubComponent(key)) { + hardwareData.push(Object.assign({ + path: key, + title: title, + selected: false, + expanded: false, + search_text: title.toLowerCase() + ' ' + searchText.toLowerCase(), + sub_components: [], + original_data: { + key: key, + value: content.data[key] } - }); - }, - deleteLogs: function(logs) { - var defer = $q.defer(); - var promises = []; + }, { + items: data + })); - function finished(){ - defer.resolve(); - } + keyIndexMap[key] = hardwareData.length - 1; + } + else { + var tempParts = key.split('/'); + tempParts.pop(); + tempParts = tempParts.join('/'); + componentIndex = keyIndexMap[tempParts]; + data = content.data[key]; + data.title = title; + hardwareData[componentIndex].sub_components.push(data); + hardwareData[componentIndex].search_text += ' ' + title.toLowerCase(); - logs.forEach(function(item){ - promises.push($http({ - method: 'POST', - url: DataService.getHost() + "/xyz/openbmc_project/logging/entry/"+item.Id+"/action/Delete", - headers: { - 'Accept': 'application/json', - 'Content-Type': 'application/json' - }, - withCredentials: true, - data: JSON.stringify({"data": []}) - })); + // Sort the subcomponents alphanumeric so they are displayed on the + // inventory page in order (e.g. core 0, core 1, core 2, ... core 12, core 13) + hardwareData[componentIndex].sub_components.sort(function(a, b) { + return a.title.localeCompare(b.title, 'en', { + numeric: true + }); }); + } + } + } + + if (callback) { + callback(hardwareData, content.data); + } + else { + return { + data: hardwareData, + original_data: content.data + }; + } + }); + }, + deleteLogs: function(logs) { + var defer = $q.defer(); + var promises = []; - $q.all(promises).then(finished); + function finished() { + defer.resolve(); + } - return defer.promise; + logs.forEach(function(item) { + promises.push($http({ + method: 'POST', + url: DataService.getHost() + '/xyz/openbmc_project/logging/entry/' + item.Id + '/action/Delete', + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json' }, - resolveLogs: function(logs) { - var defer = $q.defer(); - var promises = []; + withCredentials: true, + data: JSON.stringify({ + 'data': [] + }) + })); + }); - function finished(){ - defer.resolve(); - } + $q.all(promises).then(finished); - logs.forEach(function(item){ - promises.push($http({ - method: 'PUT', - url: DataService.getHost() + "/xyz/openbmc_project/logging/entry/"+item.Id+"/attr/Resolved", - headers: { - 'Accept': 'application/json', - 'Content-Type': 'application/json' - }, - withCredentials: true, - data: JSON.stringify({"data": "1"}) - })); - }); + return defer.promise; + }, + resolveLogs: function(logs) { + var defer = $q.defer(); + var promises = []; - $q.all(promises).then(finished); + function finished() { + defer.resolve(); + } - return defer.promise; + logs.forEach(function(item) { + promises.push($http({ + method: 'PUT', + url: DataService.getHost() + '/xyz/openbmc_project/logging/entry/' + item.Id + '/attr/Resolved', + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json' }, - getPowerConsumption: function(){ - return $http({ - method: 'GET', - url: DataService.getHost() + "/xyz/openbmc_project/sensors/power/total_power", - headers: { - 'Accept': 'application/json', - 'Content-Type': 'application/json' - }, - withCredentials: true - }).then(function(response){ - var json = JSON.stringify(response.data); - var content = JSON.parse(json); + withCredentials: true, + data: JSON.stringify({ + 'data': '1' + }) + })); + }); - return getScaledValue(content.data.Value, - content.data.Scale) + ' ' + - Constants.POWER_CONSUMPTION_TEXT[content.data.Unit]; - }, function(error){ - if ('Not Found' == error.statusText) { - return Constants.POWER_CONSUMPTION_TEXT.notavailable; - } else { - throw error; - } - }); - }, - getPowerCap: function(){ - return $http({ - method: 'GET', - url: DataService.getHost() + "/xyz/openbmc_project/control/host0/power_cap", - headers: { - 'Accept': 'application/json', - 'Content-Type': 'application/json' - }, - withCredentials: true - }).then(function(response){ - var json = JSON.stringify(response.data); - var content = JSON.parse(json); + $q.all(promises).then(finished); - return (false == content.data.PowerCapEnable) ? - Constants.POWER_CAP_TEXT.disabled : - content.data.PowerCap + ' ' + Constants.POWER_CAP_TEXT.unit; - }); - }, - setHostname: function(hostname){ - return $http({ - method: 'PUT', - url: DataService.getHost() + "/xyz/openbmc_project/network/config/attr/HostName", - headers: { - 'Accept': 'application/json', - 'Content-Type': 'application/json' - }, - withCredentials: true, - data: JSON.stringify({"data": hostname}) - }).then(function(response){ - return response.data; - }); - }, - }; - return SERVICE; - }]); + return defer.promise; + }, + getPowerConsumption: function() { + return $http({ + method: 'GET', + url: DataService.getHost() + '/xyz/openbmc_project/sensors/power/total_power', + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json' + }, + withCredentials: true + }).then(function(response) { + var json = JSON.stringify(response.data); + var content = JSON.parse(json); + + return getScaledValue(content.data.Value, + content.data.Scale) + ' ' + + Constants.POWER_CONSUMPTION_TEXT[content.data.Unit]; + }, function(error) { + if ('Not Found' == error.statusText) { + return Constants.POWER_CONSUMPTION_TEXT.notavailable; + } + else { + throw error; + } + }); + }, + getPowerCap: function() { + return $http({ + method: 'GET', + url: DataService.getHost() + '/xyz/openbmc_project/control/host0/power_cap', + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json' + }, + withCredentials: true + }).then(function(response) { + var json = JSON.stringify(response.data); + var content = JSON.parse(json); + + return (false == content.data.PowerCapEnable) ? + Constants.POWER_CAP_TEXT.disabled : + content.data.PowerCap + ' ' + Constants.POWER_CAP_TEXT.unit; + }); + }, + setHostname: function(hostname) { + return $http({ + method: 'PUT', + url: DataService.getHost() + '/xyz/openbmc_project/network/config/attr/HostName', + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json' + }, + withCredentials: true, + data: JSON.stringify({ + 'data': hostname + }) + }).then(function(response) { + return response.data; + }); + }, + }; + return SERVICE; + }]); - })(window.angular); +})(window.angular); diff --git a/app/common/services/apiInterceptor.js b/app/common/services/apiInterceptor.js index de344cd..b3f2ff4 100644 --- a/app/common/services/apiInterceptor.js +++ b/app/common/services/apiInterceptor.js @@ -7,60 +7,61 @@ */ -window.angular && (function (angular) { - 'use strict'; +window.angular && (function(angular) { + 'use strict'; - angular - .module('app.common.services') - .service('apiInterceptor', ['$q', '$rootScope', 'dataService', function($q, $rootScope, dataService){ - return { - 'request': function(config){ - dataService.loading = true; - // If caller has not defined a timeout, set to default of 20s - if (config.timeout == null){ - config.timeout = 20000; - } - return config; - }, - 'response': function(response){ - dataService.loading = false; + angular + .module('app.common.services') + .service('apiInterceptor', ['$q', '$rootScope', 'dataService', function($q, $rootScope, dataService) { + return { + 'request': function(config) { + dataService.loading = true; + // If caller has not defined a timeout, set to default of 20s + if (config.timeout == null) { + config.timeout = 20000; + } + return config; + }, + 'response': function(response) { + dataService.loading = false; - //not interested in template requests - if(!/^https?\:/i.test(response.config.url)){ - return response; - } + //not interested in template requests + if (!/^https?\:/i.test(response.config.url)) { + return response; + } - dataService.last_updated = new Date(); - if(!response){ - dataService.server_unreachable = true; - }else{ - dataService.server_unreachable = false; - } + dataService.last_updated = new Date(); + if (!response) { + dataService.server_unreachable = true; + } + else { + dataService.server_unreachable = false; + } - if(response && response.status == 'error' && - dataService.path != '/login'){ - $rootScope.$emit('timedout-user', {}); - } + if (response && response.status == 'error' && + dataService.path != '/login') { + $rootScope.$emit('timedout-user', {}); + } - return response; - }, - 'responseError': function(rejection){ - if (dataService.ignoreHttpError === false) - { - // If unauthorized, log out - if (rejection.status == 401){ - if (dataService.path != '/login'){ - $rootScope.$emit('timedout-user', {}); - } - } else if (rejection.status == -1){ - dataService.server_unreachable = true; - } + return response; + }, + 'responseError': function(rejection) { + if (dataService.ignoreHttpError === false) { + // If unauthorized, log out + if (rejection.status == 401) { + if (dataService.path != '/login') { + $rootScope.$emit('timedout-user', {}); + } + } + else if (rejection.status == -1) { + dataService.server_unreachable = true; + } - dataService.loading = false; - } - return $q.reject(rejection); - } - }; - }]); + dataService.loading = false; + } + return $q.reject(rejection); + } + }; + }]); })(window.angular); diff --git a/app/common/services/constants.js b/app/common/services/constants.js index 8b51341..d749ea8 100644 --- a/app/common/services/constants.js +++ b/app/common/services/constants.js @@ -7,161 +7,161 @@ */ -window.angular && (function (angular) { - 'use strict'; +window.angular && (function(angular) { + 'use strict'; - angular - .module('app.common.services', []) - .service('Constants', function () { - return { - API_CREDENTIALS: { - host_storage_key: 'API_HOST_KEY', - default_protocol: 'https' - }, - API_RESPONSE: { - ERROR_STATUS: 'error', - ERROR_MESSAGE: '401 Unauthorized', - SUCCESS_STATUS: 'ok', - SUCCESS_MESSAGE: '200 OK' - }, - CHASSIS_POWER_STATE: { - on: 'On', - on_code: 'xyz.openbmc_project.State.Chassis.PowerState.On', - off: 'Off', - off_code: 'xyz.openbmc_project.State.Chassis.PowerState.Off' - }, - HOST_STATE_TEXT: { - on: 'Running', - on_code: 'xyz.openbmc_project.State.Host.HostState.Running', - off: 'Off', - off_code: 'xyz.openbmc_project.State.Host.HostState.Off', - error: 'Quiesced', - error_code: 'xyz.openbmc_project.State.Host.HostState.Quiesced', - unreachable: 'Unreachable' - }, - HOST_STATE: { - on: 1, - off: -1, - error: 0, - unreachable: -2 - }, - LED_STATE: { - on: true, - off: false - }, - LED_STATE_TEXT: { - on: 'on', - off: 'off' - }, - SEVERITY_TO_HEALTH_MAP:{ - Emergency: 'Critical', - Alert: 'Critical', - Critical: 'Critical', - Error: 'Warning', - Warning: 'Warning', - Notice: 'Good', - Debug: 'Good', - Informational: 'Good' - }, - SEVERITY_TO_PRIORITY_MAP:{ - Emergency: 'High', - Alert: 'High', - Critical: 'High', - Error: 'High', - Warning: 'Medium', - Notice: 'Low', - Debug: 'Low', - Informational: 'Low' - }, - PAGINATION: { - LOG_ITEMS_PER_PAGE: 25 - }, - HARDWARE: { - component_key_filter: '/xyz/openbmc_project/inventory/system', - parent_components: [ - /xyz\/openbmc_project\/inventory\/system\/chassis\/motherboard\/cpu\d+\// - ], - uppercase_titles: [ - 'cpu', 'dimm' - ] - }, - SENSOR_UNIT_MAP: { - 'xyz.openbmc_project.Sensor.Value.Unit.RPMS': 'rpms', - 'xyz.openbmc_project.Sensor.Value.Unit.DegreesC': 'C', - 'xyz.openbmc_project.Sensor.Value.Unit.Volts': 'volts', - 'xyz.openbmc_project.Sensor.Value.Unit.Meters': 'meters', - 'xyz.openbmc_project.Sensor.Value.Unit.Watts': 'watts', - 'xyz.openbmc_project.Sensor.Value.Unit.Amperes': 'amperes', - 'xyz.openbmc_project.Sensor.Value.Unit.Joules': 'joules' - }, - SERVER_HEALTH: { - critical: 'Critical', - warning: 'Warning', - good: 'Good', - unknown: 'Unknown' - }, - SENSOR_SORT_ORDER: [ - 'xyz.openbmc_project.Sensor.Value.Unit.DegreesC', - 'xyz.openbmc_project.Sensor.Value.Unit.RPMS', - 'xyz.openbmc_project.Sensor.Value.Unit.Meters', - 'xyz.openbmc_project.Sensor.Value.Unit.Volts', - 'xyz.openbmc_project.Sensor.Value.Unit.Amperes', - 'xyz.openbmc_project.Sensor.Value.Unit.Joules', - 'xyz.openbmc_project.Sensor.Value.Unit.Meters' - ], - SENSOR_SORT_ORDER_DEFAULT: 8, - FIRMWARE: { - ACTIVATE_FIRMWARE: 'xyz.openbmc_project.Software.Activation.RequestedActivations.Active', - FUNCTIONAL_OBJPATH: '/xyz/openbmc_project/software/functional' - }, - POLL_INTERVALS: { - ACTIVATION: 5000, - DOWNLOAD_IMAGE: 5000, - POWER_OP: 5000, - }, - TIMEOUT: { - ACTIVATION: 1000 * 60 * 10, // 10 mins - DOWNLOAD_IMAGE: 1000 * 60 * 2, // 2 mins - CHASSIS_OFF: 1000 * 60 * 5, // 5 mins - HOST_ON: 1000 * 60 * 5, // 5 mins - HOST_OFF: 1000 * 60 * 5, // 5 mins - }, - MESSAGES: { - POLL: { - CHASSIS_OFF_TIMEOUT: 'Time out. Chassis did not reach power off state in allotted time.', - HOST_ON_TIMEOUT: 'Time out. System did not reach Running state in allotted time.', - HOST_OFF_TIMEOUT: 'Time out. System did not reach Off state in allotted time.', - HOST_QUIESCED: 'System is in Error state.', - DOWNLOAD_IMAGE_TIMEOUT: 'Time out. Did not download image in allotted time.', - }, - POWER_OP: { - POWER_ON_FAILED: 'Power On Failed', - WARM_REBOOT_FAILED: 'Warm Reboot Failed', - COLD_REBOOT_FAILED: 'Cold Reboot Failed', - ORDERLY_SHUTDOWN_FAILED: 'Orderly Shutdown Failed', - IMMEDIATE_SHUTDOWN_FAILED: 'Immediate Shutdown Failed', - }, - SENSOR: { - NO_SENSOR_DATA: 'There are no sensors found.', - CRITICAL_NO_SENSOR_DATA: 'There are no sensors in Critical state.', - WARNING_NO_SENSOR_DATA: 'There are no sensors in Warning state.', - NORMAL_NO_SENSOR_DATA: 'There are no sensors in Normal state.' - }, - ERROR_MODAL: { - TITLE: 'Unexpected error', - DESCRIPTION: 'Oops! An unexpected error occurred. Record specific details of the issue, then contact your company support services.' - }, - ERROR_MESSAGE_DESC_TEMPLATE: '{{status}} - {{description}}', - }, - POWER_CAP_TEXT: { - unit: 'W', - disabled: 'Not Enabled' - }, - POWER_CONSUMPTION_TEXT: { - 'xyz.openbmc_project.Sensor.Value.Unit.Watts': 'W', - notavailable: 'Not Available' - }, - }; - }); + angular + .module('app.common.services', []) + .service('Constants', function() { + return { + API_CREDENTIALS: { + host_storage_key: 'API_HOST_KEY', + default_protocol: 'https' + }, + API_RESPONSE: { + ERROR_STATUS: 'error', + ERROR_MESSAGE: '401 Unauthorized', + SUCCESS_STATUS: 'ok', + SUCCESS_MESSAGE: '200 OK' + }, + CHASSIS_POWER_STATE: { + on: 'On', + on_code: 'xyz.openbmc_project.State.Chassis.PowerState.On', + off: 'Off', + off_code: 'xyz.openbmc_project.State.Chassis.PowerState.Off' + }, + HOST_STATE_TEXT: { + on: 'Running', + on_code: 'xyz.openbmc_project.State.Host.HostState.Running', + off: 'Off', + off_code: 'xyz.openbmc_project.State.Host.HostState.Off', + error: 'Quiesced', + error_code: 'xyz.openbmc_project.State.Host.HostState.Quiesced', + unreachable: 'Unreachable' + }, + HOST_STATE: { + on: 1, + off: -1, + error: 0, + unreachable: -2 + }, + LED_STATE: { + on: true, + off: false + }, + LED_STATE_TEXT: { + on: 'on', + off: 'off' + }, + SEVERITY_TO_HEALTH_MAP: { + Emergency: 'Critical', + Alert: 'Critical', + Critical: 'Critical', + Error: 'Warning', + Warning: 'Warning', + Notice: 'Good', + Debug: 'Good', + Informational: 'Good' + }, + SEVERITY_TO_PRIORITY_MAP: { + Emergency: 'High', + Alert: 'High', + Critical: 'High', + Error: 'High', + Warning: 'Medium', + Notice: 'Low', + Debug: 'Low', + Informational: 'Low' + }, + PAGINATION: { + LOG_ITEMS_PER_PAGE: 25 + }, + HARDWARE: { + component_key_filter: '/xyz/openbmc_project/inventory/system', + parent_components: [ + /xyz\/openbmc_project\/inventory\/system\/chassis\/motherboard\/cpu\d+\// + ], + uppercase_titles: [ + 'cpu', 'dimm' + ] + }, + SENSOR_UNIT_MAP: { + 'xyz.openbmc_project.Sensor.Value.Unit.RPMS': 'rpms', + 'xyz.openbmc_project.Sensor.Value.Unit.DegreesC': 'C', + 'xyz.openbmc_project.Sensor.Value.Unit.Volts': 'volts', + 'xyz.openbmc_project.Sensor.Value.Unit.Meters': 'meters', + 'xyz.openbmc_project.Sensor.Value.Unit.Watts': 'watts', + 'xyz.openbmc_project.Sensor.Value.Unit.Amperes': 'amperes', + 'xyz.openbmc_project.Sensor.Value.Unit.Joules': 'joules' + }, + SERVER_HEALTH: { + critical: 'Critical', + warning: 'Warning', + good: 'Good', + unknown: 'Unknown' + }, + SENSOR_SORT_ORDER: [ + 'xyz.openbmc_project.Sensor.Value.Unit.DegreesC', + 'xyz.openbmc_project.Sensor.Value.Unit.RPMS', + 'xyz.openbmc_project.Sensor.Value.Unit.Meters', + 'xyz.openbmc_project.Sensor.Value.Unit.Volts', + 'xyz.openbmc_project.Sensor.Value.Unit.Amperes', + 'xyz.openbmc_project.Sensor.Value.Unit.Joules', + 'xyz.openbmc_project.Sensor.Value.Unit.Meters' + ], + SENSOR_SORT_ORDER_DEFAULT: 8, + FIRMWARE: { + ACTIVATE_FIRMWARE: 'xyz.openbmc_project.Software.Activation.RequestedActivations.Active', + FUNCTIONAL_OBJPATH: '/xyz/openbmc_project/software/functional' + }, + POLL_INTERVALS: { + ACTIVATION: 5000, + DOWNLOAD_IMAGE: 5000, + POWER_OP: 5000, + }, + TIMEOUT: { + ACTIVATION: 1000 * 60 * 10, // 10 mins + DOWNLOAD_IMAGE: 1000 * 60 * 2, // 2 mins + CHASSIS_OFF: 1000 * 60 * 5, // 5 mins + HOST_ON: 1000 * 60 * 5, // 5 mins + HOST_OFF: 1000 * 60 * 5, // 5 mins + }, + MESSAGES: { + POLL: { + CHASSIS_OFF_TIMEOUT: 'Time out. Chassis did not reach power off state in allotted time.', + HOST_ON_TIMEOUT: 'Time out. System did not reach Running state in allotted time.', + HOST_OFF_TIMEOUT: 'Time out. System did not reach Off state in allotted time.', + HOST_QUIESCED: 'System is in Error state.', + DOWNLOAD_IMAGE_TIMEOUT: 'Time out. Did not download image in allotted time.', + }, + POWER_OP: { + POWER_ON_FAILED: 'Power On Failed', + WARM_REBOOT_FAILED: 'Warm Reboot Failed', + COLD_REBOOT_FAILED: 'Cold Reboot Failed', + ORDERLY_SHUTDOWN_FAILED: 'Orderly Shutdown Failed', + IMMEDIATE_SHUTDOWN_FAILED: 'Immediate Shutdown Failed', + }, + SENSOR: { + NO_SENSOR_DATA: 'There are no sensors found.', + CRITICAL_NO_SENSOR_DATA: 'There are no sensors in Critical state.', + WARNING_NO_SENSOR_DATA: 'There are no sensors in Warning state.', + NORMAL_NO_SENSOR_DATA: 'There are no sensors in Normal state.' + }, + ERROR_MODAL: { + TITLE: 'Unexpected error', + DESCRIPTION: 'Oops! An unexpected error occurred. Record specific details of the issue, then contact your company support services.' + }, + ERROR_MESSAGE_DESC_TEMPLATE: '{{status}} - {{description}}', + }, + POWER_CAP_TEXT: { + unit: 'W', + disabled: 'Not Enabled' + }, + POWER_CONSUMPTION_TEXT: { + 'xyz.openbmc_project.Sensor.Value.Unit.Watts': 'W', + notavailable: 'Not Available' + }, + }; + }); })(window.angular); diff --git a/app/common/services/dataService.js b/app/common/services/dataService.js index d39e757..79a3a0e 100644 --- a/app/common/services/dataService.js +++ b/app/common/services/dataService.js @@ -7,141 +7,144 @@ */ -window.angular && (function (angular) { - 'use strict'; - - angular - .module('app.common.services') - .service('dataService', ['Constants', function (Constants) { - this.server_health = Constants.SERVER_HEALTH.unknown; - this.server_state = 'Unreachable'; - this.server_status = -2; - this.chassis_state = 'On'; - this.LED_state = Constants.LED_STATE_TEXT.off; - this.last_updated = new Date(); - - this.loading = false; - this.server_unreachable = false; - this.loading_message = ""; - this.showNavigation = false; - this.bodyStyle = {}; - this.path = ''; - this.sensorData = []; - - this.hostname = ""; - this.mac_address = ""; - this.remote_window_active = false; - - this.displayErrorModal = false; - this.errorModalDetails = {}; - - this.ignoreHttpError = false; - this.getServerId = function(){ - return this.host.replace(/^https?\:\/\//ig,""); - } - - this.reloadServerId = function(){ - this.server_id = this.getServerId(); - } - - this.getHost = function(){ - if(sessionStorage.getItem(Constants.API_CREDENTIALS.host_storage_key) !== null){ - return sessionStorage.getItem(Constants.API_CREDENTIALS.host_storage_key); - }else{ - return Constants.API_CREDENTIALS.default_protocol + "://" + - window.location.hostname + - (window.location.port ? ":" + window.location.port : ""); - } - } - - this.setHost = function(hostWithPort){ - hostWithPort = hostWithPort.replace(/^https?\:\/\//ig, ''); - var hostURL = Constants.API_CREDENTIALS.default_protocol + "://" + hostWithPort; - sessionStorage.setItem(Constants.API_CREDENTIALS.host_storage_key, hostURL); - this.host = hostURL; - this.reloadServerId(); - } - - this.getUser = function(){ - return sessionStorage.getItem('LOGIN_ID'); - } - - this.host = this.getHost(); - this.server_id = this.getServerId(); - - this.setNetworkInfo = function(data){ - this.hostname = data.hostname; - this.mac_address = data.mac_address; - } - - this.setPowerOnState = function(){ - this.server_state = Constants.HOST_STATE_TEXT.on; - this.server_status = Constants.HOST_STATE.on; - } - - this.setPowerOffState = function(){ - this.server_state = Constants.HOST_STATE_TEXT.off; - this.server_status = Constants.HOST_STATE.off; - } - - this.setErrorState = function(){ - this.server_state = Constants.HOST_STATE_TEXT.error; - this.server_status = Constants.HOST_STATE.error; - } - - this.setUnreachableState = function(){ - this.server_state = Constants.HOST_STATE_TEXT.unreachable; - this.server_status = Constants.HOST_STATE.unreachable; - } - - this.setRemoteWindowActive = function(){ - this.remote_window_active = true; - } - - this.setRemoteWindowInactive = function(){ - this.remote_window_active = false; - } - - this.updateServerHealth = function(logs){ - var criticals = logs.filter(function(item){ - return item.health_flags.critical == true; - }); - - if(criticals.length){ - this.server_health = Constants.SERVER_HEALTH.critical; - return; - } - - var warnings = logs.filter(function(item){ - return item.health_flags.warning == true; - }); - - if(warnings.length){ - this.server_health = Constants.SERVER_HEALTH.warning; - return; - } - - this.server_health = Constants.SERVER_HEALTH.good; - } - - this.activateErrorModal = function(data){ - if(data && data.hasOwnProperty('title')){ - this.errorModalDetails.title = data.title; - }else{ - this.errorModalDetails.title = Constants.MESSAGES.ERROR_MODAL.TITLE; - } - - if(data && data.hasOwnProperty('description')){ - this.errorModalDetails.description = data.description; - }else{ - this.errorModalDetails.description = Constants.MESSAGES.ERROR_MODAL.DESCRIPTION; - } - this.displayErrorModal = true; - } - - this.deactivateErrorModal = function(){ - this.displayErrorModal = false; - } - }]); +window.angular && (function(angular) { + 'use strict'; + + angular + .module('app.common.services') + .service('dataService', ['Constants', function(Constants) { + this.server_health = Constants.SERVER_HEALTH.unknown; + this.server_state = 'Unreachable'; + this.server_status = -2; + this.chassis_state = 'On'; + this.LED_state = Constants.LED_STATE_TEXT.off; + this.last_updated = new Date(); + + this.loading = false; + this.server_unreachable = false; + this.loading_message = ''; + this.showNavigation = false; + this.bodyStyle = {}; + this.path = ''; + this.sensorData = []; + + this.hostname = ''; + this.mac_address = ''; + this.remote_window_active = false; + + this.displayErrorModal = false; + this.errorModalDetails = {}; + + this.ignoreHttpError = false; + this.getServerId = function() { + return this.host.replace(/^https?\:\/\//ig, ''); + }; + + this.reloadServerId = function() { + this.server_id = this.getServerId(); + }; + + this.getHost = function() { + if (sessionStorage.getItem(Constants.API_CREDENTIALS.host_storage_key) !== null) { + return sessionStorage.getItem(Constants.API_CREDENTIALS.host_storage_key); + } + else { + return Constants.API_CREDENTIALS.default_protocol + '://' + + window.location.hostname + + (window.location.port ? ':' + window.location.port : ''); + } + }; + + this.setHost = function(hostWithPort) { + hostWithPort = hostWithPort.replace(/^https?\:\/\//ig, ''); + var hostURL = Constants.API_CREDENTIALS.default_protocol + '://' + hostWithPort; + sessionStorage.setItem(Constants.API_CREDENTIALS.host_storage_key, hostURL); + this.host = hostURL; + this.reloadServerId(); + }; + + this.getUser = function() { + return sessionStorage.getItem('LOGIN_ID'); + }; + + this.host = this.getHost(); + this.server_id = this.getServerId(); + + this.setNetworkInfo = function(data) { + this.hostname = data.hostname; + this.mac_address = data.mac_address; + }; + + this.setPowerOnState = function() { + this.server_state = Constants.HOST_STATE_TEXT.on; + this.server_status = Constants.HOST_STATE.on; + }; + + this.setPowerOffState = function() { + this.server_state = Constants.HOST_STATE_TEXT.off; + this.server_status = Constants.HOST_STATE.off; + }; + + this.setErrorState = function() { + this.server_state = Constants.HOST_STATE_TEXT.error; + this.server_status = Constants.HOST_STATE.error; + }; + + this.setUnreachableState = function() { + this.server_state = Constants.HOST_STATE_TEXT.unreachable; + this.server_status = Constants.HOST_STATE.unreachable; + }; + + this.setRemoteWindowActive = function() { + this.remote_window_active = true; + }; + + this.setRemoteWindowInactive = function() { + this.remote_window_active = false; + }; + + this.updateServerHealth = function(logs) { + var criticals = logs.filter(function(item) { + return item.health_flags.critical == true; + }); + + if (criticals.length) { + this.server_health = Constants.SERVER_HEALTH.critical; + return; + } + + var warnings = logs.filter(function(item) { + return item.health_flags.warning == true; + }); + + if (warnings.length) { + this.server_health = Constants.SERVER_HEALTH.warning; + return; + } + + this.server_health = Constants.SERVER_HEALTH.good; + }; + + this.activateErrorModal = function(data) { + if (data && data.hasOwnProperty('title')) { + this.errorModalDetails.title = data.title; + } + else { + this.errorModalDetails.title = Constants.MESSAGES.ERROR_MODAL.TITLE; + } + + if (data && data.hasOwnProperty('description')) { + this.errorModalDetails.description = data.description; + } + else { + this.errorModalDetails.description = Constants.MESSAGES.ERROR_MODAL.DESCRIPTION; + } + this.displayErrorModal = true; + }; + + this.deactivateErrorModal = function() { + this.displayErrorModal = false; + }; + }]); })(window.angular); diff --git a/app/common/services/index.js b/app/common/services/index.js index a33003a..d234069 100644 --- a/app/common/services/index.js +++ b/app/common/services/index.js @@ -5,13 +5,13 @@ * @exports app/common/services/index */ -window.angular && (function (angular) { - 'use strict'; +window.angular && (function(angular) { + 'use strict'; - angular - .module('app.common.services', [ - // Dependencies - // Basic resources - ]); + angular + .module('app.common.services', [ + // Dependencies + // Basic resources + ]); })(window.angular); diff --git a/app/common/services/userModel.js b/app/common/services/userModel.js index e25d3f9..cd943f9 100644 --- a/app/common/services/userModel.js +++ b/app/common/services/userModel.js @@ -7,53 +7,59 @@ */ -window.angular && (function (angular) { - 'use strict'; +window.angular && (function(angular) { + 'use strict'; - angular - .module('app.common.services') - .service('userModel', ['APIUtils',function(APIUtils){ - return { - login : function(username, password, callback){ - APIUtils.login(username, password, function(response, error){ - if(response && - (response.status == APIUtils.API_RESPONSE.SUCCESS_STATUS - || response.status === undefined)){ - sessionStorage.setItem('LOGIN_ID', username); - callback(true); - }else if(response && response.data && response.data.data - && response.data.data.description){ - callback(false, response.data.data.description); - }else if(response && response.message){ - callback(false, response.message); - }else if(error){ - callback(false, 'Server unreachable'); - }else{ - callback(false, 'Internal error'); - } - }); - }, - isLoggedIn : function(){ - if(sessionStorage.getItem('LOGIN_ID') === null){ - return false; - } - return true; - }, - logout : function(callback){ - APIUtils.logout(function(response, error){ - if(response && - response.status == APIUtils.API_RESPONSE.SUCCESS_STATUS){ - sessionStorage.removeItem('LOGIN_ID'); - sessionStorage.removeItem(APIUtils.HOST_SESSION_STORAGE_KEY); - callback(true); - }else if(response.status == APIUtils.API_RESPONSE.ERROR_STATUS){ - callback(false); - }else{ - callback(false, error); - } - }); - } - }; - }]); + angular + .module('app.common.services') + .service('userModel', ['APIUtils', function(APIUtils) { + return { + login: function(username, password, callback) { + APIUtils.login(username, password, function(response, error) { + if (response && + (response.status == APIUtils.API_RESPONSE.SUCCESS_STATUS || + response.status === undefined)) { + sessionStorage.setItem('LOGIN_ID', username); + callback(true); + } + else if (response && response.data && response.data.data && + response.data.data.description) { + callback(false, response.data.data.description); + } + else if (response && response.message) { + callback(false, response.message); + } + else if (error) { + callback(false, 'Server unreachable'); + } + else { + callback(false, 'Internal error'); + } + }); + }, + isLoggedIn: function() { + if (sessionStorage.getItem('LOGIN_ID') === null) { + return false; + } + return true; + }, + logout: function(callback) { + APIUtils.logout(function(response, error) { + if (response && + response.status == APIUtils.API_RESPONSE.SUCCESS_STATUS) { + sessionStorage.removeItem('LOGIN_ID'); + sessionStorage.removeItem(APIUtils.HOST_SESSION_STORAGE_KEY); + callback(true); + } + else if (response.status == APIUtils.API_RESPONSE.ERROR_STATUS) { + callback(false); + } + else { + callback(false, error); + } + }); + } + }; + }]); })(window.angular); |

