Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vagrant + libvirt + named public network interface through dhcp fails #1774

Open
hoozemans opened this issue Sep 8, 2023 · 0 comments
Open

Comments

@hoozemans
Copy link

hoozemans commented Sep 8, 2023

vagrant 2.3.6
vagrant-libvirt 0.12.2

I've got this virtual network:

<network>
  <name>test-public-100</name>
  <forward mode="nat">
    <nat>
      <port start="1024" end="65535"/>
    </nat>
  </forward>
  <bridge name="virbr3" stp="on" delay="0"/>
  <mac address="52:54:00:64:eb:31"/>
  <domain name="test-public-100"/>
  <ip address="192.168.100.1" netmask="255.255.255.0">
    <dhcp>
      <range start="192.168.100.60" end="192.168.100.200"/>
    </dhcp>
  </ip>
</network>

This is my machine:

# -*- mode: ruby -*-
# vi: set ft=ruby :

VAGRANT_QEMU=ENV["VAGRANT_QEMU"] || 'qemu+ssh://[email protected]/system?keyfile=/home/nout/.ssh/[email protected]'
LIBVIRT_IMAGE			= "generic/ubuntu2204"
LIBVIRT_POOL			= "nas.fast-vdi"
CLUSTER_NAME			= "test"
NODES				= 1
CPUS				= 1
MEMORY				= 1024
DISKSIZE			= 128
PUBLIC_NETWORK			= "test-public-100"

Vagrant.configure("2") do |config|
	config.ssh.insert_key = false
	config.vm.provider "libvirt" do |provider, override|
		provider.uri = VAGRANT_QEMU
		provider.storage_pool_name = LIBVIRT_POOL
		provider.default_prefix = ''
		override.vm.box = LIBVIRT_IMAGE
	end
	(1..NODES).each do |i|
		config.vm.define "#{CLUSTER_NAME}-node-#{i}" do |node|
			NODE_NAME = "#{CLUSTER_NAME}-node-#{i}"
			node.vm.network :public_network, 
				:type => "network",
				:network_name => PUBLIC_NETWORK
			node.vm.hostname = NODE_NAME
			node.vm.synced_folder './', '/vagrant', disabled: false
			node.vm.provider "libvirt" do |provider, override|
				provider.machine_virtual_size = DISKSIZE
				provider.memory = MEMORY
				provider.cpus = CPUS
			end
		end
	end
end

I would expect this to produce two network interfaces: eth0 bound to the management network, in the 192.168.121.* range, and eth1 bound to the "test-public-100" network, with a DHCP configured ip address in the 192.168.2.100.* range.

Instead I get this:

Bringing machine 'test-node-1' up with 'libvirt' provider...
==> test-node-1: Checking if box 'generic/ubuntu2204' version '4.2.16' is up to date...
==> test-node-1: Created volume larger than box defaults, will require manual resizing of
==> test-node-1: filesystems to utilize.
==> test-node-1: Creating image (snapshot of base box volume).
==> test-node-1: Creating domain with the following settings...
==> test-node-1:  -- Name:              test-node-1
==> test-node-1:  -- Description:       Source: /home/nout/development/git/vm.hoozemans.nl.vagrant/vagrant/test/simpletest/Vagrantfile
==> test-node-1:  -- Domain type:       kvm
==> test-node-1:  -- Cpus:              1
==> test-node-1:  -- Feature:           acpi
==> test-node-1:  -- Feature:           apic
==> test-node-1:  -- Feature:           pae
==> test-node-1:  -- Clock offset:      utc
==> test-node-1:  -- Memory:            1024M
==> test-node-1:  -- Management MAC:    
==> test-node-1:  -- Loader:            
==> test-node-1:  -- Nvram:             
==> test-node-1:  -- Base box:          generic/ubuntu2204
==> test-node-1:  -- Storage pool:      nas.fast-vdi
==> test-node-1:  -- Image():     /mnt/nas.fast-vdi/test-node-1.img, 128G
==> test-node-1:  -- Disk driver opts:  cache='default'
==> test-node-1:  -- Kernel:            
==> test-node-1:  -- Initrd:            
==> test-node-1:  -- Graphics Type:     vnc
==> test-node-1:  -- Graphics Port:     -1
==> test-node-1:  -- Graphics IP:       127.0.0.1
==> test-node-1:  -- Graphics Password: Not defined
==> test-node-1:  -- Video Type:        cirrus
==> test-node-1:  -- Video VRAM:        256
==> test-node-1:  -- Video 3D accel:    false
==> test-node-1:  -- Sound Type:	
==> test-node-1:  -- Keymap:            en-us
==> test-node-1:  -- TPM Backend:       passthrough
==> test-node-1:  -- TPM Path:          
==> test-node-1:  -- INPUT:             type=mouse, bus=ps2
==> test-node-1: Creating shared folders metadata...
Error while attaching new device to domain. Call to virDomainAttachDeviceFlags failed: internal error: No <source> 'network' attribute specified with <interface type='network'/>

Complete output with --debug can be found here: https://pastebin.com/uLsk7Gzu

When I add the following two lines to /usr/share/rubygems-integration/all/gems/vagrant-libvirt-0.7.0/lib/vagrant-libvirt/templates/public_interface.xml.erb:

  <%if @type == 'direct'%>
  <source dev='<%= @device %>' mode='<%= @mode %>'/>
INSERT:
  <% elsif @type == 'network'  %>
  <source network='<%=@network_name%>' portgroup='<%=@portgroup%>'/>
/INSERT
  <% elsif [email protected]? %>
  <source network='<%=@network_name%>' portgroup='<%=@portgroup%>'/>
  <% else %>
  <source bridge='<%=@device%>'/>
  <% end %>

the domain comes up without a hitch and does exactly what I expect it to do:
$ vagrant ssh -- ip a s

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 52:54:00:1b:8a:5a brd ff:ff:ff:ff:ff:ff
    altname enp0s5
    altname ens5
    inet 192.168.121.160/24 metric 100 brd 192.168.121.255 scope global dynamic eth0
       valid_lft 3556sec preferred_lft 3556sec
    inet6 fe80::5054:ff:fe1b:8a5a/64 scope link 
       valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 52:54:00:fe:11:3d brd ff:ff:ff:ff:ff:ff
    altname enp0s6
    altname ens6
    inet 192.168.100.125/24 metric 100 brd 192.168.100.255 scope global dynamic eth1
       valid_lft 3559sec preferred_lft 3559sec
    inet6 fe80::5054:ff:fefe:113d/64 scope link 
       valid_lft forever preferred_lft forever

On different machines, there is no such folder, and an edit on /home/nout/.vagrant.d/gems/3.1.4/gems/vagrant-libvirt-0.12.2/lib/vagrant-libvirt/templates/public_interface.xml.erb does not produce the desired result.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant