diff --git a/src/cli/onevm b/src/cli/onevm index 0e1f3c15de..fc1cf77cb5 100755 --- a/src/cli/onevm +++ b/src/cli/onevm @@ -56,6 +56,13 @@ cmd=CommandParser::CmdParser.new(ARGV) do :description => "Device where the image will be attached" } + ENFORCE={ + :name => "enforce", + :short => "-e", + :large => "--enforce", + :description => "Enforce that the host capacity is not exceeded" + } + ######################################################################## # Global Options ######################################################################## @@ -287,12 +294,16 @@ cmd=CommandParser::CmdParser.new(ARGV) do States: PENDING EOT - command :deploy, deploy_desc, [:range,:vmid_list], :hostid do + command :deploy, deploy_desc, [:range,:vmid_list], :hostid, :options=>[ENFORCE] do host_id = args[1] verbose = "deploying in host #{host_id}" helper.perform_actions(args[0],options,verbose) do |vm| - vm.deploy(host_id) + if !options[:enforce].nil? + vm.deploy(host_id, options[:enforce]) + else + vm.deploy(host_id) + end end end @@ -302,12 +313,16 @@ cmd=CommandParser::CmdParser.new(ARGV) do States: RUNNING EOT - command :livemigrate, livemigrate_desc, [:range,:vmid_list], :hostid do + command :livemigrate, livemigrate_desc, [:range,:vmid_list], :hostid, :options=>[ENFORCE] do host_id = args[1] verbose = "live migrating to #{host_id}" helper.perform_actions(args[0],options,verbose) do |vm| - vm.live_migrate(host_id) + if !options[:enforce].nil? + vm.live_migrate(host_id, options[:enforce]) + else + vm.live_migrate(host_id) + end end end @@ -317,12 +332,16 @@ cmd=CommandParser::CmdParser.new(ARGV) do States: RUNNING EOT - command :migrate, migrate_desc, [:range,:vmid_list], :hostid do + command :migrate, migrate_desc, [:range,:vmid_list], :hostid, :options=>[ENFORCE] do host_id = args[1] verbose = "migrating to #{host_id}" helper.perform_actions(args[0],options,verbose) do |vm| - vm.migrate(host_id) + if !options[:enforce].nil? + vm.migrate(host_id, options[:enforce]) + else + vm.migrate(host_id) + end end end diff --git a/src/oca/ruby/OpenNebula/VirtualMachine.rb b/src/oca/ruby/OpenNebula/VirtualMachine.rb index 5e7c061c8b..d4efcb6a18 100644 --- a/src/oca/ruby/OpenNebula/VirtualMachine.rb +++ b/src/oca/ruby/OpenNebula/VirtualMachine.rb @@ -140,15 +140,16 @@ module OpenNebula # Initiates the instance of the VM on the target host. # - # +host_id+ The host id (hid) of the target host where - # the VM will be instantiated. - def deploy(host_id) - return Error.new('ID not defined') if !@pe_id - - rc = @client.call(VM_METHODS[:deploy], @pe_id, host_id.to_i) - rc = nil if !OpenNebula.is_error?(rc) - - return rc + # @param host_id [Interger] The host id (hid) of the target host where + # the VM will be instantiated. + # @param enforce [true|false] If it is set to true, the host capacity + # will be checked, and the deployment will fail if the host is + # overcommited. Defaults to false + # + # @return [nil, OpenNebula::Error] nil in case of success, Error + # otherwise + def deploy(host_id, enforce=false) + return call(VM_METHODS[:deploy], @pe_id, host_id.to_i, enforce) end # Shutdowns an already deployed VM @@ -247,23 +248,31 @@ module OpenNebula end # Saves a running VM and starts it again in the specified host - def migrate(host_id) - return Error.new('ID not defined') if !@pe_id - - rc = @client.call(VM_METHODS[:migrate], @pe_id, host_id.to_i, false) - rc = nil if !OpenNebula.is_error?(rc) - - return rc + # + # @param host_id [Interger] The host id (hid) of the target host where + # the VM will be migrated. + # @param enforce [true|false] If it is set to true, the host capacity + # will be checked, and the deployment will fail if the host is + # overcommited. Defaults to false + # + # @return [nil, OpenNebula::Error] nil in case of success, Error + # otherwise + def migrate(host_id, enforce=false) + return call(VM_METHODS[:migrate], @pe_id, host_id.to_i, false, enforce) end # Migrates a running VM to another host without downtime - def live_migrate(host_id) - return Error.new('ID not defined') if !@pe_id - - rc = @client.call(VM_METHODS[:migrate], @pe_id, host_id.to_i, true) - rc = nil if !OpenNebula.is_error?(rc) - - return rc + # + # @param host_id [Interger] The host id (hid) of the target host where + # the VM will be migrated. + # @param enforce [true|false] If it is set to true, the host capacity + # will be checked, and the deployment will fail if the host is + # overcommited. Defaults to false + # + # @return [nil, OpenNebula::Error] nil in case of success, Error + # otherwise + def live_migrate(host_id, enforce=false) + return call(VM_METHODS[:migrate], @pe_id, host_id.to_i, true, enforce) end # Set the specified vm's disk to be saved in a new image