From e8be19ff53819ab9bca851f22d8a154da88468a1 Mon Sep 17 00:00:00 2001 From: abelCoronado93 Date: Tue, 31 Oct 2017 09:56:30 +0100 Subject: [PATCH] B #5518: Cost calculations take into account only the base template (oneFlow) --- .../form-panels/instantiate.js | 29 +++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) 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 3cf1be6ed6..dffed8d512 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 @@ -30,6 +30,7 @@ define(function(require) { var WizardFields = require('utils/wizard-fields'); var UserInputs = require('utils/user-inputs'); var Config = require('sunstone-config'); + var TemplateUtils = require('utils/template-utils'); /* TEMPLATES @@ -137,10 +138,34 @@ define(function(require) { }, timeout: true, success: function (request, vm_template_json){ - + that.vm_template_json = vm_template_json; $("#"+div_id, context).empty(); - var cost = OpenNebulaTemplate.cost(vm_template_json); + if (role.vm_template_contents){ + roleTemplate = TemplateUtils.stringToTemplate(role.vm_template_contents); + var append = roleTemplate.APPEND.split(","); + $.each(append, function(key, value){ + if (!that.vm_template_json.VMTEMPLATE.TEMPLATE[value]){ + that.vm_template_json.VMTEMPLATE.TEMPLATE[value] = roleTemplate[value]; + } else { + if (!Array.isArray(that.vm_template_json.VMTEMPLATE.TEMPLATE[value])){ + that.vm_template_json.VMTEMPLATE.TEMPLATE[value] = [that.vm_template_json.VMTEMPLATE.TEMPLATE[value]]; + } + if (Array.isArray(roleTemplate[value])){ + $.each(roleTemplate[value], function(rkey, rvalue){ + that.vm_template_json.VMTEMPLATE.TEMPLATE[value].push(rvalue); + }); + } else { + that.vm_template_json.VMTEMPLATE.TEMPLATE[value].push(roleTemplate[value]); + } + } + delete roleTemplate[value]; + }); + delete roleTemplate.APPEND; + $.extend(true, that.vm_template_json.VMTEMPLATE.TEMPLATE, roleTemplate); + } + + var cost = OpenNebulaTemplate.cost(that.vm_template_json); if (cost != 0 && Config.isFeatureEnabled("showback")) { total_cost += (cost * role.cardinality);