Return-Path: Delivered-To: apmail-incubator-deltacloud-dev-archive@minotaur.apache.org Received: (qmail 27428 invoked from network); 4 Jan 2011 12:06:50 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 4 Jan 2011 12:06:50 -0000 Received: (qmail 85761 invoked by uid 500); 4 Jan 2011 12:06:50 -0000 Delivered-To: apmail-incubator-deltacloud-dev-archive@incubator.apache.org Received: (qmail 85742 invoked by uid 500); 4 Jan 2011 12:06:50 -0000 Mailing-List: contact deltacloud-dev-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: deltacloud-dev@incubator.apache.org Delivered-To: mailing list deltacloud-dev@incubator.apache.org Received: (qmail 85734 invoked by uid 99); 4 Jan 2011 12:06:50 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 04 Jan 2011 12:06:50 +0000 X-ASF-Spam-Status: No, hits=-5.0 required=10.0 tests=RCVD_IN_DNSWL_HI,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of mfojtik@redhat.com designates 209.132.183.28 as permitted sender) Received: from [209.132.183.28] (HELO mx1.redhat.com) (209.132.183.28) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 04 Jan 2011 12:06:43 +0000 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id p04C6NQU002046 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 4 Jan 2011 07:06:23 -0500 Received: from patashnik.brq.redhat.com (dhcp-2-138.brq.redhat.com [10.34.2.138]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p04C6GCV027869 for ; Tue, 4 Jan 2011 07:06:22 -0500 From: mfojtik@redhat.com To: deltacloud-dev@incubator.apache.org Subject: [PATCH core 5/5] Added support for IP reporting (both VNC and NIC) Date: Tue, 4 Jan 2011 13:06:16 +0100 Message-Id: <1294142776-15709-6-git-send-email-mfojtik@redhat.com> In-Reply-To: <1294142776-15709-1-git-send-email-mfojtik@redhat.com> References: <1294142776-15709-1-git-send-email-mfojtik@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 From: Michal Fojtik --- .../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