diff --git a/src/sunstone/public/app/opennebula/template.js b/src/sunstone/public/app/opennebula/template.js index 092ef633bc..1a32500728 100644 --- a/src/sunstone/public/app/opennebula/template.js +++ b/src/sunstone/public/app/opennebula/template.js @@ -16,6 +16,7 @@ define(function(require) { var OpenNebulaAction = require('./action'); + var Config = require('sunstone-config'); var RESOURCE = "VMTEMPLATE"; @@ -95,7 +96,56 @@ define(function(require) { } else { return true; } + }, + "cost": function(template) { + var cost = 0; + var capacity = template.VMTEMPLATE.TEMPLATE; + var cpuCost = capacity.CPU_COST; + var memoryCost = capacity.MEMORY_COST; + var diskCost = capacity.DISK_COST; + + if (cpuCost == undefined){ + cpuCost = Config.onedConf.DEFAULT_COST.CPU_COST; + } + + if (memoryCost == undefined){ + memoryCost = Config.onedConf.DEFAULT_COST.MEMORY_COST; + } + + if (diskCost == undefined){ + diskCost = Config.onedConf.DEFAULT_COST.DISK_COST; + } + + if (capacity.CPU) { + cost += capacity.CPU * cpuCost; + } + + if (capacity.MEMORY) { + cost += capacity.MEMORY * memoryCost; + } + + if (diskCost != 0) { + var template_disk = capacity.DISK; + var disks = []; + if ($.isArray(template_disk)) { + disks = template_disk; + } else if (!$.isEmptyObject(template_disk)) { + disks = [template_disk]; + } + + $.each(disks, function(i,disk){ + if (disk.SIZE) { + cost += diskCost * disk.SIZE; + } + + if (disk.DISK_SNAPSHOT_TOTAL_SIZE) { + cost += diskCost * disk.DISK_SNAPSHOT_TOTAL_SIZE; + } + }); + } + + return cost; } } diff --git a/src/sunstone/public/app/tabs/oneflow-templates-tab/form-panels/instantiate.js b/src/sunstone/public/app/tabs/oneflow-templates-tab/form-panels/instantiate.js index b803651ecf..b6ead91f61 100644 --- a/src/sunstone/public/app/tabs/oneflow-templates-tab/form-panels/instantiate.js +++ b/src/sunstone/public/app/tabs/oneflow-templates-tab/form-panels/instantiate.js @@ -29,6 +29,7 @@ define(function(require) { var Notifier = require('utils/notifier'); var WizardFields = require('utils/wizard-fields'); var UserInputs = require('utils/user-inputs'); + var Config = require('sunstone-config'); /* TEMPLATES @@ -108,6 +109,8 @@ define(function(require) { that.service_template_json = template_json; + $(".name", context).text(template_json.DOCUMENT.NAME); + $("#instantiate_service_user_inputs", context).empty(); UserInputs.serviceTemplateInsert( @@ -117,6 +120,8 @@ define(function(require) { n_roles = template_json.DOCUMENT.TEMPLATE.BODY.roles.length; n_roles_done = 0; + var total_cost = 0; + $.each(template_json.DOCUMENT.TEMPLATE.BODY.roles, function(index, role){ var div_id = "user_input_role_"+index; @@ -127,13 +132,23 @@ define(function(require) { OpenNebulaTemplate.show({ data : { - id: role.vm_template + id: role.vm_template, + extended: true }, timeout: true, success: function (request, vm_template_json){ $("#"+div_id, context).empty(); + var cost = OpenNebulaTemplate.cost(vm_template_json); + + if (cost != 0 && Config.isFeatureEnabled("showback")) { + total_cost += (cost * role.cardinality); + + $(".total_cost_div", context).show(); + $(".total_cost_div .cost_value", context).text( (total_cost).toFixed(2) ); + } + UserInputs.vmTemplateInsert( $("#"+div_id, context), vm_template_json, diff --git a/src/sunstone/public/app/tabs/oneflow-templates-tab/form-panels/instantiate/html.hbs b/src/sunstone/public/app/tabs/oneflow-templates-tab/form-panels/instantiate/html.hbs index b49a32c2dd..25e0648e0b 100644 --- a/src/sunstone/public/app/tabs/oneflow-templates-tab/form-panels/instantiate/html.hbs +++ b/src/sunstone/public/app/tabs/oneflow-templates-tab/form-panels/instantiate/html.hbs @@ -28,6 +28,13 @@ +