[Ovirt-devel] [PATCH] Add host state field
Ian Main
imain at redhat.com
Thu Jun 5 06:26:12 UTC 2008
This patch adds a new column to the hosts table named 'state' which is
updated via host-status to "available" or "unavailable" based on whether
it is reachable. I'm hoping the UI folks can incorporate this fairly
easily.
It also quiets down host-status and makes it so it only kicks taskomatic
when the state of a vm needs changing.
Signed-off-by: Ian Main <imain at redhat.com>
---
wui/src/db/migrate/002_create_hosts.rb | 1 +
wui/src/host-browser/host-browser.rb | 5 ++++-
wui/src/host-status/host-status.rb | 22 ++++++++++++++++------
3 files changed, 21 insertions(+), 7 deletions(-)
diff --git a/wui/src/db/migrate/002_create_hosts.rb b/wui/src/db/migrate/002_create_hosts.rb
index e8b26f2..3e36738 100644
--- a/wui/src/db/migrate/002_create_hosts.rb
+++ b/wui/src/db/migrate/002_create_hosts.rb
@@ -30,6 +30,7 @@ class CreateHosts < ActiveRecord::Migration
t.integer :is_disabled
t.integer :hardware_pool_id, :null => false
t.integer :lock_version, :default => 0
+ t.string :state
end
execute "alter table hosts add constraint fk_host_pools
diff --git a/wui/src/host-browser/host-browser.rb b/wui/src/host-browser/host-browser.rb
index ada5ee1..e127ddb 100755
--- a/wui/src/host-browser/host-browser.rb
+++ b/wui/src/host-browser/host-browser.rb
@@ -110,7 +110,10 @@ class HostBrowser
"arch" => host_info['ARCH'],
"memory_in_mb" => host_info['MEMSIZE'],
"is_disabled" => 0,
- "hardware_pool" => HardwarePool.get_default_pool).save
+ "hardware_pool" => HardwarePool.get_default_pool,
+ # Let host-status mark it available when it
+ # successfully connects to it via libvirt.
+ "state" => "unavailable").save
rescue Exception => error
puts "Error while creating record: #{error.message}"
end
diff --git a/wui/src/host-status/host-status.rb b/wui/src/host-status/host-status.rb
index d146c74..41638da 100755
--- a/wui/src/host-status/host-status.rb
+++ b/wui/src/host-status/host-status.rb
@@ -103,15 +103,18 @@ loop do
hosts = Host.find(:all)
hosts.each do |host|
- puts "checking host" + host.hostname
-
begin
conn = Libvirt::open("qemu+tcp://" + host.hostname + "/system")
rescue
# we couldn't contact the host for whatever reason. Since we can't get
# to this host, we have to mark all vms on it as disconnected or stopped
# or such.
- puts "Failed to contact host " + host.hostname + "; skipping for now", $!
+ if host.state != "unavailable"
+ puts "Updating host state to unavailable: " + host.hostname
+ host.state = "unavailable"
+ host.save
+ end
+
Vm.find(:all, :conditions => [ "host_id = ?", host.id ]).each do |vm|
# Since we can't reach the host on which the vms reside, we mark these
# as STATE_UNREACHABLE. If they come back up we can mark them as
@@ -121,12 +124,21 @@ loop do
# If this causes too much trouble in the UI, this can be changed to
# STATE_STOPPED for now until it is resolved of another solution is
# brought forward.
- kick_taskomatic(Vm::STATE_UNREACHABLE, vm)
+
+ if vm.state != Vm::STATE_UNREACHABLE:
+ kick_taskomatic(Vm::STATE_UNREACHABLE, vm)
+ end
end
next
end
+ if host.state != "available"
+ puts "Updating host state to available: " + host.hostname
+ host.state = "available"
+ host.save
+ end
+
begin
vm_ids = conn.list_domains
rescue
@@ -135,8 +147,6 @@ loop do
next
end
- puts vm_ids.length
-
# Here we're going through every vm listed through libvirt. This
# really only lets us find ones that are started that shouldn't be.
vm_ids.each do |vm_id|
--
1.5.4.5
More information about the ovirt-devel
mailing list