incubator-deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lut...@apache.org
Subject svn commit: r962142 - in /incubator/deltacloud/trunk/rimudriver/lib: rimu_hosting_driver.rb rimuhosting_client.rb
Date Thu, 08 Jul 2010 23:25:23 GMT
Author: lutter
Date: Thu Jul  8 23:25:23 2010
New Revision: 962142

URL: http://svn.apache.org/viewvc?rev=962142&view=rev
Log:
Lots of code changes to make the rimuhosting driver work with portal.

Modified:
    incubator/deltacloud/trunk/rimudriver/lib/rimu_hosting_driver.rb
    incubator/deltacloud/trunk/rimudriver/lib/rimuhosting_client.rb

Modified: incubator/deltacloud/trunk/rimudriver/lib/rimu_hosting_driver.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/rimudriver/lib/rimu_hosting_driver.rb?rev=962142&r1=962141&r2=962142&view=diff
==============================================================================
--- incubator/deltacloud/trunk/rimudriver/lib/rimu_hosting_driver.rb (original)
+++ incubator/deltacloud/trunk/rimudriver/lib/rimu_hosting_driver.rb Thu Jul  8 23:25:23 2010
@@ -3,15 +3,15 @@ require "deltacloud/base_driver"
 
 class RimuHostingDriver < DeltaCloud::BaseDriver
   def images(credentails, opts=nil)
-    rh = new_client(credentails)
+    rh = RimuHostingClient.new(credentails)
     images = rh.list_images.map do | image |
       Image.new({
-                  :id => image["distro_code"],
-                  :name => image["distro_code"],
-                  :description => image["distro_description"],
-                  :owner_id => "root",
-                  :architecture => "x86"
-              })
+              :id => image["distro_code"].gsub(/\./,"-"),
+              :name => image["distro_code"],
+              :description => image["distro_description"],
+              :owner_id => "root",
+              :architecture => "x86"
+      })
     end
     images.sort_by{|e| [e.description]}
     images = filter_on( images, :id, opts)
@@ -19,14 +19,14 @@ class RimuHostingDriver < DeltaCloud::Ba
   end
 
   def flavors(credentials, opts=nil)
-    rh = new_client(credentials)
+    rh = RimuHostingClient.new(credentials)
     flavors = rh.list_plans.map do | flavor |
       Flavor.new({
-                  :id => flavor["pricing_plan_code"],
-                  :memory => flavor["minimum_memory_mb"].to_f/1024,
-                  :storage => flavor["minimum_disk_gb"].to_i,
-                  :architecture => "x86"
-                })
+              :id => flavor["pricing_plan_code"],
+              :memory => flavor["minimum_memory_mb"].to_f/1024,
+              :storage => flavor["minimum_disk_gb"].to_i,
+              :architecture => "x86"
+      })
     end
     flavors = filter_on( flavors, :id, opts)
     flavors
@@ -34,27 +34,28 @@ class RimuHostingDriver < DeltaCloud::Ba
 
   def realms(credentials, opts=nil)
     [Realm.new( {
-      :id=>"rimu",
-      :name=>"RimuHosting",
-      :state=> "AVAILABLE"
+            :id=>"rimu",
+            :name=>"RimuHosting",
+            :state=> "AVAILABLE"
     } )]
   end
-  
+
   def instances(credentials, opts=nil)
-    rh = new_client(credentials)
+     rh = RimuHostingClient.new(credentials)
     instances = rh.list_nodes.map do | inst |
       convert_srv_to_instance(inst)
     end
     instances = filter_on( instances, :id, opts)
     instances
   end
+
   def reboot_instance(credentials, id)
-    rh = new_client(credentials)
+     rh = RimuHostingClient.new(credentials)
     rh.set_server_state(id, :RESTARTING)
   end
 
   def start_instance(credentials, id)
-    rh = new_client(credentials)
+    rh = RimuHostingClient.new(credentials)
     rh.set_server_state(id, :STARTED)
   end
 
@@ -63,50 +64,48 @@ class RimuHostingDriver < DeltaCloud::Ba
   end
 
   def destroy_instance(credentials, id)
-    rh = new_client(credentials)
+     rh = RimuHostingClient.new(credentials)
     rh.delete_server(id)
   end
-  
+
   def create_instance(credentials, image_id, opts)
-    rh = new_client( credentials )
+     rh = RimuHostingClient.new(credentials)
     # really need to raise an exception here.
     flavor_id = 1
