diff --git a/lib/fog/compute/libvirt.rb b/lib/fog/compute/libvirt.rb index 1a0e92ebe..323c3627c 100644 --- a/lib/fog/compute/libvirt.rb +++ b/lib/fog/compute/libvirt.rb @@ -30,18 +30,22 @@ module Fog attr_reader :connection attr_reader :uri - - - # f=Fog::Compute.new(:provider => "Libvirt", :libvirt_uri => "qemu+ssh://patrick.debois@juno/system") - + attr_reader :ip_command + + def initialize(options={}) @uri = ::Fog::Compute::LibvirtUtil::URI.new(enhance_uri(options[:libvirt_uri])) + @ip_command = options[:libvirt_ip_command] # libvirt is part of the gem => ruby-libvirt require 'libvirt' - - - @connection = ::Libvirt::open(@uri.uri) + + begin + @connection = ::Libvirt::open(@uri.uri) + rescue ::Libvirt::ConnectionError + raise Fog::Errors::Error.new("Error making a connection to libvirt URI #{@uri.uri}:\n#{$!}") + end + end def enhance_uri(uri) @@ -58,16 +62,16 @@ module Fog if querystring.nil? append="?socket=/var/run/libvirt/libvirt-sock" else - if !::CGI.parse(querystring).has_key?("socket") - append="&socket=/var/run/libvirt/libvirt-sock" - end + if !::CGI.parse(querystring).has_key?("socket") + append="&socket=/var/run/libvirt/libvirt-sock" + end end end newuri=uri+append return newuri end - - + + # hack to provide 'requests' def method_missing(method_sym, *arguments, &block) if @connection.respond_to?(method_sym) @@ -76,7 +80,7 @@ module Fog super end end - + end end end diff --git a/lib/fog/compute/models/libvirt/server.rb b/lib/fog/compute/models/libvirt/server.rb index 190c4c277..4f899c30a 100644 --- a/lib/fog/compute/models/libvirt/server.rb +++ b/lib/fog/compute/models/libvirt/server.rb @@ -247,9 +247,6 @@ module Fog raw.xml_desc end - ##Note this requires arpwatch to be running - ##and chmod o+x /var/lib/arpwatch - # This retrieves the ip address of the mac address # It returns an array of public and private ip addresses # Currently only one ip address is returned, but in the future this could be multiple @@ -259,7 +256,8 @@ module Fog mac=self.mac # Check if another ip_command string was provided - ip_command=options[:ip_command].nil? ? "grep #{mac} /var/log/arpwatch.log |cut -d ':' -f 4-| cut -d ' ' -f 4" : options[:ip_command] + ip_command_global=@connection.ip_command.nil? ? "grep #{mac} /var/log/arpwatch.log |cut -d ':' -f 4-| cut -d ' ' -f 4" : @connection.ip_command + ip_command=options[:ip_command].nil? ? ip_command_global : options[:ip_command] ip_address=nil