incubator-deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@redhat.com
Subject [PATCH core] Allow creating 'sandbox' instances in GoGrid
Date Wed, 09 Feb 2011 13:30:02 GMT
From: Michal Fojtik <mfojtik@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


Mime
View raw message