You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@deltacloud.apache.org by Chris Lalancette <cl...@redhat.com> on 2010/08/05 21:57:14 UTC

[PATCH 00/10]: More fixes to the core drivers

This patch series fixes a number of bugs I came across while testing out
various drivers with condor.  The fixes are explained in the individual
patches.

Chris Lalancette


[PATCH 09/10] Fix a cut-n-paste error in the instance description.

Posted by Chris Lalancette <cl...@redhat.com>.
Signed-off-by: Chris Lalancette <cl...@redhat.com>
---
 server/server.rb |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/server/server.rb b/server/server.rb
index 6442371..0f08689 100644
--- a/server/server.rb
+++ b/server/server.rb
@@ -174,7 +174,7 @@ END
   end
 
   operation :show do
-    description 'Show an image identified by "id" parameter.'
+    description 'Show an instance identified by "id" parameter.'
     param :id,           :string, :required
     control { show(:instance) }
   end
-- 
1.7.2


Re: [PATCH 04/10] Return an instance from the gogrid *_instance methods.

Posted by Michal Fojtik <mf...@redhat.com>.
On 05/08/10 15:57 -0400, Chris Lalancette wrote:
>Signed-off-by: Chris Lalancette <cl...@redhat.com>
>---
> .../lib/deltacloud/drivers/gogrid/gogrid_driver.rb |   20 ++++++++------------
> 1 files changed, 8 insertions(+), 12 deletions(-)
>
>diff --git a/server/lib/deltacloud/drivers/gogrid/gogrid_driver.rb b/server/lib/deltacloud/drivers/gogrid/gogrid_driver.rb
>index c0103c9..750e1cd 100644
>--- a/server/lib/deltacloud/drivers/gogrid/gogrid_driver.rb
>+++ b/server/lib/deltacloud/drivers/gogrid/gogrid_driver.rb
>@@ -177,27 +177,23 @@ class GogridDriver < Deltacloud::BaseDriver
>   end
>
>   def reboot_instance(credentials, id)
>-    safely do
>-      new_client(credentials).request('grid/server/power', { 'id' => id, 'power' => 'reboot'})
>-    end
>+    inst = new_client(credentials).request('grid/server/power', { 'name' => id, 'power' => 'reboot'})['list'].first
>+    convert_instance(inst, credentials.user)
>   end
>
>   def destroy_instance(credentials, id)
>-    safely do
>-      new_client(credentials).request('grid/server/delete', { 'id' => id})
>-    end
>+    inst = new_client(credentials).request('grid/server/delete', { 'name' => id})['list'].first
>+    convert_instance(inst, credentials.user)
>   end
>
>   def stop_instance(credentials, id)
>-    safely do
>-      new_client(credentials).request('grid/server/power', { 'id' => id, 'power' => 'off'})
>-    end
>+    inst = new_client(credentials).request('grid/server/power', { 'name' => id, 'power' => 'off'})['list'].first
>+    convert_instance(inst, credentials.user)
>   end
>
>   def start_instance(credentials, id)
>-    safely do
>-      new_client(credentials).request('grid/server/power', { 'id' => id, 'power' => 'on'})
>-    end
>+    inst = new_client(credentials).request('grid/server/power', { 'name' => id, 'power' => 'on'})['list'].first
>+    convert_instance(inst, credentials.user)
>   end
>
>   def key(credentials, opts=nil)

NAK. Please preserve 'safely do; end' blocks, they are extra usefull, for
catching backend exceptions:

    def start_instance(credentials, id)
     safely do
       inst = new_client(credentials).request('grid/server/power', { 'name' => id, 'power' => 'on'})['list'].first
       convert_instance(inst, credentials.user)
     end
    end

  -- Michal

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

[PATCH 04/10] Return an instance from the gogrid *_instance methods.

Posted by Chris Lalancette <cl...@redhat.com>.
Signed-off-by: Chris Lalancette <cl...@redhat.com>
---
 .../lib/deltacloud/drivers/gogrid/gogrid_driver.rb |   20 ++++++++------------
 1 files changed, 8 insertions(+), 12 deletions(-)

diff --git a/server/lib/deltacloud/drivers/gogrid/gogrid_driver.rb b/server/lib/deltacloud/drivers/gogrid/gogrid_driver.rb
index c0103c9..750e1cd 100644
--- a/server/lib/deltacloud/drivers/gogrid/gogrid_driver.rb
+++ b/server/lib/deltacloud/drivers/gogrid/gogrid_driver.rb
@@ -177,27 +177,23 @@ class GogridDriver < Deltacloud::BaseDriver
   end
 
   def reboot_instance(credentials, id)
-    safely do
-      new_client(credentials).request('grid/server/power', { 'id' => id, 'power' => 'reboot'})
-    end
+    inst = new_client(credentials).request('grid/server/power', { 'name' => id, 'power' => 'reboot'})['list'].first
+    convert_instance(inst, credentials.user)
   end
 
   def destroy_instance(credentials, id)
-    safely do
-      new_client(credentials).request('grid/server/delete', { 'id' => id})
-    end
+    inst = new_client(credentials).request('grid/server/delete', { 'name' => id})['list'].first
+    convert_instance(inst, credentials.user)
   end
 
   def stop_instance(credentials, id)
-    safely do
-      new_client(credentials).request('grid/server/power', { 'id' => id, 'power' => 'off'})
-    end
+    inst = new_client(credentials).request('grid/server/power', { 'name' => id, 'power' => 'off'})['list'].first
+    convert_instance(inst, credentials.user)
   end
 
   def start_instance(credentials, id)
-    safely do
-      new_client(credentials).request('grid/server/power', { 'id' => id, 'power' => 'on'})
-    end
+    inst = new_client(credentials).request('grid/server/power', { 'name' => id, 'power' => 'on'})['list'].first
+    convert_instance(inst, credentials.user)
   end
 
   def key(credentials, opts=nil)
-- 
1.7.2


[PATCH 08/10] Fix a typo in a comment in GoGrid.

Posted by Chris Lalancette <cl...@redhat.com>.
Signed-off-by: Chris Lalancette <cl...@redhat.com>
---
 .../lib/deltacloud/drivers/gogrid/gogrid_driver.rb |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/server/lib/deltacloud/drivers/gogrid/gogrid_driver.rb b/server/lib/deltacloud/drivers/gogrid/gogrid_driver.rb
index 0135123..dbcb988 100644
--- a/server/lib/deltacloud/drivers/gogrid/gogrid_driver.rb
+++ b/server/lib/deltacloud/drivers/gogrid/gogrid_driver.rb
@@ -166,7 +166,7 @@ class GogridDriver < Deltacloud::BaseDriver
         if e.message == "400 Bad Request"
           # in the case of a VM that we just made, the grid/server/get method
           # throws a "400 Bad Request error".  In this case we try again by
-          # getting a full listing a filtering on the id.  This could
+          # getting a full listing and filtering on the id.  This could
           # potentially take a long time, but I don't see another way to get
           # information about a newly created instance
           instances = list_instances(credentials, opts[:id])
-- 
1.7.2


[PATCH 10/10] Make terremark use "finish" as the last state.

Posted by Chris Lalancette <cl...@redhat.com>.
Signed-off-by: Chris Lalancette <cl...@redhat.com>
---
 .../drivers/terremark/terremark_driver.rb          |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/server/lib/deltacloud/drivers/terremark/terremark_driver.rb b/server/lib/deltacloud/drivers/terremark/terremark_driver.rb
