Permalink
Browse files

BZ#644534 Added check for Quota before creating instance

https://bugzilla.redhat.com/show_bug.cgi?id=644534

This patch adds a quota check to the webapp, so the user
will be notified that their instance cannot start until
they have free quota, but in the background condor will
continue to try to start the instance until such quota is
available. Instance will show in list as 'new' until
condor can do something with it.
  • Loading branch information...
1 parent 66d91fe commit fe3ae2827eef9956415543ae01aadfe1855c6547 @mtaylor mtaylor committed with morazi Oct 28, 2010
Showing with 27 additions and 21 deletions.
  1. +15 −13 src/app/controllers/instance_controller.rb
  2. +12 −8 src/app/models/quota.rb
View
28 src/app/controllers/instance_controller.rb
@@ -107,20 +107,22 @@ def create
Pool.find(@instance.pool_id))
#FIXME: This should probably be in a transaction
if @instance.save!
-
- @task = InstanceTask.new({:user => current_user,
- :task_target => @instance,
- :action => InstanceTask::ACTION_CREATE})
- if @task.save
- condormatic_instance_create(@task)
- flash[:notice] = "Instance added."
- redirect_to :action => 'index'
- else
- @pool = @instance.pool
- render :action => 'configure'
- end
+ @task = InstanceTask.new({:user => current_user,
+ :task_target => @instance,
+ :action => InstanceTask::ACTION_CREATE})
+ if @task.save
+ condormatic_instance_create(@task)
+ if Quota.can_start_instance?(@instance, nil)
+ flash[:notice] = "Instance added."
+ else
+ flash[:warning] = "Quota Exceeded: Instance will not start until you have free quota"
+ end
+ else
+ @pool = @instance.pool
+ render :action => 'configure'
+ end
+ redirect_to :action => 'index'
else
- #@pool = Pool.find(@instance.pool_id)
@hardware_profiles = HardwareProfile.all
render :action => 'configure'
end
View
20 src/app/models/quota.rb
@@ -49,21 +49,25 @@ class Quota < ActiveRecord::Base
def self.can_create_instance?(instance, cloud_account)
[instance.owner, instance.pool, cloud_account].each do |parent|
- quota = Quota.find(parent.quota_id)
- potential_total_instances = quota.total_instances + 1
- if !Quota.no_limit(quota.maximum_total_instances) && (quota.maximum_total_instances < potential_total_instances)
- return false
+ if parent
+ quota = Quota.find(parent.quota_id)
+ potential_total_instances = quota.total_instances + 1
+ if !Quota.no_limit(quota.maximum_total_instances) && (quota.maximum_total_instances < potential_total_instances)
+ return false
+ end
end
end
return true
end
def self.can_start_instance?(instance, cloud_account)
[instance.owner, instance.pool, cloud_account].each do |parent|
- quota = Quota.find(parent.quota_id)
- potential_running_instances = quota.running_instances + 1
- if !Quota.no_limit(quota.maximum_running_instances) && quota.maximum_running_instances < potential_running_instances
- return false
+ if parent
+ quota = Quota.find(parent.quota_id)
+ potential_running_instances = quota.running_instances + 1
+ if !Quota.no_limit(quota.maximum_running_instances) && quota.maximum_running_instances < potential_running_instances
+ return false
+ end
end
end
return true

0 comments on commit fe3ae28

Please sign in to comment.