vagrant-hosts 2.6.2 → 2.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 67ecc8f4fa29f9f2672c135efa98df042014c846
4
- data.tar.gz: df396fc91d0d361ce8b583128a9b40e50af90e52
3
+ metadata.gz: cfff7593a5865f5cabdc74e7270a64c3e1f5de15
4
+ data.tar.gz: e4f29ffa5b3a999603dbe792a9ed75da87b9222b
5
5
  SHA512:
6
- metadata.gz: a442e5a025b25ddb66fe4118b7448fd05fdc89cc9948a9fbb2cf45afcc9a054a4772da401dbd7785453d439e872ef1085d142ff60c545de6fca474f1b730704d
7
- data.tar.gz: 2934bf400d9719eb3563a731873a8ddd9543546287b7b1c3d58b3205f6afa1be74169ab3a46fde9c0018da3acd8eee1a1e3a208921ad92570a558b6cf80b909a
6
+ metadata.gz: 564de5beef4fc73fe719ffeaf728cf07f2e945e1acecb2bef30b53c8ac0deddaa7d187bfa722965747f1f31ab9120ebf83ef58fb6951f34980a32b9189a1cb05
7
+ data.tar.gz: 08b964be8d8ee3d53dfce11efb0b505078f92ea54ecbd8f29c2cbcb90b88e6ceb312bf1c217c1ebe4bfc427d0c1d66bf803db80681e85ef60d41045e280e0849
data/CHANGELOG CHANGED
@@ -1,6 +1,25 @@
1
1
  CHANGELOG
2
2
  =========
3
3
 
4
+ 2.7.0
5
+ -----
6
+
7
+ 2016-03-28
8
+
9
+ This is a backwards compatible feature release.
10
+
11
+ * (GH-58) Added a flexible import/export system for sharing host entries among
12
+ groups of VMs.
13
+
14
+ * (GH-56) Added a special value, `@vagrant_ssh`, for host entries that will
15
+ be replaced with the address Vagrant uses to SSH into the VM.
16
+
17
+ * (GH-59) Made sync_hosts more friendly to VMs that have requiretty turned on.
18
+
19
+ * (GH-61) Fixed a bug where config_builder 0.x couldn't set the hosts array
20
+ on the hosts provisioner.
21
+
22
+
4
23
  2.6.2
5
24
  -----
6
25
 
data/Gemfile CHANGED
@@ -20,8 +20,8 @@ group :test do
20
20
  gem 'vagrant', :github => 'mitchellh/vagrant', :tag => ENV['TEST_VAGRANT_VERSION']
21
21
  end
22
22
 
23
- # Pinned on 12/10/2014. Compatible with Vagrant 1.5.x, 1.6.x and 1.7.x.
24
- gem 'vagrant-spec', :github => 'mitchellh/vagrant-spec', :ref => '1df5a3a'
23
+ # Pinned on 2/21/2016. Compatible with Vagrant 1.6.x, 1.7.x and 1.8.x.
24
+ gem 'vagrant-spec', :github => 'mitchellh/vagrant-spec', :ref => '9bba7e1'
25
25
  end
26
26
 
27
27
  eval_gemfile "#{__FILE__}.local" if File.exists? "#{__FILE__}.local"
@@ -21,6 +21,16 @@ behaviors of each provisioner instance.
21
21
  * Description: An array of tuples containing:
22
22
  - An IP address
23
23
  - A list of hostnames match with that address.
24
+ These entries may use special eys as described in the next section.
25
+ * Default: `[]`
26
+ * `exports`
27
+ * Description: A hash containing named lists of `[address, [aliases]]`
28
+ entries that are exported by this VM. These exports can be collected
29
+ by other VMs using the imports setting. These entries may use special
30
+ keys as described in the next section.
31
+ * Default: `{}`
32
+ * `imports`
33
+ * Description: A list of named exports to collect from other VMs.
24
34
  * Default: `[]`
25
35
  * `autoconfigure`
26
36
  * Description: A boolean which controls whether hosts are pulled in from other machines.
@@ -32,6 +42,34 @@ behaviors of each provisioner instance.
32
42
  * Description: A boolean which controls whether running the hosts provisioner causes an update on all other running machines.
33
43
  This also happens during machine destruction.
34
44
  * Default: `false`
