Class: Vagrant::Actions::VM::ForwardPorts
- Inherits:
-
Base
- Object
- Base
- Vagrant::Actions::VM::ForwardPorts
show all
- Defined in:
- lib/vagrant/actions/vm/forward_ports.rb
Instance Attribute Summary
Attributes inherited from Base
#runner
Instance Method Summary
collapse
Methods inherited from Base
#cleanup, #follows, #initialize, #precedes, #rescue
Methods included from Util
#error_and_exit, included, #logger, #wrap_output
Instance Method Details
#clear ⇒ Object
24
25
26
27
|
# File 'lib/vagrant/actions/vm/forward_ports.rb', line 24
def clear
logger.info "Deleting any previously set forwarded ports..."
@runner.vm.forwarded_ports.collect { |p| p.destroy(true) }
end
|
#execute! ⇒ Object
19
20
21
22
|
# File 'lib/vagrant/actions/vm/forward_ports.rb', line 19
def execute!
clear
forward_ports
end
|
#forward_ports ⇒ Object
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/vagrant/actions/vm/forward_ports.rb', line 29
def forward_ports
logger.info "Forwarding ports..."
@runner.env.config.vm.forwarded_ports.each do |name, options|
logger.info "Forwarding \"#{name}\": #{options[:guestport]} => #{options[:hostport]}"
port = VirtualBox::ForwardedPort.new
port.name = name
port.hostport = options[:hostport]
port.guestport = options[:guestport]
@runner.vm.forwarded_ports << port
end
@runner.vm.save(true)
end
|
#prepare ⇒ Object
5
6
7
8
9
10
11
12
13
14
15
16
17
|
# File 'lib/vagrant/actions/vm/forward_ports.rb', line 5
def prepare
VirtualBox::VM.all.each do |vm|
next if !vm.running? || vm.uuid == @runner.uuid
vm.forwarded_ports.each do |fp|
@runner.env.config.vm.forwarded_ports.each do |name, options|
if fp.hostport.to_s == options[:hostport].to_s
raise ActionException.new(:vm_port_collision, :name => name, :hostport => fp.hostport.to_s, :guestport => options[:guestport].to_s)
end
end
end
end
end
|