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 2011/02/09 14:30:02 UTC

[PATCH core] Allow creating 'sandbox' instances in GoGrid

From: Michal Fojtik <mf...@redhat.com>

---
 server/lib/deltacloud/base_driver/features.rb      |    7 +++++
 .../lib/deltacloud/drivers/gogrid/gogrid_driver.rb |   24 ++++++++++---------
 server/views/instances/new.html.haml               |    5 ++++
 3 files changed, 25 insertions(+), 11 deletions(-)

diff --git a/server/lib/deltacloud/base_driver/features.rb b/server/lib/deltacloud/base_driver/features.rb
index 76d1d22..a276314 100644
--- a/server/lib/deltacloud/base_driver/features.rb
+++ b/server/lib/deltacloud/base_driver/features.rb
@@ -204,5 +204,12 @@ module Deltacloud
       end
     end
 
+    declare_feature :instances, :sandboxing do
+      description "Allow lanuching sandbox images"
+      operation :create do
+        param :sandbox, :string,  :optional
+      end
+    end
+
   end
 end
diff --git a/server/lib/deltacloud/drivers/gogrid/gogrid_driver.rb b/server/lib/deltacloud/drivers/gogrid/gogrid_driver.rb
index 909fade..e17cbe9 100644
--- a/server/lib/deltacloud/drivers/gogrid/gogrid_driver.rb
+++ b/server/lib/deltacloud/drivers/gogrid/gogrid_driver.rb
@@ -36,6 +36,7 @@ module Deltacloud
 class GogridDriver < Deltacloud::BaseDriver
 
   feature :instances, :authentication_password
+  feature :instances, :sandboxing
 
   def hardware_profiles(credentials, opts={})
     client = new_client(credentials)
@@ -87,7 +88,7 @@ class GogridDriver < Deltacloud::BaseDriver
     end
   end
 
-  def create_instance(credentials, image_id, opts=nil)
+  def create_instance(credentials, image_id, opts={})
     server_ram = nil
     if opts[:hwp_memory]
       mem = opts[:hwp_memory].to_i
@@ -96,14 +97,15 @@ class GogridDriver < Deltacloud::BaseDriver
       server_ram = "512MB"
     end
     client = new_client(credentials)
-    name = (opts[:name] && opts[:name]!='') ? opts[:name] : get_random_instance_name
+    params = {
+      'name' => opts[:name] || get_random_instance_name,
+      'image' => image_id,
+      'server.ram' => server_ram,
+      'ip' => get_free_ip_from_realm(credentials, opts[:realm_id] || '1')
+    }
+    params.merge!('isSandbox' => 'true') if opts[:sandbox] 
     safely do
-      instance = client.request('grid/server/add', {
-        'name' => name,
-        'image' => image_id,
-        'server.ram' => server_ram,
-        'ip' => get_free_ip_from_realm(credentials, opts[:realm_id] || '1')
-      })['list'].first
+      instance = client.request('grid/server/add', params)['list'].first
       if instance
         login_data = get_login_data(client, instance[:id])
         if login_data['username'] and login_data['password']
@@ -285,8 +287,6 @@ class GogridDriver < Deltacloud::BaseDriver
     'Unregistering instances from load balancer is not supported in GoGrid')
   end
 
-
-
   def key(credentials, opts=nil)
     keys(credentials, opts).first
   end
@@ -425,7 +425,9 @@ class GogridDriver < Deltacloud::BaseDriver
         opts[:hwp_memory] = (mem.to_i * 1024).to_s
       end
     end
+
     prof = InstanceProfile.new("server", opts)
+    instance_name = "#{instance['name']} (sandbox)" if instance['isSandbox']
 
     hwp_name = instance['image']['name']
     state = convert_server_state(instance['state']['name'], instance['id'])
@@ -439,7 +441,7 @@ class GogridDriver < Deltacloud::BaseDriver
       :owner_id => owner_id,
       :image_id => instance['image']['id'],
       :instance_profile => prof,
-      :name => instance['name'],
+      :name => instance_name || instance['name'],
       :realm_id => instance['ip']['datacenter']['id'],
       :state => state,
       :actions => instance_actions_for(state),
diff --git a/server/views/instances/new.html.haml b/server/views/instances/new.html.haml
index 3307183..5d075a6 100644
--- a/server/views/instances/new.html.haml
+++ b/server/views/instances/new.html.haml
@@ -14,6 +14,11 @@
       %label
         Number of instances:
       %input{ :type => :text, :value => "1", :name => :instance_count }
