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 :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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue