vagrant-port-range 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5ea234f007fbdd768c4d153ed0a384183d5c9dc1
|
4
|
+
data.tar.gz: 0eee4fa26cd279dd3976297cd2c8eece9f1c1f4b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5f72ed60d29cd2c577abd091d89adcce449a45d02e04b0daa94794731c0cef3c9e9a9d97610fc373cad47f4adc29e2d704edee76b60da400cdc632ddbedb51a7
|
7
|
+
data.tar.gz: '0328eebddead9d8a5fe67d514630e9de2c99b893738e24994f590d411828a9eb85cb61d6ee379fb1ce2e86cea43785f67941efa6a858e8d4a7282f9bee6b2292'
|
data/lib/vagrant-port-range.rb
CHANGED
@@ -4,11 +4,8 @@ require 'vagrant-port-range/plugin'
|
|
4
4
|
module VagrantPlugins
|
5
5
|
module PortRange
|
6
6
|
lib_path = Pathname.new(File.expand_path('../vagrant-port-range', __FILE__))
|
7
|
-
autoload :Action, lib_path.join('action')
|
8
7
|
|
9
|
-
#
|
10
|
-
#
|
11
|
-
# @return [Pathname]
|
8
|
+
# Returns the path to the source of this plugins
|
12
9
|
def self.source_root
|
13
10
|
@source_root ||= Pathname.new(File.expand_path('../../', __FILE__))
|
14
11
|
end
|
@@ -3,7 +3,6 @@ require 'socket'
|
|
3
3
|
module VagrantPlugins
|
4
4
|
module PortRange
|
5
5
|
module Action
|
6
|
-
|
7
6
|
class SetupPorts
|
8
7
|
def initialize(app, env)
|
9
8
|
@app = app
|
@@ -17,8 +16,19 @@ module VagrantPlugins
|
|
17
16
|
# setup forwarded ports
|
18
17
|
forwarded_ports = @machine.config.portrange.forwarded_ports
|
19
18
|
forwarded_ports.each do |id, options|
|
19
|
+
if !options[:host_range]
|
20
|
+
@ui.error "[vagrant-port-range] Range of host ports not specified ('host_range' option)"
|
21
|
+
setupped = false
|
22
|
+
break
|
23
|
+
end
|
24
|
+
if !options[:attempts]
|
25
|
+
@ui.error "[vagrant-port-range] Number of attempts not specified ('attempts' option)"
|
26
|
+
setupped = false
|
27
|
+
break
|
28
|
+
end
|
29
|
+
|
20
30
|
# get free port and add to host
|
21
|
-
host_port =
|
31
|
+
host_port = try_find_free_port(options[:host_range], options[:attempts])
|
22
32
|
|
23
33
|
if host_port == -1
|
24
34
|
setupped = false
|
@@ -26,10 +36,10 @@ module VagrantPlugins
|
|
26
36
|
end
|
27
37
|
|
28
38
|
options[:host] = host_port
|
29
|
-
@ui.info("[vagrant-port-range]
|
39
|
+
@ui.info("[vagrant-port-range] Free port found: #{host_port}")
|
30
40
|
|
31
|
-
# delete
|
32
|
-
options.tap { |op| op.delete(:host_range) }
|
41
|
+
# delete our options
|
42
|
+
options.tap { |op| op.delete(:host_range); op.delete(:attempts); op.delete(:id); }
|
33
43
|
|
34
44
|
# standart way to add forwarded_port
|
35
45
|
@machine.config.vm.network "forwarded_port", options
|
@@ -41,12 +51,19 @@ module VagrantPlugins
|
|
41
51
|
end
|
42
52
|
end
|
43
53
|
|
44
|
-
|
54
|
+
# Trys to find free port in specified range
|
55
|
+
# Params:
|
56
|
+
# port_range - range of ports (bounds included)
|
57
|
+
# max_attempts - maximum number of attempts to try
|
58
|
+
# Returns:
|
59
|
+
# [positive number] - free port
|
60
|
+
# -1 - maximum number of attempts ended unsuccessfully
|
61
|
+
def try_find_free_port(port_range, max_attempts)
|
45
62
|
min = port_range[0]
|
46
63
|
max = port_range[1]
|
47
64
|
|
48
65
|
if min >= max
|
49
|
-
@ui.error("[vagrant-port-range] Incorrect
|
66
|
+
@ui.error("[vagrant-port-range] Incorrect range of host ports #{port_range.inspect}")
|
50
67
|
return -1
|
51
68
|
end
|
52
69
|
|
@@ -55,8 +72,8 @@ module VagrantPlugins
|
|
55
72
|
|
56
73
|
begin
|
57
74
|
attempts = attempts + 1
|
58
|
-
if attempts >
|
59
|
-
@ui.error "[vagrant-port-range]
|
75
|
+
if attempts > max_attempts
|
76
|
+
@ui.error "[vagrant-port-range] Free port from range #{port_range.inspect} not found"
|
60
77
|
return -1
|
61
78
|
end
|
62
79
|
|
@@ -68,9 +85,7 @@ module VagrantPlugins
|
|
68
85
|
retry
|
69
86
|
end
|
70
87
|
end
|
71
|
-
|
72
88
|
end
|
73
|
-
|
74
89
|
end
|
75
90
|
end
|
76
91
|
end
|
@@ -4,14 +4,6 @@ rescue LoadError
|
|
4
4
|
raise 'This plugin must run within Vagrant.'
|
5
5
|
end
|
6
6
|
|
7
|
-
# This is a sanity check to make sure no one is attempting to install
|
8
|
-
# this into an early Vagrant version.
|
9
|
-
if Vagrant::VERSION < '1.2.0'
|
10
|
-
raise 'The vagrant-port-range plugin is only compatible with Vagrant 1.2+'
|
11
|
-
end
|
12
|
-
|
13
|
-
require_relative 'action/port_range'
|
14
|
-
|
15
7
|
module VagrantPlugins
|
16
8
|
module PortRange
|
17
9
|
class Plugin < Vagrant.plugin('2')
|
@@ -28,6 +20,7 @@ module VagrantPlugins
|
|
28
20
|
end
|
29
21
|
|
30
22
|
action_hook(:portrange, :machine_action_up) do |hook|
|
23
|
+
require_relative 'action/port_range'
|
31
24
|
hook.prepend(Action::SetupPorts)
|
32
25
|
end
|
33
26
|
end
|