vagrant-hosts 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,35 @@
1
+ require 'vagrant'
2
+ require 'vagrant-hosts'
3
+
4
+ class VagrantHosts::Config < Vagrant::Config::Base
5
+
6
+ attr_reader :hosts
7
+
8
+ def initialize
9
+ @hosts = []
10
+ end
11
+
12
+ # Register a host for entry
13
+ #
14
+ # @param [String] address The IP address for aliases
15
+ # @param [Array] aliases An array of hostnames to assign to the IP address
16
+ def add_host(address, aliases)
17
+ @hosts << [address, aliases]
18
+ end
19
+
20
+ def add_ipv6_multicast
21
+ add_host '::1', ['ip6-localhost', 'ip6-loopback']
22
+ add_host 'fe00::0', ['ip6-localnet']
23
+ add_host 'ff00::0', ['ip6-mcastprefix']
24
+ add_host 'ff02::1', ['ip6-allnodes']
25
+ add_host 'ff02::2', ['ip6-allrouters']
26
+ end
27
+
28
+ def validate(env, errors)
29
+ @hosts.each do |(address, aliases)|
30
+ unless aliases.is_a? Array
31
+ errors.add("#{address} should have an array of aliases, got #{aliases.inspect}:#{aliases.class}")
32
+ end
33
+ end
34
+ end
35
+ end
@@ -1,38 +1,14 @@
1
1
  require 'vagrant'
2
2
  require 'vagrant-hosts'
3
3
  require 'vagrant-hosts/ssh' # Guerrilla patch ssh download
4
+ require 'vagrant-hosts/config'
4
5
  require 'tempfile'
5
6
 
6
7
 
7
8
  class VagrantHosts::Provisioner < Vagrant::Provisioners::Base
8
9
 
9
- class Config < Vagrant::Config::Base
10
-
11
- attr_reader :hosts
12
-
13
- def initialize
14
- @hosts = []
15
- end
16
-
17
- # Register a host for entry
18
- #
19
- # @param [String] address The IP address for aliases
20
- # @param [Array] aliases An array of hostnames to assign to the IP address
21
- def add_host(address, aliases)
22
- @hosts << [address, aliases]
23
- end
24
-
25
- def validate(env, errors)
26
- @hosts.each do |(address, aliases)|
27
- unless aliases.is_a? Array
28
- errors.add("#{address} should have an array of aliases, got #{aliases.inspect}:#{aliases.class}")
29
- end
30
- end
31
- end
32
- end
33
-
34
10
  def self.config_class
35
- Config
11
+ ::VagrantHosts::Config
36
12
  end
37
13
 
38
14
  def provision!
@@ -50,25 +26,36 @@ class VagrantHosts::Provisioner < Vagrant::Provisioners::Base
50
26
  end
51
27
 
52
28
  def sync!
53
- cache = Tempfile.new('vagrant-hosts')
54
-
55
- # It would be really cool to synchronize this file instead of blindly
56
- # smashing the remote hosts file, but this is the quick and dirty solution.
57
- #@env[:vm].channel.download('/etc/hosts', cache.path)
58
- #cache.rewind
59
- #cache.truncate(0)
29
+ upload_tmphosts
30
+ atomic_sync
31
+ end
60
32
 
61
- cache.write hosts_format
33
+ def upload_tmphosts
34
+ cache = Tempfile.new('tmp-hosts')
35
+ cache.write(format_hosts)
62
36
  cache.flush
63
-
64
37
  @env[:vm].channel.upload(cache.path, '/tmp/hosts')
65
- @env[:vm].channel.sudo('install -m 644 /tmp/hosts /etc/hosts')
38
+ end
39
+
40
+ def atomic_sync
41
+ script = <<-ATOMIC
42
+ hostname #{@env[:vm].name}
43
+ domainname vagrantup.internal
44
+ install -m 644 /tmp/hosts /etc/hosts
45
+ ATOMIC
46
+
47
+ sync = Tempfile.new('sync')
48
+ sync.write(script)
49
+ sync.flush
50
+ @env[:vm].channel.upload(sync.path, '/tmp/sync')
51
+
52
+ @env[:vm].channel.sudo('bash /tmp/sync')
66
53
  end
67
54
 
68
55
  # Generates content appropriate for a linux hosts file
69
56
  #
70
57
  # @return [String] All hosts in the config joined into hosts records
71
- def hosts_format
58
+ def format_hosts
72
59
  @config.hosts.inject('') do |str, (address, aliases)|
73
60
  str << "#{address} #{aliases.join(' ')}\n"
74
61
  end
@@ -1,3 +1,3 @@
1
1
  module VagrantHosts
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  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: 0.0.1
4
+ version: 0.0.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: 2012-12-26 00:00:00.000000000 Z
12
+ date: 2013-01-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: vagrant
@@ -38,6 +38,7 @@ files:
38
38
  - LICENSE
39
39
  - README.markdown
40
40
  - lib/vagrant-hosts.rb
41
+ - lib/vagrant-hosts/config.rb
41
42
  - lib/vagrant-hosts/provisioners/hosts.rb
42
43
  - lib/vagrant-hosts/ssh.rb
43
44
  - lib/vagrant-hosts/version.rb