summaryrefslogtreecommitdiffstats
path: root/cloudmasterd
diff options
context:
space:
mode:
authorMatthew Hicks <mhicks@mhicks-host.usersys.redhat.com>2008-06-21 23:08:25 -0400
committerMatthew Hicks <mhicks@mhicks-host.usersys.redhat.com>2008-06-21 23:08:25 -0400
commit8a0b57d23f49710fdffa037ec007e10e2968bcf0 (patch)
treedd57b26d38602053791b688f7a2b2e227416ae07 /cloudmasterd
parent6110d39864a9ca056e2d17b190fb63c5e25d9fd3 (diff)
downloadtools-8a0b57d23f49710fdffa037ec007e10e2968bcf0.tar.gz
tools-8a0b57d23f49710fdffa037ec007e10e2968bcf0.tar.xz
tools-8a0b57d23f49710fdffa037ec007e10e2968bcf0.zip
More sync logic
Diffstat (limited to 'cloudmasterd')
-rw-r--r--cloudmasterd/lib/cloudmasterd.rb45
-rwxr-xr-xcloudmasterd/primedb.rb10
2 files changed, 39 insertions, 16 deletions
diff --git a/cloudmasterd/lib/cloudmasterd.rb b/cloudmasterd/lib/cloudmasterd.rb
index 5eafdc9..ce4513b 100644
--- a/cloudmasterd/lib/cloudmasterd.rb
+++ b/cloudmasterd/lib/cloudmasterd.rb
@@ -89,6 +89,7 @@ module Cloudmasterd::Models
t.column :name, :string, :null => false, :limit => 255
t.column :email, :string, :null => false, :limit => 255
t.column :cloud, :string, :null => false, :limit => 255
+ t.column :state, :string, :null => false, :limit => 255
end
end
def self.down
@@ -136,7 +137,7 @@ module Cloudmasterd::Controllers
begin
_koan(@host, machine_fqdn, repo)
- Machine.create :name => machine_fqdn, :email => email, :cloud => @host
+ Machine.create :name => machine_fqdn, :email => email, :cloud => @host, :state => "Installing"
render :_koan
rescue Exception => e
@exception = e
@@ -172,8 +173,7 @@ module Cloudmasterd::Views
html do
head do
title 'Everest Cloud Master Controller'
- #link :rel => 'stylesheet', :type => 'text/css',
- #:href => self/'/styles.css', :media => 'screen'
+ #link :rel => 'stylesheet', :type => 'text/css', :href => self/'/styles.css', :media => 'screen'
end
body do
div.content do
@@ -186,12 +186,19 @@ module Cloudmasterd::Views
def cloud
@machines.keys.each do |email|
div do
- h1 email
- @machines[email].each do |machine|
- table do
+ h2 email
+ table do
+ tr do
+ th 'Name'
+ th 'Cloud Instance'
+ th 'State'
+ th ''
+ end
+ @machines[email].each do |machine|
tr do
td machine.name
td machine.cloud
+ td machine.state
td do
form(:method => :delete, :action => R(Cloudmasterd::Controllers::Koan, "#{machine.name}.html")) do
input :type => :submit, :value => 'Destroy'
@@ -241,7 +248,7 @@ def Cloudmasterd.create
end
def sync_state
- host_machines = {}
+ current_state = {}
Open3.popen3("func '*' call virt state") do |stdin, stdout, stderr|
# Parse out the hosts based on the func output (stripping off https:// and the port)
hosts = stderr.read.split("\n").collect{|host| host.split(" ")[1].split(":")[1][2..-1]}
@@ -249,14 +256,30 @@ def sync_state
# Parse out the machines that belong to each host and zip them together in a hash
stdout.read.split("\n").each_with_index do |host, index|
host[1..-2].split(", ").each do |machine|
- host_machines[hosts[index]] = machine[1..-2].split(" ")
+ name, state = machine[1..-2].split(" ")
+ current_state[name] = {:state => state, :cloud => hosts[index]}
end
end
end
- host_machines.each do |host, machines|
- matches = Cloudmasterd::Models::Machine.find(:all, :conditions => "name = '#{machines[0]}'")
- puts "Host: #{host} / Machine: #{machines[0]} / State: #{machines[1]} / Accounted for: #{matches.empty? ? 'false': 'true'}"
+ # Sync up the state for all the machines
+ Cloudmasterd::Models::Machine.find(:all).each do |machine|
+ if current_state.has_key?(machine.name) then
+ # We have a current state match for this machine
+ machine.update_attribute(:state, current_state[machine.name][:state])
+ machine.update_attribute(:cloud, current_state[machine.name][:cloud])
+
+ # Delete the key so we can determine unaccounted for machines
+ current_state.delete(machine.name)
+ else
+ # Not good - the machine in the DB isn't locateable
+ machine.update_attribute(:state, "Missing")
+ end
+ end
+
+ # We need to create an 'unknown' instance for all the remaining keys
+ current_state.each do |name, machine|
+ Cloudmasterd::Models::Machine.create :name => name, :email => "Unknown", :cloud => machine[:cloud], :state => machines[:state]
end
end
diff --git a/cloudmasterd/primedb.rb b/cloudmasterd/primedb.rb
index 866b91d..905dd43 100755
--- a/cloudmasterd/primedb.rb
+++ b/cloudmasterd/primedb.rb
@@ -17,8 +17,8 @@ class Machine < ActiveRecord::Base
set_table_name "cloudmasterd_machines"
end
-Machine.create(:name => "jboss-1.usersys.redhat.com", :email => "mhicks@redhat.com", :cloud => "cloud1.usersys.redhat.com")
-Machine.create(:name => "jboss-2.usersys.redhat.com", :email => "mhicks@redhat.com", :cloud => "cloud1.usersys.redhat.com")
-Machine.create(:name => "jboss-3.usersys.redhat.com", :email => "mhicks@redhat.com", :cloud => "cloud2.usersys.redhat.com")
-Machine.create(:name => "alien-jboss-1.usersys.redhat.com", :email => "calfonso@redhat.com", :cloud => "cloud3.usersys.redhat.com")
-Machine.create(:name => "alien-jboss-2.usersys.redhat.com", :email => "calfonso@redhat.com", :cloud => "cloud2.usersys.redhat.com")
+Machine.create(:name => "jboss-1.usersys.redhat.com", :email => "mhicks@redhat.com", :cloud => "cloud1.usersys.redhat.com", :state => "Installing")
+Machine.create(:name => "jboss-2.usersys.redhat.com", :email => "mhicks@redhat.com", :cloud => "cloud1.usersys.redhat.com", :state => "Installing")
+Machine.create(:name => "jboss-3.usersys.redhat.com", :email => "mhicks@redhat.com", :cloud => "cloud2.usersys.redhat.com", :state => "Installing")
+Machine.create(:name => "alien-jboss-1.usersys.redhat.com", :email => "calfonso@redhat.com", :cloud => "cloud3.usersys.redhat.com", :state => "Installing")
+Machine.create(:name => "alien-jboss-2.usersys.redhat.com", :email => "calfonso@redhat.com", :cloud => "cloud2.usersys.redhat.com", :state => "Installing")