From: Martyn Taylor mtaylor@redhat.com
--- .../controllers/resources/instances_controller.rb | 28 +++++++++++++++++++- src/config/routes.rb | 5 +++- 2 files changed, 31 insertions(+), 2 deletions(-)
diff --git a/src/app/controllers/resources/instances_controller.rb b/src/app/controllers/resources/instances_controller.rb index 9482a8d..5f2ccf8 100644 --- a/src/app/controllers/resources/instances_controller.rb +++ b/src/app/controllers/resources/instances_controller.rb @@ -1,5 +1,5 @@ class Resources::InstancesController < ApplicationController - before_filter :require_user + before_filter :require_user, :except => [:can_start, :can_create] before_filter :load_instance, :only => [:show, :remove_failed, :key, :stop] before_filter :set_view_vars, :only => [:show, :index]
@@ -128,6 +128,32 @@ class Resources::InstancesController < ApplicationController redirect_to resources_instances_path end
+ def can_create + begin + cloud_account = CloudAccount.find(params[:cloud_account_id]) + instance = Instance.find(params[:instance_id]) + params = { :request => "can_create", :result => Quota.can_create_instance?(instance, cloud_account) } + render :layout => false, :xml => params.to_xml + rescue ActiveRecord::RecordNotFound + head :not_found + rescue Exception + head :internal_server_error + end + end + + def can_start + begin + cloud_account = CloudAccount.find(params[:cloud_account_id]) + instance = Instance.find(params[:instance_id]) + params = { :request => "can_start", :result => Quota.can_start_instance?(instance, cloud_account) } + render :layout => false, :xml => params.to_xml + rescue ActiveRecord::RecordNotFound + head :not_found + rescue Exception + head :internal_server_error + end + end + private
def load_instance diff --git a/src/config/routes.rb b/src/config/routes.rb index 0aa281b..d920838 100644 --- a/src/config/routes.rb +++ b/src/config/routes.rb @@ -35,9 +35,12 @@ ActionController::Routing::Routes.draw do |map| map.namespace 'resources' do |r| r.resources :pools, :collection => { :multi_destroy => :delete } r.resources :deployments - r.resources :instances, :collection => {:start => :get, :stop => :get, :select_template => :get, :remove_failed => :get}, :member => {:key => :get} + r.resources :instances, :collection => {:start => :get, :stop => :get, :select_template => :get, :remove_failed => :get, :can_start => :get, :can_create => :get }, :member => {:key => :get} end
+ map.can_start_instance '/resources/instances/:instance_id/can_start/:cloud_account_id', :controller => 'resources/instances', :action => 'can_start', :conditions => { :method => :get } + map.can_create_instance '/resources/instances/:instance_id/can_create/:cloud_account_id', :controller => 'resources/instances', :action => 'can_create', :conditions => { :method => :get } + map.namespace 'image_factory' do |r| r.resources :assemblies r.resources :deployables, :collection => { :multi_destroy => :delete }
On 01/28/2011 09:16 AM, mtaylor@redhat.com wrote:
From: Martyn Taylormtaylor@redhat.com
.../controllers/resources/instances_controller.rb | 28 +++++++++++++++++++- src/config/routes.rb | 5 +++- 2 files changed, 31 insertions(+), 2 deletions(-)
diff --git a/src/app/controllers/resources/instances_controller.rb b/src/app/controllers/resources/instances_controller.rb index 9482a8d..5f2ccf8 100644 --- a/src/app/controllers/resources/instances_controller.rb +++ b/src/app/controllers/resources/instances_controller.rb @@ -1,5 +1,5 @@ class Resources::InstancesController< ApplicationController
- before_filter :require_user
- before_filter :require_user, :except => [:can_start, :can_create]
I think in this case we do want to require user -- but we need to redefine require_user so that it handles API calls separately. We should still get the user from the request, but the user/session handling will be different for the API.
I know we haven't really worked out the auth bits here, so perhaps as a first pass we'll have condor pass user_id=... into the URL query string and then have require_user (for api calls only) set @current_user based on the passed-in ID. If we can't do even this for now, then we should disable auth checking _within_ require_user for api calls -- that way there's only one place to fix it up once we solve api auth.
before_filter :load_instance, :only => [:show, :remove_failed, :key, :stop] before_filter :set_view_vars, :only => [:show, :index]
@@ -128,6 +128,32 @@ class Resources::InstancesController< ApplicationController redirect_to resources_instances_path end
- def can_create
- begin
cloud_account = CloudAccount.find(params[:cloud_account_id])
instance = Instance.find(params[:instance_id])
If this is on the instances controller, shouldn't this just be params[:id] ? I'm not sure if this is still true with multiple IDs here, but to be consistent with the rest of the controllers, current object for the current controller is usually just passed as :id
I haven't yet actually run through the code and tested it yet, but I'll do that tomorrow (after any subsequent patches if you have any quick solutions to the require_user issues)
Scott
aeolus-devel@lists.fedorahosted.org