From: Michal Fojtik <mfoj...@redhat.com>
Signed-off-by: Michal fojtik <mfoj...@redhat.com> --- .../lib/deltacloud/drivers/rhevm/rhevm_client.rb | 46 ++++++++++++-------- .../lib/deltacloud/drivers/rhevm/rhevm_driver.rb | 40 +++++++++-------- 2 files changed, 49 insertions(+), 37 deletions(-) diff --git a/server/lib/deltacloud/drivers/rhevm/rhevm_client.rb b/server/lib/deltacloud/drivers/rhevm/rhevm_client.rb index c7b671b..d08d2cc 100644 --- a/server/lib/deltacloud/drivers/rhevm/rhevm_client.rb +++ b/server/lib/deltacloud/drivers/rhevm/rhevm_client.rb @@ -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 diff --git a/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb b/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb index 7ee953a..dfcc7ad 100644 --- a/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb +++ b/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb @@ -74,14 +74,12 @@ class RHEVMDriver < Deltacloud::BaseDriver # 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::BaseDriver 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::BaseDriver :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, -- 1.7.4.4