vagrant-port-range 0.1.2 → 0.1.3
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 +4 -4
- data/Gemfile +3 -3
- data/README.md +84 -1
- data/Rakefile +2 -0
- data/lib/vagrant-port-range.rb +15 -8
- data/lib/vagrant-port-range/{action.rb → action/port_range.rb} +7 -5
- data/lib/vagrant-port-range/config.rb +0 -2
- data/lib/vagrant-port-range/plugin.rb +16 -4
- data/lib/vagrant-port-range/version.rb +1 -1
- data/vagrant-port-range.gemspec +13 -4
- metadata +31 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fbb290ba667171dfe779bd0bd7c0256f8f86bbcc
|
4
|
+
data.tar.gz: 171cdf86d4169bf466fd15c043f226c9143ff566
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2ad740655459d9fc65c97b441a9e199c8c6b8a6d2d59b93b1f5b79d854d479718ac73da7f52dcb8130e67d727c7984d0ebc4f3a86683b6e174a784d25c44e7cc
|
7
|
+
data.tar.gz: d0144c2850a0af1608b7ad62efe12c198046914975df4c3bc39df5b737832c2160ad54f46f11a30abf6034b676337eec9460bb8c2ca187ac9b85ce57e1d5486f
|
data/Gemfile
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
source
|
1
|
+
source 'https://rubygems.org'
|
2
2
|
|
3
3
|
group :development do
|
4
|
-
gem
|
4
|
+
gem 'vagrant', git: 'https://github.com/mitchellh/vagrant.git'
|
5
5
|
end
|
6
6
|
|
7
7
|
group :plugins do
|
8
|
-
gem
|
8
|
+
gem 'vagrant-port-range', path: '.'
|
9
9
|
end
|
data/README.md
CHANGED
@@ -1,2 +1,85 @@
|
|
1
1
|
# vagrant-port-range
|
2
|
-
|
2
|
+
|
3
|
+
[](https://badge.fury.io/rb/vagrant-port-range)
|
4
|
+
|
5
|
+
vagrant-port-range is a Vagrant plugin for mapping forwarded ports using range of host ports.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
```console
|
10
|
+
foo@bar:~$ vagrant plugin install vagrant-port-range
|
11
|
+
```
|
12
|
+
|
13
|
+
## Usage
|
14
|
+
|
15
|
+
The plugin is loaded automatically once installed.
|
16
|
+
|
17
|
+
## Configuration
|
18
|
+
|
19
|
+
### config.portrange.forwarded_port
|
20
|
+
|
21
|
+
Use [standart options from forwarded_port](https://www.vagrantup.com/docs/networking/forwarded_ports.html), except for one option **host**. Instead of **host** use **host_range** with desired port range. Plugin will automatically pick free port from given range and insert it into **host** option.
|
22
|
+
|
23
|
+
Example Vagrantfile:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
# -*- mode: ruby -*-
|
27
|
+
# vi: set ft=ruby :
|
28
|
+
|
29
|
+
Vagrant.configure("2") do |config|
|
30
|
+
config.portrange.forwarded_port guest: 6901, host_range: [3000, 4100]
|
31
|
+
config.portrange.forwarded_port guest: 8080, host_range: [3000, 4100]
|
32
|
+
config.vm.provider "docker" do |d|
|
33
|
+
d.image = "consol/ubuntu-xfce-vnc"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
```
|
38
|
+
|
39
|
+
The result:
|
40
|
+
|
41
|
+
```console
|
42
|
+
foo@bar:~$ vagrant up
|
43
|
+
|
44
|
+
Bringing machine 'default' up with 'docker' provider...
|
45
|
+
==> default: [vagrant-port-range] get free port 4022
|
46
|
+
==> default: [vagrant-port-range] get free port 3744
|
47
|
+
==> default: Creating the container...
|
48
|
+
default: Name: vagrantportrange_default_1514061829
|
49
|
+
default: Image: consol/ubuntu-xfce-vnc
|
50
|
+
default: Port: 4022:6901
|
51
|
+
default: Port: 3744:8080
|
52
|
+
default:
|
53
|
+
default: Container created: b01667fcb339703a
|
54
|
+
==> default: Starting container...
|
55
|
+
|
56
|
+
foo@bar:~$
|
57
|
+
```
|
58
|
+
|
59
|
+
In case of situation when all ports from range are in use:
|
60
|
+
|
61
|
+
```ruby
|
62
|
+
# -*- mode: ruby -*-
|
63
|
+
# vi: set ft=ruby :
|
64
|
+
|
65
|
+
Vagrant.configure("2") do |config|
|
66
|
+
config.portrange.forwarded_port guest: 6901, host_range: [80, 81]
|
67
|
+
config.vm.provider "docker" do |d|
|
68
|
+
d.image = "consol/ubuntu-xfce-vnc"
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
```
|
73
|
+
|
74
|
+
```console
|
75
|
+
# make them busy
|
76
|
+
foo@bar:~$ python3 -m http.server 80
|
77
|
+
foo@bar:~$ python3 -m http.server 81
|
78
|
+
|
79
|
+
foo@bar:~$ vagrant up
|
80
|
+
|
81
|
+
Bringing machine 'default' up with 'docker' provider...
|
82
|
+
==> default: [vagrant-port-range] Can't get free port from range [80, 81]
|
83
|
+
|
84
|
+
foo@bar:~$
|
85
|
+
```
|
data/Rakefile
CHANGED
data/lib/vagrant-port-range.rb
CHANGED
@@ -1,9 +1,16 @@
|
|
1
|
-
|
2
|
-
require 'vagrant'
|
3
|
-
rescue LoadError
|
4
|
-
raise "This plugin must run within Vagrant."
|
5
|
-
end
|
6
|
-
|
7
|
-
require 'vagrant-port-range/action'
|
8
|
-
require 'vagrant-port-range/config'
|
1
|
+
require 'pathname'
|
9
2
|
require 'vagrant-port-range/plugin'
|
3
|
+
|
4
|
+
module VagrantPlugins
|
5
|
+
module PortRange
|
6
|
+
lib_path = Pathname.new(File.expand_path('../vagrant-port-range', __FILE__))
|
7
|
+
autoload :Action, lib_path.join('action')
|
8
|
+
|
9
|
+
# This returns the path to the source of this plugin
|
10
|
+
#
|
11
|
+
# @return [Pathname]
|
12
|
+
def self.source_root
|
13
|
+
@source_root ||= Pathname.new(File.expand_path('../../', __FILE__))
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -12,29 +12,31 @@ module VagrantPlugins
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def call(env)
|
15
|
-
|
15
|
+
setupped = true
|
16
16
|
|
17
17
|
# setup forwarded ports
|
18
18
|
forwarded_ports = @machine.config.portrange.forwarded_ports
|
19
19
|
forwarded_ports.each do |id, options|
|
20
20
|
# get free port and add to host
|
21
21
|
host_port = get_free_port(options[:host_range])
|
22
|
+
|
22
23
|
if host_port == -1
|
23
|
-
|
24
|
+
setupped = false
|
24
25
|
break
|
25
26
|
end
|
27
|
+
|
26
28
|
options[:host] = host_port
|
27
29
|
@ui.info("[vagrant-port-range] get free port #{host_port}")
|
28
30
|
|
29
31
|
# delete port range option
|
30
32
|
options.tap { |op| op.delete(:host_range) }
|
31
33
|
|
32
|
-
#
|
34
|
+
# standart way to add forwarded_port
|
33
35
|
@machine.config.vm.network "forwarded_port", options
|
34
36
|
end
|
35
37
|
|
36
|
-
# continue if all
|
37
|
-
if
|
38
|
+
# continue if all ports setupped
|
39
|
+
if setupped
|
38
40
|
@app.call(env)
|
39
41
|
end
|
40
42
|
end
|
@@ -1,8 +1,21 @@
|
|
1
|
+
begin
|
2
|
+
require 'vagrant'
|
3
|
+
rescue LoadError
|
4
|
+
raise 'This plugin must run within Vagrant.'
|
5
|
+
end
|
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
|
+
|
1
15
|
module VagrantPlugins
|
2
16
|
module PortRange
|
3
|
-
|
4
17
|
class Plugin < Vagrant.plugin('2')
|
5
|
-
name
|
18
|
+
name 'vagrant-port-range'
|
6
19
|
|
7
20
|
description <<-DESC
|
8
21
|
This plugin picks free port number from given range and inserts
|
@@ -10,7 +23,7 @@ module VagrantPlugins
|
|
10
23
|
DESC
|
11
24
|
|
12
25
|
config(:portrange) do
|
13
|
-
require_relative
|
26
|
+
require_relative 'config'
|
14
27
|
Config
|
15
28
|
end
|
16
29
|
|
@@ -18,6 +31,5 @@ module VagrantPlugins
|
|
18
31
|
hook.prepend(Action::SetupPorts)
|
19
32
|
end
|
20
33
|
end
|
21
|
-
|
22
34
|
end
|
23
35
|
end
|
data/vagrant-port-range.gemspec
CHANGED
@@ -1,16 +1,25 @@
|
|
1
|
-
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'vagrant-port-range/version'
|
2
4
|
|
3
5
|
Gem::Specification.new do |s|
|
4
6
|
s.name = 'vagrant-port-range'
|
5
7
|
s.version = VagrantPlugins::PortRange::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
6
9
|
s.date = '2017-12-01'
|
7
10
|
s.description = 'Vagrant plugin for mapping ports with given port range'
|
8
11
|
s.summary = s.description
|
12
|
+
s.homepage = 'https://github.com/pr3sto/vagrant-port-range'
|
13
|
+
s.license = 'MIT'
|
14
|
+
|
9
15
|
s.authors = ['Alexey Chirukhin']
|
10
16
|
s.email = 'pr3sto1377@gmail.com'
|
17
|
+
|
11
18
|
s.files = `git ls-files`.split($\)
|
12
19
|
s.executables = s.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
20
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
13
21
|
s.require_paths = ['lib']
|
14
|
-
|
15
|
-
s.
|
16
|
-
|
22
|
+
|
23
|
+
s.add_development_dependency 'rake'
|
24
|
+
s.add_development_dependency 'rspec'
|
25
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vagrant-port-range
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexey Chirukhin
|
@@ -9,7 +9,35 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
date: 2017-12-01 00:00:00.000000000 Z
|
12
|
-
dependencies:
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
13
41
|
description: Vagrant plugin for mapping ports with given port range
|
14
42
|
email: pr3sto1377@gmail.com
|
15
43
|
executables: []
|
@@ -22,7 +50,7 @@ files:
|
|
22
50
|
- README.md
|
23
51
|
- Rakefile
|
24
52
|
- lib/vagrant-port-range.rb
|
25
|
-
- lib/vagrant-port-range/action.rb
|
53
|
+
- lib/vagrant-port-range/action/port_range.rb
|
26
54
|
- lib/vagrant-port-range/config.rb
|
27
55
|
- lib/vagrant-port-range/plugin.rb
|
28
56
|
- lib/vagrant-port-range/version.rb
|