45
+ * `sync_hosts`
46
+ * Description: A boolean which controls whether running the hosts provisioner causes an update on all other running machines.
47
+ This also happens during machine destruction.
48
+ * Default: `false`
49
+
50
+ ### Special Keys
51
+
52
+ The tuples used by the `hosts` and `exports` settings are of the form:
53
+
54
+ [address, [aliases]]
55
+
56
+ For each component, there are some special keys defined that will be replaced by
57
+ data determined from the VM.
58
+
59
+ For `address`, the following special keys may be used:
60
+
61
+ - `@vagrant_private_networks`: Expands to create one host entry with the given
62
+ `aliases` for each private network attached to a VM that has an explicitly
63
+ configured `ip` address. This is similar to the `autoconfigure` setting, but
64
+ gives control over which aliases are used.
65
+
66
+ - `@vagrant_ssh`: Expands to the IP address that `vagrant ssh` uses to connect
67
+ with the VM.
68
+
69
+ For `aliases`, the following special keys may be used:
70
+
71
+ - `@vagrant_hostnames`: Expands to an array of aliases containing:
72
+ <vm hostname> <first component of vm hostname> <vm name>
35
73
 
36
74
 
37
75
  Example Usage
@@ -115,6 +153,40 @@ Vagrant.configure('2') do |config|
115
153
  end
