From: Martyn Taylor <mtaylor(a)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 }
--
1.7.3.4