providers/virtualbox: internal networks [GH-2020]
This commit is contained in:
parent
35476328a0
commit
2d957cdaab
|
@ -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:
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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]])
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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]])
|
||||
|
|
|
@ -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
|
||||
```
|
||||
|
|
Loading…
Reference in New Issue