diff --git a/src/sunstone/public/app/tabs/clusters-tab/panels/info.js b/src/sunstone/public/app/tabs/clusters-tab/panels/info.js index 40bbcc219f9..6b7b038d4ea 100644 --- a/src/sunstone/public/app/tabs/clusters-tab/panels/info.js +++ b/src/sunstone/public/app/tabs/clusters-tab/panels/info.js @@ -24,6 +24,7 @@ define(function(require) { var RenameTr = require('utils/panel/rename-tr'); var TemplateTable = require('utils/panel/template-table'); var Sunstone = require('sunstone'); + var TemplateUtils = require('utils/template-utils'); /* CONSTANTS @@ -47,12 +48,13 @@ define(function(require) { this.icon = "fa-info-circle"; this.element = info[XML_ROOT]; + this.percent = false; // Hide information in the template table. Unshow values are stored // in the unshownTemplate object to be used when the element info is updated. that.unshownTemplate = {}; that.strippedTemplate = {}; - var unshownKeys = ['RESERVED_CPU', 'RESERVED_MEM']; + var unshownKeys = ['HOST', 'RESERVED_CPU', 'RESERVED_MEM']; $.each(that.element.TEMPLATE, function(key, value) { if ($.inArray(key, unshownKeys) > -1) { that.unshownTemplate[key] = value; @@ -80,14 +82,43 @@ define(function(require) { this.strippedTemplate, RESOURCE, Locale.tr("Attributes")); - + var reservedMem; + (this.element.TEMPLATE.RESERVED_MEM != "0%" && this.element.TEMPLATE.RESERVED_MEM != "")?reservedMem = parseInt(this.element.TEMPLATE.RESERVED_MEM): reservedMem = 0; + var reservedCPU + (this.element.TEMPLATE.RESERVED_CPU != "0%" && this.element.TEMPLATE.RESERVED_CPU != "")? reservedCPU = parseInt(this.element.TEMPLATE.RESERVED_CPU): reservedCPU = 0; return TemplateHTML({ 'element': this.element, 'renameTrHTML': renameTrHTML, - 'templateTableHTML': templateTableHTML + 'templateTableHTML': templateTableHTML, + 'percentCPU': reservedCPU, + 'percentMEM': reservedMem, }); } + function changeBarCPU(){ + if(parseInt(document.getElementById('change_bar_cpu').value) > 0) + document.getElementById('textInput_reserved_cpu').style.backgroundColor = 'rgba(111, 220, 111,0.5)'; + if(parseInt(document.getElementById('change_bar_cpu').value) < 0) + document.getElementById('textInput_reserved_cpu').style.backgroundColor = 'rgba(255, 80, 80,0.5)'; + document.getElementById('textInput_reserved_cpu').value = document.getElementById('change_bar_cpu').value; + } + + function changeInputCPU(){ + document.getElementById('change_bar_cpu').value = document.getElementById('textInput_reserved_cpu').value; + } + + function changeBarMEM(){ + if(parseInt(document.getElementById('change_bar_mem').value) > 0) + document.getElementById('textInput_reserved_mem').style.backgroundColor = 'rgba(111, 220, 111,0.5)'; + if(parseInt(document.getElementById('change_bar_mem').value) < 0) + document.getElementById('textInput_reserved_mem').style.backgroundColor = 'rgba(255, 80, 80,0.5)'; + document.getElementById('textInput_reserved_mem').value = document.getElementById('change_bar_mem').value; + } + + function changeInputMEM(){ + document.getElementById('change_bar_mem').value = document.getElementById('textInput_reserved_mem').value; + } + function _setup(context) { var that = this; @@ -95,18 +126,17 @@ define(function(require) { TemplateTable.setup(this.strippedTemplate, RESOURCE, this.element.ID, context, this.unshownTemplate); - $(".edit_reserved", context).on("click", function(){ - var dialog = Sunstone.getDialog(OVERCOMMIT_DIALOG_ID); + document.getElementById("change_bar_cpu").addEventListener("change", changeBarCPU); + document.getElementById("textInput_reserved_cpu").addEventListener("change", changeInputCPU); + document.getElementById("change_bar_mem").addEventListener("change", changeBarMEM); + document.getElementById("textInput_reserved_mem").addEventListener("change", changeInputMEM); - dialog.setParams( - { element: that.element, - action : "Cluster.append_template", - resourceName : Locale.tr("Cluster"), - tabId : TAB_ID - }); + $(document).off('click', '.update_reserved').on("click", '.update_reserved', function(){ + var reservedCPU = document.getElementById('change_bar_cpu').value+'%'; + var reservedMem = document.getElementById('change_bar_mem').value+'%'; - dialog.show(); - return false; + var obj = {RESERVED_CPU: reservedCPU, RESERVED_MEM: reservedMem}; + Sunstone.runAction("Cluster.append_template", that.element.ID, TemplateUtils.templateToString(obj)); }); } }); diff --git a/src/sunstone/public/app/tabs/clusters-tab/panels/info/html.hbs b/src/sunstone/public/app/tabs/clusters-tab/panels/info/html.hbs index 0cff5f2cb70..5499fd5c83b 100644 --- a/src/sunstone/public/app/tabs/clusters-tab/panels/info/html.hbs +++ b/src/sunstone/public/app/tabs/clusters-tab/panels/info/html.hbs @@ -31,31 +31,39 @@ {{{renameTrHTML}}} - - - - - - - - - - - - - - - - - - -
{{tr "Overcommitment"}}
{{tr "Reserved CPU"}}{{valOrDefault element.TEMPLATE.RESERVED_CPU "-"}} - -
{{tr "Reserved Memory"}}{{humanizeSize "KB" element.TEMPLATE.RESERVED_MEM}} - -
+
+
+ + + + + + + + + + + + + + + + + + +
{{tr "Overcommitment"}} + + + +
{{tr "Reserved CPU"}} +
{{tr "Reserved Memory"}} +
+
+
{{{templateTableHTML}}} diff --git a/src/sunstone/public/app/tabs/hosts-tab/panels/info.js b/src/sunstone/public/app/tabs/hosts-tab/panels/info.js index ee2d8ace746..0da79fd82cc 100644 --- a/src/sunstone/public/app/tabs/hosts-tab/panels/info.js +++ b/src/sunstone/public/app/tabs/hosts-tab/panels/info.js @@ -13,12 +13,11 @@ /* See the License for the specific language governing permissions and */ /* limitations under the License. */ /* -------------------------------------------------------------------------- */ - define(function(require) { /* DEPENDENCIES */ - + require('foundation'); var Locale = require('utils/locale'); var Humanize = require('utils/humanize'); var RenameTr = require('utils/panel/rename-tr'); @@ -31,6 +30,7 @@ define(function(require) { var DatastoresCapacityTable = require('../utils/datastores-capacity-table'); var CanImportWilds = require('../utils/can-import-wilds'); var Sunstone = require('sunstone'); + var TemplateUtils = require('utils/template-utils'); /* TEMPLATES @@ -59,7 +59,6 @@ define(function(require) { that.icon = "fa-info-circle"; that.element = info[XML_ROOT]; - that.canImportWilds = CanImportWilds(that.element); // Hide information of the Wild VMs of the Host and the ESX Hosts @@ -88,19 +87,19 @@ define(function(require) { /* FUNCTION DEFINITIONS */ - function _html() { var templateTableHTML = TemplateTable.html( this.strippedTemplate, RESOURCE, Locale.tr("Attributes")); - var renameTrHTML = RenameTr.html(TAB_ID, RESOURCE, this.element.NAME); var clusterTrHTML = ClusterTr.html(this.element.CLUSTER); var permissionsTableHTML = PermissionsTable.html(TAB_ID, RESOURCE, this.element); var cpuBars = CPUBars.html(this.element); var memoryBars = MemoryBars.html(this.element); var datastoresCapacityTableHTML = DatastoresCapacityTable.html(this.element); + var realCPU = parseInt(this.element.HOST_SHARE.TOTAL_CPU); + var realMEM = parseInt(this.element.HOST_SHARE.TOTAL_MEM); return TemplateInfo({ 'element': this.element, @@ -111,10 +110,23 @@ define(function(require) { 'cpuBars': cpuBars, 'memoryBars': memoryBars, 'stateStr': OpenNebulaHost.stateStr(this.element.STATE), - 'datastoresCapacityTableHTML': datastoresCapacityTableHTML + 'datastoresCapacityTableHTML': datastoresCapacityTableHTML, + 'maxReservedMEM': realMEM * 2, + 'maxReservedCPU': realCPU * 2, + 'realCPU': realCPU, + 'realMEM': Humanize.size(realMEM), + 'virtualMEMInput': Humanize.size(this.element.HOST_SHARE.MAX_MEM) }); } + function changeInputCPU(){ + document.getElementById('change_bar_cpu_hosts').value = document.getElementById('textInput_reserved_cpu_hosts').value; + } + + function changeInputMEM(){ + document.getElementById('change_bar_mem_hosts').value = parseInt(document.getElementById('textInput_reserved_mem_hosts').value); + } + function _setup(context) { var that = this; @@ -123,20 +135,38 @@ define(function(require) { TemplateTable.setup(this.strippedTemplate, RESOURCE, this.element.ID, context, this.unshownTemplate); PermissionsTable.setup(TAB_ID, RESOURCE, this.element, context); - $(".edit_reserved", context).on("click", function(){ - var dialog = Sunstone.getDialog(OVERCOMMIT_DIALOG_ID); - - dialog.setParams( - { element: that.element, - action : "Host.append_template", - resourceName : Locale.tr("Host"), - tabId : TAB_ID - }); - - dialog.show(); - return false; + //.off and .on prevent multiple clicks events + $(document).off('click', '.update_reserved_hosts').on("click", '.update_reserved', function(){ + var reservedCPU = parseInt(document.getElementById('change_bar_cpu_hosts').value); + var CPU = parseInt(that.element.HOST_SHARE.FREE_CPU); + var reservedMem = parseInt(document.getElementById('change_bar_mem_hosts').value); + var MEM = parseInt(that.element.HOST_SHARE.FREE_MEM); + if(parseInt(that.element.HOST_SHARE.USED_CPU) > 0) + CPU += parseInt(that.element.HOST_SHARE.USED_CPU); + reservedCPU = CPU - reservedCPU; + if(parseInt(that.element.HOST_SHARE.USED_MEM) > 0) + MEM += parseInt(that.element.HOST_SHARE.USED_MEM); + reservedMem = MEM - reservedMem; + + var obj = {RESERVED_CPU: reservedCPU, RESERVED_MEM: reservedMem}; + Sunstone.runAction("Host.append_template", that.element.ID, TemplateUtils.templateToString(obj)); }); - - return false; + + document.getElementById("change_bar_cpu_hosts").addEventListener("change", function(){ + if(parseInt(document.getElementById('change_bar_cpu_hosts').value) > that.element.HOST_SHARE.TOTAL_CPU) + document.getElementById('textInput_reserved_cpu_hosts').style.backgroundColor = 'rgba(111, 220, 111,0.5)'; + if(parseInt(document.getElementById('change_bar_cpu_hosts').value) < that.element.HOST_SHARE.TOTAL_CPU) + document.getElementById('textInput_reserved_cpu_hosts').style.backgroundColor = 'rgba(255, 80, 80,0.5)'; + document.getElementById('textInput_reserved_cpu_hosts').value = document.getElementById('change_bar_cpu_hosts').value; + }); + document.getElementById("textInput_reserved_cpu_hosts").addEventListener("change", changeInputCPU); + document.getElementById("change_bar_mem_hosts").addEventListener("change", function(){ + if(parseInt(document.getElementById('change_bar_mem_hosts').value) > that.element.HOST_SHARE.TOTAL_MEM) + document.getElementById('textInput_reserved_mem_hosts').style.backgroundColor = 'rgba(111, 220, 111,0.5)'; + if(parseInt(document.getElementById('change_bar_mem_hosts').value) < that.element.HOST_SHARE.TOTAL_MEM) + document.getElementById('textInput_reserved_mem_hosts').style.backgroundColor = 'rgba(255, 80, 80,0.5)'; + document.getElementById('textInput_reserved_mem_hosts').value = Humanize.size(parseInt(document.getElementById('change_bar_mem_hosts').value)); + }); + document.getElementById("textInput_reserved_mem_hosts").addEventListener("change", changeInputMEM); } }); diff --git a/src/sunstone/public/app/tabs/hosts-tab/panels/info/html.hbs b/src/sunstone/public/app/tabs/hosts-tab/panels/info/html.hbs index 972e0236a30..7ff53d2194c 100644 --- a/src/sunstone/public/app/tabs/hosts-tab/panels/info/html.hbs +++ b/src/sunstone/public/app/tabs/hosts-tab/panels/info/html.hbs @@ -73,30 +73,38 @@ + {{{datastoresCapacityTableHTML}}} +
+
+
+
- + - - - - + + + + - - - - + + + +
{{tr "Overcommitment"}}{{tr "Overcommitment"}} + + + +
{{tr "Reserved CPU"}}{{valOrDefault element.TEMPLATE.RESERVED_CPU "-"}} - -
{{tr "CPU"}} +
{{tr "Reserved Memory"}}{{humanizeSize "KB" element.TEMPLATE.RESERVED_MEM}} - -
{{tr "Memory"}} +
- {{{datastoresCapacityTableHTML}}}
diff --git a/src/sunstone/public/app/tabs/hosts-tab/panels/monitor.js b/src/sunstone/public/app/tabs/hosts-tab/panels/monitor.js index 7170801aeb5..c5e5f91d900 100644 --- a/src/sunstone/public/app/tabs/hosts-tab/panels/monitor.js +++ b/src/sunstone/public/app/tabs/hosts-tab/panels/monitor.js @@ -76,21 +76,22 @@ define(function(require) { data: { id: this.element.ID, monitor: { - monitor_resources : "HOST_SHARE/CPU_USAGE,HOST_SHARE/USED_CPU,HOST_SHARE/MAX_CPU,HOST_SHARE/MEM_USAGE,HOST_SHARE/USED_MEM,HOST_SHARE/MAX_MEM" + monitor_resources : "HOST_SHARE/CPU_USAGE,HOST_SHARE/USED_CPU,HOST_SHARE/MAX_CPU,HOST_SHARE/TOTAL_CPU,HOST_SHARE/MEM_USAGE,HOST_SHARE/USED_MEM,HOST_SHARE/MAX_MEM,HOST_SHARE/TOTAL_MEM" } }, success: function(req, response) { var host_graphs = [ { - monitor_resources : "HOST_SHARE/CPU_USAGE,HOST_SHARE/USED_CPU,HOST_SHARE/MAX_CPU", - labels : Locale.tr("Allocated") + "," + Locale.tr("Real") + "," + Locale.tr("Total"), + monitor_resources : "HOST_SHARE/CPU_USAGE,HOST_SHARE/USED_CPU,HOST_SHARE/MAX_CPU,HOST_SHARE/TOTAL_CPU", + labels : Locale.tr("Allocated") + "," + Locale.tr("Real") + "," + Locale.tr("Total") + "," + Locale.tr("Total +/- reserved"), humanize_figures : false, div_graph : $("#host_cpu_graph"), div_legend : $("#host_cpu_legend") }, { - monitor_resources : "HOST_SHARE/MEM_USAGE,HOST_SHARE/USED_MEM,HOST_SHARE/MAX_MEM", - labels : Locale.tr("Allocated") + "," + Locale.tr("Real") + "," + Locale.tr("Total"), + monitor_resources : "HOST_SHARE/MEM_USAGE,HOST_SHARE/USED_MEM,HOST_SHARE/MAX_MEM,HOST_SHARE/TOTAL_MEM", + labels : Locale.tr("Allocated") + "," + Locale.tr("Real") + "," + Locale.tr("Total") + "," + Locale.tr("Total +/- reserved"), + humanize_figures : false, humanize_figures : true, div_graph : $("#host_mem_graph"), div_legend : $("#host_mem_legend")