deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@redhat.com
Subject [PATCH core] EC2: Launching more instances using instance_count feature will now return list of launched instances instead of just first instance (DTACLOUD-79)
Date Wed, 14 Sep 2011 08:08:23 GMT
From: Michal Fojtik <mfojtik@redhat.com>

---
 server/lib/deltacloud/drivers/ec2/ec2_driver.rb |   10 ++++++-
 server/server.rb                                |   27 ++++++++++++++++++----
 2 files changed, 30 insertions(+), 7 deletions(-)

diff --git a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
index 736887b..bfeed20 100644
--- a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
+++ b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
@@ -229,8 +229,14 @@ module Deltacloud
             }])
           end
           safely do
-            new_instance = convert_instance(ec2.launch_instances(image_id, instance_options).first)
-            new_instance
+            new_instances = ec2.launch_instances(image_id, instance_options).collect do |i|
+              convert_instance(i)
+            end
+            if new_instances.size == 1
+              new_instances.first
+            else
+              new_instances
+            end
           end
         end
 
diff --git a/server/server.rb b/server/server.rb
index ae8d63d..38fa39b 100644
--- a/server/server.rb
+++ b/server/server.rb
@@ -441,14 +441,31 @@ END
     param :hwp_id,       :string, :optional
     control do
       @instance = driver.create_instance(credentials, params[:image_id], params)
+      if @instance.kind_of? Array
+        @instances = @instance
+        action_handler = "index"
+      else
+        response['Location'] = instance_url(@instance.id)
+        action_handler = "show"
+      end
       status 201  # Created
-      response['Location'] = instance_url(@instance.id)
       respond_to do |format|
-        format.xml  { haml :"instances/show" }
-        format.json { convert_to_json(:instance, @instance) }
+        format.xml  { haml :"instances/#{action_handler}" }
+        format.json do
+          if @instances
+            convert_to_json(:instances, @instances)
+          else
+            convert_to_json(:instance, @instance)
+          end
+        end
         format.html do
-          redirect instance_url(@instance.id) if @instance and @instance.id
-          redirect instances_url
+          if @instances
+            haml :"instances/index"
+          elsif @instance and @instance.id
+            redirect instance_url(@instance.id)
+          else
+            redirect instances_url
+          end
         end
       end
     end
-- 
1.7.6.1


Mime
View raw message