[Ovirt-devel] ovirt-server patch for vm failover and actual data set to db
Василец Дмитрий
pronix.service at gmail.com
Wed Jan 21 15:51:44 UTC 2009
this patch restart vm from crashed host and set to db current data about vm.
please test or criticize it.
fencing is ipmi , when domain['state'] set 'crashed' i will reboot host
diff --git a/src/db-omatic/db_omatic.rb b/src/db-omatic/db_omatic.rb
index 4afffb1..bdab392 100755
--- a/src/db-omatic/db_omatic.rb
+++ b/src/db-omatic/db_omatic.rb
@@ -74,6 +76,65 @@ class DbOmatic < Qpid::Qmf::Console
domain[:synced] = true
end
+ #find hostname from values['node'] where values['class_type'] == 'domain'
+ def get_host_id(abank,bbank) #возвращает значение не то что надо
- числовой идентификатор ноды возвращает
+ begin
+ @cached_objects.keys.each do |objkey|
+ if @cached_objects[objkey][:agent_bank].to_s == abank and
@cached_objects[objkey][:broker_bank].to_s == bbank and
@cached_objects[objkey][:class_type].to_s == 'node'
+ return Host.find(:first, :conditions => ['hostname =
?', at cached_objects[objkey]["hostname"].to_s]).id
+ break
+ end
+ end
+ rescue => ex
+ log("error in get_host_id")
+ log(ex)
+ end
+ end
+
+ def set_host(values,digit)
+ begin
+ vm = Vm.find(:first, :conditions => ['description = ?',values["name"].to_s])
+ if vm and digit
+ vm.host_id = digit
+ vm.save!
+ else
+ log("this vm not exist #{values["name"]}")
+ end
+ rescue => ex
+ puts "error when set_host for #{values["name"]}"
+ puts ex
+ end
+ end
+
+ def start_crashed_vm(vm)
+ task = VmTask.new( :user => 'db-omatic', :task_target => vm, :action
=> 'start_vm', :state => 'queued')
+ task.save!
+ log("set task for start crashed vm #{vm.id}")
+ end
+
+ def set_domain_stopped(domain)
+ begin
+ vm = Vm.find(:first, :conditions => ['uuid = ?', domain['uuid']])
+ if vm != nil
+ curstate = vm.state
+ vm.state = Vm::STATE_STOPPED
+ vm.host_id = nil
+ vm.save
+ domain['state'] = 'crashed' # and now i will use ipmi for reboot
anavailable host - simple fencing
+ if curstate == Vm::STATE_RUNNING
+ start_crashed_vm(vm)
+ end
+ else
+ log('vm == nil ')
+ end
+ log("domain #{domain['id']} already stopped")
+ rescue => ex
+ log("can\'t set domain #{domain['id']} stopped")
+ log(ex)
+ end
+ end
+
+
def update_host_state(host_info, state)
db_host = Host.find(:first, :conditions => [ "hostname = ?",
host_info['hostname'] ])
if db_host
@@ -130,20 +190,36 @@ class DbOmatic < Qpid::Qmf::Console
end
domain_state_change = false
-
+ change_node = false
obj.properties.each do |key, newval|
if values[key.to_s] != newval
values[key.to_s] = newval
#log "new value for property #{key} : #{newval}"
if type == "domain" and key.to_s == "state"
- domain_state_change = true
+ domain_state_change = true
end
+ if type == "domain" and key.to_s == "node"
+ change_node = true
+ end
+
end
end
if domain_state_change
update_domain_state(values)
end
+ if change_node
+ values.each do |key,val|
+ if key == 'state' and val == 'running'
+ abank = values['node'].to_s.split('-')[3]
+ bbank = values['node'].to_s.split('-')[4]
+ @@host_id = get_host_id(abank,bbank)
+ set_host(values,@@host_id)
+ log("update node data for #{values['name']}")
+ break
+ end
+ end
+ end
if new_object
if type == "node"
@@ -187,11 +263,6 @@ class DbOmatic < Qpid::Qmf::Console
end
end
-
- def del_agent(agent)
- agent_disconnected(agent)
- end
-
# This method marks objects associated with the given agent as
timed out/invalid. Called either
# when the agent heartbeats out, or we get a del_agent callback.
def agent_disconnected(agent)
@@ -204,11 +275,13 @@ class DbOmatic < Qpid::Qmf::Console
if values[:timed_out] == false
if values[:class_type] == 'node'
update_host_state(values, Host::STATE_UNAVAILABLE)
+ values[:timed_out] = true
elsif values[:class_type] == 'domain'
- update_domain_state(values, Vm::STATE_UNREACHABLE)
- end
+ set_domain_stopped(values)
+ values[:timed_out] = true
+ @cached_objects.delete(objkey)
+ end
end
- values[:timed_out] = true
end
end
end
@@ -248,6 +320,7 @@ class DbOmatic < Qpid::Qmf::Console
db_vm = Vm.find(:all)
db_vm.each do |vm|
log "Marking vm #{vm.description} as stopped."
+ vm.host_id = nil
vm.state = Vm::STATE_STOPPED
vm.save
end
--
С уважением, Дмитрий.
More information about the ovirt-devel
mailing list