From 3ce1cbcbea7f05055240e84e6d3ea5fdb94409ab Mon Sep 17 00:00:00 2001 From: Daniel Molina Date: Mon, 18 May 2015 19:01:15 +0200 Subject: [PATCH] feature #3748: Add host info panel --- src/sunstone/public/app/tabs/hosts-tab.js | 8 +- .../public/app/tabs/hosts-tab/panels/info.js | 116 ++++++++++++++++++ .../app/tabs/hosts-tab/panels/info/html.hbs | 70 +++++++++++ .../app/tabs/hosts-tab/panels/info/panelId.js | 3 + 4 files changed, 193 insertions(+), 4 deletions(-) create mode 100644 src/sunstone/public/app/tabs/hosts-tab/panels/info.js create mode 100644 src/sunstone/public/app/tabs/hosts-tab/panels/info/html.hbs create mode 100644 src/sunstone/public/app/tabs/hosts-tab/panels/info/panelId.js diff --git a/src/sunstone/public/app/tabs/hosts-tab.js b/src/sunstone/public/app/tabs/hosts-tab.js index 10cc901ba3..74471c3542 100644 --- a/src/sunstone/public/app/tabs/hosts-tab.js +++ b/src/sunstone/public/app/tabs/hosts-tab.js @@ -12,10 +12,10 @@ define(function(require) { // require('./hosts-tab/dialogs/clone') //]; - //var _panels = [ - // require('./hosts-tab/panels/info'), + var _panels = [ + require('./hosts-tab/panels/info'), // require('./hosts-tab/panels/vms') - //]; + ]; var Tab = { tabId: TAB_ID, @@ -33,7 +33,7 @@ define(function(require) { buttons: Buttons, actions: Actions, dataTable: new Table(DATATABLE_ID, {actions: true, info: true}), - //panels: _panels, + panels: _panels, //dialogs: _dialogs }; diff --git a/src/sunstone/public/app/tabs/hosts-tab/panels/info.js b/src/sunstone/public/app/tabs/hosts-tab/panels/info.js new file mode 100644 index 0000000000..b7979df2ed --- /dev/null +++ b/src/sunstone/public/app/tabs/hosts-tab/panels/info.js @@ -0,0 +1,116 @@ +define(function(require) { + /* + DEPENDENCIES + */ + + var Locale = require('utils/locale'); + var Humanize = require('utils/humanize'); + var RenameTr = require('utils/panel/rename-tr'); + var TemplateTable = require('utils/panel/template-table'); + var PermissionsTable = require('utils/panel/permissions-table'); + var ClusterTr = require('utils/panel/cluster-tr'); + var OpenNebulaHost = require('opennebula/host'); + var CPUBars = require('../utils/cpu-bars'); + var MemoryBars = require('../utils/memory-bars'); + + /* + TEMPLATES + */ + + var TemplateInfo = require('hbs!./info/html'); + + /* + CONSTANTS + */ + + var TAB_ID = require('../tabId'); + var PANEL_ID = require('./info/panelId'); + var RESOURCE = "Host" + + /* + CONSTRUCTOR + */ + + function Panel(info) { + var that = this; + that.title = Locale.tr("Info"); + that.icon = "fa-info-circle"; + + that.element = info[RESOURCE.toUpperCase()]; + + // Check if any of the existing VMs in the Host define the IMPORT_TEMPLATE + // attribute to be imported into OpenNebula. + that.canImportWilds = false; + if (that.element.TEMPLATE.VM) { + var vms = that.element.TEMPLATE.VM; + if (!$.isArray(vms)) { // If only 1 VM convert to array + vms = [vms]; + } + $.each(vms, function() { + if (this.IMPORT_TEMPLATE) { + that.canImportWilds = true; + return false; + } + }); + } + + // Hide information of the Wild VMs of the Host and the ESX Hosts + // in the template table. Unshow values are stored in the unshownTemplate + // object to be used when the host info is updated. + that.unshownTemplate = {}; + that.strippedTemplate = {}; + var unshownKeys = ['HOST', 'VM', 'WILDS']; + $.each(that.element.TEMPLATE, function(key, value) { + if ($.inArray(key, unshownKeys) > -1) { + that.unshownTemplate[key] = value; + } else { + that.strippedTemplate[key] = value; + } + }); + + return this; + }; + + Panel.PANEL_ID = PANEL_ID; + Panel.prototype.html = _html; + Panel.prototype.setup = _setup; + + return Panel; + + /* + FUNCTION DEFINITIONS + */ + + function _html() { + var templateTableHTML = TemplateTable.html( + this.strippedTemplate, + RESOURCE, + Locale.tr("Attributes")); + + var renameTrHTML = RenameTr.html(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 stateStr = Locale.tr(OpenNebulaHost.stateStr(this.element.STATE)); + + return TemplateInfo({ + 'element': this.element, + 'renameTrHTML': renameTrHTML, + 'clusterTrHTML': clusterTrHTML, + 'templateTableHTML': templateTableHTML, + 'permissionsTableHTML': permissionsTableHTML, + 'cpuBars': cpuBars, + 'memoryBars': memoryBars, + 'stateStr': stateStr, + }); + } + + function _setup(context) { + RenameTr.setup(RESOURCE, this.element.ID, context); + ClusterTr.setup(RESOURCE, this.element.ID, this.element.CLUSTER_ID, context); + TemplateTable.setup(this.strippedTemplate, RESOURCE, this.element.ID, context, this.unshownTemplate); + PermissionsTable.setup(TAB_ID, RESOURCE, this.element, context); + return false; + } +}); 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 new file mode 100644 index 0000000000..b0d0485c7e --- /dev/null +++ b/src/sunstone/public/app/tabs/hosts-tab/panels/info/html.hbs @@ -0,0 +1,70 @@ +
+
+ + + + + + + + + + + + {{{renameTrHTML}}} + {{{clusterTrHTML}}} + + + + + + + + + + + + + + + + + + + + + +
{{tr "Information"}}
{{tr "ID"}}{{element.ID}}
{{tr "State"}}{{stateStr}}
{{tr "IM MAD"}}{{element.IM_MAD}}
{{tr "VM MAD"}}{{element.VM_MAD}}
{{tr "VN MAD"}}{{element.VN_MAD}}
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
{{tr "Capacity"}}
{{tr "Allocated Memory"}}{{{memoryBars.allocated}}}
{{tr "Allocated CPU"}}{{{cpuBars.allocated}}}
{{tr "Real Memory"}}{{{memoryBars.real}}}
{{tr "Real CPU"}}{{{cpuBars.real}}}
+ {{{datastoreCapacityTableHTML}}} +
+
+
+
{{{templateTableHTML}}}
+
\ No newline at end of file diff --git a/src/sunstone/public/app/tabs/hosts-tab/panels/info/panelId.js b/src/sunstone/public/app/tabs/hosts-tab/panels/info/panelId.js new file mode 100644 index 0000000000..f0367f5dc6 --- /dev/null +++ b/src/sunstone/public/app/tabs/hosts-tab/panels/info/panelId.js @@ -0,0 +1,3 @@ +define(function(require) { + return 'host_info_tab'; +})