diff options
Diffstat (limited to 'cloudmasterd')
-rw-r--r-- | cloudmasterd/lib/cloudmasterd.rb | 59 |
1 files changed, 51 insertions, 8 deletions
diff --git a/cloudmasterd/lib/cloudmasterd.rb b/cloudmasterd/lib/cloudmasterd.rb index 934ce5d..ac091ad 100644 --- a/cloudmasterd/lib/cloudmasterd.rb +++ b/cloudmasterd/lib/cloudmasterd.rb @@ -10,6 +10,7 @@ require 'reststop' require 'everest' require 'restr' require 'xmlrpc/client' +require 'sqlite3' Camping.goes :Cloudmasterd Cloudmasterd.picnic! @@ -76,7 +77,24 @@ module Cloudmasterd::Helpers end end - + +module Cloudmasterd::Models + class Machine < Base; end + + class CreateTheBasics < V 1.0 + def self.up + create_table :cloudmasterd_machines do |t| + t.column :user_email, :string, :null => false + t.column :machine, :string, :limit => 255 + t.column :destination, :string, :limit => 255 + end + end + def self.down + drop_table :cloudmasterd_machines + end + end +end + module Cloudmasterd::Controllers class Koan < REST 'koan' # Retrieve the cobbler profile for the given profile name @@ -94,29 +112,39 @@ module Cloudmasterd::Controllers # run the appropriate koan command to create the given "fqdn" # on the given "host" and "vol_group" - def _koan(host, fqdn, repo, email) - puts "Creating machine for #{email}" - + def _koan(host, fqdn, repo) # Run the koan process func_cmd = "func \"#{host}\" call virt install #{repo} #{fqdn} True #{fqdn} /images" - puts `#{func_cmd}` + `#{func_cmd}` + raise "Func installation failed for host #{host} against repo #{fqdn}" unless $?.success? # Make the new host autostart func_cmd = "func \"#{host}\" call command run \"ln -s /etc/xen/#{fqdn} /etc/xen/auto/\"" - puts `#{func_cmd}` + `#{func_cmd}` + raise "Symbolic link creation failed for host #{host} against repo #{fqdn}" unless $?.success? end # POST /koan def create machine_fqdn = input.machine_fqdn repo = input.repo + email = input.email cobbler_profile = _get_cobbler_profile(machine_fqdn, repo) @host = _get_best_host(cobbler_profile["virt_file_size"], cobbler_profile["virt_ram"]) _koan(@host, machine_fqdn, repo) + + Machine.create :user_email => email, :machine => machine_fqdn, :destination => @host render :_koan end end + + class Cloud < REST 'cloud' + def list + @machines = Machine.find :all + render :cloud + end + end end module Cloudmasterd::Views @@ -140,6 +168,16 @@ module Cloudmasterd::Views end end end + + def cloud + @machines.each do |m| + div do + h1 m.user_email + p m.machine + p m.destination + end + end + end def _koan @host @@ -162,7 +200,12 @@ module Cloudmasterd::Views end end -# Required by picnic -def Cloudmasterd.create; end +def Cloudmasterd.create + ActiveRecord::Base.establish_connection( + :adapter => "sqlite3", + :database => "/var/lib/cloudmaster.db" + ) + Cloudmasterd::Models.create_schema :assume => (Cloudmasterd::Models::Machine.table_exists? ? 1.0 : 0.0) +end Cloudmasterd.start_picnic |