Permalink
Browse files

GH-281 DHCP server for host-only networking; initial implementation

  • Loading branch information...
1 parent 535e722 commit d9571b1324b1c093c3ca6e975755406f56c360a5 Charles Duffy committed Jan 24, 2011
Showing with 19 additions and 3 deletions.
  1. +15 −2 lib/vagrant/action/vm/network.rb
  2. +2 −1 lib/vagrant/config/vm.rb
  3. +2 −0 templates/locales/en.yml
@@ -92,9 +92,22 @@ def network_name(net_options)
# One doesn't exist, create it.
@env.ui.info I18n.t("vagrant.actions.vm.network.creating")
+ host_ip = network_ip(net_options[:ip], net_options[:netmask])
+
ni = interfaces.create
- ni.enable_static(network_ip(net_options[:ip], net_options[:netmask]),
- net_options[:netmask])
+ ni.enable_static(host_ip, net_options[:netmask])
+
+ if net_options[:dhcp_range] != nil then
+ @env.ui.info I18n.t("vagrant.actions.vm.network.dhcp.creating")
+ dhcp_server = ni.dhcp_server
+ dhcp_server.network_mask = net_options[:netmask]
+ dhcp_server.lower_ip = net_options[:dhcp_range][0]
+ dhcp_server.upper_ip = net_options[:dhcp_range][1]
+ dhcp_server.ip_address = host_ip
+ dhcp_server.enabled = true
+ dhcp_server.save
+ end
+
ni.name
end
@@ -54,7 +54,8 @@ def network(ip, options=nil)
:ip => ip,
:netmask => "255.255.255.0",
:adapter => 1,
- :name => nil
+ :name => nil,
+ :dhcp_range => nil
}.merge(options || {})
@network_options[options[:adapter]] = options
@@ -339,6 +339,8 @@ en:
the IP or name of your host only network to not match that of
a bridged or non-hostonly network.
creating: "Creating new host only network for environment..."
+ dhcp:
+ creating: "Enabling DHCP server..."
enabling: "Enabling host only network..."
not_found: |-
The specified host network could not be found: '%{name}.'

0 comments on commit d9571b1

Please sign in to comment.