From 1bdfd2c9c90f08d8bfdd9aaebe8b558a09e08917 Mon Sep 17 00:00:00 2001 From: Matthew Hicks Date: Sat, 21 Jun 2008 13:34:15 -0400 Subject: Adding a db primer (for testing) More work around the model names and db structure --- cloudmasterd/lib/cloudmasterd.rb | 14 +++++++------- cloudmasterd/primedb.rb | 24 ++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 7 deletions(-) create mode 100755 cloudmasterd/primedb.rb (limited to 'cloudmasterd') diff --git a/cloudmasterd/lib/cloudmasterd.rb b/cloudmasterd/lib/cloudmasterd.rb index 90e8d8a..fb761f0 100644 --- a/cloudmasterd/lib/cloudmasterd.rb +++ b/cloudmasterd/lib/cloudmasterd.rb @@ -84,9 +84,9 @@ module Cloudmasterd::Models 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 + t.column :name, :string, :limit => 255 + t.column :email, :string, :null => false + t.column :cloud, :string, :limit => 255 end end def self.down @@ -131,7 +131,7 @@ module Cloudmasterd::Controllers @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 + Machine.create :name => machine_fqdn, :email => email, :cloud => @host render :_koan end end @@ -139,8 +139,8 @@ module Cloudmasterd::Controllers class Cloud < REST 'cloud' def list @machines = {} - Machine.find(:all, :select => "distinct user_email").map{|x| x.user_email}.each do |email| - @machines[email] = Machine.find(:all, :conditions => "user_email = '#{email}'") + Machine.find(:all, :select => "distinct email").map{|x| x.email}.each do |email| + @machines[email] = Machine.find(:all, :conditions => "email = '#{email}'") end render :cloud end @@ -175,7 +175,7 @@ module Cloudmasterd::Views h1 email ul do @machines[email].each do |machine| - li "#{machine.destination}: #{machine.machine}" + li "#{machine.name}: #{machine.cloud}" end end end diff --git a/cloudmasterd/primedb.rb b/cloudmasterd/primedb.rb new file mode 100755 index 0000000..866b91d --- /dev/null +++ b/cloudmasterd/primedb.rb @@ -0,0 +1,24 @@ +#!/usr/bin/ruby + +require 'rubygems' +require 'sqlite3' +require 'active_record' +require 'pp' + +ActiveRecord::Base.logger = Logger.new(STDERR) +ActiveRecord::Base.colorize_logging = false + +ActiveRecord::Base.establish_connection( + :adapter => "sqlite3", + :dbfile => "/var/lib/cloudmaster.db" +) + +class Machine < ActiveRecord::Base + set_table_name "cloudmasterd_machines" +end + +Machine.create(:name => "jboss-1.usersys.redhat.com", :email => "mhicks@redhat.com", :cloud => "cloud1.usersys.redhat.com") +Machine.create(:name => "jboss-2.usersys.redhat.com", :email => "mhicks@redhat.com", :cloud => "cloud1.usersys.redhat.com") +Machine.create(:name => "jboss-3.usersys.redhat.com", :email => "mhicks@redhat.com", :cloud => "cloud2.usersys.redhat.com") +Machine.create(:name => "alien-jboss-1.usersys.redhat.com", :email => "calfonso@redhat.com", :cloud => "cloud3.usersys.redhat.com") +Machine.create(:name => "alien-jboss-2.usersys.redhat.com", :email => "calfonso@redhat.com", :cloud => "cloud2.usersys.redhat.com") -- cgit