diff --git a/CHANGELOG.md b/CHANGELOG.md index dca3ec179..34f4b0cc2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ FEATURES: - You can now specify a memory using `vb.memory` setting with VirtualBox. - Plugin developers can now hook into `environment_plugins_loaded`, which is executed after plugins are loaded but before Vagrantfiles are parsed. + - VirtualBox internal networks are now supported. [GH-2020] IMPROVEMENTS: diff --git a/plugins/providers/virtualbox/action/network.rb b/plugins/providers/virtualbox/action/network.rb index e0bb95099..56ada7a06 100644 --- a/plugins/providers/virtualbox/action/network.rb +++ b/plugins/providers/virtualbox/action/network.rb @@ -54,14 +54,21 @@ module VagrantPlugins slot = available_slots.shift end + # Internal network is a special type + if type == :private_network && options[:intnet] + type = :internal_network + end + # Configure it data = nil if type == :private_network # private_network = hostonly - data = [:hostonly, options] + data = [:hostonly, options] elsif type == :public_network # public_network = bridged - data = [:bridged, options] + data = [:bridged, options] + elsif type == :internal_network + data = [:intnet, options] end # Store it! @@ -342,6 +349,36 @@ module VagrantPlugins } end + def intnet_config(options) + return { + :type => "static", + :ip => nil, + :netmask => "255.255.255.0", + :adapter => nil, + :mac => nil, + :intnet => nil, + :auto_config => true + }.merge(options || {}) + end + + def intnet_adapter(config) + return { + :adapter => config[:adapter], + :type => :intnet, + :mac_address => config[:mac], + :nic_type => config[:nic_type], + :intnet => config[:intnet] + } + end + + def intnet_network_config(config) + return { + :type => config[:type], + :ip => config[:ip], + :netmask => config[:netmask] + } + end + def nat_config(options) return { :auto_config => false diff --git a/plugins/providers/virtualbox/driver/version_4_1.rb b/plugins/providers/virtualbox/driver/version_4_1.rb index 1f80965d2..d724fb280 100644 --- a/plugins/providers/virtualbox/driver/version_4_1.rb +++ b/plugins/providers/virtualbox/driver/version_4_1.rb @@ -115,6 +115,11 @@ module VagrantPlugins adapter[:hostonly]]) end + if adapter[:intnet] + args.concat(["--intnet#{adapter[:adapter]}", + adapter[:intnet]]) + end + if adapter[:mac_address] args.concat(["--macaddress#{adapter[:adapter]}", adapter[:mac_address]]) diff --git a/plugins/providers/virtualbox/driver/version_4_2.rb b/plugins/providers/virtualbox/driver/version_4_2.rb index f572c0cd0..684c343fa 100644 --- a/plugins/providers/virtualbox/driver/version_4_2.rb +++ b/plugins/providers/virtualbox/driver/version_4_2.rb @@ -113,6 +113,11 @@ module VagrantPlugins adapter[:hostonly]]) end + if adapter[:intnet] + args.concat(["--intnet#{adapter[:adapter]}", + adapter[:intnet]]) + end + if adapter[:mac_address] args.concat(["--macaddress#{adapter[:adapter]}", adapter[:mac_address]]) @@ -162,12 +167,12 @@ module VagrantPlugins output = "" total = "" last = 0 - + output = execute("import", "-n", ovf) output =~ /Suggested VM name "(.+?)"/ suggested_name = $1.to_s specified_name = "#{suggested_name}_#{(Time.now.to_f * 1000.0).to_i}_#{rand(100000)}" #Millisecond + Random - + #Build the specified name param list name_params = Array.new name_params << "--vsys" << "0" << "--vmname" << specified_name diff --git a/plugins/providers/virtualbox/driver/version_4_3.rb b/plugins/providers/virtualbox/driver/version_4_3.rb index 1537856a1..c57f85231 100644 --- a/plugins/providers/virtualbox/driver/version_4_3.rb +++ b/plugins/providers/virtualbox/driver/version_4_3.rb @@ -113,6 +113,11 @@ module VagrantPlugins adapter[:hostonly]]) end + if adapter[:intnet] + args.concat(["--intnet#{adapter[:adapter]}", + adapter[:intnet]]) + end + if adapter[:mac_address] args.concat(["--macaddress#{adapter[:adapter]}", adapter[:mac_address]]) diff --git a/website/docs/source/v2/networking/private_network.html.md b/website/docs/source/v2/networking/private_network.html.md index 20153c69f..176f29338 100644 --- a/website/docs/source/v2/networking/private_network.html.md +++ b/website/docs/source/v2/networking/private_network.html.md @@ -46,3 +46,32 @@ While you can choose any IP you'd like, you _should_ use an IP from the [reserved private address space](http://en.wikipedia.org/wiki/Private_network#Private_IPv4_address_spaces). These IPs are guaranteed to never be publicly routable, and most routers actually block traffic from going to them from the outside world. + +## VirtualBox Internal Network + +The VirtualBox provider supports using the private network as a +VirtualBox [internal network](https://www.virtualbox.org/manual/ch06.html#network_internal). +By default, private networks are host-only networks, because those are the +easiest to work with. However, internal networks can be enabled as well. + +To speciay a private network as an internal network for VirtualBox +use the `virtualbox__intnet` option with the network. The `virtualbox__` +(double underscore) prefix tells Vagrant that this option is only for the +VirtualBox provider. + +```ruby +Vagrant.configure("2") do |config| + config.vm.network "private_network", ip: "192.168.50.4", + virtualbox__intnet: true +end +``` + +Additionally, if you want to specify that the VirtualBox provider join +a specific internal network, specify the name of the internal network: + +```ruby +Vagrant.configure("2") do |config| + config.vm.network "private_network", ip: "192.168.50.4", + virtualbox__intnet: "mynetwork" +end +```