index ddf548f..e99d330 100644
--- a/server/lib/deltacloud/drivers/terremark/terremark_driver.rb
+++ b/server/lib/deltacloud/drivers/terremark/terremark_driver.rb
@@ -118,7 +118,7 @@ VAPP_STATE_MAP = { "0" =>  "PENDING", "1" =>  "PENDING", "2" =>  "STOPPED", "4"
     running.to(:running)          .on( :reboot )
     running.to(:shutting_down)    .on( :stop )
     shutting_down.to(:stopped)    .automatically
-    stopped.to(:end)              .on( :destroy )
+    stopped.to(:finish)           .on( :destroy )
    end
 
 
-- 
1.7.2


Re: [PATCH 06/10] Canonicalize instance states.

Posted by Chris Lalancette <cl...@redhat.com>.
On 08/05/10 - 03:57:20PM, Chris Lalancette wrote:
> For some drivers, we were passing the raw string we got from
> the cloud provider through as the instance state.  However,
> that doesn't fit in with trying to make the drivers act consistent,
> so make sure all of the drivers have a translation layer between
> the cloud provider's states and the deltcloud API states.  After
> this series, there are only 3 valid deltacloud states: "RUNNING",
> "STOPPED", and "PENDING".  We may want to think about adding
> additional states in the future, but these cover most of the
> current use-cases.

Arg, please ignore this patch for now.  There's a bug in my case statements
that causes it to fail.  I'll follow up with another patch that fixes this
issue.

-- 
Chris Lalancette

[PATCH 06/10] Canonicalize instance states.

Posted by Chris Lalancette <cl...@redhat.com>.
For some drivers, we were passing the raw string we got from
the cloud provider through as the instance state.  However,
that doesn't fit in with trying to make the drivers act consistent,
so make sure all of the drivers have a translation layer between
the cloud provider's states and the deltcloud API states.  After
this series, there are only 3 valid deltacloud states: "RUNNING",
"STOPPED", and "PENDING".  We may want to think about adding
additional states in the future, but these cover most of the
current use-cases.

Signed-off-by: Chris Lalancette <cl...@redhat.com>
---
 server/lib/deltacloud/drivers/ec2/ec2_driver.rb    |   18 +++++++++++++++---
 .../lib/deltacloud/drivers/gogrid/gogrid_driver.rb |    5 +++--
 .../drivers/opennebula/opennebula_driver.rb        |    2 +-
 .../drivers/rackspace/rackspace_driver.rb          |    8 ++++----
 .../lib/deltacloud/drivers/rhevm/rhevm_driver.rb   |   11 +++++++----
 5 files changed, 30 insertions(+), 14 deletions(-)

diff --git a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
index 909eca3..7e5e9ec 100644
--- a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
+++ b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
@@ -201,7 +201,7 @@ class EC2Driver < Deltacloud::BaseDriver
       # at this point, the action has succeeded but our follow-up
       # "describe_instances" failed for some reason.  Create a simple Instance
       # object with only the ID and new state in place
-      state = backup.instancesSet.item.first.currentState.name
+      state = convert_state(backup.instancesSet.item.first.currentState.name)
       Instance.new( {
         :id => id,
         :state => state,
@@ -351,9 +351,21 @@ class EC2Driver < Deltacloud::BaseDriver
     } )
   end
 
+  def convert_state(ec2_state)
+    case ec2_state
+    when :terminated
+      :STOPPED
+    when :running
+      :RUNNING
+    when :pending
+      :PENDING
+    when :'shutting-down'
+      :STOPPED
+    end
+  end
+
   def convert_instance(ec2_instance, owner_id)
-    state = ec2_instance['instanceState']['name'].upcase
-    state_key = state.downcase.underscore.to_sym
+    state = convert_state(ec2_instance['instanceState']['name'])
     realm_id = ec2_instance['placement']['availabilityZone']
     (realm_id = nil ) if ( realm_id == '' )
     hwp_name = ec2_instance['instanceType']
diff --git a/server/lib/deltacloud/drivers/gogrid/gogrid_driver.rb b/server/lib/deltacloud/drivers/gogrid/gogrid_driver.rb
index 750e1cd..e204cbe 100644
--- a/server/lib/deltacloud/drivers/gogrid/gogrid_driver.rb
+++ b/server/lib/deltacloud/drivers/gogrid/gogrid_driver.rb
@@ -282,6 +282,7 @@ class GogridDriver < Deltacloud::BaseDriver
 
   def convert_instance(instance, owner_id)
     hwp_name = instance['image']['name']
+    state = convert_server_state(instance['state']['name'], instance['id'])
 
     Instance.new(
        # note that we use 'name' as the id here, because newly created instances
@@ -294,8 +295,8 @@ class GogridDriver < Deltacloud::BaseDriver
       :instance_profile => InstanceProfile.new(hwp_name),
       :name => instance['name'],
       :realm_id => instance['type']['id'],
-      :state => convert_server_state(instance['state']['name'], instance['id']),
-      :actions => instance_actions_for(convert_server_state(instance['state']['name'], instance['id'])),
+      :state => state,
+      :actions => instance_actions_for(state),
       :public_addresses => [ instance['ip']['ip'] ],
       :private_addresses => [],
       :username => instance['username'],
diff --git a/server/lib/deltacloud/drivers/opennebula/opennebula_driver.rb b/server/lib/deltacloud/drivers/opennebula/opennebula_driver.rb
index c5e1408..daa9a34 100644
--- a/server/lib/deltacloud/drivers/opennebula/opennebula_driver.rb
+++ b/server/lib/deltacloud/drivers/opennebula/opennebula_driver.rb
@@ -180,7 +180,7 @@ class OpennebulaDriver < Deltacloud::BaseDriver
 
 	imageid = computehash['STORAGE/DISK[@type="disk"]'].attributes['href'].split("/").last
 
-	state = (computehash['STATE'].text == 'ACTIVE') ? 'RUNNING' : computehash['STATE'].text
+	state = (computehash['STATE'].text == :ACTIVE) ? :RUNNING : :STOPPED
 
 	hwp_name = computehash['INSTANCE_TYPE'] || 'small'
 
diff --git a/server/lib/deltacloud/drivers/rackspace/rackspace_driver.rb b/server/lib/deltacloud/drivers/rackspace/rackspace_driver.rb
index 6d6ba0b..a182c04 100644
--- a/server/lib/deltacloud/drivers/rackspace/rackspace_driver.rb
+++ b/server/lib/deltacloud/drivers/rackspace/rackspace_driver.rb
@@ -75,8 +75,8 @@ class RackspaceDriver < Deltacloud::BaseDriver
     end
     Instance.new( {
       :id => id,
-      :state => "REBOOT",
-      :actions => instance_actions_for( state ),
+      :state => :RUNNING,
+      :actions => instance_actions_for( :RUNNING ),
     } )
   end
 
@@ -91,8 +91,8 @@ class RackspaceDriver < Deltacloud::BaseDriver
     end
     Instance.new( {
       :id => id,
-      :state => "STOPPED",
-      :actions => instance_actions_for( "STOPPED" ),
+      :state => :STOPPED,
+      :actions => instance_actions_for( :STOPPED ),
     } )
   end
 
diff --git a/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb b/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb
index 18ba0fa..beac58f 100644
--- a/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb
+++ b/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb
@@ -78,10 +78,13 @@ class RHEVMDriver < Deltacloud::BaseDriver
 
   def statify(state)
     st = state.nil? ? "" : state.upcase()
-    return "running" if st == "UP"
-    return "stopped" if st == "DOWN"
-    return "pending" if st == "POWERING UP"
-    st
+    case st
+    when :UP
+      :RUNNING
+    when :DOWN
+      :STOPPED
+    when :'POWERING UP'
+      :PENDING
   end
 
   define_hardware_profile 'rhevm'
-- 
1.7.2


Re: [PATCH 05/10] Fix up rackspace driver to return instances from actions.

Posted by Michal Fojtik <mf...@redhat.com>.
On 05/08/10 15:57 -0400, Chris Lalancette wrote:
>As with the EC2 and GoGrid drivers, make sure to return
>at least a minimal instance object from the action methods.
>This fixes up stack traces being generated after these
>calls succeed.
>
>Signed-off-by: Chris Lalancette <cl...@redhat.com>
>---
> .../drivers/rackspace/rackspace_driver.rb          |   11 ++++++++++-
> 1 files changed, 10 insertions(+), 1 deletions(-)
>
>diff --git a/server/lib/deltacloud/drivers/rackspace/rackspace_driver.rb b/server/lib/deltacloud/drivers/rackspace/rackspace_driver.rb
>index 0dc1733..6d6ba0b 100644
>--- a/server/lib/deltacloud/drivers/rackspace/rackspace_driver.rb
>+++ b/server/lib/deltacloud/drivers/rackspace/rackspace_driver.rb
>@@ -73,6 +73,11 @@ class RackspaceDriver < Deltacloud::BaseDriver
>     safely do
>       racks.reboot_server(id)
>     end
>+    Instance.new( {
>+      :id => id,
>+      :state => "REBOOT",
>+      :actions => instance_actions_for( state ),
>+    } )
>   end
>
>   def stop_instance(credentials, id)
>@@ -84,6 +89,11 @@ class RackspaceDriver < Deltacloud::BaseDriver
>     safely do
>       racks.delete_server(id)
>     end
>+    Instance.new( {
>+      :id => id,
>+      :state => "STOPPED",
>+      :actions => instance_actions_for( "STOPPED" ),
>+    } )
>   end
>
>
>@@ -123,7 +133,6 @@ class RackspaceDriver < Deltacloud::BaseDriver
>
>
>   def convert_srv_to_instance(srv)
>-    status = srv["status"] == "ACTIVE" ? "RUNNING" : "PENDING"
>     inst = Instance.new(:id => srv["id"].to_s,
>                         :owner_id => "root",
>                         :realm_id => "us")

ACK.


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

[PATCH 05/10] Fix up rackspace driver to return instances from actions.

Posted by Chris Lalancette <cl...@redhat.com>.
As with the EC2 and GoGrid drivers, make sure to return
at least a minimal instance object from the action methods.
This fixes up stack traces being generated after these
calls succeed.

Signed-off-by: Chris Lalancette <cl...@redhat.com>
---
 .../drivers/rackspace/rackspace_driver.rb          |   11 ++++++++++-
 1 files changed, 10 insertions(+), 1 deletions(-)

diff --git a/server/lib/deltacloud/drivers/rackspace/rackspace_driver.rb b/server/lib/deltacloud/drivers/rackspace/rackspace_driver.rb
index 0dc1733..6d6ba0b 100644
--- a/server/lib/deltacloud/drivers/rackspace/rackspace_driver.rb
+++ b/server/lib/deltacloud/drivers/rackspace/rackspace_driver.rb
@@ -73,6 +73,11 @@ class RackspaceDriver < Deltacloud::BaseDriver
     safely do
       racks.reboot_server(id)
     end
+    Instance.new( {
+      :id => id,
+      :state => "REBOOT",
+      :actions => instance_actions_for( state ),
+    } )
   end
 
   def stop_instance(credentials, id)
@@ -84,6 +89,11 @@ class RackspaceDriver < Deltacloud::BaseDriver
     safely do
       racks.delete_server(id)
     end
+    Instance.new( {
+      :id => id,
+      :state => "STOPPED",
+      :actions => instance_actions_for( "STOPPED" ),
+    } )
   end
 
 
@@ -123,7 +133,6 @@ class RackspaceDriver < Deltacloud::BaseDriver
 
 
   def convert_srv_to_instance(srv)
-    status = srv["status"] == "ACTIVE" ? "RUNNING" : "PENDING"
     inst = Instance.new(:id => srv["id"].to_s,
                         :owner_id => "root",
                         :realm_id => "us")
-- 
1.7.2


Re: [PATCH 02/10] Properly define hardware profiles for gogrid.

Posted by Michal Fojtik <mf...@redhat.com>.
On 05/08/10 15:57 -0400, Chris Lalancette wrote:
>Signed-off-by: Chris Lalancette <cl...@redhat.com>
>---
> .../lib/deltacloud/drivers/gogrid/gogrid_driver.rb |   30 ++++++++++++++++++--
> 1 files changed, 27 insertions(+), 3 deletions(-)
>
>diff --git a/server/lib/deltacloud/drivers/gogrid/gogrid_driver.rb b/server/lib/deltacloud/drivers/gogrid/gogrid_driver.rb
>index 28cba15..31fa74b 100644
>--- a/server/lib/deltacloud/drivers/gogrid/gogrid_driver.rb
>+++ b/server/lib/deltacloud/drivers/gogrid/gogrid_driver.rb
>@@ -37,10 +37,34 @@ class GogridDriver < Deltacloud::BaseDriver
>
>   feature :instances, :authentication_password
>
>-  define_hardware_profile 'server' do
>+  define_hardware_profile '512MB' do
>+    cpu            0.5
>+    memory         512
>+    storage        30
>+  end
>+
>+  define_hardware_profile '1GB' do
>+    cpu            1
>+    memory         1
>+    storage        60
>+  end
>+
>+  define_hardware_profile '2GB' do
>     cpu            2
>-    memory         [512, 1024, 2048, 4096, 8192]
>-    storage        10
>+    memory         2
>+    storage        120
>+  end
>+
>+  define_hardware_profile '4GB' do
>+    cpu            4
>+    memory         4
>+    storage        240
>+  end
>+
>+  define_hardware_profile '8GB' do
>+    cpu            8
>+    memory         8
>+    storage        480
>   end
>
>   def supported_collections

Perfect! ACK.

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

[PATCH 02/10] Properly define hardware profiles for gogrid.

Posted by Chris Lalancette <cl...@redhat.com>.
Signed-off-by: Chris Lalancette <cl...@redhat.com>
---
 .../lib/deltacloud/drivers/gogrid/gogrid_driver.rb |   30 ++++++++++++++++++--
 1 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/server/lib/deltacloud/drivers/gogrid/gogrid_driver.rb b/server/lib/deltacloud/drivers/gogrid/gogrid_driver.rb
index 28cba15..31fa74b 100644
--- a/server/lib/deltacloud/drivers/gogrid/gogrid_driver.rb
+++ b/server/lib/deltacloud/drivers/gogrid/gogrid_driver.rb
@@ -37,10 +37,34 @@ class GogridDriver < Deltacloud::BaseDriver
 
   feature :instances, :authentication_password
 
-  define_hardware_profile 'server' do
+  define_hardware_profile '512MB' do
+    cpu            0.5
+    memory         512
+    storage        30
+  end
+
+  define_hardware_profile '1GB' do
+    cpu            1
+    memory         1
+    storage        60
+  end
+
+  define_hardware_profile '2GB' do
     cpu            2
-    memory         [512, 1024, 2048, 4096, 8192]
-    storage        10
+    memory         2
+    storage        120
+  end
+
+  define_hardware_profile '4GB' do
+    cpu            4
+    memory         4
+    storage        240
+  end
+
+  define_hardware_profile '8GB' do
+    cpu            8
+    memory         8
+    storage        480
   end
 
   def supported_collections
-- 
1.7.2


Re: [PATCH 00/10]: More fixes to the core drivers

Posted by Michal Fojtik <mf...@redhat.com>.
On 05/08/10 15:57 -0400, Chris Lalancette wrote:
>This patch series fixes a number of bugs I came across while testing out
>various drivers with condor.  The fixes are explained in the individual
>patches.
>
>Chris Lalancette

ACKing other patches as well. They applied cleanely and looks good.

  -- Michal

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

[PATCH 03/10] Deal with hardware profiles in GoGrid.

Posted by Chris Lalancette <cl...@redhat.com>.
Signed-off-by: Chris Lalancette <cl...@redhat.com>
---
 .../lib/deltacloud/drivers/gogrid/gogrid_driver.rb |   25 ++++++-------------
 1 files changed, 8 insertions(+), 17 deletions(-)

diff --git a/server/lib/deltacloud/drivers/gogrid/gogrid_driver.rb b/server/lib/deltacloud/drivers/gogrid/gogrid_driver.rb
index 31fa74b..c0103c9 100644
--- a/server/lib/deltacloud/drivers/gogrid/gogrid_driver.rb
+++ b/server/lib/deltacloud/drivers/gogrid/gogrid_driver.rb
@@ -98,20 +98,20 @@ class GogridDriver < Deltacloud::BaseDriver
   end
 
   def create_instance(credentials, image_id, opts=nil)
-    server_ram = nil
-    if opts[:hwp_memory]
-      mem = opts[:hwp_memory].to_i
-      server_ram = (mem == 512) ? "512MB" : "#{mem / 1024}GB"
+    image = image(credentials, :id => image_id )
+    if opts && opts[:hwp_id]
+      hwp = find_hardware_profile(credentials, opts[:hwp_id], image.id)
     else
-      server_ram = "512MB"
+      hwp = find_hardware_profile(credentials, "512MB", image.id)
     end
+
     client = new_client(credentials)
     name = (opts[:name] && opts[:name]!='') ? opts[:name] : get_random_instance_name
     safely do
       instance = client.request('grid/server/add', {
         'name' => name,
         'image' => image_id,
-        'server.ram' => server_ram,
+        'server.ram' => hwp.name,
         'ip' => get_next_free_ip(credentials)
       })['list'].first
       if instance
@@ -285,16 +285,7 @@ class GogridDriver < Deltacloud::BaseDriver
   end
 
   def convert_instance(instance, owner_id)
-    opts = {}
-    unless instance['ram']['id'] == "1"
-      mem = instance['ram']['name']
-      if mem == "512MB"
-        opts[:hwp_memory] = "512"
-      else
-        opts[:hwp_memory] = (mem.to_i * 1024).to_s
-      end
-    end
-    prof = InstanceProfile.new("server", opts)
+    hwp_name = instance['image']['name']
 
     Instance.new(
        # note that we use 'name' as the id here, because newly created instances
@@ -304,7 +295,7 @@ class GogridDriver < Deltacloud::BaseDriver
       :id => instance['name'],
       :owner_id => owner_id,
       :image_id => instance['image']['id'],
-      :instance_profile => prof,
+      :instance_profile => InstanceProfile.new(hwp_name),
       :name => instance['name'],
       :realm_id => instance['type']['id'],
       :state => convert_server_state(instance['state']['name'], instance['id']),
-- 
1.7.2


Re: [PATCH 01/10] Remove the begin..rescue block from gogrid_client request.

Posted by Michal Fojtik <mf...@redhat.com>.
On 05/08/10 15:57 -0400, Chris Lalancette wrote:
>Some of the callers want to be able to handle exceptions
>in their own way, so we should make sure to propagate the
>exception.
>
>Signed-off-by: Chris Lalancette <cl...@redhat.com>
>---
> .../lib/deltacloud/drivers/gogrid/gogrid_client.rb |    6 +-----
> 1 files changed, 1 insertions(+), 5 deletions(-)
>
>diff --git a/server/lib/deltacloud/drivers/gogrid/gogrid_client.rb b/server/lib/deltacloud/drivers/gogrid/gogrid_client.rb
>index 70e0cfc..f4f5796 100644
>--- a/server/lib/deltacloud/drivers/gogrid/gogrid_client.rb
>+++ b/server/lib/deltacloud/drivers/gogrid/gogrid_client.rb
>@@ -31,11 +31,7 @@ class GoGridClient
>   end
>
>   def request(method, params={})
>-    begin
>-      JSON::parse(sendAPIRequest(method, params))
>-    rescue Exception => e
>-      STDERR.puts("ERROR: #{e.message}")
>-    end
>+    JSON::parse(sendAPIRequest(method, params))
>   end

ACK. This will now throw Internal Server error, which is fine, because we
can now catch it and return it in error XML.

>
>   def encode_params(params)
>--
>1.7.2
>

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

[PATCH 01/10] Remove the begin..rescue block from gogrid_client request.

Posted by Chris Lalancette <cl...@redhat.com>.
Some of the callers want to be able to handle exceptions
in their own way, so we should make sure to propagate the
exception.

Signed-off-by: Chris Lalancette <cl...@redhat.com>
---
 .../lib/deltacloud/drivers/gogrid/gogrid_client.rb |    6 +-----
 1 files changed, 1 insertions(+), 5 deletions(-)

diff --git a/server/lib/deltacloud/drivers/gogrid/gogrid_client.rb b/server/lib/deltacloud/drivers/gogrid/gogrid_client.rb
index 70e0cfc..f4f5796 100644
--- a/server/lib/deltacloud/drivers/gogrid/gogrid_client.rb
+++ b/server/lib/deltacloud/drivers/gogrid/gogrid_client.rb
@@ -31,11 +31,7 @@ class GoGridClient
   end
 
   def request(method, params={})
-    begin
-      JSON::parse(sendAPIRequest(method, params))
-    rescue Exception => e
-      STDERR.puts("ERROR: #{e.message}")
-    end
+    JSON::parse(sendAPIRequest(method, params))
   end
   
   def encode_params(params)
-- 
1.7.2


[PATCH 07/10] Throw a useful error from GoGrid when the name is too long.

Posted by Chris Lalancette <cl...@redhat.com>.
Signed-off-by: Chris Lalancette <cl...@redhat.com>
---
 .../lib/deltacloud/drivers/gogrid/gogrid_driver.rb |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/server/lib/deltacloud/drivers/gogrid/gogrid_driver.rb b/server/lib/deltacloud/drivers/gogrid/gogrid_driver.rb
index e204cbe..0135123 100644
--- a/server/lib/deltacloud/drivers/gogrid/gogrid_driver.rb
+++ b/server/lib/deltacloud/drivers/gogrid/gogrid_driver.rb
@@ -107,6 +107,9 @@ class GogridDriver < Deltacloud::BaseDriver
 
     client = new_client(credentials)
     name = (opts[:name] && opts[:name]!='') ? opts[:name] : get_random_instance_name
+    if name.length > 20
+      raise Deltacloud::BackendError.new(400, "name-too-long", "Name '#{name}' is too long; the maximum for GoGrid is 20 characters", nil)
+    end
     safely do
       instance = client.request('grid/server/add', {
         'name' => name,
-- 
1.7.2