From 17052e69924df6864fc17d7c7e9ae21b6dcd91cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Mon, 2 Sep 2013 12:53:54 +0200 Subject: [PATCH 01/30] Feature #1713: Add host, ds and vnet rename actions --- include/Cluster.h | 24 +++ include/Datastore.h | 8 + include/Host.h | 8 + include/Image.h | 10 +- include/RequestManagerRename.h | 74 +++++++++ include/VirtualMachine.h | 10 ++ src/cli/onecluster | 10 ++ src/cli/onedatastore | 10 ++ src/cli/onehost | 10 ++ src/oca/ruby/opennebula/cluster.rb | 11 ++ src/oca/ruby/opennebula/datastore.rb | 13 +- src/oca/ruby/opennebula/host.rb | 13 +- src/rm/RequestManager.cc | 6 + src/rm/RequestManagerRename.cc | 215 +++++++++++++++++++++++++++ 14 files changed, 419 insertions(+), 3 deletions(-) diff --git a/include/Cluster.h b/include/Cluster.h index 822c2a28d0..52b4d46fd2 100644 --- a/include/Cluster.h +++ b/include/Cluster.h @@ -143,6 +143,30 @@ public: return rc; } + /** + * Returns a copy of the host IDs set + */ + set get_host_ids() + { + return hosts.get_collection_copy(); + } + + /** + * Returns a copy of the datastore IDs set + */ + set get_datastore_ids() + { + return datastores.get_collection_copy(); + } + + /** + * Returns a copy of the vnet IDs set + */ + set get_vnet_ids() + { + return vnets.get_collection_copy(); + } + // ************************************************************************* // DataBase implementation (Public) // ************************************************************************* diff --git a/include/Datastore.h b/include/Datastore.h index 2e7816f8e1..181dbdeba1 100644 --- a/include/Datastore.h +++ b/include/Datastore.h @@ -97,6 +97,14 @@ public: return del_collection_id(id); }; + /** + * Returns a copy of the Image IDs set + */ + set get_image_ids() + { + return get_collection_copy(); + } + /** * Retrieves TM mad name * @return string tm mad name diff --git a/include/Host.h b/include/Host.h index 801f32cc3c..aad9cef2e4 100644 --- a/include/Host.h +++ b/include/Host.h @@ -390,6 +390,14 @@ public: return host_share.test(cpu, mem, disk); } + /** + * Returns a copy of the VM IDs set + */ + set get_vm_ids() + { + return vm_collection.get_collection_copy(); + } + /** * Factory method for host templates */ diff --git a/include/Image.h b/include/Image.h index 500e26eb76..285bd18758 100644 --- a/include/Image.h +++ b/include/Image.h @@ -479,13 +479,21 @@ public: }; /** - * Returns the Datastore ID + * Returns the Datastore name */ const string& get_ds_name() const { return ds_name; }; + /** + * Updates the Datastore name + */ + void set_ds_name(const string& name) + { + ds_name = name; + }; + /** * Clones this image template including image specific attributes: NAME, * TYPE, PATH, FSTYPE, SIZE and PERSISTENT diff --git a/include/RequestManagerRename.h b/include/RequestManagerRename.h index 0034e5b62a..ecd470b053 100644 --- a/include/RequestManagerRename.h +++ b/include/RequestManagerRename.h @@ -45,6 +45,8 @@ protected: RequestAttributes& att); virtual PoolObjectSQL * get(const string& name, int uid, bool lock) = 0; + + virtual void post_execute(int oid){}; }; /* ------------------------------------------------------------------------- */ @@ -159,6 +161,78 @@ public: }; }; +/* ------------------------------------------------------------------------- */ +/* ------------------------------------------------------------------------- */ + +class ClusterRename: public RequestManagerRename +{ +public: + ClusterRename(): + RequestManagerRename("ClusterRename", "Renames a cluster") + { + Nebula& nd = Nebula::instance(); + pool = nd.get_clpool(); + auth_object = PoolObjectSQL::CLUSTER; + }; + + ~ClusterRename(){}; + + PoolObjectSQL * get(const string& name, int uid, bool lock) + { + return static_cast(pool)->get(name, lock); + }; + + void post_execute(int oid); +}; + +/* ------------------------------------------------------------------------- */ +/* ------------------------------------------------------------------------- */ + +class DatastoreRename: public RequestManagerRename +{ +public: + DatastoreRename(): + RequestManagerRename("DatastoreRename", "Renames a datastore") + { + Nebula& nd = Nebula::instance(); + pool = nd.get_dspool(); + auth_object = PoolObjectSQL::DATASTORE; + }; + + ~DatastoreRename(){}; + + PoolObjectSQL * get(const string& name, int uid, bool lock) + { + return static_cast(pool)->get(name, lock); + }; + + void post_execute(int oid); +}; + +/* ------------------------------------------------------------------------- */ +/* ------------------------------------------------------------------------- */ + +class HostRename: public RequestManagerRename +{ +public: + HostRename(): + RequestManagerRename("HostRename", "Renames a host") + { + Nebula& nd = Nebula::instance(); + pool = nd.get_hpool(); + auth_object = PoolObjectSQL::HOST; + }; + + ~HostRename(){}; + + PoolObjectSQL * get(const string& name, int uid, bool lock) + { + return static_cast(pool)->get(name, lock); + }; + + void post_execute(int oid); +}; + /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ diff --git a/include/VirtualMachine.h b/include/VirtualMachine.h index 38e943835a..645dc0b377 100644 --- a/include/VirtualMachine.h +++ b/include/VirtualMachine.h @@ -623,6 +623,16 @@ public: return history->hostname; }; + /** + * Updates the current hostname. The hasHistory() + * function MUST be called before this one. + * @param hostname New hostname + */ + void set_hostname(const string& hostname) + { + history->hostname = hostname; + }; + /** * Returns the hostname for the previous host. The hasPreviousHistory() * function MUST be called before this one. diff --git a/src/cli/onecluster b/src/cli/onecluster index 4e61e09e09..5624ec649b 100755 --- a/src/cli/onecluster +++ b/src/cli/onecluster @@ -197,4 +197,14 @@ cmd=CommandParser::CmdParser.new(ARGV) do obj.update(str, options[:append]) end end + + rename_desc = <<-EOT.unindent + Renames the Cluster + EOT + + command :rename, rename_desc, :clusterid, :name do + helper.perform_action(args[0],options,"renamed") do |o| + o.rename(args[1]) + end + end end diff --git a/src/cli/onedatastore b/src/cli/onedatastore index 77e4c4b2c2..7c09d0cb16 100755 --- a/src/cli/onedatastore +++ b/src/cli/onedatastore @@ -174,4 +174,14 @@ cmd=CommandParser::CmdParser.new(ARGV) do obj.update(str, options[:append]) end end + + rename_desc = <<-EOT.unindent + Renames the Datastore + EOT + + command :rename, rename_desc, :datastoreid, :name do + helper.perform_action(args[0],options,"renamed") do |o| + o.rename(args[1]) + end + end end diff --git a/src/cli/onehost b/src/cli/onehost index 9c9a4d9463..108db2d3fd 100755 --- a/src/cli/onehost +++ b/src/cli/onehost @@ -213,4 +213,14 @@ cmd=CommandParser::CmdParser.new(ARGV) do host.flush end end + + rename_desc = <<-EOT.unindent + Renames the Host + EOT + + command :rename, rename_desc, :hostid, :name do + helper.perform_action(args[0],options,"renamed") do |o| + o.rename(args[1]) + end + end end diff --git a/src/oca/ruby/opennebula/cluster.rb b/src/oca/ruby/opennebula/cluster.rb index 9f0997d96c..25c9d758f8 100644 --- a/src/oca/ruby/opennebula/cluster.rb +++ b/src/oca/ruby/opennebula/cluster.rb @@ -34,6 +34,7 @@ module OpenNebula :addvnet => "cluster.addvnet", :delvnet => "cluster.delvnet", :update => "cluster.update", + :rename => "cluster.rename" } # Creates a Cluster description with just its identifier @@ -171,6 +172,16 @@ module OpenNebula super(CLUSTER_METHODS[:update], new_template, append ? 1 : 0) end + # Renames this Cluster + # + # @param name [String] New name for the Cluster. + # + # @return [nil, OpenNebula::Error] nil in case of success, Error + # otherwise + def rename(name) + return call(CLUSTER_METHODS[:rename], @pe_id, name) + end + # --------------------------------------------------------------------- # Helpers to get information # --------------------------------------------------------------------- diff --git a/src/oca/ruby/opennebula/datastore.rb b/src/oca/ruby/opennebula/datastore.rb index 6bf2a9abca..fe702abfaa 100644 --- a/src/oca/ruby/opennebula/datastore.rb +++ b/src/oca/ruby/opennebula/datastore.rb @@ -29,7 +29,8 @@ module OpenNebula :delete => "datastore.delete", :update => "datastore.update", :chown => "datastore.chown", - :chmod => "datastore.chmod" + :chmod => "datastore.chmod", + :rename => "datastore.rename" } DATASTORE_TYPES=%w{IMAGE SYSTEM FILE} @@ -146,6 +147,16 @@ module OpenNebula group_m, group_a, other_u, other_m, other_a) end + # Renames this datastore + # + # @param name [String] New name for the datastore + # + # @return [nil, OpenNebula::Error] nil in case of success, Error + # otherwise + def rename(name) + return call(DATASTORE_METHODS[:rename], @pe_id, name) + end + # --------------------------------------------------------------------- # Helpers to get information # --------------------------------------------------------------------- diff --git a/src/oca/ruby/opennebula/host.rb b/src/oca/ruby/opennebula/host.rb index 94ab6f6323..7476e01c9e 100644 --- a/src/oca/ruby/opennebula/host.rb +++ b/src/oca/ruby/opennebula/host.rb @@ -30,7 +30,8 @@ module OpenNebula :delete => "host.delete", :enable => "host.enable", :update => "host.update", - :monitoring => "host.monitoring" + :monitoring => "host.monitoring", + :rename => "host.rename" } HOST_STATES=%w{INIT MONITORING_MONITORED MONITORED ERROR DISABLED MONITORING_ERROR MONITORING_INIT MONITORING_DISABLED} @@ -176,6 +177,16 @@ module OpenNebula return @client.call(HOST_METHODS[:monitoring], @pe_id) end + # Renames this Host + # + # @param name [String] New name for the Host. + # + # @return [nil, OpenNebula::Error] nil in case of success, Error + # otherwise + def rename(name) + return call(HOST_METHODS[:rename], @pe_id, name) + end + ####################################################################### # Helpers to get Host information ####################################################################### diff --git a/src/rm/RequestManager.cc b/src/rm/RequestManager.cc index 05d9aae885..55e70802fb 100644 --- a/src/rm/RequestManager.cc +++ b/src/rm/RequestManager.cc @@ -405,6 +405,9 @@ void RequestManager::register_xml_methods() xmlrpc_c::methodPtr vn_rename(new VirtualNetworkRename()); xmlrpc_c::methodPtr image_rename(new ImageRename()); xmlrpc_c::methodPtr doc_rename(new DocumentRename()); + xmlrpc_c::methodPtr cluster_rename(new ClusterRename()); + xmlrpc_c::methodPtr datastore_rename(new DatastoreRename()); + xmlrpc_c::methodPtr host_rename(new HostRename()); /* VM related methods */ RequestManagerRegistry.addMethod("one.vm.deploy", vm_deploy); @@ -452,6 +455,7 @@ void RequestManager::register_xml_methods() RequestManagerRegistry.addMethod("one.host.delete", host_delete); RequestManagerRegistry.addMethod("one.host.info", host_info); RequestManagerRegistry.addMethod("one.host.monitoring", host_monitoring); + RequestManagerRegistry.addMethod("one.host.rename", host_rename); RequestManagerRegistry.addMethod("one.hostpool.info", hostpool_info); RequestManagerRegistry.addMethod("one.hostpool.monitoring", host_pool_monitoring); @@ -524,6 +528,7 @@ void RequestManager::register_xml_methods() RequestManagerRegistry.addMethod("one.datastore.update", datastore_update); RequestManagerRegistry.addMethod("one.datastore.chown", datastore_chown); RequestManagerRegistry.addMethod("one.datastore.chmod", datastore_chmod); + RequestManagerRegistry.addMethod("one.datastore.rename", datastore_rename); RequestManagerRegistry.addMethod("one.datastorepool.info",datastorepool_info); @@ -532,6 +537,7 @@ void RequestManager::register_xml_methods() RequestManagerRegistry.addMethod("one.cluster.delete", cluster_delete); RequestManagerRegistry.addMethod("one.cluster.info", cluster_info); RequestManagerRegistry.addMethod("one.cluster.update", cluster_update); + RequestManagerRegistry.addMethod("one.cluster.rename", cluster_rename); RequestManagerRegistry.addMethod("one.cluster.addhost", cluster_addhost); RequestManagerRegistry.addMethod("one.cluster.delhost", cluster_delhost); diff --git a/src/rm/RequestManagerRename.cc b/src/rm/RequestManagerRename.cc index 0c5ba2bcca..6ca01c0b02 100644 --- a/src/rm/RequestManagerRename.cc +++ b/src/rm/RequestManagerRename.cc @@ -113,8 +113,223 @@ void RequestManagerRename::request_execute(xmlrpc_c::paramList const& paramList, pool->update_cache_index(old_name, operms.uid, new_name, operms.uid); + post_execute(oid); + success_response(oid, att); return; } +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + +void * cluster_rename_loop(void *arg) +{ + Cluster * cluster = static_cast(arg); + + if (cluster == 0) + { + return 0; + } + + const set & hosts = cluster->get_host_ids(); + const set & datastores = cluster->get_datastore_ids(); + const set & vnets = cluster->get_vnet_ids(); + + set::iterator it; + + int oid = cluster->get_oid(); + string cluster_name = cluster->get_name(); + + cluster->unlock(); + + Host * host; + HostPool* hpool = Nebula::instance().get_hpool(); + + Datastore * ds; + DatastorePool* dspool = Nebula::instance().get_dspool(); + + VirtualNetwork* vnet; + VirtualNetworkPool* vnpool = Nebula::instance().get_vnpool(); + + for (it = hosts.begin(); it != hosts.end(); it++) + { + host = hpool->get(*it, true); + + if (host != 0) + { + if (host->get_cluster_id() == oid) + { + host->set_cluster(oid, cluster_name); + hpool->update(host); + } + + host->unlock(); + } + } + + for (it = datastores.begin(); it != datastores.end(); it++) + { + ds = dspool->get(*it, true); + + if (ds != 0) + { + if (ds->get_cluster_id() == oid) + { + ds->set_cluster(oid, cluster_name); + dspool->update(ds); + } + + ds->unlock(); + } + } + + for (it = vnets.begin(); it != vnets.end(); it++) + { + vnet = vnpool->get(*it, true); + + if (vnet != 0) + { + if (vnet->get_cluster_id() == oid) + { + vnet->set_cluster(oid, cluster_name); + vnpool->update(vnet); + } + + vnet->unlock(); + } + } + + return 0; +} + +void ClusterRename::post_execute(int oid) +{ + pthread_t pthread; + + pthread_attr_t pattr; + + pthread_attr_init (&pattr); + pthread_attr_setdetachstate (&pattr, PTHREAD_CREATE_DETACHED); + + Cluster * cluster = static_cast(pool)->get(oid, true); + + pthread_create(&pthread, &pattr, cluster_rename_loop, (void *) cluster); +} + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + +void * ds_rename_loop(void *arg) +{ + Datastore * datastore = static_cast(arg); + + if (datastore == 0) + { + return 0; + } + + const set & images = datastore->get_image_ids(); + + set::iterator it; + + int oid = datastore->get_oid(); + string image_name = datastore->get_name(); + + datastore->unlock(); + + Image * image; + ImagePool * ipool = Nebula::instance().get_ipool(); + + for (it = images.begin(); it != images.end(); it++) + { + image = ipool->get(*it, true); + + if (image != 0) + { + if (image->get_ds_id() == oid) + { + image->set_ds_name(image_name); + ipool->update(image); + } + + image->unlock(); + } + } + + return 0; +} + +void DatastoreRename::post_execute(int oid) +{ + pthread_t pthread; + + pthread_attr_t pattr; + + pthread_attr_init (&pattr); + pthread_attr_setdetachstate (&pattr, PTHREAD_CREATE_DETACHED); + + Datastore * datastore = static_cast(pool)->get(oid, true); + + pthread_create(&pthread, &pattr, ds_rename_loop, (void *) datastore); +} + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + +void * host_rename_loop(void *arg) +{ + Host * host = static_cast(arg); + + if (host == 0) + { + return 0; + } + + const set & vms = host->get_vm_ids(); + + set::iterator it; + + int oid = host->get_oid(); + string host_name = host->get_name(); + + host->unlock(); + + VirtualMachine * vm; + VirtualMachinePool * vmpool = Nebula::instance().get_vmpool(); + + for (it = vms.begin(); it != vms.end(); it++) + { + vm = vmpool->get(*it, true); + + if (vm != 0) + { + if (vm->hasHistory() && vm->get_hid() == oid) + { + vm->set_hostname(host_name); + vmpool->update(vm); + } + + vm->unlock(); + } + } + + return 0; +} + +void HostRename::post_execute(int oid) +{ + pthread_t pthread; + + pthread_attr_t pattr; + + pthread_attr_init (&pattr); + pthread_attr_setdetachstate (&pattr, PTHREAD_CREATE_DETACHED); + + Host * host = static_cast(pool)->get(oid, true); + + pthread_create(&pthread, &pattr, host_rename_loop, (void *) host); +} + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ From 6641d15469e4887d129ce9813d5d894bbee1da0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Mon, 2 Sep 2013 15:08:23 +0200 Subject: [PATCH 02/30] Feature #1713: Add rename actions to sunstone --- .../models/OpenNebulaJSON/ClusterJSON.rb | 5 +++ .../models/OpenNebulaJSON/DatastoreJSON.rb | 5 +++ .../models/OpenNebulaJSON/HostJSON.rb | 4 ++ src/sunstone/public/js/opennebula.js | 21 +++++++++ .../public/js/plugins/clusters-tab.js | 43 +++++++++++++++++-- .../public/js/plugins/datastores-tab.js | 39 +++++++++++++++-- src/sunstone/public/js/plugins/hosts-tab.js | 40 +++++++++++++++-- 7 files changed, 147 insertions(+), 10 deletions(-) diff --git a/src/sunstone/models/OpenNebulaJSON/ClusterJSON.rb b/src/sunstone/models/OpenNebulaJSON/ClusterJSON.rb index c2d8a09c12..8713d15574 100644 --- a/src/sunstone/models/OpenNebulaJSON/ClusterJSON.rb +++ b/src/sunstone/models/OpenNebulaJSON/ClusterJSON.rb @@ -43,6 +43,7 @@ module OpenNebulaJSON when "addvnet" then self.addvnet(action_hash['params']) when "delvnet" then self.delvnet(action_hash['params']) when "update" then self.update(action_hash['params']) + when "rename" then self.rename(action_hash['params']) else error_msg = "#{action_hash['perform']} action not " << @@ -78,5 +79,9 @@ module OpenNebulaJSON def update(params=Hash.new) super(params['template_raw']) end + + def rename(params=Hash.new) + super(params['name']) + end end end diff --git a/src/sunstone/models/OpenNebulaJSON/DatastoreJSON.rb b/src/sunstone/models/OpenNebulaJSON/DatastoreJSON.rb index e7ff02b4ea..a17ad80f7e 100644 --- a/src/sunstone/models/OpenNebulaJSON/DatastoreJSON.rb +++ b/src/sunstone/models/OpenNebulaJSON/DatastoreJSON.rb @@ -50,6 +50,7 @@ module OpenNebulaJSON when "update" then self.update(action_hash['params']) when "chown" then self.chown(action_hash['params']) when "chmod" then self.chmod_octet(action_hash['params']) + when "rename" then self.rename(action_hash['params']) else error_msg = "#{action_hash['perform']} action not " << " available for this resource" @@ -68,5 +69,9 @@ module OpenNebulaJSON def chmod_octet(params=Hash.new) super(params['octet']) end + + def rename(params=Hash.new) + super(params['name']) + end end end diff --git a/src/sunstone/models/OpenNebulaJSON/HostJSON.rb b/src/sunstone/models/OpenNebulaJSON/HostJSON.rb index 196010d609..57adb5df10 100644 --- a/src/sunstone/models/OpenNebulaJSON/HostJSON.rb +++ b/src/sunstone/models/OpenNebulaJSON/HostJSON.rb @@ -51,6 +51,7 @@ module OpenNebulaJSON when "enable" then self.enable when "disable" then self.disable when "update" then self.update(action_hash['params']) + when "rename" then self.rename(action_hash['params']) else error_msg = "#{action_hash['perform']} action not " << " available for this resource" @@ -62,5 +63,8 @@ module OpenNebulaJSON super(params['template_raw']) end + def rename(params=Hash.new) + super(params['name']) + end end end diff --git a/src/sunstone/public/js/opennebula.js b/src/sunstone/public/js/opennebula.js index 878e005170..4fcf8542a1 100644 --- a/src/sunstone/public/js/opennebula.js +++ b/src/sunstone/public/js/opennebula.js @@ -531,6 +531,13 @@ var OpenNebula = { }, "pool_monitor" : function(params){ OpenNebula.Action.monitor(params,OpenNebula.Host.resource,true); + }, + "rename" : function(params){ + var action_obj = params.data.extra_param; + OpenNebula.Action.simple_action(params, + OpenNebula.Host.resource, + "rename", + action_obj); } }, @@ -1152,6 +1159,13 @@ var OpenNebula = { OpenNebula.Cluster.resource, "update", action_obj); + }, + "rename" : function(params){ + var action_obj = params.data.extra_param; + OpenNebula.Action.simple_action(params, + OpenNebula.Cluster.resource, + "rename", + action_obj); } }, "Datastore" : { @@ -1191,6 +1205,13 @@ var OpenNebula = { }, "fetch_template" : function(params){ OpenNebula.Action.show(params,OpenNebula.Datastore.resource,"template"); + }, + "rename" : function(params){ + var action_obj = params.data.extra_param; + OpenNebula.Action.simple_action(params, + OpenNebula.Datastore.resource, + "rename", + action_obj); } }, diff --git a/src/sunstone/public/js/plugins/clusters-tab.js b/src/sunstone/public/js/plugins/clusters-tab.js index 53f372bf6b..b296532e8a 100644 --- a/src/sunstone/public/js/plugins/clusters-tab.js +++ b/src/sunstone/public/js/plugins/clusters-tab.js @@ -1070,6 +1070,18 @@ var cluster_actions = { type: "single", call: popUpUpdateClusterDialog }, + + "Cluster.rename" : { + type: "single", + call: OpenNebula.Cluster.rename, + callback: function(request) { + notifyMessage("Cluster renamed correctly"); + Sunstone.runAction('Cluster.showinfo',request.request.data[0]); + Sunstone.runAction('Cluster.list'); + }, + error: onError, + notify: true + } }; var cluster_buttons = { @@ -1233,18 +1245,22 @@ function updateClusterInfo(request,cluster){
\ \ \ - \ \ \ \ \ - \ + \ \ \ - \ - \ + \ + \ + \ \ \
' + +
' + tr("Cluster") + ' - '+cluster_info.NAME+'
' + tr("id") + ''+cluster_info.ID+''+cluster_info.ID+'
' + tr("Name") + ''+cluster_info.NAME+''+tr("Name")+''+cluster_info.NAME+'
\ + \ +
\ +
\ @@ -1291,6 +1307,25 @@ function updateClusterInfo(request,cluster){
' } + $("#div_edit_rename_link").die(); + $(".input_edit_value_rename").die(); + + // Listener for edit link for rename + $("#div_edit_rename_link").live("click", function() { + var value_str = $(".value_td_rename").text(); + $(".value_td_rename").html(''); + }); + + $(".input_edit_value_rename").live("change", function() { + var value_str = $(".input_edit_value_rename").val(); + if(value_str!="") + { + // Let OpenNebula know + var name_template = {"name": value_str}; + Sunstone.runAction("Cluster.rename",cluster_info.ID,name_template); + } + }); + //Sunstone.updateInfoPanelTab(info_panel_name,tab_name, new tab object); Sunstone.updateInfoPanelTab("cluster_info_panel","cluster_info_tab",info_tab); Sunstone.updateInfoPanelTab("cluster_info_panel","cluster_host_tab",cluster_host_tab); diff --git a/src/sunstone/public/js/plugins/datastores-tab.js b/src/sunstone/public/js/plugins/datastores-tab.js index 9913f3d759..eb51f684a9 100644 --- a/src/sunstone/public/js/plugins/datastores-tab.js +++ b/src/sunstone/public/js/plugins/datastores-tab.js @@ -524,6 +524,18 @@ var datastore_actions = { hideDialog(); $('div#datastores_tab div.legend_div').slideToggle(); } + }, + + "Datastore.rename" : { + type: "single", + call: OpenNebula.Datastore.rename, + callback: function(request) { + notifyMessage("Datastore renamed correctly"); + Sunstone.runAction('Datastore.showinfo',request.request.data[0]); + Sunstone.runAction('Datastore.list'); + }, + error: onError, + notify: true } }; @@ -733,9 +745,12 @@ function updateDatastoreInfo(request,ds){ \ \ \ - '+tr("Name")+'\ - '+info.NAME+'\ - \ + '+tr("Name")+'\ + '+info.NAME+'\ +
\ + \ +
\ + \ \ '+ cluster_str + @@ -787,6 +802,24 @@ function updateDatastoreInfo(request,ds){ content : '
' + datastore_image_table_tmpl + '
' } + $("#div_edit_rename_link").die(); + $(".input_edit_value_rename").die(); + + // Listener for edit link for rename + $("#div_edit_rename_link").live("click", function() { + var value_str = $(".value_td_rename").text(); + $(".value_td_rename").html(''); + }); + + $(".input_edit_value_rename").live("change", function() { + var value_str = $(".input_edit_value_rename").val(); + if(value_str!="") + { + // Let OpenNebula know + var name_template = {"name": value_str}; + Sunstone.runAction("Datastore.rename",info.ID,name_template); + } + }); // Add tabs Sunstone.updateInfoPanelTab("datastore_info_panel","datastore_info_tab",info_tab); diff --git a/src/sunstone/public/js/plugins/hosts-tab.js b/src/sunstone/public/js/plugins/hosts-tab.js index 2ef52deb31..450a2b3f8f 100644 --- a/src/sunstone/public/js/plugins/hosts-tab.js +++ b/src/sunstone/public/js/plugins/hosts-tab.js @@ -384,8 +384,19 @@ var host_actions = { hideDialog(); $('div#hosts_tab div.legend_div').slideToggle(); } - } + }, + "Host.rename" : { + type: "single", + call: OpenNebula.Host.rename, + callback: function(request) { + notifyMessage("Host renamed correctly"); + Sunstone.runAction('Host.showinfo',request.request.data[0]); + Sunstone.runAction('Host.list'); + }, + error: onError, + notify: true + } }; var host_buttons = { @@ -732,8 +743,12 @@ function updateHostInfo(request,host){ '+host_info.ID+'\ \ \ - ' + tr("Name") + '\ - '+host_info.NAME+'\ + '+tr("Name")+'\ + '+host_info.NAME+'\ +
\ + \ +
\ + \ \ ' + insert_cluster_dropdown("Host",host_info.ID,host_info.CLUSTER,host_info.CLUSTER_ID) + @@ -828,6 +843,25 @@ function updateHostInfo(request,host){ ' } + $("#div_edit_rename_link").die(); + $(".input_edit_value_rename").die(); + + // Listener for edit link for rename + $("#div_edit_rename_link").live("click", function() { + var value_str = $(".value_td_rename").text(); + $(".value_td_rename").html(''); + }); + + $(".input_edit_value_rename").live("change", function() { + var value_str = $(".input_edit_value_rename").val(); + if(value_str!="") + { + // Let OpenNebula know + var name_template = {"name": value_str}; + Sunstone.runAction("Host.rename",host_info.ID,name_template); + } + }); + //Sunstone.updateInfoPanelTab(info_panel_name,tab_name, new tab object); Sunstone.updateInfoPanelTab("host_info_panel","host_info_tab",info_tab); Sunstone.updateInfoPanelTab("host_info_panel","host_monitoring_tab",monitor_tab); From a0e538310e0ecf0a0a24d75eb11716bea937a819 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Mon, 2 Sep 2013 15:27:34 +0200 Subject: [PATCH 03/30] Feature #1713: Add rename actions to Java OCA --- .../opennebula/client/cluster/Cluster.java | 25 +++++++++++++++++++ .../client/datastore/Datastore.java | 25 +++++++++++++++++++ .../src/org/opennebula/client/host/Host.java | 25 +++++++++++++++++++ 3 files changed, 75 insertions(+) diff --git a/src/oca/java/src/org/opennebula/client/cluster/Cluster.java b/src/oca/java/src/org/opennebula/client/cluster/Cluster.java index 15ea8b3e31..094016ae1a 100644 --- a/src/oca/java/src/org/opennebula/client/cluster/Cluster.java +++ b/src/oca/java/src/org/opennebula/client/cluster/Cluster.java @@ -37,6 +37,7 @@ public class Cluster extends PoolElement{ private static final String DELDATASTORE = METHOD_PREFIX + "deldatastore"; private static final String ADDVNET = METHOD_PREFIX + "addvnet"; private static final String DELVNET = METHOD_PREFIX + "delvnet"; + private static final String RENAME = METHOD_PREFIX + "rename"; /** * Creates a new Cluster representation. @@ -199,6 +200,19 @@ public class Cluster extends PoolElement{ return client.call(DELVNET, id, vnetId); } + /** + * Renames this Cluster. + * + * @param client XML-RPC Client. + * @param id The image id of the target host we want to modify. + * @param name New name for the Cluster + * @return If successful the message contains the cluster id. + */ + public static OneResponse rename(Client client, int id, String name) + { + return client.call(RENAME, id, name); + } + // ================================= // Instanced object XML-RPC methods // ================================= @@ -315,6 +329,17 @@ public class Cluster extends PoolElement{ return delVnet(client, id, vnetId); } + /** + * Renames this Cluster + * + * @param name New name for the Cluster. + * @return If an error occurs the error message contains the reason. + */ + public OneResponse rename(String name) + { + return rename(client, id, name); + } + // ================================= // Helpers // ================================= diff --git a/src/oca/java/src/org/opennebula/client/datastore/Datastore.java b/src/oca/java/src/org/opennebula/client/datastore/Datastore.java index 26a03b8b60..f68b42303f 100644 --- a/src/oca/java/src/org/opennebula/client/datastore/Datastore.java +++ b/src/oca/java/src/org/opennebula/client/datastore/Datastore.java @@ -35,6 +35,7 @@ public class Datastore extends PoolElement private static final String UPDATE = METHOD_PREFIX + "update"; private static final String CHOWN = METHOD_PREFIX + "chown"; private static final String CHMOD = METHOD_PREFIX + "chmod"; + private static final String RENAME = METHOD_PREFIX + "rename"; private static final String[] DATASTORE_TYPES = {"IMAGE", "SYSTEM", "FILE"}; @@ -212,6 +213,19 @@ public class Datastore extends PoolElement return chmod(client, CHMOD, id, octet); } + /** + * Renames this Datastore. + * + * @param client XML-RPC Client. + * @param id The image id of the target host we want to modify. + * @param name New name for the Datastore + * @return If successful the message contains the datastore id. + */ + public static OneResponse rename(Client client, int id, String name) + { + return client.call(RENAME, id, name); + } + // ================================= // Instanced object XML-RPC methods // ================================= @@ -373,6 +387,17 @@ public class Datastore extends PoolElement return chmod(client, id, octet); } + /** + * Renames this Datastore + * + * @param name New name for the Datastore. + * @return If an error occurs the error message contains the reason. + */ + public OneResponse rename(String name) + { + return rename(client, id, name); + } + // ================================= // Helpers // ================================= diff --git a/src/oca/java/src/org/opennebula/client/host/Host.java b/src/oca/java/src/org/opennebula/client/host/Host.java index df36d87eae..f9aba9eb8f 100644 --- a/src/oca/java/src/org/opennebula/client/host/Host.java +++ b/src/oca/java/src/org/opennebula/client/host/Host.java @@ -34,6 +34,7 @@ public class Host extends PoolElement{ private static final String ENABLE = METHOD_PREFIX + "enable"; private static final String UPDATE = METHOD_PREFIX + "update"; private static final String MONITORING = METHOD_PREFIX + "monitoring"; + private static final String RENAME = METHOD_PREFIX + "rename"; private static final String[] HOST_STATES = {"INIT", "MONITORING_MONITORED", "MONITORED", "ERROR", "DISABLED", @@ -189,6 +190,19 @@ public class Host extends PoolElement{ return client.call(MONITORING, id); } + /** + * Renames this Host. + * + * @param client XML-RPC Client. + * @param id The image id of the target host we want to modify. + * @param name New name for the Host + * @return If successful the message contains the host id. + */ + public static OneResponse rename(Client client, int id, String name) + { + return client.call(RENAME, id, name); + } + // ================================= // Instanced object XML-RPC methods // ================================= @@ -280,6 +294,17 @@ public class Host extends PoolElement{ return monitoring(client, id); } + /** + * Renames this Host. + * + * @param name New name for the Host + * @return If successful the message contains the host id. + */ + public OneResponse rename(String name) + { + return rename(client, id, name); + } + // ================================= // Helpers // ================================= From dcf019f91b929e816b5eba3aa6e8fc93ae4d7605 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Mon, 2 Sep 2013 15:44:34 +0200 Subject: [PATCH 04/30] Sunstone message missing from translations --- src/sunstone/public/js/plugins/files-tab.js | 2 +- src/sunstone/public/js/plugins/images-tab.js | 2 +- src/sunstone/public/js/plugins/templates-tab.js | 1 + src/sunstone/public/js/plugins/vms-tab.js | 2 +- src/sunstone/public/js/plugins/vnets-tab.js | 2 +- 5 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/sunstone/public/js/plugins/files-tab.js b/src/sunstone/public/js/plugins/files-tab.js index 96d88e5456..f926825033 100644 --- a/src/sunstone/public/js/plugins/files-tab.js +++ b/src/sunstone/public/js/plugins/files-tab.js @@ -353,7 +353,7 @@ var file_actions = { type: "single", call: OpenNebula.Image.rename, callback: function(request) { - notifyMessage("File renamed correctly"); + notifyMessage(tr("File renamed correctly")); Sunstone.runAction('Image.showinfo',request.request.data[0]); Sunstone.runAction('Image.list'); }, diff --git a/src/sunstone/public/js/plugins/images-tab.js b/src/sunstone/public/js/plugins/images-tab.js index 2a50f9fb51..006fee889a 100644 --- a/src/sunstone/public/js/plugins/images-tab.js +++ b/src/sunstone/public/js/plugins/images-tab.js @@ -522,7 +522,7 @@ var image_actions = { type: "single", call: OpenNebula.Image.rename, callback: function(request) { - notifyMessage("Image renamed correctly"); + notifyMessage(tr("Image renamed correctly")); Sunstone.runAction('Image.showinfo',request.request.data[0]); Sunstone.runAction('Image.list'); }, diff --git a/src/sunstone/public/js/plugins/templates-tab.js b/src/sunstone/public/js/plugins/templates-tab.js index fe01ebd4e4..da15d5219c 100644 --- a/src/sunstone/public/js/plugins/templates-tab.js +++ b/src/sunstone/public/js/plugins/templates-tab.js @@ -381,6 +381,7 @@ var template_actions = { type: "single", call: OpenNebula.Template.rename, callback: function(request) { + notifyMessage(tr("Template renamed correctly")); Sunstone.runAction('Template.showinfo',request.request.data[0]); Sunstone.runAction("Template.show",request.request.data[0]); }, diff --git a/src/sunstone/public/js/plugins/vms-tab.js b/src/sunstone/public/js/plugins/vms-tab.js index b7c113f977..4c031c1ab4 100644 --- a/src/sunstone/public/js/plugins/vms-tab.js +++ b/src/sunstone/public/js/plugins/vms-tab.js @@ -819,7 +819,7 @@ var vm_actions = { type: "single", call: OpenNebula.VM.rename, callback: function(request) { - notifyMessage("VirtualMachine renamed correctly"); + notifyMessage(tr("VirtualMachine renamed correctly")); Sunstone.runAction('VM.showinfo',request.request.data[0]); Sunstone.runAction("VM.list"); }, diff --git a/src/sunstone/public/js/plugins/vnets-tab.js b/src/sunstone/public/js/plugins/vnets-tab.js index 44696d188a..8439354b77 100644 --- a/src/sunstone/public/js/plugins/vnets-tab.js +++ b/src/sunstone/public/js/plugins/vnets-tab.js @@ -617,7 +617,7 @@ var vnet_actions = { type: "single", call: OpenNebula.Network.rename, callback: function(request) { - notifyMessage("VirtualNetwork renamed correctly"); + notifyMessage(tr("VirtualNetwork renamed correctly")); Sunstone.runAction('Network.showinfo',request.request.data[0]); Sunstone.runAction("Network.list"); }, From 8b3dd9f1866c0781f12a6cf5c92dc8ffa6da285a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Mon, 2 Sep 2013 15:47:18 +0200 Subject: [PATCH 05/30] Feature #1713: New rename messages missing from translations --- src/sunstone/public/js/plugins/clusters-tab.js | 2 +- src/sunstone/public/js/plugins/datastores-tab.js | 2 +- src/sunstone/public/js/plugins/hosts-tab.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/sunstone/public/js/plugins/clusters-tab.js b/src/sunstone/public/js/plugins/clusters-tab.js index b296532e8a..245c255590 100644 --- a/src/sunstone/public/js/plugins/clusters-tab.js +++ b/src/sunstone/public/js/plugins/clusters-tab.js @@ -1075,7 +1075,7 @@ var cluster_actions = { type: "single", call: OpenNebula.Cluster.rename, callback: function(request) { - notifyMessage("Cluster renamed correctly"); + notifyMessage(tr("Cluster renamed correctly")); Sunstone.runAction('Cluster.showinfo',request.request.data[0]); Sunstone.runAction('Cluster.list'); }, diff --git a/src/sunstone/public/js/plugins/datastores-tab.js b/src/sunstone/public/js/plugins/datastores-tab.js index eb51f684a9..35729778be 100644 --- a/src/sunstone/public/js/plugins/datastores-tab.js +++ b/src/sunstone/public/js/plugins/datastores-tab.js @@ -530,7 +530,7 @@ var datastore_actions = { type: "single", call: OpenNebula.Datastore.rename, callback: function(request) { - notifyMessage("Datastore renamed correctly"); + notifyMessage(tr("Datastore renamed correctly")); Sunstone.runAction('Datastore.showinfo',request.request.data[0]); Sunstone.runAction('Datastore.list'); }, diff --git a/src/sunstone/public/js/plugins/hosts-tab.js b/src/sunstone/public/js/plugins/hosts-tab.js index 450a2b3f8f..956724045a 100644 --- a/src/sunstone/public/js/plugins/hosts-tab.js +++ b/src/sunstone/public/js/plugins/hosts-tab.js @@ -390,7 +390,7 @@ var host_actions = { type: "single", call: OpenNebula.Host.rename, callback: function(request) { - notifyMessage("Host renamed correctly"); + notifyMessage(tr("Host renamed correctly")); Sunstone.runAction('Host.showinfo',request.request.data[0]); Sunstone.runAction('Host.list'); }, From 97d45b68df38cd013bb6e8674bde775faf714031 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Tue, 3 Sep 2013 12:47:21 +0200 Subject: [PATCH 06/30] Feature #1713: Add host, ds & cluster name checks to fsck --- src/onedb/fsck.rb | 183 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 140 insertions(+), 43 deletions(-) diff --git a/src/onedb/fsck.rb b/src/onedb/fsck.rb index 649643234b..1d29fd41fd 100644 --- a/src/onedb/fsck.rb +++ b/src/onedb/fsck.rb @@ -308,9 +308,11 @@ module OneDBFsck cluster = {} - @db.fetch("SELECT oid FROM cluster_pool") do |row| + @db.fetch("SELECT oid, name FROM cluster_pool") do |row| cluster[row[:oid]] = {} + cluster[row[:oid]][:name] = row[:name] + cluster[row[:oid]][:hosts] = [] cluster[row[:oid]][:datastores] = [] cluster[row[:oid]][:vnets] = [] @@ -322,13 +324,21 @@ module OneDBFsck datastores_fix = {} vnets_fix = {} - @db.fetch("SELECT oid,body FROM host_pool") do |row| + @db.fetch("SELECT oid,body,cid FROM host_pool") do |row| doc = Document.new(row[:body]) cluster_id = doc.root.get_text('CLUSTER_ID').to_s.to_i + cluster_name = doc.root.get_text('CLUSTER') + + if cluster_id != row[:cid] + log_error("Host #{row[:oid]} is in cluster #{cluster_id}, but cid column has cluster #{row[:cid]}") + hosts_fix[row[:oid]] = {:body => row[:body], :cid => cluster_id} + end if cluster_id != -1 - if cluster[cluster_id].nil? + cluster_entry = cluster[cluster_id] + + if cluster_entry.nil? log_error("Host #{row[:oid]} is in cluster #{cluster_id}, but it does not exist") doc.root.each_element('CLUSTER_ID') do |e| @@ -339,25 +349,43 @@ module OneDBFsck e.text = "" end - hosts_fix[row[:oid]] = doc.to_s + hosts_fix[row[:oid]] = {:body => doc.to_s, :cid => -1} else - cluster[cluster_id][:hosts] << row[:oid] + if cluster_name != cluster_entry[:name] + log_error("Host #{row[:oid]} has a wrong name for cluster #{cluster_id}, #{cluster_name}. It will be changed to #{cluster_entry[:name]}") + + doc.root.each_element('CLUSTER') do |e| + e.text = cluster_entry[:name] + end + + hosts_fix[row[:oid]] = {:body => doc.to_s, :cid => cluster_id} + end + + cluster_entry[:hosts] << row[:oid] end end end - hosts_fix.each do |id, body| - @db[:host_pool].where(:oid => id).update(:body => body, :cid => -1) + hosts_fix.each do |id, entry| + @db[:host_pool].where(:oid => id).update(:body => entry[:body], :cid => entry[:cid]) end - @db.fetch("SELECT oid,body FROM datastore_pool") do |row| + @db.fetch("SELECT oid,body,cid FROM datastore_pool") do |row| doc = Document.new(row[:body]) cluster_id = doc.root.get_text('CLUSTER_ID').to_s.to_i + cluster_name = doc.root.get_text('CLUSTER') + + if cluster_id != row[:cid] + log_error("Datastore #{row[:oid]} is in cluster #{cluster_id}, but cid column has cluster #{row[:cid]}") + hosts_fix[row[:oid]] = {:body => row[:body], :cid => cluster_id} + end if cluster_id != -1 - if cluster[cluster_id].nil? + cluster_entry = cluster[cluster_id] + + if cluster_entry.nil? log_error("Datastore #{row[:oid]} is in cluster #{cluster_id}, but it does not exist") doc.root.each_element('CLUSTER_ID') do |e| @@ -368,16 +396,16 @@ module OneDBFsck e.text = "" end - datastores_fix[row[:oid]] = doc.to_s + datastores_fix[row[:oid]] = {:body => doc.to_s, :cid => -1} else if doc.root.get_text('TYPE').to_s != "1" - cluster[cluster_id][:datastores] << row[:oid] + cluster_entry[:datastores] << row[:oid] else - if cluster[cluster_id][:system_ds] == 0 - cluster[cluster_id][:datastores] << row[:oid] - cluster[cluster_id][:system_ds] = row[:oid] + if cluster_entry[:system_ds] == 0 + cluster_entry[:datastores] << row[:oid] + cluster_entry[:system_ds] = row[:oid] else - log_error("System Datastore #{row[:oid]} is in Cluster #{cluster_id}, but it already contains System Datastore #{cluster[cluster_id][:system_ds]}") + log_error("System Datastore #{row[:oid]} is in Cluster #{cluster_id}, but it already contains System Datastore #{cluster_entry[:system_ds]}") doc.root.each_element('CLUSTER_ID') do |e| e.text = "-1" @@ -387,25 +415,45 @@ module OneDBFsck e.text = "" end - datastores_fix[row[:oid]] = doc.to_s + datastores_fix[row[:oid]] = {:body => doc.to_s, :cid => -1} + + next end end + + if cluster_name != cluster_entry[:name] + log_error("Datastore #{row[:oid]} has a wrong name for cluster #{cluster_id}, #{cluster_name}. It will be changed to #{cluster_entry[:name]}") + + doc.root.each_element('CLUSTER') do |e| + e.text = cluster_entry[:name] + end + + datastores_fix[row[:oid]] = {:body => doc.to_s, :cid => cluster_id} + end end end end - datastores_fix.each do |id, body| - @db[:datastore_pool].where(:oid => id).update(:body => body, :cid => -1) + datastores_fix.each do |id, entry| + @db[:datastore_pool].where(:oid => id).update(:body => entry[:body], :cid => entry[:cid]) end - @db.fetch("SELECT oid,body FROM network_pool") do |row| + @db.fetch("SELECT oid,body,cid FROM network_pool") do |row| doc = Document.new(row[:body]) cluster_id = doc.root.get_text('CLUSTER_ID').to_s.to_i + cluster_name = doc.root.get_text('CLUSTER') + + if cluster_id != row[:cid] + log_error("VNet #{row[:oid]} is in cluster #{cluster_id}, but cid column has cluster #{row[:cid]}") + hosts_fix[row[:oid]] = {:body => row[:body], :cid => cluster_id} + end if cluster_id != -1 - if cluster[cluster_id].nil? + cluster_entry = cluster[cluster_id] + + if cluster_entry.nil? log_error("VNet #{row[:oid]} is in cluster #{cluster_id}, but it does not exist") doc.root.each_element('CLUSTER_ID') do |e| @@ -416,15 +464,25 @@ module OneDBFsck e.text = "" end - vnets_fix[row[:oid]] = doc.to_s + vnets_fix[row[:oid]] = {:body => doc.to_s, :cid => -1} else - cluster[cluster_id][:vnets] << row[:oid] + if cluster_name != cluster_entry[:name] + log_error("VNet #{row[:oid]} has a wrong name for cluster #{cluster_id}, #{cluster_name}. It will be changed to #{cluster_entry[:name]}") + + doc.root.each_element('CLUSTER') do |e| + e.text = cluster_entry[:name] + end + + vnets_fix[row[:oid]] = {:body => doc.to_s, :cid => -1} + end + + cluster_entry[:vnets] << row[:oid] end end end - vnets_fix.each do |id, body| - @db[:network_pool].where(:oid => id).update(:body => body, :cid => -1) + vnets_fix.each do |id, entry| + @db[:network_pool].where(:oid => id).update(:body => entry[:body], :cid => entry[:cid]) end @@ -528,35 +586,49 @@ module OneDBFsck datastore = {} - @db.fetch("SELECT oid FROM datastore_pool") do |row| - datastore[row[:oid]] = [] + @db.fetch("SELECT oid, name FROM datastore_pool") do |row| + datastore[row[:oid]] = {:name => row[:name], :images => []} end - images_fix = {} + ds_1_name = datastore[1][:name] + images_fix = {} @db.fetch("SELECT oid,body FROM image_pool") do |row| doc = Document.new(row[:body]) ds_id = doc.root.get_text('DATASTORE_ID').to_s.to_i + ds_name = doc.root.get_text('DATASTORE') if ds_id != -1 - if datastore[ds_id].nil? - log_error("Image #{row[:oid]} has datastore #{ds_id}, but it does not exist. It will be moved to the Datastore default (1), but it is probably unusable anymore") + ds_entry = datastore[ds_id] + + if ds_entry.nil? + log_error("Image #{row[:oid]} has datastore #{ds_id}, but it does not exist. It will be moved to the Datastore #{ds_1_name} (1), but it is probably unusable anymore") doc.root.each_element('DATASTORE_ID') do |e| e.text = "1" end doc.root.each_element('DATASTORE') do |e| - e.text = "default" + e.text = ds_1_name end images_fix[row[:oid]] = doc.to_s - datastore[1] << row[:oid] + datastore[1][:images] << row[:oid] else - datastore[ds_id] << row[:oid] + if ds_name != ds_entry[:name] + log_error("Image #{row[:oid]} has a wrong name for datastore #{ds_id}, #{ds_name}. It will be changed to #{ds_entry[:name]}") + + doc.root.each_element('DATASTORE') do |e| + e.text = ds_entry[:name] + end + + images_fix[row[:oid]] = doc.to_s + end + + ds_entry[:images] << row[:oid] end end end @@ -576,7 +648,7 @@ module OneDBFsck images_new_elem = doc.root.add_element("IMAGES") - datastore[ds_id].each do |id| + datastore[ds_id][:images].each do |id| id_elem = images_elem.elements.delete("ID[.=#{id}]") if id_elem.nil? @@ -611,8 +683,9 @@ module OneDBFsck counters[:vnet] = {} # Initialize all the host counters to 0 - @db.fetch("SELECT oid FROM host_pool") do |row| + @db.fetch("SELECT oid, name FROM host_pool") do |row| counters[:host][row[:oid]] = { + :name => row[:name], :memory => 0, :cpu => 0, :rvms => Set.new @@ -655,6 +728,8 @@ module OneDBFsck } end + vms_fix = {} + # Aggregate information of the RUNNING vms @db.fetch("SELECT oid,body FROM vm_pool WHERE state<>6") do |row| vm_doc = Document.new(row[:body]) @@ -713,21 +788,41 @@ module OneDBFsck cpu = e.text.to_f } - # Get hostid + # Get hostid, hostname hid = -1 vm_doc.root.each_element("HISTORY_RECORDS/HISTORY[last()]/HID") { |e| hid = e.text.to_i } - if counters[:host][hid].nil? + hostname = "" + vm_doc.root.each_element("HISTORY_RECORDS/HISTORY[last()]/HOSTNAME") { |e| + hostname = e.text + } + + counters_host = counters[:host][hid] + + if counters_host.nil? log_error("VM #{row[:oid]} is using Host #{hid}, but it does not exist") else - counters[:host][hid][:memory] += memory - counters[:host][hid][:cpu] += cpu - counters[:host][hid][:rvms].add(row[:oid]) + if counters_host[:name] != hostname + log_error("VM #{row[:oid]} has a wrong hostname for Host #{hid}, #{hostname}. It will be changed to #{counters_host[:name]}") + + vm_doc.root.each_element("HISTORY_RECORDS/HISTORY[last()]/HOSTNAME") { |e| + e.text = counters_host[:name] + } + + vms_fix[row[:oid]] = vm_doc.to_s + end + + counters_host[:memory] += memory + counters_host[:cpu] += cpu + counters_host[:rvms].add(row[:oid]) end end + vms_fix.each do |id, body| + @db[:vm_pool].where(:oid => id).update(:body => body) + end ######################################################################## @@ -752,9 +847,11 @@ module OneDBFsck hid = row[:oid] - rvms = counters[:host][hid][:rvms].size - cpu_usage = (counters[:host][hid][:cpu]*100).to_i - mem_usage = counters[:host][hid][:memory]*1024 + counters_host = counters[:host][hid] + + rvms = counters_host[:rvms].size + cpu_usage = (counters_host[:cpu]*100).to_i + mem_usage = counters_host[:memory]*1024 # rewrite running_vms host_doc.root.each_element("HOST_SHARE/RUNNING_VMS") {|e| @@ -770,7 +867,7 @@ module OneDBFsck vms_new_elem = host_doc.root.add_element("VMS") - counters[:host][hid][:rvms].each do |id| + counters_host[:rvms].each do |id| id_elem = vms_elem.elements.delete("ID[.=#{id}]") if id_elem.nil? From 30753069152dd7a170b9e9bdddcfc7d1306da2c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Tue, 3 Sep 2013 16:09:15 +0200 Subject: [PATCH 07/30] Bug #2300: Fix users column in onegroup list --- src/cli/one_helper/onegroup_helper.rb | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/cli/one_helper/onegroup_helper.rb b/src/cli/one_helper/onegroup_helper.rb index 5f4e93573f..f072a15462 100644 --- a/src/cli/one_helper/onegroup_helper.rb +++ b/src/cli/one_helper/onegroup_helper.rb @@ -61,10 +61,15 @@ class OneGroupHelper < OpenNebulaHelper::OneHelper end column :USERS, "Number of Users in this group", :size=>5 do |d| - if d["USERS"]["ID"].nil? - "0" + ids = d["USERS"]["ID"] + + case ids + when String + "1" + when Array + ids.size else - d["USERS"]["ID"].size + "0" end end From b00f9e9c34a5c80083c2f4891c137e896518d123 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Tue, 3 Sep 2013 17:32:23 +0200 Subject: [PATCH 08/30] Bug #2295: Show hostname for VMs in poweroff --- src/sunstone/public/js/plugins/vms-tab.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sunstone/public/js/plugins/vms-tab.js b/src/sunstone/public/js/plugins/vms-tab.js index 4c031c1ab4..10e9490ab0 100644 --- a/src/sunstone/public/js/plugins/vms-tab.js +++ b/src/sunstone/public/js/plugins/vms-tab.js @@ -1092,7 +1092,7 @@ function vMachineElementArray(vm_json){ var state = OpenNebula.Helper.resource_state("vm",vm.STATE); var hostname = "--"; - if (state == tr("ACTIVE") || state == tr("SUSPENDED")){ + if (state == tr("ACTIVE") || state == tr("SUSPENDED") || state == tr("POWEROFF")){ if (vm.HISTORY_RECORDS.HISTORY.constructor == Array){ hostname = vm.HISTORY_RECORDS.HISTORY[vm.HISTORY_RECORDS.HISTORY.length-1].HOSTNAME; } else { @@ -1392,7 +1392,7 @@ function updateVMInfo(request,vm){ var vm_info = vm.VM; var vm_state = OpenNebula.Helper.resource_state("vm",vm_info.STATE); var hostname = "--" - if (vm_state == tr("ACTIVE") || vm_state == tr("SUSPENDED")) { + if (vm_state == tr("ACTIVE") || vm_state == tr("SUSPENDED") || vm_state == tr("POWEROFF")) { if (vm_info.HISTORY_RECORDS.HISTORY.constructor == Array){ hostname = vm_info.HISTORY_RECORDS.HISTORY[vm_info.HISTORY_RECORDS.HISTORY.length-1].HOSTNAME } else { From c7bb778c56726d413f61c9aee62812521b3e87b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Wed, 4 Sep 2013 16:21:34 +0200 Subject: [PATCH 09/30] Feature #1742: Add secondary groups to sunstone user tab --- src/sunstone/etc/sunstone-views/admin.yaml | 2 + src/sunstone/etc/sunstone-views/cloud.yaml | 2 + src/sunstone/etc/sunstone-views/user.yaml | 2 + src/sunstone/etc/sunstone-views/vdcadmin.yaml | 2 + src/sunstone/public/js/opennebula.js | 21 +++++----- src/sunstone/public/js/plugins/users-tab.js | 42 ++++++++++++++++++- 6 files changed, 59 insertions(+), 12 deletions(-) diff --git a/src/sunstone/etc/sunstone-views/admin.yaml b/src/sunstone/etc/sunstone-views/admin.yaml index 4d4fc77898..3f6286503c 100644 --- a/src/sunstone/etc/sunstone-views/admin.yaml +++ b/src/sunstone/etc/sunstone-views/admin.yaml @@ -54,6 +54,8 @@ tabs: User.update_password: true User.quotas_dialog: true User.chgrp: true + User.addgroup: true + User.delgroup: true User.chauth: true User.delete: true groups-tab: diff --git a/src/sunstone/etc/sunstone-views/cloud.yaml b/src/sunstone/etc/sunstone-views/cloud.yaml index 1e5bf5b7f0..7f43dfd8d1 100644 --- a/src/sunstone/etc/sunstone-views/cloud.yaml +++ b/src/sunstone/etc/sunstone-views/cloud.yaml @@ -55,6 +55,8 @@ tabs: User.update_password: true User.quotas_dialog: true User.chgrp: true + User.addgroup: true + User.delgroup: true User.chauth: true User.delete: true groups-tab: diff --git a/src/sunstone/etc/sunstone-views/user.yaml b/src/sunstone/etc/sunstone-views/user.yaml index f3c5175274..e6dd473d01 100644 --- a/src/sunstone/etc/sunstone-views/user.yaml +++ b/src/sunstone/etc/sunstone-views/user.yaml @@ -55,6 +55,8 @@ tabs: User.update_password: true User.quotas_dialog: true User.chgrp: true + User.addgroup: true + User.delgroup: true User.chauth: true User.delete: true groups-tab: diff --git a/src/sunstone/etc/sunstone-views/vdcadmin.yaml b/src/sunstone/etc/sunstone-views/vdcadmin.yaml index dccafc9e96..3fea87e030 100644 --- a/src/sunstone/etc/sunstone-views/vdcadmin.yaml +++ b/src/sunstone/etc/sunstone-views/vdcadmin.yaml @@ -55,6 +55,8 @@ tabs: User.update_password: true User.quotas_dialog: true User.chgrp: true + User.addgroup: true + User.delgroup: true User.chauth: true User.delete: true groups-tab: diff --git a/src/sunstone/public/js/opennebula.js b/src/sunstone/public/js/opennebula.js index 878e005170..bfab475816 100644 --- a/src/sunstone/public/js/opennebula.js +++ b/src/sunstone/public/js/opennebula.js @@ -936,18 +936,17 @@ var OpenNebula = { "set_quota" : function(params){ var action_obj = { quotas : params.data.extra_param }; OpenNebula.Action.simple_action(params,OpenNebula.User.resource,"set_quota",action_obj); + }, + "addgroup" : function(params){ + var action_obj = {"group_id": params.data.extra_param }; + OpenNebula.Action.simple_action(params,OpenNebula.User.resource, + "addgroup",action_obj); + }, + "delgroup" : function(params){ + var action_obj = {"group_id": params.data.extra_param }; + OpenNebula.Action.simple_action(params,OpenNebula.User.resource, + "delgroup",action_obj); } - - // "addgroup" : function(params){ - // var action_obj = {"group_id": params.data.extra_param }; - // OpenNebula.Action.simple_action(params,OpenNebula.User.resource, - // "addgroup",action_obj); - // }, - // "delgroup" : function(params){ - // var action_obj = {"group_id": params.data.extra_param }; - // OpenNebula.Action.simple_action(params,OpenNebula.User.resource, - // "delgroup",action_obj); - // } }, "Image": { diff --git a/src/sunstone/public/js/plugins/users-tab.js b/src/sunstone/public/js/plugins/users-tab.js index cac9a55453..8fdf5ea272 100644 --- a/src/sunstone/public/js/plugins/users-tab.js +++ b/src/sunstone/public/js/plugins/users-tab.js @@ -427,7 +427,26 @@ var user_actions = { error: onError, notify: true }, - + "User.addgroup" : { + type: "multiple", + call: OpenNebula.User.addgroup, + callback : function(req){ + Sunstone.runAction("User.show",req.request.data[0][0]); + }, + elements : userElements, + error: onError, + notify: true + }, + "User.delgroup" : { + type: "multiple", + call: OpenNebula.User.delgroup, + callback : function(req){ + Sunstone.runAction("User.show",req.request.data[0][0]); + }, + elements : userElements, + error: onError, + notify: true + }, "User.change_authentication" : { type: "custom", call: popUpChangeAuthenticationDialog @@ -561,6 +580,22 @@ var user_buttons = { tip: tr("This will change the main group of the selected users. Select the new group")+":", condition: mustBeAdmin }, + "User.addgroup" : { + type: "confirm_with_select", + text: tr("Add to group"), + layout: "user_select", + select: groups_sel, + tip: tr("This will add the user to a secondary group. Select the new group")+":", + condition: mustBeAdmin + }, + "User.delgroup" : { + type: "confirm_with_select", + text: tr("Remove from group"), + layout: "user_select", + select: groups_sel, + tip: tr("This will remove the user from a secondary group. Select the group")+":", + condition: mustBeAdmin + }, "User.delete" : { type: "confirm", text: tr("Delete"), @@ -722,6 +757,11 @@ function updateUserInfo(request,user){ ' + insert_group_dropdown("User",info.ID,info.GNAME,info.GID) + '\ + \ + ' + tr("Secondary groups") + '\ + '+(typeof info.GROUPS.ID == "object" ? info.GROUPS.ID.join(",") : "-")+'\ + \ + \ \ ' + tr("Authentication driver") + '\ '+info.AUTH_DRIVER+'\ From 7be821b342184b93af6a84e76191bd9d5d61b266 Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Wed, 4 Sep 2013 17:13:11 +0200 Subject: [PATCH 10/30] bug #2294: install nokogiri < 1.6.0 for ruby < 1.9 in install_gems --- share/install_gems/install_gems | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/share/install_gems/install_gems b/share/install_gems/install_gems index 053a68f670..e435212e33 100755 --- a/share/install_gems/install_gems +++ b/share/install_gems/install_gems @@ -2,7 +2,6 @@ require 'pp' -$nokogiri='nokogiri' DEFAULT=%w{sunstone quota cloud ozones_server auth_ldap vmware oneflow} @@ -12,6 +11,12 @@ else SQLITE='sqlite3-ruby --version 1.2.0' end +if !defined?(RUBY_VERSION) || RUBY_VERSION < '1.9.0' + $nokogiri='nokogiri --version "< 1.6.0"' +else + $nokogiri='nokogiri' +end + GROUPS={ :quota => [SQLITE, 'sequel'], :sunstone => ['json', 'rack', 'sinatra', 'thin', SQLITE], @@ -41,7 +46,7 @@ DISTRIBUTIONS={ SQLITE => ['gcc', 'libsqlite3-dev'], 'mysql' => ['gcc', 'libmysqlclient-dev'], 'curb' => ['gcc', 'libcurl4-openssl-dev'], - 'nokogiri' => %w{gcc rake libxml2-dev libxslt1-dev}, + $nokogiri => %w{gcc rake libxml2-dev libxslt1-dev}, 'xmlparser' => ['gcc', 'libexpat1-dev'], 'thin' => ['g++'], 'json' => ['gcc'] @@ -58,7 +63,7 @@ DISTRIBUTIONS={ SQLITE => ['gcc', 'sqlite-devel'], 'mysql' => ['gcc', 'mysql-devel'], 'curb' => ['gcc', 'curl-devel'], - 'nokogiri' => %w{gcc rubygem-rake libxml2-devel libxslt-devel}, + $nokogiri => %w{gcc rubygem-rake libxml2-devel libxslt-devel}, 'xmlparser' => ['gcc', 'expat-devel'], 'thin' => ['gcc-c++'], 'json' => ['gcc'] @@ -72,7 +77,7 @@ DISTRIBUTIONS={ SQLITE => ['gcc', 'sqlite3-devel'], 'mysql' => ['gcc', 'libmysqlclient-devel'], 'curb' => ['gcc', 'libcurl-devel'], - 'nokogiri' => %w{rubygem-rake gcc rubygem-rake libxml2-devel libxslt-devel}, + $nokogiri => %w{rubygem-rake gcc rubygem-rake libxml2-devel libxslt-devel}, 'xmlparser' => ['gcc', 'libexpat-devel'], 'thin' => ['rubygem-rake', 'gcc-c++'], 'json' => ['gcc'] From 33579df771a44318bc60bde78b302b1d339733d3 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Wed, 4 Sep 2013 18:43:23 +0200 Subject: [PATCH 11/30] feature #1713: Deal with concurrent renames --- include/RequestManagerRename.h | 73 +++++++++++++++++++------ src/rm/RequestManagerRename.cc | 97 ++++++++++++---------------------- 2 files changed, 91 insertions(+), 79 deletions(-) diff --git a/include/RequestManagerRename.h b/include/RequestManagerRename.h index ecd470b053..9e9dcf362a 100644 --- a/include/RequestManagerRename.h +++ b/include/RequestManagerRename.h @@ -34,6 +34,8 @@ protected: const string& params = "A:sis") :Request(method_name,params,help) { + pthread_mutex_init(&mutex, 0); + auth_op = AuthRequest::MANAGE; }; @@ -44,9 +46,60 @@ protected: void request_execute(xmlrpc_c::paramList const& _paramList, RequestAttributes& att); - virtual PoolObjectSQL * get(const string& name, int uid, bool lock) = 0; + /** + * Gets and object by name and owner. Default implementation returns no + * object + */ + virtual PoolObjectSQL * get(const string& name, int uid, bool lock) + { + return 0; + } + + /** + * Batch rename of related objects. Default implementation does nothing + */ + virtual void batch_rename(int oid){}; + + /** + * Test if a rename is being perform on a given object. If not it set it. + * @return true if the rename can be performed (no ongoing rename) + */ + bool test_and_set_rename(int oid) + { + pair::iterator,bool> rc; + + pthread_mutex_lock(&mutex); + + rc = rename_ids.insert(oid); + + pthread_mutex_unlock(&mutex); + + return rc.second == true; + } + + /** + * Clear the rename. + */ + void clear_rename(int oid) + { + pthread_mutex_lock(&mutex); + + rename_ids.erase(oid); + + pthread_mutex_unlock(&mutex); + } + +private: + /** + * Mutex to control concurrent access to the ongoing rename operations + */ + pthread_mutex_t mutex; + + /** + * Set of IDs being renamed; + */ + set rename_ids; - virtual void post_execute(int oid){}; }; /* ------------------------------------------------------------------------- */ @@ -64,11 +117,6 @@ public: }; ~VirtualMachineRename(){}; - - PoolObjectSQL * get(const string& name, int uid, bool lock) - { - return 0; - }; }; /* ------------------------------------------------------------------------- */ @@ -154,11 +202,6 @@ public: }; ~DocumentRename(){}; - - PoolObjectSQL * get(const string& name, int uid, bool lock) - { - return 0; - }; }; /* ------------------------------------------------------------------------- */ @@ -182,7 +225,7 @@ public: return static_cast(pool)->get(name, lock); }; - void post_execute(int oid); + void batch_rename(int oid); }; /* ------------------------------------------------------------------------- */ @@ -206,7 +249,7 @@ public: return static_cast(pool)->get(name, lock); }; - void post_execute(int oid); + void batch_rename(int oid); }; /* ------------------------------------------------------------------------- */ @@ -230,7 +273,7 @@ public: return static_cast(pool)->get(name, lock); }; - void post_execute(int oid); + void batch_rename(int oid); }; /* -------------------------------------------------------------------------- */ diff --git a/src/rm/RequestManagerRename.cc b/src/rm/RequestManagerRename.cc index e4616c6c0f..0685f3fa75 100644 --- a/src/rm/RequestManagerRename.cc +++ b/src/rm/RequestManagerRename.cc @@ -36,16 +36,27 @@ void RequestManagerRename::request_execute(xmlrpc_c::paramList const& paramList, PoolObjectAuth operms; PoolObjectSQL * object; + if (test_and_set_rename(oid) == false) + { + failure_response(INTERNAL, + request_error("Object is being renamed", ""), att); + + return; + } + rc = get_info(pool, oid, auth_object, att, operms, old_name); if ( rc == -1 ) { + clear_rename(oid); return; } if (old_name == new_name) { success_response(oid, att); + + clear_rename(oid); return; } @@ -62,12 +73,12 @@ void RequestManagerRename::request_execute(xmlrpc_c::paramList const& paramList, failure_response(AUTHORIZATION, authorization_error(ar.message, att), att); - + clear_rename(oid); return; } } - // --------------- Check name uniqueness ----------------------------------- + // ----------------------- Check name uniqueness --------------------------- object = get(new_name, operms.uid, true); @@ -85,10 +96,12 @@ void RequestManagerRename::request_execute(xmlrpc_c::paramList const& paramList, << id; failure_response(ACTION, request_error(oss.str(), ""), att); + + clear_rename(oid); return; } - // --------------- Update the object --------------------------------------- + // -------------------------- Update the object ---------------------------- object = pool->get(oid, true); @@ -97,6 +110,9 @@ void RequestManagerRename::request_execute(xmlrpc_c::paramList const& paramList, failure_response(NO_EXISTS, get_error(object_name(auth_object), oid), att); + + clear_rename(oid); + return; } if ( object->set_name(new_name, error_str) != 0 ) @@ -104,6 +120,8 @@ void RequestManagerRename::request_execute(xmlrpc_c::paramList const& paramList, object->unlock(); failure_response(ACTION, request_error(error_str, ""), att); + + clear_rename(oid); return; } @@ -113,23 +131,25 @@ void RequestManagerRename::request_execute(xmlrpc_c::paramList const& paramList, pool->update_cache_index(old_name, operms.uid, new_name, operms.uid); - post_execute(oid); + batch_rename(oid); success_response(oid, att); + clear_rename(oid); + return; } /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -void * cluster_rename_loop(void *arg) +void ClusterRename::batch_rename(int oid) { - Cluster * cluster = static_cast(arg); + Cluster * cluster = static_cast(pool)->get(oid, true); if (cluster == 0) { - return 0; + return; } const set & hosts = cluster->get_host_ids(); @@ -138,7 +158,6 @@ void * cluster_rename_loop(void *arg) set::iterator it; - int oid = cluster->get_oid(); string cluster_name = cluster->get_name(); cluster->unlock(); @@ -199,41 +218,24 @@ void * cluster_rename_loop(void *arg) vnet->unlock(); } } - - return 0; -} - -void ClusterRename::post_execute(int oid) -{ - pthread_t pthread; - - pthread_attr_t pattr; - - pthread_attr_init (&pattr); - pthread_attr_setdetachstate (&pattr, PTHREAD_CREATE_DETACHED); - - Cluster * cluster = static_cast(pool)->get(oid, true); - - pthread_create(&pthread, &pattr, cluster_rename_loop, (void *) cluster); } /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -void * ds_rename_loop(void *arg) +void DatastoreRename::batch_rename(int oid) { - Datastore * datastore = static_cast(arg); + Datastore * datastore = static_cast(pool)->get(oid, true); if (datastore == 0) { - return 0; + return; } const set & images = datastore->get_image_ids(); set::iterator it; - int oid = datastore->get_oid(); string image_name = datastore->get_name(); datastore->unlock(); @@ -256,41 +258,24 @@ void * ds_rename_loop(void *arg) image->unlock(); } } - - return 0; -} - -void DatastoreRename::post_execute(int oid) -{ - pthread_t pthread; - - pthread_attr_t pattr; - - pthread_attr_init (&pattr); - pthread_attr_setdetachstate (&pattr, PTHREAD_CREATE_DETACHED); - - Datastore * datastore = static_cast(pool)->get(oid, true); - - pthread_create(&pthread, &pattr, ds_rename_loop, (void *) datastore); } /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -void * host_rename_loop(void *arg) +void HostRename::batch_rename(int oid) { - Host * host = static_cast(arg); + Host * host = static_cast(pool)->get(oid, true); if (host == 0) { - return 0; + return; } const set & vms = host->get_vm_ids(); set::iterator it; - int oid = host->get_oid(); string host_name = host->get_name(); host->unlock(); @@ -313,22 +298,6 @@ void * host_rename_loop(void *arg) vm->unlock(); } } - - return 0; -} - -void HostRename::post_execute(int oid) -{ - pthread_t pthread; - - pthread_attr_t pattr; - - pthread_attr_init (&pattr); - pthread_attr_setdetachstate (&pattr, PTHREAD_CREATE_DETACHED); - - Host * host = static_cast(pool)->get(oid, true); - - pthread_create(&pthread, &pattr, host_rename_loop, (void *) host); } /* -------------------------------------------------------------------------- */ From cb070444c7ca7be4742b4f77808bee935df65f16 Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Thu, 5 Sep 2013 17:42:55 +0200 Subject: [PATCH 12/30] feature #2187: add files_ds and init options to CLI template creation --- src/cli/one_helper.rb | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/cli/one_helper.rb b/src/cli/one_helper.rb index be3e96dc01..7c91853407 100644 --- a/src/cli/one_helper.rb +++ b/src/cli/one_helper.rb @@ -248,6 +248,19 @@ EOT :large => '--boot device', :description => 'Select boot device (hd|fd|cdrom|network)', :format => String + }, + { + :name => 'files_ds', + :large => '--files_ds file1,file2', + :format => Array, + :description => 'Add files to the contextualization CD from the' << + 'files datastore' + }, + { + :name => 'init', + :large => '--init script1,script2', + :format => Array, + :description => 'Script or scripts to start in context' } ] @@ -774,7 +787,8 @@ EOT end def self.create_context(options) - if !(options.keys & [:ssh, :net_context, :context]).empty? + context_options = [:ssh, :net_context, :context, :init, :files_ds] + if !(options.keys & context_options).empty? lines=[] if options[:ssh] @@ -792,11 +806,21 @@ EOT end if options[:net_context] - lines << "NETWORK = \"YES\"" + lines << "NETWORK = \"YES\"" end lines+=options[:context] if options[:context] + if options[:files_ds] + options[:files_ds].each do |file| + lines << %Q + end + end + + if options[:init] + lines << %Q + end + if !lines.empty? "CONTEXT=[\n"< Date: Thu, 5 Sep 2013 18:27:04 +0200 Subject: [PATCH 13/30] Feature #1742: Add secondary groups to sunstone config tab --- src/sunstone/public/js/plugins/config-tab.js | 152 +++++++++++++++---- 1 file changed, 121 insertions(+), 31 deletions(-) diff --git a/src/sunstone/public/js/plugins/config-tab.js b/src/sunstone/public/js/plugins/config-tab.js index 9a749b11af..845bc93e12 100644 --- a/src/sunstone/public/js/plugins/config-tab.js +++ b/src/sunstone/public/js/plugins/config-tab.js @@ -94,7 +94,7 @@ var config_tab_content =
\ \ \ - \ + \ \ \ \ @@ -153,7 +153,18 @@ var config_tab_content = \
    \
  • \ -
  • \ +
  • \ +
    \ +
    \ + \ +
    \ +
    \ + \ +
    \ +
    \ +
    \ +
  • \
