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/15 12:40:52 UTC

[PATCH core 1/3] Revamped using 'cloudservers' gem (thanks Rackspace!)

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

---
 .../drivers/rackspace/rackspace_client.rb          |  130 --------------
 .../drivers/rackspace/rackspace_driver.rb          |  180 +++++++++++---------
 server/lib/deltacloud/models/instance.rb           |    2 +
 server/views/instances/show.html.haml              |    9 +
 4 files changed, 109 insertions(+), 212 deletions(-)
 delete mode 100644 server/lib/deltacloud/drivers/rackspace/rackspace_client.rb

diff --git a/server/lib/deltacloud/drivers/rackspace/rackspace_client.rb b/server/lib/deltacloud/drivers/rackspace/rackspace_client.rb
deleted file mode 100644
index d803302..0000000
--- a/server/lib/deltacloud/drivers/rackspace/rackspace_client.rb
+++ /dev/null
@@ -1,130 +0,0 @@
-#
-# Copyright (C) 2009, 2010  Red Hat, Inc.
-#
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements.  See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.  The
-# ASF licenses this file to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance with the
-# License.  You may obtain a copy of the License at
-#
-#       http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
-# License for the specific language governing permissions and limitations
-# under the License.
-
-require "net/http"
-require "net/https"
-require 'rubygems'
-require 'json'
-
-#
-# author: Michael Neale
-# TODO: catch generic errors in JSON response and throw (probably)
-#
-module Deltacloud
-  module Drivers
-    module Rackspace
-
-class RackspaceClient
-
-  @@AUTH_API = URI.parse('https://auth.api.rackspacecloud.com/v1.0')
-
-  def initialize(username, auth_key)
-    http = Net::HTTP.new(@@AUTH_API.host,@@AUTH_API.port)
-    http.use_ssl = true
-    authed = http.get(@@AUTH_API.path, {'X-Auth-User' => username, 'X-Auth-Key' => auth_key})
-    if authed.is_a?(Net::HTTPUnauthorized)
-      raise Deltacloud::AuthException, "Failed to authenticate to Rackspace"
-    elsif !authed.is_a?(Net::HTTPSuccess)
-      backend_error!(resp)
-    end
-    @auth_token  = authed.header['X-Auth-Token']
-    @service_uri = URI.parse(authed.header['X-Server-Management-Url'])
-    @service = Net::HTTP.new(@service_uri.host, @service_uri.port)
-    @service.use_ssl = true
-  end
-
-  def list_flavors
-    JSON.parse(get('/flavors/detail'))['flavors']
-  end
-
-  def list_images
-    JSON.parse(get('/images/detail'))['images']
-  end
-
-  def list_servers
-      JSON.parse(get('/servers/detail'))['servers']
-  end
-
-
-  def load_server_details( server_id )
-    JSON.parse(get("/servers/#{server_id}"))['server']
-  end
-
-
-  def start_server(image_id, flavor_id, name)
-    json = { :server => { :name => name,
-                          :imageId => image_id.to_i,
-                          :flavorId => flavor_id.to_i }}.to_json
-    # FIXME: The response has the root password in 'adminPass'; we somehow
-    # need to communicate this back since it's the only place where we can
-    # get it from
-    JSON.parse(post("/servers", json, headers).body)["server"]
-  end
-
-  def delete_server(server_id)
-    delete("/servers/#{server_id}", headers)
-  end
-
-  def reboot_server(server_id)
-    json = { :reboot => { :type => :SOFT }}.to_json
-    post("/servers/#{server_id}/action", json, headers)
-  end
-
-
-  def headers
-    {"Accept" => "application/json", "X-Auth-Token" => @auth_token, "Content-Type" => "application/json"}
-  end
-
-  private
-  def get(path)
-    resp = @service.get(@service_uri.path + path, {"Accept" => "application/json", "X-Auth-Token" => @auth_token})
-    unless resp.is_a?(Net::HTTPSuccess)
-      backend_error!(resp)
-    end
-    resp.body
-  end
-
-  def post(path, json, headers)
-    resp = @service.post(@service_uri.path + path, json, headers)
-    unless resp.is_a?(Net::HTTPSuccess)
-      backend_error!(resp)
-    end
-    resp
-  end
-
-  def delete(path, headers)
-    resp = @service.delete(@service_uri.path + path, headers)
-    unless resp.is_a?(Net::HTTPSuccess)
-      backend_error!(resp)
-    end
-    resp
-  end
-
-  def backend_error!(resp)
-    json = JSON.parse(resp.body)
-    cause = json.keys[0]
-    code = json[cause]["code"]
-    message = json[cause]["message"]
-    details = json[cause]["details"]
-    raise Deltacloud::BackendError.new(code, cause, message, details)
-  end
-
-end
-    end
-  end
-end
diff --git a/server/lib/deltacloud/drivers/rackspace/rackspace_driver.rb b/server/lib/deltacloud/drivers/rackspace/rackspace_driver.rb
index 8d743aa..028b63a 100644
--- a/server/lib/deltacloud/drivers/rackspace/rackspace_driver.rb
+++ b/server/lib/deltacloud/drivers/rackspace/rackspace_driver.rb
@@ -17,8 +17,8 @@
 # under the License.
 
 require 'deltacloud/base_driver'
-require 'deltacloud/drivers/rackspace/rackspace_client'
 require 'cloudfiles'
+require 'cloudservers'
 
 module Deltacloud
   module Drivers
@@ -27,20 +27,21 @@ module Deltacloud
 class RackspaceDriver < Deltacloud::BaseDriver
 
   feature :instances, :user_name
+  feature :instances, :authentication_password
 
   def supported_collections
     DEFAULT_COLLECTIONS + [ :buckets ]
   end
 
-  def hardware_profiles(credentials, opts = nil)
-    racks = new_client( credentials )
-    results=""
+  def hardware_profiles(credentials, opts = {})
+    rs = new_client( credentials )
+    results = []
     safely do
-      results = racks.list_flavors.map do |flav|
-        HardwareProfile.new(flav["id"].to_s) do
+      results = rs.list_flavors.collect do |f|
+        HardwareProfile.new(f[:id].to_s) do
           architecture 'x86_64'
-          memory flav["ram"].to_i
-          storage flav["disk"].to_i
+          memory f[:ram].to_i
+          storage f[:disk].to_i
         end
       end
     end
@@ -48,22 +49,21 @@ class RackspaceDriver < Deltacloud::BaseDriver
   end
 
   def images(credentials, opts=nil)
-    racks = new_client( credentials )
-    results=""
+    rs = new_client(credentials)
+    results = []
     safely do
-      results = racks.list_images.map do |img|
-        Image.new( {
-                     :id=>img["id"].to_s,
-                     :name=>img["name"],
-                     :description => img["name"] + " " + img["status"] + "",
-                     :owner_id=>"root",
-                     :architecture=>'x86_64'
-                   } )
+      results = rs.list_images.collect do |img|
+        Image.new(
+          :id => img[:id].to_s,
+          :name => img[:name],
+          :description => img[:name],
+          :owner_id => credentials.user,
+          :state => img[:status],
+          :architecture => 'x86_64'
+        )
       end
     end
-    results.sort_by{|e| [e.description]}
-    results = filter_on( results, :id, opts )
-    results
+    filter_on( results, :id, opts )
   end
 
   #rackspace does not at this stage have realms... its all US/TX, all the time (at least at time of writing)
@@ -75,67 +75,102 @@ class RackspaceDriver < Deltacloud::BaseDriver
     } )]
   end
 
-  def reboot_instance(credentials, id)
-    racks = new_client(credentials)
+  #
+  # create instance. Default to flavor 1 - really need a name though...
+  # In rackspace, all flavors work with all images.
+  #
+  def create_instance(credentials, image_id, opts)
+    rs = new_client( credentials )
+    result = nil
     safely do
-      racks.reboot_server(id)
+      server = rs.create_server(:name => opts[:name] || Time.now.to_s, 
+                       :imageId => image_id.to_i, 
+                       :flavorId => opts[:hwp_id].to_i || hardware_profiles(credentials).first.id.to_i)
+      result = convert_instance_after_create(server, credentials.user, server.adminPass)
     end
-    Instance.new( {
-      :id => id,
-      :state => "RUNNING",
-      :actions => instance_actions_for( "RUNNING" ),
-    } )
+    result
   end
 
-  def stop_instance(credentials, id)
-    destroy_instance(credentials, id)
+  def reboot_instance(credentials, instance_id)
+    rs = new_client(credentials)
+    safely do
+      server = rs.get_server(instance_id.to_i)
+      server.reboot!
+      convert_instance_after_create(server, credentials.user)
+    end
   end
 
-  def destroy_instance(credentials, id)
-    racks = new_client(credentials)
+  def destroy_instance(credentials, instance_id)
+    rs = new_client(credentials)
     safely do
-      racks.delete_server(id)
+      server = rs.get_server(instance_id.to_i)
+      server.delete!
+      convert_instance_after_create(server, credentials.user)
     end
-    Instance.new( {
-      :id => id,
-      :state => "STOPPED",
-      :actions => instance_actions_for( "STOPPED" ),
-    } )
   end
 
+  alias_method :stop_instance, :destroy_instance
+
+  def convert_instance_after_create(server, user_name, password='')
+    inst = Instance.new(
+      :id => server.id.to_s,
+      :realm_id => 'us',
+      :owner_id => user_name,
+      :description => server.name,
+      :name => server.name,
+      :state => (server.status == 'ACTIVE') ? 'RUNNING' : 'PENDING',
+      :architecture => 'x86_64',
+      :image_id => server.imageId.to_s,
+      :instance_profile => InstanceProfile::new(server.flavorId.to_s),
+      :public_addresses => server.addresses[:public],
+      :private_addresses => server.addresses[:private],
+      :username => 'root',
+      :password => password ? password : nil
+    )
+    inst.actions = instance_actions_for(inst.state)
+    inst
+  end
 
-  #
-  # create instance. Default to flavor 1 - really need a name though...
-  # In rackspace, all flavors work with all images.
-  #
-  def create_instance(credentials, image_id, opts)
-    racks = new_client( credentials )
-    hwp_id = opts[:hwp_id] || 1
-    name = Time.now.to_s
-    if (opts[:name]) then name = opts[:name] end
-    safely do
-      return convert_srv_to_instance(racks.start_server(image_id, hwp_id, name))
-    end
+  def convert_instance(server, user_name = '')
+    inst = Instance.new(
+      :id => server[:id].to_s,
+      :realm_id => 'us',
+      :owner_id => user_name,
+      :description => server[:name],
+      :name => server[:name],
+      :state => (server[:status] == 'ACTIVE') ? 'RUNNING' : 'PENDING',
+      :architecture => 'x86_64',
+      :image_id => server[:imageId].to_s,
+      :instance_profile => InstanceProfile::new(server[:flavorId].to_s),
+      :public_addresses => server[:addresses][:public],
+      :private_addresses => server[:addresses][:private]
+    )
+    inst.actions = instance_actions_for(inst.state)
+    inst
   end
 
   #
   # Instances
   #
-  def instances(credentials, opts=nil)
-    racks = new_client(credentials)
-    instances = []
+  def instances(credentials, opts={})
+
+    rs = new_client(credentials)
+    insts = []
+
     safely do
-      if (opts.nil?)
-        instances = racks.list_servers.map do |srv|
-          convert_srv_to_instance(srv)
-        end
+      if opts[:id]
+        server = rs.get_server(opts[:id].to_i)
+        insts << convert_instance_after_create(server, credentials.user)
       else
-        instances << convert_srv_to_instance(racks.load_server_details(opts[:id]))
+        insts = rs.list_servers_detail.collect do |server|
+          convert_instance(server, credentials.user)
+        end
       end
     end
-    instances = filter_on( instances, :id, opts )
-    instances = filter_on( instances, :state, opts )
-    instances
+
+    insts = filter_on( insts, :id, opts )
+    insts = filter_on( insts, :state, opts )
+    insts
   end
 
   def valid_credentials?(credentials)
@@ -149,14 +184,10 @@ class RackspaceDriver < Deltacloud::BaseDriver
 
   define_instance_states do
     start.to( :pending )          .on( :create )
-
     pending.to( :running )        .automatically
-
     running.to( :running )        .on( :reboot )
     running.to( :shutting_down )  .on( :stop )
-
     shutting_down.to( :stopped )  .automatically
-
     stopped.to( :finish )         .automatically
   end
 
@@ -290,25 +321,10 @@ class RackspaceDriver < Deltacloud::BaseDriver
 
 private
 
-  def convert_srv_to_instance(srv)
-    inst = Instance.new(:id => srv["id"].to_s,
-                        :owner_id => "root",
-                        :realm_id => "us")
-    inst.name = srv["name"]
-    inst.state = srv["status"] == "ACTIVE" ? "RUNNING" : "PENDING"
-    inst.actions = instance_actions_for(inst.state)
-    inst.image_id = srv["imageId"].to_s
-    inst.instance_profile = InstanceProfile.new(srv["flavorId"].to_s)
-    if srv["addresses"]
-      inst.public_addresses  = srv["addresses"]["public"]
-      inst.private_addresses = srv["addresses"]["private"]
-    end
-    inst
-  end
 
   def new_client(credentials)
     safely do
-      return RackspaceClient.new(credentials.user, credentials.password)
+      CloudServers::Connection.new(:username => credentials.user, :api_key => credentials.password)
     end
   end
 
diff --git a/server/lib/deltacloud/models/instance.rb b/server/lib/deltacloud/models/instance.rb
index 467d93f..6345590 100644
--- a/server/lib/deltacloud/models/instance.rb
+++ b/server/lib/deltacloud/models/instance.rb
@@ -30,6 +30,8 @@ class Instance < BaseModel
   attr_accessor :launch_time
   attr_accessor :keyname
   attr_accessor :authn_error
+  attr_accessor :username
+  attr_accessor :password
 
   def to_s
     name
diff --git a/server/views/instances/show.html.haml b/server/views/instances/show.html.haml
index 0a6e115..76d77ba 100644
--- a/server/views/instances/show.html.haml
+++ b/server/views/instances/show.html.haml
@@ -36,6 +36,15 @@
     %dt Private Addresses
     %dd
       = @instance.private_addresses.collect { |address| "<div>#{address}</div>" }.join
+  - if @instance.password
+    %di
+      %dt Username
+      %dd
+        = @instance.username
+    %di
+      %dt Password
+      %dd
+        = @instance.password
   %di
     %dt
     %dd
-- 
1.7.4


[PATCH core 2/3] Rackspace: Added support for creating images from instances

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

---
 .../drivers/rackspace/rackspace_driver.rb          |   16 ++++++++++++++++
 1 files changed, 16 insertions(+), 0 deletions(-)

diff --git a/server/lib/deltacloud/drivers/rackspace/rackspace_driver.rb b/server/lib/deltacloud/drivers/rackspace/rackspace_driver.rb
index 028b63a..e64edae 100644
--- a/server/lib/deltacloud/drivers/rackspace/rackspace_driver.rb
+++ b/server/lib/deltacloud/drivers/rackspace/rackspace_driver.rb
@@ -91,6 +91,22 @@ class RackspaceDriver < Deltacloud::BaseDriver
     result
   end
 
+  def create_image(credentials, opts={})
+    rs = new_client(credentials)
+    safely do
+      server = rs.get_server(opts[:id].to_i)
+      image = server.create_image(opts[:name])
+      Image.new(
+        :id => image.id.to_s,
+        :name => image.name,
+        :description => image.name,
+        :owner_id => credentials.user,
+        :state => image.status,
+        :architecture => 'x86_64'
+      )
+    end
+  end
+
   def reboot_instance(credentials, instance_id)
     rs = new_client(credentials)
     safely do
-- 
1.7.4


Re: [PATCH core 3/3] Fixed run_on_instance and launching instance with default HWP

Posted by Michal Fojtik <mf...@redhat.com>.
On Feb 15, 2011, at 9:40 PM, marios@redhat.com wrote:

