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

allow setting a default lease time for networks #1799

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/configuration.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,7 @@ starts with `libvirt__` string. Here is a list of those options:
address in range (after network name and gateway).
* `:libvirt__dhcp_stop` - Last address given out via DHCP. Default is last
possible address in range (before broadcast address).
* `:libvirt__dhcp_default_lease_time` - default DHCP lease time for addresses in the network
* `:libvirt__dhcp_bootp_file` - The file to be used for the boot image. Used
only when dhcp is enabled.
* `:libvirt__dhcp_bootp_server` - The server that runs the DHCP server. Used
Expand Down
1 change: 1 addition & 0 deletions lib/vagrant-libvirt/action/create_networks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ def create_private_network(env)
@network_dhcp_enabled = true
@network_dhcp_bootp_file = @options[:dhcp_bootp_file]
@network_dhcp_bootp_server = @options[:dhcp_bootp_server]
@network_dhcp_default_lease_time = @options[:dhcp_default_lease_time]
@network_range_start = start_address
@network_range_stop = stop_address
else
Expand Down
6 changes: 5 additions & 1 deletion lib/vagrant-libvirt/templates/private_network.xml.erb
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,18 @@
<% end %>
<% if @network_dhcp_enabled %>
<dhcp>
<range start="<%= @network_range_start %>" end="<%= @network_range_stop %>" />
<range start="<%= @network_range_start %>" end="<%= @network_range_stop %>">
<% if @network_dhcp_bootp_file %>
<% if @network_dhcp_bootp_server %>
<bootp file="<%= @network_dhcp_bootp_file %>" server="<%= @network_dhcp_bootp_server %>" />
<% else %>
<bootp file="<%= @network_dhcp_bootp_file %>" />
<% end %>
<% end %>
<% if @network_dhcp_default_lease_time %>
<lease expiry='@network_dhcp_default_lease_time' unit='hours'/>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the issue discussion, this looked like it should be inside the range tag, while here it is only inside the dhcp tag. Appears would need to change how the range tag is closed to add this.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for checking, nice catch! I addressed this by adding a closing </range> tag if @network_dhcp_default_lease_time is defined.

see 1aa7ed8

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it'll require changing the range tag as well to remove the trailing /> to prevent it being closed before this as well. Presumably this means the current bootp XML is ignored as well

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True. If my XML is not off, commit 4c25b52 should fix this...

<% end %>
</range>
</dhcp>
<% end %>
</ip>
Expand Down