\ \ \ @@ -202,12 +213,7 @@ Sunstone.addActions({ call: OpenNebula.User.update, callback: function(request) { notifyMessage(tr("Template updated correctly")); - OpenNebula.User.show({ - data : { - id: "-1" - }, - success: updateUserConfigInfo - }); + fillUserInfo(); }, error: onError }, @@ -307,6 +313,16 @@ function setupConfigDialog() { } }) }); + + $("#quota_group_sel").die(); + + $("#quota_group_sel").live("change", function() { + var value_str = $('select#quota_group_sel').val(); + if(value_str!="") + { + fillGroupQuotas(value_str) + } + }); } function tr(str){ @@ -333,23 +349,32 @@ function updateUserConfigInfo(request,user_json) { $("#user_information tbody").html('\ \ - \ + \ \ \ \ - \ + \ \ \ \ - \ + \ \ \ - \ - \ + \ + \ + \ + \ + \ + \ + \ \ \ \ - \ + \ ') $("#setting_user_template").html( @@ -358,28 +383,57 @@ function updateUserConfigInfo(request,user_json) { "-1", tr("Custom Attributes")) ) + + $("#div_edit_chg_group_link").die(); + $("#group_confirm_select").die(); + + // Listener for key,value pair edit action + $("#div_edit_chg_group_link").live("click", function() { + // TODO: do not call group.list again, use the callback from + // $("span.user-login a.configuration").click + OpenNebula.Group.list( + { + success: function(request, group_list) { + var value_str = $(".value_td_group").text(); + var select_str='"; + $(".value_td_group").html(select_str); + $("select#group_confirm_select").val(info.GID); + }, + error: onError + }) + }); + + $("#group_confirm_select").live("change", function() { + var value_str = $('select#group_confirm_select').val(); + if(value_str!="") + { + // Let OpenNebula know + var resource_struct = new Array(); + resource_struct[0] = info.ID; + Sunstone.runAction("User.chgrp",resource_struct,value_str); + fillUserInfo(); + } + }); } -$(document).ready(function(){ - setupConfigDialog(); - setupUpdatePassword(); - - $("span.user-login a.configuration").click(function(){ - OpenNebula.User.show({ - data : { - id: '-1' - }, - success: updateUserConfigInfo - }); - +function fillGroupQuotas(group_id){ OpenNebula.Group.show({ data : { - id: '-1' + id: group_id }, success: function(request,group_json){ var info = group_json.GROUP; - var default_group_quotas = Quotas.default_quotas(info.DEFAULT_GROUP_QUOTAS) + var default_group_quotas = Quotas.default_quotas(info.DEFAULT_GROUP_QUOTAS); + var quotas_tab_html = Quotas.vms(info, default_group_quotas); quotas_tab_html += Quotas.cpu(info, default_group_quotas); quotas_tab_html += Quotas.memory(info, default_group_quotas); @@ -387,10 +441,46 @@ $(document).ready(function(){ quotas_tab_html += Quotas.network(info, default_group_quotas); quotas_tab_html += Quotas.datastore(info, default_group_quotas); - $("#group_quotasTab").html(quotas_tab_html); + $("#group_quotasTabBody").html(quotas_tab_html); + + $("select#quota_group_sel").val(info.ID); } }); +} - $config_dialog.reveal(); - }); +function fillUserInfo(){ + OpenNebula.User.show({ + data : { + id: '-1' + }, + success: updateUserConfigInfo + }); +} + +$(document).ready(function(){ + setupConfigDialog(); + setupUpdatePassword(); + + $("span.user-login a.configuration").click(function(){ + fillUserInfo(); + + OpenNebula.Group.list( + { + success: function(request, group_list) { + var group_dropdown_options = ""; + $.each(group_list,function(){ + group_dropdown_options += + ''; + }); + + $('select#quota_group_sel', $config_dialog).html(group_dropdown_options); + + fillGroupQuotas('-1'); + } + }); + + $config_dialog.reveal(); + }); }); \ No newline at end of file From cd1964ea7a5c3adad53d3c89d1744edd3f7d87e4 Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Fri, 6 Sep 2013 16:20:16 +0200 Subject: [PATCH 14/30] feature #2187: change separator of INIT_SCRIPTS to space --- src/cli/one_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cli/one_helper.rb b/src/cli/one_helper.rb index 7c91853407..d73d6fbe1c 100644 --- a/src/cli/one_helper.rb +++ b/src/cli/one_helper.rb @@ -818,7 +818,7 @@ EOT end if options[:init] - lines << %Q + lines << %Q end if !lines.empty? From 4d95677c48950235ebd8004acf8892bc48ce9824 Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Fri, 6 Sep 2013 16:40:26 +0200 Subject: [PATCH 15/30] feature #2187: fix FILES_DS generation from CLI --- src/cli/one_helper.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/cli/one_helper.rb b/src/cli/one_helper.rb index d73d6fbe1c..d153dc70b9 100644 --- a/src/cli/one_helper.rb +++ b/src/cli/one_helper.rb @@ -812,9 +812,13 @@ EOT lines+=options[:context] if options[:context] if options[:files_ds] - options[:files_ds].each do |file| - lines << %Q - end + text='FILES_DS="' + text << options[:files_ds].map do |file| + %Q<$FILE[IMAGE=\\"#{file}\\"]> + end.join(' ') + text << '"' + + lines << text end if options[:init] From 59a5bc8d63e25dabddc1879908c8ee0ae8268fb3 Mon Sep 17 00:00:00 2001 From: Daniel Molina Date: Fri, 6 Sep 2013 16:59:29 +0200 Subject: [PATCH 16/30] feature #2187: Add INIT_SCRIPTS to Sunstone --- .../public/js/plugins/templates-tab.js | 28 ++++++++++++++----- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/src/sunstone/public/js/plugins/templates-tab.js b/src/sunstone/public/js/plugins/templates-tab.js index da15d5219c..efb08601e0 100644 --- a/src/sunstone/public/js/plugins/templates-tab.js +++ b/src/sunstone/public/js/plugins/templates-tab.js @@ -2865,7 +2865,7 @@ function setupCreateTemplateDialog(){ } }); - + $("#refresh_ramdisk_table").die(); $("#refresh_ramdisk_table").live('click', function(){ @@ -3178,16 +3178,27 @@ function setupCreateTemplateDialog(){ ''+ '
'+ '
'+ - '
'+ + '
'+ ''+ '
'+ - '
'+ + '
'+ ''+ '
'+ - '
'+ + '
'+ '
'+ '
'+ '
'+ + '
'+ + '
'+ + ''+ + '
'+ + '
'+ + ''+ + '
'+ + '
'+ + '
'+tr("If the VM uses the OpenNebula contextualization package the init.sh file is executed by default. When the init script added is not called init.sh or more than one init script is added, this list contains the scripts to run and the order. Ex. “init.sh users.sh mysql.sh”")+'
'+ + '
'+ + '
'+ ''+ '
  • '+ '
    '+ @@ -3287,7 +3298,7 @@ function setupCreateTemplateDialog(){ } }); - + $("#refresh_context_table").die(); $("#refresh_context_table").live('click', function(){ @@ -4601,6 +4612,9 @@ function fillTemplatePopUp(request, response){ else if (net_regexp.test(key)) { $("#network_context", context_section).attr('checked','checked'); } + else if ("INIT_SCRIPTS" == key){ + $("input#INIT_SCRIPTS").val(value); + } else if ("FILES_DS" == key){ $('#FILES_DS', context_section).val(context["FILES_DS"]) var files = []; @@ -5034,7 +5048,7 @@ function setupInstantiateTemplateDialog(easy_provision){ dialog.addClass("reveal-modal large"); dialog.removeClass("max-height") } - + setupTips(dialog); @@ -5071,7 +5085,7 @@ function setupInstantiateTemplateDialog(easy_provision){ 'image_id': image_id } } - } + } if (!vm_name.length){ //empty name use OpenNebula core default for (var i=0; i< n_times_int; i++){ From b8929650412c803463df2569b996cc2894a60b0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Fri, 6 Sep 2013 17:11:03 +0200 Subject: [PATCH 17/30] Feature #2212: IMAGE/FSTYPE and DISK/FORMAT now default to 'raw' --- src/image/Image.cc | 19 ++++++++----------- src/tm/TransferManager.cc | 11 ++++++++--- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/image/Image.cc b/src/image/Image.cc index cacc154504..5d89810b65 100644 --- a/src/image/Image.cc +++ b/src/image/Image.cc @@ -177,12 +177,17 @@ int Image::insert(SqlDB *db, string& error_str) { if ( source.empty() && path.empty() ) { + if (type != DATABLOCK) + { + goto error_no_path; + } + erase_template_attribute("FSTYPE", fs_type); // DATABLOCK image needs FSTYPE - if (type != DATABLOCK || fs_type.empty()) + if (fs_type.empty()) { - goto error_no_path; + fs_type = "raw"; } } else if ( !source.empty() && !path.empty() ) @@ -210,15 +215,7 @@ error_type: goto error_common; error_no_path: - if ( type == DATABLOCK ) - { - error_str = "A DATABLOCK type IMAGE has to declare a PATH, or both " - "SIZE and FSTYPE."; - } - else - { - error_str = "No PATH in template."; - } + error_str = "No PATH in template."; goto error_common; error_path_and_source: diff --git a/src/tm/TransferManager.cc b/src/tm/TransferManager.cc index 859876f18f..20c627d1ab 100644 --- a/src/tm/TransferManager.cc +++ b/src/tm/TransferManager.cc @@ -284,10 +284,15 @@ int TransferManager::prolog_transfer_command( size = disk->vector_value("SIZE"); format = disk->vector_value("FORMAT"); - if ( size.empty() || format.empty() ) + if (format.empty()) { - os << "No size or format in FS"; - vm->log("TM", Log::WARNING, "No size or format in FS, skipping"); + format = "raw"; + } + + if ( size.empty() ) + { + os << "No size in FS"; + vm->log("TM", Log::WARNING, "No size in FS, skipping"); return 0; } From 28ebcdfc089a60dd2a3e8ef42aa75afe17ca9678 Mon Sep 17 00:00:00 2001 From: Tino Vazquez Date: Mon, 9 Sep 2013 15:15:02 +0200 Subject: [PATCH 18/30] feature #2262: Add Storage Server parameter to Ceph, iSCSI and LVM --- src/sunstone/public/js/plugins/datastores-tab.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/sunstone/public/js/plugins/datastores-tab.js b/src/sunstone/public/js/plugins/datastores-tab.js index 35729778be..e81d01b161 100644 --- a/src/sunstone/public/js/plugins/datastores-tab.js +++ b/src/sunstone/public/js/plugins/datastores-tab.js @@ -257,6 +257,7 @@ var create_datastore_tmpl = \
    \
    \ +
    '+tr("Server name or IP where OpenNebula will be staging the new images into. This server will act as the entry point for new inmages in the datastore.")+'
    \
    \
  • \
    \ @@ -865,7 +866,7 @@ function hide_all(context) $('label[for="bridge_list"],input#bridge_list',context).hide(); $('label[for="ds_use_ssh"],input#ds_use_ssh',context).hide(); $('label[for="tm_use_ssh"],input#tm_use_ssh',context).hide(); - $('label[for="host"],input#host',context).hide(); + $('label[for="host"],input#host',context).parent().parent().hide(); $('label[for="base_iqn"],input#base_iqn',context).hide(); $('label[for="vg_name"],input#vg_name',context).hide(); $('select#ds_mad').removeAttr('disabled'); @@ -959,6 +960,7 @@ function setupCreateDatastoreDialog(){ var base_iqn = $('#base_iqn',context).val(); var vg_name = $('#vg_name',context).val(); + if (!name){ notifyError("Please provide a name"); return false; @@ -1001,7 +1003,7 @@ function setupCreateDatastoreDialog(){ ds_obj.datastore.base_iqn = base_iqn; if (vg_name) - ds_obj.datastore.vg_name = vg_name; + ds_obj.datastore.vg_name = vg_name; Sunstone.runAction("Datastore.create",ds_obj); @@ -1083,7 +1085,7 @@ function select_iscsi(){ $('select#ds_mad').attr('disabled', 'disabled'); $('select#tm_mad').val('iscsi'); $('select#tm_mad').attr('disabled', 'disabled'); - $('label[for="host"],input#host').fadeIn(); + $('label[for="host"],input#host').parent().parent().fadeIn(); $('label[for="base_iqn"],input#base_iqn').fadeIn(); $('label[for="vg_name"],input#vg_name').fadeIn(); $('select#disk_type').children('option').each(function() { @@ -1102,6 +1104,7 @@ function select_ceph(){ $('select#ds_mad').attr('disabled', 'disabled'); $('select#tm_mad').val('ceph'); $('select#tm_mad').attr('disabled', 'disabled'); + $('label[for="host"],input#host').parent().parent().fadeIn(); $('select#disk_type').val('RBD'); } @@ -1110,7 +1113,7 @@ function select_lvm(){ $('select#ds_mad').attr('disabled', 'disabled'); $('select#tm_mad').val('lvm'); $('select#tm_mad').attr('disabled', 'disabled'); - $('label[for="host"],input#host').fadeIn(); + $('label[for="host"],input#host').parent().parent().fadeIn(); $('label[for="vg_name"],input#vg_name').fadeIn(); $('select#disk_type').children('option').each(function() { var value_str = $(this).val(); From 13f4ff0cdb8dbf8530283d9f31037eb1f0cccde9 Mon Sep 17 00:00:00 2001 From: atwardowski Date: Thu, 8 Aug 2013 13:44:29 -0400 Subject: [PATCH 19/30] Update OpenvSwitch.rb Block ARP cache poisoning in openvswitch --- src/vnm_mad/remotes/ovswitch/OpenvSwitch.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/vnm_mad/remotes/ovswitch/OpenvSwitch.rb b/src/vnm_mad/remotes/ovswitch/OpenvSwitch.rb index 304327d5d1..c731aee9ca 100644 --- a/src/vnm_mad/remotes/ovswitch/OpenvSwitch.rb +++ b/src/vnm_mad/remotes/ovswitch/OpenvSwitch.rb @@ -80,6 +80,8 @@ class OpenvSwitchVLAN < OpenNebulaNetwork end def mac_spoofing + add_flow("in_port=#{port},arp,dl_src=#{@nic[:mac]}",:drop,45000) + add_flow("in_port=#{port},arp,dl_src=#{@nic[:mac]},nw_src=#{@nic[:ip]}",:normal,46000) add_flow("in_port=#{port},dl_src=#{@nic[:mac]}",:normal,40000) add_flow("in_port=#{port}",:drop,39000) end From cdd10b4adfc3258eefc274f995757d53b5d973a4 Mon Sep 17 00:00:00 2001 From: Tino Vazquez Date: Mon, 9 Sep 2013 18:30:21 +0200 Subject: [PATCH 20/30] bug #2210: Add missing tooltips in VM template creation wizard --- .../public/js/plugins/templates-tab.js | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/sunstone/public/js/plugins/templates-tab.js b/src/sunstone/public/js/plugins/templates-tab.js index efb08601e0..e86150087f 100644 --- a/src/sunstone/public/js/plugins/templates-tab.js +++ b/src/sunstone/public/js/plugins/templates-tab.js @@ -195,7 +195,7 @@ var easy_provision_vm_template_tmpl ='\
    \
    \
    \ - '+tr("Step 3: Select a template")+'\ + '+tr("Step 2: Select a template")+'\
    \
    \ \ @@ -281,8 +281,7 @@ var easy_provision_vm_template_tmpl ='\ \
    \
    \ -
    \ -
    \ +
    '+tr("Identifier of the image to be used as the main disk for this Virtual Machine. This choice will select the Operating System the VM will run under.")+'
    \
    \
    \
    \ @@ -971,7 +970,7 @@ function generate_disk_tab_content(str_disk_tab_id, str_datatable_id){ ''+ '
    '+ '
    '+ - '
    '+ + '
    '+tr("Image ID to be used in the Virtual Image disk.")+ '
    '+ '
    '+ '
    '+ @@ -985,7 +984,7 @@ function generate_disk_tab_content(str_disk_tab_id, str_datatable_id){ ''+ '
    '+ '
    '+ - '
    '+ + '
    '+tr("Name of the image to be used in the Virtual Image disk.")+ '
    '+ '
    '+ '
    '+ @@ -1001,7 +1000,7 @@ function generate_disk_tab_content(str_disk_tab_id, str_datatable_id){ ''+ '
    '+ '
    '+ - '
    '+ + '
    '+tr("Identifier of the user owner of the image to reduce ambiguity.")+ '
    '+ '
    '+ '
    '+ @@ -1015,7 +1014,7 @@ function generate_disk_tab_content(str_disk_tab_id, str_datatable_id){ ''+ '
    '+ '
    '+ - '
    '+ + '
    '+tr("Name of the user owner of the image to reduce ambiguity.")+ '
    '+ '
    '+ '
    '+ @@ -1709,7 +1708,7 @@ function generate_nic_tab_content(str_nic_tab_id, str_datatable_id){ ''+ ''+ '
    '+ - '
    '+ + '
    '+tr("Identifier of the virtual network from which to lease an IP and MAC address to this Virtual Machine network interface.")+ '
    '+ '
    '+ '
    '+ @@ -1723,7 +1722,7 @@ function generate_nic_tab_content(str_nic_tab_id, str_datatable_id){ ''+ ''+ '
    '+ - '
    '+ + '
    '+tr("Name of the virtual network from which to lease an IP and MAC address to this Virtual Machine network interface.")+ '
    '+ '
    '+ '
    '+ @@ -1739,7 +1738,7 @@ function generate_nic_tab_content(str_nic_tab_id, str_datatable_id){ ''+ ''+ '
    '+ - '
    '+ + '
    '+tr("Identifier of the user owner of the virtual network from which to lease an IP and MAC address to this Virtual Machine network interface.")+ '
    '+ '
    '+ '
    '+ @@ -1753,7 +1752,7 @@ function generate_nic_tab_content(str_nic_tab_id, str_datatable_id){ ''+ ''+ '
    '+ - '
    '+ + '
    '+tr("Name of the user owner of the virtual network from which to lease an IP and MAC address to this Virtual Machine network interface.")+ '
    '+ '
    '+ '
    '+ @@ -3185,7 +3184,7 @@ function setupCreateTemplateDialog(){ ''+ ''+ '
    '+ - '
    '+ + '
    '+tr("Raw String for the FILE_DS attribute of the VM template, representing files that will be included in the contextualization image. Each file must be stored in a FILE_DS Datastore and must be of type CONTEXT")+'
    '+ '
    '+ ''+ '
    '+ From beeb642af6d736d66e553f9b9d8a38bbdaca22ad Mon Sep 17 00:00:00 2001 From: Tino Vazquez Date: Tue, 10 Sep 2013 12:00:56 +0200 Subject: [PATCH 21/30] Homogenize storage gateway host list parameter in all datastore types template This also includes Sunstone interface changes --- src/datastore_mad/remotes/ceph/cp | 8 +++-- src/datastore_mad/remotes/iscsi/cp | 8 +++-- src/datastore_mad/remotes/lvm/cp | 8 +++-- .../public/js/plugins/datastores-tab.js | 31 +++++-------------- 4 files changed, 23 insertions(+), 32 deletions(-) diff --git a/src/datastore_mad/remotes/ceph/cp b/src/datastore_mad/remotes/ceph/cp index a388c840d6..5d81aa186a 100755 --- a/src/datastore_mad/remotes/ceph/cp +++ b/src/datastore_mad/remotes/ceph/cp @@ -51,7 +51,7 @@ while IFS= read -r -d '' element; do done < <($XPATH /DS_DRIVER_ACTION_DATA/DATASTORE/BASE_PATH \ /DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/RESTRICTED_DIRS \ /DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/SAFE_DIRS \ - /DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/HOST \ + /DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/BRIDGE_LIST \ /DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/POOL_NAME \ /DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/STAGING_DIR \ /DS_DRIVER_ACTION_DATA/IMAGE/PATH \ @@ -66,7 +66,7 @@ unset i BASE_PATH="${XPATH_ELEMENTS[i++]}" RESTRICTED_DIRS="${XPATH_ELEMENTS[i++]}" SAFE_DIRS="${XPATH_ELEMENTS[i++]}" -DST_HOST="${XPATH_ELEMENTS[i++]}" +BRIDGE_LIST="${XPATH_ELEMENTS[i++]}" POOL_NAME="${XPATH_ELEMENTS[i++]:-$POOL_NAME}" STAGING_DIR="${XPATH_ELEMENTS[i++]:-$STAGING_DIR}" SRC="${XPATH_ELEMENTS[i++]}" @@ -76,8 +76,10 @@ SHA1="${XPATH_ELEMENTS[i++]}" NO_DECOMPRESS="${XPATH_ELEMENTS[i++]}" LIMIT_TRANSFER_BW="${XPATH_ELEMENTS[i++]}" +DST_HOST=`get_destination_host $IMAGE_ID` + if [ -z "$DST_HOST" ]; then - error_message "Datastore template missing 'HOST' attribute." + error_message "Datastore template missing 'BRIDGE_LIST' attribute." exit -1 fi diff --git a/src/datastore_mad/remotes/iscsi/cp b/src/datastore_mad/remotes/iscsi/cp index dfaec846a6..9f8587abc6 100755 --- a/src/datastore_mad/remotes/iscsi/cp +++ b/src/datastore_mad/remotes/iscsi/cp @@ -51,7 +51,7 @@ while IFS= read -r -d '' element; do done < <($XPATH /DS_DRIVER_ACTION_DATA/DATASTORE/BASE_PATH \ /DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/RESTRICTED_DIRS \ /DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/SAFE_DIRS \ - /DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/HOST \ + /DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/BRIDGE_LIST \ /DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/VG_NAME \ /DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/BASE_IQN \ /DS_DRIVER_ACTION_DATA/IMAGE/PATH \ @@ -64,7 +64,7 @@ done < <($XPATH /DS_DRIVER_ACTION_DATA/DATASTORE/BASE_PATH \ BASE_PATH="${XPATH_ELEMENTS[j++]}" RESTRICTED_DIRS="${XPATH_ELEMENTS[j++]}" SAFE_DIRS="${XPATH_ELEMENTS[j++]}" -DST_HOST="${XPATH_ELEMENTS[j++]}" +BRIDGE_LIST="${XPATH_ELEMENTS[j++]}" VG_NAME="${XPATH_ELEMENTS[j++]:-$VG_NAME}" BASE_IQN="${XPATH_ELEMENTS[j++]:-$BASE_IQN}" SRC="${XPATH_ELEMENTS[j++]}" @@ -74,8 +74,10 @@ SHA1="${XPATH_ELEMENTS[j++]}" NO_DECOMPRESS="${XPATH_ELEMENTS[j++]}" LIMIT_TRANSFER_BW="${XPATH_ELEMENTS[j++]}" +DST_HOST=`get_destination_host $IMAGE_ID` + if [ -z "$DST_HOST" ]; then - error_message "Datastore template missing 'HOST' attribute." + error_message "Datastore template missing 'BRIDGE_LIST' attribute." exit -1 fi diff --git a/src/datastore_mad/remotes/lvm/cp b/src/datastore_mad/remotes/lvm/cp index 7c9d95b0dd..5ed8ab9561 100755 --- a/src/datastore_mad/remotes/lvm/cp +++ b/src/datastore_mad/remotes/lvm/cp @@ -51,7 +51,7 @@ while IFS= read -r -d '' element; do done < <($XPATH /DS_DRIVER_ACTION_DATA/DATASTORE/BASE_PATH \ /DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/RESTRICTED_DIRS \ /DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/SAFE_DIRS \ - /DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/HOST \ + /DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/BRIDGE_LIST \ /DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/VG_NAME \ /DS_DRIVER_ACTION_DATA/IMAGE/PATH \ /DS_DRIVER_ACTION_DATA/IMAGE/SIZE \ @@ -63,7 +63,7 @@ done < <($XPATH /DS_DRIVER_ACTION_DATA/DATASTORE/BASE_PATH \ BASE_PATH="${XPATH_ELEMENTS[j++]}" RESTRICTED_DIRS="${XPATH_ELEMENTS[j++]}" SAFE_DIRS="${XPATH_ELEMENTS[j++]}" -DST_HOST="${XPATH_ELEMENTS[j++]}" +BRIDGE_LIST="${XPATH_ELEMENTS[j++]}" VG_NAME="${XPATH_ELEMENTS[j++]:-$VG_NAME}" SRC="${XPATH_ELEMENTS[j++]}" SIZE="${XPATH_ELEMENTS[j++]}" @@ -72,8 +72,10 @@ SHA1="${XPATH_ELEMENTS[j++]}" NO_DECOMPRESS="${XPATH_ELEMENTS[j++]}" LIMIT_TRANSFER_BW="${XPATH_ELEMENTS[j++]}" +DST_HOST=`get_destination_host $IMAGE_ID` + if [ -z "$DST_HOST" ]; then - error_message "Datastore template missing 'HOST' attribute." + error_message "Datastore template missing 'BRIDGE_LIST' attribute." exit -1 fi diff --git a/src/sunstone/public/js/plugins/datastores-tab.js b/src/sunstone/public/js/plugins/datastores-tab.js index e81d01b161..5bcf24703f 100644 --- a/src/sunstone/public/js/plugins/datastores-tab.js +++ b/src/sunstone/public/js/plugins/datastores-tab.js @@ -231,16 +231,6 @@ var create_datastore_tmpl =
    '+tr("Paths that can not be used to register images. A space separated list of paths. This will prevent users registering important files as VM images and accessing them thourgh their VMs. OpenNebula will automatically add its configuration directories: /var/lib/one, /etc/one and oneadmin's home ($HOME).")+'
    \
    \ \ -
    \ -
    \ - \ -
    \ -
    \ - \ -
    \ -
    \ -
    \ -
    \
    \
    \ \ @@ -251,13 +241,13 @@ var create_datastore_tmpl =
    \
    \
    \ - \ + \
    \
    \ - \ + \
    \
    \ -
    '+tr("Server name or IP where OpenNebula will be staging the new images into. This server will act as the entry point for new inmages in the datastore.")+'
    \ +
    '+tr("Space separated list of Server names or IPs where OpenNebula will be staging the new images into. This server will act as the entry point for new inmages in the datastore.")+'
    \
    \
    \
    \ @@ -863,10 +853,9 @@ function hide_all(context) { // Hide all the options that depends on datastore type // and reset the selects - $('label[for="bridge_list"],input#bridge_list',context).hide(); $('label[for="ds_use_ssh"],input#ds_use_ssh',context).hide(); $('label[for="tm_use_ssh"],input#tm_use_ssh',context).hide(); - $('label[for="host"],input#host',context).parent().parent().hide(); + $('label[for="bridge_list"],input#bridge_list',context).parent().parent().hide(); $('label[for="base_iqn"],input#base_iqn',context).hide(); $('label[for="vg_name"],input#vg_name',context).hide(); $('select#ds_mad').removeAttr('disabled'); @@ -956,7 +945,6 @@ function setupCreateDatastoreDialog(){ var bridge_list = $('#bridge_list',context).val(); var ds_use_ssh = $('#ds_use_ssh',context).is(':checked'); var tm_use_ssh = $('#tm_use_ssh',context).is(':checked'); - var host = $('#host',context).val(); var base_iqn = $('#base_iqn',context).val(); var vg_name = $('#vg_name',context).val(); @@ -996,9 +984,6 @@ function setupCreateDatastoreDialog(){ if (tm_use_ssh) ds_obj.datastore.tm_use_ssh = "YES"; - if (host) - ds_obj.datastore.host = host; - if (base_iqn) ds_obj.datastore.base_iqn = base_iqn; @@ -1069,7 +1054,7 @@ function select_filesystem(){ } function select_vmware_vmfs(){ - $('label[for="bridge_list"],input#bridge_list').fadeIn(); + $('label[for="bridge_list"],input#bridge_list').parent().parent().fadeIn(); $('label[for="ds_use_ssh"],input#ds_use_ssh').fadeIn(); $('label[for="tm_use_ssh"],input#tm_use_ssh').fadeIn(); $('select#ds_mad').val('vmfs'); @@ -1085,7 +1070,7 @@ function select_iscsi(){ $('select#ds_mad').attr('disabled', 'disabled'); $('select#tm_mad').val('iscsi'); $('select#tm_mad').attr('disabled', 'disabled'); - $('label[for="host"],input#host').parent().parent().fadeIn(); + $('label[for="bridge_list"],input#bridge_list').parent().parent().fadeIn(); $('label[for="base_iqn"],input#base_iqn').fadeIn(); $('label[for="vg_name"],input#vg_name').fadeIn(); $('select#disk_type').children('option').each(function() { @@ -1104,7 +1089,7 @@ function select_ceph(){ $('select#ds_mad').attr('disabled', 'disabled'); $('select#tm_mad').val('ceph'); $('select#tm_mad').attr('disabled', 'disabled'); - $('label[for="host"],input#host').parent().parent().fadeIn(); + $('label[for="bridge_list"],input#bridge_list').parent().parent().fadeIn(); $('select#disk_type').val('RBD'); } @@ -1113,7 +1098,7 @@ function select_lvm(){ $('select#ds_mad').attr('disabled', 'disabled'); $('select#tm_mad').val('lvm'); $('select#tm_mad').attr('disabled', 'disabled'); - $('label[for="host"],input#host').parent().parent().fadeIn(); + $('label[for="bridge_list"],input#bridge_list').parent().parent().fadeIn(); $('label[for="vg_name"],input#vg_name').fadeIn(); $('select#disk_type').children('option').each(function() { var value_str = $(this).val(); From bf5d2380566bd5fad47623d6594831c18bee6bbd Mon Sep 17 00:00:00 2001 From: Tino Vazquez Date: Tue, 10 Sep 2013 17:23:33 +0200 Subject: [PATCH 22/30] Bug #2290: Now refresh after successful attach/detach won't fail --- src/sunstone/public/js/plugins/vms-tab.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sunstone/public/js/plugins/vms-tab.js b/src/sunstone/public/js/plugins/vms-tab.js index 10e9490ab0..df9e0b5b54 100644 --- a/src/sunstone/public/js/plugins/vms-tab.js +++ b/src/sunstone/public/js/plugins/vms-tab.js @@ -766,7 +766,7 @@ var vm_actions = { type: "single", call: OpenNebula.VM.attachdisk, callback: function(request) { - Sunstone.runAction("VM.showinfo", request.request.data[0]); + Sunstone.runAction("VM.showinfo", request.request.data[0][0]); }, error: onError, notify: true @@ -775,7 +775,7 @@ var vm_actions = { type: "single", call: OpenNebula.VM.detachdisk, callback: function(request) { - Sunstone.runAction("VM.showinfo", request.request.data[0]); + Sunstone.runAction("VM.showinfo", request.request.data[0][0]); }, error: onError, notify: true From e3e8a19f3e673ce138b2c2b890dc88a21f1835d4 Mon Sep 17 00:00:00 2001 From: Tino Vazquez Date: Tue, 10 Sep 2013 18:53:39 +0200 Subject: [PATCH 23/30] Bug #2290: Switch from input to label to VM and DISK ID values in different VM dialogs, so value is not lost upon datatable refresh --- src/sunstone/public/js/plugins/vms-tab.js | 36 +++++++++++------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/sunstone/public/js/plugins/vms-tab.js b/src/sunstone/public/js/plugins/vms-tab.js index df9e0b5b54..938b7346f6 100644 --- a/src/sunstone/public/js/plugins/vms-tab.js +++ b/src/sunstone/public/js/plugins/vms-tab.js @@ -2084,7 +2084,7 @@ function setupSaveAsDialog(){ \
    \
    \ - \ +
    \
    \
    \ @@ -2095,7 +2095,7 @@ function setupSaveAsDialog(){ \
    \
    \ - \ +
    \
    \
    \ @@ -2140,7 +2140,7 @@ function setupSaveAsDialog(){ setupTips(dialog); $('#save_as_form',dialog).submit(function(){ - var vm_id = $('#vm_id', this).val(); + var vm_id = $('#vm_id', this).text(); var image_name = $('#image_name', this).val(); var snapshot_type = $('#snapshot_type', this).val(); @@ -2150,7 +2150,7 @@ function setupSaveAsDialog(){ } var obj = { - disk_id : $('#disk_id', this).val(), + disk_id : $('#disk_id', this).text(), image_name : image_name, type: "", hot: (snapshot_type == "true" ? true : false) @@ -2164,8 +2164,8 @@ function setupSaveAsDialog(){ }; function popUpSaveAsDialog(vm_id, disk_id){ - $('#vm_id',$save_as_dialog).val(vm_id); - $('#disk_id',$save_as_dialog).val(disk_id); + $('#vm_id',$save_as_dialog).text(vm_id); + $('#disk_id',$save_as_dialog).twzt(disk_id); $save_as_dialog.reveal(); } @@ -2189,7 +2189,7 @@ function setupAttachDiskDialog(){ \
    \
    \ - \ +
    \
    \
    \ @@ -2212,7 +2212,7 @@ function setupAttachDiskDialog(){ setup_disk_tab_content(dialog, "attach_disk", "attach_disk") $('#attach_disk_form',dialog).submit(function(){ - var vm_id = $('#vm_id', this).val(); + var vm_id = $('#vm_id', this).text(); var data = {}; addSectionJSON(data, this); @@ -2226,7 +2226,7 @@ function setupAttachDiskDialog(){ }; function popUpAttachDiskDialog(vm_id){ - $('#vm_id',$attach_disk_dialog).val(vm_id); + $('#vm_id',$attach_disk_dialog).text(vm_id); $attach_disk_dialog.reveal(); } @@ -2447,7 +2447,7 @@ function setupAttachNicDialog(){ \
    \
    \ - \ +
    \
    \
    \ @@ -2470,7 +2470,7 @@ function setupAttachNicDialog(){ setup_nic_tab_content(dialog, "attach_nic", "attach_nic") $('#attach_nic_form',dialog).submit(function(){ - var vm_id = $('#vm_id', this).val(); + var vm_id = $('#vm_id', this).text(); var data = {}; addSectionJSON(data, this); @@ -2484,7 +2484,7 @@ function setupAttachNicDialog(){ }; function popUpAttachNicDialog(vm_id){ - $('#vm_id',$attach_nic_dialog).val(vm_id); + $('#vm_id',$attach_nic_dialog).text(vm_id); $attach_nic_dialog.reveal(); } @@ -2609,7 +2609,7 @@ function setupResizeCapacityDialog(){ \
    \
    \ - \ +
    \
    \
    \ @@ -2647,7 +2647,7 @@ function setupResizeCapacityDialog(){ setup_capacity_tab_content(dialog); $('#resize_capacity_form',dialog).submit(function(){ - var vm_id = $('#vm_id', this).val(); + var vm_id = $('#vm_id', this).text(); var enforce = false; if ($("#enforce", this).is(":checked")) { @@ -2670,7 +2670,7 @@ function setupResizeCapacityDialog(){ }; function popUpResizeCapacityDialog(vm_id){ - $('#vm_id',$resize_capacity_dialog).val(vm_id); + $('#vm_id',$resize_capacity_dialog).text(vm_id); $resize_capacity_dialog.reveal(); } @@ -2811,7 +2811,7 @@ function setupSnapshotDialog(){ \
    \
    \ - \ +
    \
    \
    \ @@ -2840,7 +2840,7 @@ function setupSnapshotDialog(){ setupTips(dialog); $('#snapshot_form',dialog).submit(function(){ - var vm_id = $('#vm_id', this).val(); + var vm_id = $('#vm_id', this).text(); var snapshot_name = $('#snapshot_name', this).val(); var obj = { @@ -2855,7 +2855,7 @@ function setupSnapshotDialog(){ }; function popUpSnapshotDialog(vm_id){ - $('#vm_id',$snapshot_dialog).val(vm_id); + $('#vm_id',$snapshot_dialog).text(vm_id); $snapshot_dialog.reveal(); } From f77ec81fb87bdd79f42d30f5aacdc9419acddb9c Mon Sep 17 00:00:00 2001 From: Tino Vazquez Date: Tue, 10 Sep 2013 19:00:49 +0200 Subject: [PATCH 24/30] Bug #2290: Fix typo --- src/sunstone/public/js/plugins/vms-tab.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sunstone/public/js/plugins/vms-tab.js b/src/sunstone/public/js/plugins/vms-tab.js index 938b7346f6..348e7a6bd5 100644 --- a/src/sunstone/public/js/plugins/vms-tab.js +++ b/src/sunstone/public/js/plugins/vms-tab.js @@ -2165,7 +2165,7 @@ function setupSaveAsDialog(){ function popUpSaveAsDialog(vm_id, disk_id){ $('#vm_id',$save_as_dialog).text(vm_id); - $('#disk_id',$save_as_dialog).twzt(disk_id); + $('#disk_id',$save_as_dialog).text(disk_id); $save_as_dialog.reveal(); } From 5767c4b7f6218f19c09b56279f2f434309fb6a12 Mon Sep 17 00:00:00 2001 From: Jaime Melis Date: Wed, 11 Sep 2013 15:13:55 +0200 Subject: [PATCH 25/30] Bug #2106: attach ceph image problem. This patch is a minor modification of the one submitted by Alan Zhang in dev.opennebula.org. --- src/vmm_mad/remotes/kvm/attach_disk | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/vmm_mad/remotes/kvm/attach_disk b/src/vmm_mad/remotes/kvm/attach_disk index d25291b5a9..507e27d9c6 100755 --- a/src/vmm_mad/remotes/kvm/attach_disk +++ b/src/vmm_mad/remotes/kvm/attach_disk @@ -31,7 +31,7 @@ DRV_ACTION="$5" XPATH="${DRIVER_PATH}/../../datastore/xpath.rb -b $DRV_ACTION" -unset i XPATH_ELEMENTS +unset i j XPATH_ELEMENTS DISK_XPATH="/VMM_DRIVER_ACTION_DATA/VM/TEMPLATE/DISK[ATTACH='YES']" @@ -40,12 +40,14 @@ while IFS= read -r -d '' element; do done < <($XPATH $DISK_XPATH/DRIVER \ $DISK_XPATH/TYPE \ $DISK_XPATH/READONLY \ - $DISK_XPATH/CACHE) + $DISK_XPATH/CACHE \ + $DISK_XPATH/IMAGE_ID) -DRIVER="${XPATH_ELEMENTS[0]:-$DEFAULT_TYPE}" -TYPE="${XPATH_ELEMENTS[1]}" -READONLY="${XPATH_ELEMENTS[2]}" -CACHE="${XPATH_ELEMENTS[3]}" +DRIVER="${XPATH_ELEMENTS[j++]:-$DEFAULT_TYPE}" +TYPE="${XPATH_ELEMENTS[j++]}" +READONLY="${XPATH_ELEMENTS[j++]}" +CACHE="${XPATH_ELEMENTS[j++]}" +IMAGE_ID="${XPATH_ELEMENTS[j++]}" TYPE=$(echo "$TYPE"|tr A-Z a-z) @@ -60,7 +62,14 @@ cdrom) TYPE_XML="file" DEVICE="cdrom" ;; -*) +rbd) + TYPE_SOURCE="protocol" + TYPE_XML="network" + SOURCE="rbd" + SOURCE_ARGS="name='one/one-$IMAGE_ID'" + DEVICE="disk" + ;; +*) #NOTE: This includes TYPE=FS and TYPE=SWAP TYPE_SOURCE="file" TYPE_XML="file" @@ -83,7 +92,7 @@ ATTACH_FILE="$SOURCE.attach" cat < $ATTACH_FILE - + $READONLY From 5528686aa63991aab53c845158ffd2734cc00ab6 Mon Sep 17 00:00:00 2001 From: Tino Vazquez Date: Wed, 11 Sep 2013 18:47:50 +0200 Subject: [PATCH 26/30] Bug #2290: Clear hidden pane before attaching imge to VM disk --- src/sunstone/public/js/plugins/vms-tab.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/sunstone/public/js/plugins/vms-tab.js b/src/sunstone/public/js/plugins/vms-tab.js index 348e7a6bd5..0ba5a0e238 100644 --- a/src/sunstone/public/js/plugins/vms-tab.js +++ b/src/sunstone/public/js/plugins/vms-tab.js @@ -2215,6 +2215,21 @@ function setupAttachDiskDialog(){ var vm_id = $('#vm_id', this).text(); var data = {}; + + if($('input[type=radio]:checked', dialog).val()=="image") + { + // Clear the volatile fields + $('input#FORMAT', dialog).val(""); + $('input#SIZE_TMP', dialog).val(""); + } + else + { + $('input#IMAGE_ID', dialog).val(""); + $('input#IMAGE', dialog).val(""); + $('input#IMAGE_UID', dialog).val(""); + $('input#IMAGE_UNAME',dialog).val(""); + } + addSectionJSON(data, this); var obj = {DISK: data} From 8f2e1c5237267bdd71f4dbba5cec74314eabed22 Mon Sep 17 00:00:00 2001 From: Tino Vazquez Date: Wed, 11 Sep 2013 19:04:47 +0200 Subject: [PATCH 27/30] Improve init_scripts tip --- src/sunstone/public/js/plugins/templates-tab.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sunstone/public/js/plugins/templates-tab.js b/src/sunstone/public/js/plugins/templates-tab.js index e86150087f..67288e875b 100644 --- a/src/sunstone/public/js/plugins/templates-tab.js +++ b/src/sunstone/public/js/plugins/templates-tab.js @@ -3195,7 +3195,7 @@ function setupCreateTemplateDialog(){ ''+ '
    '+ '
    '+ - '
    '+tr("If the VM uses the OpenNebula contextualization package the init.sh file is executed by default. When the init script added is not called init.sh or more than one init script is added, this list contains the scripts to run and the order. Ex. “init.sh users.sh mysql.sh”")+'
    '+ + '
    '+tr("OpenNebula expects the VM to have an OpenNebula contextualization package installed, which will look for a script called init.sh in the contextualization CD. If you want the VM to execute an script that is not called init.sh (or if you want to call more than just one script),this list contains the scripts to run and their order. Ex. \"init.sh users.sh mysql.sh\" will force the VM to execute init.sh , then users.sh and lastly mysql.sh at boot time")+'
    '+ '
    '+ ''+ ''+ From 71ce6fe0c061b049a8365934d8492910f2e4efda Mon Sep 17 00:00:00 2001 From: Tino Vazquez Date: Wed, 11 Sep 2013 19:16:21 +0200 Subject: [PATCH 28/30] bug #2315: Uncheck contextualization by default --- src/sunstone/public/js/plugins/templates-tab.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/sunstone/public/js/plugins/templates-tab.js b/src/sunstone/public/js/plugins/templates-tab.js index 67288e875b..beb073f0e7 100644 --- a/src/sunstone/public/js/plugins/templates-tab.js +++ b/src/sunstone/public/js/plugins/templates-tab.js @@ -3088,7 +3088,7 @@ function setupCreateTemplateDialog(){ ''+tr("SSH")+''+ '
    '+ '
    '+ - ''+ + ''+ '
    '+ '
    '+ ''+ @@ -3099,12 +3099,12 @@ function setupCreateTemplateDialog(){ '
    '+ '
    '+ '
    '+ - ''+ + ''+ '
    '+ '
    '+ '
    '+ '
    '+ - '
    ' + tr("User information") +'
    ' + tr("User information") +'
    ' + tr("ID") + ''+info.ID+''+info.ID+'
    ' + tr("Name") + ''+info.NAME+''+info.NAME+'
    ' + tr("Group ID") + ''+info.GID+''+info.GID+'
    ' + tr("Group Name") + ''+info.GNAME+'' + tr("Group") + ''+ info.GNAME +'\ +
    \ + \ +
    \ +
    ' + tr("Secondary groups") + ''+(typeof info.GROUPS.ID == "object" ? info.GROUPS.ID.join(",") : "-")+'
    ' + tr("Password") + '