Class: VagrantPlugins::Skytap::Model::ForwardedPort

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-skytap/model/forwarded_port.rb

Overview

This is based on code from the VirtualBox provider.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of ForwardedPort.



41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/vagrant-skytap/model/forwarded_port.rb', line 41

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)
  @guest_ip = options[:guest_ip] || nil
  @host_ip = options[:host_ip] || nil
  @protocol = options[:protocol] || "tcp"
end

Instance Attribute Details

#auto_correctBoolean (readonly)

If true, this port should be auto-corrected.

Returns:

  • (Boolean)


9
10
11
# File 'lib/vagrant-skytap/model/forwarded_port.rb', line 9

def auto_correct
  @auto_correct
end

#guest_ipString (readonly)

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

Returns:



24
25
26
# File 'lib/vagrant-skytap/model/forwarded_port.rb', line 24

def guest_ip
  @guest_ip
end

#guest_portInteger (readonly)

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

Returns:

  • (Integer)


29
30
31
# File 'lib/vagrant-skytap/model/forwarded_port.rb', line 29

def guest_port
  @guest_port
end

#host_ipString (readonly)

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

Returns:



34
35
36
# File 'lib/vagrant-skytap/model/forwarded_port.rb', line 34

def host_ip
  @host_ip
end

#host_portInteger (readonly)

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

Returns:

  • (Integer)


39
40
41
# File 'lib/vagrant-skytap/model/forwarded_port.rb', line 39

def host_port
  @host_port
end

#idString (readonly)

The unique ID for the forwarded port.

Returns:



14
15
16
# File 'lib/vagrant-skytap/model/forwarded_port.rb', line 14

def id
  @id
end

#protocolString (readonly)

The protocol to forward.

Returns:



19
20
21
# File 'lib/vagrant-skytap/model/forwarded_port.rb', line 19

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.

Parameters:

  • new_port (Integer)

    The new port



57
58
59
# File 'lib/vagrant-skytap/model/forwarded_port.rb', line 57

def correct_host_port(new_port)
  @host_port = new_port
end

#internal_ssh_port?Boolean

Returns true if this is the SSH port used internally by Vagrant.

Parameters:

  • (Boolean)

Returns:

  • (Boolean)


72
73
74
# File 'lib/vagrant-skytap/model/forwarded_port.rb', line 72

def internal_ssh_port?
  (guest_port == 22 && host_port == 2222) || id == "ssh"
end

#privileged_host_port?Boolean

Returns true if the host port is privileged.

Parameters:

  • (Boolean)

Returns:

  • (Boolean)


64
65
66
# File 'lib/vagrant-skytap/model/forwarded_port.rb', line 64

def privileged_host_port?
  host_port <= 1024
end