From 68e2797a9bf83ba26d2949356bc2437675c6d9de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Font=C3=A1n=20Mui=C3=B1os?= Date: Fri, 24 Apr 2009 13:52:43 +0000 Subject: [PATCH] Disable a host if it has non DONE VMs when deleting (#8) git-svn-id: http://svn.opennebula.org/one/trunk@489 3034c82b-c49b-4eb3-8279-a7acafdc01c0 --- src/client/ruby/onehost | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/src/client/ruby/onehost b/src/client/ruby/onehost index c5e5c61f1d..5f33b60143 100755 --- a/src/client/ruby/onehost +++ b/src/client/ruby/onehost @@ -216,12 +216,28 @@ end server=ONE::Server.new $host=host=ONE::Host.new(server) +#$vm=vm=ONE::VM.new(server) def command_exit(code) $host.close_db exit(code) end +# Returns true if there are non DONE VM's in a host, false otherwise +def vms_in_host?(host) + sql_statement="select history.vid,history.hid,history.seq,vm_pool.state"+ + " from history,vm_pool where vm_pool.oid=history.vid and"+ + " vm_pool.state<>6 and history.hid=#{host} group by vid" + + result=$host.get_db.db.execute(sql_statement) + + if result.length>0 + true + else + false + end +end + onehost_opts=OnehostParse.new onehost_opts.parse(ARGV) @@ -250,10 +266,18 @@ when "show" when "delete" check_parameters("delete", 1) host_id=get_host_id(host, ARGV[0]) - result=host.delete(host_id) - if result[0] - puts "Host deleted" if ops[:verbose] - command_exit 0 + if vms_in_host?(host_id) + result=host.disable(host_id) + if result[0] + puts "Host disabled" if ops[:verbose] + command_exit 0 + end + else + result=host.delete(host_id) + if result[0] + puts "Host deleted" if ops[:verbose] + command_exit 0 + end end when "list"