deltacloud aggregator rpm spec
by Mo Morsi
Attached is my first take at the aggregator rpm spec. The spec is much
cleaner, what is there is only what is needed, and I split the codebase
into two packages, the main package containing the standalone aggregator
application, and a 'httpd' subpackage (thinking of changing the name to
'daemons' or something) which provides the config / scripts needed to
get the services up and running.
It's a working copy, everything looks to be in place, but more
dependencies need to be added and I am in the process of testing it out.
-Mo
14 years, 3 months
[PATCH portal] Rails version and db config updates.
by jason.guiditta
This patch updates environment so portal will run on both F11 and F12
as well as adding sample config files to support mysql and sqlite. If
a developer/admin wants to use either, they can just rename them to
database.yml. Perhaps we can do the same thing with postgres and have no
versioned .yml file, always leave it to person installing to choose their
db of choice, but if we do that, it will be in a subsequent patch.
---
src/config/database.mysql | 48 ++++++++++++++++++++++++++++++++++++++++++++
src/config/database.sqlite | 25 ++++++++++++++++++++++
src/config/environment.rb | 2 +-
3 files changed, 74 insertions(+), 1 deletions(-)
create mode 100644 src/config/database.mysql
create mode 100644 src/config/database.sqlite
diff --git a/src/config/database.mysql b/src/config/database.mysql
new file mode 100644
index 0000000..3e39c57
--- /dev/null
+++ b/src/config/database.mysql
@@ -0,0 +1,48 @@
+# MySQL. Versions 4.1 and 5.0 are recommended.
+#
+# Install the MySQL driver:
+# gem install mysql
+# On Mac OS X:
+# sudo gem install mysql -- --with-mysql-dir=/usr/local/mysql
+# On Mac OS X Leopard:
+# sudo env ARCHFLAGS="-arch i386" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
+# This sets the ARCHFLAGS environment variable to your native architecture
+# On Windows:
+# gem install mysql
+# Choose the win32 build.
+# Install MySQL and put its /bin directory on your path.
+#
+# And be sure to use new-style password hashing:
+# http://dev.mysql.com/doc/refman/5.0/en/old-client.html
+development:
+ adapter: mysql
+ encoding: utf8
+ database: dc_development
+ pool: 5
+ username: dc
+ password: delta
+ host: localhost
+# socket: /var/lib/mysql/mysql.sock
+
+# Warning: The database defined as "test" will be erased and
+# re-generated from your development database when you run "rake".
+# Do not set this db to the same as development or production.
+test:
+ adapter: mysql
+ encoding: utf8
+ database: dc_test
+ pool: 5
+ username: dc
+ password: delta
+ host: localhost
+# socket: /var/lib/mysql/mysql.sock
+
+production:
+ adapter: mysql
+ encoding: utf8
+ database: dc_production
+ pool: 5
+ username: dc
+ password: delta
+ host: localhost
+# socket: /var/lib/mysql/mysql.sock
diff --git a/src/config/database.sqlite b/src/config/database.sqlite
new file mode 100644
index 0000000..4fd78e6
--- /dev/null
+++ b/src/config/database.sqlite
@@ -0,0 +1,25 @@
+# SQLite version 3.x
+# gem install sqlite3-ruby (not necessary on OS X Leopard)
+development:
+ adapter: sqlite3
+ database: db/development.sqlite3
+ pool: 5
+ timeout: 5000
+
+# Warning: The database defined as "test" will be erased and
+# re-generated from your development database when you run "rake".
+# Do not set this db to the same as development or production.
+test: &TEST
+ adapter: sqlite3
+ database: db/test.sqlite3
+ pool: 5
+ timeout: 5000
+
+production:
+ adapter: sqlite3
+ database: db/production.sqlite3
+ pool: 5
+ timeout: 5000
+
+cucumber:
+ <<: *TEST
\ No newline at end of file
diff --git a/src/config/environment.rb b/src/config/environment.rb
index 4396acc..d3d2e2f 100644
--- a/src/config/environment.rb
+++ b/src/config/environment.rb
@@ -20,7 +20,7 @@
# Be sure to restart your web server when you modify this file.
# Specifies gem version of Rails to use when vendor/rails is not present
-RAILS_GEM_VERSION = '2.3.2' unless defined? RAILS_GEM_VERSION
+RAILS_GEM_VERSION = '>= 2.3.2' unless defined? RAILS_GEM_VERSION
# Bootstrap the Rails environment, frameworks, and default configuration
require File.join(File.dirname(__FILE__), 'boot')
--
1.6.6
14 years, 3 months
[PATCH] Fixed extension bug in API
by Michal Fojtik
---
server/libexec/lib/sinatra/abstract_format.rb | 23 +++++++++++++++++++++++
server/libexec/server.rb | 3 +++
2 files changed, 26 insertions(+), 0 deletions(-)
create mode 100644 server/libexec/lib/sinatra/abstract_format.rb
diff --git a/server/libexec/lib/sinatra/abstract_format.rb b/server/libexec/lib/sinatra/abstract_format.rb
new file mode 100644
index 0000000..9dd58b0
--- /dev/null
+++ b/server/libexec/lib/sinatra/abstract_format.rb
@@ -0,0 +1,23 @@
+require 'pathname'
+
+module Rack
+ class AbstractFormat
+
+ def initialize(app, default = nil)
+ @app, @default = app, default
+ end
+
+ def call(env)
+ path = Pathname(env['PATH_INFO'])
+ return @app.call(env) unless ['.html', '.xml'].include?(path.extname)
+ env['PATH_INFO'] = path.to_s.sub(/#{path.extname}$/,'')
+ env['HTTP_ACCEPT'] = concat(env['HTTP_ACCEPT'], Rack::Mime.mime_type(path.extname, @default))
+ @app.call(env)
+ end
+
+ private
+ def concat(accept, type)
+ (accept || '').split(',').unshift(type).compact.join(',')
+ end
+ end
+end
diff --git a/server/libexec/server.rb b/server/libexec/server.rb
index 8185eff..a085f32 100644
--- a/server/libexec/server.rb
+++ b/server/libexec/server.rb
@@ -2,6 +2,7 @@ require 'rubygems'
require 'deltacloud'
require 'sinatra'
require 'sinatra/respond_to'
+require 'sinatra/abstract_format'
require 'erb'
require 'haml'
require 'open3'
@@ -24,6 +25,8 @@ module Sinatra
register Sinatra::RespondTo
end
+use Rack::AbstractFormat
+
# Common actions
#
--
1.6.6.2
14 years, 3 months
[PATCH 5/5] fixed controllers and views to work with new model.
by Scott Seago
Signed-off-by: Scott Seago <sseago(a)redhat.com>
---
src/app/controllers/instance_controller.rb | 18 ++---------
src/app/controllers/portal_pool_controller.rb | 13 +++++--
src/app/controllers/provider_controller.rb | 2 +-
src/app/models/instance.rb | 25 +++++++++++++--
src/app/models/instance_task.rb | 7 +++-
src/app/models/portal_pool.rb | 40 +++++++++++++++++++-----
src/app/models/provider.rb | 7 ++++-
src/app/views/instance/new.html.erb | 20 ++++++------
src/app/views/instance/show.html.erb | 2 +-
src/app/views/portal_pool/show.html.erb | 6 ++--
10 files changed, 92 insertions(+), 48 deletions(-)
diff --git a/src/app/controllers/instance_controller.rb b/src/app/controllers/instance_controller.rb
index 24127e1..8893286 100644
--- a/src/app/controllers/instance_controller.rb
+++ b/src/app/controllers/instance_controller.rb
@@ -32,12 +32,11 @@ class InstanceController < ApplicationController
def show
@instances = Instance.find(:all, :conditions => {:portal_pool_id => params[:id]})
@pool = PortalPool.find(params[:id])
- @provider = @pool.cloud_account.provider
end
def new
@instance = Instance.new({:portal_pool_id => params[:id]})
- _new(params[:provider])
+ @pool = PortalPool.find(params[:id])
end
def create
@@ -46,18 +45,18 @@ class InstanceController < ApplicationController
#FIXME: This should probably be in a transaction
if @instance.save
- @task = InstanceTask.new({:user => @instance.portal_pool.cloud_account.username,
+ @task = InstanceTask.new({:user => current_user,
:task_target => @instance,
:action => InstanceTask::ACTION_CREATE})
if @task.save
flash[:notice] = "Instance added."
redirect_to :controller => "portal_pool", :action => 'show', :id => @instance.portal_pool_id
else
- _new(params[:provider_id])
+ @pool = @instance.portal_pool
render :action => 'new'
end
else
- _new(params[:provider_id])
+ @pool = PortalPool.find((a)instance.portal_pool_id)
render :action => 'new'
end
end
@@ -82,13 +81,4 @@ class InstanceController < ApplicationController
def delete
end
- private
-
- def _new(provider)
- @flavors = Flavor.find(:all, :conditions => {:provider_id => provider})
- @images = Image.find(:all, :conditions => {:provider_id => provider})
- @realms = Realm.find(:all, :conditions => {:provider_id => provider})
- @provider_id = provider
- end
-
end
diff --git a/src/app/controllers/portal_pool_controller.rb b/src/app/controllers/portal_pool_controller.rb
index b06041c..ae45d02 100644
--- a/src/app/controllers/portal_pool_controller.rb
+++ b/src/app/controllers/portal_pool_controller.rb
@@ -27,10 +27,9 @@ class PortalPoolController < ApplicationController
end
def show
- @instances = Instance.find(:all, :conditions => {:portal_pool_id => params[:id]})
#FIXME: clean this up, many error cases here
@pool = PortalPool.find(params[:id])
- @provider = @pool.cloud_account.provider
+ @instances = @pool.instances
end
def new
@@ -41,10 +40,16 @@ class PortalPoolController < ApplicationController
def create
@account = CloudAccount.find_or_create(params[:account])
+ #FIXME: owner is set to current user for self-service account creation,
+ # but in the more general case we need a way for the admin to pick
+ # a user
+ # FIXME: automatically grant owner access rights to the pool
+ params[:portal_pool][:owner_id] = @current_user.id
#FIXME: This should probably be in a transaction
if @account.save
- @portal_pool = @account.portal_pools.build(params[:portal_pool])
- if @portal_pool.save && @portal_pool.populate_realms_and_images
+ @portal_pool = PortalPool.new(params[:portal_pool])
+ @portal_pool.cloud_accounts << @account
+ if @portal_pool.save && @portal_pool.populate_realms_and_images([@account])
flash[:notice] = "Pool added."
redirect_to :action => 'show', :id => @portal_pool.id
else
diff --git a/src/app/controllers/provider_controller.rb b/src/app/controllers/provider_controller.rb
index 947c63c..c969797 100644
--- a/src/app/controllers/provider_controller.rb
+++ b/src/app/controllers/provider_controller.rb
@@ -32,7 +32,7 @@ class ProviderController < ApplicationController
def new
@provider = Provider.new(params[:provider])
- if request.post? && @provider.save && @provider.populate_flavors
+ if request.post? && @provider.save && @provider.populate_hardware_profiles
flash[:notice] = "Provider added."
redirect_to :action => "show", :id => @provider
end
diff --git a/src/app/models/instance.rb b/src/app/models/instance.rb
index 83d463a..a528e4e 100644
--- a/src/app/models/instance.rb
+++ b/src/app/models/instance.rb
@@ -39,9 +39,9 @@ class Instance < ActiveRecord::Base
validates_presence_of :name
validates_uniqueness_of :name, :scope => :portal_pool_id
- # FIXME: for now, flavor is required, realm is optional, although for RHEV-M,
- # flavor may be optional too
- validates_presence_of :flavor_id
+ # FIXME: for now, hardware profile is required, realm is optional, although for RHEV-M,
+ # hardware profile may be optional too
+ validates_presence_of :hardware_profile_id
validates_presence_of :image_id
STATE_NEW = "new"
@@ -83,5 +83,24 @@ class Instance < ActiveRecord::Base
return task
end
+ def front_end_realm
+ if cloud_account.nil?
+ ""
+ else
+ cloud_account.provider.name + Realm::AGGREGATOR_REALM_PROVIDER_DELIMITER +
+ cloud_account.username + (realm.nil? ? "" :
+ (Realm::AGGREGATOR_REALM_ACCOUNT_DELIMITER +
+ realm.name))
+ end
+ end
+
+ def front_end_realm=(realm_name)
+ provider_name, tmpstr = realm_name.split(Realm::AGGREGATOR_REALM_PROVIDER_DELIMITER,2)
+ account_name, realm_name = tmpstr.split(Realm::AGGREGATOR_REALM_ACCOUNT_DELIMITER,2)
+ provider = Provider.find_by_name(provider_name)
+ self.cloud_account = provider.cloud_accounts.find_by_username(account_name)
+ self.realm = provider.realms.find_by_name(realm_name) unless realm_name.nil?
+ end
+
end
diff --git a/src/app/models/instance_task.rb b/src/app/models/instance_task.rb
index 88b2e5f..9da110b 100644
--- a/src/app/models/instance_task.rb
+++ b/src/app/models/instance_task.rb
@@ -44,8 +44,11 @@ class InstanceTask < Task
# automatic transitions from transient states.
def self.valid_actions_for_instance_state(state, instance, user=nil)
actions = []
- c_state = instance.portal_pool.cloud_account.connect.instance_state(state)
- if c_state
+ # FIXME: cloud_account won't always be set here, but we're requiring
+ # front end realm for now.
+ cloud_account = instance.cloud_account
+ c_state = cloud_account.connect.instance_state(state) unless cloud_account.nil?
+ if !cloud_account.nil? and c_state
transitions = c_state.transitions
transitions.each do |transition|
# FIXME if we allow actions based on the expected state after
diff --git a/src/app/models/portal_pool.rb b/src/app/models/portal_pool.rb
index c88e4df..1fd9dd4 100644
--- a/src/app/models/portal_pool.rb
+++ b/src/app/models/portal_pool.rb
@@ -29,12 +29,11 @@ class PortalPool < ActiveRecord::Base
has_many :hardware_profiles, :dependent => :destroy
- validates_presence_of :cloud_account_id
validates_presence_of :owner_id
validates_presence_of :name
validates_uniqueness_of :name, :scope => :owner_id
- validates_uniqueness_of :exported_as
+ validates_uniqueness_of :exported_as, :if => :exported_as
has_many :permissions, :as => :permission_object, :dependent => :destroy,
:include => [:role],
@@ -44,16 +43,20 @@ class PortalPool < ActiveRecord::Base
realm_list = []
cloud_accounts.each do |cloud_account|
prefix = cloud_account.provider.name +
- AGGREGATOR_REALM_PROVIDER_DELIMITER + cloud_account.username
+ Realm::AGGREGATOR_REALM_PROVIDER_DELIMITER +
+ cloud_account.username
+ realm_list << prefix
cloud_account.provider.realms.each do |realm|
- realm_list << prefix + AGGREGATOR_REALM_ACCOUNT_DELIMITER + realm.name
+ realm_list << prefix + Realm::AGGREGATOR_REALM_ACCOUNT_DELIMITER +
+ realm.name
end
end
+ realm_list
end
-
- def populate_realms_and_images
- cloud_accounts.each do |cloud_account|
+ # FIXME: for already-mapped accounts, update rather than add new
+ def populate_realms_and_images(accounts=cloud_accounts)
+ accounts.each do |cloud_account|
client = cloud_account.connect
realms = client.realms
if client.driver_name == "ec2"
@@ -77,10 +80,11 @@ class PortalPool < ActiveRecord::Base
end
images.each do |image|
#ignore if it exists
- #FIXME: we need to handle keeping in sync forupdates as well as
+ #FIXME: we need to handle keeping in sync for updates as well as
# account permissions
- unless Image.find_by_external_key_and_provider_id(image.id,
+ ar_image = Image.find_by_external_key_and_provider_id(image.id,
cloud_account.provider.id)
+ unless ar_image
ar_image = Image.new(:external_key => image.id,
:name => image.name ? image.name :
(image.description ? image.description :
@@ -89,6 +93,24 @@ class PortalPool < ActiveRecord::Base
:provider_id => cloud_account.provider.id)
ar_image.save!
end
+ # FIXME: what do we ue for external_key values for front end images?
+ # FIXME: this will break if multiple imported accounts (from different
+ # providers) use the same external key
+ front_end_image = Image.new(:external_key => ar_image.external_key,
+ :name => ar_image.name,
+ :architecture => ar_image.architecture,
+ :portal_pool_id => id)
+ front_end_image.save!
+ end
+ cloud_account.provider.hardware_profiles.each do |hardware_profile|
+ front_hardware_profile = HardwareProfile.new(:external_key =>
+ hardware_profile.external_key,
+ :name => hardware_profile.name,
+ :memory => hardware_profile.memory,
+ :storage => hardware_profile.storage,
+ :architecture => hardware_profile.architecture,
+ :portal_pool_id => id)
+ front_hardware_profile.save!
end
end
end
diff --git a/src/app/models/provider.rb b/src/app/models/provider.rb
index 14ffd80..650cc4d 100644
--- a/src/app/models/provider.rb
+++ b/src/app/models/provider.rb
@@ -48,7 +48,8 @@ class Provider < ActiveRecord::Base
end
def populate_hardware_profiles
- hardware_profiles = connect.hardware_profiles
+ # FIXME: once API has hw profiles, change the below
+ hardware_profiles = connect.flavors
# FIXME: this should probably be in the same transaction as provider.save
self.transaction do
hardware_profiles.each do |hardware_profile|
@@ -63,6 +64,10 @@ class Provider < ActiveRecord::Base
end
end
+ def portal_pools
+ cloud_accounts.collect {|account| account.portal_pools}.flatten
+ end
+
# TODO: implement or remove - this is meant to contain a hash of
# supported cloud_types to use in populating form, though if we
# infer that field, we don't need this.
diff --git a/src/app/views/instance/new.html.erb b/src/app/views/instance/new.html.erb
index 7acb09e..1ca2024 100644
--- a/src/app/views/instance/new.html.erb
+++ b/src/app/views/instance/new.html.erb
@@ -5,25 +5,25 @@
<% form_tag :action => 'create' do-%>
<ul>
<li><label>Name<span>Name for this new Instance</span></label><%= text_field :instance, :name, :class => "txtfield" %></li>
- <% if @flavors.size > 0 %>
- <li><label>Flavor<span>Pick your flavor</span></label>
- <%= select("instance", "flavor_id", @flavors.collect {|p| [ p.name, p.id ] }, { :include_blank => true }) %>
+ <% if @pool.hardware_profiles.size > 0 %>
+ <li><label>Hardware Profile<span>Pick your hardware profile</span></label>
+ <%= select("instance", "hardware_profile_id",
+ @pool.hardware_profiles.collect {|p| [ p.name, p.id ] },
+ { :include_blank => true }) %>
</li>
<% end %>
- <% if @images.size > 0 %>
+ <% if @pool.images.size > 0 %>
<li><label>Image<span>Choose a bundled image to use</span></label>
- <%= select("instance", "image_id", @images.collect {|i| [ truncate(i.name, 29, '...'), i.id ] }, { :include_blank => true }) %>
+ <%= select("instance", "image_id", @pool.images.collect {|i| [ truncate(i.name, 29, '...'), i.id ] }, { :include_blank => true }) %>
</li>
<% end %>
- <% if @realms.size > 0 %>
+ <% if @pool.realms.size > 0 %>
<li><label>Realm<span>Choose a realm</span></label>
- <%= select("instance", "realm_id", @realms.collect {|r| [ r.name, r.id ] }, { :include_blank => true }) %>
+ <%= select("instance", "front_end_realm", @pool.realms, { :include_blank => false }) %>
</li>
<% end %>
</ul>
- <input id="instance_provider_id" type="hidden" value="<%=@provider_id%>" name="provider_id"/>
- <%#= hidden_field :provider, :provider_id %>
<%= hidden_field :instance, :portal_pool_id %>
<%= submit_tag "Save", :class => "submit" %>
<% end %>
-</div>
\ No newline at end of file
+</div>
diff --git a/src/app/views/instance/show.html.erb b/src/app/views/instance/show.html.erb
index 2a550d8..a2bfe2f 100644
--- a/src/app/views/instance/show.html.erb
+++ b/src/app/views/instance/show.html.erb
@@ -26,4 +26,4 @@
</tbody>
</table>
<% end %>
-<%= link_to "Add a new instance", :controller => "instance", :action => "new", :id => @pool, :provider => @provider%>
+<%= link_to "Add a new instance", :controller => "instance", :action => "new", :id => @pool %>
diff --git a/src/app/views/portal_pool/show.html.erb b/src/app/views/portal_pool/show.html.erb
index 998b27f..d649199 100644
--- a/src/app/views/portal_pool/show.html.erb
+++ b/src/app/views/portal_pool/show.html.erb
@@ -7,7 +7,7 @@
<th scope="col">Actions</th>
<th scope="col">Name</th>
<th scope="col">State</th>
- <th scope="col">Flavor</th>
+ <th scope="col">Hardware Profile</th>
<th scope="col">Image</th>
</tr>
</thead>
@@ -28,11 +28,11 @@
</td>
<td><%= instance.name %></td>
<td><%= instance.state %></td>
- <td><%= instance.flavor.name %></td>
+ <td><%= instance.hardware_profile.name %></td>
<td><%= instance.image.name %></td>
</tr>
<% } %>
</tbody>
</table>
<% end %>
-<%= link_to "Add a new instance", {:controller => "instance", :action => "new", :id => @pool, :provider => @provider}, :class=>"actionlink"%>
+<%= link_to "Add a new instance", {:controller => "instance", :action => "new", :id => @pool}, :class=>"actionlink"%>
--
1.6.2.5
14 years, 4 months
[PATCH] Cleaned up front end/back end resource mapping
by Scott Seago
Cleaned up front end/back end resource mapping a bit and added some validation rules. Also added a method to pool to aggregate the realm list.
Signed-off-by: Scott Seago <sseago(a)redhat.com>
---
src/app/models/hardware_profile.rb | 37 ++++++++++++++++---
src/app/models/image.rb | 39 +++++++++++++++++---
src/app/models/instance.rb | 8 +---
src/app/models/portal_pool.rb | 15 ++++++++
src/app/models/realm.rb | 2 +
.../20090804135630_create_hardware_profiles.rb | 6 ++-
src/db/migrate/20090804140143_create_images.rb | 7 +++-
src/db/migrate/20090804142049_create_instances.rb | 2 -
src/test/fixtures/hardware_profiles.yml | 10 +++---
src/test/fixtures/images.yml | 2 +-
src/test/fixtures/instances.yml | 2 -
11 files changed, 100 insertions(+), 30 deletions(-)
diff --git a/src/app/models/hardware_profile.rb b/src/app/models/hardware_profile.rb
index 65fa12f..fdcdd3f 100644
--- a/src/app/models/hardware_profile.rb
+++ b/src/app/models/hardware_profile.rb
@@ -24,21 +24,22 @@ class HardwareProfile < ActiveRecord::Base
has_many :provider_instances, :class_name => "Instance",
:foreign_key => "provider_hardware_profile_id"
belongs_to :provider
+ belongs_to :portal_pool
- has_and_belongs_to_many :master_hardware_profiles,
+ has_and_belongs_to_many :aggregator_hardware_profiles,
:class_name => "HardwareProfile",
:join_table => "hardware_profile_map",
:foreign_key => "provider_hardware_profile_id",
- :association_foreign_key => "master_hardware_profile_id"
+ :association_foreign_key => "aggregator_hardware_profile_id"
has_and_belongs_to_many :provider_hardware_profiles,
:class_name => "HardwareProfile",
:join_table => "hardware_profile_map",
- :foreign_key => "master_hardware_profile_id",
+ :foreign_key => "aggregator_hardware_profile_id",
:association_foreign_key => "provider_hardware_profile_id"
validates_presence_of :external_key
- validates_uniqueness_of :external_key, :scope => :provider_id
+ validates_uniqueness_of :external_key, :scope => [:provider_id, :portal_pool_id]
validates_presence_of :name
@@ -47,5 +48,31 @@ class HardwareProfile < ActiveRecord::Base
validates_presence_of :memory
validates_numericality_of :memory
- validates_presence_of :architecture
+ validates_presence_of :architecture, :if => :provider
+
+ def validate
+ if (provider.nil? and portal_pool.nil?)
+ if !aggregator_hardware_profiles.empty?
+ errors.add(:aggregator_hardware_profiles,
+ "Aggregator profiles are not allowed for custom Instance profiles")
+ end
+ if !provider_hardware_profiles.empty?
+ errors.add(:provider_hardware_profiles,
+ "Provider profiles are not allowed for custom Instance profiles")
+ end
+ elsif (!provider.nil? and !portal_pool.nil?)
+ errors.add(:provider, "provider or pool must be blank")
+ errors.add(:portal_pool, "provider or pool must be blank")
+ elsif provider.nil?
+ if !aggregator_hardware_profiles.empty?
+ errors.add(:aggregator_hardware_profiles,
+ "Aggregator profiles only allowed for provider profiles")
+ end
+ elsif portal_pool.nil?
+ if !provider_hardware_profiles.empty?
+ errors.add(:provider_hardware_profiles,
+ "Provider profiles only allowed for aggregator profiles")
+ end
+ end
+ end
end
diff --git a/src/app/models/image.rb b/src/app/models/image.rb
index 098d09b..894d4b3 100644
--- a/src/app/models/image.rb
+++ b/src/app/models/image.rb
@@ -22,17 +22,44 @@
class Image < ActiveRecord::Base
has_many :instances
belongs_to :provider
+ belongs_to :portal_pool
- belongs_to :master_image, :class_name => "Image",
- :foreign_key => "master_image_id"
- has_many :provider_images, :class_name => "Image",
- :foreign_key => "master_image_id"
+ has_and_belongs_to_many :aggregator_images,
+ :class_name => "Image",
+ :join_table => "image_map",
+ :foreign_key => "provider_image_id",
+ :association_foreign_key => "aggregator_image_id"
+
+ has_and_belongs_to_many :provider_images,
+ :class_name => "Image",
+ :join_table => "image_map",
+ :foreign_key => "aggregator_image_id",
+ :association_foreign_key => "provider_image_id"
validates_presence_of :external_key
- validates_uniqueness_of :external_key, :scope => :provider_id
+ validates_uniqueness_of :external_key, :scope => [:provider_id, :portal_pool_id]
validates_presence_of :name
- validates_presence_of :architecture
+ validates_presence_of :architecture, :if => :provider
+ def validate
+ if (provider.nil? and portal_pool.nil?)
+ errors.add(:provider, "provider or pool must be specified")
+ errors.add(:portal_pool, "provider or pool must be specified")
+ elsif (!provider.nil? and !portal_pool.nil?)
+ errors.add(:provider, "provider or pool must be blank")
+ errors.add(:portal_pool, "provider or pool must be blank")
+ elsif provider.nil?
+ if !aggregator_images.empty?
+ errors.add(:aggregator_images,
+ "Aggregator image only allowed for provider images")
+ end
+ elsif portal_pool.nil?
+ if !provider_images.empty?
+ errors.add(:provider_images,
+ "Provider images only allowed for aggregator images")
+ end
+ end
+ end
end
diff --git a/src/app/models/instance.rb b/src/app/models/instance.rb
index 6e4241c..83d463a 100644
--- a/src/app/models/instance.rb
+++ b/src/app/models/instance.rb
@@ -24,16 +24,12 @@ class Instance < ActiveRecord::Base
belongs_to :cloud_account
belongs_to :hardware_profile
- belongs_to :provider_hardware_profile, :class_name => "HardwareProfile",
- :foreign_key => "provider_hardware_profile_id"
-
belongs_to :image
- belongs_to :provider_image, :class_name => "Image",
- :foreign_key => "provider_image_id"
-
belongs_to :realm
validates_presence_of :portal_pool_id
+ validates_presence_of :hardware_profile_id
+ validates_presence_of :image_id
#validates_presence_of :external_key
# TODO: can we do uniqueness validation on indirect association
diff --git a/src/app/models/portal_pool.rb b/src/app/models/portal_pool.rb
index 0f0c42b..c88e4df 100644
--- a/src/app/models/portal_pool.rb
+++ b/src/app/models/portal_pool.rb
@@ -25,6 +25,9 @@ class PortalPool < ActiveRecord::Base
has_many :instances, :dependent => :destroy
belongs_to :owner, :class_name => "User", :foreign_key => "owner_id"
+ has_many :images, :dependent => :destroy
+ has_many :hardware_profiles, :dependent => :destroy
+
validates_presence_of :cloud_account_id
@@ -37,6 +40,18 @@ class PortalPool < ActiveRecord::Base
:include => [:role],
:order => "permissions.id ASC"
+ def realms
+ realm_list = []
+ cloud_accounts.each do |cloud_account|
+ prefix = cloud_account.provider.name +
+ AGGREGATOR_REALM_PROVIDER_DELIMITER + cloud_account.username
+ cloud_account.provider.realms.each do |realm|
+ realm_list << prefix + AGGREGATOR_REALM_ACCOUNT_DELIMITER + realm.name
+ end
+ end
+ end
+
+
def populate_realms_and_images
cloud_accounts.each do |cloud_account|
client = cloud_account.connect
diff --git a/src/app/models/realm.rb b/src/app/models/realm.rb
index f2cbee9..07bb306 100644
--- a/src/app/models/realm.rb
+++ b/src/app/models/realm.rb
@@ -30,4 +30,6 @@ class Realm < ActiveRecord::Base
validates_presence_of :name
+ AGGREGATOR_REALM_PROVIDER_DELIMITER = ":"
+ AGGREGATOR_REALM_ACCOUNT_DELIMITER = "/"
end
diff --git a/src/db/migrate/20090804135630_create_hardware_profiles.rb b/src/db/migrate/20090804135630_create_hardware_profiles.rb
index 97eea9a..0c4209f 100644
--- a/src/db/migrate/20090804135630_create_hardware_profiles.rb
+++ b/src/db/migrate/20090804135630_create_hardware_profiles.rb
@@ -28,17 +28,19 @@ class CreateHardwareProfiles < ActiveRecord::Migration
t.float :storage, :null => false
t.string :architecture, :null => false
t.integer :provider_id
+ t.integer :portal_pool_id
t.integer :lock_version, :default => 0
t.timestamps
end
create_table "hardware_profile_map", :force => true, :id => false do |t|
- t.column "master_hardware_profile_id", :integer
+ t.column "aggregator_hardware_profile_id", :integer
t.column "provider_hardware_profile_id", :integer
-end
+ end
end
def self.down
+ drop_table :hardware_profile_map
drop_table :hardware_profiles
end
end
diff --git a/src/db/migrate/20090804140143_create_images.rb b/src/db/migrate/20090804140143_create_images.rb
index 986c997..0520c73 100644
--- a/src/db/migrate/20090804140143_create_images.rb
+++ b/src/db/migrate/20090804140143_create_images.rb
@@ -26,13 +26,18 @@ class CreateImages < ActiveRecord::Migration
t.string :name, :null => false, :limit => 1024
t.string :architecture, :null => false
t.integer :provider_id
- t.integer :master_image_id
+ t.integer :portal_pool_id
t.integer :lock_version, :default => 0
t.timestamps
end
+ create_table "image_map", :force => true, :id => false do |t|
+ t.column "aggregator_image_id", :integer
+ t.column "provider_image_id", :integer
+ end
end
def self.down
+ drop_table :image_map
drop_table :images
end
end
diff --git a/src/db/migrate/20090804142049_create_instances.rb b/src/db/migrate/20090804142049_create_instances.rb
index 2880e85..9cd76d4 100644
--- a/src/db/migrate/20090804142049_create_instances.rb
+++ b/src/db/migrate/20090804142049_create_instances.rb
@@ -25,9 +25,7 @@ class CreateInstances < ActiveRecord::Migration
t.string :external_key
t.string :name, :null => false, :limit => 1024
t.integer :hardware_profile_id, :null => false
- t.integer :provider_hardware_profile_id
t.integer :image_id, :null => false
- t.integer :provider_image_id
t.integer :realm_id
t.integer :portal_pool_id, :null => false
t.integer :cloud_account_id
diff --git a/src/test/fixtures/hardware_profiles.yml b/src/test/fixtures/hardware_profiles.yml
index cc70c3e..638aa8d 100644
--- a/src/test/fixtures/hardware_profiles.yml
+++ b/src/test/fixtures/hardware_profiles.yml
@@ -46,32 +46,32 @@ m1_small_frontend:
memory: 1.7
storage: 160
architecture: i386
- provider_hardware_profiles: m1_small_frontend
+ provider_hardware_profiles: m1_small_backend
m1_large_frontend:
external_key: m1-large
name: m1-large
memory: 7.5
storage: 850
architecture: x86_64
- provider_hardware_profiles: m1_large_frontend
+ provider_hardware_profiles: m1_large_backend
m1_xlarge_frontend:
external_key: m1-xlarge
name: m1-xlarge
memory: 15
storage: 1690
architecture: x86_64
- provider_hardware_profiles: m1_xlarge_frontend
+ provider_hardware_profiles: m1_xlarge_backend
c1_medium_frontend:
external_key: c1-medium
name: c1-medium
memory: 1.7
storage: 350
architecture: x86_64
- provider_hardware_profiles: c1_medium_frontend
+ provider_hardware_profiles: c1_medium_backend
c1_xlarge_frontend:
external_key: c1-xlarge
name: c1-xlarge
memory: 7
storage: 1690
architecture: x86_64
- provider_hardware_profiles: c1_xlarge_frontend
+ provider_hardware_profiles: c1_xlarge_backend
diff --git a/src/test/fixtures/images.yml b/src/test/fixtures/images.yml
index f9f2677..bc7d135 100644
--- a/src/test/fixtures/images.yml
+++ b/src/test/fixtures/images.yml
@@ -14,4 +14,4 @@ fedora_13_image_frontend:
external_key: fedora_13
name: fedora_13
architecture: x86_64
- provider_images: fedora_13_image_frontend
+ provider_images: fedora_13_image_backend
diff --git a/src/test/fixtures/instances.yml b/src/test/fixtures/instances.yml
index 1b7c84b..5c781fa 100644
--- a/src/test/fixtures/instances.yml
+++ b/src/test/fixtures/instances.yml
@@ -9,9 +9,7 @@ test_instance:
external_key: test_instance
name: test_instance
hardware_profile: c1_xlarge_frontend
- provider_hardware_profile: c1_xlarge_backend
image: fedora_13_image_frontend
- provider_image: fedora_13_image_backend
realm: us_realm
portal_pool: test_pool
cloud_account: mock_account
--
1.6.0.6
14 years, 4 months
[PATCH 2/2] first round of model changes for new cloud aggregator design
by Scott Seago
This is part of an overall redesign of the codebase. The most significant change
is that a pool is now made up of one or more "back end" (or provider) accounts.
Initially a user will have to pick a back end account (via the selection of a
realm), but ultimately provider account selection will be optional, and the
scheduler will automatically choose a back end account for each instance.
In addition resources such as images or hardware profiles will be mapped from
front end to back end clouds so that pool-specific images and hardware profiles
chosen by the user will be mapped to the appropriate resources for whichever
back-end cloud account ultimately receives the 'new instance' request.
1) the full hardware profile model is not included -- this is roughly the old flavor model renamed to 'hardware profile'
2) images and hardware profiles do not reflect the ability to map back-end images and profiles of multiple architectures to a single front end image or profile.
Signed-off-by: Scott Seago <sseago(a)redhat.com>
---
src/app/models/cloud_account.rb | 8 +--
src/app/models/flavor.rb | 39 ----------
src/app/models/hardware_profile.rb | 51 +++++++++++++
src/app/models/image.rb | 5 +-
src/app/models/instance.rb | 10 +++-
src/app/models/permission.rb | 2 +-
src/app/models/{user.rb => pool_account.rb} | 11 ++-
src/app/models/portal_pool.rb | 75 ++++++++++---------
src/app/models/provider.rb | 21 +++---
src/app/models/{user.rb => quota.rb} | 5 +-
src/app/models/user.rb | 3 +
...al_pools.rb => 20090802000000_create_quotas.rb} | 17 +++--
.../migrate/20090803141507_create_portal_pools.rb | 6 ++-
... => 20090804135630_create_hardware_profiles.rb} | 13 +++-
src/db/migrate/20090804140143_create_images.rb | 3 +-
src/db/migrate/20090804142049_create_instances.rb | 5 +-
...s.rb => 20091215182906_create_pool_accounts.rb} | 9 ++-
src/test/fixtures/cloud_accounts.yml | 4 +
src/test/fixtures/hardware_profiles.yml | 77 ++++++++++++++++++++
src/test/fixtures/images.yml | 10 +++
src/test/fixtures/instances.yml | 13 ++++
src/test/fixtures/permissions.yml | 8 ++
src/test/fixtures/pool_accounts.yml | 10 +++
src/test/fixtures/portal_pools.yml | 4 +
src/test/fixtures/providers.yml | 4 +
src/test/fixtures/{flavors.yml => quotas.yml} | 2 +
src/test/fixtures/realms.yml | 8 ++
src/test/fixtures/users.yml | 8 ++
.../{flavor_test.rb => hardware_profile_test.rb} | 0
.../unit/{flavor_test.rb => pool_account_test.rb} | 2 +-
src/test/unit/{flavor_test.rb => quota_test.rb} | 2 +-
31 files changed, 316 insertions(+), 119 deletions(-)
delete mode 100644 src/app/models/flavor.rb
create mode 100644 src/app/models/hardware_profile.rb
copy src/app/models/{user.rb => pool_account.rb} (80%)
copy src/app/models/{user.rb => quota.rb} (92%)
copy src/db/migrate/{20090803141507_create_portal_pools.rb => 20090802000000_create_quotas.rb} (72%)
rename src/db/migrate/{20090804135630_create_flavors.rb => 20090804135630_create_hardware_profiles.rb} (78%)
copy src/db/migrate/{20090803141507_create_portal_pools.rb => 20091215182906_create_pool_accounts.rb} (84%)
create mode 100644 src/test/fixtures/hardware_profiles.yml
create mode 100644 src/test/fixtures/pool_accounts.yml
rename src/test/fixtures/{flavors.yml => quotas.yml} (75%)
copy src/test/unit/{flavor_test.rb => hardware_profile_test.rb} (100%)
copy src/test/unit/{flavor_test.rb => pool_account_test.rb} (69%)
rename src/test/unit/{flavor_test.rb => quota_test.rb} (71%)
diff --git a/src/app/models/cloud_account.rb b/src/app/models/cloud_account.rb
index afb4623..a753e6e 100644
--- a/src/app/models/cloud_account.rb
+++ b/src/app/models/cloud_account.rb
@@ -21,14 +21,12 @@
class CloudAccount < ActiveRecord::Base
belongs_to :provider
- has_many :portal_pools, :dependent => :destroy
+ has_many :pool_accounts, :dependent => :destroy
+ has_many :portal_pools, :through => :pool_accounts
+ has_many :instances
# what form does the account quota take?
- # we aren't yet defining the local user object
- # has_many :portal_users
-
-
validates_presence_of :provider_id
validates_presence_of :username
diff --git a/src/app/models/flavor.rb b/src/app/models/flavor.rb
deleted file mode 100644
index e518fd3..0000000
--- a/src/app/models/flavor.rb
+++ /dev/null
@@ -1,39 +0,0 @@
-#
-# Copyright (C) 2009 Red Hat, Inc.
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; version 2 of the License.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-# MA 02110-1301, USA. A copy of the GNU General Public License is
-# also available at http://www.gnu.org/copyleft/gpl.html.
-
-# Filters added to this controller apply to all controllers in the application.
-# Likewise, all the methods added will be available for all controllers.
-
-class Flavor < ActiveRecord::Base
- has_many :instances
- belongs_to :provider
-
- validates_presence_of :provider_id
-
- validates_presence_of :external_key
- validates_uniqueness_of :external_key, :scope => :provider_id
-
- validates_presence_of :name
-
- validates_presence_of :storage
- validates_numericality_of :storage
- validates_presence_of :memory
- validates_numericality_of :memory
-
- validates_presence_of :architecture
-end
diff --git a/src/app/models/hardware_profile.rb b/src/app/models/hardware_profile.rb
new file mode 100644
index 0000000..65fa12f
--- /dev/null
+++ b/src/app/models/hardware_profile.rb
@@ -0,0 +1,51 @@
+#
+# Copyright (C) 2009 Red Hat, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+# MA 02110-1301, USA. A copy of the GNU General Public License is
+# also available at http://www.gnu.org/copyleft/gpl.html.
+
+# Filters added to this controller apply to all controllers in the application.
+# Likewise, all the methods added will be available for all controllers.
+
+class HardwareProfile < ActiveRecord::Base
+ has_many :instances
+ has_many :provider_instances, :class_name => "Instance",
+ :foreign_key => "provider_hardware_profile_id"
+ belongs_to :provider
+
+ has_and_belongs_to_many :master_hardware_profiles,
+ :class_name => "HardwareProfile",
+ :join_table => "hardware_profile_map",
+ :foreign_key => "provider_hardware_profile_id",
+ :association_foreign_key => "master_hardware_profile_id"
+
+ has_and_belongs_to_many :provider_hardware_profiles,
+ :class_name => "HardwareProfile",
+ :join_table => "hardware_profile_map",
+ :foreign_key => "master_hardware_profile_id",
+ :association_foreign_key => "provider_hardware_profile_id"
+
+ validates_presence_of :external_key
+ validates_uniqueness_of :external_key, :scope => :provider_id
+
+ validates_presence_of :name
+
+ validates_presence_of :storage
+ validates_numericality_of :storage
+ validates_presence_of :memory
+ validates_numericality_of :memory
+
+ validates_presence_of :architecture
+end
diff --git a/src/app/models/image.rb b/src/app/models/image.rb
index a69aaf2..098d09b 100644
--- a/src/app/models/image.rb
+++ b/src/app/models/image.rb
@@ -23,7 +23,10 @@ class Image < ActiveRecord::Base
has_many :instances
belongs_to :provider
- validates_presence_of :provider_id
+ belongs_to :master_image, :class_name => "Image",
+ :foreign_key => "master_image_id"
+ has_many :provider_images, :class_name => "Image",
+ :foreign_key => "master_image_id"
validates_presence_of :external_key
validates_uniqueness_of :external_key, :scope => :provider_id
diff --git a/src/app/models/instance.rb b/src/app/models/instance.rb
index a2cb01a..6e4241c 100644
--- a/src/app/models/instance.rb
+++ b/src/app/models/instance.rb
@@ -21,8 +21,16 @@
class Instance < ActiveRecord::Base
belongs_to :portal_pool
- belongs_to :flavor
+ belongs_to :cloud_account
+
+ belongs_to :hardware_profile
+ belongs_to :provider_hardware_profile, :class_name => "HardwareProfile",
+ :foreign_key => "provider_hardware_profile_id"
+
belongs_to :image
+ belongs_to :provider_image, :class_name => "Image",
+ :foreign_key => "provider_image_id"
+
belongs_to :realm
validates_presence_of :portal_pool_id
diff --git a/src/app/models/permission.rb b/src/app/models/permission.rb
index 7c2bd9c..733cb0a 100644
--- a/src/app/models/permission.rb
+++ b/src/app/models/permission.rb
@@ -19,8 +19,8 @@
class Permission < ActiveRecord::Base
belongs_to :pool
-
belongs_to :role
+ belongs_to :user
validates_presence_of :pool_id
validates_presence_of :role_id
diff --git a/src/app/models/user.rb b/src/app/models/pool_account.rb
similarity index 80%
copy from src/app/models/user.rb
copy to src/app/models/pool_account.rb
index cd49d32..2ba8de7 100644
--- a/src/app/models/user.rb
+++ b/src/app/models/pool_account.rb
@@ -1,5 +1,5 @@
#
-# Copyright (C) 2009 Red Hat, Inc.
+# Copyright (C) 2010 Red Hat, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -18,7 +18,12 @@
# Filters added to this controller apply to all controllers in the application.
# Likewise, all the methods added will be available for all controllers.
+class PoolAccount < ActiveRecord::Base
+ belongs_to :cloud_account
+ belongs_to :portal_pool
+ belongs_to :quota
+
+ validates_presence_of :cloud_account_id
+ validates_presence_of :portal_pool_id
-class User < ActiveRecord::Base
- acts_as_authentic
end
diff --git a/src/app/models/portal_pool.rb b/src/app/models/portal_pool.rb
index 6f4084b..0f0c42b 100644
--- a/src/app/models/portal_pool.rb
+++ b/src/app/models/portal_pool.rb
@@ -20,55 +20,60 @@
# Likewise, all the methods added will be available for all controllers.
class PortalPool < ActiveRecord::Base
- belongs_to :cloud_account
+ has_many :pool_accounts, :dependent => :destroy
+ has_many :cloud_accounts, :through => :pool_accounts
has_many :instances, :dependent => :destroy
+ belongs_to :owner, :class_name => "User", :foreign_key => "owner_id"
- # what form does the pool quota take?
validates_presence_of :cloud_account_id
+ validates_presence_of :owner_id
validates_presence_of :name
- validates_uniqueness_of :name, :scope => :cloud_account_id
+ validates_uniqueness_of :name, :scope => :owner_id
+ validates_uniqueness_of :exported_as
has_many :permissions, :as => :permission_object, :dependent => :destroy,
:include => [:role],
:order => "permissions.id ASC"
def populate_realms_and_images
- client = cloud_account.connect
- realms = client.realms
- if client.driver_name == "ec2"
- images = client.images(:owner_id=>:self)
- else
- images = client.images
- end
- # FIXME: this should probably be in the same transaction as portal_pool.save
- self.transaction do
- realms.each do |realm|
- #ignore if it exists
- #FIXME: we need to handle keeping in sync forupdates as well as
- # account permissions
- unless Realm.find_by_external_key_and_provider_id(realm.id,
- cloud_account.provider.id)
- ar_realm = Realm.new(:external_key => realm.id,
- :name => realm.name ? realm.name : realm.id,
- :provider_id => cloud_account.provider.id)
- ar_realm.save!
- end
+ cloud_accounts.each do |cloud_account|
+ client = cloud_account.connect
+ realms = client.realms
+ if client.driver_name == "ec2"
+ images = client.images(:owner_id=>:self)
+ else
+ images = client.images
end
- images.each do |image|
- #ignore if it exists
- #FIXME: we need to handle keeping in sync forupdates as well as
- # account permissions
- unless Image.find_by_external_key_and_provider_id(image.id,
+ # FIXME: this should probably be in the same transaction as portal_pool.save
+ self.transaction do
+ realms.each do |realm|
+ #ignore if it exists
+ #FIXME: we need to handle keeping in sync forupdates as well as
+ # account permissions
+ unless Realm.find_by_external_key_and_provider_id(realm.id,
+ cloud_account.provider.id)
+ ar_realm = Realm.new(:external_key => realm.id,
+ :name => realm.name ? realm.name : realm.id,
+ :provider_id => cloud_account.provider.id)
+ ar_realm.save!
+ end
+ end
+ images.each do |image|
+ #ignore if it exists
+ #FIXME: we need to handle keeping in sync forupdates as well as
+ # account permissions
+ unless Image.find_by_external_key_and_provider_id(image.id,
cloud_account.provider.id)
- ar_image = Image.new(:external_key => image.id,
- :name => image.name ? image.name :
- (image.description ? image.description :
- image.id),
- :architecture => image.architecture,
- :provider_id => cloud_account.provider.id)
- ar_image.save!
+ ar_image = Image.new(:external_key => image.id,
+ :name => image.name ? image.name :
+ (image.description ? image.description :
+ image.id),
+ :architecture => image.architecture,
+ :provider_id => cloud_account.provider.id)
+ ar_image.save!
+ end
end
end
end
diff --git a/src/app/models/provider.rb b/src/app/models/provider.rb
index dab9fee..14ffd80 100644
--- a/src/app/models/provider.rb
+++ b/src/app/models/provider.rb
@@ -23,10 +23,9 @@ class Provider < ActiveRecord::Base
require 'util/deltacloud'
has_many :cloud_accounts, :dependent => :destroy
- has_many :flavors, :dependent => :destroy
+ has_many :hardware_profiles, :dependent => :destroy
has_many :images, :dependent => :destroy
has_many :realms, :dependent => :destroy
- has_many :portal_pools, :through=>:cloud_accounts
validates_presence_of :name
validates_uniqueness_of :name
@@ -48,18 +47,18 @@ class Provider < ActiveRecord::Base
end
end
- def populate_flavors
- flavors = connect.flavors
+ def populate_hardware_profiles
+ hardware_profiles = connect.hardware_profiles
# FIXME: this should probably be in the same transaction as provider.save
self.transaction do
- flavors.each do |flavor|
- ar_flavor = Flavor.new(:external_key => flavor.id,
- :name => flavor.name ? flavor.name : flavor.id,
- :memory => flavor.memory,
- :storage => flavor.storage,
- :architecture => flavor.architecture,
+ hardware_profiles.each do |hardware_profile|
+ ar_hardware_profile = HardwareProfile.new(:external_key => hardware_profile.id,
+ :name => hardware_profile.name ? hardware_profile.name : hardware_profile.id,
+ :memory => hardware_profile.memory,
+ :storage => hardware_profile.storage,
+ :architecture => hardware_profile.architecture,
:provider_id => id)
- ar_flavor.save!
+ ar_hardware_profile.save!
end
end
end
diff --git a/src/app/models/user.rb b/src/app/models/quota.rb
similarity index 92%
copy from src/app/models/user.rb
copy to src/app/models/quota.rb
index cd49d32..28d1943 100644
--- a/src/app/models/user.rb
+++ b/src/app/models/quota.rb
@@ -19,6 +19,7 @@
# Filters added to this controller apply to all controllers in the application.
# Likewise, all the methods added will be available for all controllers.
-class User < ActiveRecord::Base
- acts_as_authentic
+class Quota < ActiveRecord::Base
+ has_one :portal_pool
+ has_one :pool_account
end
diff --git a/src/app/models/user.rb b/src/app/models/user.rb
index cd49d32..3e20689 100644
--- a/src/app/models/user.rb
+++ b/src/app/models/user.rb
@@ -21,4 +21,7 @@
class User < ActiveRecord::Base
acts_as_authentic
+
+ has_many :permissions
+ has_many :owned_pools, :class_name => "PortalPool", :foreign_key => "owner_id"
end
diff --git a/src/db/migrate/20090803141507_create_portal_pools.rb b/src/db/migrate/20090802000000_create_quotas.rb
similarity index 72%
copy from src/db/migrate/20090803141507_create_portal_pools.rb
copy to src/db/migrate/20090802000000_create_quotas.rb
index 9fea790..c61fb16 100644
--- a/src/db/migrate/20090803141507_create_portal_pools.rb
+++ b/src/db/migrate/20090802000000_create_quotas.rb
@@ -1,5 +1,6 @@
#
# Copyright (C) 2009 Red Hat, Inc.
+# Written by Scott Seago <sseago(a)redhat.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -16,20 +17,20 @@
# MA 02110-1301, USA. A copy of the GNU General Public License is
# also available at http://www.gnu.org/copyleft/gpl.html.
-# Filters added to this controller apply to all controllers in the application.
-# Likewise, all the methods added will be available for all controllers.
-
-class CreatePortalPools < ActiveRecord::Migration
+class CreateQuotas < ActiveRecord::Migration
def self.up
- create_table :portal_pools do |t|
- t.string :name, :null => false
- t.integer :cloud_account_id, :null => false
+ create_table :quotas do |t|
+ t.integer :running_cpus
+ t.integer :running_memory
+ t.integer :running_instances
+ t.integer :total_storage
+ t.integer :total_instances
t.integer :lock_version, :default => 0
t.timestamps
end
end
def self.down
- drop_table :portal_pools
+ drop_table :quotas
end
end
diff --git a/src/db/migrate/20090803141507_create_portal_pools.rb b/src/db/migrate/20090803141507_create_portal_pools.rb
index 9fea790..d60b050 100644
--- a/src/db/migrate/20090803141507_create_portal_pools.rb
+++ b/src/db/migrate/20090803141507_create_portal_pools.rb
@@ -23,13 +23,17 @@ class CreatePortalPools < ActiveRecord::Migration
def self.up
create_table :portal_pools do |t|
t.string :name, :null => false
- t.integer :cloud_account_id, :null => false
+ t.string :exported_as
+ t.integer :owner_id, :null => false
+ t.integer :quota_id
t.integer :lock_version, :default => 0
t.timestamps
end
+
end
def self.down
+ drop_table :cloud_accounts_portal_pools
drop_table :portal_pools
end
end
diff --git a/src/db/migrate/20090804135630_create_flavors.rb b/src/db/migrate/20090804135630_create_hardware_profiles.rb
similarity index 78%
rename from src/db/migrate/20090804135630_create_flavors.rb
rename to src/db/migrate/20090804135630_create_hardware_profiles.rb
index 3378b8e..97eea9a 100644
--- a/src/db/migrate/20090804135630_create_flavors.rb
+++ b/src/db/migrate/20090804135630_create_hardware_profiles.rb
@@ -19,21 +19,26 @@
# Filters added to this controller apply to all controllers in the application.
# Likewise, all the methods added will be available for all controllers.
-class CreateFlavors < ActiveRecord::Migration
+class CreateHardwareProfiles < ActiveRecord::Migration
def self.up
- create_table :flavors do |t|
+ create_table :hardware_profiles do |t|
t.string :external_key, :null => false
t.string :name, :null => false, :limit => 1024
t.float :memory, :null => false
t.float :storage, :null => false
t.string :architecture, :null => false
- t.integer :provider_id, :null => false
+ t.integer :provider_id
t.integer :lock_version, :default => 0
t.timestamps
end
+
+ create_table "hardware_profile_map", :force => true, :id => false do |t|
+ t.column "master_hardware_profile_id", :integer
+ t.column "provider_hardware_profile_id", :integer
+end
end
def self.down
- drop_table :flavors
+ drop_table :hardware_profiles
end
end
diff --git a/src/db/migrate/20090804140143_create_images.rb b/src/db/migrate/20090804140143_create_images.rb
index 5717caf..986c997 100644
--- a/src/db/migrate/20090804140143_create_images.rb
+++ b/src/db/migrate/20090804140143_create_images.rb
@@ -25,7 +25,8 @@ class CreateImages < ActiveRecord::Migration
t.string :external_key, :null => false
t.string :name, :null => false, :limit => 1024
t.string :architecture, :null => false
- t.integer :provider_id, :null => false
+ t.integer :provider_id
+ t.integer :master_image_id
t.integer :lock_version, :default => 0
t.timestamps
end
diff --git a/src/db/migrate/20090804142049_create_instances.rb b/src/db/migrate/20090804142049_create_instances.rb
index 17abbfe..2880e85 100644
--- a/src/db/migrate/20090804142049_create_instances.rb
+++ b/src/db/migrate/20090804142049_create_instances.rb
@@ -24,10 +24,13 @@ class CreateInstances < ActiveRecord::Migration
create_table :instances do |t|
t.string :external_key
t.string :name, :null => false, :limit => 1024
- t.integer :flavor_id, :null => false
+ t.integer :hardware_profile_id, :null => false
+ t.integer :provider_hardware_profile_id
t.integer :image_id, :null => false
+ t.integer :provider_image_id
t.integer :realm_id
t.integer :portal_pool_id, :null => false
+ t.integer :cloud_account_id
t.string :public_address
t.string :private_address
t.string :state
diff --git a/src/db/migrate/20090803141507_create_portal_pools.rb b/src/db/migrate/20091215182906_create_pool_accounts.rb
similarity index 84%
copy from src/db/migrate/20090803141507_create_portal_pools.rb
copy to src/db/migrate/20091215182906_create_pool_accounts.rb
index 9fea790..e3b4fe6 100644
--- a/src/db/migrate/20090803141507_create_portal_pools.rb
+++ b/src/db/migrate/20091215182906_create_pool_accounts.rb
@@ -19,17 +19,18 @@
# Filters added to this controller apply to all controllers in the application.
# Likewise, all the methods added will be available for all controllers.
-class CreatePortalPools < ActiveRecord::Migration
+class CreatePoolAccounts < ActiveRecord::Migration
def self.up
- create_table :portal_pools do |t|
- t.string :name, :null => false
+ create_table :pool_accounts do |t|
t.integer :cloud_account_id, :null => false
+ t.integer :portal_pool_id, :null => false
+ t.integer :quota_id
t.integer :lock_version, :default => 0
t.timestamps
end
end
def self.down
- drop_table :portal_pools
+ drop_table :pool_accounts
end
end
diff --git a/src/test/fixtures/cloud_accounts.yml b/src/test/fixtures/cloud_accounts.yml
index 5bf0293..f9d41da 100644
--- a/src/test/fixtures/cloud_accounts.yml
+++ b/src/test/fixtures/cloud_accounts.yml
@@ -5,3 +5,7 @@
#
# two:
# column: value
+mock_account:
+ username: mockuser
+ password: mockpassword
+ provider: mock_provider
diff --git a/src/test/fixtures/hardware_profiles.yml b/src/test/fixtures/hardware_profiles.yml
new file mode 100644
index 0000000..cc70c3e
--- /dev/null
+++ b/src/test/fixtures/hardware_profiles.yml
@@ -0,0 +1,77 @@
+# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
+
+# one:
+# column: value
+#
+# two:
+# column: value
+m1_small_backend:
+ external_key: m1-small
+ name: m1-small
+ memory: 1.7
+ storage: 160
+ architecture: i386
+ provider: mock_provider
+m1_large_backend:
+ external_key: m1-large
+ name: m1-large
+ memory: 7.5
+ storage: 850
+ architecture: x86_64
+ provider: mock_provider
+m1_xlarge_backend:
+ external_key: m1-xlarge
+ name: m1-xlarge
+ memory: 15
+ storage: 1690
+ architecture: x86_64
+ provider: mock_provider
+c1_medium_backend:
+ external_key: c1-medium
+ name: c1-medium
+ memory: 1.7
+ storage: 350
+ architecture: x86_64
+ provider: mock_provider
+c1_xlarge_backend:
+ external_key: c1-xlarge
+ name: c1-xlarge
+ memory: 7
+ storage: 1690
+ architecture: x86_64
+ provider: mock_provider
+m1_small_frontend:
+ external_key: m1-small
+ name: m1-small
+ memory: 1.7
+ storage: 160
+ architecture: i386
+ provider_hardware_profiles: m1_small_frontend
+m1_large_frontend:
+ external_key: m1-large
+ name: m1-large
+ memory: 7.5
+ storage: 850
+ architecture: x86_64
+ provider_hardware_profiles: m1_large_frontend
+m1_xlarge_frontend:
+ external_key: m1-xlarge
+ name: m1-xlarge
+ memory: 15
+ storage: 1690
+ architecture: x86_64
+ provider_hardware_profiles: m1_xlarge_frontend
+c1_medium_frontend:
+ external_key: c1-medium
+ name: c1-medium
+ memory: 1.7
+ storage: 350
+ architecture: x86_64
+ provider_hardware_profiles: c1_medium_frontend
+c1_xlarge_frontend:
+ external_key: c1-xlarge
+ name: c1-xlarge
+ memory: 7
+ storage: 1690
+ architecture: x86_64
+ provider_hardware_profiles: c1_xlarge_frontend
diff --git a/src/test/fixtures/images.yml b/src/test/fixtures/images.yml
index 5bf0293..f9f2677 100644
--- a/src/test/fixtures/images.yml
+++ b/src/test/fixtures/images.yml
@@ -5,3 +5,13 @@
#
# two:
# column: value
+fedora_13_image_backend:
+ external_key: fedora_13
+ name: fedora_13
+ architecture: x86_64
+ provider: mock_provider
+fedora_13_image_frontend:
+ external_key: fedora_13
+ name: fedora_13
+ architecture: x86_64
+ provider_images: fedora_13_image_frontend
diff --git a/src/test/fixtures/instances.yml b/src/test/fixtures/instances.yml
index 5bf0293..1b7c84b 100644
--- a/src/test/fixtures/instances.yml
+++ b/src/test/fixtures/instances.yml
@@ -5,3 +5,16 @@
#
# two:
# column: value
+test_instance:
+ external_key: test_instance
+ name: test_instance
+ hardware_profile: c1_xlarge_frontend
+ provider_hardware_profile: c1_xlarge_backend
+ image: fedora_13_image_frontend
+ provider_image: fedora_13_image_backend
+ realm: us_realm
+ portal_pool: test_pool
+ cloud_account: mock_account
+ public_address:
+ private_address:
+ state: stopped
diff --git a/src/test/fixtures/permissions.yml b/src/test/fixtures/permissions.yml
index 5bf0293..892007e 100644
--- a/src/test/fixtures/permissions.yml
+++ b/src/test/fixtures/permissions.yml
@@ -5,3 +5,11 @@
#
# two:
# column: value
+admin_permission:
+ role: site_administrator
+ user: test_admin
+ permission_object: base_portal_object (BasePortalObject)
+user_permission:
+ role: instance_creator_and_user
+ user: test_user
+ permission_object: test_pool (PortalPool)
diff --git a/src/test/fixtures/pool_accounts.yml b/src/test/fixtures/pool_accounts.yml
new file mode 100644
index 0000000..6ba868f
--- /dev/null
+++ b/src/test/fixtures/pool_accounts.yml
@@ -0,0 +1,10 @@
+# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
+
+# one:
+# column: value
+#
+# two:
+# column: value
+test_pool_mock_account:
+ cloud_account: mock_account
+ portal_pool: test_pool
diff --git a/src/test/fixtures/portal_pools.yml b/src/test/fixtures/portal_pools.yml
index 5bf0293..53b94ab 100644
--- a/src/test/fixtures/portal_pools.yml
+++ b/src/test/fixtures/portal_pools.yml
@@ -5,3 +5,7 @@
#
# two:
# column: value
+test_pool
+ name: test_pool
+ owner: test_user
+ cloud_accounts: mock_account
diff --git a/src/test/fixtures/providers.yml b/src/test/fixtures/providers.yml
index 5bf0293..506c7d2 100644
--- a/src/test/fixtures/providers.yml
+++ b/src/test/fixtures/providers.yml
@@ -5,3 +5,7 @@
#
# two:
# column: value
+mock_provider:
+ name: mock
+ cloud_type: Mock
+ url: http://localhost:3001/api
diff --git a/src/test/fixtures/flavors.yml b/src/test/fixtures/quotas.yml
similarity index 75%
rename from src/test/fixtures/flavors.yml
rename to src/test/fixtures/quotas.yml
index 5bf0293..ddae3be 100644
--- a/src/test/fixtures/flavors.yml
+++ b/src/test/fixtures/quotas.yml
@@ -5,3 +5,5 @@
#
# two:
# column: value
+test_pool_quota:
+ running_instances: 10
diff --git a/src/test/fixtures/realms.yml b/src/test/fixtures/realms.yml
index 5bf0293..14cc32e 100644
--- a/src/test/fixtures/realms.yml
+++ b/src/test/fixtures/realms.yml
@@ -5,3 +5,11 @@
#
# two:
# column: value
+us_realm:
+ external_key: us
+ name: United States
+ provider: mock_provider
+eu_realm:
+ external_key: eu
+ name: Europe
+ provider: mock_provider
diff --git a/src/test/fixtures/users.yml b/src/test/fixtures/users.yml
index 3a3acb5..83d4f93 100644
--- a/src/test/fixtures/users.yml
+++ b/src/test/fixtures/users.yml
@@ -13,3 +13,11 @@ test_user:
persistence_token: 5136b29cb04a5b8840fe74451b8bdf83531f57c072826eaf63a5c05e71828ed58fc5359a2f22b02e54298d64e043a870bc03d898249dd7f577f6c5418d5ba5a6
single_access_token: YxaPK0smnUj2t9Pq0xuK
perishable_token: XZO-3xU2OIqHAUJOkDMX
+test_admin:
+ login: tadmin
+ email: tadmin(a)example.com
+ password_salt: <%= salt = Authlogic::Random.hex_token %>
+ crypted_password: <%= Authlogic::CryptoProviders::Sha512.encrypt("testpass" + salt) %>
+ persistence_token: 5136b29cb04a5b8840fe74451b8bdf83531f57c072826eaf63a5c05e71828ed58fc5359a2f22b02e54298d64e043a870bc03d898249dd7f577f6c5418d5ba5a6
+ single_access_token: YxaPK0smnUj2t9Pq0xuK
+ perishable_token: XZO-3xU2OIqHAUJOkDMX
diff --git a/src/test/unit/flavor_test.rb b/src/test/unit/hardware_profile_test.rb
similarity index 100%
copy from src/test/unit/flavor_test.rb
copy to src/test/unit/hardware_profile_test.rb
diff --git a/src/test/unit/flavor_test.rb b/src/test/unit/pool_account_test.rb
similarity index 69%
copy from src/test/unit/flavor_test.rb
copy to src/test/unit/pool_account_test.rb
index 539b662..be6686d 100644
--- a/src/test/unit/flavor_test.rb
+++ b/src/test/unit/pool_account_test.rb
@@ -1,6 +1,6 @@
require 'test_helper'
-class FlavorTest < ActiveSupport::TestCase
+class PoolAccountTest < ActiveSupport::TestCase
# Replace this with your real tests.
test "the truth" do
assert true
diff --git a/src/test/unit/flavor_test.rb b/src/test/unit/quota_test.rb
similarity index 71%
rename from src/test/unit/flavor_test.rb
rename to src/test/unit/quota_test.rb
index 539b662..f629b97 100644
--- a/src/test/unit/flavor_test.rb
+++ b/src/test/unit/quota_test.rb
@@ -1,6 +1,6 @@
require 'test_helper'
-class FlavorTest < ActiveSupport::TestCase
+class QuotaTest < ActiveSupport::TestCase
# Replace this with your real tests.
test "the truth" do
assert true
--
1.6.2.5
14 years, 4 months
[PATCH] Added XML representation of generated documentation
by Michal Fojtik
Hi,
I added a XML version of generated documentation. This will be used in
command line client and can be used in 3th party applications as well.
- Michal
---
server/libexec/lib/sinatra/rabbit.rb | 3 +++
server/libexec/views/docs/collection.xml.haml | 18 ++++++++++++++++++
server/libexec/views/docs/index.xml.haml | 5 +++++
server/libexec/views/docs/operation.xml.haml | 13 +++++++++++++
4 files changed, 39 insertions(+), 0 deletions(-)
create mode 100644 server/libexec/views/docs/collection.xml.haml
create mode 100644 server/libexec/views/docs/index.xml.haml
create mode 100644 server/libexec/views/docs/operation.xml.haml
diff --git a/server/libexec/lib/sinatra/rabbit.rb b/server/libexec/lib/sinatra/rabbit.rb
index 82a245b..4a51a4c 100644
--- a/server/libexec/lib/sinatra/rabbit.rb
+++ b/server/libexec/lib/sinatra/rabbit.rb
@@ -49,6 +49,7 @@ module Sinatra
@collection, @operation = coll, oper
respond_to do |format|
format.html { haml :'docs/operation' }
+ format.xml { haml :'docs/operation' }
end
end
end
@@ -146,6 +147,7 @@ module Sinatra
@collection, @operations = coll, oper
respond_to do |format|
format.html { haml :'docs/collection' }
+ format.xml { haml :'docs/collection' }
end
end
end
@@ -205,6 +207,7 @@ module Sinatra
get '/api/docs\/?' do
respond_to do |format|
format.html { haml :'docs/index' }
+ format.xml { haml :'docs/index' }
end
end
diff --git a/server/libexec/views/docs/collection.xml.haml b/server/libexec/views/docs/collection.xml.haml
new file mode 100644
index 0000000..5cdac84
--- /dev/null
+++ b/server/libexec/views/docs/collection.xml.haml
@@ -0,0 +1,18 @@
+%docs
+ %collection{:url => "/api/docs/#{(a)collection.name}"}
+ %name #{(a)collection.name}
+ %description #{(a)collection.description}
+ %operations
+ - @operations.keys.sort_by { |k| k.to_s }.each do |operation|
+ %operation{:url => "/api/docs/#{(a)collection.name.to_s}/#{operation}"}
+ %name #{operation}
+ %description #{(a)operations[operation].description}
+ - @operations[operation].params.each_key do |p|
+ %parameter
+ %name #{p}
+ %type #{@operations[operation].params[p][:type]}
+ %class #{@operations[operation].params[p][:class]}
+ - unless @operations[operation].params[p][:options].empty?
+ %values
+ - @operations[operation].params[p][:options].each do |v|
+ %value #{v}
diff --git a/server/libexec/views/docs/index.xml.haml b/server/libexec/views/docs/index.xml.haml
new file mode 100644
index 0000000..bf64340
--- /dev/null
+++ b/server/libexec/views/docs/index.xml.haml
@@ -0,0 +1,5 @@
+%docs
+ - collections.keys.sort_by { |k| k.to_s }.each do |collection|
+ %collection{:url => "/api/docs/#{collection}"}
+ %name #{collection}
+ %description #{collections[collection].description}
diff --git a/server/libexec/views/docs/operation.xml.haml b/server/libexec/views/docs/operation.xml.haml
new file mode 100644
index 0000000..d935365
--- /dev/null
+++ b/server/libexec/views/docs/operation.xml.haml
@@ -0,0 +1,13 @@
+%docs
+ %operation{:url => "/api/docs/#{@collection.name.to_s}/#{(a)operation.name.to_s}"}
+ %name #{(a)operation.name.to_s}
+ %description #{(a)operation.description}
+ - @operation.params.each_key do |p|
+ %parameter
+ %name #{p}
+ %type #{@operation.params[p][:type]}
+ %class #{@operation.params[p][:class]}
+ - unless @operation.params[p][:options].empty?
+ %values
+ - @operation.params[p][:options].each do |v|
+ %value #{v}
--
1.6.4.4
14 years, 4 months
Command line client (fixed)
by Michal Fojtik
This will add new file instead of patching old one (so old client is not needed). Anyway, you still need to apply 'XML documentation' patches.
14 years, 4 months