From 923bcf04f075907ab18fe25fe2f30489183dabd5 Mon Sep 17 00:00:00 2001 From: Matthew Hicks Date: Mon, 23 Jun 2008 09:37:13 -0400 Subject: Moving the sync script to an external location and adding cleanup logic --- cloudmasterd/extra/cloudmasterd.redhat | 2 + cloudmasterd/extra/cloudmasterd.spec | 2 +- cloudmasterd/lib/cloudmasterd.rb | 116 ------------------------------- cloudmasterd/lib/cloudmasterd/version.rb | 2 +- 4 files changed, 4 insertions(+), 118 deletions(-) (limited to 'cloudmasterd') diff --git a/cloudmasterd/extra/cloudmasterd.redhat b/cloudmasterd/extra/cloudmasterd.redhat index 5059c72..d0446ca 100755 --- a/cloudmasterd/extra/cloudmasterd.redhat +++ b/cloudmasterd/extra/cloudmasterd.redhat @@ -19,11 +19,13 @@ CTL=cloudmasterd-ctl case "$1" in start) echo -n $"Starting cloudmasterd: " + `/usr/bin/cloudmasterd-sync > /var/log/cloudmasterd-sync.log &` $CTL start RETVAL=$? ;; stop) echo -n $"Stopping cloudmasterd: " + `pkill -f cloudmasterd-sync` $CTL stop RETVAL=$? ;; diff --git a/cloudmasterd/extra/cloudmasterd.spec b/cloudmasterd/extra/cloudmasterd.spec index 3a52dca..77bc999 100644 --- a/cloudmasterd/extra/cloudmasterd.spec +++ b/cloudmasterd/extra/cloudmasterd.spec @@ -6,7 +6,7 @@ Summary: daemon for machine configuration Name: rubygem-%{gemname} -Version: 0.1.7 +Version: 0.1.9 Release: 1%{?dist} Group: Development/Languages License: GPLv2+ or Ruby diff --git a/cloudmasterd/lib/cloudmasterd.rb b/cloudmasterd/lib/cloudmasterd.rb index 86182eb..70ab816 100644 --- a/cloudmasterd/lib/cloudmasterd.rb +++ b/cloudmasterd/lib/cloudmasterd.rb @@ -19,109 +19,6 @@ Camping.goes :Cloudmasterd Cloudmasterd.picnic! module Cloudmasterd::Helpers - class Syncer - def self.run - begin - sync_memory - sync_state - sync_owners - rescue Exception => e - puts "ERROR: An error occured during syncing - #{e.to_s}" - end - end - - def self.parse_hosts(func_stderr) - hosts = [] - func_stderr.split("\n").each do |host_line| - # Handle a remote exception coming from a disconnected host - if host_line.index("remote exception") then - hosts.pop() - else - hosts << host_line.split(":")[1][2..-1] - end - end - return hosts - end - - def self.sync_memory - current_state = {} - Open3.popen3("func '*' call virt freemem") do |stdin, stdout, stderr| - hosts = parse_hosts(stderr.read) - - # Parse out the machines that belong to each host and zip them together in a hash - stdout.read.split("\n").each_with_index do |memory, index| - current_state[hosts[index]] = memory - end - end - - Cloudmasterd::Models::Cloud.transaction do - # Sync up the DB state - delete everything first - Cloudmasterd::Models::Cloud.delete_all - - # Create the current entries - current_state.each do |host, memory| - Cloudmasterd::Models::Cloud.create :name => host, :memory => memory - end - end - end - - def self.sync_state - current_state = {} - Open3.popen3("func '*' call virt state") do |stdin, stdout, stderr| - hosts = parse_hosts(stderr.read) - - # 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| - name, state = machine[1..-2].split(" ") - current_state[name] = {:state => state, :cloud => hosts[index]} unless name == "Domain-0" - end - end - end - - # 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_attributes(:cloud => current_state[machine.name][:cloud], :state => current_state[machine.name][:state]) - - # 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 => machine[:state] - end - end - - def self.sync_owners - # Sync up any unowned machines that now have an owner (handles race condition with syncing states) - unowned_machines = {} - Cloudmasterd::Models::Machine.find(:all, :conditions => "email = 'unknown'").each do |machine| - unowned_machines[machine.name] = machine - end - - owned_machines = {} - Cloudmasterd::Models::Machine.find(:all, :conditions => "email <> 'unknown'").each do |machine| - owned_machines[machine.name] = machine - end - - owned_machines.each do |name, machine| - if unowned_machines.has_key?(name) then - # Delete the unowned machine and update the owned one - u_machine = unowned_machines[name] - machine.update_attributes(:cloud => u_machine.cloud, :state => u_machine.state) - u_machine.destroy() - end - end - end - end - class Cobblerd def initialize(repo) @repo = repo @@ -281,9 +178,6 @@ module Cloudmasterd::Controllers class Status < REST 'status' def list - # TODO: Figure out how to move this to a background thread - Cloudmasterd::Helpers::Syncer.run - @machines = {} Machine.find(:all, :select => "distinct email").map{|x| x.email}.each do |email| @machines[email] = Machine.find(:all, :conditions => "email = '#{email}'", :order => 'cloud') @@ -400,16 +294,6 @@ def Cloudmasterd.create :database => "/var/lib/cloudmaster.db" ) Cloudmasterd::Models.create_schema :assume => (Cloudmasterd::Models::Machine.table_exists? ? 1.0 : 0.0) - - # Sync up the state initially - Cloudmasterd::Helpers::Syncer.run end -#Thread.new do -# while true do -# Cloudmasterd::Helpers::Syncer.run -# sleep 5 -# end -#end - Cloudmasterd.start_picnic diff --git a/cloudmasterd/lib/cloudmasterd/version.rb b/cloudmasterd/lib/cloudmasterd/version.rb index d45b0fd..457ad80 100644 --- a/cloudmasterd/lib/cloudmasterd/version.rb +++ b/cloudmasterd/lib/cloudmasterd/version.rb @@ -2,7 +2,7 @@ module Cloudmasterd #:nodoc: module VERSION #:nodoc: MAJOR = 0 MINOR = 1 - TINY = 7 + TINY = 9 STRING = [MAJOR, MINOR, TINY].join('.') end -- cgit