-
Notifications
You must be signed in to change notification settings - Fork 4.4k
/
forwarded_port.rb
70 lines (60 loc) · 1.96 KB
/
forwarded_port.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
module VagrantPlugins
module ProviderVirtualBox
module Model
# Represents a single forwarded port for VirtualBox. This has various
# helpers and defaults for a forwarded port.
class ForwardedPort
# The NAT adapter on which to attach the forwarded port.
#
# @return [Integer]
attr_reader :adapter
# If true, this port should be auto-corrected.
#
# @return [Boolean]
attr_reader :auto_correct
# The unique ID for the forwarded port.
#
# @return [String]
attr_reader :id
# The protocol to forward.
#
# @return [String]
attr_reader :protocol
# The IP that the forwarded port will connect to on the guest machine.
#
# @return [String]
attr_reader :guest_ip
# The port on the guest to be exposed on the host.
#
# @return [Integer]
attr_reader :guest_port
# The IP that the forwarded port will bind to on the host machine.
#
# @return [String]
attr_reader :host_ip
# The port on the host used to access the port on the guest.
#
# @return [Integer]
attr_reader :host_port
def initialize(id, host_port, guest_port, options)
@id = id
@guest_port = guest_port
@host_port = host_port
options ||= {}
@auto_correct = true
@auto_correct = options[:auto_correct] if options.has_key?(:auto_correct)
@adapter = (options[:adapter] || 1).to_i
@guest_ip = options[:guest_ip] || nil
@host_ip = options[:host_ip] || nil
@protocol = options[:protocol] || "tcp"
end
# This corrects the host port and changes it to the given new port.
#
# @param [Integer] new_port The new port
def correct_host_port(new_port)
@host_port = new_port
end
end
end
end
end