From 38f6167f155f9368b5502dad5704bc219e267ffd Mon Sep 17 00:00:00 2001 From: Hector Sanjuan <hsanjuan@opennebula.org> Date: Tue, 3 Jul 2012 12:50:55 +0200 Subject: [PATCH] Bug #1306: Sunstone: Add template update possibility to Clusters. (cherry picked from commit 43b8b659a03db56f5e004cc51a88c727765570c4) --- .../models/OpenNebulaJSON/ClusterJSON.rb | 5 ++ src/sunstone/public/js/opennebula.js | 10 +++ .../public/js/plugins/clusters-tab.js | 67 ++++++++++++++++++- src/sunstone/public/js/sunstone-util.js | 2 +- 4 files changed, 80 insertions(+), 4 deletions(-) diff --git a/src/sunstone/models/OpenNebulaJSON/ClusterJSON.rb b/src/sunstone/models/OpenNebulaJSON/ClusterJSON.rb index b834218a38..a6cfe414e7 100644 --- a/src/sunstone/models/OpenNebulaJSON/ClusterJSON.rb +++ b/src/sunstone/models/OpenNebulaJSON/ClusterJSON.rb @@ -42,6 +42,7 @@ module OpenNebulaJSON when "deldatastore" then self.deldatastore(action_hash['params']) when "addvnet" then self.addvnet(action_hash['params']) when "delvnet" then self.delvnet(action_hash['params']) + when "update" then self.update(action_hash['params']) else error_msg = "#{action_hash['perform']} action not " << @@ -73,5 +74,9 @@ module OpenNebulaJSON def delvnet(params=Hash.new) super(params['vnet_id'].to_i) end + + def update(params=Hash.new) + super(params['template_raw']) + end end end diff --git a/src/sunstone/public/js/opennebula.js b/src/sunstone/public/js/opennebula.js index 999d3d1c06..4011e2e40a 100644 --- a/src/sunstone/public/js/opennebula.js +++ b/src/sunstone/public/js/opennebula.js @@ -944,6 +944,16 @@ var OpenNebula = { OpenNebula.Action.simple_action(params,OpenNebula.Cluster.resource, "delvnet",action_obj); }, + "fetch_template" : function(params){ + OpenNebula.Action.show(params,OpenNebula.Cluster.resource,"template"); + }, + "update" : function(params){ + var action_obj = {"template_raw" : params.data.extra_param }; + OpenNebula.Action.simple_action(params, + OpenNebula.Cluster.resource, + "update", + action_obj); + } }, "Datastore" : { "resource" : "DATASTORE", diff --git a/src/sunstone/public/js/plugins/clusters-tab.js b/src/sunstone/public/js/plugins/clusters-tab.js index 3b365ea362..4806e58132 100644 --- a/src/sunstone/public/js/plugins/clusters-tab.js +++ b/src/sunstone/public/js/plugins/clusters-tab.js @@ -28,6 +28,9 @@ var clusters_tab_content = '\ <th class="check"><input type="checkbox" class="check_all" value="">' + tr("All") + '</input></th>\ <th>' + tr("ID") + '</th>\ <th>' + tr("Name") + '</th>\ + <th>' + tr("Hosts") + '</th>\ + <th>' + tr("Virtual Networks") + '</th>\ + <th>' + tr("Datastores") + '</th>\ </tr>\ </thead>\ <tbody id="tbodyclusters">\ @@ -173,6 +176,37 @@ var cluster_actions = { error : onError, notify:true }, + + "Cluster.update" : { + type: "single", + call: OpenNebula.Cluster.update, + callback: function(){ + notifyMessage(tr("Template updated correctly")); + }, + error: onError + }, + + "Cluster.fetch_template" : { + type: "single", + call: OpenNebula.Cluster.fetch_template, + callback: function(request,response){ + $('#template_update_dialog #template_update_textarea').val(response.template); + }, + error: onError + }, + + "Cluster.update_dialog" : { + type: "custom", + call: function() { + popUpTemplateUpdateDialog("Cluster", + makeSelectOptions(dataTable_clusters, + 1,//idcol + 2,//namecol + [], + []), + clusterElements()); + }, + }, }; var cluster_buttons = { @@ -185,6 +219,11 @@ var cluster_buttons = { type: "create_dialog", text: tr("+ New") }, + "Cluster.update_dialog" : { + type : "action", + text : tr("Update properties"), + alwaysActive: true + }, "Cluster.delete" : { type: "confirm", text: tr("Delete") @@ -343,10 +382,32 @@ function clusterElementArray(element_json){ var element = element_json.CLUSTER; + var hosts = 0; + if ($.isArray(element.HOSTS.ID)) + hosts = element.HOSTS.ID.length; + else if (!$.isEmptyObject(element.HOSTS.ID)) + hosts = 1; + + var vnets = 0; + if ($.isArray(element.VNETS.ID)) + vnets = element.VNETS.ID.length; + else if (!$.isEmptyObject(element.VNETS.ID)) + vnets = 1; + + var dss = 0; + if ($.isArray(element.DATASTORES.ID)) + dss = element.DATASTORES.ID.length; + else if (!$.isEmptyObject(element.DATASTORES.ID)) + dss = 1; + + return [ '<input class="check_item" type="checkbox" id="cluster_'+element.ID+'" name="selected_items" value="'+element.ID+'"/>', element.ID, element.NAME, + hosts, + vnets, + dss ]; } @@ -929,7 +990,7 @@ $(document).ready(function(){ "aoColumnDefs": [ { "bSortable": false, "aTargets": ["check"] }, { "sWidth": "60px", "aTargets": [0] }, - { "sWidth": "35px", "aTargets": [1] }, + { "sWidth": "35px", "aTargets": [1,3,4,5] }, ], "oLanguage": (datatable_lang != "") ? { @@ -941,8 +1002,8 @@ $(document).ready(function(){ dataTable_clusters.fnClearTable(); addElement([ spinner, - '','',''],dataTable_clusters); -// Sunstone.runAction("Cluster.list"); + '','','','',''],dataTable_clusters); + Sunstone.runAction("Cluster.list"); setupCreateClusterDialog(); diff --git a/src/sunstone/public/js/sunstone-util.js b/src/sunstone/public/js/sunstone-util.js index e5970d40d4..a000052cf1 100644 --- a/src/sunstone/public/js/sunstone-util.js +++ b/src/sunstone/public/js/sunstone-util.js @@ -734,7 +734,7 @@ function setupTemplateUpdateDialog(){ autoOpen:false, width:700, modal:true, - height:410, + height:430, resizable:false, });