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

Can I set the DHCP lease time via vagrant-libvirt? #1792

Open
johanneskastl opened this issue Dec 10, 2023 · 2 comments
Open

Can I set the DHCP lease time via vagrant-libvirt? #1792

johanneskastl opened this issue Dec 10, 2023 · 2 comments

Comments

@johanneskastl
Copy link

Is your feature request related to a problem? Please describe.

TL;DR: Can I influence the DHCP leasetime for the network created by vagrant-libvirt?

When using vagrant-libvirt on e.g. a laptop, the VM's IP addresses might change if you put the laptop to sleep/suspend and wake it up again. Apparently, the DHCP lease time is only 1 hour, so after that the IPs might change.

In my case it is not possible to set static IPs, so I would like to increase the DHCP lease time to e.g. 24h or even 1 week.

Describe the solution you'd like
Apparently one can set lots of things on private networks, but not for the public network.
https://vagrant-libvirt.github.io/vagrant-libvirt/configuration.html#private-network-options
https://vagrant-libvirt.github.io/vagrant-libvirt/configuration.html#public-network-options

Although there are some DHCP-related options for private networks, there is nothing regarding the leasetime.

A sample Vagrantfile without the network options might look like this:

Vagrant.configure("2") do |config|

  # name the VMs
  config.vm.define "leap155" do |node|

    # which image to use
    node.vm.box = "opensuse/Leap-15.5.x86_64"

    # disable synced folders
    node.vm.synced_folder ".", "/vagrant", disabled: true

    # sizing of the VMs
    node.vm.provider "libvirt" do |lv|
      lv.random_hostname = false
      lv.memory = 2048
      lv.cpus = 2
    end

    # set the hostname
    node.vm.hostname = "leap155"

  end # config.vm.define nodes
end

This results in a new network vagrant-libvirt being created whose xml looks like this:

network ipv6='yes'>                                                                                                                                                                         
  <name>vagrant-libvirt</name>                                                                                                                                                               
  <uuid>34d7cbbd-4cf4-4c4f-b9f6-8524f9101fc1</uuid>                                                                                                                                          
  <forward mode='nat'/>                                                                                                                                                                      
  <bridge name='virbr3' stp='on' delay='0'/>                                                                                                                                                 
  <mac address='52:54:00:77:6b:c8'/>                                                                                                                                                         
  <ip address='192.168.121.1' netmask='255.255.255.0'>                                                                                                                                       
    <dhcp>                                                                                                                                                                                   
      <range start='192.168.121.1' end='192.168.121.254'/>                                                                                                                                   
    </dhcp>                                                                                                                                                                                  
  </ip>                                                                                                                                                                                      
</network>

All it would need is one line inside the <range> according to the libvirt documentation.

    <dhcp>
      <range start='192.168.121.1' end='192.168.121.254'/>
        <lease expiry='1' unit='hours'/>
      </range>
    </dhcp>
@abbbi
Copy link
Contributor

abbbi commented Jan 31, 2024

its currently not implemented. I think it would be pretty straight forward to implement, the closest thing is to look at the old "bootp" related commits for what has to be changed:

both the network generation code and the template must be adopted:

lib/vagrant-libvirt/action/create_networks.rb
lib/vagrant-libvirt/templates/private_network.xml.erb

commit 80f8c6b comes pretty close to this.

@johanneskastl
Copy link
Author

@abbbi I tried to come up with something similar, see #1799.

This will only influence explicitly created private networks, I guess (if this even works...)

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

No branches or pull requests

2 participants