Merge pull request #853 from tmad/pci_network

Add option to specify PCI bus/slot for network interfaces
This commit is contained in:
Dmitry Vasilets 2018-02-02 17:49:19 +01:00 committed by GitHub
commit d9732b855f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 30 additions and 3 deletions

View File

@ -650,6 +650,8 @@ starts with `libvirt__` string. Here is a list of those options:
info](http://www.linux-kvm.org/page/Multiqueue) info](http://www.linux-kvm.org/page/Multiqueue)
* `:autostart` - Automatic startup of network by the libvirt daemon. * `:autostart` - Automatic startup of network by the libvirt daemon.
If not specified the default is 'false'. If not specified the default is 'false'.
* `:bus` - The bus of the PCI device. Both :bus and :slot have to be defined.
* `:slot` - The slot of the PCI device. Both :bus and :slot have to be defined.
When the option `:libvirt__dhcp_enabled` is to to 'false' it shouldn't matter When the option `:libvirt__dhcp_enabled` is to to 'false' it shouldn't matter
whether the virtual network contains a DHCP server or not and vagrant-libvirt whether the virtual network contains a DHCP server or not and vagrant-libvirt
@ -698,6 +700,8 @@ used by this network are configurable at the provider level.
for for more information. for for more information.
* `management_network_autostart` - Automatic startup of mgmt network, if not * `management_network_autostart` - Automatic startup of mgmt network, if not
specified the default is 'false'. specified the default is 'false'.
* `:management_network_pci_bus` - The bus of the PCI device.
* `:management_network_pci_slot` - The slot of the PCI device.
* `management_network_mac` - MAC address of management network interface. * `management_network_mac` - MAC address of management network interface.
You may wonder how vagrant-libvirt knows the IP address a VM received. Libvirt You may wonder how vagrant-libvirt knows the IP address a VM received. Libvirt

View File

@ -77,6 +77,8 @@ module VagrantPlugins
@driver_queues = iface_configuration.fetch(:driver_queues, false) @driver_queues = iface_configuration.fetch(:driver_queues, false)
@device_name = iface_configuration.fetch(:iface_name, false) @device_name = iface_configuration.fetch(:iface_name, false)
@mtu = iface_configuration.fetch(:mtu, nil) @mtu = iface_configuration.fetch(:mtu, nil)
@pci_bus = iface_configuration.fetch(:bus, nil)
@pci_slot = iface_configuration.fetch(:slot, nil)
template_name = 'interface' template_name = 'interface'
# Configuration for public interfaces which use the macvtap driver # Configuration for public interfaces which use the macvtap driver
if iface_configuration[:iface_type] == :public_network if iface_configuration[:iface_type] == :public_network
@ -146,7 +148,9 @@ module VagrantPlugins
@model_type, @model_type,
@mtu, @mtu,
driver_options, driver_options,
@udp_tunnel) @udp_tunnel,
@pci_bus,
@pci_slot)
else else
to_xml(template_name) to_xml(template_name)
end end
@ -237,7 +241,7 @@ module VagrantPlugins
def interface_xml(type, source_options, mac, device_name, def interface_xml(type, source_options, mac, device_name,
iface_number, model_type, mtu, driver_options, iface_number, model_type, mtu, driver_options,
udp_tunnel={}) udp_tunnel={}, pci_bus, pci_slot)
Nokogiri::XML::Builder.new do |xml| Nokogiri::XML::Builder.new do |xml|
xml.interface(type: type || 'network') do xml.interface(type: type || 'network') do
xml.source(source_options) do xml.source(source_options) do
@ -249,6 +253,7 @@ module VagrantPlugins
xml.model(type: model_type.to_s) xml.model(type: model_type.to_s)
xml.mtu(size: Integer(mtu)) if mtu xml.mtu(size: Integer(mtu)) if mtu
xml.driver(driver_options) xml.driver(driver_options)
xml.address(type: 'pci', bus: pci_bus, slot: pci_slot) if pci_bus and pci_slot
end end
end.to_xml( end.to_xml(
save_with: Nokogiri::XML::Node::SaveOptions::NO_DECLARATION | save_with: Nokogiri::XML::Node::SaveOptions::NO_DECLARATION |

View File

@ -51,6 +51,8 @@ module VagrantPlugins
attr_accessor :management_network_mac attr_accessor :management_network_mac
attr_accessor :management_network_guest_ipv6 attr_accessor :management_network_guest_ipv6
attr_accessor :management_network_autostart attr_accessor :management_network_autostart
attr_accessor :management_network_pci_bus
attr_accessor :management_network_pci_slot
# Default host prefix (alternative to use project folder name) # Default host prefix (alternative to use project folder name)
attr_accessor :default_prefix attr_accessor :default_prefix
@ -162,6 +164,8 @@ module VagrantPlugins
@management_network_mac = UNSET_VALUE @management_network_mac = UNSET_VALUE
@management_network_guest_ipv6 = UNSET_VALUE @management_network_guest_ipv6 = UNSET_VALUE
@management_network_autostart = UNSET_VALUE @management_network_autostart = UNSET_VALUE
@management_network_pci_slot = UNSET_VALUE
@management_network_pci_bus = UNSET_VALUE
# Domain specific settings. # Domain specific settings.
@uuid = UNSET_VALUE @uuid = UNSET_VALUE
@ -595,6 +599,8 @@ module VagrantPlugins
@management_network_mac = nil if @management_network_mac == UNSET_VALUE @management_network_mac = nil if @management_network_mac == UNSET_VALUE
@management_network_guest_ipv6 = 'yes' if @management_network_guest_ipv6 == UNSET_VALUE @management_network_guest_ipv6 = 'yes' if @management_network_guest_ipv6 == UNSET_VALUE
@management_network_autostart = false if @management_network_autostart == UNSET_VALUE @management_network_autostart = false if @management_network_autostart == UNSET_VALUE
@management_network_pci_bus = nil if @management_network_pci_bus == UNSET_VALUE
@management_network_pci_slot = nil if @management_network_pci_slot == UNSET_VALUE
# generate a URI if none is supplied # generate a URI if none is supplied
@uri = _generate_uri if @uri == UNSET_VALUE @uri = _generate_uri if @uri == UNSET_VALUE

View File

@ -20,4 +20,7 @@
<% if @ovs %> <% if @ovs %>
<virtualport type='openvswitch'/> <virtualport type='openvswitch'/>
<% end %> <% end %>
<% if @pci_bus and @pci_slot %>
<address type='pci' bus='<%=@pci_bus%>' slot='<%=@pci_slot%>' />
<% end %>
</interface> </interface>

View File

@ -14,6 +14,8 @@ module VagrantPlugins
management_network_mac = env[:machine].provider_config.management_network_mac management_network_mac = env[:machine].provider_config.management_network_mac
management_network_guest_ipv6 = env[:machine].provider_config.management_network_guest_ipv6 management_network_guest_ipv6 = env[:machine].provider_config.management_network_guest_ipv6
management_network_autostart = env[:machine].provider_config.management_network_autostart management_network_autostart = env[:machine].provider_config.management_network_autostart
management_network_pci_bus = env[:machine].provider_config.management_network_pci_bus
management_network_pci_slot = env[:machine].provider_config.management_network_pci_slot
logger.info "Using #{management_network_name} at #{management_network_address} as the management network #{management_network_mode} is the mode" logger.info "Using #{management_network_name} at #{management_network_address} as the management network #{management_network_mode} is the mode"
begin begin
@ -39,13 +41,20 @@ module VagrantPlugins
dhcp_enabled: true, dhcp_enabled: true,
forward_mode: management_network_mode, forward_mode: management_network_mode,
guest_ipv6: management_network_guest_ipv6, guest_ipv6: management_network_guest_ipv6,
autostart: management_network_autostart autostart: management_network_autostart,
bus: management_network_pci_bus,
slot: management_network_pci_slot
} }
unless management_network_mac.nil? unless management_network_mac.nil?
management_network_options[:mac] = management_network_mac management_network_options[:mac] = management_network_mac
end end
unless management_network_pci_bus.nil? and management_network_pci_slot.nil?
management_network_options[:bus] = management_network_pci_bus
management_network_options[:slot] = management_network_pci_slot
end
if (env[:machine].config.vm.box && if (env[:machine].config.vm.box &&
!env[:machine].provider_config.mgmt_attach) !env[:machine].provider_config.mgmt_attach)
raise Errors::ManagementNetworkRequired raise Errors::ManagementNetworkRequired