mirror of
https://github.com/vagrant-libvirt/vagrant-libvirt.git
synced 2025-02-25 18:55:27 -06:00
amazing rubocop -a autofix
This commit is contained in:
parent
d6000307d6
commit
981ca18b5e
@ -12,7 +12,7 @@ module VagrantPlugins
|
|||||||
end
|
end
|
||||||
|
|
||||||
def _disk_name(name, disk)
|
def _disk_name(name, disk)
|
||||||
"#{name}-#{disk[:device]}.#{disk[:type]}" # disk name
|
"#{name}-#{disk[:device]}.#{disk[:type]}" # disk name
|
||||||
end
|
end
|
||||||
|
|
||||||
def _disks_print(disks)
|
def _disks_print(disks)
|
||||||
@ -55,10 +55,10 @@ module VagrantPlugins
|
|||||||
@graphics_autoport = config.graphics_autoport
|
@graphics_autoport = config.graphics_autoport
|
||||||
@graphics_port = config.graphics_port
|
@graphics_port = config.graphics_port
|
||||||
@graphics_ip = config.graphics_ip
|
@graphics_ip = config.graphics_ip
|
||||||
@graphics_passwd = if config.graphics_passwd.to_s.empty?
|
@graphics_passwd = if config.graphics_passwd.to_s.empty?
|
||||||
''
|
''
|
||||||
else
|
else
|
||||||
"passwd='#{config.graphics_passwd}'"
|
"passwd='#{config.graphics_passwd}'"
|
||||||
end
|
end
|
||||||
@video_type = config.video_type
|
@video_type = config.video_type
|
||||||
@video_vram = config.video_vram
|
@video_vram = config.video_vram
|
||||||
@ -88,13 +88,13 @@ module VagrantPlugins
|
|||||||
|
|
||||||
# USB device passthrough
|
# USB device passthrough
|
||||||
@usbs = config.usbs
|
@usbs = config.usbs
|
||||||
|
|
||||||
# Redirected devices
|
# Redirected devices
|
||||||
@redirdevs = config.redirdevs
|
@redirdevs = config.redirdevs
|
||||||
@redirfilters = config.redirfilters
|
@redirfilters = config.redirfilters
|
||||||
|
|
||||||
# RNG device passthrough
|
# RNG device passthrough
|
||||||
@rng =config.rng
|
@rng = config.rng
|
||||||
|
|
||||||
config = env[:machine].provider_config
|
config = env[:machine].provider_config
|
||||||
@domain_type = config.driver
|
@domain_type = config.driver
|
||||||
@ -108,7 +108,8 @@ module VagrantPlugins
|
|||||||
x.pool_name == @storage_pool_name
|
x.pool_name == @storage_pool_name
|
||||||
end
|
end
|
||||||
domain_volume = ProviderLibvirt::Util::Collection.find_matching(
|
domain_volume = ProviderLibvirt::Util::Collection.find_matching(
|
||||||
actual_volumes,"#{@name}.img")
|
actual_volumes, "#{@name}.img"
|
||||||
|
)
|
||||||
raise Errors::DomainVolumeExists if domain_volume.nil?
|
raise Errors::DomainVolumeExists if domain_volume.nil?
|
||||||
@domain_volume_path = domain_volume.path
|
@domain_volume_path = domain_volume.path
|
||||||
end
|
end
|
||||||
@ -117,12 +118,12 @@ module VagrantPlugins
|
|||||||
# If not, we dump the storage pool xml to get its defined path.
|
# If not, we dump the storage pool xml to get its defined path.
|
||||||
# the default storage prefix is typically: /var/lib/libvirt/images/
|
# the default storage prefix is typically: /var/lib/libvirt/images/
|
||||||
if env[:machine].config.vm.box
|
if env[:machine].config.vm.box
|
||||||
storage_prefix = File.dirname(@domain_volume_path) + '/' # steal
|
storage_prefix = File.dirname(@domain_volume_path) + '/' # steal
|
||||||
else
|
else
|
||||||
storage_pool = env[:machine].provider.driver.connection.client.lookup_storage_pool_by_name(@storage_pool_name)
|
storage_pool = env[:machine].provider.driver.connection.client.lookup_storage_pool_by_name(@storage_pool_name)
|
||||||
raise Errors::NoStoragePool if storage_pool.nil?
|
raise Errors::NoStoragePool if storage_pool.nil?
|
||||||
xml = Nokogiri::XML(storage_pool.xml_desc)
|
xml = Nokogiri::XML(storage_pool.xml_desc)
|
||||||
storage_prefix = xml.xpath("/pool/target/path").inner_text.to_s + '/'
|
storage_prefix = xml.xpath('/pool/target/path').inner_text.to_s + '/'
|
||||||
end
|
end
|
||||||
|
|
||||||
@disks.each do |disk|
|
@disks.each do |disk|
|
||||||
@ -148,10 +149,11 @@ module VagrantPlugins
|
|||||||
path: disk[:absolute_path],
|
path: disk[:absolute_path],
|
||||||
capacity: disk[:size],
|
capacity: disk[:size],
|
||||||
#:allocation => ?,
|
#:allocation => ?,
|
||||||
pool_name: @storage_pool_name)
|
pool_name: @storage_pool_name
|
||||||
|
)
|
||||||
rescue Fog::Errors::Error => e
|
rescue Fog::Errors::Error => e
|
||||||
raise Errors::FogDomainVolumeCreateError,
|
raise Errors::FogDomainVolumeCreateError,
|
||||||
error_message: e.message
|
error_message: e.message
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
disk[:preexisting] = true
|
disk[:preexisting] = true
|
||||||
@ -161,9 +163,7 @@ module VagrantPlugins
|
|||||||
# Output the settings we're going to use to the user
|
# Output the settings we're going to use to the user
|
||||||
env[:ui].info(I18n.t('vagrant_libvirt.creating_domain'))
|
env[:ui].info(I18n.t('vagrant_libvirt.creating_domain'))
|
||||||
env[:ui].info(" -- Name: #{@name}")
|
env[:ui].info(" -- Name: #{@name}")
|
||||||
if @uuid != ''
|
env[:ui].info(" -- Forced UUID: #{@uuid}") if @uuid != ''
|
||||||
env[:ui].info(" -- Forced UUID: #{@uuid}")
|
|
||||||
end
|
|
||||||
env[:ui].info(" -- Domain type: #{@domain_type}")
|
env[:ui].info(" -- Domain type: #{@domain_type}")
|
||||||
env[:ui].info(" -- Cpus: #{@cpus}")
|
env[:ui].info(" -- Cpus: #{@cpus}")
|
||||||
@cpu_features.each do |cpu_feature|
|
@cpu_features.each do |cpu_feature|
|
||||||
@ -193,7 +193,7 @@ module VagrantPlugins
|
|||||||
env[:ui].info(" -- Boot device: #{device}")
|
env[:ui].info(" -- Boot device: #{device}")
|
||||||
end
|
end
|
||||||
|
|
||||||
if @disks.length > 0
|
unless @disks.empty?
|
||||||
env[:ui].info(" -- Disks: #{_disks_print(@disks)}")
|
env[:ui].info(" -- Disks: #{_disks_print(@disks)}")
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -205,7 +205,7 @@ module VagrantPlugins
|
|||||||
env[:ui].info(msg)
|
env[:ui].info(msg)
|
||||||
end
|
end
|
||||||
|
|
||||||
if @cdroms.length > 0
|
unless @cdroms.empty?
|
||||||
env[:ui].info(" -- CDROMS: #{_cdroms_print(@cdroms)}")
|
env[:ui].info(" -- CDROMS: #{_cdroms_print(@cdroms)}")
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -226,7 +226,7 @@ module VagrantPlugins
|
|||||||
env[:ui].info(" -- PCI passthrough: #{pci[:bus]}:#{pci[:slot]}.#{pci[:function]}")
|
env[:ui].info(" -- PCI passthrough: #{pci[:bus]}:#{pci[:slot]}.#{pci[:function]}")
|
||||||
end
|
end
|
||||||
|
|
||||||
if !@rng[:model].nil?
|
unless @rng[:model].nil?
|
||||||
env[:ui].info(" -- RNG device model: #{@rng[:model]}")
|
env[:ui].info(" -- RNG device model: #{@rng[:model]}")
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -239,17 +239,16 @@ module VagrantPlugins
|
|||||||
env[:ui].info(" -- USB passthrough: #{usb_dev.join(', ')}")
|
env[:ui].info(" -- USB passthrough: #{usb_dev.join(', ')}")
|
||||||
end
|
end
|
||||||
|
|
||||||
if not @redirdevs.empty?
|
unless @redirdevs.empty?
|
||||||
env[:ui].info(" -- Redirected Devices: ")
|
env[:ui].info(' -- Redirected Devices: ')
|
||||||
@redirdevs.each do |redirdev|
|
@redirdevs.each do |redirdev|
|
||||||
msg = " -> bus=usb, type=#{redirdev[:type]}"
|
msg = " -> bus=usb, type=#{redirdev[:type]}"
|
||||||
env[:ui].info(msg)
|
env[:ui].info(msg)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
unless @redirfilters.empty?
|
||||||
if not @redirfilters.empty?
|
env[:ui].info(' -- USB Device filter for Redirected Devices: ')
|
||||||
env[:ui].info(" -- USB Device filter for Redirected Devices: ")
|
|
||||||
@redirfilters.each do |redirfilter|
|
@redirfilters.each do |redirfilter|
|
||||||
msg = " -> class=#{redirfilter[:class]}, "
|
msg = " -> class=#{redirfilter[:class]}, "
|
||||||
msg += "vendor=#{redirfilter[:vendor]}, "
|
msg += "vendor=#{redirfilter[:vendor]}, "
|
||||||
@ -260,7 +259,6 @@ module VagrantPlugins
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
env[:ui].info(" -- Command line : #{@cmd_line}")
|
env[:ui].info(" -- Command line : #{@cmd_line}")
|
||||||
|
|
||||||
# Create libvirt domain.
|
# Create libvirt domain.
|
||||||
@ -268,9 +266,10 @@ module VagrantPlugins
|
|||||||
# existing volume? Use domain creation from template..
|
# existing volume? Use domain creation from template..
|
||||||
begin
|
begin
|
||||||
server = env[:machine].provider.driver.connection.servers.create(
|
server = env[:machine].provider.driver.connection.servers.create(
|
||||||
xml: to_xml('domain'))
|
xml: to_xml('domain')
|
||||||
|
)
|
||||||
rescue Fog::Errors::Error => e
|
rescue Fog::Errors::Error => e
|
||||||
raise Errors::FogCreateServerError, error_message: e.message
|
raise Errors::FogCreateServerError, error_message: e.message
|
||||||
end
|
end
|
||||||
|
|
||||||
# Immediately save the ID since it is created at this point.
|
# Immediately save the ID since it is created at this point.
|
||||||
|
@ -3,20 +3,19 @@ require 'log4r'
|
|||||||
module VagrantPlugins
|
module VagrantPlugins
|
||||||
module ProviderLibvirt
|
module ProviderLibvirt
|
||||||
module Action
|
module Action
|
||||||
|
|
||||||
# Create a snapshot of base box image. This new snapshot is just new
|
# Create a snapshot of base box image. This new snapshot is just new
|
||||||
# cow image with backing storage pointing to base box image. Use this
|
# cow image with backing storage pointing to base box image. Use this
|
||||||
# image as new domain volume.
|
# image as new domain volume.
|
||||||
class CreateDomainVolume
|
class CreateDomainVolume
|
||||||
include VagrantPlugins::ProviderLibvirt::Util::ErbTemplate
|
include VagrantPlugins::ProviderLibvirt::Util::ErbTemplate
|
||||||
|
|
||||||
def initialize(app, env)
|
def initialize(app, _env)
|
||||||
@logger = Log4r::Logger.new("vagrant_libvirt::action::create_domain_volume")
|
@logger = Log4r::Logger.new('vagrant_libvirt::action::create_domain_volume')
|
||||||
@app = app
|
@app = app
|
||||||
end
|
end
|
||||||
|
|
||||||
def call(env)
|
def call(env)
|
||||||
env[:ui].info(I18n.t("vagrant_libvirt.creating_domain_volume"))
|
env[:ui].info(I18n.t('vagrant_libvirt.creating_domain_volume'))
|
||||||
|
|
||||||
# Get config options.
|
# Get config options.
|
||||||
config = env[:machine].provider_config
|
config = env[:machine].provider_config
|
||||||
@ -26,33 +25,34 @@ module VagrantPlugins
|
|||||||
|
|
||||||
# Verify the volume doesn't exist already.
|
# Verify the volume doesn't exist already.
|
||||||
domain_volume = ProviderLibvirt::Util::Collection.find_matching(
|
domain_volume = ProviderLibvirt::Util::Collection.find_matching(
|
||||||
env[:machine].provider.driver.connection.volumes.all, @name)
|
env[:machine].provider.driver.connection.volumes.all, @name
|
||||||
|
)
|
||||||
raise Errors::DomainVolumeExists if domain_volume
|
raise Errors::DomainVolumeExists if domain_volume
|
||||||
|
|
||||||
# Get path to backing image - box volume.
|
# Get path to backing image - box volume.
|
||||||
box_volume = ProviderLibvirt::Util::Collection.find_matching(
|
box_volume = ProviderLibvirt::Util::Collection.find_matching(
|
||||||
env[:machine].provider.driver.connection.volumes.all, env[:box_volume_name])
|
env[:machine].provider.driver.connection.volumes.all, env[:box_volume_name]
|
||||||
|
)
|
||||||
@backing_file = box_volume.path
|
@backing_file = box_volume.path
|
||||||
|
|
||||||
# Virtual size of image. Take value worked out by HandleBoxImage
|
# Virtual size of image. Take value worked out by HandleBoxImage
|
||||||
@capacity = env[:box_virtual_size] #G
|
@capacity = env[:box_virtual_size] # G
|
||||||
|
|
||||||
# Create new volume from xml template. Fog currently doesn't support
|
# Create new volume from xml template. Fog currently doesn't support
|
||||||
# volume snapshots directly.
|
# volume snapshots directly.
|
||||||
begin
|
begin
|
||||||
domain_volume = env[:machine].provider.driver.connection.volumes.create(
|
domain_volume = env[:machine].provider.driver.connection.volumes.create(
|
||||||
:xml => to_xml('volume_snapshot'),
|
xml: to_xml('volume_snapshot'),
|
||||||
:pool_name => config.storage_pool_name)
|
pool_name: config.storage_pool_name
|
||||||
|
)
|
||||||
rescue Fog::Errors::Error => e
|
rescue Fog::Errors::Error => e
|
||||||
raise Errors::FogDomainVolumeCreateError,
|
raise Errors::FogDomainVolumeCreateError,
|
||||||
:error_message => e.message
|
error_message: e.message
|
||||||
end
|
end
|
||||||
|
|
||||||
@app.call(env)
|
@app.call(env)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -5,7 +5,6 @@ require 'vagrant/util/scoped_hash_override'
|
|||||||
module VagrantPlugins
|
module VagrantPlugins
|
||||||
module ProviderLibvirt
|
module ProviderLibvirt
|
||||||
module Action
|
module Action
|
||||||
|
|
||||||
# Create network interfaces for domain, before domain is running.
|
# Create network interfaces for domain, before domain is running.
|
||||||
# Networks for connecting those interfaces should be already prepared.
|
# Networks for connecting those interfaces should be already prepared.
|
||||||
class CreateNetworkInterfaces
|
class CreateNetworkInterfaces
|
||||||
@ -27,10 +26,11 @@ module VagrantPlugins
|
|||||||
# Get domain first.
|
# Get domain first.
|
||||||
begin
|
begin
|
||||||
domain = env[:machine].provider.driver.connection.client.lookup_domain_by_uuid(
|
domain = env[:machine].provider.driver.connection.client.lookup_domain_by_uuid(
|
||||||
env[:machine].id.to_s)
|
env[:machine].id.to_s
|
||||||
|
)
|
||||||
rescue => e
|
rescue => e
|
||||||
raise Errors::NoDomainError,
|
raise Errors::NoDomainError,
|
||||||
:error_message => e.message
|
error_message: e.message
|
||||||
end
|
end
|
||||||
|
|
||||||
# Setup list of interfaces before creating them.
|
# Setup list of interfaces before creating them.
|
||||||
@ -39,11 +39,10 @@ module VagrantPlugins
|
|||||||
# Vagrant gives you adapter 0 by default
|
# Vagrant gives you adapter 0 by default
|
||||||
# Assign interfaces to slots.
|
# Assign interfaces to slots.
|
||||||
configured_networks(env, @logger).each do |options|
|
configured_networks(env, @logger).each do |options|
|
||||||
|
|
||||||
# dont need to create interface for this type
|
# dont need to create interface for this type
|
||||||
next if options[:iface_type] == :forwarded_port
|
next if options[:iface_type] == :forwarded_port
|
||||||
|
|
||||||
# TODO fill first ifaces with adapter option specified.
|
# TODO: fill first ifaces with adapter option specified.
|
||||||
if options[:adapter]
|
if options[:adapter]
|
||||||
if adapters[options[:adapter]]
|
if adapters[options[:adapter]]
|
||||||
raise Errors::InterfaceSlotNotAvailable
|
raise Errors::InterfaceSlotNotAvailable
|
||||||
@ -54,13 +53,14 @@ module VagrantPlugins
|
|||||||
else
|
else
|
||||||
free_slot = find_empty(adapters)
|
free_slot = find_empty(adapters)
|
||||||
@logger.debug "Adapter not specified so found slot #{free_slot}"
|
@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
|
||||||
|
|
||||||
# We have slot for interface, fill it with interface configuration.
|
# We have slot for interface, fill it with interface configuration.
|
||||||
adapters[free_slot] = options
|
adapters[free_slot] = options
|
||||||
adapters[free_slot][:network_name] = interface_network(
|
adapters[free_slot][:network_name] = interface_network(
|
||||||
env[:machine].provider.driver.connection.client, adapters[free_slot])
|
env[:machine].provider.driver.connection.client, adapters[free_slot]
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Create each interface as new domain device.
|
# Create each interface as new domain device.
|
||||||
@ -95,18 +95,17 @@ module VagrantPlugins
|
|||||||
end
|
end
|
||||||
# default mcast tunnel to 239.255.1.1. Web search says this
|
# default mcast tunnel to 239.255.1.1. Web search says this
|
||||||
# 239.255.x.x is a safe range to use for general use mcast
|
# 239.255.x.x is a safe range to use for general use mcast
|
||||||
if @type == 'mcast'
|
default_ip = if @type == 'mcast'
|
||||||
default_ip = '239.255.1.1'
|
'239.255.1.1'
|
||||||
else
|
else
|
||||||
default_ip = '127.0.0.1'
|
'127.0.0.1'
|
||||||
end
|
end
|
||||||
@tunnel_ip = iface_configuration.fetch(:tunnel_ip, default_ip)
|
@tunnel_ip = iface_configuration.fetch(:tunnel_ip, default_ip)
|
||||||
@model_type = iface_configuration.fetch(:model_type, @nic_model_type)
|
@model_type = iface_configuration.fetch(:model_type, @nic_model_type)
|
||||||
template_name = 'tunnel_interface'
|
template_name = 'tunnel_interface'
|
||||||
@logger.info("Setting up #{@type} tunnel interface using #{@tunnel_ip} port #{@tunnel_port}")
|
@logger.info("Setting up #{@type} tunnel interface using #{@tunnel_ip} port #{@tunnel_port}")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
message = "Creating network interface eth#{@iface_number}"
|
message = "Creating network interface eth#{@iface_number}"
|
||||||
message << " connected to network #{@network_name}."
|
message << " connected to network #{@network_name}."
|
||||||
if @mac
|
if @mac
|
||||||
@ -119,31 +118,29 @@ module VagrantPlugins
|
|||||||
domain.attach_device(to_xml(template_name))
|
domain.attach_device(to_xml(template_name))
|
||||||
rescue => e
|
rescue => e
|
||||||
raise Errors::AttachDeviceError,
|
raise Errors::AttachDeviceError,
|
||||||
:error_message => e.message
|
error_message: e.message
|
||||||
end
|
end
|
||||||
|
|
||||||
# Re-read the network configuration and grab the MAC address
|
# Re-read the network configuration and grab the MAC address
|
||||||
unless @mac
|
next if @mac
|
||||||
xml = Nokogiri::XML(domain.xml_desc)
|
xml = Nokogiri::XML(domain.xml_desc)
|
||||||
if iface_configuration[:iface_type] == :public_network
|
if iface_configuration[:iface_type] == :public_network
|
||||||
if @type == 'direct'
|
if @type == 'direct'
|
||||||
@mac = xml.xpath("/domain/devices/interface[source[@dev='#{@device}']]/mac/@address")
|
@mac = xml.xpath("/domain/devices/interface[source[@dev='#{@device}']]/mac/@address")
|
||||||
elsif !@portgroup.nil?
|
elsif !@portgroup.nil?
|
||||||
@mac = xml.xpath("/domain/devices/interface[source[@network='#{@network_name}']]/mac/@address")
|
|
||||||
else
|
|
||||||
@mac = xml.xpath("/domain/devices/interface[source[@bridge='#{@device}']]/mac/@address")
|
|
||||||
end
|
|
||||||
else
|
|
||||||
@mac = xml.xpath("/domain/devices/interface[source[@network='#{@network_name}']]/mac/@address")
|
@mac = xml.xpath("/domain/devices/interface[source[@network='#{@network_name}']]/mac/@address")
|
||||||
|
else
|
||||||
|
@mac = xml.xpath("/domain/devices/interface[source[@bridge='#{@device}']]/mac/@address")
|
||||||
end
|
end
|
||||||
iface_configuration[:mac] = @mac.to_s
|
else
|
||||||
|
@mac = xml.xpath("/domain/devices/interface[source[@network='#{@network_name}']]/mac/@address")
|
||||||
end
|
end
|
||||||
|
iface_configuration[:mac] = @mac.to_s
|
||||||
end
|
end
|
||||||
|
|
||||||
# Continue the middleware chain.
|
# Continue the middleware chain.
|
||||||
@app.call(env)
|
@app.call(env)
|
||||||
|
|
||||||
|
|
||||||
if env[:machine].config.vm.box
|
if env[:machine].config.vm.box
|
||||||
# Configure interfaces that user requested. Machine should be up and
|
# Configure interfaces that user requested. Machine should be up and
|
||||||
# running now.
|
# running now.
|
||||||
@ -158,17 +155,17 @@ module VagrantPlugins
|
|||||||
@logger.debug "Configuring interface slot_number #{slot_number} options #{options}"
|
@logger.debug "Configuring interface slot_number #{slot_number} options #{options}"
|
||||||
|
|
||||||
network = {
|
network = {
|
||||||
:interface => slot_number,
|
interface: slot_number,
|
||||||
:use_dhcp_assigned_default_route => options[:use_dhcp_assigned_default_route],
|
use_dhcp_assigned_default_route: options[:use_dhcp_assigned_default_route],
|
||||||
:mac_address => options[:mac],
|
mac_address: options[:mac]
|
||||||
}
|
}
|
||||||
|
|
||||||
if options[:ip]
|
if options[:ip]
|
||||||
network = {
|
network = {
|
||||||
:type => :static,
|
type: :static,
|
||||||
:ip => options[:ip],
|
ip: options[:ip],
|
||||||
:netmask => options[:netmask],
|
netmask: options[:netmask],
|
||||||
:gateway => options[:gateway],
|
gateway: options[:gateway]
|
||||||
}.merge(network)
|
}.merge(network)
|
||||||
else
|
else
|
||||||
network[:type] = :dhcp
|
network[:type] = :dhcp
|
||||||
@ -182,18 +179,19 @@ module VagrantPlugins
|
|||||||
|
|
||||||
env[:ui].info I18n.t('vagrant.actions.vm.network.configuring')
|
env[:ui].info I18n.t('vagrant.actions.vm.network.configuring')
|
||||||
env[:machine].guest.capability(
|
env[:machine].guest.capability(
|
||||||
:configure_networks, networks_to_configure)
|
:configure_networks, networks_to_configure
|
||||||
|
)
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def find_empty(array, start=0, stop=@nic_adapter_count)
|
def find_empty(array, start = 0, stop = @nic_adapter_count)
|
||||||
(start..stop).each do |i|
|
(start..stop).each do |i|
|
||||||
return i unless array[i]
|
return i unless array[i]
|
||||||
end
|
end
|
||||||
return nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
# Return network name according to interface options.
|
# Return network name according to interface options.
|
||||||
@ -202,7 +200,7 @@ module VagrantPlugins
|
|||||||
return 'tunnel_interface' if options.fetch(:tunnel_type, nil)
|
return 'tunnel_interface' if options.fetch(:tunnel_type, nil)
|
||||||
|
|
||||||
if options[:network_name]
|
if options[:network_name]
|
||||||
@logger.debug "Found network by name"
|
@logger.debug 'Found network by name'
|
||||||
return options[:network_name]
|
return options[:network_name]
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -215,7 +213,7 @@ module VagrantPlugins
|
|||||||
address = network_address(options[:ip], options[:netmask])
|
address = network_address(options[:ip], options[:netmask])
|
||||||
available_networks.each do |network|
|
available_networks.each do |network|
|
||||||
if address == network[:network_address]
|
if address == network[:network_address]
|
||||||
@logger.debug "Found network by ip"
|
@logger.debug 'Found network by ip'
|
||||||
return network[:name]
|
return network[:name]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -36,7 +36,7 @@ module VagrantPlugins
|
|||||||
configured_networks(env, @logger).each do |options|
|
configured_networks(env, @logger).each do |options|
|
||||||
# Only need to create private networks
|
# Only need to create private networks
|
||||||
next if options[:iface_type] != :private_network ||
|
next if options[:iface_type] != :private_network ||
|
||||||
options.fetch(:tunnel_type, nil)
|
options.fetch(:tunnel_type, nil)
|
||||||
@logger.debug "Searching for network with options #{options}"
|
@logger.debug "Searching for network with options #{options}"
|
||||||
|
|
||||||
# should fix other methods so this doesn't have to be instance var
|
# should fix other methods so this doesn't have to be instance var
|
||||||
@ -46,7 +46,8 @@ module VagrantPlugins
|
|||||||
# list is used throughout this class and should be easier to
|
# list is used throughout this class and should be easier to
|
||||||
# process than libvirt API calls.
|
# process than libvirt API calls.
|
||||||
@available_networks = libvirt_networks(
|
@available_networks = libvirt_networks(
|
||||||
env[:machine].provider.driver.connection.client)
|
env[:machine].provider.driver.connection.client
|
||||||
|
)
|
||||||
|
|
||||||
# Prepare a hash describing network for this specific interface.
|
# Prepare a hash describing network for this specific interface.
|
||||||
@interface_network = {
|
@interface_network = {
|
||||||
@ -129,24 +130,22 @@ module VagrantPlugins
|
|||||||
@interface_network[:network_address] = net_address
|
@interface_network[:network_address] = net_address
|
||||||
|
|
||||||
# if network is veryisolated, search by name
|
# if network is veryisolated, search by name
|
||||||
if @options[:libvirt__forward_mode] == "veryisolated"
|
network = if @options[:libvirt__forward_mode] == 'veryisolated'
|
||||||
network = lookup_network_by_name(@options[:network_name])
|
lookup_network_by_name(@options[:network_name])
|
||||||
elsif net_address
|
elsif net_address
|
||||||
# otherwise, search by ip (if set)
|
# otherwise, search by ip (if set)
|
||||||
network = lookup_network_by_ip(net_address)
|
lookup_network_by_ip(net_address)
|
||||||
else
|
else
|
||||||
# leaving this here to mimic prior behavior. If we get
|
# leaving this here to mimic prior behavior. If we get
|
||||||
# here, something's probably broken.
|
# here, something's probably broken.
|
||||||
network = lookup_network_by_name(@options[:network_name])
|
lookup_network_by_name(@options[:network_name])
|
||||||
end
|
end
|
||||||
@interface_network = network if network
|
@interface_network = network if network
|
||||||
|
|
||||||
if @interface_network[:created]
|
verify_dhcp if @interface_network[:created]
|
||||||
verify_dhcp
|
|
||||||
end
|
|
||||||
|
|
||||||
if @options[:network_name]
|
if @options[:network_name]
|
||||||
@logger.debug "Checking that network name does not clash with ip"
|
@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.
|
||||||
@ -178,7 +177,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"
|
@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
|
||||||
@ -205,12 +204,12 @@ module VagrantPlugins
|
|||||||
def handle_network_name_option(env)
|
def handle_network_name_option(env)
|
||||||
return if @options[:ip] || \
|
return if @options[:ip] || \
|
||||||
!@options[:network_name] || \
|
!@options[:network_name] || \
|
||||||
!@options[:libvirt__forward_mode] == "veryisolated"
|
!@options[:libvirt__forward_mode] == 'veryisolated'
|
||||||
|
|
||||||
network = lookup_network_by_name(@options[:network_name])
|
network = lookup_network_by_name(@options[:network_name])
|
||||||
@interface_network = network if network
|
@interface_network = network if network
|
||||||
|
|
||||||
if @options[:libvirt__forward_mode] == "veryisolated"
|
if @options[:libvirt__forward_mode] == 'veryisolated'
|
||||||
# if this interface has a network address, something's wrong.
|
# if this interface has a network address, something's wrong.
|
||||||
if @interface_network[:network_address]
|
if @interface_network[:network_address]
|
||||||
raise Errors::NetworkNotAvailableError,
|
raise Errors::NetworkNotAvailableError,
|
||||||
@ -266,7 +265,7 @@ module VagrantPlugins
|
|||||||
|
|
||||||
# Return the first available virbr interface name
|
# Return the first available virbr interface name
|
||||||
def generate_bridge_name
|
def generate_bridge_name
|
||||||
@logger.debug "generating name for bridge"
|
@logger.debug 'generating name for bridge'
|
||||||
count = 0
|
count = 0
|
||||||
while lookup_bridge_by_name(bridge_name = "virbr#{count}")
|
while lookup_bridge_by_name(bridge_name = "virbr#{count}")
|
||||||
count += 1
|
count += 1
|
||||||
@ -290,7 +289,7 @@ module VagrantPlugins
|
|||||||
if @options[:dhcp_enabled]
|
if @options[:dhcp_enabled]
|
||||||
# Find out DHCP addresses pool range.
|
# Find out DHCP addresses pool range.
|
||||||
network_address = "#{@interface_network[:network_address]}/"
|
network_address = "#{@interface_network[:network_address]}/"
|
||||||
network_address << "#{@interface_network[:netmask]}"
|
network_address << (@interface_network[:netmask]).to_s
|
||||||
net = @interface_network[:network_address] ? IPAddr.new(network_address) : nil
|
net = @interface_network[:network_address] ? IPAddr.new(network_address) : nil
|
||||||
|
|
||||||
# First is address of network, second is gateway (by default).
|
# First is address of network, second is gateway (by default).
|
||||||
@ -313,7 +312,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"
|
@logger.debug 'created network'
|
||||||
rescue => e
|
rescue => e
|
||||||
raise Errors::CreateNetworkError, error_message: e.message
|
raise Errors::CreateNetworkError, error_message: e.message
|
||||||
end
|
end
|
||||||
@ -332,21 +331,16 @@ module VagrantPlugins
|
|||||||
end
|
end
|
||||||
|
|
||||||
def autostart_network
|
def autostart_network
|
||||||
begin
|
@interface_network[:libvirt_network].autostart = true
|
||||||
@interface_network[:libvirt_network].autostart = true
|
rescue => e
|
||||||
rescue => e
|
raise Errors::AutostartNetworkError, error_message: e.message
|
||||||
raise Errors::AutostartNetworkError, error_message: e.message
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def activate_network
|
def activate_network
|
||||||
begin
|
@interface_network[:libvirt_network].create
|
||||||
@interface_network[:libvirt_network].create
|
rescue => e
|
||||||
rescue => e
|
raise Errors::ActivateNetworkError, error_message: e.message
|
||||||
raise Errors::ActivateNetworkError, error_message: e.message
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user