Skip to content

Commit

Permalink
Make no assumptions on biosdevname/systemd device naming
Browse files Browse the repository at this point in the history
This hopefully covers all use cases regardless of the distro or device type
(virtio, e1000, rtl8139, passthrough).
  • Loading branch information
Mika Båtsman committed Jan 11, 2021
1 parent 1d870df commit 2298314
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,12 @@ Vagrant.configure("2") do |config|
:ovirt__network_name => 'ovirtmgmt' #DHCP
# Static configuration
#:ovirt__ip => '192.168.2.198', :ovirt__network_name => 'ovirtmgmt', :ovirt__gateway => '192.168.2.125', :ovirt__netmask => '255.255.0.0', :ovirt__dns_servers => '192.168.2.1', :ovirt__dns_search => 'test.local'
# Static configuration with biosdevname naming interfaces in format ensX, where X starts from 3
#:ovirt__ip => '192.168.2.198', :ovirt__network_name => 'ovirtmgmt', :ovirt__gateway => '192.168.2.125', :ovirt__netmask => '255.255.0.0', :ovirt__dns_servers => '192.168.2.1', :ovirt__dns_search => 'test.local', :ovirt__biosdevname => true
# Static configuration with biosdevname. Guest OS assigns interface names (ens3, em1 or something else). ovirt__interface_name has to match that name.
#:ovirt__ip => '192.168.2.198', :ovirt__network_name => 'ovirtmgmt', :ovirt__gateway => '192.168.2.125', :ovirt__netmask => '255.255.0.0', :ovirt__dns_servers => '192.168.2.1', :ovirt__dns_search => 'test.local', :ovirt__interface_name => 'ens3'
# configure additional interface
# config.vm.network :private_network,
# :ovirt__ip => '192.168.2.199', :ovirt__network_name => 'ovirtmgmt', :ovirt__netmask => '255.255.0.0', :ovirt__interface_name => 'ens4'
config.vm.provider :ovirt4 do |ovirt|
ovirt.url = 'https://server/ovirt-engine/api'
Expand Down
11 changes: 5 additions & 6 deletions lib/vagrant-ovirt4/action/start_vm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,15 @@ def call(env)
(0...configured_ifaces_options.length()).each do |iface_index|
iface_options = configured_ifaces_options[iface_index]

if iface_options[:biosdevname] then
prefix = 'ens'
iface_index = iface_index + 3
if iface_options[:interface_name] != nil then
iface_name = iface_options[:interface_name]
else
prefix = 'eth'
iface_name = "eth#{iface_index}"
end

if iface_options[:ip] then
nic_configuration = {
name: "#{prefix}#{iface_index}",
name: iface_name,
on_boot: true,
boot_protocol: OvirtSDK4::BootProtocol::STATIC,
ip: {
Expand All @@ -67,7 +66,7 @@ def call(env)
}
else
nic_configuration = {
name: "#{prefix}#{iface_index}",
name: iface_name,
on_boot: true,
boot_protocol: OvirtSDK4::BootProtocol::DHCP,
}
Expand Down

0 comments on commit 2298314

Please sign in to comment.