Class: VagrantPlugins::Utm::Model::ForwardedPort

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant_utm/model/forwarded_port.rb

Overview

Represents a single forwarded port for UTM. This has various helpers and defaults for a forwarded port.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, host_port, guest_port, options) ⇒ ForwardedPort

Returns a new instance of ForwardedPort.



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/vagrant_utm/model/forwarded_port.rb', line 52

def initialize(id, host_port, guest_port, options)
  @id         = id
  @guest_port = guest_port
  @host_port  = host_port

  options ||= {}
  @auto_correct = false
  @auto_correct = options[:auto_correct] if options.key?(:auto_correct)
  # if adapter is not set, use index 1 (Emulated VLAN).
  # index 0 is the default adapter (Shared Network)
  @adapter  = (options[:adapter] || 1).to_i
  @guest_ip = options[:guest_ip] || nil
  @host_ip = options[:host_ip] || nil
  @protocol = options[:protocol] || "tcp" # default to TCP
end

Instance Attribute Details

#adapterInteger (readonly)

The ‘Emulated VLAN’ adapter on which to attach the forwarded port.

Returns:

  • (Integer)


15
16
17
# File 'lib/vagrant_utm/model/forwarded_port.rb', line 15

def adapter
  @adapter
end

#auto_correctBoolean (readonly)

If true, this port should be auto-corrected. TODO: This is not implemented yet.

Returns:

  • (Boolean)


20
21
22
# File 'lib/vagrant_utm/model/forwarded_port.rb', line 20

def auto_correct
  @auto_correct
end

#guest_ipString (readonly)

The IP that the forwarded port will connect to on the guest machine.

Returns:

  • (String)


35
36
37
# File 'lib/vagrant_utm/model/forwarded_port.rb', line 35

def guest_ip
  @guest_ip
end

#guest_portInteger (readonly)

The port on the guest to be exposed on the host.

Returns:

  • (Integer)


40
41
42
# File 'lib/vagrant_utm/model/forwarded_port.rb', line 40

def guest_port
  @guest_port
end

#host_ipString (readonly)

The IP that the forwarded port will bind to on the host machine.

Returns:

  • (String)


45
46
47
# File 'lib/vagrant_utm/model/forwarded_port.rb', line 45

def host_ip
  @host_ip
end

#host_portInteger (readonly)

The port on the host used to access the port on the guest.

Returns:

  • (Integer)


50
51
52
# File 'lib/vagrant_utm/model/forwarded_port.rb', line 50

def host_port
  @host_port
end

#idString (readonly)

The unique ID for the forwarded port.

Returns:

  • (String)


25
26
27
# File 'lib/vagrant_utm/model/forwarded_port.rb', line 25

def id
  @id
end

#protocolString (readonly)

The protocol to forward.

Returns:

  • (String)


30
31
32
# File 'lib/vagrant_utm/model/forwarded_port.rb', line 30

def protocol
  @protocol
end

Instance Method Details

#correct_host_port(new_port) ⇒ Object

This corrects the host port and changes it to the given new port. TODO: This is not implemented yet.

Parameters:

  • new_port (Integer)

    The new port



71
72
73
# File 'lib/vagrant_utm/model/forwarded_port.rb', line 71

def correct_host_port(new_port)
  @host_port = new_port
end