vagrant-hosts 2.7.1 → 2.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +12 -0
- data/README.markdown +4 -1
- data/lib/vagrant-hosts/addresses.rb +2 -0
- data/lib/vagrant-hosts/cap.rb +4 -5
- data/lib/vagrant-hosts/cap/facts/base.rb +43 -0
- data/lib/vagrant-hosts/cap/facts/posix.rb +44 -0
- data/lib/vagrant-hosts/cap/facts/windows.rb +42 -0
- data/lib/vagrant-hosts/cap/sync_hosts/base.rb +6 -0
- data/lib/vagrant-hosts/plugin.rb +13 -0
- data/lib/vagrant-hosts/version.rb +1 -1
- data/templates/locales/en.yml +1 -6
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bc25e420c49e7f62fdb74de109d2d297bbcd04ef
|
4
|
+
data.tar.gz: 84dc84eaf30ba2d749dd691568aabd97fe1bc8bb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f5fa318724084c3ad5ba7323330ab0550cef794a8bedbde25eed798648a3987de7289e4d90f2d98a6542368bce6cb211326aef1d55120b04e9cf70b1fbde0a78
|
7
|
+
data.tar.gz: 5576b69d80d8ea0c2f7338aead65a83142ccb3afb5d4782dda9555e50972dee7c310206ff8096a54fe6cefdea4bf2b768f7231010c8f3fb381fe7037a6b07065
|
data/CHANGELOG
CHANGED
@@ -1,6 +1,18 @@
|
|
1
1
|
CHANGELOG
|
2
2
|
=========
|
3
3
|
|
4
|
+
2.8.0
|
5
|
+
-----
|
6
|
+
|
7
|
+
2016-04-18
|
8
|
+
|
9
|
+
This is a backwards compatible feature release.
|
10
|
+
|
11
|
+
* (GH-56) Added a special value, `@facter_ipaddress`, for host entries that
|
12
|
+
will be replaced with the IPv4 address assigned to the default
|
13
|
+
network interface.
|
14
|
+
|
15
|
+
|
4
16
|
2.7.1
|
5
17
|
-----
|
6
18
|
|
data/README.markdown
CHANGED
@@ -21,7 +21,7 @@ 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
|
24
|
+
These entries may use special keys as described in the next section.
|
25
25
|
* Default: `[]`
|
26
26
|
* `exports`
|
27
27
|
* Description: A hash containing named lists of `[address, [aliases]]`
|
@@ -54,6 +54,9 @@ data determined from the VM.
|
|
54
54
|
|
55
55
|
For `address`, the following special keys may be used:
|
56
56
|
|
57
|
+
- `@facter_ipaddress`: Expands to the IPv4 address assigned to the
|
58
|
+
default network interface of the guest VM.
|
59
|
+
|
57
60
|
- `@vagrant_private_networks`: Expands to create one host entry with the given
|
58
61
|
`aliases` for each private network attached to a VM that has an explicitly
|
59
62
|
configured `ip` address. This is similar to the `autoconfigure` setting, but
|
data/lib/vagrant-hosts/cap.rb
CHANGED
@@ -1,15 +1,14 @@
|
|
1
1
|
module VagrantHosts
|
2
2
|
module Cap
|
3
3
|
module SyncHosts
|
4
|
-
|
5
|
-
class UnknownVersion < Vagrant::Errors::VagrantError
|
6
|
-
error_key(:unknown_version, 'vagrant_hosts.cap.sync_hosts')
|
7
|
-
end
|
8
|
-
|
9
4
|
require 'vagrant-hosts/cap/sync_hosts/base'
|
10
5
|
require 'vagrant-hosts/cap/sync_hosts/posix'
|
11
6
|
require 'vagrant-hosts/cap/sync_hosts/windows'
|
7
|
+
end
|
12
8
|
|
9
|
+
module Facts
|
10
|
+
require_relative 'cap/facts/posix'
|
11
|
+
require_relative 'cap/facts/windows'
|
13
12
|
end
|
14
13
|
end
|
15
14
|
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# Base class for retrieving network facts from guest VMs
|
2
|
+
#
|
3
|
+
# @since 2.8.0
|
4
|
+
class VagrantHosts::Cap::Facts::Base
|
5
|
+
|
6
|
+
# Retrieve facts from a guest VM
|
7
|
+
#
|
8
|
+
# See {#load_facts} for implementation details.
|
9
|
+
#
|
10
|
+
# @return [Hash] A hash of facts.
|
11
|
+
def self.network_facts(machine)
|
12
|
+
new(machine).load_facts
|
13
|
+
end
|
14
|
+
|
15
|
+
attr_reader :machine
|
16
|
+
|
17
|
+
def initialize(machine)
|
18
|
+
@machine = machine
|
19
|
+
end
|
20
|
+
|
21
|
+
def load_facts
|
22
|
+
raise NotImplementedError
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
# TODO: Split this out into a shared module.
|
28
|
+
def sudo(cmd)
|
29
|
+
stdout = ''
|
30
|
+
stderr = ''
|
31
|
+
|
32
|
+
retval = machine.communicate.sudo(cmd) do |type, data|
|
33
|
+
if type == :stderr
|
34
|
+
stderr << data.chomp
|
35
|
+
else
|
36
|
+
stdout << data.chomp
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
{:stdout => stdout, :stderr => stderr, :retval => retval}
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require_relative 'base'
|
2
|
+
|
3
|
+
# Base class for retrieving network facts from POSIX
|
4
|
+
#
|
5
|
+
# @since 2.8.0
|
6
|
+
class VagrantHosts::Cap::Facts::POSIX < VagrantHosts::Cap::Facts::Base
|
7
|
+
|
8
|
+
def load_facts
|
9
|
+
facts = {}
|
10
|
+
facts['networking'] = {}
|
11
|
+
facts['networking']['interfaces'] = parse_ifconfig
|
12
|
+
|
13
|
+
iface = get_default_iface
|
14
|
+
facts['networking']['ip'] = facts['networking']['interfaces'][iface]['ip']
|
15
|
+
|
16
|
+
facts
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def ifconfig
|
22
|
+
ifconfig_output = sudo('ifconfig -a')[:stdout]
|
23
|
+
# Group output by interface.
|
24
|
+
ifconfig_output.split(/^([[:alnum:]]+[:]?\s)/).drop(1).each_slice(2).map(&:join)
|
25
|
+
end
|
26
|
+
|
27
|
+
def parse_ifconfig
|
28
|
+
results = ifconfig.map do |i|
|
29
|
+
i.match(/^([[:alnum:]]+)[:]?\s.*inet (?:addr:)?([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/m)
|
30
|
+
end.compact.map do |r|
|
31
|
+
name, ip = r.captures
|
32
|
+
[name, {'ip' => ip}]
|
33
|
+
end
|
34
|
+
|
35
|
+
Hash[results]
|
36
|
+
end
|
37
|
+
|
38
|
+
def get_default_iface
|
39
|
+
route_table = sudo('netstat -rn')[:stdout]
|
40
|
+
default = route_table.lines.find {|e| e.start_with?('default') || e.start_with?('0.0.0.0')}
|
41
|
+
|
42
|
+
default.split.last.chomp
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require_relative 'base'
|
2
|
+
|
3
|
+
# Base class for retrieving network facts from Windows
|
4
|
+
#
|
5
|
+
# @since 2.8.0
|
6
|
+
class VagrantHosts::Cap::Facts::Windows < VagrantHosts::Cap::Facts::Base
|
7
|
+
|
8
|
+
def load_facts
|
9
|
+
facts = {}
|
10
|
+
facts['networking'] = {}
|
11
|
+
facts['networking']['interfaces'] = parse_ifconfig
|
12
|
+
|
13
|
+
iface = get_default_iface
|
14
|
+
facts['networking']['ip'] = iface
|
15
|
+
|
16
|
+
facts
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def parse_ifconfig
|
22
|
+
# Imagine a call to Get-WmiObject -Query that returns a combined dataset
|
23
|
+
# built from Win32_NetworkAdapter (interface names) and
|
24
|
+
# Win32_NetworkAdapterConfiguration (everything else, like ipaddress).
|
25
|
+
#
|
26
|
+
# TODO: Implement said query.
|
27
|
+
|
28
|
+
Hash.new
|
29
|
+
end
|
30
|
+
|
31
|
+
def get_default_iface
|
32
|
+
route_table = sudo('netstat -rn')[:stdout]
|
33
|
+
|
34
|
+
default = route_table.lines.find do |e|
|
35
|
+
e.lstrip.start_with?('default') ||
|
36
|
+
e.lstrip.start_with?('0.0.0.0')
|
37
|
+
end
|
38
|
+
|
39
|
+
default.split[-2].chomp
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
@@ -14,6 +14,12 @@ class VagrantHosts::Cap::SyncHosts::Base
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def sync!
|
17
|
+
# This ensures that a default hostname is created from the macine name
|
18
|
+
# if the VM wasn't configured with a hostname.
|
19
|
+
#
|
20
|
+
# FIXME: Write tests for this behavior.
|
21
|
+
# TODO: Move this behavior into a config block on the hosts provisioner
|
22
|
+
# so that this capability can remain focused on updating /etc/hosts.
|
17
23
|
hostname = @machine.config.vm.hostname || @machine.name.to_s
|
18
24
|
change_host_name(hostname)
|
19
25
|
|
data/lib/vagrant-hosts/plugin.rb
CHANGED
@@ -34,6 +34,19 @@ class VagrantHosts::Plugin < Vagrant.plugin(2)
|
|
34
34
|
VagrantHosts::Cap::SyncHosts::Windows
|
35
35
|
end
|
36
36
|
|
37
|
+
|
38
|
+
[:darwin, :linux, :solaris, :solaris11].each do |os|
|
39
|
+
guest_capability(os, 'network_facts') do
|
40
|
+
require_relative 'cap'
|
41
|
+
VagrantHosts::Cap::Facts::POSIX
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
guest_capability(:windows, 'network_facts') do
|
46
|
+
require_relative 'cap'
|
47
|
+
VagrantHosts::Cap::Facts::Windows
|
48
|
+
end
|
49
|
+
|
37
50
|
command(:hosts) do
|
38
51
|
require_relative 'command'
|
39
52
|
VagrantHosts::Command
|
data/templates/locales/en.yml
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vagrant-hosts
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.8.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-
|
11
|
+
date: 2016-04-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -57,6 +57,9 @@ files:
|
|
57
57
|
- lib/vagrant-hosts.rb
|
58
58
|
- lib/vagrant-hosts/addresses.rb
|
59
59
|
- lib/vagrant-hosts/cap.rb
|
60
|
+
- lib/vagrant-hosts/cap/facts/base.rb
|
61
|
+
- lib/vagrant-hosts/cap/facts/posix.rb
|
62
|
+
- lib/vagrant-hosts/cap/facts/windows.rb
|
60
63
|
- lib/vagrant-hosts/cap/sync_hosts/base.rb
|
61
64
|
- lib/vagrant-hosts/cap/sync_hosts/posix.rb
|
62
65
|
- lib/vagrant-hosts/cap/sync_hosts/windows.rb
|