From: marios <[email protected]>

---
 .../deltacloud/drivers/rimu/rimu_hosting_client.rb |   87 ------------
 .../deltacloud/drivers/rimu/rimu_hosting_driver.rb |  143 -------------------
 .../drivers/rimuhosting/rimuhosting_client.rb      |   88 ++++++++++++
 .../drivers/rimuhosting/rimuhosting_driver.rb      |  144 ++++++++++++++++++++
 server/lib/drivers.rb                              |    6 +-
 5 files changed, 234 insertions(+), 234 deletions(-)
 delete mode 100755 server/lib/deltacloud/drivers/rimu/rimu_hosting_client.rb
 delete mode 100755 server/lib/deltacloud/drivers/rimu/rimu_hosting_driver.rb
 create mode 100755 
server/lib/deltacloud/drivers/rimuhosting/rimuhosting_client.rb
 create mode 100755 
server/lib/deltacloud/drivers/rimuhosting/rimuhosting_driver.rb

diff --git a/server/lib/deltacloud/drivers/rimu/rimu_hosting_client.rb 
b/server/lib/deltacloud/drivers/rimu/rimu_hosting_client.rb
deleted file mode 100755
index f145caa..0000000
--- a/server/lib/deltacloud/drivers/rimu/rimu_hosting_client.rb
+++ /dev/null
@@ -1,87 +0,0 @@
-#
-# Copyright (C) 2009  RimuHosting Ltd
-# Author: Ivan Meredith <[email protected]>
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  
USA
-
-require "net/http"
-require "net/https"
-require "rubygems"
-require "json"
-require "deltacloud/base_driver"
-
-module Deltacloud
-  module Drivers
-    module Rimu
-
-class RimuHostingClient
-  def initialize(credentials ,baseuri = 'https://rimuhosting.com/r')
-    @uri = URI.parse(baseuri)
-    @service = Net::HTTP.new(@uri.host, @uri.port)
-    @service.use_ssl = true
-    if credentials.provided?
-      @auth = "rimuhosting apikey=#{credentials.password}"
-    end
-
-  end
-
-  def request(resource, data='', method='GET')
-    headers = {"Accept" => "application/json", "Content-Type" => 
"application/json"}
-    if([email protected]?)
-      headers["Authorization"] = @auth
-    end
-    r = @service.send_request(method, @uri.path + resource, data, headers)
-         puts r.body
-    res = JSON.parse(r.body)
-    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
-    request('/distributions')["distro_infos"]
-  end
-
-  def list_plans
-    puts "testsdasfdsf"
-    request('/pricing-plans;server-type=VPS')["pricing_plan_infos"]
-  end
-
-  def list_nodes
-    request('/orders;include_inactive=N')["about_orders"]
-  end
-
-  def set_server_state(id, state)
-    json = {"reboot_request" => {"running_state" => state}}.to_json
-    request("/orders/order-#{id}-a/vps/running-state", json, 'PUT')
-  end
-
-  def delete_server(id)
-    request("/orders/order-#{id}-a/vps",'', 'DELETE')
-  end
-
-  def create_server(image_id, plan_code, name)
-    json = {:new_vps => {:instantiation_options => {:domain_name => name, 
:distro => image_id},
-                        :pricing_plan_code => plan_code}}.to_json
-    request('/orders/new-vps',json, 'POST')[:about_order]
-  end
-end
-
-    end
-  end
-end
diff --git a/server/lib/deltacloud/drivers/rimu/rimu_hosting_driver.rb 
b/server/lib/deltacloud/drivers/rimu/rimu_hosting_driver.rb
deleted file mode 100755
index d0ffac9..0000000
--- a/server/lib/deltacloud/drivers/rimu/rimu_hosting_driver.rb
+++ /dev/null
@@ -1,143 +0,0 @@
-#
-# Copyright (C) 2009  RimuHosting Ltd
-# Author: Ivan Meredith <[email protected]>
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  
USA
-
-require "deltacloud/base_driver"
-require "deltacloud/drivers/rimu/rimu_hosting_client"
-
-module Deltacloud
-  module Drivers
-    module Rimu
-
-class RimuHostingDriver < Deltacloud::BaseDriver
-
-  feature :instances, :user_name
-
-  def images(credentails, opts=nil)
-    rh = RimuHostingClient.new(credentails)
-    images = rh.list_images.map do | image |
-      Image.new({
-              :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)
-    images
-  end
-
-  def hardware_profiles(credentials, opts = nil)
-    rh = RimuHostingClient.new(credentials)
-    results = rh.list_plans.map do |plan|
-      # FIXME: x86 is not a valid architecture; what is Rimu offering ?
-      # FIXME: VPS plans offer a range of memory/storage, but that's
-      #        not contained in hte pricing_plan_infos
-      HardwareProfile.new(plan["pricing_plan_code"]) do
-        memory plan["minimum_memory_mb"].to_f
-        storage => plan["minimum_disk_gb"].to_i
-        architecture => "x86"
-      end
-    end
-    filter_hardware_profiles(results, opts)
-  end
-
-  def realms(credentials, opts=nil)
-    [Realm.new( {
-            :id=>"rimu",
-            :name=>"RimuHosting",
-            :state=> "AVAILABLE"
-    } )]
-  end
-
-  def instances(credentials, opts=nil)
-     rh = RimuHostingClient.new(credentials)
-    instances = rh.list_nodes.map do | inst |
-      convert_srv_to_instance(inst)
-    end
-    instances = filter_on( instances, :id, opts)
-    instances = filter_on( instances, :state, opts )
-    instances
-  end
-
-  def reboot_instance(credentials, id)
-     rh = RimuHostingClient.new(credentials)
-    rh.set_server_state(id, :RESTARTING)
-  end
-
-  def start_instance(credentials, id)
-    rh = RimuHostingClient.new(credentials)
-    rh.set_server_state(id, :STARTED)
-  end
-
-  def stop_instance(credentials, id)
-    destroy_instance(credentials, id)
-  end
-
-  def destroy_instance(credentials, id)
-     rh = RimuHostingClient.new(credentials)
-    rh.delete_server(id)
-  end
-
-  def create_instance(credentials, image_id, opts)
-     rh = RimuHostingClient.new(credentials)
-    # really need to raise an exception here.
-    hwp_id = opts[:hwp_id] || 1
-    # 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.create_server(image_id, hwp_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",
-            :instance_profile => InstanceProfile.new("none"),
-            :actions => instance_actions_for("RUNNING")
-    })
-  end
-
-  define_instance_states do
-    start.to( :pending )          .automatically
-
-    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
-
-
-end
-
-    end
-  end
-end
diff --git a/server/lib/deltacloud/drivers/rimuhosting/rimuhosting_client.rb 
b/server/lib/deltacloud/drivers/rimuhosting/rimuhosting_client.rb
new file mode 100755
index 0000000..9c24066
--- /dev/null
+++ b/server/lib/deltacloud/drivers/rimuhosting/rimuhosting_client.rb
@@ -0,0 +1,88 @@
+#
+# Copyright (C) 2009  RimuHosting Ltd
+# Author: Ivan Meredith <[email protected]>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  
USA
+
+require "net/http"
+require "net/https"
+require "rubygems"
+require "json"
+require "deltacloud/base_driver"
+
+module Deltacloud
+  module Drivers
+    module RimuHosting
+
+class RimuHostingClient
+  def initialize(credentials, baseuri = 'https://rimuhosting.com/r')
+    @uri = URI.parse(baseuri)
+    @service = Net::HTTP.new(@uri.host, @uri.port)
+    @service.use_ssl = true
+    if credentials.nil?
+      raise Deltacloud::AuthException.new
+    else
+      @auth = "rimuhosting apikey=#{credentials.password}"
+    end
+  end
+
+  def request(resource, data='', method='GET')
+    headers = {"Accept" => "application/json", "Content-Type" => 
"application/json"}
+    if([email protected]?)
+      headers["Authorization"] = @auth
+    end
+    r = @service.send_request(method, @uri.path + resource, data, headers)
+         puts r.body
+    res = JSON.parse(r.body)
+    res = res[res.keys[0]]
+    if(res['response_type'] == "ERROR" and ((res['error_info']['error_class'] 
== "PermissionException") or 
+                                             res['error_info']['error_class'] 
== "LoginRequired"))
+      raise Deltacloud::AuthException.new
+    end
+    res
+  end
+
+  def list_images
+    request('/distributions')["distro_infos"]
+  end
+
+  def list_plans
+    puts "testsdasfdsf"
+    request('/pricing-plans;server-type=VPS')["pricing_plan_infos"]
+  end
+
+  def list_nodes
+    request('/orders;include_inactive=N')["about_orders"]
+  end
+
+  def set_server_state(id, state)
+    json = {"reboot_request" => {"running_state" => state}}.to_json
+    request("/orders/order-#{id}-a/vps/running-state", json, 'PUT')
+  end
+
+  def delete_server(id)
+    request("/orders/order-#{id}-a/vps",'', 'DELETE')
+  end
+
+  def create_server(image_id, plan_code, name)
+    json = {:new_vps => {:instantiation_options => {:domain_name => name, 
:distro => image_id},
+                        :pricing_plan_code => plan_code}}.to_json
+    request('/orders/new-vps',json, 'POST')[:about_order]
+  end
+end
+
+    end
+  end
+end
diff --git a/server/lib/deltacloud/drivers/rimuhosting/rimuhosting_driver.rb 
b/server/lib/deltacloud/drivers/rimuhosting/rimuhosting_driver.rb
new file mode 100755
index 0000000..44baa41
--- /dev/null
+++ b/server/lib/deltacloud/drivers/rimuhosting/rimuhosting_driver.rb
@@ -0,0 +1,144 @@
+#
+# Copyright (C) 2009  RimuHosting Ltd
+# Author: Ivan Meredith <[email protected]>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  
USA
+
+require "deltacloud/base_driver"
+require "deltacloud/drivers/rimuhosting/rimuhosting_client"
+
+module Deltacloud
+  module Drivers
+    module RimuHosting
+
+class RimuHostingDriver < Deltacloud::BaseDriver
+
+  feature :instances, :user_name
+
+  def images(credentials, opts=nil)
+    rh = RimuHostingClient.new(credentials)
+    images = rh.list_images.map do | image |
+      Image.new({
+              :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)
+    images
+  end
+
+  def hardware_profiles(credentials, opts = nil)
+    rh = RimuHostingClient.new(credentials)
+    results = rh.list_plans.map do |plan|
+      # FIXME: x86 is not a valid architecture; what is Rimu offering ?
+      # FIXME: VPS plans offer a range of memory/storage, but that's
+      #        not contained in hte pricing_plan_infos
+      HardwareProfile.new(plan["pricing_plan_code"]) do
+        memory plan["minimum_memory_mb"].to_f
+        storage  plan["minimum_disk_gb"].to_i
+        architecture "x86"
+      end
+    end
+    filter_hardware_profiles(results, opts)
+  end
+
+  def realms(credentials, opts=nil)
+    [Realm.new( {
+            :id=>"rimu",
+            :name=>"RimuHosting",
+            :state=> "AVAILABLE"
+    } )]
+  end
+
+  def instances(credentials, opts=nil)
+    rh = RimuHostingClient.new(credentials)
+    instances = rh.list_nodes.map do | inst |
+      convert_srv_to_instance(inst)
+    end
+    instances = filter_on( instances, :id, opts)
+    instances = filter_on( instances, :state, opts )
+    instances
+  end
+
+  def reboot_instance(credentials, id)
+     rh = RimuHostingClient.new(credentials)
+    rh.set_server_state(id, :RESTARTING)
+  end
+
+  def start_instance(credentials, id)
+    rh = RimuHostingClient.new(credentials)
+    rh.set_server_state(id, :STARTED)
+  end
+
+  def stop_instance(credentials, id)
+    destroy_instance(credentials, id)
+  end
+
+  def destroy_instance(credentials, id)
+     rh = RimuHostingClient.new(credentials)
+    rh.delete_server(id)
+  end
+
+  def create_instance(credentials, image_id, opts)
+     rh = RimuHostingClient.new(credentials)
+    # really need to raise an exception here.
+    hwp_id = opts[:hwp_id] || 1
+    # 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.create_server(image_id, hwp_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",
+            :instance_profile => InstanceProfile.new("none"),
+            :actions => instance_actions_for("RUNNING"), 
+            :public_addresses => inst["allocated_ips"]["primary_ip"]
+    })
+  end
+
+  define_instance_states do
+    start.to( :pending )          .automatically
+
+    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
+
+
+end
+
+    end
+  end
+end
diff --git a/server/lib/drivers.rb b/server/lib/drivers.rb
index 269fe75..6c5d6a6 100644
--- a/server/lib/drivers.rb
+++ b/server/lib/drivers.rb
@@ -3,7 +3,7 @@ DRIVERS = {
   :rackspace => { :name => "Rackspace" },
   :gogrid => { :name => "Gogrid" },
   :rhevm => { :name => "RHEVM" },
-  :rimu => { :name => "Rimu", :class => "RimuHostingDriver"},
+  :rimuhosting => { :name => "RimuHosting"},
   :opennebula => { :name => "Opennebula", :class => "OpennebulaDriver" },
   :terremark => { :name => "Terremark"},
   :mock => { :name => "Mock" }
@@ -19,7 +19,7 @@ def driver_class_name
 end
 
 def driver_source_name
-  File.join("deltacloud", "drivers", "#{DRIVER}", "#{DRIVER}_driver.rb")
+  File.join("deltacloud", "drivers", "#{DRIVER}", "#{DRIVER}_driver.rb") 
 end
 
 def driver_mock_source_name
@@ -29,10 +29,8 @@ end
 
 def driver
   require driver_source_name
-
   if Sinatra::Application.environment.eql? :test
     require driver_mock_source_name
   end
-
   @driver ||= eval( driver_class_name ).new
 end
-- 
1.6.6.1

_______________________________________________
deltacloud-devel mailing list
[email protected]
https://fedorahosted.org/mailman/listinfo/deltacloud-devel

Reply via email to