From 4ec70ff34acf9ef7733cf6dc606a147a9c3ca9bd Mon Sep 17 00:00:00 2001 From: Matthew Hicks Date: Mon, 23 Jun 2008 15:06:37 -0400 Subject: Tools cleanup --- cloudmasterd/lib/cloudmasterd.rb | 58 +++++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 27 deletions(-) (limited to 'cloudmasterd/lib/cloudmasterd.rb') diff --git a/cloudmasterd/lib/cloudmasterd.rb b/cloudmasterd/lib/cloudmasterd.rb index d82f165..b4cbf08 100644 --- a/cloudmasterd/lib/cloudmasterd.rb +++ b/cloudmasterd/lib/cloudmasterd.rb @@ -1,7 +1,3 @@ -$: << File.dirname(File.expand_path(__FILE__)) - -gem 'reststop', '~> 0.2' - require 'yaml' require 'fileutils' require 'rubygems' @@ -12,6 +8,7 @@ require 'restr' require 'xmlrpc/client' require 'sqlite3' require 'open3' +require 'cloudmasterd/syncer' Camping.goes :Cloudmasterd Cloudmasterd.picnic! @@ -137,37 +134,44 @@ module Cloudmasterd::Controllers email = input.email cobbler_profile = _get_cobbler_profile(machine_fqdn, repo) - @host = _get_best_host(cobbler_profile["virt_file_size"], cobbler_profile["virt_ram"]) - begin - _koan(@host, machine_fqdn, repo) + # Synchronize access before making the func calls + Syncer::lock do + @host = _get_best_host(cobbler_profile["virt_file_size"], cobbler_profile["virt_ram"]) + + begin + _koan(@host, machine_fqdn, repo) - Machine.create :name => machine_fqdn, :email => email, :cloud => @host, :state => "Installing" - render :_koan - rescue Exception => e - @exception = e - render :_error + Machine.create :name => machine_fqdn, :email => email, :cloud => @host, :state => "Installing" + render :_koan + rescue Exception => e + @exception = e + render :_error + end end end def destroy(name) puts "Destroying image #{name}" - Machine.find(:all, :conditions => "name = '#{name}'").each do |machine| - # If the machine is missing, don't bother remotely trying to cleanup - unless machine.state == "missing" then - # Destroy the virtual machine - `func "#{machine.cloud}" call command run "virsh destroy #{machine.name}"` - `func "#{machine.cloud}" call command run "virsh undefine #{machine.name}"` - - # Remove the auto start file if it exists - `func "#{machine.cloud}" call command run "rm -rf /etc/xen/auto/#{machine.name}"` - - # Remove the image file - `func "#{machine.cloud}" call command run "rm -rf /images/#{machine.name}-disk0"` - end - # Delete the DB record - machine.destroy + Syncer::lock do + Machine.find(:all, :conditions => "name = '#{name}'").each do |machine| + # If the machine is missing, don't bother remotely trying to cleanup + unless machine.state == "missing" then + # Destroy the virtual machine + `func "#{machine.cloud}" call command run "virsh destroy #{machine.name}"` + `func "#{machine.cloud}" call command run "virsh undefine #{machine.name}"` + + # Remove the auto start file if it exists + `func "#{machine.cloud}" call command run "rm -rf /etc/xen/auto/#{machine.name}"` + + # Remove the image file + `func "#{machine.cloud}" call command run "rm -rf /images/#{machine.name}-disk0"` + end + + # Delete the DB record + machine.destroy + end end redirect R(Status) -- cgit