Signed-off-by: Scott Seago <[email protected]>
---
src/app/controllers/cloud_accounts_controller.rb | 27 ++++++++++++---------
src/app/controllers/portal_pool_controller.rb | 18 ++++++++------
src/app/models/cloud_account.rb | 4 +++
src/app/models/portal_pool.rb | 12 ++++-----
4 files changed, 34 insertions(+), 27 deletions(-)
diff --git a/src/app/controllers/cloud_accounts_controller.rb
b/src/app/controllers/cloud_accounts_controller.rb
index 8f43981..fd9fa83 100644
--- a/src/app/controllers/cloud_accounts_controller.rb
+++ b/src/app/controllers/cloud_accounts_controller.rb
@@ -35,11 +35,7 @@ class CloudAccountsController < ApplicationController
@pool = PortalPool.find(params[:pool_id])
require_privilege(Privilege::ACCOUNT_ADD,@pool)
@cloud_account = CloudAccount.new
- @providers = []
- all_providers = Provider.all
- all_providers.each {|provider|
- @providers << provider if authorized?(Privilege::PROVIDER_VIEW,provider)
- }
+ @providers = Provider.list_for_user(@current_user,
Privilege::PROVIDER_VIEW)
end
@@ -53,13 +49,20 @@ class CloudAccountsController < ApplicationController
def create_from_pool
@pool = PortalPool.find(params[:pool][:id])
- @cloud_account = CloudAccount.new(params[:cloud_account])
- @provider = Provider.find(params[:provider][:id])
- @cloud_account.provider = @provider
- @cloud_account.save!
- @pool.cloud_accounts << @cloud_account unless @pool.cloud_accounts.map{|x|
x.id}.include?(@cloud_account.id)
- @pool.save!
- @pool.populate_realms_and_images([...@cloud_account])
+ require_privilege(Privilege::ACCOUNT_ADD,@pool)
+ PortalPool.transaction do
+ @cloud_account = CloudAccount.new(params[:cloud_account])
+ @provider = Provider.find(params[:provider][:id])
+ @cloud_account.provider = @provider
+ @cloud_account.save!
+ @pool.cloud_accounts << @cloud_account unless
@pool.cloud_accounts.map{|x| x.id}.include?(@cloud_account.id)
+ @pool.save!
+ @pool.populate_realms_and_images([...@cloud_account])
+ perm = Permission.new(:user => @current_user,
+ :role => Role.find_by_name("Account
Administrator"),
+ :permission_object => @cloud_account)
+ perm.save!
+ end
redirect_to :controller => "portal_pool", :action => 'show', :id =>
@pool.id
end
diff --git a/src/app/controllers/portal_pool_controller.rb
b/src/app/controllers/portal_pool_controller.rb
index 354ee7e..69208fa 100644
--- a/src/app/controllers/portal_pool_controller.rb
+++ b/src/app/controllers/portal_pool_controller.rb
@@ -92,22 +92,24 @@ class PortalPoolController < ApplicationController
def accounts_for_pool
@pool = PortalPool.find(params[:pool_id])
- require_privilege(Privilege::ACCOUNT_ADD,@pool)
+ require_privilege(Privilege::ACCOUNT_VIEW,@pool)
@cloud_accounts = []
- all_accounts = CloudAccount.all
+ all_accounts = CloudAccount.list_for_user(@current_user,
Privilege::ACCOUNT_ADD)
all_accounts.each {|account|
- if authorized?(Privilege::ACCOUNT_VIEW,account) &&
authorized?(Privilege::ACCOUNT_ADD,account)
- @cloud_accounts << account unless @pool.cloud_accounts.map{|x|
x.id}.include?(account.id)
- end
+ @cloud_accounts << account unless @pool.cloud_accounts.map{|x|
x.id}.include?(account.id)
}
end
def add_account
@portal_pool = PortalPool.find(params[:portal_pool])
@cloud_account = CloudAccount.find(params[:cloud_account])
- @portal_pool.cloud_accounts << @cloud_account unless
@portal_pool.cloud_accounts.map{|x| x.id}.include?(@cloud_account.id)
- @portal_pool.save!
- @portal_pool.populate_realms_and_images([...@cloud_account])
+ require_privilege(Privilege::ACCOUNT_ADD,@portal_pool)
+ require_privilege(Privilege::ACCOUNT_ADD,@cloud_account)
+ PortalPool.transaction do
+ @portal_pool.cloud_accounts << @cloud_account unless
@portal_pool.cloud_accounts.map{|x| x.id}.include?(@cloud_account.id)
+ @portal_pool.save!
+ @portal_pool.populate_realms_and_images([...@cloud_account])
+ end
redirect_to :action => 'show', :id => @portal_pool.id
end
diff --git a/src/app/models/cloud_account.rb b/src/app/models/cloud_account.rb
index 62df9fa..6d44b64 100644
--- a/src/app/models/cloud_account.rb
+++ b/src/app/models/cloud_account.rb
@@ -52,4 +52,8 @@ class CloudAccount < ActiveRecord::Base
a = CloudAccount.find_by_username_and_provider_id(account["username"],
account["provider_id"])
return a.nil? ? CloudAccount.new(account) : a
end
+
+ def account_prefix_for_realm
+ provider.name + Realm::AGGREGATOR_REALM_PROVIDER_DELIMITER + username
+ end
end
diff --git a/src/app/models/portal_pool.rb b/src/app/models/portal_pool.rb
index 28b700e..73f1909 100644
--- a/src/app/models/portal_pool.rb
+++ b/src/app/models/portal_pool.rb
@@ -43,9 +43,7 @@ class PortalPool < ActiveRecord::Base
def realms
realm_list = []
cloud_accounts.each do |cloud_account|
- prefix = cloud_account.provider.name +
- Realm::AGGREGATOR_REALM_PROVIDER_DELIMITER +
- cloud_account.username
+ prefix = cloud_account.account_prefix_for_realm
realm_list << prefix
cloud_account.provider.realms.each do |realm|
realm_list << prefix + Realm::AGGREGATOR_REALM_ACCOUNT_DELIMITER +
@@ -94,10 +92,9 @@ class PortalPool < ActiveRecord::Base
:provider_id => cloud_account.provider.id)
ar_image.save!
end
- # FIXME: what do we ue for external_key values for front end images?
- # FIXME: this will break if multiple imported accounts (from
different
- # providers) use the same external key
- front_end_image = Image.new(:external_key => ar_image.external_key,
+ front_end_image = Image.new(:external_key =>
+
cloud_account.account_prefix_for_realm +
+ ar_image.external_key,
:name => ar_image.name,
:architecture => ar_image.architecture,
:portal_pool_id => id)
@@ -105,6 +102,7 @@ class PortalPool < ActiveRecord::Base
end
cloud_account.provider.hardware_profiles.each do |hardware_profile|
front_hardware_profile = HardwareProfile.new(:external_key =>
+
cloud_account.account_prefix_for_realm +
hardware_profile.external_key,
:name => hardware_profile.name,
:memory => hardware_profile.memory,
--
1.6.2.5
_______________________________________________
deltacloud-devel mailing list
[email protected]
https://fedorahosted.org/mailman/listinfo/deltacloud-devel