vagrant-hosts 2.0.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +11 -0
- data/lib/vagrant-hosts/addresses.rb +59 -0
- data/lib/vagrant-hosts/cap/sync_hosts/base.rb +3 -53
- data/lib/vagrant-hosts/cap/sync_hosts/posix.rb +4 -1
- data/lib/vagrant-hosts/cap/sync_hosts/windows.rb +1 -1
- data/lib/vagrant-hosts/command.rb +42 -0
- data/lib/vagrant-hosts/command/helpers.rb +35 -0
- data/lib/vagrant-hosts/command/list.rb +42 -0
- data/lib/vagrant-hosts/command/puppetize.rb +42 -0
- data/lib/vagrant-hosts/plugin.rb +5 -0
- data/lib/vagrant-hosts/version.rb +1 -1
- metadata +7 -2
data/CHANGELOG
CHANGED
@@ -1,6 +1,17 @@
|
|
1
1
|
CHANGELOG
|
2
2
|
=========
|
3
3
|
|
4
|
+
2.1.0
|
5
|
+
-----
|
6
|
+
|
7
|
+
2013-11-13
|
8
|
+
|
9
|
+
This is a backwards compatible feature and bugfix release.
|
10
|
+
|
11
|
+
* (GH-19) Explicitly require 'tempfile' to define Tempfile constant
|
12
|
+
* (GH-18) Add `hosts` command to list machine addresses and generate Puppet
|
13
|
+
manifests to create host entries on the host machine.
|
14
|
+
|
4
15
|
2.0.0
|
5
16
|
-----
|
6
17
|
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module VagrantHosts::Addresses
|
2
|
+
|
3
|
+
private
|
4
|
+
|
5
|
+
def all_hosts(config)
|
6
|
+
|
7
|
+
all_hosts = []
|
8
|
+
all_hosts += local_hosts
|
9
|
+
|
10
|
+
if config.autoconfigure
|
11
|
+
all_hosts += vagrant_hosts
|
12
|
+
end
|
13
|
+
all_hosts += config.hosts
|
14
|
+
|
15
|
+
all_hosts
|
16
|
+
end
|
17
|
+
|
18
|
+
# Builds an array containing hostname and aliases for a given machine.
|
19
|
+
def hostnames_for_machine(machine)
|
20
|
+
# Cast any Symbols to Strings
|
21
|
+
machine_name = machine.name.to_s
|
22
|
+
hostname = machine.config.vm.hostname || machine_name
|
23
|
+
|
24
|
+
hostnames = [hostname]
|
25
|
+
# If the hostname is a fqdn, add the first component as an alias.
|
26
|
+
hostnames << hostname.split('.').first if hostname.index('.')
|
27
|
+
# Also add the machine name as an alias.
|
28
|
+
hostnames << machine_name unless hostnames.include? machine_name
|
29
|
+
|
30
|
+
hostnames
|
31
|
+
end
|
32
|
+
|
33
|
+
def local_hosts(machine)
|
34
|
+
[
|
35
|
+
['127.0.0.1', ['localhost']],
|
36
|
+
['127.0.1.1', hostnames_for_machine(machine)],
|
37
|
+
]
|
38
|
+
end
|
39
|
+
|
40
|
+
def vagrant_hosts(env)
|
41
|
+
hosts = []
|
42
|
+
|
43
|
+
all_machines(env).each do |m|
|
44
|
+
m.config.vm.networks.each do |(net_type, opts)|
|
45
|
+
next unless net_type == :private_network
|
46
|
+
addr = opts[:ip]
|
47
|
+
hosts << [addr, hostnames_for_machine(m)]
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
hosts
|
52
|
+
end
|
53
|
+
|
54
|
+
# @return [Array<Vagrant::Machine>]
|
55
|
+
def all_machines(env)
|
56
|
+
env.active_machines.map { |vm_id| env.machine(*vm_id) }
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
@@ -1,6 +1,9 @@
|
|
1
1
|
# Provide an abstract base class for syncing hosts entries
|
2
2
|
class VagrantHosts::Cap::SyncHosts::Base
|
3
3
|
|
4
|
+
require 'vagrant-hosts/addresses'
|
5
|
+
include VagrantHosts::Addresses
|
6
|
+
|
4
7
|
def self.sync_hosts(machine, config)
|
5
8
|
new(machine, config).sync!
|
6
9
|
end
|
@@ -32,57 +35,4 @@ class VagrantHosts::Cap::SyncHosts::Base
|
|
32
35
|
end
|
33
36
|
end
|
34
37
|
|
35
|
-
def all_hosts
|
36
|
-
all_hosts = []
|
37
|
-
all_hosts += local_hosts
|
38
|
-
|
39
|
-
if @config.autoconfigure
|
40
|
-
all_hosts += vagrant_hosts
|
41
|
-
end
|
42
|
-
all_hosts += @config.hosts
|
43
|
-
|
44
|
-
all_hosts
|
45
|
-
end
|
46
|
-
|
47
|
-
# Builds an array containing hostname and aliases for a given machine.
|
48
|
-
def hostnames_for_machine machine
|
49
|
-
# Cast any Symbols to Strings
|
50
|
-
machine_name = machine.name.to_s
|
51
|
-
hostname = machine.config.vm.hostname || machine_name
|
52
|
-
|
53
|
-
hostnames = [hostname]
|
54
|
-
# If the hostname is a fqdn, add the first component as an alias.
|
55
|
-
hostnames << hostname.split('.').first if hostname.index('.')
|
56
|
-
# Also add the machine name as an alias.
|
57
|
-
hostnames << machine_name unless hostnames.include? machine_name
|
58
|
-
|
59
|
-
hostnames
|
60
|
-
end
|
61
|
-
|
62
|
-
def local_hosts
|
63
|
-
[
|
64
|
-
['127.0.0.1', ['localhost']],
|
65
|
-
['127.0.1.1', hostnames_for_machine(@machine)],
|
66
|
-
]
|
67
|
-
end
|
68
|
-
|
69
|
-
def vagrant_hosts
|
70
|
-
hosts = []
|
71
|
-
|
72
|
-
all_machines.each do |m|
|
73
|
-
m.config.vm.networks.each do |(net_type, opts)|
|
74
|
-
next unless net_type == :private_network
|
75
|
-
addr = opts[:ip]
|
76
|
-
hosts << [addr, hostnames_for_machine(m)]
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
hosts
|
81
|
-
end
|
82
|
-
|
83
|
-
# @return [Array<Vagrant::Machine>]
|
84
|
-
def all_machines
|
85
|
-
@env.active_machines.map { |vm_id| @env.machine(*vm_id) }
|
86
|
-
end
|
87
|
-
|
88
38
|
end
|
@@ -1,4 +1,7 @@
|
|
1
1
|
# Provide a base class for syncing hosts entries on POSIX systems.
|
2
|
+
|
3
|
+
require 'tempfile'
|
4
|
+
|
2
5
|
class VagrantHosts::Cap::SyncHosts::POSIX < VagrantHosts::Cap::SyncHosts::Base
|
3
6
|
|
4
7
|
private
|
@@ -19,7 +22,7 @@ class VagrantHosts::Cap::SyncHosts::POSIX < VagrantHosts::Cap::SyncHosts::Base
|
|
19
22
|
#
|
20
23
|
# @return [String] All hosts in the config joined into hosts records
|
21
24
|
def format_hosts
|
22
|
-
all_hosts.inject('') do |str, (address, aliases)|
|
25
|
+
all_hosts(@config).inject('') do |str, (address, aliases)|
|
23
26
|
str << "#{address} #{aliases.join(' ')}\n"
|
24
27
|
end
|
25
28
|
end
|
@@ -3,7 +3,7 @@ class VagrantHosts::Cap::SyncHosts::Windows < VagrantHosts::Cap::SyncHosts::Base
|
|
3
3
|
|
4
4
|
def update_hosts
|
5
5
|
host_entries = []
|
6
|
-
all_hosts.each do |(address, aliases)|
|
6
|
+
all_hosts(@config).each do |(address, aliases)|
|
7
7
|
aliases.each do |name|
|
8
8
|
host_entries << "#{address} #{name}"
|
9
9
|
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'vagrant'
|
2
|
+
module VagrantHosts
|
3
|
+
class Command < Vagrant.plugin('2', :command)
|
4
|
+
|
5
|
+
require 'vagrant-hosts/command/helpers'
|
6
|
+
include VagrantHosts::Command::Helpers
|
7
|
+
|
8
|
+
require 'vagrant-hosts/addresses'
|
9
|
+
|
10
|
+
|
11
|
+
require 'vagrant-hosts/command/puppetize'
|
12
|
+
require 'vagrant-hosts/command/list'
|
13
|
+
|
14
|
+
def initialize(argv, env)
|
15
|
+
@argv = argv
|
16
|
+
@env = env
|
17
|
+
@cmd_name = 'hosts'
|
18
|
+
|
19
|
+
split_argv
|
20
|
+
register_subcommands
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
def execute
|
25
|
+
invoke_subcommand
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def register_subcommands
|
31
|
+
@subcommands = Vagrant::Registry.new
|
32
|
+
|
33
|
+
@subcommands.register('puppetize') do
|
34
|
+
VagrantHosts::Command::Puppetize
|
35
|
+
end
|
36
|
+
|
37
|
+
@subcommands.register('list') do
|
38
|
+
VagrantHosts::Command::List
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module VagrantHosts::Command::Helpers
|
2
|
+
|
3
|
+
private
|
4
|
+
|
5
|
+
def split_argv
|
6
|
+
@main_args, @subcommand, @sub_args = split_main_and_subcommand(@argv)
|
7
|
+
end
|
8
|
+
|
9
|
+
def invoke_subcommand
|
10
|
+
if @subcommand and (klass = @subcommands.get(@subcommand))
|
11
|
+
klass.new(@argv, @env).execute
|
12
|
+
elsif @subcommand
|
13
|
+
@env.ui.error "Unrecognized subcommand: #{@subcommand}"
|
14
|
+
print_subcommand_help(:error)
|
15
|
+
else
|
16
|
+
print_subcommand_help
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def print_subcommand_help(output = :info)
|
21
|
+
msg = []
|
22
|
+
msg << "Usage: vagrant #{@cmd_name} <command> [<args>]"
|
23
|
+
msg << ''
|
24
|
+
msg << 'Available subcommands:'
|
25
|
+
|
26
|
+
keys = []
|
27
|
+
@subcommands.each { |(key, _)| keys << key }
|
28
|
+
msg += keys.sort.map { |key| " #{key}" }
|
29
|
+
|
30
|
+
msg << ''
|
31
|
+
msg << "For help on any individual command run `vagrant #{@cmd_name} <command> -h`"
|
32
|
+
|
33
|
+
@env.ui.send(output, msg.join("\n"))
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
class VagrantHosts::Command::List < Vagrant.plugin('2', :command)
|
2
|
+
|
3
|
+
include VagrantHosts::Command::Helpers
|
4
|
+
include VagrantHosts::Addresses
|
5
|
+
|
6
|
+
def initialize(argv, env)
|
7
|
+
@argv = argv
|
8
|
+
@env = env
|
9
|
+
@cmd_name = 'hosts list'
|
10
|
+
|
11
|
+
split_argv
|
12
|
+
end
|
13
|
+
|
14
|
+
def execute
|
15
|
+
|
16
|
+
argv = parse_options(parser)
|
17
|
+
|
18
|
+
@env.ui.info format_hosts
|
19
|
+
0
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def format_hosts
|
25
|
+
vagrant_hosts(@env).inject('') do |str, (address, aliases)|
|
26
|
+
str << "#{address} #{aliases.join(' ')}\n"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
def parser
|
32
|
+
OptionParser.new do |o|
|
33
|
+
o.banner = "Usage: vagrant #{@cmd_name} [<args>]"
|
34
|
+
o.separator ''
|
35
|
+
|
36
|
+
o.on('-h', '--help', 'Display this help message') do
|
37
|
+
puts o
|
38
|
+
exit 0
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
class VagrantHosts::Command::Puppetize < Vagrant.plugin('2', :command)
|
2
|
+
|
3
|
+
include VagrantHosts::Command::Helpers
|
4
|
+
include VagrantHosts::Addresses
|
5
|
+
|
6
|
+
def initialize(argv, env)
|
7
|
+
@argv = argv
|
8
|
+
@env = env
|
9
|
+
@cmd_name = 'hosts puppetize'
|
10
|
+
|
11
|
+
split_argv
|
12
|
+
end
|
13
|
+
|
14
|
+
def execute
|
15
|
+
argv = parse_options(parser)
|
16
|
+
|
17
|
+
@env.ui.info format_hosts
|
18
|
+
0
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def format_hosts
|
24
|
+
vagrant_hosts(@env).inject('') do |str, (address, aliases)|
|
25
|
+
str << "host { '#{aliases.shift}':\n ip => '#{address}',\n"
|
26
|
+
str << "host_aliases => ['#{aliases.join('\', \' ')}'],\n" if (!aliases.empty?)
|
27
|
+
str << "}\n"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def parser
|
32
|
+
OptionParser.new do |o|
|
33
|
+
o.banner = "Usage: vagrant #{@cmd_name} [<args>]"
|
34
|
+
o.separator ''
|
35
|
+
|
36
|
+
o.on('-h', '--help', 'Display this help message') do
|
37
|
+
puts o
|
38
|
+
exit 0
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/lib/vagrant-hosts/plugin.rb
CHANGED
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: 2.
|
4
|
+
version: 2.1.0
|
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-11-13 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: ! ' Manage static DNS entries and configuration for Vagrant guests.
|
15
15
|
|
@@ -23,10 +23,15 @@ files:
|
|
23
23
|
- LICENSE
|
24
24
|
- README.markdown
|
25
25
|
- lib/vagrant-hosts.rb
|
26
|
+
- lib/vagrant-hosts/addresses.rb
|
26
27
|
- lib/vagrant-hosts/cap.rb
|
27
28
|
- lib/vagrant-hosts/cap/sync_hosts/base.rb
|
28
29
|
- lib/vagrant-hosts/cap/sync_hosts/posix.rb
|
29
30
|
- lib/vagrant-hosts/cap/sync_hosts/windows.rb
|
31
|
+
- lib/vagrant-hosts/command.rb
|
32
|
+
- lib/vagrant-hosts/command/helpers.rb
|
33
|
+
- lib/vagrant-hosts/command/list.rb
|
34
|
+
- lib/vagrant-hosts/command/puppetize.rb
|
30
35
|
- lib/vagrant-hosts/config.rb
|
31
36
|
- lib/vagrant-hosts/config_builder.rb
|
32
37
|
- lib/vagrant-hosts/plugin.rb
|