vagrant-port-range 0.1.2
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 +7 -0
- data/.gitignore +50 -0
- data/Gemfile +9 -0
- data/LICENSE +21 -0
- data/README.md +2 -0
- data/Rakefile +3 -0
- data/lib/vagrant-port-range.rb +9 -0
- data/lib/vagrant-port-range/action.rb +74 -0
- data/lib/vagrant-port-range/config.rb +26 -0
- data/lib/vagrant-port-range/plugin.rb +23 -0
- data/lib/vagrant-port-range/version.rb +5 -0
- data/vagrant-port-range.gemspec +16 -0
- metadata +54 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9c3517827e5226f3b01631295d376b047a6ed6b5
|
4
|
+
data.tar.gz: 57c6917b1d4d0101df31ea54be7e183f338e42e7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 174f5a6e386bfe4ba7348bfda448b3e6abdc2dc977a0d9be27f21a3d85d7f47c44bfa38551cea1ea8eef28237a84f44c9ffc8364e6aab3d315bcf7c795d96aba
|
7
|
+
data.tar.gz: f7c9b305dc695337c6e74ce9bca383ef0f2735db26c6f6e80ad9800641b4d1c68d35277084dd7fe06ec40feb3557b1d559b5cd3d8eb52abc636acc8d81051922
|
data/.gitignore
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/spec/examples.txt
|
9
|
+
/test/tmp/
|
10
|
+
/test/version_tmp/
|
11
|
+
/tmp/
|
12
|
+
|
13
|
+
# Used by dotenv library to load environment variables.
|
14
|
+
# .env
|
15
|
+
|
16
|
+
## Specific to RubyMotion:
|
17
|
+
.dat*
|
18
|
+
.repl_history
|
19
|
+
build/
|
20
|
+
*.bridgesupport
|
21
|
+
build-iPhoneOS/
|
22
|
+
build-iPhoneSimulator/
|
23
|
+
|
24
|
+
## Specific to RubyMotion (use of CocoaPods):
|
25
|
+
#
|
26
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
27
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
28
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
29
|
+
#
|
30
|
+
# vendor/Pods/
|
31
|
+
|
32
|
+
## Documentation cache and generated files:
|
33
|
+
/.yardoc/
|
34
|
+
/_yardoc/
|
35
|
+
/doc/
|
36
|
+
/rdoc/
|
37
|
+
|
38
|
+
## Environment normalization:
|
39
|
+
/.bundle/
|
40
|
+
/vendor/bundle
|
41
|
+
/lib/bundler/man/
|
42
|
+
|
43
|
+
# for a library or gem, you might want to ignore these files since the code is
|
44
|
+
# intended to run in multiple environments; otherwise, check them in:
|
45
|
+
Gemfile.lock
|
46
|
+
.ruby-version
|
47
|
+
.ruby-gemset
|
48
|
+
|
49
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
50
|
+
.rvmrc
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2017 Alexey Chirukhin
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'socket'
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module PortRange
|
5
|
+
module Action
|
6
|
+
|
7
|
+
class SetupPorts
|
8
|
+
def initialize(app, env)
|
9
|
+
@app = app
|
10
|
+
@machine = env[:machine]
|
11
|
+
@ui = env[:ui]
|
12
|
+
end
|
13
|
+
|
14
|
+
def call(env)
|
15
|
+
setuped = true
|
16
|
+
|
17
|
+
# setup forwarded ports
|
18
|
+
forwarded_ports = @machine.config.portrange.forwarded_ports
|
19
|
+
forwarded_ports.each do |id, options|
|
20
|
+
# get free port and add to host
|
21
|
+
host_port = get_free_port(options[:host_range])
|
22
|
+
if host_port == -1
|
23
|
+
setuped = false
|
24
|
+
break
|
25
|
+
end
|
26
|
+
options[:host] = host_port
|
27
|
+
@ui.info("[vagrant-port-range] get free port #{host_port}")
|
28
|
+
|
29
|
+
# delete port range option
|
30
|
+
options.tap { |op| op.delete(:host_range) }
|
31
|
+
|
32
|
+
# add options in standart way
|
33
|
+
@machine.config.vm.network "forwarded_port", options
|
34
|
+
end
|
35
|
+
|
36
|
+
# continue if all good
|
37
|
+
if setuped
|
38
|
+
@app.call(env)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def get_free_port(port_range)
|
43
|
+
min = port_range[0]
|
44
|
+
max = port_range[1]
|
45
|
+
|
46
|
+
if min >= max
|
47
|
+
@ui.error("[vagrant-port-range] Incorrect host_range option #{port_range.inspect}")
|
48
|
+
return -1
|
49
|
+
end
|
50
|
+
|
51
|
+
# number of attempts to find free port
|
52
|
+
attempts = 0
|
53
|
+
|
54
|
+
begin
|
55
|
+
attempts = attempts + 1
|
56
|
+
if attempts > 10
|
57
|
+
@ui.error "[vagrant-port-range] Can't get free port from range #{port_range.inspect}"
|
58
|
+
return -1
|
59
|
+
end
|
60
|
+
|
61
|
+
# try random port and return if succeed
|
62
|
+
try_port = rand(min..max)
|
63
|
+
server = TCPServer.new('127.0.0.1', try_port)
|
64
|
+
return try_port
|
65
|
+
rescue Errno::EADDRINUSE
|
66
|
+
retry
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'securerandom'
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module PortRange
|
5
|
+
|
6
|
+
class Config < Vagrant.plugin("2", :config)
|
7
|
+
attr_reader :forwarded_ports
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@forwarded_ports = {}
|
11
|
+
end
|
12
|
+
|
13
|
+
def forwarded_port(**options)
|
14
|
+
options = options.dup
|
15
|
+
|
16
|
+
if !options[:id]
|
17
|
+
options[:id] = "#{SecureRandom.uuid}"
|
18
|
+
end
|
19
|
+
|
20
|
+
id = options[:id]
|
21
|
+
forwarded_ports[id] = options
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module PortRange
|
3
|
+
|
4
|
+
class Plugin < Vagrant.plugin('2')
|
5
|
+
name "vagrant-port-range"
|
6
|
+
|
7
|
+
description <<-DESC
|
8
|
+
This plugin picks free port number from given range and inserts
|
9
|
+
it into host port in command config.vm.network "forwarded_port"
|
10
|
+
DESC
|
11
|
+
|
12
|
+
config(:portrange) do
|
13
|
+
require_relative "config"
|
14
|
+
Config
|
15
|
+
end
|
16
|
+
|
17
|
+
action_hook(:portrange, :machine_action_up) do |hook|
|
18
|
+
hook.prepend(Action::SetupPorts)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require File.expand_path('../lib/vagrant-port-range/version', __FILE__)
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = 'vagrant-port-range'
|
5
|
+
s.version = VagrantPlugins::PortRange::VERSION
|
6
|
+
s.date = '2017-12-01'
|
7
|
+
s.description = 'Vagrant plugin for mapping ports with given port range'
|
8
|
+
s.summary = s.description
|
9
|
+
s.authors = ['Alexey Chirukhin']
|
10
|
+
s.email = 'pr3sto1377@gmail.com'
|
11
|
+
s.files = `git ls-files`.split($\)
|
12
|
+
s.executables = s.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
s.require_paths = ['lib']
|
14
|
+
s.homepage = 'https://github.com/pr3sto/vagrant-port-range'
|
15
|
+
s.license = 'MIT'
|
16
|
+
end
|
metadata
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: vagrant-port-range
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alexey Chirukhin
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-12-01 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Vagrant plugin for mapping ports with given port range
|
14
|
+
email: pr3sto1377@gmail.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- ".gitignore"
|
20
|
+
- Gemfile
|
21
|
+
- LICENSE
|
22
|
+
- README.md
|
23
|
+
- Rakefile
|
24
|
+
- lib/vagrant-port-range.rb
|
25
|
+
- lib/vagrant-port-range/action.rb
|
26
|
+
- lib/vagrant-port-range/config.rb
|
27
|
+
- lib/vagrant-port-range/plugin.rb
|
28
|
+
- lib/vagrant-port-range/version.rb
|
29
|
+
- vagrant-port-range.gemspec
|
30
|
+
homepage: https://github.com/pr3sto/vagrant-port-range
|
31
|
+
licenses:
|
32
|
+
- MIT
|
33
|
+
metadata: {}
|
34
|
+
post_install_message:
|
35
|
+
rdoc_options: []
|
36
|
+
require_paths:
|
37
|
+
- lib
|
38
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
43
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
requirements: []
|
49
|
+
rubyforge_project:
|
50
|
+
rubygems_version: 2.6.14
|
51
|
+
signing_key:
|
52
|
+
specification_version: 4
|
53
|
+
summary: Vagrant plugin for mapping ports with given port range
|
54
|
+
test_files: []
|