Permalink
Browse files

[VBOX] Can now define host only networks in addition to NATs

  • Loading branch information...
mitchellh committed Dec 15, 2010
1 parent 5177672 commit 4c7b8f4e944050ee963cf38e93bdf4b552f61b82
Showing with 26 additions and 8 deletions.
  1. +2 −1 CHANGELOG.md
  2. +24 −7 lib/virtuoso/virtualbox/vm.rb
View
@@ -2,7 +2,8 @@
Hypervisor Changes:
- - VirtualBox: Implemented `VM#network` for NAT networking.
+ - VirtualBox: Implemented `VM#network` for NAT and host only
+ networking.
- VirtualBox: Headless support by setting option `:headless` to
a truthy value.
@@ -8,9 +8,13 @@ def initialize(*args)
end
def network(type, options=nil)
- raise Error::UnsupportedNetworkError if type != :nat
+ raise Error::UnsupportedNetworkError if ![:nat, :host_only].include?(type)
- @networks << { :type => :nat, :model => "82540EM" }.merge(options || {})
+ if type == :nat
+ @networks << { :type => :nat, :model => "82540EM" }.merge(options || {})
+ else
+ @networks << { :type => :host_only, :model => "82540EM", :network => "vboxnet0" }.merge(options || {})
+ end
end
def spec
@@ -26,11 +30,21 @@ def spec
# Networks
@networks.each do |network|
- nat = Libvirt::Spec::Device.get(:interface).new
- nat.type = :user
- nat.mac_address = network[:mac_address] if network[:mac_address]
- nat.model_type = network[:model]
- d.devices << nat
+ if network[:type] == :nat
+ # Configure the NAT device
+ nat = Libvirt::Spec::Device.get(:interface).new
+ nat.type = :user
+ nat.mac_address = network[:mac_address] if network[:mac_address]
+ nat.model_type = network[:model]
+ d.devices << nat
+ else
+ # Configure the host only network
+ net = Libvirt::Spec::Device.get(:interface).new
+ net.type = :network
+ net.model_type = network[:model]
+ net.source_network = network[:network]
+ d.devices << net
+ end
end
# If we're running headless, attach the RDP device
@@ -100,6 +114,9 @@ def reload
if network.type == :user
# NAT
network(:nat, :model => network.model_type, :mac_address => network.mac_address)
+ elsif network.type == :network
+ # Host only
+ network(:host_only, :model => network.model_type, :network => network.source_network)
end
end
end

0 comments on commit 4c7b8f4

Please sign in to comment.