mirror of
https://github.com/vagrant-libvirt/vagrant-libvirt.git
synced 2025-02-25 18:55:27 -06:00
Add network debugging output
This commit is contained in:
parent
6ebb73e555
commit
c4d758b4e7
@ -37,6 +37,7 @@ module VagrantPlugins
|
|||||||
|
|
||||||
# Assign interfaces to slots.
|
# Assign interfaces to slots.
|
||||||
env[:machine].config.vm.networks.each do |type, options|
|
env[:machine].config.vm.networks.each do |type, options|
|
||||||
|
@logger.debug "In config found network type #{type} options #{options}"
|
||||||
|
|
||||||
# Get options for this interface. Options can be specified in
|
# Get options for this interface. Options can be specified in
|
||||||
# Vagrantfile in short format (:ip => ...), or provider format
|
# Vagrantfile in short format (:ip => ...), or provider format
|
||||||
@ -51,8 +52,10 @@ module VagrantPlugins
|
|||||||
end
|
end
|
||||||
|
|
||||||
free_slot = options[:adapter].to_i
|
free_slot = options[:adapter].to_i
|
||||||
|
@logger.debug "Using specified adapter slot #{free_slot}"
|
||||||
else
|
else
|
||||||
free_slot = find_empty(adapters)
|
free_slot = find_empty(adapters)
|
||||||
|
@logger.debug "Adapter not specified so found slot #{free_slot}"
|
||||||
raise Errors::InterfaceSlotNotAvailable if free_slot == nil
|
raise Errors::InterfaceSlotNotAvailable if free_slot == nil
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -104,6 +107,7 @@ module VagrantPlugins
|
|||||||
# it has to be available during provisioning - ifdown command is
|
# it has to be available during provisioning - ifdown command is
|
||||||
# not acceptable here.
|
# not acceptable here.
|
||||||
next if slot_number == 0
|
next if slot_number == 0
|
||||||
|
@logger.debug "Configuring interface slot_number #{slot_number} options #{options}"
|
||||||
|
|
||||||
network = {
|
network = {
|
||||||
:interface => slot_number,
|
:interface => slot_number,
|
||||||
@ -139,7 +143,10 @@ module VagrantPlugins
|
|||||||
|
|
||||||
# Return network name according to interface options.
|
# Return network name according to interface options.
|
||||||
def interface_network(libvirt_client, options)
|
def interface_network(libvirt_client, options)
|
||||||
return options[:network_name] if options[:network_name]
|
if options[:network_name]
|
||||||
|
@logger.debug "Found network by name"
|
||||||
|
return options[:network_name]
|
||||||
|
end
|
||||||
|
|
||||||
# Get list of all (active and inactive) libvirt networks.
|
# Get list of all (active and inactive) libvirt networks.
|
||||||
available_networks = libvirt_networks(libvirt_client)
|
available_networks = libvirt_networks(libvirt_client)
|
||||||
@ -147,11 +154,13 @@ module VagrantPlugins
|
|||||||
if options[:ip]
|
if options[:ip]
|
||||||
address = network_address(options[:ip], options[:netmask])
|
address = network_address(options[:ip], options[:netmask])
|
||||||
available_networks.each do |network|
|
available_networks.each do |network|
|
||||||
|
@logger.debug "Found network by ip"
|
||||||
return network[:name] if address == network[:network_address]
|
return network[:name] if address == network[:network_address]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# TODO Network default can be missing or named different.
|
# TODO Network default can be missing
|
||||||
|
@logger.debug "Did not find network so using default #{@default_network}"
|
||||||
return @default_network;
|
return @default_network;
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -28,6 +28,7 @@ module VagrantPlugins
|
|||||||
# Iterate over networks requested from config. If some network is not
|
# Iterate over networks requested from config. If some network is not
|
||||||
# available, create it if possible. Otherwise raise an error.
|
# available, create it if possible. Otherwise raise an error.
|
||||||
env[:machine].config.vm.networks.each do |type, options|
|
env[:machine].config.vm.networks.each do |type, options|
|
||||||
|
@logger.debug "In config found network type #{type} options #{options}"
|
||||||
|
|
||||||
# Get a list of all (active and inactive) libvirt networks. This
|
# Get a list of all (active and inactive) libvirt networks. This
|
||||||
# list is used throughout this class and should be easier to
|
# list is used throughout this class and should be easier to
|
||||||
@ -64,10 +65,13 @@ module VagrantPlugins
|
|||||||
}
|
}
|
||||||
|
|
||||||
if @options[:ip]
|
if @options[:ip]
|
||||||
|
@logger.debug "handle by ip"
|
||||||
handle_ip_option(env)
|
handle_ip_option(env)
|
||||||
elsif @options[:network_name]
|
elsif @options[:network_name]
|
||||||
|
@logger.debug "handle by name"
|
||||||
handle_network_name_option
|
handle_network_name_option
|
||||||
else
|
else
|
||||||
|
@logger.debug "neither ip nor name specified so finding default"
|
||||||
# TODO: Should be smarter than just using fixed 'default' string.
|
# TODO: Should be smarter than just using fixed 'default' string.
|
||||||
@interface_network = lookup_network_by_name('default')
|
@interface_network = lookup_network_by_name('default')
|
||||||
if !@interface_network
|
if !@interface_network
|
||||||
@ -87,6 +91,7 @@ module VagrantPlugins
|
|||||||
|
|
||||||
# Return hash of network for specified name, or nil if not found.
|
# Return hash of network for specified name, or nil if not found.
|
||||||
def lookup_network_by_name(network_name)
|
def lookup_network_by_name(network_name)
|
||||||
|
@logger.debug "looking up network named #{network_name}"
|
||||||
@available_networks.each do |network|
|
@available_networks.each do |network|
|
||||||
return network if network[:name] == network_name
|
return network if network[:name] == network_name
|
||||||
end
|
end
|
||||||
@ -95,6 +100,7 @@ module VagrantPlugins
|
|||||||
|
|
||||||
# Return hash of network for specified bridge, or nil if not found.
|
# Return hash of network for specified bridge, or nil if not found.
|
||||||
def lookup_bridge_by_name(bridge_name)
|
def lookup_bridge_by_name(bridge_name)
|
||||||
|
@logger.debug "looking up bridge named #{bridge_name}"
|
||||||
@available_networks.each do |network|
|
@available_networks.each do |network|
|
||||||
return network if network[:bridge_name] == bridge_name
|
return network if network[:bridge_name] == bridge_name
|
||||||
end
|
end
|
||||||
@ -120,11 +126,14 @@ module VagrantPlugins
|
|||||||
if available_network[:network_address] == \
|
if available_network[:network_address] == \
|
||||||
@interface_network[:network_address]
|
@interface_network[:network_address]
|
||||||
@interface_network = available_network
|
@interface_network = available_network
|
||||||
|
@logger.debug "found existing network by ip, values are"
|
||||||
|
@logger.debug @interface_network
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if @options[:network_name]
|
if @options[:network_name]
|
||||||
|
@logger.debug "Checking that network name does not clash with ip"
|
||||||
if @interface_network[:created]
|
if @interface_network[:created]
|
||||||
# Just check for mismatch error here - if name and ip from
|
# Just check for mismatch error here - if name and ip from
|
||||||
# config match together.
|
# config match together.
|
||||||
@ -156,6 +165,7 @@ module VagrantPlugins
|
|||||||
# Is name for new network set? If not, generate a unique one.
|
# Is name for new network set? If not, generate a unique one.
|
||||||
count = 0
|
count = 0
|
||||||
while @interface_network[:name].nil?
|
while @interface_network[:name].nil?
|
||||||
|
@logger.debug "generating name for network"
|
||||||
|
|
||||||
# Generate a network name.
|
# Generate a network name.
|
||||||
network_name = env[:root_path].basename.to_s.dup
|
network_name = env[:root_path].basename.to_s.dup
|
||||||
@ -171,6 +181,7 @@ module VagrantPlugins
|
|||||||
# Generate a unique name for network bridge.
|
# Generate a unique name for network bridge.
|
||||||
count = 0
|
count = 0
|
||||||
while @interface_network[:bridge_name].nil?
|
while @interface_network[:bridge_name].nil?
|
||||||
|
@logger.debug "generating name for bridge"
|
||||||
bridge_name = 'virbr'
|
bridge_name = 'virbr'
|
||||||
bridge_name << count.to_s
|
bridge_name << count.to_s
|
||||||
count += 1
|
count += 1
|
||||||
@ -234,6 +245,7 @@ module VagrantPlugins
|
|||||||
begin
|
begin
|
||||||
@interface_network[:libvirt_network] = \
|
@interface_network[:libvirt_network] = \
|
||||||
@libvirt_client.define_network_xml(to_xml('private_network'))
|
@libvirt_client.define_network_xml(to_xml('private_network'))
|
||||||
|
@logger.debug "created network"
|
||||||
rescue => e
|
rescue => e
|
||||||
raise Errors::CreateNetworkError, error_message: e.message
|
raise Errors::CreateNetworkError, error_message: e.message
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user