-    if (opts[:flavor_id]) then flavor_id = opts[:flavor_id] end
+    if (opts[:flavor_id]) then
+      flavor_id = opts[:flavor_id]
+    end
     # really bad, but at least its a fqdn
     name = Time.now.to_s + '.com'
-    if (opts[:name]) then name = opts[:name] end
-    convert_srv_to_instance(rh.start_server(image_id, flavor_id, name))
+    if (opts[:name]) then
+      name = opts[:name]
+    end
+    convert_srv_to_instance(rh.create_server(image_id, flavor_id, name))
 
-    
   end
 
   def convert_srv_to_instance( inst )
-     Instance.new({
-                  :id => inst["order_oid"].to_s,
-                  :name => inst["domain_name"],
-                  :image_id => "lenny",
-                  :state => "RUNNING",
-                  :name => inst["domain_name"],
-                  :realm_id => "RH",
-                  :owner_id => "root",
-                  :flavor_id => "none",
-                  :actions => instance_actions_for("RUNNING")
-              })
+    Instance.new({
+            :id => inst["order_oid"].to_s,
+            :name => inst["domain_name"],
+            :image_id => "lenny",
+            :state => "RUNNING",
+            :name => inst["domain_name"],
+            :realm_id => "RH",
+            :owner_id => "root",
+            :flavor_id => "none",
+            :actions => instance_actions_for("RUNNING")
+    })
   end
+
   def instance_states
     [
-      [ :begin, { :running => :_auto_ }],
-      [ :pending, { :running => :_auto_ }],
-      [ :running, { :running => :reboot, :shutting_down => :stop}],
-      [ :shutting_down, { :stopped => :_auto_}],
-      [ :stopped, { :end => :_auto_}]    
+            [ :begin, { :running => :_auto_ }],
+            [ :pending, { :running => :_auto_ }],
+            [ :running, { :running => :reboot, :shutting_down => :stop}],
+            [ :shutting_down, { :stopped => :_auto_}],
+            [ :stopped, { :end => :_auto_}]
     ]
   end
-  def new_client(credentials)
-    if (credentials[:password].nil? || credentials[:password] == '' || credentials[:name].nil?
|| credentials[:name] == '')
-      raise DeltaCloud::AuthException.new
-    end
- 
-    RimuHostingClient.new(credentials[:name], credentials[:password])
-  end
+
 end
\ No newline at end of file

Modified: incubator/deltacloud/trunk/rimudriver/lib/rimuhosting_client.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/rimudriver/lib/rimuhosting_client.rb?rev=962142&r1=962141&r2=962142&view=diff
==============================================================================
--- incubator/deltacloud/trunk/rimudriver/lib/rimuhosting_client.rb (original)
+++ incubator/deltacloud/trunk/rimudriver/lib/rimuhosting_client.rb Thu Jul  8 23:25:23 2010
@@ -2,21 +2,35 @@ require "net/http"
 require "net/https"
 require "rubygems"
 require "json"
-
+require "deltacloud/base_driver"
 
 class RimuHostingClient
-  def initialize(name, password ,baseuri = 'https://rimuhosting.com/r')
+  def initialize(credentials ,baseuri = 'https://rimuhosting.com/r')
     @uri = URI.parse(baseuri)
     @service = Net::HTTP.new(@uri.host, @uri.port)
     @service.use_ssl = true
-    @auth = "rimuhosting apikey=%s" % [password]  
+    if(credentials[:password].nil? || credentials[:password] == "")
+      @auth = nil
+    else
+      @auth = "rimuhosting apikey=%s" % [credentials[:password]]  
+    end
+
   end
 
   def request(resource, data='', method='GET')
-    headers = {"Accept" => "application/json", "Content-Type" => "application/json",
"Authorization" => @auth}
+    headers = {"Accept" => "application/json", "Content-Type" => "application/json"}
+    if(!@auth.nil?)
+      headers["Authorization"] = @auth
+    end
     r = @service.send_request(method, @uri.path + resource, data, headers)
+         puts r.body
     res = JSON.parse(r.body)
-    res[res.keys[0]]
+    res = res[res.keys[0]]
+
+    if(res['response_type'] == "ERROR" and res['error_info']['error_class'] == "PermissionException")
+      raise DeltaCloud::AuthException.new
+    end
+    res
   end
 
   def list_images
@@ -24,6 +38,7 @@ class RimuHostingClient
   end
 
   def list_plans
+    puts "testsdasfdsf"
     request('/pricing-plans;server-type=VPS')["pricing_plan_infos"]
   end
 



Mime
View raw message