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 410cf523ac..622763f6b7 100644 --- a/src/sunstone/public/app/tabs/hosts-tab/panels/info.js +++ b/src/sunstone/public/app/tabs/hosts-tab/panels/info.js @@ -13,6 +13,7 @@ define(function(require) { var CPUBars = require('../utils/cpu-bars'); var MemoryBars = require('../utils/memory-bars'); var DatastoresCapacityTable = require('../utils/datastores-capacity-table'); + var CanImportWilds = require('../utils/can-import-wilds'); /* TEMPLATES @@ -40,21 +41,7 @@ define(function(require) { that.element = info[XML_ROOT]; - // 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; - } - }); - } + that.canImportWilds = CanImportWilds(that.element); // Hide information of the Wild VMs of the Host and the ESX Hosts // in the template table. Unshow values are stored in the unshownTemplate diff --git a/src/sunstone/public/app/tabs/hosts-tab/utils/can-import-wilds.js b/src/sunstone/public/app/tabs/hosts-tab/utils/can-import-wilds.js new file mode 100644 index 0000000000..bdd50a62c5 --- /dev/null +++ b/src/sunstone/public/app/tabs/hosts-tab/utils/can-import-wilds.js @@ -0,0 +1,33 @@ +define(function(require){ + /* + CONSTRUCTOR + */ + + return _canImportWilds; + + /* + FUNCTION DEFINITIONS + */ + + /* Check if any of the existing VMs in the Host define the IMPORT_TEMPLATE + attribute to be imported into OpenNebula. + @param {Object} element Host element as returned by OpenNebula + @result {Boolean} + */ + function _canImportWilds(element) { + var canImportWilds = false; + if (element.TEMPLATE.VM) { + var vms = element.TEMPLATE.VM; + if (!$.isArray(vms)) { // If only 1 VM convert to array + vms = [vms]; + } + $.each(vms, function() { + if (this.IMPORT_TEMPLATE) { + canImportWilds = true; + return false; + } + }); + } + return canImportWilds; + } +}); \ No newline at end of file