summaryrefslogtreecommitdiffstats
path: root/cloudmasterd
diff options
context:
space:
mode:
authorMatthew Hicks <mhicks@mhicks-host.usersys.redhat.com>2008-06-22 00:44:19 -0400
committerMatthew Hicks <mhicks@mhicks-host.usersys.redhat.com>2008-06-22 00:44:19 -0400
commit368308cbac7d1b42087dc0fcbd581c742a79786c (patch)
tree75e1f0c36b0ad91a4f7f40c441b6b7773424bc04 /cloudmasterd
parentad01e6cfb46b9ed936c905e33717be853b348f5b (diff)
downloadtools-368308cbac7d1b42087dc0fcbd581c742a79786c.tar.gz
tools-368308cbac7d1b42087dc0fcbd581c742a79786c.tar.xz
tools-368308cbac7d1b42087dc0fcbd581c742a79786c.zip
More cleanup
Fixing the /etc/xen/auto variable
Diffstat (limited to 'cloudmasterd')
-rw-r--r--cloudmasterd/lib/cloudmasterd.rb32
1 files changed, 31 insertions, 1 deletions
diff --git a/cloudmasterd/lib/cloudmasterd.rb b/cloudmasterd/lib/cloudmasterd.rb
index 2bffbbc..a9303c7 100644
--- a/cloudmasterd/lib/cloudmasterd.rb
+++ b/cloudmasterd/lib/cloudmasterd.rb
@@ -20,6 +20,12 @@ Cloudmasterd.picnic!
module Cloudmasterd::Helpers
class Syncer
def self.run
+ sync_memory
+ sync_state
+ sync_owners
+ end
+
+ def self.sync_memory
# Figure out the current amount of memory
freemem = 0
`func '*' call virt freemem`.split("\n").each{|mem| freemem = freemem + mem.to_i}
@@ -30,7 +36,9 @@ module Cloudmasterd::Helpers
else
memory[0].update_attribute(:free, freemem)
end
+ end
+ def self.sync_state
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)
@@ -64,6 +72,28 @@ module Cloudmasterd::Helpers
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
@@ -175,7 +205,7 @@ module Cloudmasterd::Controllers
raise output unless $?.success?
# Make the new host autostart
- `func "#{host}" call command run "ln -s /etc/xen/#{fqdn.split('.')[0]} /etc/xen/auto/"`
+ `func "#{host}" call command run "ln -s /etc/xen/#{fqdn} /etc/xen/auto/"`
end
# POST /koan