diff options
| author | Matthew Hicks <mhicks@mhicks-host.usersys.redhat.com> | 2008-06-23 15:06:37 -0400 |
|---|---|---|
| committer | Matthew Hicks <mhicks@mhicks-host.usersys.redhat.com> | 2008-06-24 08:08:25 -0400 |
| commit | 4ec70ff34acf9ef7733cf6dc606a147a9c3ca9bd (patch) | |
| tree | b410d5426238f27edba0eb031e67c13f01de829d /cloudmasterd/lib/cloudmasterd.rb | |
| parent | 4b539425989d8c3d10a24a988175be5ba850bbec (diff) | |
Tools cleanup
Diffstat (limited to 'cloudmasterd/lib/cloudmasterd.rb')
| -rw-r--r-- | cloudmasterd/lib/cloudmasterd.rb | 58 |
1 files changed, 31 insertions, 27 deletions
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) |
