From bd5151dcba94f4a1f8b61ba16794575e50ca10e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Fri, 9 Mar 2012 15:05:27 +0100 Subject: [PATCH 1/3] Feature #1112: Migrator to 3.3.80 returns error if it finds active VMs --- src/onedb/3.3.0_to_3.3.80.rb | 41 ++++++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/src/onedb/3.3.0_to_3.3.80.rb b/src/onedb/3.3.0_to_3.3.80.rb index 7194edc1e5..884d9bceae 100644 --- a/src/onedb/3.3.0_to_3.3.80.rb +++ b/src/onedb/3.3.0_to_3.3.80.rb @@ -25,7 +25,38 @@ module Migrator "OpenNebula 3.3.80" end + SHORT_VM_STATES=%w{init pend hold actv stop susp done fail} + + SHORT_LCM_STATES=%w{prol boot runn migr save save save migr prol, + epil epil shut shut fail clea unkn} + def up + + header_done = false + + @db.fetch("SELECT oid,name,state,lcm_state FROM vm_pool WHERE ( state <> 1 AND state <> 6 )") do |row| + if ( !header_done ) + puts "You can't have active VMs. Please shutdown or delete the following VMs:" + puts + puts " ID STAT NAME" + + header_done = true + end + + if row[:state] != 3 + state_str = SHORT_VM_STATES[row[:state]] + else + state_str = SHORT_LCM_STATES[row[:lcm_state]] + end + + puts "#{'%6.6s' % row[:oid].to_s} #{state_str} #{row[:name]}" + end + + if ( header_done ) + puts + return false + end + one_location = ENV["ONE_LOCATION"] if !one_location @@ -208,9 +239,7 @@ module Migrator if ( hash.length == 32 && hash =~ /^[0-9A-F]+$/i ) e.text = "#{var_location}/datastores/1/#{hash}" - # TODO: create link, or mv image file? `ln -s #{previous_source} #{e.text}` - # `mv #{e.text} #{previous_source}` end } @@ -250,15 +279,15 @@ module Migrator " 0" << " 0" << " " << - " fs" << # TODO - " shared" << # TODO + " fs" << + " shared" << " #{var_location}/datastores/1" << " -1" << " none" << images_element << " " << "" From 3e9af3242ce65199f2b05d67f594c7360a6dd9fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Fri, 9 Mar 2012 15:11:00 +0100 Subject: [PATCH 2/3] Feature #1112: Set DS_MAD as '-' for the system datastore --- src/datastore/DatastorePool.cc | 2 +- src/onedb/3.3.0_to_3.3.80.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/datastore/DatastorePool.cc b/src/datastore/DatastorePool.cc index 7dfd9fe096..1557659a39 100644 --- a/src/datastore/DatastorePool.cc +++ b/src/datastore/DatastorePool.cc @@ -52,7 +52,7 @@ DatastorePool::DatastorePool(SqlDB * db): // --------------------------------------------------------------------- oss << "NAME = " << SYSTEM_DS_NAME << endl - << "DS_MAD = fs" << endl + << "DS_MAD = -" << endl << "TM_MAD = shared"; ds_tmpl = new DatastoreTemplate; diff --git a/src/onedb/3.3.0_to_3.3.80.rb b/src/onedb/3.3.0_to_3.3.80.rb index 884d9bceae..3dff69249c 100644 --- a/src/onedb/3.3.0_to_3.3.80.rb +++ b/src/onedb/3.3.0_to_3.3.80.rb @@ -122,14 +122,14 @@ module Migrator " 0" << " 0" << " " << - " fs" << + " -" << " shared" << " #{var_location}/datastores/0" << " -1" << " none" << " " << " " << "" From f2e6303c3ee887af7564b998b583f2ab5d2f7324 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Fri, 9 Mar 2012 15:49:45 +0100 Subject: [PATCH 3/3] Feature #1112: Add new cluster_id parameter to one.vn.allocate --- include/RequestManagerAllocate.h | 14 ++++++++++++-- src/cli/onehost | 4 ++++ src/cli/onevnet | 13 +++++++++++-- src/oca/ruby/OpenNebula/VirtualNetwork.rb | 10 +++++++--- 4 files changed, 34 insertions(+), 7 deletions(-) diff --git a/include/RequestManagerAllocate.h b/include/RequestManagerAllocate.h index 9522314868..8b3497b418 100644 --- a/include/RequestManagerAllocate.h +++ b/include/RequestManagerAllocate.h @@ -146,7 +146,7 @@ public: VirtualNetworkAllocate(): RequestManagerAllocate("VirtualNetworkAllocate", "Allocates a new virtual network", - "A:ss", + "A:ssi", true) { Nebula& nd = Nebula::instance(); @@ -170,6 +170,16 @@ public: RequestAttributes& att, int cluster_id, const string& cluster_name); + + int get_cluster_id(xmlrpc_c::paramList const& paramList) + { + return xmlrpc_c::value_int(paramList.getInt(2)); + }; + + int add_to_cluster(Cluster* cluster, int id, string& error_msg) + { + return cluster->add_datastore(id, error_msg); + }; }; /* ------------------------------------------------------------------------- */ @@ -181,7 +191,7 @@ public: ImageAllocate(): RequestManagerAllocate("ImageAllocate", "Allocates a new image", - "A:ss", + "A:ssi", true) { Nebula& nd = Nebula::instance(); diff --git a/src/cli/onehost b/src/cli/onehost index 9f72204b66..4c60cc1673 100755 --- a/src/cli/onehost +++ b/src/cli/onehost @@ -52,6 +52,10 @@ cmd=CommandParser::CmdParser.new(ARGV) do helper.list_to_id(arg) end + set :format, :clusterid, OpenNebulaHelper.rname_to_id_desc("CLUSTER") do |arg| + OpenNebulaHelper.rname_to_id(arg, "CLUSTER") + end + ######################################################################## # Commands ######################################################################## diff --git a/src/cli/onevnet b/src/cli/onevnet index 720673db27..6f8a7084ff 100755 --- a/src/cli/onevnet +++ b/src/cli/onevnet @@ -52,6 +52,10 @@ cmd=CommandParser::CmdParser.new(ARGV) do OpenNebulaHelper.rname_to_id(arg, "USER") end + set :format, :clusterid, OpenNebulaHelper.rname_to_id_desc("CLUSTER") do |arg| + OpenNebulaHelper.rname_to_id(arg, "CLUSTER") + end + set :format, :vnetid, OneVNetHelper.to_id_desc do |arg| helper.to_id(arg) end @@ -72,10 +76,15 @@ cmd=CommandParser::CmdParser.new(ARGV) do Creates a new Virtual Network from the given template file EOT - command :create, create_desc, :file do + command :create, create_desc, :file, [:clusterid, nil] do helper.create_resource(options) do |vn| template=File.read(args[0]) - vn.allocate(template) + + if args.size == 1 + vn.allocate(template) + else + vn.allocate(template, args[1].to_i) + end end end diff --git a/src/oca/ruby/OpenNebula/VirtualNetwork.rb b/src/oca/ruby/OpenNebula/VirtualNetwork.rb index 1c24e0ad95..2b82cc1622 100644 --- a/src/oca/ruby/OpenNebula/VirtualNetwork.rb +++ b/src/oca/ruby/OpenNebula/VirtualNetwork.rb @@ -78,9 +78,13 @@ module OpenNebula # Allocates a new VirtualNetwork in OpenNebula # - # +description+ A string containing the template of the VirtualNetwork. - def allocate(description) - super(VN_METHODS[:allocate],description) + # @param description [String] The template of the VirtualNetwork. + # @param cluster_id [Integer] Id of the cluster + # + # @return [Integer, OpenNebula::Error] the new ID in case of + # success, error otherwise + def allocate(description,cluster_id=ClusterPool::NONE_CLUSTER_ID) + super(VN_METHODS[:allocate], description, cluster_id) end # Replaces the template contents