From: Martyn Taylor mtaylor@redhat.com
--- src/app/controllers/quotas_controller.rb | 27 ++++++++++++++++++++++++++- 1 files changed, 26 insertions(+), 1 deletions(-)
diff --git a/src/app/controllers/quotas_controller.rb b/src/app/controllers/quotas_controller.rb index e9937fb..26a8f15 100644 --- a/src/app/controllers/quotas_controller.rb +++ b/src/app/controllers/quotas_controller.rb @@ -72,6 +72,32 @@ class QuotasController < ApplicationController redirect_to :action => 'show', :id => @parent, :parent_type => @parent_type end
+ def can_create_instance + begin + cloud_account = CloudAccount.find(params[:cloud_account_id]) + instance = Instance.find(params[:instance_id]) + params = { :request => "can_create_instance", :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_instance + begin + cloud_account = CloudAccount.find(params[:cloud_account_id]) + instance = Instance.find(params[:instance_id]) + params = { :request => "can_start_instance", :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 get_parent_object(params) if params[:parent_type] == "pool" @@ -100,5 +126,4 @@ class QuotasController < ApplicationController return params end
- end
On Thu, 2011-01-27 at 17:16 +0000, mtaylor@redhat.com wrote:
From: Martyn Taylor mtaylor@redhat.com
src/app/controllers/quotas_controller.rb | 27 ++++++++++++++++++++++++++- 1 files changed, 26 insertions(+), 1 deletions(-)
diff --git a/src/app/controllers/quotas_controller.rb b/src/app/controllers/quotas_controller.rb index e9937fb..26a8f15 100644 --- a/src/app/controllers/quotas_controller.rb +++ b/src/app/controllers/quotas_controller.rb @@ -72,6 +72,32 @@ class QuotasController < ApplicationController redirect_to :action => 'show', :id => @parent, :parent_type => @parent_type end
- def can_create_instance
- begin
cloud_account = CloudAccount.find(params[:cloud_account_id])
instance = Instance.find(params[:instance_id])
params = { :request => "can_create_instance", :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_instance
- begin
cloud_account = CloudAccount.find(params[:cloud_account_id])
instance = Instance.find(params[:instance_id])
params = { :request => "can_start_instance", :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 get_parent_object(params) if params[:parent_type] == "pool"
@@ -100,5 +126,4 @@ class QuotasController < ApplicationController return params end
end
Martyn, this looks like a good first pass, talked things over a bit today with Scott and Ian, so I'll give you some feedback based on all that (and hopefully they will chime in if I get something wrong or there is more detail to add).
1. You might be able to simplify the uri a bit if you put these checks in the instance controller, as you would only call this to check if you can perform the action on an instance, so perhaps something like: instances/1/can_start/cloud_account/1
2. We already discussed no auth on this first pass, but Scott was mentioning we would probably want to support http auth, but I think this will require some more discussion, and probably could be in v2 of these methods
3. The quota check (the one you are calling on Quota model itself) should work its way up the hierarchy internally, so if any of the levels of quota are no good, the method still returns false (pool, user, etc).
Aside from those things, Ian said this is basically what he was hoping for, so if you want to incorporate points 1&3, I still think we can defer #2, as we should know from the conductor side what user was trying to start or create this instance (at least I would hope we know that). Ping me tomorrow if you need any clarification of want to discuss any of these points.
-j
aeolus-devel@lists.fedorahosted.org