deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@apache.org
Subject svn commit: r1199708 - in /incubator/deltacloud/trunk/server/lib/deltacloud/drivers/rhevm: rhevm_client.rb rhevm_driver.rb
Date Wed, 09 Nov 2011 12:35:13 GMT
Author: mfojtik
Date: Wed Nov  9 12:35:13 2011
New Revision: 1199708

URL: http://svn.apache.org/viewvc?rev=1199708&view=rev
Log:
RHEVM: Various optimization to preserve multiple requests to access single resource

Signed-off-by: Michal fojtik <mfojtik@redhat.com>

Modified:
    incubator/deltacloud/trunk/server/lib/deltacloud/drivers/rhevm/rhevm_client.rb
    incubator/deltacloud/trunk/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb

Modified: incubator/deltacloud/trunk/server/lib/deltacloud/drivers/rhevm/rhevm_client.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/lib/deltacloud/drivers/rhevm/rhevm_client.rb?rev=1199708&r1=1199707&r2=1199708&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/lib/deltacloud/drivers/rhevm/rhevm_client.rb (original)
+++ incubator/deltacloud/trunk/server/lib/deltacloud/drivers/rhevm/rhevm_client.rb Wed Nov
 9 12:35:13 2011
@@ -196,16 +196,21 @@ module RHEVM
         :accept => "application/xml"
       }
       headers.merge!(auth_header)
-      if opts[:id]
-        vm = Client::parse_response(RHEVM::client(@api_entrypoint)["/templates/%s" % opts[:id]].get(headers)).root
-        [ RHEVM::Template::new(self, vm)]
-      else
-        Client::parse_response(RHEVM::client(@api_entrypoint)["/templates"].get(headers)).xpath('/templates/template').collect
do |vm|
-          RHEVM::Template::new(self, vm)
-        end
+      rhevm_templates = RHEVM::client(@api_entrypoint)["/templates"].get(headers)
+      Client::parse_response(rhevm_templates).xpath('/templates/template').collect do |t|
+        RHEVM::Template::new(self, t)
       end
     end
 
+    def template(template_id)
+      headers = {
+        :accept => "application/xml"
+      }
+      headers.merge!(auth_header)
+      rhevm_template = RHEVM::client(@api_entrypoint)["/templates/%s" % template_id].get(headers)
+      RHEVM::Template::new(self, Client::parse_response(rhevm_template).root)
+    end
+
     def clusters(opts={})
       headers = {
         :accept => "application/xml; detail=datacenters"
@@ -226,16 +231,21 @@ module RHEVM
         :accept => "application/xml"
       }
       headers.merge!(auth_header)
-      if opts[:id]
-        vm = Client::parse_response(RHEVM::client(@api_entrypoint)["/datacenters/%s" % opts[:id]].get(headers)).root
-        [ RHEVM::DataCenter::new(self, vm)]
-      else
-        Client::parse_response(RHEVM::client(@api_entrypoint)["/datacenters"].get(headers)).xpath('/data_centers/data_center').collect
do |vm|
-          RHEVM::DataCenter::new(self, vm)
-        end
+      rhevm_datacenters = RHEVM::client(@api_entrypoint)["/datacenters"].get(headers)
+      Client::parse_response(rhevm_datacenters).xpath('/data_centers/data_center').collect
do |dc|
+        RHEVM::DataCenter::new(self, dc)
       end
     end
 
+    def datacenter(datacenter_id)
+      headers = {
+        :accept => "application/xml"
+      }
+      headers.merge!(auth_header)
+      rhevm_datacenter = RHEVM::client(@api_entrypoint)["/datacenters/%s" % datacenter_id].get(headers)
+      RHEVM::DataCenter::new(self, Client::parse_response(rhevm_datacenter).root)
+    end
+
     def hosts(opts={})
       headers = {
         :accept => "application/xml"
@@ -347,10 +357,10 @@ module RHEVM
       @macs = (xml/'nics/nic/mac').collect { |mac| mac[:address] }
       @creation_time = (xml/'creation_time').text
       @ip = ((xml/'guest_info/ip').first[:address] rescue nil)
-      unless @ip
-        @vnc = ((xml/'display/address').first.text rescue "127.0.0.1")
-        @vnc += ":#{((xml/'display/port').first.text rescue "5890")}"
-      end
+      @vnc = {
+        :address => ((xml/'display/address').first.text rescue "127.0.0.1"),
+        :port => ((xml/'display/port').first.text rescue "5890")
+      } unless @ip
     end
 
   end

Modified: incubator/deltacloud/trunk/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb?rev=1199708&r1=1199707&r2=1199708&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb (original)
+++ incubator/deltacloud/trunk/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb Wed Nov
 9 12:35:13 2011
@@ -74,14 +74,12 @@ class RHEVMDriver < Deltacloud::BaseDriv
   # Realms
   #
 
-  def realms(credentials, opts=nil)
+  def realms(credentials, opts={})
     client = new_client(credentials)
     realm_arr = []
     safely do
-      clusters = client.clusters
-      clusters.each do |r|
-        d = client.datacenters(:id => r.datacenter.id).first
-        realm_arr << convert_realm(r, d)
+      realm_arr = client.clusters.collect do |r|
+        convert_realm(r, client.datacenter(r.datacenter.id))
       end
     end
     realm_arr = filter_on( realm_arr, :id, opts )
@@ -92,12 +90,10 @@ class RHEVMDriver < Deltacloud::BaseDriv
     client = new_client(credentials)
     img_arr = []
     safely do
-      templates = client.templates
       if (!opts.nil? && opts[:id])
-        templates = templates.select{|t| opts[:id] == t.id}
-      end
-      templates.each do |t|
-        img_arr << convert_image(client, t)
+        img_arr << convert_image(client, client.template(opts[:id]))
+      else
+        img_arr = client.templates.collect { |t| convert_image(client, t) }
       end
     end
     img_arr = filter_on( img_arr, :architecture, opts )
@@ -233,15 +229,21 @@ class RHEVMDriver < Deltacloud::BaseDriv
                                    :hwp_storage => "#{storage_size}"
     )
     public_addresses = []
-    # First check if RHEV-M guest tools are installed and IP address is offered by them
-    public_addresses << inst.ip if inst.ip
-    # Second check if ConfServer broker is running, then ask for an IP there
-    public_addresses << confserver_ip(inst.id) if ENV['CONFIG_SERVER_ADDRESS'] and
public_addresses.empty?
-    public_addresses.compact!
-    # If everything fails fallback to report MAC address
-    public_addresses = inst.macs if public_addresses.empty?
-    public_addresses.flatten!
-    public_addresses << inst.vnc if inst.vnc
+    # First try to get IP address from RHEV-M. This require rhev-agent package
+    # installed on guest
+    public_addresses << InstanceAddress.new(inst.ip, :type => :ipv6) if inst.ip
+    # ConfServer will overide the IP address returned by RHEV-M guest agent
+    if ENV['CONFIG_SERVER_ADDRESS']
+      ip = confserver_ip(inst.id)
+      public_addresses = [ InstanceAddress.new(ip, :type => :ipv6) ]
+    end
+    # If IP retrieval failed, fallback to VNC and MAC address
+    if public_addresses.empty?
+      public_addresses = inst.macs.collect { |mac_address| InstanceAddress.new(mac_address,
:type => :mac) }
+    end
+    if inst.vnc
+      public_addresses << InstanceAddress.new(inst.vnc[:address], :port => inst.vnc[:port],
:type => :vnc)
+    end
     Instance.new(
       :id => inst.id,
       :name => inst.name,



Mime
View raw message