mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Added a global libvirt provider option ip_command to specify the ip_command
Also more robust handling of connection error when the libvirt connection fails
This commit is contained in:
parent
eab73a69e8
commit
24569955cb
2 changed files with 19 additions and 17 deletions
|
@ -30,18 +30,22 @@ module Fog
|
||||||
|
|
||||||
attr_reader :connection
|
attr_reader :connection
|
||||||
attr_reader :uri
|
attr_reader :uri
|
||||||
|
attr_reader :ip_command
|
||||||
|
|
||||||
|
|
||||||
# f=Fog::Compute.new(:provider => "Libvirt", :libvirt_uri => "qemu+ssh://patrick.debois@juno/system")
|
|
||||||
|
|
||||||
def initialize(options={})
|
def initialize(options={})
|
||||||
@uri = ::Fog::Compute::LibvirtUtil::URI.new(enhance_uri(options[:libvirt_uri]))
|
@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
|
# libvirt is part of the gem => ruby-libvirt
|
||||||
require 'libvirt'
|
require 'libvirt'
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
@connection = ::Libvirt::open(@uri.uri)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def enhance_uri(uri)
|
def enhance_uri(uri)
|
||||||
|
@ -58,9 +62,9 @@ module Fog
|
||||||
if querystring.nil?
|
if querystring.nil?
|
||||||
append="?socket=/var/run/libvirt/libvirt-sock"
|
append="?socket=/var/run/libvirt/libvirt-sock"
|
||||||
else
|
else
|
||||||
if !::CGI.parse(querystring).has_key?("socket")
|
if !::CGI.parse(querystring).has_key?("socket")
|
||||||
append="&socket=/var/run/libvirt/libvirt-sock"
|
append="&socket=/var/run/libvirt/libvirt-sock"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
newuri=uri+append
|
newuri=uri+append
|
||||||
|
|
|
@ -247,9 +247,6 @@ module Fog
|
||||||
raw.xml_desc
|
raw.xml_desc
|
||||||
end
|
end
|
||||||
|
|
||||||
##Note this requires arpwatch to be running
|
|
||||||
##and chmod o+x /var/lib/arpwatch
|
|
||||||
|
|
||||||
# This retrieves the ip address of the mac address
|
# This retrieves the ip address of the mac address
|
||||||
# It returns an array of public and private ip addresses
|
# 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
|
# Currently only one ip address is returned, but in the future this could be multiple
|
||||||
|
@ -259,7 +256,8 @@ module Fog
|
||||||
mac=self.mac
|
mac=self.mac
|
||||||
|
|
||||||
# Check if another ip_command string was provided
|
# 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
|
ip_address=nil
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue