incubator-deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@redhat.com
Subject [PATCH core 5/5] Added support for IP reporting (both VNC and NIC)
Date Tue, 04 Jan 2011 12:06:16 GMT
From: Michal Fojtik <mfojtik@redhat.com>

---
 .../lib/deltacloud/drivers/rhevm/rhevm_client.rb   |   24 +++++++++++++++++++-
 .../lib/deltacloud/drivers/rhevm/rhevm_driver.rb   |   24 +++++++++++++++----
 server/views/instances/show.xml.haml               |   12 ++++++---
 3 files changed, 50 insertions(+), 10 deletions(-)

diff --git a/server/lib/deltacloud/drivers/rhevm/rhevm_client.rb b/server/lib/deltacloud/drivers/rhevm/rhevm_client.rb
index 55f54a4..92ad758 100644
--- a/server/lib/deltacloud/drivers/rhevm/rhevm_client.rb
+++ b/server/lib/deltacloud/drivers/rhevm/rhevm_client.rb
@@ -139,7 +139,7 @@ module RHEVM
 
   class Vm < BaseModel
     attr_accessor(:status, :memory, :sockets, :cores, :bootdevs, :host, :cluster, :template,
:vmpool, :profile)
-    attr_accessor(:creation_time, :storage)
+    attr_accessor(:creation_time, :storage, :nics, :display)
 
     def initialize(client, xml)
       super(client, xml)
@@ -161,7 +161,29 @@ module RHEVM
       disks_response = Nokogiri::XML(client.get("#{client.host}#{storage_link}"))
       @storage = disks_response.xpath('disks/disk/size').collect { |s| s.text.to_f }
       @storage = @storage.inject(nil) { |p, i| p ? p+i : i }
+      @display = {
+        :type => (xml/'display/type').text,
+        :address => (xml/'display/address').text,
+        :port => (xml/'display/port').text
+      } if (xml/'display')
+      @nics = get_nics(client, xml)
+      self
     end
+
+    private
+
+    def get_nics(client, xml)
+      nics = []
+      doc = Nokogiri::XML(client.get(client.host + (xml/'link[@rel="nics"]').first[:href]))
+      (doc/'nics/nic').each do |nic|
+        nics << {
+          :mac => (nic/'mac').first[:address],
+          :address => (nic/'ip').first ? (nic/'ip').first[:address]  : nil
+        }
+      end
+      nics
+    end
+
   end
 
   class Template < BaseModel
diff --git a/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb b/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb
index 740ed9e..8b4282f 100644
--- a/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb
+++ b/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb
@@ -214,9 +214,21 @@ class RHEVMDriver < Deltacloud::BaseDriver
                                    :hwp_cpu => inst.cores,
                                    :hwp_storage => "#{storage_size}"
     )
-    # TODO: Implement public_addresses (nics/ip)
-    # NOTE: This must be enabled on 'guest' side, otherwise this property is not
-    # available through RHEV-M API
+    # Include VNC and SPICE addresses
+    if inst.display
+      display_address = { 
+        :type => inst.display[:type],
+        :address => inst.display[:address],
+        :port => inst.display[:port]
+      }
+    end
+    public_addresses = []
+    unless inst.nics.empty?
+      inst.nics.each do |nic|
+        public_addresses << { :address => nic[:address], :mac => nic[:mac]}
+      end
+    end
+    public_addresses << display_address if display_address
     Instance.new(
       :id => inst.id,
       :name => inst.name,
@@ -227,7 +239,9 @@ class RHEVMDriver < Deltacloud::BaseDriver
       :launch_time => inst.creation_time,
       :instance_profile => profile,
       :hardware_profile_id => profile.id,
-      :actions=>instance_actions_for( state )
+      :actions=>instance_actions_for( state ),
+      :public_addresses => public_addresses,
+      :private_addresses => []
     )
   end
 
@@ -269,7 +283,7 @@ class RHEVMDriver < Deltacloud::BaseDriver
       :description => img.description,
       :owner_id => client.username,
       :architecture => 'x86_64', # All RHEV-M VMs are x86_64
-      :status => img.status
+      :state => img.status
     )
   end
 
diff --git a/server/views/instances/show.xml.haml b/server/views/instances/show.xml.haml
index c31a215..27cf77f 100644
--- a/server/views/instances/show.xml.haml
+++ b/server/views/instances/show.xml.haml
@@ -25,12 +25,16 @@
     %launch_time<
       =@instance.launch_time
   - if @instance.public_addresses
-    %public_addresses
+    %public_addresses<
       - @instance.public_addresses.each do |address|
-        %address<
-          =address
+        - if address.class.eql?(Hash) and address[:address]!=""
+          %address{ :port => address[:port], :type => address[:type], :mac => address[:mac]
}<
+            =address[:address]
+        - elsif address.class.eql?(String)
+          %address<
+            =address
   - if @instance.private_addresses
-    %private_addresses
+    %private_addresses<
       - @instance.private_addresses.each do |address|
         %address<
           =address
-- 
1.7.3.3


Mime
View raw message