1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-16 22:50:10 +03:00

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
This commit is contained in:
Javier Fontán Muiños 2009-04-24 13:52:43 +00:00
parent 2b69d749cc
commit 68e2797a9b

View File

@ -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"