From: martyntaylor <[email protected]>

---
 src/app/controllers/instance_controller.rb |   24 +++++++++++++++---------
 1 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/src/app/controllers/instance_controller.rb 
b/src/app/controllers/instance_controller.rb
index ad90404..a81af6a 100644
--- a/src/app/controllers/instance_controller.rb
+++ b/src/app/controllers/instance_controller.rb
@@ -98,16 +98,22 @@ class InstanceController < ApplicationController
                       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'
+      if Quota.can_start_instance?(@instance, nil)
+        @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
       else
-        @pool = @instance.pool
+        @instance.destroy
+        flash[:notice] = "Quota Exceeded: Could not create instance"
+        @hardware_profiles = HardwareProfile.all
         render :action => 'configure'
       end
     else
-- 
1.7.2.3

_______________________________________________
deltacloud-devel mailing list
[email protected]
https://fedorahosted.org/mailman/listinfo/deltacloud-devel

Reply via email to