From 5c950d820074c7a88a5e373e6e8aead2eeaea821 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 4 Jan 2013 15:48:54 -1000 Subject: [PATCH] Remove old `forward_port` method for configuration. Use `network` --- config/default.rb | 4 +++- plugins/kernel_v1/config/vm.rb | 2 +- plugins/kernel_v2/config/vm.rb | 26 +++++++++++++++----------- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/config/default.rb b/config/default.rb index 180e0fc76..4aea2ecea 100644 --- a/config/default.rb +++ b/config/default.rb @@ -14,9 +14,11 @@ Vagrant.configure("2") do |config| config.vm.auto_port_range = (2200..2250) config.vm.box_url = nil config.vm.base_mac = nil - config.vm.forward_port 22, 2222, :name => "ssh", :auto => true config.vm.guest = :linux + # Share SSH locally by default + config.vm.network :forwarded_port, 22, 2222, :id => "ssh", :auto => true + # Share the root folder. This can then be overridden by # other Vagrantfiles, if they wish. config.vm.share_folder("v-root", "/vagrant", ".") diff --git a/plugins/kernel_v1/config/vm.rb b/plugins/kernel_v1/config/vm.rb index fd641bcc0..96fc4e8a6 100644 --- a/plugins/kernel_v1/config/vm.rb +++ b/plugins/kernel_v1/config/vm.rb @@ -107,7 +107,7 @@ module VagrantPlugins guestport = options.delete(:guestport) hostport = options.delete(:hostport) - new.vm.forward_port(guestport, hostport, options) + new.vm.network(:forwarded_port, guestport, hostport, options) end # Re-define all networks. diff --git a/plugins/kernel_v2/config/vm.rb b/plugins/kernel_v2/config/vm.rb index 7178c3778..0b9ac53e0 100644 --- a/plugins/kernel_v2/config/vm.rb +++ b/plugins/kernel_v2/config/vm.rb @@ -45,17 +45,6 @@ module VagrantPlugins result end - def forward_port(guestport, hostport, options=nil) - @forwarded_ports << { - :name => "#{guestport.to_s(32)}-#{hostport.to_s(32)}", - :guestport => guestport, - :hostport => hostport, - :protocol => :tcp, - :adapter => 1, - :auto => false - }.merge(options || {}) - end - def share_folder(name, guestpath, hostpath, opts=nil) @shared_folders[name] = { :guestpath => guestpath.to_s, @@ -69,6 +58,21 @@ module VagrantPlugins }.merge(opts || {}) end + # Define a way to access the machine via a network. This exposes a + # high-level abstraction for networking that may not directly map + # 1-to-1 for every provider. For example, AWS has no equivalent to + # "port forwarding." But most providers will attempt to implement this + # in a way that behaves similarly. + # + # `type` can be one of: + # + # * `:forwarded_port` - A port that is accessible via localhost + # that forwards into the machine. + # * `:private_network` - The machine gets an IP that is not directly + # publicly accessible, but ideally accessible from this machine. + # * `:public_network` - The machine gets an IP on a shared network. + # + # @param [Symbol] type Type of network def network(type, *args) @networks << [type, args] end