vagrant-hosts 1.1.1 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +14 -0
- data/lib/vagrant-hosts.rb +3 -4
- data/lib/vagrant-hosts/config.rb +49 -45
- data/lib/vagrant-hosts/config_builder.rb +31 -0
- data/lib/vagrant-hosts/plugin.rb +4 -5
- data/lib/vagrant-hosts/provisioner.rb +6 -82
- data/lib/vagrant-hosts/provisioner/hostname.rb +13 -14
- data/lib/vagrant-hosts/provisioner/linux.rb +80 -0
- data/lib/vagrant-hosts/version.rb +1 -1
- data/templates/locales/en.yml +6 -0
- metadata +5 -2
data/CHANGELOG
CHANGED
@@ -1,6 +1,20 @@
|
|
1
1
|
CHANGELOG
|
2
2
|
=========
|
3
3
|
|
4
|
+
1.1.2
|
5
|
+
-----
|
6
|
+
|
7
|
+
2013-08-07
|
8
|
+
|
9
|
+
This is a backwards compatible bugfix release.
|
10
|
+
|
11
|
+
* GH-6 provisioner `autoconfigure` option works with explicit hosts
|
12
|
+
* GH-7 all host aliases are respected
|
13
|
+
* Autoconfigured entries should ensure private_networks have an IP address
|
14
|
+
* Remove hardcoded dependency on virtualbox vm provider
|
15
|
+
|
16
|
+
Thanks to Tom Linkin for his help on this release.
|
17
|
+
|
4
18
|
1.1.1
|
5
19
|
-----
|
6
20
|
|
data/lib/vagrant-hosts.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
|
-
# Declare top level vagrant hosts module.
|
2
1
|
module VagrantHosts
|
3
|
-
|
2
|
+
require 'vagrant-hosts/version'
|
3
|
+
require 'vagrant-hosts/plugin'
|
4
4
|
end
|
5
5
|
|
6
|
-
|
7
|
-
require 'vagrant-hosts/plugin'
|
6
|
+
I18n.load_path << File.expand_path('../templates/locales/en.yml', File.dirname(__FILE__))
|
data/lib/vagrant-hosts/config.rb
CHANGED
@@ -1,62 +1,66 @@
|
|
1
1
|
require 'vagrant'
|
2
2
|
|
3
3
|
module VagrantHosts
|
4
|
-
class Config < Vagrant.plugin('2', :config)
|
4
|
+
class Config < Vagrant.plugin('2', :config)
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
# @!attribute hosts
|
7
|
+
# @return [Array<Array<String, Array<String>>>] A list of IP addresses and their aliases
|
8
|
+
attr_reader :hosts
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
# @!attribute autoconfigure
|
11
|
+
# @return [TrueClass, FalseClass] If hosts should be generated from the
|
12
|
+
# other vagrant machines
|
13
|
+
attr_accessor :autoconfigure
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
# Register a host for entry
|
21
|
-
#
|
22
|
-
# @param [String] address The IP address for aliases
|
23
|
-
# @param [Array] aliases An array of hostnames to assign to the IP address
|
24
|
-
def add_host(address, aliases)
|
25
|
-
@hosts << [address, aliases]
|
26
|
-
end
|
15
|
+
def initialize
|
16
|
+
@hosts = []
|
17
|
+
@autoconfigure = UNSET_VALUE
|
18
|
+
end
|
27
19
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
add_host
|
33
|
-
|
34
|
-
|
35
|
-
end
|
20
|
+
# Register a host for entry
|
21
|
+
#
|
22
|
+
# @param [String] address The IP address for aliases
|
23
|
+
# @param [Array] aliases An array of hostnames to assign to the IP address
|
24
|
+
def add_host(address, aliases)
|
25
|
+
@hosts << [address, aliases]
|
26
|
+
end
|
36
27
|
|
37
|
-
|
38
|
-
|
39
|
-
|
28
|
+
# All IPv6 multicast addresses
|
29
|
+
def add_ipv6_multicast
|
30
|
+
add_host '::1', ['ip6-localhost', 'ip6-loopback']
|
31
|
+
add_host 'fe00::0', ['ip6-localnet']
|
32
|
+
add_host 'ff00::0', ['ip6-mcastprefix']
|
33
|
+
add_host 'ff02::1', ['ip6-allnodes']
|
34
|
+
add_host 'ff02::2', ['ip6-allrouters']
|
40
35
|
end
|
41
|
-
end
|
42
36
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
37
|
+
def finalize!
|
38
|
+
if @autoconfigure == UNSET_VALUE
|
39
|
+
if @hosts.empty?
|
40
|
+
@autoconfigure = true
|
41
|
+
else
|
42
|
+
@autoconfigure = false
|
43
|
+
end
|
44
|
+
end
|
48
45
|
end
|
49
|
-
end
|
50
46
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
47
|
+
# @param other [VagrantHosts::Config]
|
48
|
+
# @return [VagrantHosts::Config] The merged results
|
49
|
+
def merge(other)
|
50
|
+
super.tap do |result|
|
51
|
+
result.hosts += other.hosts
|
56
52
|
end
|
57
53
|
end
|
58
54
|
|
59
|
-
|
55
|
+
def validate(machine)
|
56
|
+
errors = []
|
57
|
+
@hosts.each do |(address, aliases)|
|
58
|
+
unless aliases.is_a? Array
|
59
|
+
errors << "#{address} should have an array of aliases, got #{aliases.inspect}:#{aliases.class}"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
{"Vagrant Hosts" => errors}
|
64
|
+
end
|
60
65
|
end
|
61
66
|
end
|
62
|
-
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'config_builder/model'
|
2
|
+
|
3
|
+
module VagrantHosts
|
4
|
+
module ConfigBuilder
|
5
|
+
class Model < ::ConfigBuilder::Model::Base
|
6
|
+
|
7
|
+
# @!attribute [rw] hosts
|
8
|
+
attr_accessor :hosts
|
9
|
+
# @!attribute [rw] autoconfigure
|
10
|
+
attr_accessor :autoconfigure
|
11
|
+
|
12
|
+
def initialize
|
13
|
+
@hosts = []
|
14
|
+
end
|
15
|
+
|
16
|
+
def to_proc
|
17
|
+
Proc.new do |vm_config|
|
18
|
+
vm_config.provision :hosts do |h_config|
|
19
|
+
h_config.autoconfigure = @autoconfigure if defined? @autoconfigure
|
20
|
+
|
21
|
+
@hosts.each do |(address, aliases)|
|
22
|
+
h_config.add_host address, aliases
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
::ConfigBuilder::ModelCollection.provisioner.register('hosts', self)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/vagrant-hosts/plugin.rb
CHANGED
@@ -2,11 +2,6 @@ require 'vagrant'
|
|
2
2
|
require 'vagrant-hosts'
|
3
3
|
require 'vagrant-hosts/version'
|
4
4
|
|
5
|
-
if Vagrant::VERSION < VagrantHosts::REQUIRED_VAGRANT_VERSION
|
6
|
-
raise "vagrant-hosts version #{VagrantHosts::VERSION} requires Vagrant " +
|
7
|
-
"#{VagrantHosts::REQUIRED_VAGRANT_VERSION} or later"
|
8
|
-
end
|
9
|
-
|
10
5
|
class VagrantHosts::Plugin < Vagrant.plugin(2)
|
11
6
|
name 'hosts'
|
12
7
|
|
@@ -24,4 +19,8 @@ class VagrantHosts::Plugin < Vagrant.plugin(2)
|
|
24
19
|
require_relative 'config'
|
25
20
|
VagrantHosts::Config
|
26
21
|
end
|
22
|
+
|
23
|
+
action_hook(:hosts, :config_builder_extension) do
|
24
|
+
require_relative 'config_builder'
|
25
|
+
end
|
27
26
|
end
|
@@ -2,95 +2,19 @@ require 'vagrant'
|
|
2
2
|
require 'tempfile'
|
3
3
|
|
4
4
|
module VagrantHosts
|
5
|
-
class Provisioner < Vagrant.plugin('2', :provisioner)
|
5
|
+
class Provisioner < Vagrant.plugin('2', :provisioner)
|
6
6
|
|
7
|
-
def initialize(machine, config)
|
8
|
-
@machine, @config = machine, config
|
9
|
-
end
|
10
|
-
|
11
|
-
def provision
|
12
|
-
# too tired to do this. detect target platform, select according provider,
|
13
|
-
# add entries that are specified in the config and are not on the client
|
14
|
-
|
15
|
-
driver = Linux.new(@machine, @config)
|
16
|
-
driver.sync!
|
17
|
-
end
|
18
|
-
|
19
|
-
class Linux
|
20
|
-
|
21
|
-
# This has to be inside of this class, because otherwise the hostname mixin
|
22
|
-
# will create this class with a different superclass. It makes me sad. :(
|
23
7
|
require 'vagrant-hosts/provisioner/hostname'
|
24
|
-
|
25
|
-
|
8
|
+
require 'vagrant-hosts/provisioner/linux'
|
26
9
|
|
27
10
|
def initialize(machine, config)
|
28
11
|
@machine, @config = machine, config
|
29
12
|
end
|
30
13
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
private
|
37
|
-
|
38
|
-
def upload_tmphosts
|
39
|
-
cache = Tempfile.new('tmp-hosts')
|
40
|
-
cache.write(format_hosts)
|
41
|
-
cache.flush
|
42
|
-
@machine.communicate.upload(cache.path, '/tmp/hosts')
|
43
|
-
end
|
44
|
-
|
45
|
-
def update_hosts
|
46
|
-
hostname = @machine.config.vm.hostname || @machine.name.to_s
|
47
|
-
change_host_name(hostname)
|
48
|
-
@machine.communicate.sudo('install -m 644 /tmp/hosts /etc/hosts')
|
49
|
-
end
|
50
|
-
|
51
|
-
# Generates content appropriate for a linux hosts file
|
52
|
-
#
|
53
|
-
# @return [String] All hosts in the config joined into hosts records
|
54
|
-
def format_hosts
|
55
|
-
all_hosts.inject('') do |str, (address, aliases)|
|
56
|
-
str << "#{address} #{aliases.join(' ')}\n"
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
def all_hosts
|
61
|
-
all_hosts = []
|
62
|
-
|
63
|
-
if @config.autoconfigure
|
64
|
-
all_hosts += vagrant_hosts
|
65
|
-
else
|
66
|
-
all_hosts += @config.hosts
|
67
|
-
end
|
68
|
-
|
69
|
-
all_hosts.unshift(['127.0.0.1', ['localhost']])
|
70
|
-
all_hosts.unshift(['127.0.1.1', [@machine.name]])
|
71
|
-
end
|
72
|
-
|
73
|
-
def vagrant_hosts
|
74
|
-
hosts = []
|
75
|
-
env = @machine.env
|
76
|
-
names = env.machine_names
|
77
|
-
|
78
|
-
# Assume that all VMs are using the current provider
|
79
|
-
provider = @machine.provider
|
80
|
-
|
81
|
-
names.each do |name|
|
82
|
-
network_settings = env.machine(name, :virtualbox).config.vm.networks
|
83
|
-
hostname = env.machine(name, :virtualbox).config.vm.hostname
|
84
|
-
network_settings.each do |entry|
|
85
|
-
if entry[0] == :private_network
|
86
|
-
ipaddr = entry[1][:ip]
|
87
|
-
hosts << [ipaddr, [hostname, name]]
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
hosts
|
14
|
+
# @todo use guest capabilities instead of hardcoded provisioner provider
|
15
|
+
def provision
|
16
|
+
driver = Linux.new(@machine, @config)
|
17
|
+
driver.sync!
|
93
18
|
end
|
94
19
|
end
|
95
20
|
end
|
96
|
-
end
|
@@ -1,15 +1,17 @@
|
|
1
1
|
require 'vagrant'
|
2
|
-
require 'vagrant
|
2
|
+
require 'vagrant/errors'
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
4
|
+
# Abstract the details of setting a guest hostname on different versions of
|
5
|
+
# Vagrant.
|
6
|
+
#
|
7
|
+
# Vagrant commit 61d2f9f96fc0f0ef5869c732674f25c4ccc85c8c converts the
|
8
|
+
# #change_host_name # method to a capability, which breaks the API between
|
9
|
+
# 1.1 and 1.2. :(
|
10
|
+
module VagrantHosts::Provisioner::Hostname
|
11
|
+
|
12
|
+
class UnknownVersion < Vagrant::Errors::VagrantError
|
13
|
+
error_key(:unknown_version, 'vagrant_hosts')
|
14
|
+
end
|
13
15
|
|
14
16
|
# @param name [String] The new hostname to apply on the guest
|
15
17
|
def change_host_name(name)
|
@@ -19,10 +21,7 @@ module Hostname
|
|
19
21
|
when /1\.2/
|
20
22
|
@machine.guest.capability(:change_host_name, name)
|
21
23
|
else
|
22
|
-
raise
|
24
|
+
raise UnknownVersion, :vagrant_version => Vagrant::VERSION
|
23
25
|
end
|
24
26
|
end
|
25
|
-
|
26
|
-
end
|
27
|
-
end
|
28
27
|
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
class VagrantHosts::Provisioner::Linux
|
2
|
+
|
3
|
+
include VagrantHosts::Provisioner::Hostname
|
4
|
+
|
5
|
+
def initialize(machine, config)
|
6
|
+
@machine, @config = machine, config
|
7
|
+
|
8
|
+
@env = @machine.env
|
9
|
+
end
|
10
|
+
|
11
|
+
def sync!
|
12
|
+
upload_tmphosts
|
13
|
+
update_hosts
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def upload_tmphosts
|
19
|
+
cache = Tempfile.new('tmp-hosts')
|
20
|
+
cache.write(format_hosts)
|
21
|
+
cache.flush
|
22
|
+
@machine.communicate.upload(cache.path, '/tmp/hosts')
|
23
|
+
end
|
24
|
+
|
25
|
+
def update_hosts
|
26
|
+
hostname = @machine.config.vm.hostname || @machine.name.to_s
|
27
|
+
change_host_name(hostname)
|
28
|
+
@machine.communicate.sudo('install -m 644 /tmp/hosts /etc/hosts')
|
29
|
+
end
|
30
|
+
|
31
|
+
# Generates content appropriate for a linux hosts file
|
32
|
+
#
|
33
|
+
# @return [String] All hosts in the config joined into hosts records
|
34
|
+
def format_hosts
|
35
|
+
all_hosts.inject('') do |str, (address, aliases)|
|
36
|
+
str << "#{address} #{aliases.join(' ')}\n"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def all_hosts
|
41
|
+
all_hosts = []
|
42
|
+
all_hosts += local_hosts
|
43
|
+
|
44
|
+
if @config.autoconfigure
|
45
|
+
all_hosts += vagrant_hosts
|
46
|
+
end
|
47
|
+
all_hosts += @config.hosts
|
48
|
+
|
49
|
+
all_hosts
|
50
|
+
end
|
51
|
+
|
52
|
+
def local_hosts
|
53
|
+
[
|
54
|
+
['127.0.0.1', ['localhost']],
|
55
|
+
['127.0.1.1', [@machine.name]],
|
56
|
+
]
|
57
|
+
end
|
58
|
+
|
59
|
+
def vagrant_hosts
|
60
|
+
hosts = []
|
61
|
+
|
62
|
+
all_machines.each do |m|
|
63
|
+
m_networks = m.config.vm.networks
|
64
|
+
m_hostname = m.config.vm.hostname
|
65
|
+
|
66
|
+
m_networks.each do |(net_type, opts)|
|
67
|
+
next unless net_types == :private_network
|
68
|
+
addr = opts[:ip]
|
69
|
+
hosts << [addr, [m_hostname, @machine.name]]
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
hosts
|
74
|
+
end
|
75
|
+
|
76
|
+
# @return [Array<Vagrant::Machine>]
|
77
|
+
def all_machines
|
78
|
+
@env.active_machines.map { |vm_id| @env.machine(*vm_id) }
|
79
|
+
end
|
80
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vagrant-hosts
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-08-08 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: ! ' Manage static DNS entries and configuration for Vagrant guests.
|
15
15
|
|
@@ -24,10 +24,13 @@ files:
|
|
24
24
|
- README.markdown
|
25
25
|
- lib/vagrant-hosts.rb
|
26
26
|
- lib/vagrant-hosts/config.rb
|
27
|
+
- lib/vagrant-hosts/config_builder.rb
|
27
28
|
- lib/vagrant-hosts/plugin.rb
|
28
29
|
- lib/vagrant-hosts/provisioner.rb
|
29
30
|
- lib/vagrant-hosts/provisioner/hostname.rb
|
31
|
+
- lib/vagrant-hosts/provisioner/linux.rb
|
30
32
|
- lib/vagrant-hosts/version.rb
|
33
|
+
- templates/locales/en.yml
|
31
34
|
- vagrant-hosts.gemspec
|
32
35
|
homepage: https://github.com/adrienthebo/vagrant-hosts
|
33
36
|
licenses:
|