From 7c4c03540c5dae959704812b37292ee7d197df57 Mon Sep 17 00:00:00 2001 From: Abel Coronado Date: Thu, 19 Oct 2017 15:42:32 +0200 Subject: [PATCH] F #5461: Support empty attributes in merges in Sunstone (#534) * F #5461: Support empty attributes in merges in Sunstone * F #5461: Added SCHED_REQUIREMENTS instantiate VM --- .../models/OpenNebulaJSON/TemplateJSON.rb | 7 +++++++ .../templates-tab/form-panels/instantiate.js | 16 ++++++++++------ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/sunstone/models/OpenNebulaJSON/TemplateJSON.rb b/src/sunstone/models/OpenNebulaJSON/TemplateJSON.rb index 4ab4ddca70..a51c92fc90 100644 --- a/src/sunstone/models/OpenNebulaJSON/TemplateJSON.rb +++ b/src/sunstone/models/OpenNebulaJSON/TemplateJSON.rb @@ -107,6 +107,13 @@ module OpenNebulaJSON end template = template_to_str(params['template']) + + ['NIC', 'SCHED_ACTION', 'SCHED_REQUIREMENTS', 'SCHED_DS_REQUIREMENTS'].each { |i| + if params['template'][i] && params['template'][i].empty? + template << "\n#{i} = []" + end + } + super(params['vm_name'], params['hold'], template, persistent) else super(params['vm_name'], params['hold'], "", persistent) diff --git a/src/sunstone/public/app/tabs/templates-tab/form-panels/instantiate.js b/src/sunstone/public/app/tabs/templates-tab/form-panels/instantiate.js index 8716a521c2..09441ef4bc 100644 --- a/src/sunstone/public/app/tabs/templates-tab/form-panels/instantiate.js +++ b/src/sunstone/public/app/tabs/templates-tab/form-panels/instantiate.js @@ -259,16 +259,22 @@ define(function(require) { var vmgroup = VMGroupSection.retrieve($(".vmgroupContext"+ template_id)); if(vmgroup){ $.extend(tmp_json, vmgroup); + } else { + tmp_json.VMGROUP = []; } var sched = WizardFields.retrieveInput($("#SCHED_REQUIREMENTS" + template_id, context)); - if(sched){ + if (sched){ tmp_json.SCHED_REQUIREMENTS = sched; + } else { + tmp_json.SCHED_REQUIREMENTS = []; } var sched_ds = WizardFields.retrieveInput($("#SCHED_DS_REQUIREMENTS" + template_id, context)); - if(sched_ds){ + if (sched_ds){ tmp_json.SCHED_DS_REQUIREMENTS = sched_ds; + } else { + tmp_json.SCHED_DS_REQUIREMENTS = []; } var nics = []; @@ -277,14 +283,12 @@ define(function(require) { $.each(networks, function(){ if (this.TYPE == "NIC"){ pcis.push(this); - }else{ + } else { nics.push(this); } }); - if (nics.length > 0) { - tmp_json.NIC = nics; - } + tmp_json.NIC = nics; // Replace PCIs of type nic only var original_tmpl = that.template_objects[index].VMTEMPLATE;