+  -if driver_has_feature?(:sandboxing)
+    %p
+      %label
+        Sandbox?:
+      %input{ :type => :checkbox, :value => "1", :name => :sandbox }
   -if driver_has_feature?(:register_to_load_balancer)
     %p
       %label
-- 
1.7.4


Re: [PATCH core] Allow creating 'sandbox' instances in GoGrid

Posted by Michal Fojtik <mf...@redhat.com>.
On 09/02/11 15:27 -0800, David Lutterkort wrote:
>On Wed, 2011-02-09 at 14:30 +0100, mfojtik@redhat.com wrote:
>> From: Michal Fojtik <mf...@redhat.com>
>>
>> ---
>>  server/lib/deltacloud/base_driver/features.rb      |    7 +++++
>>  .../lib/deltacloud/drivers/gogrid/gogrid_driver.rb |   24 ++++++++++---------
>>  server/views/instances/new.html.haml               |    5 ++++
>>  3 files changed, 25 insertions(+), 11 deletions(-)
>
>ACK, with two comments: (1) how do we test this ? (2) minor nit below:

I'll remove (sandbox) string from images, it was used just for testing.
I agree that we can add some element or attribute to image which will
indicate that it's sandbox instance.

Testing: Let's check this attribute. So basically we can create a new
instance using sandbox param and then check if this instance has sandbox
attribute.

   -- Michal

>
>> diff --git a/server/lib/deltacloud/drivers/gogrid/gogrid_driver.rb b/server/lib/deltacloud/drivers/gogrid/gogrid_driver.rb
>> index 909fade..e17cbe9 100644
>> --- a/server/lib/deltacloud/drivers/gogrid/gogrid_driver.rb
>> +++ b/server/lib/deltacloud/drivers/gogrid/gogrid_driver.rb
>
>> @@ -425,7 +425,9 @@ class GogridDriver < Deltacloud::BaseDriver
>>          opts[:hwp_memory] = (mem.to_i * 1024).to_s
>>        end
>>      end
>> +
>>      prof = InstanceProfile.new("server", opts)
>> +    instance_name = "#{instance['name']} (sandbox)" if instance['isSandbox']
>
>We shouldn't modify the name of the instance - if users are using these
>names to identify instances, it would be very bad if we change them
>behind their backs.
>
>It's more work internally, but if we need to indicate that an instance
>is sandboxed, we should do that with a separate element in the instance
>XML.
>
>David
>
>

-- 
--------------------------------------------------------
Michal Fojtik, mfojtik@redhat.com
Deltacloud API: http://deltacloud.org
--------------------------------------------------------

Re: [PATCH core] Allow creating 'sandbox' instances in GoGrid

Posted by David Lutterkort <lu...@redhat.com>.
On Wed, 2011-02-09 at 14:30 +0100, mfojtik@redhat.com wrote:
> From: Michal Fojtik <mf...@redhat.com>
> 
> ---
>  server/lib/deltacloud/base_driver/features.rb      |    7 +++++
>  .../lib/deltacloud/drivers/gogrid/gogrid_driver.rb |   24 ++++++++++---------
>  server/views/instances/new.html.haml               |    5 ++++
>  3 files changed, 25 insertions(+), 11 deletions(-)

ACK, with two comments: (1) how do we test this ? (2) minor nit below:

> diff --git a/server/lib/deltacloud/drivers/gogrid/gogrid_driver.rb b/server/lib/deltacloud/drivers/gogrid/gogrid_driver.rb
> index 909fade..e17cbe9 100644
> --- a/server/lib/deltacloud/drivers/gogrid/gogrid_driver.rb
> +++ b/server/lib/deltacloud/drivers/gogrid/gogrid_driver.rb

> @@ -425,7 +425,9 @@ class GogridDriver < Deltacloud::BaseDriver
>          opts[:hwp_memory] = (mem.to_i * 1024).to_s
>        end
>      end
> +
>      prof = InstanceProfile.new("server", opts)
> +    instance_name = "#{instance['name']} (sandbox)" if instance['isSandbox']

We shouldn't modify the name of the instance - if users are using these
names to identify instances, it would be very bad if we change them
behind their backs.

It's more work internally, but if we need to indicate that an instance
is sandboxed, we should do that with a separate element in the instance
XML.

David