vagrant-auto_network 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +3 -0
- data/README.markdown +61 -0
- data/lib/auto_network.rb +13 -0
- data/lib/auto_network/mixin.rb +15 -0
- data/lib/auto_network/pool.rb +39 -0
- data/lib/auto_network/version.rb +3 -0
- data/lib/vagrant-auto_network.rb +1 -0
- data/vagrant-auto_network.gemspec +20 -0
- metadata +69 -0
data/Gemfile
ADDED
data/README.markdown
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
Vagrant Auto-network
|
2
|
+
====================
|
3
|
+
|
4
|
+
Automatically configure Vagrant private network interfaces.
|
5
|
+
|
6
|
+
Summary
|
7
|
+
-------
|
8
|
+
|
9
|
+
Adding a private network address for vagrant machines generally requires
|
10
|
+
manually entering network interfaces and IP addresses for each machine, and
|
11
|
+
adding or removing machines means updating private network interfaces to make
|
12
|
+
sure that new machines don't collide. Alternately one can run a full blown DHCP
|
13
|
+
server but this is not necessarily portable and requires significant preparation
|
14
|
+
on top of Vagrant.
|
15
|
+
|
16
|
+
This plugin registers an internal address range and assigns unique IP addresses
|
17
|
+
for each successive request so that network configuration is entirely hands off.
|
18
|
+
It's much lighter than running a DNS server and masks the underlying work of
|
19
|
+
manually assigning addresses.
|
20
|
+
|
21
|
+
Usage
|
22
|
+
-----
|
23
|
+
|
24
|
+
Vagrant.configure('2') do |config|
|
25
|
+
config.vm.define 'first' do |node|
|
26
|
+
node.vm.box = "centos-5-i386"
|
27
|
+
|
28
|
+
node.vm.extend AutoNetwork::Mixin
|
29
|
+
node.vm.auto_network!
|
30
|
+
end
|
31
|
+
|
32
|
+
config.vm.define 'second' do |node|
|
33
|
+
node.vm.box = "centos-5-i386"
|
34
|
+
|
35
|
+
node.vm.extend AutoNetwork::Mixin
|
36
|
+
node.vm.auto_network!
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
Installation
|
41
|
+
------------
|
42
|
+
|
43
|
+
vagrant plugin install vagrant-auto_network
|
44
|
+
|
45
|
+
Caveats
|
46
|
+
-------
|
47
|
+
|
48
|
+
The default pool range has been hardcoded as '10.20.1.2/24', pending the
|
49
|
+
ability to query the host virtual network adapters for their configuration.
|
50
|
+
To change this, add the following _before_ the Vagrant configuration block:
|
51
|
+
|
52
|
+
AutoNetwork.default_pool = '172.16.0.0/12'
|
53
|
+
|
54
|
+
Contact
|
55
|
+
-------
|
56
|
+
|
57
|
+
* Source code: https://github.com/adrienthebo/vagrant-auto\_network
|
58
|
+
* Issue tracker: https://github.com/adrienthebo/vagrant-auto\_network/issues
|
59
|
+
|
60
|
+
If you have questions or concerns about this module, contact finch on Freenode,
|
61
|
+
or email adrien@puppetlabs.com.
|
data/lib/auto_network.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'auto_network/pool'
|
2
|
+
|
3
|
+
module AutoNetwork
|
4
|
+
|
5
|
+
# Extension to vagrant VM configuration to automatically configure an
|
6
|
+
# internal network.
|
7
|
+
module Mixin
|
8
|
+
|
9
|
+
def auto_network!
|
10
|
+
pool = AutoNetwork::Pool.instance
|
11
|
+
addr = pool.next
|
12
|
+
network :private_network, :ip => addr
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'auto_network'
|
2
|
+
|
3
|
+
require 'ipaddress'
|
4
|
+
|
5
|
+
module AutoNetwork
|
6
|
+
class Pool
|
7
|
+
|
8
|
+
class PoolExhaustedError < StandardError; end
|
9
|
+
|
10
|
+
# Provide a single instance of this class
|
11
|
+
#
|
12
|
+
# @return [AutoNetwork::Pool]
|
13
|
+
def self.instance
|
14
|
+
@myself ||= new
|
15
|
+
end
|
16
|
+
|
17
|
+
# @param addr [String] The network address range to use as the address pool.
|
18
|
+
# Defaults to `AutoNetwork.default_pool`
|
19
|
+
def initialize(addr = AutoNetwork.default_pool)
|
20
|
+
@addr = addr
|
21
|
+
@network = IPAddress.parse(addr)
|
22
|
+
|
23
|
+
@range = @network.hosts
|
24
|
+
# Drop the first IP address as it should be reserved for the host system
|
25
|
+
@range.shift
|
26
|
+
end
|
27
|
+
|
28
|
+
# @return [String] The string representation of the next available address
|
29
|
+
# @raise [PoolExhaustedError] There are no remaining addresses in the pool.
|
30
|
+
def next
|
31
|
+
if @range.empty?
|
32
|
+
raise PoolExhaustedError, "No addresses remaining in network address pool #{addr.inspect}"
|
33
|
+
end
|
34
|
+
|
35
|
+
addr = @range.shift
|
36
|
+
addr.address
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'auto_network'
|
@@ -0,0 +1,20 @@
|
|
1
|
+
lib = File.expand_path('../lib/', __FILE__)
|
2
|
+
$:.unshift lib unless $:.include?(lib)
|
3
|
+
|
4
|
+
require 'auto_network/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "vagrant-auto_network"
|
8
|
+
gem.version = AutoNetwork::VERSION
|
9
|
+
|
10
|
+
gem.authors = 'Adrien Thebo'
|
11
|
+
gem.email = 'adrien@somethingsinistral.net'
|
12
|
+
gem.homepage = 'https://github.com/adrienthebo/vagrant-auto_network'
|
13
|
+
|
14
|
+
gem.summary = "Automatically create an internal network for all vagrant boxes"
|
15
|
+
|
16
|
+
gem.add_dependency 'ipaddress'
|
17
|
+
|
18
|
+
gem.files = %x{git ls-files -z}.split("\0")
|
19
|
+
gem.require_path = 'lib'
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: vagrant-auto_network
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Adrien Thebo
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-07-07 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: ipaddress
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
description:
|
31
|
+
email: adrien@somethingsinistral.net
|
32
|
+
executables: []
|
33
|
+
extensions: []
|
34
|
+
extra_rdoc_files: []
|
35
|
+
files:
|
36
|
+
- Gemfile
|
37
|
+
- README.markdown
|
38
|
+
- lib/auto_network.rb
|
39
|
+
- lib/auto_network/mixin.rb
|
40
|
+
- lib/auto_network/pool.rb
|
41
|
+
- lib/auto_network/version.rb
|
42
|
+
- lib/vagrant-auto_network.rb
|
43
|
+
- vagrant-auto_network.gemspec
|
44
|
+
homepage: https://github.com/adrienthebo/vagrant-auto_network
|
45
|
+
licenses: []
|
46
|
+
post_install_message:
|
47
|
+
rdoc_options: []
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ! '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
requirements: []
|
63
|
+
rubyforge_project:
|
64
|
+
rubygems_version: 1.8.23
|
65
|
+
signing_key:
|
66
|
+
specification_version: 3
|
67
|
+
summary: Automatically create an internal network for all vagrant boxes
|
68
|
+
test_files: []
|
69
|
+
has_rdoc:
|