diff --git a/src/sunstone/public/app/tabs/hosts-tab/utils/cpu-bars.js b/src/sunstone/public/app/tabs/hosts-tab/utils/cpu-bars.js new file mode 100644 index 0000000000..1ab441f0da --- /dev/null +++ b/src/sunstone/public/app/tabs/hosts-tab/utils/cpu-bars.js @@ -0,0 +1,55 @@ +define(function(require) { + /* + Generate an Object containing the html for the real and allocated CPU + */ + + var ProgressBar = require('utils/progress-bar'); + var Humanize = require('utils/humanize') + + /* + @param {Object} info Object representing the Host as returned by OpenNebula + @param {Boolean} hostShareFlag if true the info param is the HOST_SHARE element instead of HOSt + */ + var _html = function(host, hostShareFlag) { + var hostShare = hostShareFlag ? host : host.HOST_SHARE; + var maxCPU = parseInt(hostShare.MAX_CPU); + var infoStr; + + var allocatedCPUBar + if (hostShare.CPU_USAGE) { + var allocatedCPU = parseInt(hostShare.CPU_USAGE); + + if (maxCPU > 0) { + var ratioAllocatedCPU = Math.round((allocatedCPU / maxCPU) * 100); + infoStr = allocatedCPU + ' / ' + maxCPU + ' (' + ratioAllocatedCPU + '%)'; + } else { + infoStr = ""; + } + + allocatedCPUBar = ProgressBar.html(allocatedCPU, maxCPU, infoStr); + } + + var realCPUBar + if (hostShare.USED_CPU) { + var realCPU = parseInt(hostShare.USED_CPU); + + if (maxCPU > 0) { + var ratioRealCPU = Math.round((realCPU / maxCPU) * 100); + infoStr = realCPU + ' / ' + maxCPU + ' (' + ratioRealCPU + '%)'; + } else { + infoStr = ""; + } + + realCPUBar = ProgressBar.html(realCPU, maxCPU, infoStr); + } + + return { + real: realCPUBar, + allocated: allocatedCPUBar + } + } + + return { + 'html': _html + } +}) \ No newline at end of file diff --git a/src/sunstone/public/app/tabs/hosts-tab/utils/memory-bars.js b/src/sunstone/public/app/tabs/hosts-tab/utils/memory-bars.js new file mode 100644 index 0000000000..8b4a7e9b45 --- /dev/null +++ b/src/sunstone/public/app/tabs/hosts-tab/utils/memory-bars.js @@ -0,0 +1,55 @@ +define(function(require) { + /* + Generate an Object containing the html for the real and allocated MEMORY + */ + + var ProgressBar = require('utils/progress-bar'); + var Humanize = require('utils/humanize') + + /* + @param {Object} info Object representing the Host as returned by OpenNebula + @param {Boolean} hostShareFlag if true the info param is the HOST_SHARE element instead of HOSt + */ + var _html = function(host, hostShareFlag) { + var hostShare = hostShareFlag ? host : host.HOST_SHARE; + var maxMem = parseInt(hostShare.MAX_MEM); + var infoStr = ""; + + var allocatedMemBar; + if (hostShare.MEM_USAGE) { + var allocatedMem = parseInt(hostShare.MEM_USAGE); + + if (maxMem > 0) { + var ratioAllocatedMem = Math.round((allocatedMem / maxMem) * 100); + infoStr = Humanize.size(allocatedMem) + ' / ' + Humanize.size(maxMem) + ' (' + ratioAllocatedMem + '%)'; + } else { + infoStr = Humanize.size(allocatedMem) + ' / -'; + } + + allocatedMemBar = ProgressBar.html(allocatedMem, maxMem, infoStr); + } + + var realMemBar; + if (hostShare.USED_MEM) { + var realMem = parseInt(hostShare.USED_MEM); + + if (maxMem > 0) { + var ratioRealMem = Math.round((realMem / maxMem) * 100); + infoStr = Humanize.size(realMem) + ' / ' + Humanize.size(maxMem) + ' (' + ratioRealMem + '%)'; + } else { + infoStr = Humanize.size(realMem) + ' / -'; + } + + realMemBar = ProgressBar.html(realMem, maxMem, infoStr); + } + + return { + real: realMemBar, + allocated: allocatedMemBar + } + } + + return { + 'html': _html + } +}) \ No newline at end of file