> On 15/02/11 22:33, Michal Fojtik wrote:
>> On Feb 15, 2011, at 9:16 PM, marios@redhat.com wrote:
>> 
>> Hi,
>> 
>>> runoninstance gave me a 'execution expired error'
>>> 
>>> [marios@marios deltacloud]$ curl -F 'cmd=uname -a' -F 'password=bla' --user 'foo:bar' http://localhost:3001/api/instances/615657/run?format=xml
>>> <error status='500' url='/api/instances/615657/run?format=xml'>
>>>  <kind>backend_error</kind>
>>>  <backend driver='rackspace'>
>>>    <code>500</code>
>>>    <cause>Deltacloud::Runner::InstanceSSHError</cause>
>>>    <details><![CDATA[././lib/deltacloud/runner.rb:88:in `execute'
>>>    ././lib/deltacloud/runner.rb:49:in `execute'
>>>    ././lib/deltacloud/drivers/rackspace/rackspace_driver.rb:122:in `run_on_instance'
>>>    ././lib/deltacloud/drivers/rackspace/rackspace_driver.rb:389:in `call'
>>> 
>>> ...
>>> 
>>> 
>>>  </backend>
>>>  <message><![CDATA[Timeout::Error: execution expired]]></message>
>>> 
>> 
>> Your instance needs to be in RUNNING state in order to execute some commands on it.
>> This error usually happens if instance is not in RUNNING state or SSH is not started.
>> 
>> Can you please try it again?
>> 
> 
> 
> ok, will do. you probably missed the second issue i ran into cos it was at the bottom of my post  - same problem as in my original review with opts[:hwp_id] being nil

You're right, will fix it tomorrow, thanks. I need to write some unit tests for this, trying that
just with Ruby client sometimes doesn't work.

> 
>> Btw. testing code I'm used:
>> 
>> require 'deltacloud'
>> 
>> c = DeltaCloud::new('rackspace_user', 'api_key', 'http://localhost:3001/api')
>> instance = c.instance('123456')
>> puts instance.run('ls -lah /', :username =>  'root', :password =>  'password')
>> 
>>   -- Michal
>> 
>>> 
>>> On 15/02/11 13:40, mfojtik@redhat.com wrote:
>>>> From: Michal Fojtik<mf...@redhat.com>
>>>> @@ -85,25 +85,41 @@ class RackspaceDriver<   Deltacloud::BaseDriver
>>>>      safely do
>>>>        server = rs.create_server(:name =>   opts[:name] || Time.now.to_s,
>>>>                         :imageId =>   image_id.to_i,
>>>> -                       :flavorId =>   opts[:hwp_id].to_i || hardware_profiles(credentials).first.id.to_i)
>>>> +                       :flavorId =>   opts[:hwp_id].length>0 ? opts[:hwp_id].to_i : 1)
>>>>        result = convert_instance_after_create(server, credentials.user, server.adminPass)
>>>>      end
>>>>      result
>>>>    end
>>>> 
>>> 
>>> getting an error here. (you are still not catching the case where opts[:hwp_id] is nil):
>>> 
>>> 
>>> [marios@marios deltacloud]$ curl -i -d 'image_id=4' --user 'foo:bar' http://localhost:3001/api/instances?format=xml
>>> HTTP/1.1 500 Internal Server Error
>>> X-Runtime: 4.845465
>>> Content-Type: application/xml;charset=utf-8
>>> Content-Length: 4739
>>> Connection: keep-alive
>>> Server: thin 1.2.7 codename No Hup
>>> 
>>> <error status='500' url='/api/instances?format=xml'>
>>>  <kind>backend_error</kind>
>>>  <backend driver='rackspace'>
>>>    <code>500</code>
>>>    <cause>NoMethodError</cause>
>>> <details><![CDATA[././lib/deltacloud/drivers/rackspace/rackspace_driver.rb:88:in `create_instance'
>>>    ././lib/deltacloud/drivers/rackspace/rackspace_driver.rb:389:in `call'
>>>    ././lib/deltacloud/drivers/rackspace/rackspace_driver.rb:389:in `safely'
>>>    ././lib/deltacloud/drivers/rackspace/rackspace_driver.rb:85:in `create_instance'
>>>    ././server.rb:333
>>> 
>>> 
>>> ...
>>> 
>>> </backend>
>>>  <message><![CDATA[undefined method `length' for nil:NilClass]]></message>
>>> 
>>> 
>>> 
>>> 
>>> 
>>> 
>>> 
>> 
>> Michal Fojtik
>> Software Engineer, Deltacloud API project
>> http://www.deltacloud.org
>> mfojtik@redhat.com
>> 
>> 
> 

Michal Fojtik
Software Engineer, Deltacloud API project
http://www.deltacloud.org
mfojtik@redhat.com



Re: [PATCH core 3/3] Fixed run_on_instance and launching instance with default HWP

Posted by "marios@redhat.com" <ma...@redhat.com>.
On 15/02/11 22:33, Michal Fojtik wrote:
> On Feb 15, 2011, at 9:16 PM, marios@redhat.com wrote:
>
> Hi,
>
>> runoninstance gave me a 'execution expired error'
>>
>> [marios@marios deltacloud]$ curl -F 'cmd=uname -a' -F 'password=bla' --user 'foo:bar' http://localhost:3001/api/instances/615657/run?format=xml
>> <error status='500' url='/api/instances/615657/run?format=xml'>
>>   <kind>backend_error</kind>
>>   <backend driver='rackspace'>
>>     <code>500</code>
>>     <cause>Deltacloud::Runner::InstanceSSHError</cause>
>>     <details><![CDATA[././lib/deltacloud/runner.rb:88:in `execute'
>>     ././lib/deltacloud/runner.rb:49:in `execute'
>>     ././lib/deltacloud/drivers/rackspace/rackspace_driver.rb:122:in `run_on_instance'
>>     ././lib/deltacloud/drivers/rackspace/rackspace_driver.rb:389:in `call'
>>
>> ...
>>
>>
>>   </backend>
>>   <message><![CDATA[Timeout::Error: execution expired]]></message>
>>
>
> Your instance needs to be in RUNNING state in order to execute some commands on it.
> This error usually happens if instance is not in RUNNING state or SSH is not started.
>
> Can you please try it again?
>


ok, will do. you probably missed the second issue i ran into cos it was 
at the bottom of my post  - same problem as in my original review with 
opts[:hwp_id] being nil


> Btw. testing code I'm used:
>
> require 'deltacloud'
>
> c = DeltaCloud::new('rackspace_user', 'api_key', 'http://localhost:3001/api')
> instance = c.instance('123456')
> puts instance.run('ls -lah /', :username =>  'root', :password =>  'password')
>
>    -- Michal
>
>>
>> On 15/02/11 13:40, mfojtik@redhat.com wrote:
>>> From: Michal Fojtik<mf...@redhat.com>
>>> @@ -85,25 +85,41 @@ class RackspaceDriver<   Deltacloud::BaseDriver
>>>       safely do
>>>         server = rs.create_server(:name =>   opts[:name] || Time.now.to_s,
>>>                          :imageId =>   image_id.to_i,
>>> -                       :flavorId =>   opts[:hwp_id].to_i || hardware_profiles(credentials).first.id.to_i)
>>> +                       :flavorId =>   opts[:hwp_id].length>0 ? opts[:hwp_id].to_i : 1)
>>>         result = convert_instance_after_create(server, credentials.user, server.adminPass)
>>>       end
>>>       result
>>>     end
>>>
>>
>> getting an error here. (you are still not catching the case where opts[:hwp_id] is nil):
>>
>>
>> [marios@marios deltacloud]$ curl -i -d 'image_id=4' --user 'foo:bar' http://localhost:3001/api/instances?format=xml
>> HTTP/1.1 500 Internal Server Error
>> X-Runtime: 4.845465
>> Content-Type: application/xml;charset=utf-8
>> Content-Length: 4739
>> Connection: keep-alive
>> Server: thin 1.2.7 codename No Hup
>>
>> <error status='500' url='/api/instances?format=xml'>
>>   <kind>backend_error</kind>
>>   <backend driver='rackspace'>
>>     <code>500</code>
>>     <cause>NoMethodError</cause>
>> <details><![CDATA[././lib/deltacloud/drivers/rackspace/rackspace_driver.rb:88:in `create_instance'
>>     ././lib/deltacloud/drivers/rackspace/rackspace_driver.rb:389:in `call'
>>     ././lib/deltacloud/drivers/rackspace/rackspace_driver.rb:389:in `safely'
>>     ././lib/deltacloud/drivers/rackspace/rackspace_driver.rb:85:in `create_instance'
>>     ././server.rb:333
>>
>>
>> ...
>>
>> </backend>
>>   <message><![CDATA[undefined method `length' for nil:NilClass]]></message>
>>
>>
>>
>>
>>
>>
>>
>
> Michal Fojtik
> Software Engineer, Deltacloud API project
> http://www.deltacloud.org
> mfojtik@redhat.com
>
>


Re: [PATCH core 3/3] Fixed run_on_instance and launching instance with default HWP

Posted by Michal Fojtik <mf...@redhat.com>.
On 16/02/11 17:31 +0200, marios@redhat.com wrote:
>On 16/02/11 15:04, Michal Fojtik wrote:
>>>
>>>
>>></backend>
>>><message><![CDATA[Timeout::Error: execution expired]]></message>
>>></error>
>>
>>Yes, there is a 5 seconds timeout set for connecting to instance. Maybe
>>I should increase this timeout. Can you please do it manually for this time
>>and if it will work I'll raise this value.
>>
>
>
>as discussed on irc, i increased the timeout to 10s (runner.rb, line 
>76) and this fixed it so you may want to do this (and perhaps add 
>another margin of error? 15s? unless theres a reason against) before 
>commit

Increased timeout, fixed Hardware Profile handling and pushed :-)
Thanks for reviewing that!

   -- Michal

>
>

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

Re: [PATCH core 3/3] Fixed run_on_instance and launching instance with default HWP

Posted by "marios@redhat.com" <ma...@redhat.com>.
On 16/02/11 15:04, Michal Fojtik wrote:
>>
>>
>> </backend>
>> <message><![CDATA[Timeout::Error: execution expired]]></message>
>> </error>
>
> Yes, there is a 5 seconds timeout set for connecting to instance. Maybe
> I should increase this timeout. Can you please do it manually for this time
> and if it will work I'll raise this value.
>


as discussed on irc, i increased the timeout to 10s (runner.rb, line 76) 
and this fixed it so you may want to do this (and perhaps add another 
margin of error? 15s? unless theres a reason against) before commit



Re: [PATCH core 3/3] Fixed run_on_instance and launching instance with default HWP

Posted by Michal Fojtik <mf...@redhat.com>.
On 15/02/11 22:50 +0200, marios@redhat.com wrote:
>On 15/02/11 22:33, Michal Fojtik wrote:
>>Your instance needs to be in RUNNING state in order to execute some commands on it.
>>This error usually happens if instance is not in RUNNING state or SSH is not started.
>>
>>Can you please try it again?
>>
>
>definitely in running state - same error

That's pretty weird, because it works for me. I'll try to reproduce your
approach to see what happen.

>
>
>>Btw. testing code I'm used:
>>
>>require 'deltacloud'
>>
>>c = DeltaCloud::new('rackspace_user', 'api_key', 'http://localhost:3001/api')
>>instance = c.instance('123456')
>>puts instance.run('ls -lah /', :username =>  'root', :password =>  'password')
>>
>>   -- Michal
>>
>
>shouldn't matter what client we use for testing (in fact thats one of 
>our arguments for REST right?). stacktrace:
>
>
>[marios@marios deltacloud]$ curl  --user 'foo:bar' 
>http://localhost:3001/api/instances?format=xml
><?xml version='1.0' encoding='utf-8' ?>
><instances>
>  <instance href='http://localhost:3001/api/instances/615721' id='615721'>
>    <name>TueFeb1522424402002011</name>
>    <owner_id>mandreou</owner_id>
>    <image href='http://localhost:3001/api/images/4' id='4'></image>
>    <realm href='http://localhost:3001/api/realms/us' id='us'></realm>
>    <state>RUNNING</state>
>    <hardware_profile 
>href='http://localhost:3001/api/hardware_profiles/1' id='1'>
>    </hardware_profile>
>    <actions>
>      <link href='http://localhost:3001/api/instances/615721/reboot' 
>method='post' rel='reboot' />
>      <link href='http://localhost:3001/api/instances/615721/stop' 
>method='post' rel='stop' />
>    </actions>
>    <public_addresses>
>      <address>50.56.69.214</address>
>    </public_addresses>
>    <private_addresses>
>      <address>10.181.83.165</address>
>    </private_addresses>
>  </instance>
></instances>
>
>
>[marios@marios deltacloud]$ curl -id 'cmd=uname -a' -d 'password=bar' 
>--user 'bla:bla' 
>http://localhost:3001/api/instances/615721/run?format=xml
>HTTP/1.1 500 Internal Server Error
>X-Runtime: 9.498340
>Content-Type: application/xml;charset=utf-8
>Content-Length: 4872
>Connection: keep-alive
>Server: thin 1.2.7 codename No Hup
>
><error status='500' url='/api/instances/615721/run?format=xml'>
>  <kind>backend_error</kind>
>  <backend driver='rackspace'>
>    <code>500</code>
>    <cause>Deltacloud::Runner::InstanceSSHError</cause>
>    <details><![CDATA[././lib/deltacloud/runner.rb:88:in `execute'
>    ././lib/deltacloud/runner.rb:49:in `execute'
>    ././lib/deltacloud/drivers/rackspace/rackspace_driver.rb:122:in 
>`run_on_instance'
>    ././lib/deltacloud/drivers/rackspace/rackspace_driver.rb:389:in `call'
>    ././lib/deltacloud/drivers/rackspace/rackspace_driver.rb:389:in 
>`safely'
>    ././lib/deltacloud/drivers/rackspace/rackspace_driver.rb:121:in 
>`run_on_instance'
>    ././server.rb:389
>    ././lib/sinatra/rabbit.rb:87:in `instance_eval'
>    ././lib/sinatra/rabbit.rb:87:in `POST /api/instances/:id/run'
>
>...
>
>
>  </backend>
>  <message><![CDATA[Timeout::Error: execution expired]]></message>
></error>

Yes, there is a 5 seconds timeout set for connecting to instance. Maybe
I should increase this timeout. Can you please do it manually for this time
and if it will work I'll raise this value.

>>>
>>>On 15/02/11 13:40, mfojtik@redhat.com wrote:
>>>>From: Michal Fojtik<mf...@redhat.com>
>>>>@@ -85,25 +85,41 @@ class RackspaceDriver<   Deltacloud::BaseDriver
>>>>      safely do
>>>>        server = rs.create_server(:name =>   opts[:name] || Time.now.to_s,
>>>>                         :imageId =>   image_id.to_i,
>>>>-                       :flavorId =>   opts[:hwp_id].to_i || hardware_profiles(credentials).first.id.to_i)
>>>>+                       :flavorId =>   opts[:hwp_id].length>0 ? opts[:hwp_id].to_i : 1)
>>>>        result = convert_instance_after_create(server, credentials.user, server.adminPass)
>>>>      end
>>>>      result
>>>>    end
>>>>
>>>
>>>getting an error here. (you are still not catching the case where opts[:hwp_id] is nil):
>>>
>>>
>>>[marios@marios deltacloud]$ curl -i -d 'image_id=4' --user 'foo:bar' http://localhost:3001/api/instances?format=xml
>>>HTTP/1.1 500 Internal Server Error
>>>X-Runtime: 4.845465
>>>Content-Type: application/xml;charset=utf-8
>>>Content-Length: 4739
>>>Connection: keep-alive
>>>Server: thin 1.2.7 codename No Hup
>>>
>>><error status='500' url='/api/instances?format=xml'>
>>>  <kind>backend_error</kind>
>>>  <backend driver='rackspace'>
>>>    <code>500</code>
>>>    <cause>NoMethodError</cause>
>>><details><![CDATA[././lib/deltacloud/drivers/rackspace/rackspace_driver.rb:88:in `create_instance'
>>>    ././lib/deltacloud/drivers/rackspace/rackspace_driver.rb:389:in `call'
>>>    ././lib/deltacloud/drivers/rackspace/rackspace_driver.rb:389:in `safely'
>>>    ././lib/deltacloud/drivers/rackspace/rackspace_driver.rb:85:in `create_instance'
>>>    ././server.rb:333
>>>
>>>
>>>...
>>>
>>></backend>
>>>  <message><![CDATA[undefined method `length' for nil:NilClass]]></message>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>
>>Michal Fojtik
>>Software Engineer, Deltacloud API project
>>http://www.deltacloud.org
>>mfojtik@redhat.com
>>
>>
>

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

Re: [PATCH core 3/3] Fixed run_on_instance and launching instance with default HWP

Posted by "marios@redhat.com" <ma...@redhat.com>.
On 15/02/11 22:33, Michal Fojtik wrote:
> Your instance needs to be in RUNNING state in order to execute some commands on it.
> This error usually happens if instance is not in RUNNING state or SSH is not started.
>
> Can you please try it again?
>

definitely in running state - same error


> Btw. testing code I'm used:
>
> require 'deltacloud'
>
> c = DeltaCloud::new('rackspace_user', 'api_key', 'http://localhost:3001/api')
> instance = c.instance('123456')
> puts instance.run('ls -lah /', :username =>  'root', :password =>  'password')
>
>    -- Michal
>

shouldn't matter what client we use for testing (in fact thats one of 
our arguments for REST right?). stacktrace:


[marios@marios deltacloud]$ curl  --user 'foo:bar' 
http://localhost:3001/api/instances?format=xml
<?xml version='1.0' encoding='utf-8' ?>
<instances>
   <instance href='http://localhost:3001/api/instances/615721' id='615721'>
     <name>TueFeb1522424402002011</name>
     <owner_id>mandreou</owner_id>
     <image href='http://localhost:3001/api/images/4' id='4'></image>
     <realm href='http://localhost:3001/api/realms/us' id='us'></realm>
     <state>RUNNING</state>
     <hardware_profile 
href='http://localhost:3001/api/hardware_profiles/1' id='1'>
     </hardware_profile>
     <actions>
       <link href='http://localhost:3001/api/instances/615721/reboot' 
method='post' rel='reboot' />
       <link href='http://localhost:3001/api/instances/615721/stop' 
method='post' rel='stop' />
     </actions>
     <public_addresses>
       <address>50.56.69.214</address>
     </public_addresses>
     <private_addresses>
       <address>10.181.83.165</address>
     </private_addresses>
   </instance>
</instances>


[marios@marios deltacloud]$ curl -id 'cmd=uname -a' -d 'password=bar' 
--user 'bla:bla' http://localhost:3001/api/instances/615721/run?format=xml
HTTP/1.1 500 Internal Server Error
X-Runtime: 9.498340
Content-Type: application/xml;charset=utf-8
Content-Length: 4872
Connection: keep-alive
Server: thin 1.2.7 codename No Hup

<error status='500' url='/api/instances/615721/run?format=xml'>
   <kind>backend_error</kind>
   <backend driver='rackspace'>
     <code>500</code>
     <cause>Deltacloud::Runner::InstanceSSHError</cause>
     <details><![CDATA[././lib/deltacloud/runner.rb:88:in `execute'
     ././lib/deltacloud/runner.rb:49:in `execute'
     ././lib/deltacloud/drivers/rackspace/rackspace_driver.rb:122:in 
`run_on_instance'
     ././lib/deltacloud/drivers/rackspace/rackspace_driver.rb:389:in `call'
     ././lib/deltacloud/drivers/rackspace/rackspace_driver.rb:389:in 
`safely'
     ././lib/deltacloud/drivers/rackspace/rackspace_driver.rb:121:in 
`run_on_instance'
     ././server.rb:389
     ././lib/sinatra/rabbit.rb:87:in `instance_eval'
     ././lib/sinatra/rabbit.rb:87:in `POST /api/instances/:id/run'

...


   </backend>
   <message><![CDATA[Timeout::Error: execution expired]]></message>
</error>





>>
>> On 15/02/11 13:40, mfojtik@redhat.com wrote:
>>> From: Michal Fojtik<mf...@redhat.com>
>>> @@ -85,25 +85,41 @@ class RackspaceDriver<   Deltacloud::BaseDriver
>>>       safely do
>>>         server = rs.create_server(:name =>   opts[:name] || Time.now.to_s,
>>>                          :imageId =>   image_id.to_i,
>>> -                       :flavorId =>   opts[:hwp_id].to_i || hardware_profiles(credentials).first.id.to_i)
>>> +                       :flavorId =>   opts[:hwp_id].length>0 ? opts[:hwp_id].to_i : 1)
>>>         result = convert_instance_after_create(server, credentials.user, server.adminPass)
>>>       end
>>>       result
>>>     end
>>>
>>
>> getting an error here. (you are still not catching the case where opts[:hwp_id] is nil):
>>
>>
>> [marios@marios deltacloud]$ curl -i -d 'image_id=4' --user 'foo:bar' http://localhost:3001/api/instances?format=xml
>> HTTP/1.1 500 Internal Server Error
>> X-Runtime: 4.845465
>> Content-Type: application/xml;charset=utf-8
>> Content-Length: 4739
>> Connection: keep-alive
>> Server: thin 1.2.7 codename No Hup
>>
>> <error status='500' url='/api/instances?format=xml'>
>>   <kind>backend_error</kind>
>>   <backend driver='rackspace'>
>>     <code>500</code>
>>     <cause>NoMethodError</cause>
>> <details><![CDATA[././lib/deltacloud/drivers/rackspace/rackspace_driver.rb:88:in `create_instance'
>>     ././lib/deltacloud/drivers/rackspace/rackspace_driver.rb:389:in `call'
>>     ././lib/deltacloud/drivers/rackspace/rackspace_driver.rb:389:in `safely'
>>     ././lib/deltacloud/drivers/rackspace/rackspace_driver.rb:85:in `create_instance'
>>     ././server.rb:333
>>
>>
>> ...
>>
>> </backend>
>>   <message><![CDATA[undefined method `length' for nil:NilClass]]></message>
>>
>>
>>
>>
>>
>>
>>
>
> Michal Fojtik
> Software Engineer, Deltacloud API project
> http://www.deltacloud.org
> mfojtik@redhat.com
>
>


Re: [PATCH core 3/3] Fixed run_on_instance and launching instance with default HWP

Posted by Michal Fojtik <mf...@redhat.com>.
On Feb 15, 2011, at 9:16 PM, marios@redhat.com wrote:

Hi,

> runoninstance gave me a 'execution expired error'
> 
> [marios@marios deltacloud]$ curl -F 'cmd=uname -a' -F 'password=bla' --user 'foo:bar' http://localhost:3001/api/instances/615657/run?format=xml
> <error status='500' url='/api/instances/615657/run?format=xml'>
>  <kind>backend_error</kind>
>  <backend driver='rackspace'>
>    <code>500</code>
>    <cause>Deltacloud::Runner::InstanceSSHError</cause>
>    <details><![CDATA[././lib/deltacloud/runner.rb:88:in `execute'
>    ././lib/deltacloud/runner.rb:49:in `execute'
>    ././lib/deltacloud/drivers/rackspace/rackspace_driver.rb:122:in `run_on_instance'
>    ././lib/deltacloud/drivers/rackspace/rackspace_driver.rb:389:in `call'
> 
> ...
> 
> 
>  </backend>
>  <message><![CDATA[Timeout::Error: execution expired]]></message>
> 

Your instance needs to be in RUNNING state in order to execute some commands on it.
This error usually happens if instance is not in RUNNING state or SSH is not started.

Can you please try it again?

Btw. testing code I'm used:

require 'deltacloud'

c = DeltaCloud::new('rackspace_user', 'api_key', 'http://localhost:3001/api')
instance = c.instance('123456')
puts instance.run('ls -lah /', :username => 'root', :password => 'password')

  -- Michal

> 
> On 15/02/11 13:40, mfojtik@redhat.com wrote:
>> From: Michal Fojtik<mf...@redhat.com>
>> @@ -85,25 +85,41 @@ class RackspaceDriver<  Deltacloud::BaseDriver
>>      safely do
>>        server = rs.create_server(:name =>  opts[:name] || Time.now.to_s,
>>                         :imageId =>  image_id.to_i,
>> -                       :flavorId =>  opts[:hwp_id].to_i || hardware_profiles(credentials).first.id.to_i)
>> +                       :flavorId =>  opts[:hwp_id].length>0 ? opts[:hwp_id].to_i : 1)
>>        result = convert_instance_after_create(server, credentials.user, server.adminPass)
>>      end
>>      result
>>    end
>> 
> 
> getting an error here. (you are still not catching the case where opts[:hwp_id] is nil):
> 
> 
> [marios@marios deltacloud]$ curl -i -d 'image_id=4' --user 'foo:bar' http://localhost:3001/api/instances?format=xml
> HTTP/1.1 500 Internal Server Error
> X-Runtime: 4.845465
> Content-Type: application/xml;charset=utf-8
> Content-Length: 4739
> Connection: keep-alive
> Server: thin 1.2.7 codename No Hup
> 
> <error status='500' url='/api/instances?format=xml'>
>  <kind>backend_error</kind>
>  <backend driver='rackspace'>
>    <code>500</code>
>    <cause>NoMethodError</cause>
> <details><![CDATA[././lib/deltacloud/drivers/rackspace/rackspace_driver.rb:88:in `create_instance'
>    ././lib/deltacloud/drivers/rackspace/rackspace_driver.rb:389:in `call'
>    ././lib/deltacloud/drivers/rackspace/rackspace_driver.rb:389:in `safely'
>    ././lib/deltacloud/drivers/rackspace/rackspace_driver.rb:85:in `create_instance'
>    ././server.rb:333
> 
> 
> ...
> 
> </backend>
>  <message><![CDATA[undefined method `length' for nil:NilClass]]></message>
> 
> 
> 
> 
> 
> 
> 

Michal Fojtik
Software Engineer, Deltacloud API project
http://www.deltacloud.org
mfojtik@redhat.com



Re: [PATCH core 3/3] Fixed run_on_instance and launching instance with default HWP

Posted by "marios@redhat.com" <ma...@redhat.com>.
runoninstance gave me a 'execution expired error'

[marios@marios deltacloud]$ curl -F 'cmd=uname -a' -F 'password=bla' 
--user 'foo:bar' http://localhost:3001/api/instances/615657/run?format=xml
<error status='500' url='/api/instances/615657/run?format=xml'>
   <kind>backend_error</kind>
   <backend driver='rackspace'>
     <code>500</code>
     <cause>Deltacloud::Runner::InstanceSSHError</cause>
     <details><![CDATA[././lib/deltacloud/runner.rb:88:in `execute'
     ././lib/deltacloud/runner.rb:49:in `execute'
     ././lib/deltacloud/drivers/rackspace/rackspace_driver.rb:122:in 
`run_on_instance'
     ././lib/deltacloud/drivers/rackspace/rackspace_driver.rb:389:in `call'

...


   </backend>
   <message><![CDATA[Timeout::Error: execution expired]]></message>


On 15/02/11 13:40, mfojtik@redhat.com wrote:
> From: Michal Fojtik<mf...@redhat.com>
> @@ -85,25 +85,41 @@ class RackspaceDriver<  Deltacloud::BaseDriver
>       safely do
>         server = rs.create_server(:name =>  opts[:name] || Time.now.to_s,
>                          :imageId =>  image_id.to_i,
> -                       :flavorId =>  opts[:hwp_id].to_i || hardware_profiles(credentials).first.id.to_i)
> +                       :flavorId =>  opts[:hwp_id].length>0 ? opts[:hwp_id].to_i : 1)
>         result = convert_instance_after_create(server, credentials.user, server.adminPass)
>       end
>       result
>     end
>

  getting an error here. (you are still not catching the case where 
opts[:hwp_id] is nil):


[marios@marios deltacloud]$ curl -i -d 'image_id=4' --user 'foo:bar' 
http://localhost:3001/api/instances?format=xml
HTTP/1.1 500 Internal Server Error
X-Runtime: 4.845465
Content-Type: application/xml;charset=utf-8
Content-Length: 4739
Connection: keep-alive
Server: thin 1.2.7 codename No Hup

<error status='500' url='/api/instances?format=xml'>
   <kind>backend_error</kind>
   <backend driver='rackspace'>
     <code>500</code>
     <cause>NoMethodError</cause>
 
<details><![CDATA[././lib/deltacloud/drivers/rackspace/rackspace_driver.rb:88:in 
`create_instance'
     ././lib/deltacloud/drivers/rackspace/rackspace_driver.rb:389:in `call'
     ././lib/deltacloud/drivers/rackspace/rackspace_driver.rb:389:in 
`safely'
     ././lib/deltacloud/drivers/rackspace/rackspace_driver.rb:85:in 
`create_instance'
     ././server.rb:333


...

  </backend>
   <message><![CDATA[undefined method `length' for nil:NilClass]]></message>








[PATCH core 3/3] Fixed run_on_instance and launching instance with default HWP

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

---
 server/lib/deltacloud/drivers/ec2/ec2_driver.rb    |    1 -
 .../drivers/rackspace/rackspace_driver.rb          |  120 +++++++++++---------
 2 files changed, 68 insertions(+), 53 deletions(-)

diff --git a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
index fd3f9d9..5083622 100644
--- a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
+++ b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
@@ -231,7 +231,6 @@ module Deltacloud
 
         def destroy_instance(credentials, instance_id)
           ec2 = new_client(credentials)
-          puts "Terminating instance #{instance_id}"
           instance_id = instance_id
           if ec2.terminate_instances([instance_id])
             untag_instance(credentials, instance_id)
diff --git a/server/lib/deltacloud/drivers/rackspace/rackspace_driver.rb b/server/lib/deltacloud/drivers/rackspace/rackspace_driver.rb
index e64edae..76403db 100644
--- a/server/lib/deltacloud/drivers/rackspace/rackspace_driver.rb
+++ b/server/lib/deltacloud/drivers/rackspace/rackspace_driver.rb
@@ -30,7 +30,7 @@ class RackspaceDriver < Deltacloud::BaseDriver
   feature :instances, :authentication_password
 
   def supported_collections
-    DEFAULT_COLLECTIONS + [ :buckets ]
+    DEFAULT_COLLECTIONS + [ :buckets ] - [ :storage_snapshots, :storage_volumes ]
   end
 
   def hardware_profiles(credentials, opts = {})
@@ -85,25 +85,41 @@ class RackspaceDriver < Deltacloud::BaseDriver
     safely do
       server = rs.create_server(:name => opts[:name] || Time.now.to_s, 
                        :imageId => image_id.to_i, 
-                       :flavorId => opts[:hwp_id].to_i || hardware_profiles(credentials).first.id.to_i)
+                       :flavorId => opts[:hwp_id].length>0 ? opts[:hwp_id].to_i : 1)
       result = convert_instance_after_create(server, credentials.user, server.adminPass)
     end
     result
   end
 
-  def create_image(credentials, opts={})
-    rs = new_client(credentials)
+  # TODO: This action is reserved for create image from instance
+  #
+  #def create_image(credentials, opts={})
+  #  rs = new_client(credentials)
+  #  safely do
+  #    server = rs.get_server(opts[:id].to_i)
+  #    image = server.create_image(opts[:name])
+  #    Image.new(
+  #      :id => image.id.to_s,
+  #      :name => image.name,
+  #      :description => image.name,
+  #      :owner_id => credentials.user,
+  #      :state => image.status,
+  #      :architecture => 'x86_64'
+  #    )
+  #  end
+  #end
+
+  def run_on_instance(credentials, opts={})
+    target = instance(credentials, :id => opts[:id])
+    param = {}
+    param[:credentials] = {
+      :username => 'root',
+      :password => opts[:password]
+    }
+    param[:port] = opts[:port] || '22'
+    param[:ip] = target.public_addresses.first
     safely do
-      server = rs.get_server(opts[:id].to_i)
-      image = server.create_image(opts[:name])
-      Image.new(
-        :id => image.id.to_s,
-        :name => image.name,
-        :description => image.name,
-        :owner_id => credentials.user,
-        :state => image.status,
-        :architecture => 'x86_64'
-      )
+      Deltacloud::Runner.execute(opts[:cmd], param)
     end
   end
 
@@ -127,44 +143,6 @@ class RackspaceDriver < Deltacloud::BaseDriver
 
   alias_method :stop_instance, :destroy_instance
 
-  def convert_instance_after_create(server, user_name, password='')
-    inst = Instance.new(
-      :id => server.id.to_s,
-      :realm_id => 'us',
-      :owner_id => user_name,
-      :description => server.name,
-      :name => server.name,
-      :state => (server.status == 'ACTIVE') ? 'RUNNING' : 'PENDING',
-      :architecture => 'x86_64',
-      :image_id => server.imageId.to_s,
-      :instance_profile => InstanceProfile::new(server.flavorId.to_s),
-      :public_addresses => server.addresses[:public],
-      :private_addresses => server.addresses[:private],
-      :username => 'root',
-      :password => password ? password : nil
-    )
-    inst.actions = instance_actions_for(inst.state)
-    inst
-  end
-
-  def convert_instance(server, user_name = '')
-    inst = Instance.new(
-      :id => server[:id].to_s,
-      :realm_id => 'us',
-      :owner_id => user_name,
-      :description => server[:name],
-      :name => server[:name],
-      :state => (server[:status] == 'ACTIVE') ? 'RUNNING' : 'PENDING',
-      :architecture => 'x86_64',
-      :image_id => server[:imageId].to_s,
-      :instance_profile => InstanceProfile::new(server[:flavorId].to_s),
-      :public_addresses => server[:addresses][:public],
-      :private_addresses => server[:addresses][:private]
-    )
-    inst.actions = instance_actions_for(inst.state)
-    inst
-  end
-
   #
   # Instances
   #
@@ -362,6 +340,44 @@ private
               })
   end
 
+  def convert_instance_after_create(server, user_name, password='')
+    inst = Instance.new(
+      :id => server.id.to_s,
+      :realm_id => 'us',
+      :owner_id => user_name,
+      :description => server.name,
+      :name => server.name,
+      :state => (server.status == 'ACTIVE') ? 'RUNNING' : 'PENDING',
+      :architecture => 'x86_64',
+      :image_id => server.imageId.to_s,
+      :instance_profile => InstanceProfile::new(server.flavorId.to_s),
+      :public_addresses => server.addresses[:public],
+      :private_addresses => server.addresses[:private],
+      :username => 'root',
+      :password => password ? password : nil
+    )
+    inst.actions = instance_actions_for(inst.state)
+    inst
+  end
+
+  def convert_instance(server, user_name = '')
+    inst = Instance.new(
+      :id => server[:id].to_s,
+      :realm_id => 'us',
+      :owner_id => user_name,
+      :description => server[:name],
+      :name => server[:name],
+      :state => (server[:status] == 'ACTIVE') ? 'RUNNING' : 'PENDING',
+      :architecture => 'x86_64',
+      :image_id => server[:imageId].to_s,
+      :instance_profile => InstanceProfile::new(server[:flavorId].to_s),
+      :public_addresses => server[:addresses][:public],
+      :private_addresses => server[:addresses][:private]
+    )
+    inst.actions = instance_actions_for(inst.state)
+    inst
+  end
+
   def cloudfiles_client(credentials)
     safely do
       CloudFiles::Connection.new(:username => credentials.user, :api_key => credentials.password)
-- 
1.7.4