Class: VagrantPlugins::AVF::PortAllocator
- Inherits:
-
Object
- Object
- VagrantPlugins::AVF::PortAllocator
- Defined in:
- lib/vagrant_provider_avf/port_allocator.rb
Constant Summary collapse
- DEFAULT_RANGE =
(2222..2299)
Instance Method Summary collapse
- #allocate(preferred_port: nil) ⇒ Object
-
#initialize(host: "127.0.0.1", port_range: DEFAULT_RANGE, server_class: TCPServer) ⇒ PortAllocator
constructor
A new instance of PortAllocator.
Constructor Details
#initialize(host: "127.0.0.1", port_range: DEFAULT_RANGE, server_class: TCPServer) ⇒ PortAllocator
Returns a new instance of PortAllocator.
8 9 10 11 12 |
# File 'lib/vagrant_provider_avf/port_allocator.rb', line 8 def initialize(host: "127.0.0.1", port_range: DEFAULT_RANGE, server_class: TCPServer) @host = host @port_range = port_range @server_class = server_class end |
Instance Method Details
#allocate(preferred_port: nil) ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/vagrant_provider_avf/port_allocator.rb', line 14 def allocate(preferred_port: nil) return preferred_port if preferred_port && available?(preferred_port) raise Errors::SshPortUnavailable, "SSH forwarding port #{preferred_port} is unavailable" if preferred_port @port_range.each do |port| return port if available?(port) end raise Errors::SshPortUnavailable, "no available SSH forwarding ports in #{@port_range.begin}-#{@port_range.end}" end |