providers/virtualbox: internal networks [GH-2020]

This commit is contained in:
Mitchell Hashimoto 2013-11-25 11:02:54 -08:00
parent 35476328a0
commit 2d957cdaab
6 changed files with 86 additions and 4 deletions

View File

@ -13,6 +13,7 @@ FEATURES:
- You can now specify a memory using `vb.memory` setting with VirtualBox. - You can now specify a memory using `vb.memory` setting with VirtualBox.
- Plugin developers can now hook into `environment_plugins_loaded`, which is - Plugin developers can now hook into `environment_plugins_loaded`, which is
executed after plugins are loaded but before Vagrantfiles are parsed. executed after plugins are loaded but before Vagrantfiles are parsed.
- VirtualBox internal networks are now supported. [GH-2020]
IMPROVEMENTS: IMPROVEMENTS:

View File

@ -54,14 +54,21 @@ module VagrantPlugins
slot = available_slots.shift slot = available_slots.shift
end end
# Internal network is a special type
if type == :private_network && options[:intnet]
type = :internal_network
end
# Configure it # Configure it
data = nil data = nil
if type == :private_network if type == :private_network
# private_network = hostonly # private_network = hostonly
data = [:hostonly, options] data = [:hostonly, options]
elsif type == :public_network elsif type == :public_network
# public_network = bridged # public_network = bridged
data = [:bridged, options] data = [:bridged, options]
elsif type == :internal_network
data = [:intnet, options]
end end
# Store it! # Store it!
@ -342,6 +349,36 @@ module VagrantPlugins
} }
end 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) def nat_config(options)
return { return {
:auto_config => false :auto_config => false

View File

@ -115,6 +115,11 @@ module VagrantPlugins
adapter[:hostonly]]) adapter[:hostonly]])
end end
if adapter[:intnet]
args.concat(["--intnet#{adapter[:adapter]}",
adapter[:intnet]])
end
if adapter[:mac_address] if adapter[:mac_address]
args.concat(["--macaddress#{adapter[:adapter]}", args.concat(["--macaddress#{adapter[:adapter]}",
adapter[:mac_address]]) adapter[:mac_address]])

View File

@ -113,6 +113,11 @@ module VagrantPlugins
adapter[:hostonly]]) adapter[:hostonly]])
end end
if adapter[:intnet]
args.concat(["--intnet#{adapter[:adapter]}",
adapter[:intnet]])
end
if adapter[:mac_address] if adapter[:mac_address]
args.concat(["--macaddress#{adapter[:adapter]}", args.concat(["--macaddress#{adapter[:adapter]}",
adapter[:mac_address]]) adapter[:mac_address]])

View File

@ -113,6 +113,11 @@ module VagrantPlugins
adapter[:hostonly]]) adapter[:hostonly]])
end end
if adapter[:intnet]
args.concat(["--intnet#{adapter[:adapter]}",
adapter[:intnet]])
end
if adapter[:mac_address] if adapter[:mac_address]
args.concat(["--macaddress#{adapter[:adapter]}", args.concat(["--macaddress#{adapter[:adapter]}",
adapter[:mac_address]]) adapter[:mac_address]])

View File

@ -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, 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 and most routers actually block traffic from going to them from the
outside world. 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
```