1
0
Fork 0
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:
Patrick Debois 2011-08-09 07:22:35 -06:00
parent eab73a69e8
commit 24569955cb
2 changed files with 19 additions and 17 deletions

View file

@ -30,18 +30,22 @@ module Fog
attr_reader :connection
attr_reader :uri
attr_reader :ip_command
# f=Fog::Compute.new(:provider => "Libvirt", :libvirt_uri => "qemu+ssh://patrick.debois@juno/system")
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'
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)

View file

@ -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