You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@deltacloud.apache.org by mf...@redhat.com on 2010/08/24 16:04:29 UTC

Support for multiple instance launch for EC2

Hi,

This patch add a new feature which allow user to launch multiple
instances at once using same image.
Support is included for EC2 at this time and I tested this feature
against real EC2.

Also I made a small clean up in core code. I removed flavors and accounts
collections from JSON parser and pushed key collection in.
Please be sure, you add new collection here otherwise JSON output
will not work.

Last improvement is support for specifying response format using
simple query attribute 'format'. This is an addition and all other
ways (like Accept, extension) will still work as ussual.
To try this patch, simply browse to:

http://localhost:3001/api/instances?format=json

 -- Michal


[PATCH core 2/4] Removed obsoleted collections (account, flavor) and added keys

Posted by mf...@redhat.com.
---
 server/lib/deltacloud/helpers/conversion_helper.rb |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/server/lib/deltacloud/helpers/conversion_helper.rb b/server/lib/deltacloud/helpers/conversion_helper.rb
index e96f9b7..bfe7800 100644
--- a/server/lib/deltacloud/helpers/conversion_helper.rb
+++ b/server/lib/deltacloud/helpers/conversion_helper.rb
@@ -22,7 +22,7 @@ require 'deltacloud/base_driver'
 module ConversionHelper
 
   def convert_to_json(type, obj)
-    if ( [ :flavor, :account, :image, :realm, :instance, :storage_volume, :storage_snapshot, :hardware_profile ].include?( type ) )
+    if ( [ :image, :realm, :instance, :storage_volume, :storage_snapshot, :hardware_profile, :key ].include?( type ) )
       if Array.eql?(obj.class)
         data = obj.collect do |o|
           o.to_hash.merge({ :href => self.send(:"#{type}_url", type.eql?(:hardware_profile) ? o.name : o.id ) })
-- 
1.7.2


[PATCH core 1/4] Added params[:format] to allow set response type using query parameter

Posted by mf...@redhat.com.
---
 server/lib/sinatra/respond_to.rb |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/server/lib/sinatra/respond_to.rb b/server/lib/sinatra/respond_to.rb
index f4704ea..f88c025 100644
--- a/server/lib/sinatra/respond_to.rb
+++ b/server/lib/sinatra/respond_to.rb
@@ -57,6 +57,9 @@ module Sinatra
             if ext
               @mime_types = [ Helpers::mime_type(ext) ]
               format ext
+            elsif (params[:format])
+              @mime_types = [Helpers::mime_type(params[:format])]
+              format params[:format]
             end
           end
         end
-- 
1.7.2


[PATCH core 3/4] Added JQuery code to display select box for keys when creating a new instance

Posted by mf...@redhat.com.
---
 server/public/javascripts/application.js |    9 +++++++++
 server/views/instances/new.html.haml     |    8 +++++++-
 2 files changed, 16 insertions(+), 1 deletions(-)

diff --git a/server/public/javascripts/application.js b/server/public/javascripts/application.js
index 80e1d1c..32d77d7 100644
--- a/server/public/javascripts/application.js
+++ b/server/public/javascripts/application.js
@@ -29,4 +29,13 @@ $(document).ready(function() {
     return false;
   })
 
+  if ($("select[name=keyname]").length) {
+    $.getJSON('/api/keys?format=json', function(data) {
+      $("select[name=keyname]").empty()
+      $.each(data.keys, function(i, key){
+        $("select[name=keyname]").append('<option value="'+key.id+'">'+key.id+'</option>')
+      })
+    })
+  }
+
 })
diff --git a/server/views/instances/new.html.haml b/server/views/instances/new.html.haml
index 6d67c2d..3846886 100644
--- a/server/views/instances/new.html.haml
+++ b/server/views/instances/new.html.haml
@@ -13,7 +13,13 @@
     %p
       %label
         Instance Keyname:
-        %input{:name => 'keyname', :size => 30 }
+        %select{:name => 'keyname'}
+          %option loading...
+  -if driver_has_feature?(:create_multiple_instance)
+    %p
+      %label
+        Number of instances to launch:
+        %input{:name => 'amount', :size => 30, :value => '1' }
   - if !@hardware_profiles.empty?
     %h3 What size machine?
     - for hwp in @hardware_profiles
-- 
1.7.2


Re: [PATCH core 4/4] Added possibility to lunch multiple instances at once for EC2

Posted by Michal Fojtik <mf...@redhat.com>.
On 26/08/10 16:00 -0700, David Lutterkort wrote:
>On Tue, 2010-08-24 at 16:04 +0200, mfojtik@redhat.com wrote:
>> diff --git a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
>> index 909eca3..91e7855 100644
>> --- a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
>> +++ b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
>> @@ -40,6 +40,7 @@ class EC2Driver < Deltacloud::BaseDriver
>>    end
>>
>>    feature :instances, :user_data
>> +  feature :instances, :create_multiple_instance
>>    feature :instances, :authentication_key
>>    feature :images, :owner_id
>>
>> @@ -180,6 +181,8 @@ class EC2Driver < Deltacloud::BaseDriver
>>        hwp = find_hardware_profile(credentials, opts[:hwp_id], image.id)
>>        ec2_instances = ec2.run_instances(
>>          :image_id => image.id,
>> +        :min_count => opts[:amount].to_i || 1,
>> +        :max_count => opts[:amount].to_i || 1,
>
>Why not expose min_count and max_count directly, i.e. feature
>create_multiple_instances adds both as parameters to the crete call ?

Yes, but for GoGrid this could be confusing, since they doesn't support
min/max_count. We need to find out consensus for both drivers.

  -- Michal

-- 
--------------------------------------------------------
Michal Fojtik, mfojtik@redhat.com, +420 532 294 4307
Ruby / Ruby On Rails Developer
Deltacloud API: http://deltacloud.org
--------------------------------------------------------

Re: [PATCH core 4/4] Added possibility to lunch multiple instances at once for EC2

Posted by David Lutterkort <lu...@redhat.com>.
On Tue, 2010-08-24 at 16:04 +0200, mfojtik@redhat.com wrote:
> diff --git a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
> index 909eca3..91e7855 100644
> --- a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
> +++ b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
> @@ -40,6 +40,7 @@ class EC2Driver < Deltacloud::BaseDriver
>    end
>  
>    feature :instances, :user_data
> +  feature :instances, :create_multiple_instance
>    feature :instances, :authentication_key
>    feature :images, :owner_id
>  
> @@ -180,6 +181,8 @@ class EC2Driver < Deltacloud::BaseDriver
>        hwp = find_hardware_profile(credentials, opts[:hwp_id], image.id)
>        ec2_instances = ec2.run_instances(
>          :image_id => image.id,
> +        :min_count => opts[:amount].to_i || 1,
> +        :max_count => opts[:amount].to_i || 1,

Why not expose min_count and max_count directly, i.e. feature
create_multiple_instances adds both as parameters to the crete call ?

David



[PATCH core 4/4] Added possibility to lunch multiple instances at once for EC2

Posted by mf...@redhat.com.
---
 server/lib/deltacloud/base_driver/features.rb   |    6 ++++++
 server/lib/deltacloud/drivers/ec2/ec2_driver.rb |    3 +++
 2 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/server/lib/deltacloud/base_driver/features.rb b/server/lib/deltacloud/base_driver/features.rb
index 3ed4085..1ed7be7 100644
--- a/server/lib/deltacloud/base_driver/features.rb
+++ b/server/lib/deltacloud/base_driver/features.rb
@@ -162,5 +162,11 @@ module Deltacloud
       description "Size instances according to changes to a hardware profile"
       # The parameters are filled in from the hardware profiles
     end
+
+    declare_feature :instances, :create_multiple_instance do
+      operation :create do
+        param :amount, :string, :optional
+      end
+    end
   end
 end
diff --git a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
index 909eca3..91e7855 100644
--- a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
+++ b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
@@ -40,6 +40,7 @@ class EC2Driver < Deltacloud::BaseDriver
   end
 
   feature :instances, :user_data
+  feature :instances, :create_multiple_instance
   feature :instances, :authentication_key
   feature :images, :owner_id
 
@@ -180,6 +181,8 @@ class EC2Driver < Deltacloud::BaseDriver
       hwp = find_hardware_profile(credentials, opts[:hwp_id], image.id)
       ec2_instances = ec2.run_instances(
         :image_id => image.id,
+        :min_count => opts[:amount].to_i || 1,
+        :max_count => opts[:amount].to_i || 1,
         :user_data => opts[:user_data],
         :key_name => opts[:keyname],
         :availability_zone => realm_id,
-- 
1.7.2