The sinatra revamp
by David Lutterkort
Hi guys,
Michal and I have been quietly working towards moving deltacloud-core
from Rails to Sinatra. That work is now ready for inclusion.
Rather than post a long list of large patches (with the removel of Rails
there's quite a few inbox busters in there), I put what I want to commit
up in the dev/sinatra-final branch of the repo at
http://gitorious.org/deltacloud-sinatra/deltacloud-sinatra
If you want to give this a try with the mock driver, you'll need to
git clone git://gitorious.org/deltacloud-sinatra/deltacloud-sinatra.git
cd deltacloud-sinatra
git checkout dev/sinatra-final
gem install sinatra thin rerun rack-accept-media-types haml compass
cd client && rake fixtures
cd ../server && ./bin/deltacloudd -i mock
Then go to http://localhost:3000/api and browse either the HTML or XML
output. You'll find some autogenerated docs under /api/docs (though they
need a little bit of work)
Unless somebody finds some major problem[1], I will merge that branch
into master of git://git.fedorahosted.org/git/deltacloud/core.git
tomorrow. Since there's no way to keep those changes bisectable, I'll
tag the current HEAD of master with rails/final and tag the HEAD of
master after merging as sinatra/first.
David
[1] It's very likely that even if there are some problems with the
sinatra branch, I'd merge anyway nad fix the problems later, simply
since maintaining this stuff on a separate branch is slowing everything
down; the split was never meant to live for very long
14 years, 4 months
Problem with EC2 driver
by Hemendra Jadaun
Hi,
I am working on Deltacloud and I have successfully installed it which is working fine with mock driver.
When I tried the same with ec2 driver, at first it gave error for aws_right file missing, which I installed it
by "gem install right_aws". Then I tried again but then it gave me exception ec2.amazonaws.com temporarily
unavailable (execution expired) while adding pool.
Then I got suggestion to use "git://git.fedorahosted.org/deltacloud/core.git" and running
the script ./server/bin/deltacloudd ec2 after that I added the cloud provider and then tried adding pool
it gave me the same error "ec2.amazonaws.com temporarily unavailable (execution expired)" .
I have used correct Access key and secret key while adding pool. Also attached is the log for framework.
Also I have confusion with readme given framework (git://git.fedorahosted.org/git/deltacloud/framework.git/)
and in core(git://git.fedorahosted.org/git/deltacloud/core.git/), both the readme seems to be same.
Do we need framework and core folder in spite the fact that we would be using just one for running the framework script.
The readme seems to be confusing. Can u please elaborate the steps.
Thanks & Regards,
Hemendra Jadaun
________________________________
This Email may contain confidential or privileged information for the intended recipient (s) If you are not the intended recipient, please do not use or disseminate the information, notify the sender and delete it from your system.
______________________________________________________________________
14 years, 4 months
new cloud hacker meetup in SF
by Adrian Cole
Hi, all.
I've started a meetup to corral those who spend their evenings
contributing to cloud apis. This group is cross-api and doesn't care
about what language people use, we meet in person and talk about
things that all of us deal with. The only requirement is that you are
transparently committed to open source cloud projects.
http://www.meetup.com/cloudhackers-SF/
Cheers,
-Adrian
14 years, 4 months
[PATCH] Add a new README, updated for Fedora 12.
by Chris Lalancette
The old README in the portal/ directory was getting very
out-of-date. There were a few hoops I had to go through
to get deltacloud running on Fedora 12, so I documented
them here.
Signed-off-by: Chris Lalancette <clalance(a)redhat.com>
---
getting_started.txt | 152 +++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 152 insertions(+), 0 deletions(-)
create mode 100644 getting_started.txt
diff --git a/getting_started.txt b/getting_started.txt
new file mode 100644
index 0000000..1169822
--- /dev/null
+++ b/getting_started.txt
@@ -0,0 +1,152 @@
+This is a getting started guide for working with Deltacloud. It's
+intended for people who want to get deltacloud up and running for
+development purposes. If you want to just install and run deltacloud,
+please use the packages provided by your distribution.
+
+How the deltacloud pieces fit together
+--------------------------------------
+Deltacloud consists of 4 main pieces: the deltacloud aggregator, the
+deltacloud Web User Interface (WUI), the deltacloud drivers, and
+the deltacloud API. The architecture loosely looks like the
+picture below:
+
+ ############
+ ## ## Native API deltacloud
+# Cloud # (i.e. EC2) +------------+ API +------------+
+# Provider # <----------> | deltacloud | <----------> | deltacloud |
+# (i.e. EC2) # | driver | | API user |
+ ## ## +------------+ +------------+
+ ###########
+ ^
+ | deltacloud API
+ |
+ \/
+ deltacloud deltacloud
++------------+ API +------------+ API +------------+
+| deltacloud | <----------> | deltacloud | <----------> | deltacloud |
+| WUI | | aggregator | | API user |
++------------+ +------------+ +------------+
+
+In words, what the above picture means is that you have one or more
+deltacloud drivers running that translate the deltacloud API into
+the native API that the backend cloud speaks (if a backend cloud
+speaks deltacloud API natively, then this isn't necessary). Once
+the driver is in place, then a deltacloud API user can talk to the
+backend cloud using the deltacloud API. One of the deltacloud API
+users is the deltacloud aggregator, which can be used to aggregate
+disparate backend clouds and make business logic decisions about
+which particular cloud an instance should start in. The deltacloud
+aggregator speaks to the deltacloud WUI, which provides a
+user-friendly web user interface for users. The aggregator can
+also be accessed via the deltacloud API to support other
+user interfaces.
+
+Checking out the components
+---------------------------
+If you are reading this document, I assume you have already checked
+out the docs git repository. Just in case you haven't, you should
+check out the following pieces:
+
+$ git clone git://git.fedorahosted.org/git/deltacloud/core.git/
+ - This is the "core" of deltacloud; it includes both the source code
+ for the deltacloud API, and the various drivers
+$ git clone git://git.fedorahosted.org/git/deltacloud/docs.git/
+ - Documentation for deltacloud (including this document)
+$ git clone git://git.fedorahosted.org/git/deltacloud/portal.git/
+ - The deltacloud aggregator code
+
+Installing packages
+-------------------
+In order to make the deltacloud components work, you'll need to
+install at least the following packages (on Fedora 12: your distro's
+packages may vary):
+
+rubygem-rails
+rubygem-daemons
+rubygem-gettext_rails
+postgresql
+postgresql-server
+ruby-postgres
+rubygem-compass (this is not yet in Fedora, so you'll have to gem install)
+rubygem-haml (this is not yet in Fedora, so you'll have to gem install)
+
+Postgresql database setup
+-------------------------
+Once you have the proper packages installed you have to setup the
+postgresql database. As root:
+
+# /sbin/service postgresql initdb
+# /sbin/service postgresql start
+# su - postgres
+$ psql
+postgres=# CREATE USER dcloud WITH PASSWORD 'v23zj59an' CREATEDB;
+postgres=# \q
+$ exit
+
+Now you need to edit the pg_hba.conf file
+(/var/lib/pgsql/data/pg_hba.conf on Fedora 12):
+
+--------- snip ------------------------------
+local all all trust
+host all all 127.0.0.1 255.255.255.255 trust
+host all all ::1/128 trust
+--------- snip ------------------------------
+
+If you are running on Fedora 12 *only*, to make rake
+succeed you need to append the following to
+/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/connection_adapters/postgresql_adapter.rb:
+
+ def PGconn.quote_ident(name)
+ %("#{name}")
+ end
+
+(see http://github.com/mneumann/postgres-pr/issues/unreads#issue/1)
+
+Setting up the drivers
+----------------------
+For testing purposes we'll start with the mock driver. Use of the
+rest of the drivers should be similar, although may require some
+additional gems be installed.
+
+$ cd path/to/deltacloud/core/server/bin
+$ ./deltacloudd mock
+
+Setting up the aggregator
+-------------------------
+Now we need to setup the aggregator (which includes the UI).
+As your normal user:
+
+$ cd path/to/deltacloud/portal/src
+$ rake db:create:all
+$ rake db:migrate
+$ rake db:test:prepare
+
+If all went well here, then the database should be ready for you
+to start up the aggregator. We also have to set it up so that
+the aggregator can find the deltacloud API:
+
+$ ln -s /absolute/path/to/deltacloud/core/client \
+ /absolute/path/to/deltacloud/portal/src/vendor/plugins
+
+You can now run the UI:
+
+$ ./script/server -p 3001
+
+Which will start up the UI. There is one more piece to start
+up before we can actually run, and that is taskomatic.
+
+Setting up taskomatic
+---------------------
+Taskomatic is the component that actually runs tasks in
+response to user action. It lives inside the portal
+code and uses the same database schema as the portal.
+To run it, you just need to:
+
+$ cd path/to/deltacloud/portal/src/task-omatic
+$ RAILS_ENV=development ./taskomatic.rb -n
+
+Checking out the UI
+-------------------
+Now that you have all of the components running, you
+should be able to point your web browser at localhost:3000
+and see the UI. Happy hacking!
--
1.6.6
14 years, 4 months
Error - Deltacloud with EC2 driver
by Ravi Sawlani
Hi
I am facing some problem with deltacloud while using EC2 driver.
As mentioned in the portal readme at http://deltacloud.org/download.html, at first i tested deltacloud with
mock driver which was running fine. Then I switched to EC2 driver but I it gave me error while I try and create
pool for the instances. Whenever I try and create pool filling in the Access key and Secret key in Username and
password respectively, it gave me error "ec2.amazonaws.com temporarily unavailable (execution expired)"
in the framework log. Then i got a reply from Mr. David Lutterkort [lutter(a)redhat.com] to use
git://git.fedorahosted.org/deltacloud/core.git and run framework using ./server/bin/deltacloudd ec2.
But when I tried creating pool it gave me similar error i.e Error "ec2.amazonaws.com temporarily unavailable
(execution expired)" in the framework log. Also attached is the framework log
Also I want to clear one more thing, Framework/Portal usually don't run at 3000 port because service
"deltacloud-mongrel-rails" runs at 3000 port. For now we run framework and portal at 3001 and 3002 respectively.
Please help me out with this.
Thanks
Ravi Sawlani
________________________________
This Email may contain confidential or privileged information for the intended recipient (s) If you are not the intended recipient, please do not use or disseminate the information, notify the sender and delete it from your system.
______________________________________________________________________
14 years, 4 months
Error - Deltacloud with EC2 driver
by Ravi Sawlani
Hi
I am facing some problem with deltacloud while using EC2 driver.
As mentioned in the portal readme at http://deltacloud.org/download.html, at first i tested deltacloud with
mock driver which was running fine. Then I switched to EC2 driver but I it gave me error while I try and create
pool for the instances. Whenever I try and create pool filling in the Access key and Secret key in Username and
password respectively, it gave me error "ec2.amazonaws.com temporarily unavailable (execution expired)"
in the framework log. Then i got a reply from Mr. David Lutterkort [lutter(a)redhat.com] to use
git://git.fedorahosted.org/deltacloud/core.git and run framework using ./server/bin/deltacloudd ec2.
But when I tried creating pool it gave me similar error i.e Error "ec2.amazonaws.com temporarily unavailable
(execution expired)" in the framework log. Also attached is the framework log
Also I want to clear one more thing, Framework/Portal usually don't run at 3000 port because service
"deltacloud-mongrel-rails" runs at 3000 port. For now we run framework and portal at 3001 and 3002 respectively.
Please help me out with this.
Thanks
Ravi Sawlani
________________________________
This Email may contain confidential or privileged information for the intended recipient (s) If you are not the intended recipient, please do not use or disseminate the information, notify the sender and delete it from your system.
______________________________________________________________________
14 years, 4 months
[PATCH 2/2] first round of model changes to reflect the new front-end/back-end cloud design. Several components are not yet complete and will be included in subsequent patches. In particular:
by Scott Seago
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 | 4 +-
...s.rb => 20091215182906_create_pool_accounts.rb} | 9 ++-
.../{flavors.yml => hardware_profiles.yml} | 0
.../fixtures/{flavors.yml => pool_accounts.yml} | 0
src/test/fixtures/{flavors.yml => quotas.yml} | 0
.../{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 +-
23 files changed, 167 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%)
copy src/test/fixtures/{flavors.yml => hardware_profiles.yml} (100%)
copy src/test/fixtures/{flavors.yml => pool_accounts.yml} (100%)
rename src/test/fixtures/{flavors.yml => quotas.yml} (100%)
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..de02d46 100644
--- a/src/db/migrate/20090804142049_create_instances.rb
+++ b/src/db/migrate/20090804142049_create_instances.rb
@@ -24,10 +24,12 @@ 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 :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/flavors.yml b/src/test/fixtures/hardware_profiles.yml
similarity index 100%
copy from src/test/fixtures/flavors.yml
copy to src/test/fixtures/hardware_profiles.yml
diff --git a/src/test/fixtures/flavors.yml b/src/test/fixtures/pool_accounts.yml
similarity index 100%
copy from src/test/fixtures/flavors.yml
copy to src/test/fixtures/pool_accounts.yml
diff --git a/src/test/fixtures/flavors.yml b/src/test/fixtures/quotas.yml
similarity index 100%
rename from src/test/fixtures/flavors.yml
rename to src/test/fixtures/quotas.yml
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 1/2] initial permission/privilege model for the portal.
by Scott Seago
This is still preliminary, as there are a few things missing:
1) no support for using these permissions in the controllers
2) no UI to manipulate permission records
3) The roles would ideally be loaded via a yml file rather than in the migration, since they are theoretically dynamic values -- changes over time would be allowed without changes to the underlying code.
4) Test fixtures defined for privileges, and roles. Fixtures for permissions will come after we have user and pool, etc fixtures. Those are also needed for permission test cases.
Signed-off-by: Scott Seago <sseago(a)redhat.com>
---
src/app/models/base_portal_object.rb | 33 +++++
src/app/models/cloud_account.rb | 4 +
src/app/models/permission.rb | 43 +++++++
src/app/models/portal_pool.rb | 4 +
src/app/models/privilege.rb | 76 +++++++++++
src/app/models/provider.rb | 4 +
src/app/models/role.rb | 27 ++++
src/db/migrate/20091008153046_create_privileges.rb | 49 +++++++
src/db/migrate/20091008153058_create_roles.rb | 132 ++++++++++++++++++++
.../migrate/20091008153106_create_permissions.rb | 37 ++++++
.../20091019215838_create_base_portal_objects.rb | 14 ++
src/test/fixtures/base_portal_objects.yml | 9 ++
src/test/fixtures/permissions.yml | 7 +
src/test/fixtures/privileges.yml | 40 ++++++
src/test/fixtures/roles.yml | 47 +++++++
src/test/unit/base_portal_object_test.rb | 8 ++
src/test/unit/permission_test.rb | 8 ++
src/test/unit/privilege_test.rb | 8 ++
src/test/unit/role_test.rb | 8 ++
19 files changed, 558 insertions(+), 0 deletions(-)
create mode 100644 src/app/models/base_portal_object.rb
create mode 100644 src/app/models/permission.rb
create mode 100644 src/app/models/privilege.rb
create mode 100644 src/app/models/role.rb
create mode 100644 src/db/migrate/20091008153046_create_privileges.rb
create mode 100644 src/db/migrate/20091008153058_create_roles.rb
create mode 100644 src/db/migrate/20091008153106_create_permissions.rb
create mode 100644 src/db/migrate/20091019215838_create_base_portal_objects.rb
create mode 100644 src/test/fixtures/base_portal_objects.yml
create mode 100644 src/test/fixtures/permissions.yml
create mode 100644 src/test/fixtures/privileges.yml
create mode 100644 src/test/fixtures/roles.yml
create mode 100644 src/test/unit/base_portal_object_test.rb
create mode 100644 src/test/unit/permission_test.rb
create mode 100644 src/test/unit/privilege_test.rb
create mode 100644 src/test/unit/role_test.rb
diff --git a/src/app/models/base_portal_object.rb b/src/app/models/base_portal_object.rb
new file mode 100644
index 0000000..e96dd44
--- /dev/null
+++ b/src/app/models/base_portal_object.rb
@@ -0,0 +1,33 @@
+#
+# 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
+# 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.
+
+class BasePortalObject < ActiveRecord::Base
+ has_many :permissions, :as => :permission_object, :dependent => :destroy,
+ :include => [:role],
+ :order => "permissions.id ASC"
+
+ validates_presence_of :name
+ validates_uniqueness_of :name
+
+ GENERAL_PERMISSION_SCOPE = "general_permission_scope"
+
+ def self.general_permission_scope
+ self.find_by_name(GENERAL_PERMISSION_SCOPE)
+ end
+end
diff --git a/src/app/models/cloud_account.rb b/src/app/models/cloud_account.rb
index db213b0..afb4623 100644
--- a/src/app/models/cloud_account.rb
+++ b/src/app/models/cloud_account.rb
@@ -35,6 +35,10 @@ class CloudAccount < ActiveRecord::Base
validates_uniqueness_of :username, :scope => :provider_id
validates_presence_of :password
+ has_many :permissions, :as => :permission_object, :dependent => :destroy,
+ :include => [:role],
+ :order => "permissions.id ASC"
+
def connect
begin
return DeltaCloud.new(username, password, provider.url)
diff --git a/src/app/models/permission.rb b/src/app/models/permission.rb
new file mode 100644
index 0000000..7c2bd9c
--- /dev/null
+++ b/src/app/models/permission.rb
@@ -0,0 +1,43 @@
+#
+# 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
+# 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.
+
+class Permission < ActiveRecord::Base
+ belongs_to :pool
+
+ belongs_to :role
+
+ validates_presence_of :pool_id
+ validates_presence_of :role_id
+
+ validates_presence_of :user_id
+ validates_uniqueness_of :user_id, :scope => [:permission_object_id,
+ :permission_object_type]
+
+ belongs_to :permission_object, :polymorphic => true
+ # type-specific associations
+ belongs_to :portal_pool, :class_name => "PortalPool",
+ :foreign_key => "permission_object_id"
+ belongs_to :provider, :class_name => "Provider",
+ :foreign_key => "permission_object_id"
+ belongs_to :cloud_account, :class_name => "CloudAccount",
+ :foreign_key => "permission_object_id"
+ belongs_to :base_portal_object, :class_name => "BasePortalObject",
+ :foreign_key => "permission_object_id"
+
+end
diff --git a/src/app/models/portal_pool.rb b/src/app/models/portal_pool.rb
index 6c30a67..6f4084b 100644
--- a/src/app/models/portal_pool.rb
+++ b/src/app/models/portal_pool.rb
@@ -30,6 +30,10 @@ class PortalPool < ActiveRecord::Base
validates_presence_of :name
validates_uniqueness_of :name, :scope => :cloud_account_id
+ 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
diff --git a/src/app/models/privilege.rb b/src/app/models/privilege.rb
new file mode 100644
index 0000000..06dd18e
--- /dev/null
+++ b/src/app/models/privilege.rb
@@ -0,0 +1,76 @@
+#
+# 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
+# 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.
+
+class Privilege < ActiveRecord::Base
+ has_and_belongs_to_many :roles
+
+ validates_presence_of :name
+ validates_uniqueness_of :name
+
+ #default privileges
+ PERM_SET = "set_perms" # can create/modify/delete permission
+ # records on this object
+ PERM_VIEW = "view_perms" # can view permission records on this
+ # object
+
+ # instance privileges normally checked at the pool level, although
+ # instance-specific overrides could be a future enhancement.
+ INSTANCE_MODIFY = "instance_modify" # can create, modify, delete, or
+ # control (start, stop, etc) instances
+ INSTANCE_CONTROL = "instance_control" # can control (start, stop, etc)
+ # instances
+ INSTANCE_VIEW = "instance_view" # can view instance metadata
+ # do we need a separate "connect" privilege?
+
+ # stats privileges normally checked at the pool level, although
+ # instance-specific overrides could be a future enhancement.
+ STATS_VIEW = "stats_view" # can view monitoring data for
+ # instances
+
+ # account privileges normally checked at the provider level, although
+ # account-specific overrides could be a future enhancement.
+ ACCOUNT_MODIFY = "account_modify" # can create or modify cloud accounts
+ ACCOUNT_VIEW = "account_view" # can create or modify cloud accounts
+
+ # pool privileges normally checked at the provider level
+ # (and at the account level for choosing which accounts are visible on the
+ # new pool form), although
+ # pool-specific overrides could be a future enhancement.
+ POOL_MODIFY = "pool_modify" # can create or modify a pool
+ POOL_VIEW = "pool_view" # can view a pool
+
+ # quota privileges normally checked at the pool or account level,
+ # depending on which quota level we're dealing with
+ # (account level for cloud-imposed quota, pool level for portal quota)
+ QUOTA_MODIFY = "quota_modify" # can create or modify a quota
+ QUOTA_VIEW = "quota_view" # can view a quota
+
+ # provider privileges normally checked at the provider level, although
+ # 'new provider' action requires this privilege at the SystemPermission level
+ PROVIDER_MODIFY = "provider_modify" # can create or modify a provider
+ PROVIDER_VIEW = "provider_view" # can view a provider
+
+ # normally checked at the SystemPermission level
+ USER_MODIFY = "user_modify" # can create a new user (other than
+ # self-registration) or modify another
+ # user's metadata (for admin-level
+ # actions)
+ USER_VIEW = "user_view" # can view a user's profile data
+
+end
diff --git a/src/app/models/provider.rb b/src/app/models/provider.rb
index b7a071a..dab9fee 100644
--- a/src/app/models/provider.rb
+++ b/src/app/models/provider.rb
@@ -34,6 +34,10 @@ class Provider < ActiveRecord::Base
validates_presence_of :cloud_type
validates_presence_of :url
+ has_many :permissions, :as => :permission_object, :dependent => :destroy,
+ :include => [:role],
+ :order => "permissions.id ASC"
+
def connect
begin
return DeltaCloud.new(nil, nil, url)
diff --git a/src/app/models/role.rb b/src/app/models/role.rb
new file mode 100644
index 0000000..db4a9ac
--- /dev/null
+++ b/src/app/models/role.rb
@@ -0,0 +1,27 @@
+#
+# 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
+# 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.
+
+class Role < ActiveRecord::Base
+ has_many :permissions
+ has_and_belongs_to_many :privileges, :uniq => true
+
+ validates_presence_of :name
+ validates_uniqueness_of :name
+
+end
diff --git a/src/db/migrate/20091008153046_create_privileges.rb b/src/db/migrate/20091008153046_create_privileges.rb
new file mode 100644
index 0000000..74932b0
--- /dev/null
+++ b/src/db/migrate/20091008153046_create_privileges.rb
@@ -0,0 +1,49 @@
+#
+# 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
+# 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.
+
+class CreatePrivileges < ActiveRecord::Migration
+ def self.up
+ create_table :privileges do |t|
+ t.string :name, :null => false
+ t.integer :lock_version, :default => 0
+
+ t.timestamps
+ end
+
+ #create default privileges
+ privileges = ["set_perms", "view_perms",
+ "instance_modify", "instance_control", "instance_view",
+ "stats_view",
+ "account_modify", "account_view",
+ "pool_modify", "pool_view",
+ "quota_modify", "quota_view",
+ "provider_modify", "provider_view",
+ "user_modify", "user_view"]
+ Privilege.transaction do
+ privileges.each do |priv_name|
+ privilege = Privilege.new({:name => priv_name})
+ privilege.save!
+ end
+ end
+ end
+
+ def self.down
+ drop_table :privileges
+ end
+end
diff --git a/src/db/migrate/20091008153058_create_roles.rb b/src/db/migrate/20091008153058_create_roles.rb
new file mode 100644
index 0000000..44c360d
--- /dev/null
+++ b/src/db/migrate/20091008153058_create_roles.rb
@@ -0,0 +1,132 @@
+#
+# 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
+# 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.
+
+class CreateRoles < ActiveRecord::Migration
+ def self.up
+ create_table :roles do |t|
+ t.string :name, :null => false
+ t.string :scope, :null => false
+ t.integer :lock_version, :default => 0
+
+ t.timestamps
+ end
+ create_table :privileges_roles, :id => false do |t|
+ t.integer :privilege_id, :null => false
+ t.integer :role_id, :null => false
+ end
+
+ #create default roles
+ roles = {"Instance Controller" =>
+ {:role_scope => "PortalPool",
+ :privileges => ["instance_control",
+ "instance_view",
+ "pool_view"]},
+ "Instance Controller With Monitoring" =>
+ {:role_scope => "PortalPool",
+ :privileges => ["instance_control",
+ "instance_view",
+ "pool_view",
+ "stats_view"]},
+ "Instance Creator and User" =>
+ {:role_scope => "PortalPool",
+ :privileges => ["instance_control",
+ "instance_view",
+ "pool_view",
+ "stats_view",
+ "instance_modify",
+ "quota_view",
+ "set_perms",
+ "view_perms"]},
+ "Self-service Pool User" =>
+ {:role_scope => "PortalPool",
+ :privileges => ["instance_control",
+ "instance_view",
+ "pool_view",
+ "stats_view",
+ "instance_modify",
+ "quota_view",
+ "set_perms",
+ "view_perms",
+ "account_modify"]},
+ "Pool Creator" =>
+ {:role_scope => "Provider",
+ :privileges => ["provider_view",
+ "pool_modify",
+ "pool_view",
+ "quota_view"]},
+ "Pool Administrator" =>
+ {:role_scope => "Provider",
+ :privileges => ["provider_view",
+ "pool_modify",
+ "pool_view",
+ "quota_view",
+ "quota_modify",
+ "account_view",
+ "account_modify",
+ "set_perms",
+ "view_perms"]},
+ "Account Administrator" =>
+ {:role_scope => "CloudAccount",
+ :privileges => ["set_perms",
+ "view_perms",
+ "account_view",
+ "account_modify"]},
+ "Account User" =>
+ {:role_scope => "CloudAccount",
+ :privileges => ["account_view"]},
+ "Provider Administrator" =>
+ {:role_scope => "BasePortalObject",
+ :privileges => ["provider_modify",
+ "provider_view"]},
+ "Administrator" =>
+ {:role_scope => "BasePortalObject",
+ :privileges => ["provider_modify",
+ "provider_view",
+ "account_modify",
+ "account_view",
+ "user_modify",
+ "user_view",
+ "set_perms",
+ "view_perms",
+ "pool_modify",
+ "pool_view",
+ "quota_modify",
+ "quota_view",
+ "stats_view",
+ "instance_modify",
+ "instance_control",
+ "instance_view"]}
+
+ }
+ Role.transaction do
+ roles.each do |role_name, role_hash|
+ role = Role.new({:name => role_name, :scope => role_hash[:role_scope]})
+ role.save!
+ role.privileges = role_hash[:privileges].collect do |priv_name|
+ Privilege.find_by_name(priv_name)
+ end
+ role.save!
+ end
+ end
+ end
+
+ def self.down
+ drop_table :roles
+ end
+end
diff --git a/src/db/migrate/20091008153106_create_permissions.rb b/src/db/migrate/20091008153106_create_permissions.rb
new file mode 100644
index 0000000..6e5a7a5
--- /dev/null
+++ b/src/db/migrate/20091008153106_create_permissions.rb
@@ -0,0 +1,37 @@
+#
+# 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
+# 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.
+
+class CreatePermissions < ActiveRecord::Migration
+ def self.up
+ create_table :permissions do |t|
+ t.integer :role_id, :null => false
+ t.integer :user_id, :null => false
+ t.integer :permission_object_id
+ t.string :permission_object_type
+ t.integer :pool_id
+ t.integer :lock_version, :default => 0
+
+ t.timestamps
+ end
+ end
+
+ def self.down
+ drop_table :permissions
+ end
+end
diff --git a/src/db/migrate/20091019215838_create_base_portal_objects.rb b/src/db/migrate/20091019215838_create_base_portal_objects.rb
new file mode 100644
index 0000000..badea5d
--- /dev/null
+++ b/src/db/migrate/20091019215838_create_base_portal_objects.rb
@@ -0,0 +1,14 @@
+class CreateBasePortalObjects < ActiveRecord::Migration
+ def self.up
+ create_table :base_portal_objects do |t|
+ t.string :name, :null => false
+ t.timestamps
+ end
+
+ BasePortalObject.new({:name => "general_permission_scope"}).save!
+ end
+
+ def self.down
+ drop_table :base_portal_objects
+ end
+end
diff --git a/src/test/fixtures/base_portal_objects.yml b/src/test/fixtures/base_portal_objects.yml
new file mode 100644
index 0000000..7e9b357
--- /dev/null
+++ b/src/test/fixtures/base_portal_objects.yml
@@ -0,0 +1,9 @@
+# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
+
+# one:
+# column: value
+#
+# two:
+# column: value
+base_portal_object:
+ name: general_permission_scope
\ No newline at end of file
diff --git a/src/test/fixtures/permissions.yml b/src/test/fixtures/permissions.yml
new file mode 100644
index 0000000..5bf0293
--- /dev/null
+++ b/src/test/fixtures/permissions.yml
@@ -0,0 +1,7 @@
+# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
+
+# one:
+# column: value
+#
+# two:
+# column: value
diff --git a/src/test/fixtures/privileges.yml b/src/test/fixtures/privileges.yml
new file mode 100644
index 0000000..6ccb16b
--- /dev/null
+++ b/src/test/fixtures/privileges.yml
@@ -0,0 +1,40 @@
+# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
+
+# one:
+# column: value
+#
+# two:
+# column: value
+set_perms:
+ name: set_perms
+view_perms:
+ name: view_perms
+instance_modify:
+ name: instance_modify
+instance_control:
+ name: instance_control
+instance_view:
+ name: instance_view
+stats_view:
+ name: stats_view
+account_modify:
+ name: account_modify
+account_view:
+ name: account_view
+pool_modify:
+ name: pool_modify
+pool_view:
+ name: pool_view
+quota_modify:
+ name: quota_modify
+quota_view:
+ name: quota_view
+provider_modify:
+ name: provider_modify
+provider_view:
+ name: provider_view
+user_modify:
+ name: user_modify
+user_view:
+ name: user_view
+
diff --git a/src/test/fixtures/roles.yml b/src/test/fixtures/roles.yml
new file mode 100644
index 0000000..2ac7e5f
--- /dev/null
+++ b/src/test/fixtures/roles.yml
@@ -0,0 +1,47 @@
+# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
+
+# one:
+# column: value
+#
+# two:
+# column: value
+instance_controller:
+ name: Instance Controller
+ scope: PortalPool
+ privileges: instance_control, instance_view, pool_view
+instance_controller_with_monitoring:
+ name: Instance Controller With Monitoring
+ scope: PortalPool
+ privileges: instance_control, instance_view, pool_view, stats_view
+instance_creator_and_user:
+ name: Instance Creator and User
+ scope: PortalPool
+ privileges: instance_control, instance_view, pool_view, stats_view, instance_modify, quota_view, set_perms, view_perms
+self_service_pool_user:
+ name: Self-service Pool User
+ scope: PortalPool
+ privileges: instance_control, instance_view, pool_view, stats_view, instance_modify, quota_view, set_perms, view_perms, account_modify
+pool_creator:
+ name: Pool Creator
+ scope: Provider
+ privileges: provider_view, pool_modify, pool_view, quota_view
+pool_administrator:
+ name: Pool Administrator
+ scope: Provider
+ privileges: provider_view, pool_modify, pool_view, quota_modify, quota_view, account_modify, account_view, stats_view, set_perms, view_perms
+account_administrator:
+ name: Account Administrator
+ scope: CloudAccount
+ privileges: account_modify, account_view, stats_view, set_perms, view_perms
+account_user:
+ name: Account User
+ scope: CloudAccount
+ privileges: account_view
+provider_administrator:
+ name: Provider Administrator
+ scope: BasePortalObject
+ privileges: provider_modify, provider_view, stats_view
+site_administrator:
+ name: Site Administrator
+ scope: BasePortalObject
+ privileges: provider_modify, provider_view, account_modify, account_view, user_modify, user_view, set_perms, view_perms, pool_modify, pool_view, quota_modify, quota_view, stats_view, instance_modify, instance_control, instance_view
diff --git a/src/test/unit/base_portal_object_test.rb b/src/test/unit/base_portal_object_test.rb
new file mode 100644
index 0000000..e6e4b9d
--- /dev/null
+++ b/src/test/unit/base_portal_object_test.rb
@@ -0,0 +1,8 @@
+require 'test_helper'
+
+class BasePortalObjectTest < ActiveSupport::TestCase
+ # Replace this with your real tests.
+ test "the truth" do
+ assert true
+ end
+end
diff --git a/src/test/unit/permission_test.rb b/src/test/unit/permission_test.rb
new file mode 100644
index 0000000..08fcc0b
--- /dev/null
+++ b/src/test/unit/permission_test.rb
@@ -0,0 +1,8 @@
+require 'test_helper'
+
+class PermissionTest < ActiveSupport::TestCase
+ # Replace this with your real tests.
+ test "the truth" do
+ assert true
+ end
+end
diff --git a/src/test/unit/privilege_test.rb b/src/test/unit/privilege_test.rb
new file mode 100644
index 0000000..459d805
--- /dev/null
+++ b/src/test/unit/privilege_test.rb
@@ -0,0 +1,8 @@
+require 'test_helper'
+
+class PrivilegeTest < ActiveSupport::TestCase
+ # Replace this with your real tests.
+ test "the truth" do
+ assert true
+ end
+end
diff --git a/src/test/unit/role_test.rb b/src/test/unit/role_test.rb
new file mode 100644
index 0000000..b0374ce
--- /dev/null
+++ b/src/test/unit/role_test.rb
@@ -0,0 +1,8 @@
+require 'test_helper'
+
+class RoleTest < ActiveSupport::TestCase
+ # Replace this with your real tests.
+ test "the truth" do
+ assert true
+ end
+end
--
1.6.2.5
14 years, 4 months
[PATCH] first round of model changes to reflect the new front-end/back-end cloud design. Several components are not yet complete and will be included in subsequent patches. In particular:
by Scott Seago
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 | 4 +-
.../{flavors.yml => hardware_profiles.yml} | 0
src/test/fixtures/{flavors.yml => quotas.yml} | 0
.../{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 +-
21 files changed, 162 insertions(+), 115 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/test/fixtures/{flavors.yml => hardware_profiles.yml} (100%)
rename src/test/fixtures/{flavors.yml => quotas.yml} (100%)
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..de02d46 100644
--- a/src/db/migrate/20090804142049_create_instances.rb
+++ b/src/db/migrate/20090804142049_create_instances.rb
@@ -24,10 +24,12 @@ 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 :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/test/fixtures/flavors.yml b/src/test/fixtures/hardware_profiles.yml
similarity index 100%
copy from src/test/fixtures/flavors.yml
copy to src/test/fixtures/hardware_profiles.yml
diff --git a/src/test/fixtures/flavors.yml b/src/test/fixtures/quotas.yml
similarity index 100%
rename from src/test/fixtures/flavors.yml
rename to src/test/fixtures/quotas.yml
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.0.6
14 years, 4 months
[PATCH] initial permission/privilege model for the portal.
by Scott Seago
This is still preliminary, as there are a few things missing:
1) no support for using these permissions in the controllers
2) no UI to manipulate permission records
3) The roles would ideally be loaded via a yml file rather than in the migration, since they are theoretically dynamic values -- changes over time would be allowed without changes to the underlying code.
4) No fixtures/tests for any of this yet. I'll update this patch with fixtures, etc. before pushing, but I wanted to get this out there while the recent model decisions were still in my mind.
Signed-off-by: Scott Seago <sseago(a)redhat.com>
---
src/app/models/base_portal_object.rb | 33 ++++++
src/app/models/cloud_account.rb | 4 +
src/app/models/permission.rb | 43 ++++++++
src/app/models/portal_pool.rb | 4 +
src/app/models/privilege.rb | 76 +++++++++++++
src/app/models/provider.rb | 4 +
src/app/models/role.rb | 34 ++++++
src/db/migrate/20091008153046_create_privileges.rb | 49 +++++++++
src/db/migrate/20091008153058_create_roles.rb | 112 ++++++++++++++++++++
.../migrate/20091008153106_create_permissions.rb | 37 +++++++
.../20091019215838_create_base_portal_objects.rb | 14 +++
src/test/fixtures/base_portal_objects.yml | 7 ++
src/test/fixtures/permissions.yml | 7 ++
src/test/fixtures/privileges.yml | 7 ++
src/test/fixtures/roles.yml | 7 ++
src/test/unit/base_portal_object_test.rb | 8 ++
src/test/unit/permission_test.rb | 8 ++
src/test/unit/privilege_test.rb | 8 ++
src/test/unit/role_test.rb | 8 ++
19 files changed, 470 insertions(+), 0 deletions(-)
create mode 100644 src/app/models/base_portal_object.rb
create mode 100644 src/app/models/permission.rb
create mode 100644 src/app/models/privilege.rb
create mode 100644 src/app/models/role.rb
create mode 100644 src/db/migrate/20091008153046_create_privileges.rb
create mode 100644 src/db/migrate/20091008153058_create_roles.rb
create mode 100644 src/db/migrate/20091008153106_create_permissions.rb
create mode 100644 src/db/migrate/20091019215838_create_base_portal_objects.rb
create mode 100644 src/test/fixtures/base_portal_objects.yml
create mode 100644 src/test/fixtures/permissions.yml
create mode 100644 src/test/fixtures/privileges.yml
create mode 100644 src/test/fixtures/roles.yml
create mode 100644 src/test/unit/base_portal_object_test.rb
create mode 100644 src/test/unit/permission_test.rb
create mode 100644 src/test/unit/privilege_test.rb
create mode 100644 src/test/unit/role_test.rb
diff --git a/src/app/models/base_portal_object.rb b/src/app/models/base_portal_object.rb
new file mode 100644
index 0000000..e96dd44
--- /dev/null
+++ b/src/app/models/base_portal_object.rb
@@ -0,0 +1,33 @@
+#
+# 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
+# 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.
+
+class BasePortalObject < ActiveRecord::Base
+ has_many :permissions, :as => :permission_object, :dependent => :destroy,
+ :include => [:role],
+ :order => "permissions.id ASC"
+
+ validates_presence_of :name
+ validates_uniqueness_of :name
+
+ GENERAL_PERMISSION_SCOPE = "general_permission_scope"
+
+ def self.general_permission_scope
+ self.find_by_name(GENERAL_PERMISSION_SCOPE)
+ end
+end
diff --git a/src/app/models/cloud_account.rb b/src/app/models/cloud_account.rb
index db213b0..afb4623 100644
--- a/src/app/models/cloud_account.rb
+++ b/src/app/models/cloud_account.rb
@@ -35,6 +35,10 @@ class CloudAccount < ActiveRecord::Base
validates_uniqueness_of :username, :scope => :provider_id
validates_presence_of :password
+ has_many :permissions, :as => :permission_object, :dependent => :destroy,
+ :include => [:role],
+ :order => "permissions.id ASC"
+
def connect
begin
return DeltaCloud.new(username, password, provider.url)
diff --git a/src/app/models/permission.rb b/src/app/models/permission.rb
new file mode 100644
index 0000000..7c2bd9c
--- /dev/null
+++ b/src/app/models/permission.rb
@@ -0,0 +1,43 @@
+#
+# 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
+# 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.
+
+class Permission < ActiveRecord::Base
+ belongs_to :pool
+
+ belongs_to :role
+
+ validates_presence_of :pool_id
+ validates_presence_of :role_id
+
+ validates_presence_of :user_id
+ validates_uniqueness_of :user_id, :scope => [:permission_object_id,
+ :permission_object_type]
+
+ belongs_to :permission_object, :polymorphic => true
+ # type-specific associations
+ belongs_to :portal_pool, :class_name => "PortalPool",
+ :foreign_key => "permission_object_id"
+ belongs_to :provider, :class_name => "Provider",
+ :foreign_key => "permission_object_id"
+ belongs_to :cloud_account, :class_name => "CloudAccount",
+ :foreign_key => "permission_object_id"
+ belongs_to :base_portal_object, :class_name => "BasePortalObject",
+ :foreign_key => "permission_object_id"
+
+end
diff --git a/src/app/models/portal_pool.rb b/src/app/models/portal_pool.rb
index 6c30a67..6f4084b 100644
--- a/src/app/models/portal_pool.rb
+++ b/src/app/models/portal_pool.rb
@@ -30,6 +30,10 @@ class PortalPool < ActiveRecord::Base
validates_presence_of :name
validates_uniqueness_of :name, :scope => :cloud_account_id
+ 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
diff --git a/src/app/models/privilege.rb b/src/app/models/privilege.rb
new file mode 100644
index 0000000..06dd18e
--- /dev/null
+++ b/src/app/models/privilege.rb
@@ -0,0 +1,76 @@
+#
+# 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
+# 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.
+
+class Privilege < ActiveRecord::Base
+ has_and_belongs_to_many :roles
+
+ validates_presence_of :name
+ validates_uniqueness_of :name
+
+ #default privileges
+ PERM_SET = "set_perms" # can create/modify/delete permission
+ # records on this object
+ PERM_VIEW = "view_perms" # can view permission records on this
+ # object
+
+ # instance privileges normally checked at the pool level, although
+ # instance-specific overrides could be a future enhancement.
+ INSTANCE_MODIFY = "instance_modify" # can create, modify, delete, or
+ # control (start, stop, etc) instances
+ INSTANCE_CONTROL = "instance_control" # can control (start, stop, etc)
+ # instances
+ INSTANCE_VIEW = "instance_view" # can view instance metadata
+ # do we need a separate "connect" privilege?
+
+ # stats privileges normally checked at the pool level, although
+ # instance-specific overrides could be a future enhancement.
+ STATS_VIEW = "stats_view" # can view monitoring data for
+ # instances
+
+ # account privileges normally checked at the provider level, although
+ # account-specific overrides could be a future enhancement.
+ ACCOUNT_MODIFY = "account_modify" # can create or modify cloud accounts
+ ACCOUNT_VIEW = "account_view" # can create or modify cloud accounts
+
+ # pool privileges normally checked at the provider level
+ # (and at the account level for choosing which accounts are visible on the
+ # new pool form), although
+ # pool-specific overrides could be a future enhancement.
+ POOL_MODIFY = "pool_modify" # can create or modify a pool
+ POOL_VIEW = "pool_view" # can view a pool
+
+ # quota privileges normally checked at the pool or account level,
+ # depending on which quota level we're dealing with
+ # (account level for cloud-imposed quota, pool level for portal quota)
+ QUOTA_MODIFY = "quota_modify" # can create or modify a quota
+ QUOTA_VIEW = "quota_view" # can view a quota
+
+ # provider privileges normally checked at the provider level, although
+ # 'new provider' action requires this privilege at the SystemPermission level
+ PROVIDER_MODIFY = "provider_modify" # can create or modify a provider
+ PROVIDER_VIEW = "provider_view" # can view a provider
+
+ # normally checked at the SystemPermission level
+ USER_MODIFY = "user_modify" # can create a new user (other than
+ # self-registration) or modify another
+ # user's metadata (for admin-level
+ # actions)
+ USER_VIEW = "user_view" # can view a user's profile data
+
+end
diff --git a/src/app/models/provider.rb b/src/app/models/provider.rb
index b7a071a..dab9fee 100644
--- a/src/app/models/provider.rb
+++ b/src/app/models/provider.rb
@@ -34,6 +34,10 @@ class Provider < ActiveRecord::Base
validates_presence_of :cloud_type
validates_presence_of :url
+ has_many :permissions, :as => :permission_object, :dependent => :destroy,
+ :include => [:role],
+ :order => "permissions.id ASC"
+
def connect
begin
return DeltaCloud.new(nil, nil, url)
diff --git a/src/app/models/role.rb b/src/app/models/role.rb
new file mode 100644
index 0000000..ed7aaf4
--- /dev/null
+++ b/src/app/models/role.rb
@@ -0,0 +1,34 @@
+#
+# 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
+# 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.
+
+class Role < ActiveRecord::Base
+ has_many :permissions
+ has_and_belongs_to_many :privileges, :uniq => true
+
+ validates_presence_of :name
+ validates_uniqueness_of :name
+
+
+ #default roles
+ SUPER_ADMIN = "Super Admin"
+ ADMIN = "Administrator"
+ USER = "User"
+ MONITOR = "Monitor"
+ CLOUD_USER = "Cloud User"
+end
diff --git a/src/db/migrate/20091008153046_create_privileges.rb b/src/db/migrate/20091008153046_create_privileges.rb
new file mode 100644
index 0000000..53817f8
--- /dev/null
+++ b/src/db/migrate/20091008153046_create_privileges.rb
@@ -0,0 +1,49 @@
+#
+# 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
+# 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.
+
+class CreatePrivileges < ActiveRecord::Migration
+ def self.up
+ create_table :privileges do |t|
+ t.string :name, :null => false
+ t.integer :lock_version, :default => 0
+
+ t.timestamps
+ end
+
+ #create default privileges
+ privileges = ["set_perms", "view_perms",
+ "instance_modify", "instance_control", "instance_view",
+ "instance_console", "stats_view",
+ "account_modify", "account_view",
+ "pool_modify", "pool_view",
+ "quota_modify", "quota_view",
+ "provider_modify", "provider_view",
+ "user_modify", "user_view"]
+ Privilege.transaction do
+ privileges.each do |priv_name|
+ privilege = Privilege.new({:name => priv_name})
+ privilege.save!
+ end
+ end
+ end
+
+ def self.down
+ drop_table :privileges
+ end
+end
diff --git a/src/db/migrate/20091008153058_create_roles.rb b/src/db/migrate/20091008153058_create_roles.rb
new file mode 100644
index 0000000..15e91c5
--- /dev/null
+++ b/src/db/migrate/20091008153058_create_roles.rb
@@ -0,0 +1,112 @@
+#
+# 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
+# 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.
+
+class CreateRoles < ActiveRecord::Migration
+ def self.up
+ create_table :roles do |t|
+ t.string :name, :null => false
+ t.string :scope, :null => false
+ t.integer :lock_version, :default => 0
+
+ t.timestamps
+ end
+ create_table :privileges_roles, :id => false do |t|
+ t.integer :privilege_id, :null => false
+ t.integer :role_id, :null => false
+ end
+
+ #create default roles
+ roles = {"Instance Controller" =>
+ {:role_scope => "PortalPool",
+ :privileges => ["instance_console",
+ "instance_control",
+ "instance_view",
+ "pool_view"]},
+ "Instance Controller With Monitoring" =>
+ {:role_scope => "PortalPool",
+ :privileges => ["instance_console",
+ "instance_control",
+ "instance_view",
+ "pool_view",
+ "stats_view"]},
+ "Instance Creator and User" =>
+ {:role_scope => "PortalPool",
+ :privileges => ["instance_console",
+ "instance_control",
+ "instance_view",
+ "pool_view",
+ "stats_view",
+ "instance_modify",
+ "quota_view",
+ "set_perms",
+ "view_perms"]},
+ "Pool Creator" =>
+ {:role_scope => "Provider",
+ :privileges => ["provider_view",
+ "pool_modify",
+ "pool_view",
+ "quota_view"]},
+ "Pool Administrator" =>
+ {:role_scope => "Provider",
+ :privileges => ["provider_view",
+ "pool_modify",
+ "pool_view",
+ "quota_view",
+ "quota_modify",
+ "account_view",
+ "account_modify"]},
+ "Account Administrator" =>
+ {:role_scope => "CloudAccount",
+ :privileges => ["set_perms",
+ "view_perms",
+ "account_view",
+ "account_modify"]},
+ "Account User" =>
+ {:role_scope => "CloudAccount",
+ :privileges => ["account_view"]},
+ "Provider Administrator" =>
+ {:role_scope => "BasePortalObject",
+ :privileges => ["provider_modify",
+ "provider_view"]},
+ "Administrator" =>
+ {:role_scope => "BasePortalObject",
+ :privileges => ["provider_modify",
+ "provider_view",
+ "user_modify",
+ "user_view",
+ "view_perms",
+ "set_perms"]}
+
+ }
+ Role.transaction do
+ roles.each do |role_name, role_hash|
+ role = Role.new({:name => role_name, :scope => role_hash[:role_scope]})
+ role.save!
+ role.privileges = role_hash[:privileges].collect do |priv_name|
+ Privilege.find_by_name(priv_name)
+ end
+ role.save!
+ end
+ end
+ end
+
+ def self.down
+ drop_table :roles
+ end
+end
diff --git a/src/db/migrate/20091008153106_create_permissions.rb b/src/db/migrate/20091008153106_create_permissions.rb
new file mode 100644
index 0000000..6e5a7a5
--- /dev/null
+++ b/src/db/migrate/20091008153106_create_permissions.rb
@@ -0,0 +1,37 @@
+#
+# 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
+# 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.
+
+class CreatePermissions < ActiveRecord::Migration
+ def self.up
+ create_table :permissions do |t|
+ t.integer :role_id, :null => false
+ t.integer :user_id, :null => false
+ t.integer :permission_object_id
+ t.string :permission_object_type
+ t.integer :pool_id
+ t.integer :lock_version, :default => 0
+
+ t.timestamps
+ end
+ end
+
+ def self.down
+ drop_table :permissions
+ end
+end
diff --git a/src/db/migrate/20091019215838_create_base_portal_objects.rb b/src/db/migrate/20091019215838_create_base_portal_objects.rb
new file mode 100644
index 0000000..badea5d
--- /dev/null
+++ b/src/db/migrate/20091019215838_create_base_portal_objects.rb
@@ -0,0 +1,14 @@
+class CreateBasePortalObjects < ActiveRecord::Migration
+ def self.up
+ create_table :base_portal_objects do |t|
+ t.string :name, :null => false
+ t.timestamps
+ end
+
+ BasePortalObject.new({:name => "general_permission_scope"}).save!
+ end
+
+ def self.down
+ drop_table :base_portal_objects
+ end
+end
diff --git a/src/test/fixtures/base_portal_objects.yml b/src/test/fixtures/base_portal_objects.yml
new file mode 100644
index 0000000..5bf0293
--- /dev/null
+++ b/src/test/fixtures/base_portal_objects.yml
@@ -0,0 +1,7 @@
+# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
+
+# one:
+# column: value
+#
+# two:
+# column: value
diff --git a/src/test/fixtures/permissions.yml b/src/test/fixtures/permissions.yml
new file mode 100644
index 0000000..5bf0293
--- /dev/null
+++ b/src/test/fixtures/permissions.yml
@@ -0,0 +1,7 @@
+# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
+
+# one:
+# column: value
+#
+# two:
+# column: value
diff --git a/src/test/fixtures/privileges.yml b/src/test/fixtures/privileges.yml
new file mode 100644
index 0000000..5bf0293
--- /dev/null
+++ b/src/test/fixtures/privileges.yml
@@ -0,0 +1,7 @@
+# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
+
+# one:
+# column: value
+#
+# two:
+# column: value
diff --git a/src/test/fixtures/roles.yml b/src/test/fixtures/roles.yml
new file mode 100644
index 0000000..5bf0293
--- /dev/null
+++ b/src/test/fixtures/roles.yml
@@ -0,0 +1,7 @@
+# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
+
+# one:
+# column: value
+#
+# two:
+# column: value
diff --git a/src/test/unit/base_portal_object_test.rb b/src/test/unit/base_portal_object_test.rb
new file mode 100644
index 0000000..e6e4b9d
--- /dev/null
+++ b/src/test/unit/base_portal_object_test.rb
@@ -0,0 +1,8 @@
+require 'test_helper'
+
+class BasePortalObjectTest < ActiveSupport::TestCase
+ # Replace this with your real tests.
+ test "the truth" do
+ assert true
+ end
+end
diff --git a/src/test/unit/permission_test.rb b/src/test/unit/permission_test.rb
new file mode 100644
index 0000000..08fcc0b
--- /dev/null
+++ b/src/test/unit/permission_test.rb
@@ -0,0 +1,8 @@
+require 'test_helper'
+
+class PermissionTest < ActiveSupport::TestCase
+ # Replace this with your real tests.
+ test "the truth" do
+ assert true
+ end
+end
diff --git a/src/test/unit/privilege_test.rb b/src/test/unit/privilege_test.rb
new file mode 100644
index 0000000..459d805
--- /dev/null
+++ b/src/test/unit/privilege_test.rb
@@ -0,0 +1,8 @@
+require 'test_helper'
+
+class PrivilegeTest < ActiveSupport::TestCase
+ # Replace this with your real tests.
+ test "the truth" do
+ assert true
+ end
+end
diff --git a/src/test/unit/role_test.rb b/src/test/unit/role_test.rb
new file mode 100644
index 0000000..b0374ce
--- /dev/null
+++ b/src/test/unit/role_test.rb
@@ -0,0 +1,8 @@
+require 'test_helper'
+
+class RoleTest < ActiveSupport::TestCase
+ # Replace this with your real tests.
+ test "the truth" do
+ assert true
+ end
+end
--
1.6.0.6
14 years, 4 months