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:25:03 UTC

svn commit: r962136 - in /incubator/deltacloud/trunk/rimudriver/lib: rimu_hosting_driver.rb rimuhosting_client.rb rimuhosting_driver.rb

Author: lutter
Date: Thu Jul  8 23:25:03 2010
New Revision: 962136

URL: http://svn.apache.org/viewvc?rev=962136&view=rev
Log:
Added flavor, instances and images

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

Added: 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=962136&view=auto
==============================================================================
--- incubator/deltacloud/trunk/rimudriver/lib/rimu_hosting_driver.rb (added)
+++ incubator/deltacloud/trunk/rimudriver/lib/rimu_hosting_driver.rb Thu Jul  8 23:25:03 2010
@@ -0,0 +1,70 @@
+require "rimuhosting_client"
+require "deltacloud/base_driver"
+
+class RimuHostingDriver < DeltaCloud::BaseDriver
+  def images(credentails, opts=nil)
+    rh = new_client(credentails)
+    res = 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"
+              })
+    end
+    #res.sort_by{|e| [e.description]}
+    res  
+  end
+
+  def flavor(credentials, opts=nil)
+    flav = flavors(credentials, opts)  
+    flav.each { |x| return x if x.id == opts[:id] }
+    nil
+  end
+  def flavors(credentials, opts=nil)
+    rh = new_client(credentials)
+    res = 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"
+                })
+    end
+  end
+
+  def instances(credentials, opts=nil)
+    rh = new_client(credentials)
+    res = rh.list_nodes.map do | inst |
+      Instance.new({
+                  :id => inst["order_oid"],
+                  :name => inst["domain_name"],
+                  :image_id => inst["distro"],
+                  :state => "RUNNING",
+                  :name => inst["domain_name"],
+                  :realm_id => "RH",
+                  :owner_id => "root",
+                  :flavor_id => "none",
+                  :actions => instance_actions_for("RUNNING")
+              })
+    end
+  end
+
+  def instance_states
+    [
+      [ :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=962136&r1=962135&r2=962136&view=diff
==============================================================================
--- incubator/deltacloud/trunk/rimudriver/lib/rimuhosting_client.rb (original)
+++ incubator/deltacloud/trunk/rimudriver/lib/rimuhosting_client.rb Thu Jul  8 23:25:03 2010
@@ -0,0 +1,35 @@
+require "net/http"
+require "net/https"
+require "rubygems"
+require "json"
+
+
+class RimuHostingClient
+  def initialize(name, password ,baseuri = 'http://localhost:8080/rimuhosting/r')
+    @uri = URI.parse(baseuri)
+
+    @service = Net::HTTP.new(@uri.host, @uri.port)
+    @service.use_ssl = false
+    @auth = "rimuhosting username=%s;password=%s" % [name, password]
+  end
+
+  def request(resource, data='', method='GET')
+    headers = {"Accept" => "application/json", "Content-Type" => "application/json", "Authorization" => @auth}
+    r = @service.send_request(method, @uri.path + resource, data, headers)
+    res = JSON.parse(r.body)  
+    res[res.keys[0]]
+  end
+
+  def list_images
+    request('/distributions')["distro_infos"]
+  end
+
+  def list_plans
+    request('/pricing-plans;server-type=VPS')["pricing_plan_infos"]
+  end
+
+  def list_nodes
+    request('/orders;include_inactive=N')["about_orders"]
+  end
+end
+