116
154
  ```
117
155
 
156
+ - - -
157
+
158
+ Use exports and special keys to share names among VMs:
159
+
160
+ ```ruby
161
+ Vagrant.configure('2') do |config|
162
+
163
+ # A node running in a remote compute environment, such as AWS or OpenStack.
164
+ config.vm.define :cloud do |node|
165
+ node.vm.provision :hosts do |provisioner|
166
+ provisioner.sync_hosts = true
167
+ provisioner.exports = {
168
+ 'global' => [
169
+ ['@vagrant_ssh', ['@vagrant_hostnames']],
170
+ ],
171
+ }
172
+ end
173
+ end
174
+
175
+ # A node running locally under Virtualbox
176
+ config.vm.define :local do |node|
177
+ node.vm.provision :hosts do |provisioner|
178
+ provisioner.sync_hosts = true
179
+ provisioner.imports = ['global', 'virtualbox']
180
+ provisioner.exports = {
181
+ 'virtualbox' => [
182
+ ['@vagrant_private_networks', ['@vagrant_hostnames']],
183
+ ],
184
+ }
185
+ end
186
+ end
187
+ end
188
+ ```
189
+
118
190
  Vagrant Commands
119
191
  ----------------
120
192
 
@@ -1,5 +1,16 @@
1
+ require 'resolv'
2
+ require 'ipaddr'
3
+
1
4
  module VagrantHosts::Addresses
2
5
 
6
+ # Cache for networking data
7
+ #
8
+ # @return [Hash{String => Hash{String => String}}]
9
+ # @private
10
+ #
11
+ # @since 2.7.0
12
+ CACHE ||= {}
13
+
3
14
  private
4
15
 
5
16
  def all_hosts(config)
@@ -9,9 +20,14 @@ module VagrantHosts::Addresses
9
20
  if config.autoconfigure
10
21
  all_hosts += vagrant_hosts(@env)
11
22
  end
12
- all_hosts += config.hosts
13
23
 
14
- all_hosts
24
+ unless config.imports.empty?
25
+ all_hosts += collect_imports(@machine, config)
26
+ end
27
+
28
+ all_hosts += resolve_host_entries(config.hosts, @machine)
29
+
30
+ all_hosts.uniq
15
31
  end
16
32
 
17
33
  # Builds an array containing hostname and aliases for a given machine.
@@ -53,6 +69,164 @@ module VagrantHosts::Addresses
53
69
  hosts
54
70
  end
55
71
 
72
+ # Collect all hosts entries for a machine
73
+ #
74
+ # @param machine [Vagrant::Machine] A vagrant VM to perform collection upon.
75
+ # @param config [VagrantHosts::Config] A configuration object for the hosts
76
+ # provisioner.
77
+ #
78
+ # @return [Array<Array<IPAddr, Array<String>>>] A list of address, alias
79
+ # tuples.
80
+ #
81
+ # @since 2.7.0
82
+ def collect_imports(machine, config)
83
+ env = machine.env
84
+ imports = config.imports
85
+
86
+ # TODO: Use Set?
87
+ hosts = []
88
+
89
+ all_machines(env).each do |m|
90
+ next if m.name == machine.name
91
+
92
+ host_provisioners(m).each do |p|
93
+ imports.each do |k|
94
+ next unless p.config.exports.has_key?(k)
95
+ hosts.concat resolve_host_entries(p.config.exports[k], m)
96
+ end
97
+ end
98
+ end
99
+
100
+ hosts.uniq
101
+ end
102
+
103
+ # Generate a list of IP addresses and aliases for a vagrant machine
104
+ #
105
+ # This functionresolves a list of addresses and aliases, possibly including
106
+ # special keys, into a list of addresses and aliases.
107
+ #
108
+ # See {#resolve_addresses} and {#resolve_aliases} for special key handling.
109
+ #
110
+ # @param entries[Array<String, Array<String>>] A list of entries.
111
+ #
112
+ # @raise [IPAddr::InvalidAddressError] Raised when an invalid address is
113
+ # supplied.
114
+ # @raise [Resolv::ResolvError] When a hostname cannot be resolved to an IP.
115
+ #
116
+ # @return [Array<IPAddr, Array<String>>]
117
+ #
118
+ # @since 2.7.0
119
+ def resolve_host_entries(entries, machine)
120
+ entries.flat_map do |(address, aliases)|
121
+ names = resolve_aliases(aliases, machine)
122
+ resolve_addresses(address, machine).map {|ip| [resolve_ip(ip), names]}
123
+ end
124
+ end
125
+
126
+ # Generate a list of IP addresses for a vagrant machine
127
+ #
128
+ # This function resolves an address or special key into a list of
129
+ # IP addresses.
130
+ #
131
+ # Special keys currently supported:
132
+ #
133
+ # - `@vagrant_private_networks`: The IP addresses of each privte network
134
+ # attached to the machine.
135
+ #
136
+ # - `@vagrant_ssh`: The IP address used by Vagrant to communicate with the
137
+ # machine (also includes WinRM and other communicators).
138
+ #
139
+ # @param aliases [String] An IP address or special key.
140
+ # @param machine [Vagrant::Machine] The Vagrant machine to use when resolving
141
+ # addresses.
142
+ #
143
+ # @return [Array<String>] A list of addresses.
144
+ #
145
+ # @since 2.7.0
146
+ def resolve_addresses(address, machine)
147
+ # Some network addresses, such as ssh_info, can be expensive to
148
+ # look up from cloud environments such as AWS, vSphere and OpenStack.
149
+ # So, we cache these special keys.
150
+ if CACHE.key?(machine.name) && CACHE[machine.name].key?(address)
151
+ ips = CACHE[machine.name][address]
152
+ else
153
+ ips = case address
154
+ when '@vagrant_private_networks'
155
+ machine.config.vm.networks.map do |(net_type, opts)|
156
+ next unless net_type == :private_network
157
+ opts[:ip]
158
+ end.compact
159
+ when '@vagrant_ssh'
160
+ if (info = machine.ssh_info)
161
+ info[:host]
162
+ else
163
+ []
164
+ end
165
+ else
166
+ address
167
+ end
168
+
169
+ if address.start_with?('@')
170
+ CACHE[machine.name] ||= {}
171
+ CACHE[machine.name][address] = ips
172
+ end
173
+ end
174
+
175
+ Array(ips)
176
+ end
177
+
178
+ # Generate an list of IP addresses from a string
179
+ #
180
+ # This function resolves a string into an IP address.
181
+ # IP addresses.
182
+ #
183
+ # @param address [String] A string that might be an IP address or a hostname.
184
+ #
185
+ # @raise [IPAddr::InvalidAddressError] Raised when an invalid address is
186
+ # supplied.
187
+ # @raise [Resolv::ResolvError] When a hostname cannot be resolved to an IP.
188
+ #
189
+ # @return [IPAddr] An IP address.
190
+ #
191
+ # @since 2.7.0
192
+ def resolve_ip(address)
193
+ ip = begin
194
+ IPAddr.new(address)
195
+ rescue IPAddr::InvalidAddressError
196
+ # Wasn't an IP address. Resolve it. The AWS provider does this.
197
+ IPAddr.new(Resolv.getaddress(address))
198
+ end
199
+
200
+ ip
201
+ end
202
+
203
+ # Generate a list of hostnames for a vagrant machine
204
+ #
205
+ # This function resolves a list of hostnames or special keys into a list of
206
+ # hostnmaes.
207
+ #
208
+ # Special keys currently supported:
209
+ #
210
+ # - `@vagrant_hostnames`: See {#hostnames_for_machine}.
211
+ #
212
+ # @param aliases [Array<String>] A list of hostnames or special keys.
213
+ # @param machine [Vagrant::Machine] The Vagrant machine to use when resolving
214
+ # aliases.
215
+ #
216
+ # @return [Array<String>] A list of hostnames.
217
+ #
218
+ # @since 2.7.0
219
+ def resolve_aliases(aliases, machine)
220
+ aliases.flat_map do |a|
221
+ case a
222
+ when '@vagrant_hostnames'
223
+ hostnames_for_machine(machine)
224
+ else
225
+ a
226
+ end
227
+ end
228
+ end
229
+
56
230
  # @return [Array<Vagrant::Machine>]
57
231
  def all_machines(env)
58
232
  env.active_machines.map do |vm_id|
@@ -64,4 +238,15 @@ module VagrantHosts::Addresses
64
238
  end.compact
65
239
  end
66
240
 
241
+ # NOTE: This method exists for compatibility with Vagrant 1.6 and earlier.
242
+ # Remove it once support for these versions is dropped.
243
+ def host_provisioners(machine)
244
+ machine.config.vm.provisioners.select do |p|
245
+ if Vagrant::VERSION < '1.7'
246
+ p.name.intern == :hosts
247
+ else
248
+ p.type.intern == :hosts
249
+ end
250
+ end
251
+ end
67
252
  end
@@ -14,23 +14,7 @@ class VagrantHosts::Cap::SyncHosts::Base
14
14
  end
15
15
 
16
16
  def sync!
17
- hostname = @machine.config.vm.hostname || @machine.name.to_s
18
- change_host_name(hostname)
19
-
20
17
  # call to method not implemented by abstract base class
21
18
  update_hosts
22
19
  end
23
-
24
- private
25
-
26
- # @param name [String] The new hostname to apply on the guest
27
- def change_host_name(name)
28
- case Vagrant::VERSION
29
- when /^1\.1/
30
- @machine.guest.change_host_name(name)
31
- else
32
- @machine.guest.capability(:change_host_name, name)
33
- end
34
- end
35
-
36
20
  end
@@ -15,7 +15,18 @@ class VagrantHosts::Cap::SyncHosts::POSIX < VagrantHosts::Cap::SyncHosts::Base
15
15
 
16
16
  def update_hosts
17
17
  upload_tmphosts
18
+
19
+ # Switch to PTY mode as this provider may execute across multiple machines
20
+ # which may not have requiretty set to false (i.e. because they're still
21
+ # booting and scripts that disable requiretty haven't run yet). Not doing
22
+ # this can have nasty side effects --- such as preventing machines from
23
+ # being destroyed.
24
+ old_pty_setting = @machine.config.ssh.pty
25
+ @machine.config.ssh.pty = true
26
+
18
27
  @machine.communicate.sudo('cat /tmp/hosts > /etc/hosts')
28
+ ensure
29
+ @machine.config.ssh.pty = old_pty_setting
19
30
  end
20
31
 
21
32
  # Generates content appropriate for a linux hosts file
@@ -25,8 +25,26 @@ module VagrantHosts
25
25
  # destruction. Defaults to `false`.
26
26
  attr_accessor :sync_hosts
27
27
 
28
+ # @!attribute [rw] exports
29
+ # @return [Hash{String => Array<Array<String, Array<String>>>}]
30
+ # A hash containing named lists of `[address, [aliases]]` tuples
31
+ # that are exported by this VM. These exports can be collected by other
32
+ # VMs using the {#imports} option.
33
+ #
34
+ # @since 2.7.0
35
+ attr_accessor :exports
36
+
37
+ # @!attribute [rw] imports
38
+ # @return [Array<String>]
39
+ # A list of exports to collect from other VMs.
40
+ #
41
+ # @since 2.7.0
42
+ attr_accessor :imports
43
+
28
44
  def initialize
29
45
  @hosts = []
46
+ @exports = {}
47
+ @imports = []
30
48
  @autoconfigure = UNSET_VALUE
31
49
  @add_localhost_hostnames = UNSET_VALUE
32
50
  @sync_hosts = UNSET_VALUE
@@ -51,7 +69,7 @@ module VagrantHosts
51
69
 
52
70
  def finalize!
53
71
  if @autoconfigure == UNSET_VALUE
54
- if @hosts.empty?
72
+ if @hosts.empty? && @imports.empty?
55
73
  @autoconfigure = true
56
74
  else
57
75
  @autoconfigure = false
@@ -1,37 +1,7 @@
1
- require 'config_builder/model'
1
+ require 'config_builder/version'
2
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
- # @!attribute [rw] add_localhost_hostnames
12
- attr_accessor :add_localhost_hostnames
13
- # @!attribute [rw] sync_hosts
14
- attr_accessor :sync_hosts
15
-
16
- def initialize
17
- @hosts = []
18
- end
19
-
20
- def to_proc
21
- Proc.new do |vm_config|
22
- vm_config.provision :hosts do |h_config|
23
- h_config.autoconfigure = attr(:autoconfigure) unless attr(:autoconfigure).nil?
24
- h_config.add_localhost_hostnames = attr(:add_localhost_hostnames) unless attr(:add_localhost_hostnames).nil?
25
- h_config.sync_hosts = attr(:sync_hosts) unless attr(:sync_hosts).nil?
26
-
27
- @hosts.each do |(address, aliases)|
28
- h_config.add_host address, aliases
29
- end
30
- end
31
- end
32
- end
33
-
34
- ::ConfigBuilder::Model::Provisioner.register('hosts', self)
35
- end
36
- end
3
+ if ConfigBuilder::VERSION > '1.0'
4
+ require_relative 'config_builder/1_x.rb'
5
+ else
6
+ require_relative 'config_builder/0_x.rb'
37
7
  end
@@ -0,0 +1,40 @@
1
+ require 'config_builder/model'
2
+
3
+ # Integration with ConfigBuilder 0.x and older
4
+ module VagrantHosts
5
+ module ConfigBuilder
6
+ class Model < ::ConfigBuilder::Model::Base
7
+
8
+ # @!attribute [rw] hosts
9
+ attr_accessor :hosts
10
+ # @!attribute [rw] autoconfigure
11
+ attr_accessor :autoconfigure
12
+ # @!attribute [rw] add_localhost_hostnames
13
+ attr_accessor :add_localhost_hostnames
14
+ # @!attribute [rw] sync_hosts
15
+ attr_accessor :sync_hosts
16
+
17
+ def initialize
18
+ @defaults = {
19
+ :hosts => [],
20
+ }
21
+ end
22
+
23
+ def to_proc
24
+ Proc.new do |vm_config|
25
+ vm_config.provision :hosts do |h_config|
26
+ h_config.autoconfigure = attr(:autoconfigure) unless attr(:autoconfigure).nil?
27
+ h_config.add_localhost_hostnames = attr(:add_localhost_hostnames) unless attr(:add_localhost_hostnames).nil?
28
+ h_config.sync_hosts = attr(:sync_hosts) unless attr(:sync_hosts).nil?
29
+
30
+ attr(:hosts).each do |(address, aliases)|
31
+ h_config.add_host address, aliases
32
+ end
33
+ end
34
+ end
35
+ end
36
+
37
+ ::ConfigBuilder::Model::Provisioner.register('hosts', self)
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,33 @@
1
+ require 'config_builder/model'
2
+
3
+ # Integration with ConfigBuilder 1.x and newer
4
+ #
5
+ # @since 2.7.0
6
+ module VagrantHosts
7
+ module ConfigBuilder
8
+ class Model < ::ConfigBuilder::Model::Provisioner::Base
9
+
10
+ # @!attribute [rw] hosts
11
+ def_model_attribute :hosts
12
+ # @!attribute [rw] autoconfigure
13
+ def_model_attribute :autoconfigure
14
+ # @!attribute [rw] add_localhost_hostnames
15
+ def_model_attribute :add_localhost_hostnames
16
+ # @!attribute [rw] sync_hosts
17
+ def_model_attribute :sync_hosts
18
+ # @!attribute [rw] exports
19
+ def_model_attribute :exports
20
+ # @!attribute [rw] exports
21
+ def_model_attribute :imports
22
+
23
+ # @private
24
+ def configure_hosts(config, val)
25
+ val.each do |(address, aliases)|
26
+ config.add_host(address, aliases)
27
+ end
28
+ end
29
+
30
+ ::ConfigBuilder::Model::Provisioner.register('hosts', self)
31
+ end
32
+ end
33
+ end
@@ -32,14 +32,18 @@ module VagrantHosts
32
32
  # returning false (mitchellh/vagrant#6356).
33
33
  false
34
34
  end
35
- has_hosts = vm.config.vm.provisioners.any? {|p| p.type.intern == :hosts}
35
+ has_hosts = if Vagrant::VERSION < '1.7'
36
+ vm.config.vm.provisioners.any? {|p| p.name.intern == :hosts}
37
+ else
38
+ vm.config.vm.provisioners.any? {|p| p.type.intern == :hosts}
39
+ end
36
40
 
37
41
  running && has_hosts && (not calling_machine)
38
42
  end
39
43
 
40
44
  machines_to_provision.each do |vm|
41
45
  vm.ui.info "Updating hosts on: #{vm.name}"
42
- vm.config.vm.provisioners.select {|p| p.type.intern == :hosts}.each do |p|
46
+ host_provisioners(vm).each do |p|
43
47
  # Duplicate the hosts configuration.
44
48
  hosts_config = @config.class.new.merge(p.config)
45
49
  # Set sync_hosts to false to avoid recursion.
@@ -1,3 +1,3 @@
1
1
  module VagrantHosts
2
- VERSION = '2.6.2'
2
+ VERSION = '2.7.0'
3
3
  end
@@ -0,0 +1,115 @@
1
+ require 'spec_helper'
2
+
3
+ require 'vagrant-hosts/addresses'
4
+ require 'vagrant-hosts/config'
5
+
6
+
7
+ describe 'Vagrant Integration: VagrantHosts::Addresses' do
8
+ include_context 'vagrant-unit'
9
+
10
+ let(:test_env) {
11
+ env = isolated_environment
12
+
13
+ env.vagrantfile <<-EOF
14
+ Vagrant.configure('2') do |config|
15
+ config.vm.define 'machine-a' do |node|
16
+ node.vm.hostname = 'machine-a.testvm'
17
+
18
+ node.vm.network :private_network, ip: '10.40.1.1'
19
+ node.vm.network :private_network, ip: '10.40.1.3'
20
+
21
+ node.vm.provision 'hosts' do |p|
22
+ p.exports = {
23
+ 'global' => [
24
+ ['@vagrant_private_networks', ['@vagrant_hostnames']]
25
+ ],
26
+ }
27
+ end
28
+ end
29
+
30
+ config.vm.define 'machine-b' do |node|
31
+ node.vm.network :private_network, ip: '10.40.1.2'
32
+
33
+ node.vm.provision 'hosts' do |p|
34
+ p.exports = {
35
+ 'global' => [
36
+ ['@vagrant_private_networks', ['@vagrant_hostnames']],
37
+ ],
38
+ 'ssh' => [
39
+ ['@vagrant_ssh', ['@vagrant_hostnames']],
40
+ ],
41
+ }
42
+ end
43
+ end
44
+ end
45
+ EOF
46
+ env
47
+ }
48
+ let(:env) {
49
+ test_env.create_vagrant_env(local_data_path: "#{test_env.workdir}/.vagrant")
50
+ }
51
+ let(:machine_a) { env.machine(:'machine-a', :dummy) }
52
+ let(:machine_b) { env.machine(:'machine-b', :dummy) }
53
+
54
+ subject do
55
+ # A simple class which simulates inclusion of VagrantHosts::Addresses
56
+ Class.new do
57
+ include VagrantHosts::Addresses
58
+ # Expose private methods included above for testing.
59
+ public *self.private_instance_methods
60
+
61
+ def initialize(env, machine)
62
+ # Create instance variables that VagrantHosts::Addresses expects to
63
+ # have access to.
64
+ @env = env
65
+ @machine = machine
66
+ end
67
+ end.new(env, machine_a)
68
+ end
69
+
70
+ # Mark test VMs as active.
71
+ before :each do
72
+ allow(env).to receive(:active_machines).and_return([
73
+ [:'machine-a', :dummy],
74
+ [:'machine-b', :dummy],
75
+ ])
76
+
77
+ # Give Machine B a SSH address.
78
+ allow(machine_b).to receive(:ssh_info).and_return({:host => '10.40.1.4'})
79
+ end
80
+
81
+ describe '#vagrant_hosts' do
82
+ it 'returns private_network entries for each machine' do
83
+ expect(subject.vagrant_hosts(env)).to include(
84
+ ['10.40.1.1', ['machine-a.testvm', 'machine-a']],
85
+ ['10.40.1.3', ['machine-a.testvm', 'machine-a']],
86
+ ['10.40.1.2', ['machine-b']],
87
+ )
88
+ end
89
+ end
90
+
91
+ describe '#collect_imports' do
92
+ it 'returns imports from other machines' do
93
+ config = VagrantHosts::Config.new
94
+ config.imports = ['global', 'ssh']
95
+ config.finalize!
96
+
97
+ expect(subject.collect_imports(machine_a, config)).to eq([
98
+ [IPAddr.new('10.40.1.2'), ['machine-b']],
99
+ [IPAddr.new('10.40.1.4'), ['machine-b']],
100
+ ])
101
+ end
102
+ end
103
+
104
+ describe '#all_hosts' do
105
+ it 'resolves special addresses and aliases' do
106
+ config = VagrantHosts::Config.new
107
+ config.add_host '@vagrant_private_networks', ['@vagrant_hostnames']
108
+ config.finalize!
109
+
110
+ expect(subject.all_hosts(config)).to include(
111
+ [IPAddr.new('10.40.1.1'), ['machine-a.testvm', 'machine-a']],
112
+ )
113
+ end
114
+ end
115
+ end
@@ -4,4 +4,6 @@ $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
4
4
  # Acceptance tests are not loaded.
5
5
  ENV['VAGRANT_NO_PLUGINS'] = '1'
6
6
 
7
+ # Load the vagrant-hosts plugin so that Provisioners and such can be found.
8
+ require 'vagrant-hosts'
7
9
  require 'vagrant-spec/unit'
@@ -22,7 +22,7 @@ Gem::Specification.new do |gem|
22
22
  gem.files = %x{git ls-files -z}.split("\0")
23
23
  gem.require_path = 'lib'
24
24
 
25
- gem.add_development_dependency 'rake'
26
- # Pin to 2.14.x for compatibility with vagrant-spec.
25
+ # Pinned for compatibility with vagrant-spec.
26
+ gem.add_development_dependency 'rake', '~> 10.0'
27
27
  gem.add_development_dependency 'rspec', '~> 2.14.0'
28
28
  end
metadata CHANGED
@@ -1,41 +1,41 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-hosts
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.6.2
4
+ version: 2.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adrien Thebo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-07 00:00:00.000000000 Z
11
+ date: 2016-03-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '10.0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: '10.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rspec
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: 2.14.0
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: 2.14.0
41
41
  description: |2
@@ -45,10 +45,10 @@ executables: []
45
45
  extensions: []
46
46
  extra_rdoc_files: []
47
47
  files:
48
- - .gitignore
49
- - .rspec
50
- - .travis.yml
51
- - .yardopts
48
+ - ".gitignore"
49
+ - ".rspec"
50
+ - ".travis.yml"
51
+ - ".yardopts"
52
52
  - CHANGELOG
53
53
  - Gemfile
54
54
  - LICENSE
@@ -66,9 +66,12 @@ files:
66
66
  - lib/vagrant-hosts/command/puppetize.rb
67
67
  - lib/vagrant-hosts/config.rb
68
68
  - lib/vagrant-hosts/config_builder.rb
69
+ - lib/vagrant-hosts/config_builder/0_x.rb
70
+ - lib/vagrant-hosts/config_builder/1_x.rb
69
71
  - lib/vagrant-hosts/plugin.rb
70
72
  - lib/vagrant-hosts/provisioner/hosts.rb
71
73
  - lib/vagrant-hosts/version.rb
74
+ - spec/integration/addresses_spec.rb
72
75
  - spec/spec_helper.rb
73
76
  - spec/unit/config_spec.rb
74
77
  - tasks/spec.rake
@@ -84,17 +87,17 @@ require_paths:
84
87
  - lib
85
88
  required_ruby_version: !ruby/object:Gem::Requirement
86
89
  requirements:
87
- - - '>='
90
+ - - ">="
88
91
  - !ruby/object:Gem::Version
89
92
  version: '0'
90
93
  required_rubygems_version: !ruby/object:Gem::Requirement
91
94
  requirements:
92
- - - '>='
95
+ - - ">="
93
96
  - !ruby/object:Gem::Version
94
97
  version: '0'
95
98
  requirements: []
96
99
  rubyforge_project:
97
- rubygems_version: 2.0.14
100
+ rubygems_version: 2.4.5.1
98
101
  signing_key:
99
102
  specification_version: 4
100
103
  summary: Manage static DNS on vagrant guests