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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9c3517827e5226f3b01631295d376b047a6ed6b5
4
- data.tar.gz: 57c6917b1d4d0101df31ea54be7e183f338e42e7
3
+ metadata.gz: fbb290ba667171dfe779bd0bd7c0256f8f86bbcc
4
+ data.tar.gz: 171cdf86d4169bf466fd15c043f226c9143ff566
5
5
  SHA512:
6
- metadata.gz: 174f5a6e386bfe4ba7348bfda448b3e6abdc2dc977a0d9be27f21a3d85d7f47c44bfa38551cea1ea8eef28237a84f44c9ffc8364e6aab3d315bcf7c795d96aba
7
- data.tar.gz: f7c9b305dc695337c6e74ce9bca383ef0f2735db26c6f6e80ad9800641b4d1c68d35277084dd7fe06ec40feb3557b1d559b5cd3d8eb52abc636acc8d81051922
6
+ metadata.gz: 2ad740655459d9fc65c97b441a9e199c8c6b8a6d2d59b93b1f5b79d854d479718ac73da7f52dcb8130e67d727c7984d0ebc4f3a86683b6e174a784d25c44e7cc
7
+ data.tar.gz: d0144c2850a0af1608b7ad62efe12c198046914975df4c3bc39df5b737832c2160ad54f46f11a30abf6034b676337eec9460bb8c2ca187ac9b85ce57e1d5486f
data/Gemfile CHANGED
@@ -1,9 +1,9 @@
1
- source "https://rubygems.org"
1
+ source 'https://rubygems.org'
2
2
 
3
3
  group :development do
4
- gem "vagrant", git: "https://github.com/mitchellh/vagrant.git"
4
+ gem 'vagrant', git: 'https://github.com/mitchellh/vagrant.git'
5
5
  end
6
6
 
7
7
  group :plugins do
8
- gem "vagrant-port-range", path: "."
8
+ gem 'vagrant-port-range', path: '.'
9
9
  end
data/README.md CHANGED
@@ -1,2 +1,85 @@
1
1
  # vagrant-port-range
2
- Vagrant plugin for picking free port from given range
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/vagrant-port-range.svg)](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
@@ -1,3 +1,5 @@
1
1
  require 'rubygems'
2
2
  require 'bundler/setup'
3
+
4
+ # This installs the tasks that help with gem creation and publishing
3
5
  Bundler::GemHelper.install_tasks
@@ -1,9 +1,16 @@
1
- begin
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
- setuped = true
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
- setuped = false
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
- # add options in standart way
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 good
37
- if setuped
38
+ # continue if all ports setupped
39
+ if setupped
38
40
  @app.call(env)
39
41
  end
40
42
  end
@@ -2,7 +2,6 @@ require 'securerandom'
2
2
 
3
3
  module VagrantPlugins
4
4
  module PortRange
5
-
6
5
  class Config < Vagrant.plugin("2", :config)
7
6
  attr_reader :forwarded_ports
8
7
 
@@ -21,6 +20,5 @@ module VagrantPlugins
21
20
  forwarded_ports[id] = options
22
21
  end
23
22
  end
24
-
25
23
  end
26
24
  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 "vagrant-port-range"
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 "config"
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
@@ -1,5 +1,5 @@
1
1
  module VagrantPlugins
2
2
  module PortRange
3
- VERSION = '0.1.2'
3
+ VERSION = '0.1.3'
4
4
  end
5
5
  end
@@ -1,16 +1,25 @@
1
- require File.expand_path('../lib/vagrant-port-range/version', __FILE__)
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
- s.homepage = 'https://github.com/pr3sto/vagrant-port-range'
15
- s.license = 'MIT'
16
- end
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.2
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