You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltacloud.apache.org by lu...@apache.org on 2010/07/09 01:24:46 UTC

svn commit: r962131 - in /incubator/deltacloud/trunk/drivers/rackspace: .gitignore lib/rackspace_client.rb lib/rackspace_driver.rb

Author: lutter
Date: Thu Jul  8 23:24:46 2010
New Revision: 962131

URL: http://svn.apache.org/viewvc?rev=962131&view=rev
Log:
Got more working - everything but instance creation

Added:
    incubator/deltacloud/trunk/drivers/rackspace/.gitignore
Modified:
    incubator/deltacloud/trunk/drivers/rackspace/lib/rackspace_client.rb
    incubator/deltacloud/trunk/drivers/rackspace/lib/rackspace_driver.rb

Added: incubator/deltacloud/trunk/drivers/rackspace/.gitignore
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/drivers/rackspace/.gitignore?rev=962131&view=auto
==============================================================================
--- incubator/deltacloud/trunk/drivers/rackspace/.gitignore (added)
+++ incubator/deltacloud/trunk/drivers/rackspace/.gitignore Thu Jul  8 23:24:46 2010
@@ -0,0 +1 @@
+.#rackspace_driver.rb
\ No newline at end of file

Modified: incubator/deltacloud/trunk/drivers/rackspace/lib/rackspace_client.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/drivers/rackspace/lib/rackspace_client.rb?rev=962131&r1=962130&r2=962131&view=diff
==============================================================================
--- incubator/deltacloud/trunk/drivers/rackspace/lib/rackspace_client.rb (original)
+++ incubator/deltacloud/trunk/drivers/rackspace/lib/rackspace_client.rb Thu Jul  8 23:24:46 2010
@@ -3,7 +3,10 @@ require "net/https"
 require 'rubygems'
 require 'json'
 
-
+#
+# author: Michael Neale
+# TODO: catch generic errors in JSON response and throw (probably)
+#
 class RackspaceClient
 
   @@AUTH_API = URI.parse('https://auth.api.rackspacecloud.com/v1.0')

Modified: incubator/deltacloud/trunk/drivers/rackspace/lib/rackspace_driver.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/drivers/rackspace/lib/rackspace_driver.rb?rev=962131&r1=962130&r2=962131&view=diff
==============================================================================
--- incubator/deltacloud/trunk/drivers/rackspace/lib/rackspace_driver.rb (original)
+++ incubator/deltacloud/trunk/drivers/rackspace/lib/rackspace_driver.rb Thu Jul  8 23:24:46 2010
@@ -14,7 +14,6 @@ class RackspaceDriver < DeltaCloud::Base
                   } )    
     end
     results = filter_on( results, :id, opts )
-    results = filter_on( results, :architecture, opts )
     results
   end
 
@@ -23,15 +22,72 @@ class RackspaceDriver < DeltaCloud::Base
     results = racks.list_images.map do |img|
       Image.new( {
                    :id=>img["id"].to_s,
-                   :description=>img["name"],
+                   :name=>img["name"],
+                   :description => img["name"] + " " + img["status"] + "",
                    :owner_id=>"root",
                    :architecture=>'x86_64'
                  } )
     end
     results.sort_by{|e| [e.description]}
+    results
+  end
+
+  #rackspace does not at this stage have realms... its all US/TX, all the time (at least at time of writing) 
+  def realms(credentials, opts=nil)
+    [Realm.new( {
+      :id=>"us",
+      :name=>"United States",
+      :state=> "AVAILABLE"
+    } )]
+  end
+
+  def reboot_instance(credentials, id)
+    racks = new_client(credentials)
+    racks.reboot_server(id)
+  end
+
+  def stop_instance(credentials, id)
+    destroy_instance(credentials, id)
+  end
+
+  def destroy_instance(credentials, id)
+    racks = new_client(credentials)
+    racks.delete_server(id)
+  end
+
+
+  #
+  # Instances
+  #
+  def instances(credentials, opts=nil)
+    racks = new_client(credentials)
+    instances = []
+    if (opts.nil?)
+      instances = racks.list_servers.map do |srv| 
+        convert_srv_to_instance(srv)
+      end
+    else 
+      instances << convert_srv_to_instance(racks.load_server_details(opts[:id]))
+    end
+    instances
   end
 
 
+  def convert_srv_to_instance(srv) 
+            Instance.new( {
+                            :id=>srv["id"],
+                            :state=>srv["status"] == "ACTIVE" ? "RUNNING" : "PENDING",
+                            :name=>srv["name"],
+                            :image_id=>srv["imageId"],
+                            :owner_id=>"root",
+                            :realm_id=>"us",
+                            :public_addresses=>( srv["addresses"]["public"] ),
+                            :private_addresses=>( srv["addresses"]["private"] ),
+                            :flavor_id=>srv["flavorId"],
+                            :actions=>instance_actions_for(srv["status"] == "ACTIVE" ? "RUNNING" : "PENDING"),
+                          } )
+  end
+
 
   def new_client(credentials)
     if ( credentials[:name].nil? || credentials[:password].nil? || credentials[:name] == '' || credentials[:password] == '' )
@@ -40,4 +96,32 @@ class RackspaceDriver < DeltaCloud::Base
     RackspaceClient.new(credentials[:name], credentials[:password])
   end
 
+  @@INSTANCE_STATES = [
+    [ :begin, { 
+        :pending=>:create,
+    } ],
+    [ :pending, { 
+        :running=>:_auto_, 
+    } ],
+    [ :running, { 
+        :running=>:reboot, 
+        :shutting_down=>:stop
+    } ],
+    [ :shutting_down, { 
+        :stopped=>:_auto_,
+    } ],
+    [ :stopped, {
+        :end=>:_auto_,
+    } ],
+  ]
+
+  def instance_states()
+    @@INSTANCE_STATES 
+  end
+
+
+#PENDING
+#STOPPED
+#RUNNING
+
 end