vagrant-hosts 1.1.5 → 2.0.0rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +13 -0
- data/lib/vagrant-hosts/cap.rb +15 -0
- data/lib/vagrant-hosts/{provisioner/linux.rb → cap/sync_hosts/base.rb} +19 -23
- data/lib/vagrant-hosts/cap/sync_hosts/posix.rb +27 -0
- data/lib/vagrant-hosts/cap/sync_hosts/windows.rb +23 -0
- data/lib/vagrant-hosts/plugin.rb +24 -5
- data/lib/vagrant-hosts/provisioner/hosts.rb +17 -0
- data/lib/vagrant-hosts/version.rb +1 -1
- data/templates/locales/en.yml +5 -3
- metadata +10 -8
- data/lib/vagrant-hosts/provisioner.rb +0 -20
- data/lib/vagrant-hosts/provisioner/hostname.rb +0 -27
data/CHANGELOG
CHANGED
@@ -1,6 +1,19 @@
|
|
1
1
|
CHANGELOG
|
2
2
|
=========
|
3
3
|
|
4
|
+
2.0.0
|
5
|
+
-----
|
6
|
+
|
7
|
+
2013-09-16
|
8
|
+
|
9
|
+
This is a backwards incompatible feature release.
|
10
|
+
|
11
|
+
* (GH-15) Extract guest operating system configuration to capabilities
|
12
|
+
* (GH-15) Add support for Windows guests
|
13
|
+
|
14
|
+
Thanks to Reid Vandewiele for doing the heavy lifting of extracting the
|
15
|
+
capabilities and adding the Windows guest capability.
|
16
|
+
|
4
17
|
1.1.5
|
5
18
|
-----
|
6
19
|
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module VagrantHosts
|
2
|
+
module Cap
|
3
|
+
module SyncHosts
|
4
|
+
|
5
|
+
class UnknownVersion < Vagrant::Errors::VagrantError
|
6
|
+
error_key(:unknown_version, 'vagrant_hosts.cap.sync_hosts')
|
7
|
+
end
|
8
|
+
|
9
|
+
require 'vagrant-hosts/cap/sync_hosts/base'
|
10
|
+
require 'vagrant-hosts/cap/sync_hosts/posix'
|
11
|
+
require 'vagrant-hosts/cap/sync_hosts/windows'
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -1,39 +1,34 @@
|
|
1
|
-
class
|
1
|
+
# Provide an abstract base class for syncing hosts entries
|
2
|
+
class VagrantHosts::Cap::SyncHosts::Base
|
2
3
|
|
3
|
-
|
4
|
+
def self.sync_hosts(machine, config)
|
5
|
+
new(machine, config).sync!
|
6
|
+
end
|
4
7
|
|
5
8
|
def initialize(machine, config)
|
6
9
|
@machine, @config = machine, config
|
7
|
-
|
8
10
|
@env = @machine.env
|
9
11
|
end
|
10
12
|
|
11
13
|
def sync!
|
12
|
-
|
14
|
+
hostname = @machine.config.vm.hostname || @machine.name.to_s
|
15
|
+
change_host_name(hostname)
|
16
|
+
|
17
|
+
# call to method not implemented by abstract base class
|
13
18
|
update_hosts
|
14
19
|
end
|
15
20
|
|
16
21
|
private
|
17
22
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
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"
|
23
|
+
# @param name [String] The new hostname to apply on the guest
|
24
|
+
def change_host_name(name)
|
25
|
+
case Vagrant::VERSION
|
26
|
+
when /^1\.1/
|
27
|
+
@machine.guest.change_host_name(name)
|
28
|
+
when /^1\.2/, /^1\.3/
|
29
|
+
@machine.guest.capability(:change_host_name, name)
|
30
|
+
else
|
31
|
+
raise UnknownVersion, :vagrant_version => Vagrant::VERSION
|
37
32
|
end
|
38
33
|
end
|
39
34
|
|
@@ -89,4 +84,5 @@ class VagrantHosts::Provisioner::Linux
|
|
89
84
|
def all_machines
|
90
85
|
@env.active_machines.map { |vm_id| @env.machine(*vm_id) }
|
91
86
|
end
|
87
|
+
|
92
88
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# Provide a base class for syncing hosts entries on POSIX systems.
|
2
|
+
class VagrantHosts::Cap::SyncHosts::POSIX < VagrantHosts::Cap::SyncHosts::Base
|
3
|
+
|
4
|
+
private
|
5
|
+
|
6
|
+
def upload_tmphosts
|
7
|
+
cache = Tempfile.new('tmp-hosts')
|
8
|
+
cache.write(format_hosts)
|
9
|
+
cache.flush
|
10
|
+
@machine.communicate.upload(cache.path, '/tmp/hosts')
|
11
|
+
end
|
12
|
+
|
13
|
+
def update_hosts
|
14
|
+
upload_tmphosts
|
15
|
+
@machine.communicate.sudo('install -m 644 /tmp/hosts /etc/hosts')
|
16
|
+
end
|
17
|
+
|
18
|
+
# Generates content appropriate for a linux hosts file
|
19
|
+
#
|
20
|
+
# @return [String] All hosts in the config joined into hosts records
|
21
|
+
def format_hosts
|
22
|
+
all_hosts.inject('') do |str, (address, aliases)|
|
23
|
+
str << "#{address} #{aliases.join(' ')}\n"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# Provide a base class for syncing hosts entries on Windows systems.
|
2
|
+
class VagrantHosts::Cap::SyncHosts::Windows < VagrantHosts::Cap::SyncHosts::Base
|
3
|
+
|
4
|
+
def update_hosts
|
5
|
+
host_entries = []
|
6
|
+
all_hosts.each do |(address, aliases)|
|
7
|
+
aliases.each do |name|
|
8
|
+
host_entries << "#{address} #{name}"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
script = []
|
13
|
+
script << '$HostsLocation = "$env:windir\\System32\\drivers\\etc\\hosts";'
|
14
|
+
|
15
|
+
host_entries.each do |entry|
|
16
|
+
script << "\$HostEntry = \"#{entry}\""
|
17
|
+
script << "if (!((gc \$HostsLocation) -contains $HostEntry)) { Add-Content -Path $HostsLocation -Value $HostEntry; }"
|
18
|
+
end
|
19
|
+
|
20
|
+
@machine.communicate.sudo(script.join("\r\n"))
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
data/lib/vagrant-hosts/plugin.rb
CHANGED
@@ -10,16 +10,35 @@ class VagrantHosts::Plugin < Vagrant.plugin(2)
|
|
10
10
|
Vagrant guests.
|
11
11
|
DESC
|
12
12
|
|
13
|
-
provisioner(:hosts) do
|
14
|
-
require_relative 'provisioner'
|
15
|
-
VagrantHosts::Provisioner
|
16
|
-
end
|
17
|
-
|
18
13
|
config(:hosts, :provisioner) do
|
19
14
|
require_relative 'config'
|
20
15
|
VagrantHosts::Config
|
21
16
|
end
|
22
17
|
|
18
|
+
provisioner(:hosts) do
|
19
|
+
require_relative 'provisioner/hosts'
|
20
|
+
VagrantHosts::Provisioner::Hosts
|
21
|
+
end
|
22
|
+
|
23
|
+
# Guest capabilities for vagrant-hosts
|
24
|
+
|
25
|
+
guest_capability(:linux, 'sync_hosts') do
|
26
|
+
require_relative 'cap'
|
27
|
+
VagrantHosts::Cap::SyncHosts::POSIX
|
28
|
+
end
|
29
|
+
|
30
|
+
guest_capability(:solaris, 'sync_hosts') do
|
31
|
+
require_relative 'cap'
|
32
|
+
VagrantHosts::Cap::SyncHosts::POSIX
|
33
|
+
end
|
34
|
+
|
35
|
+
guest_capability(:windows, 'sync_hosts') do
|
36
|
+
require_relative 'cap'
|
37
|
+
VagrantHosts::Cap::SyncHosts::Windows
|
38
|
+
end
|
39
|
+
|
40
|
+
# ConfigBuilder tie-ins
|
41
|
+
|
23
42
|
def self.config_builder_hook
|
24
43
|
require_relative 'config_builder'
|
25
44
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'vagrant'
|
2
|
+
|
3
|
+
module VagrantHosts
|
4
|
+
module Provisioner
|
5
|
+
class Hosts < Vagrant.plugin('2', :provisioner)
|
6
|
+
|
7
|
+
def initialize(machine, config)
|
8
|
+
super
|
9
|
+
end
|
10
|
+
|
11
|
+
def provision
|
12
|
+
@machine.guest.capability(:sync_hosts, @config)
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/templates/locales/en.yml
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
---
|
2
2
|
en:
|
3
3
|
vagrant_hosts:
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
cap:
|
5
|
+
sync_hosts:
|
6
|
+
unknown_version: |-
|
7
|
+
%{vagrant_version} isn't a recognized Vagrant version, vagrant-hosts can't reliably
|
8
|
+
detect the `change_host_name` method.
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vagrant-hosts
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
5
|
-
prerelease:
|
4
|
+
version: 2.0.0rc1
|
5
|
+
prerelease: 5
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Adrien Thebo
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-09-
|
12
|
+
date: 2013-09-16 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: ! ' Manage static DNS entries and configuration for Vagrant guests.
|
15
15
|
|
@@ -23,12 +23,14 @@ files:
|
|
23
23
|
- LICENSE
|
24
24
|
- README.markdown
|
25
25
|
- lib/vagrant-hosts.rb
|
26
|
+
- lib/vagrant-hosts/cap.rb
|
27
|
+
- lib/vagrant-hosts/cap/sync_hosts/base.rb
|
28
|
+
- lib/vagrant-hosts/cap/sync_hosts/posix.rb
|
29
|
+
- lib/vagrant-hosts/cap/sync_hosts/windows.rb
|
26
30
|
- lib/vagrant-hosts/config.rb
|
27
31
|
- lib/vagrant-hosts/config_builder.rb
|
28
32
|
- lib/vagrant-hosts/plugin.rb
|
29
|
-
- lib/vagrant-hosts/provisioner.rb
|
30
|
-
- lib/vagrant-hosts/provisioner/hostname.rb
|
31
|
-
- lib/vagrant-hosts/provisioner/linux.rb
|
33
|
+
- lib/vagrant-hosts/provisioner/hosts.rb
|
32
34
|
- lib/vagrant-hosts/version.rb
|
33
35
|
- templates/locales/en.yml
|
34
36
|
- vagrant-hosts.gemspec
|
@@ -48,9 +50,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
48
50
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
51
|
none: false
|
50
52
|
requirements:
|
51
|
-
- - ! '
|
53
|
+
- - ! '>'
|
52
54
|
- !ruby/object:Gem::Version
|
53
|
-
version:
|
55
|
+
version: 1.3.1
|
54
56
|
requirements: []
|
55
57
|
rubyforge_project:
|
56
58
|
rubygems_version: 1.8.23
|
@@ -1,20 +0,0 @@
|
|
1
|
-
require 'vagrant'
|
2
|
-
require 'tempfile'
|
3
|
-
|
4
|
-
module VagrantHosts
|
5
|
-
class Provisioner < Vagrant.plugin('2', :provisioner)
|
6
|
-
|
7
|
-
require 'vagrant-hosts/provisioner/hostname'
|
8
|
-
require 'vagrant-hosts/provisioner/linux'
|
9
|
-
|
10
|
-
def initialize(machine, config)
|
11
|
-
@machine, @config = machine, config
|
12
|
-
end
|
13
|
-
|
14
|
-
# @todo use guest capabilities instead of hardcoded provisioner provider
|
15
|
-
def provision
|
16
|
-
driver = Linux.new(@machine, @config)
|
17
|
-
driver.sync!
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
require 'vagrant'
|
2
|
-
require 'vagrant/errors'
|
3
|
-
|
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
|
15
|
-
|
16
|
-
# @param name [String] The new hostname to apply on the guest
|
17
|
-
def change_host_name(name)
|
18
|
-
case Vagrant::VERSION
|
19
|
-
when /^1\.1/
|
20
|
-
@machine.guest.change_host_name(name)
|
21
|
-
when /^1\.2/, /^1\.3/
|
22
|
-
@machine.guest.capability(:change_host_name, name)
|
23
|
-
else
|
24
|
-
raise UnknownVersion, :vagrant_version => Vagrant::VERSION
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|