Feature #1338: Add enforce param to CLI and Ruby OCA

This commit is contained in:
Carlos Martín committed 2012-12-11 15:43:31 +01:00
1 parent 6ebd41e218
commit 06eceb43cb
2 files changed
+57 -29

No files matched your search

+25 -6
View File
@@ -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
+32 -23
View File
@@ -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