vagrant-dnsmasq 0.0.6 → 0.0.7

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: 835c9917b38e165f4a5b04c593c11d8ad88c1b45
4
- data.tar.gz: 2a0dd01d6baafd68a189d3526f4db622c839d53f
3
+ metadata.gz: a22f37f14051709fb9d3ff209ba8f7bbf43ddf54
4
+ data.tar.gz: 31dde16d265e00a553caeed1a707da3774c82a65
5
5
  SHA512:
6
- metadata.gz: f5918efdad10112169ddae03bbb89b23f2cdd7805336867a196ffb0a69817e49fa8f6d12fa7fcade4bacf8a527cbe69adc35f0a4cdc9329621745e7f9c651795
7
- data.tar.gz: e62960e4ec379a5302b204d3f3ab35911094d32fb85214b4810adafbb5b76ea8c810776e8fbcf31507aba21f65eaf278c237df467347d1953c04f0c4ce3effb3
6
+ metadata.gz: 8d31c836656532f3b975976f94f72073be3e2ca72184682375ca11371082e56d2a2b96fac114d61960b84a7e90ee8139348b85474287a5d94e11012fbffa8fe9
7
+ data.tar.gz: f218310e2fa580f1789b9208fe8a91a5c1cdfe54279d8d21bf08701a7c138aa5748741f2f70d6b33895e10b734088ff02cdf3fe6d1bef4a97f822497e5d8d430
@@ -15,7 +15,7 @@ GIT
15
15
  PATH
16
16
  remote: .
17
17
  specs:
18
- vagrant-dnsmasq (0.0.6)
18
+ vagrant-dnsmasq (0.0.7)
19
19
 
20
20
  GEM
21
21
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -41,9 +41,12 @@ config.dnsmasq.domain = '.dev'
41
41
  # overwrite default location for /etc/resolver directory
42
42
  # config.dnsmasq.resolver = '/etc/resolver'
43
43
 
44
- # overwrite default location for /usr/local/etc/dnsmasq.conf
45
- # brew_prefix = `brew --prefix`.strip
46
- # config.dnsmasq.dnsmasqconf = brew_prefix + '/etc/dnsmasq.conf'
44
+ # 'vagrant destroy' does not delete /etc/resolver nameserver file, defaults to false
45
+ # config.dnsmasq.keep_resolver_on_destroy = true
46
+
47
+ # overwrite default location for /etc/dnsmasq.conf
48
+ brew_prefix = `brew --prefix`.strip
49
+ config.dnsmasq.dnsmasqconf = brew_prefix + '/etc/dnsmasq.conf'
47
50
 
48
51
  # disable dnsmasq handling
49
52
  # config.dnsmasq.disable = true
@@ -10,7 +10,7 @@ module Vagrant
10
10
 
11
11
  def call(env)
12
12
  if @machine.config.dnsmasq.enabled?
13
- # env[:ui].info "Dnsmasq handler actived"
13
+ env[:ui].info "Dnsmasq handler actived"
14
14
 
15
15
  @ip = @machine.config.dnsmasq.ip
16
16
 
@@ -53,7 +53,7 @@ module Vagrant
53
53
 
54
54
  # update /etc/resolver
55
55
  resolver = Resolver.new(@machine.config.dnsmasq.resolver, true) # true for sudo
56
- resolver.insert(@machine.config.dnsmasq.domain, use_ip)
56
+ resolver.insert(@machine.config.dnsmasq.domain, Ip.new('127.0.0.1'))
57
57
 
58
58
  env[:ui].success "Dnsmasq handler set IP '#{use_ip}' for domain '#{@machine.config.dnsmasq.domain.dotted}'"
59
59
 
@@ -83,8 +83,10 @@ module Vagrant
83
83
  dnsmasq.delete(@machine.config.dnsmasq.domain)
84
84
 
85
85
  # update /etc/resolver
86
- resolver = Resolver.new(@machine.config.dnsmasq.resolver, true) # true for sudo
87
- resolver.delete(@machine.config.dnsmasq.domain)
86
+ unless @machine.config.dnsmasq.keep_resolver_on_destroy
87
+ resolver = Resolver.new(@machine.config.dnsmasq.resolver, true) # true for sudo
88
+ resolver.delete(@machine.config.dnsmasq.domain)
89
+ end
88
90
 
89
91
  env[:ui].success "Dnsmasq handler removed domain '#{@machine.config.dnsmasq.domain}'"
90
92
 
@@ -5,6 +5,7 @@ module Vagrant
5
5
  attr_accessor :domain
6
6
  attr_accessor :ip
7
7
  attr_accessor :resolver
8
+ attr_accessor :keep_resolver_on_destroy
8
9
  attr_accessor :dnsmasqconf
9
10
  attr_accessor :disable
10
11
 
@@ -12,12 +13,14 @@ module Vagrant
12
13
  @domain = UNSET_VALUE
13
14
  @ip = UNSET_VALUE
14
15
  @resolver = UNSET_VALUE
16
+ @keep_resolver_on_destroy = UNSET_VALUE
15
17
  @dnsmasqconf = UNSET_VALUE
16
18
  @disable = UNSET_VALUE
17
19
  end
18
20
 
19
21
  def finalize!
20
22
  @domain = nil if @domain == UNSET_VALUE
23
+ @keep_resolver_on_destroy = false if @keep_resolver_on_destroy == UNSET_VALUE
21
24
  @resolver = '/etc/resolver' if @resolver == UNSET_VALUE
22
25
  @dnsmasqconf = "/etc/dnsmasq.conf" if @dnsmasqconf == UNSET_VALUE
23
26
  @disable = false if @disable == UNSET_VALUE
@@ -64,8 +67,6 @@ module Vagrant
64
67
  @ip = nil
65
68
  end
66
69
 
67
-
68
-
69
70
  # verify resolver
70
71
  if @resolver
71
72
  errors << "directory '#{@resolver}' does not exist" unless Dir.exists? @resolver
@@ -8,6 +8,19 @@ class DnsmasqConf
8
8
  @filename = filename
9
9
  end
10
10
 
11
+ def self.flush_cache!
12
+ begin
13
+ # restart dnsmasq (if installed with homebrew)
14
+ system "launchctl unload /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist"
15
+ system "launchctl load /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist"
16
+
17
+ # @todo: call proc or try other fancy things to reload dnsmasq
18
+
19
+ rescue => e
20
+ # hmm ... i dont care
21
+ end
22
+ end
23
+
11
24
  def insert(domain, ip)
12
25
  raise ArgumentError, 'invalid domain instance' unless domain.is_a? Domain
13
26
  raise ArgumentError, 'invalid ip instance' unless ip.is_a? Ip
@@ -17,6 +30,8 @@ class DnsmasqConf
17
30
  File.open(@filename, 'a') { |file|
18
31
  file.write "\naddress=/#{domain.dotted}/#{ip.v4}"
19
32
  }
33
+
34
+ DnsmasqConf::flush_cache!
20
35
  end
21
36
 
22
37
  def includes?(domain)
@@ -32,6 +47,7 @@ class DnsmasqConf
32
47
  raise ArgumentError, 'invalid domain instance' unless domain.is_a? Domain
33
48
 
34
49
  delete_line_from_file(@filename, Regexp.new("address=/\.#{domain.name}"))
50
+ DnsmasqConf::flush_cache!
35
51
  end
36
52
 
37
53
 
@@ -19,13 +19,15 @@ class Resolver
19
19
 
20
20
  def insert(domain, ip)
21
21
  raise ArgumentError, 'invalid domain instance' unless domain.is_a? Domain
22
+ raise ArgumentError, 'invalid ip instance' unless ip.is_a? Ip
22
23
 
23
- delete(domain) if includes?(domain)
24
-
25
- puts "You may be asked for your password to insert #{@dirname}/#{domain.name} (ip: #{ip})" if @sudo
26
- system("#{'sudo' if @sudo} sh -c \"echo 'nameserver #{ip.v4}' >> #{@dirname}/#{domain.name}\"")
27
- Resolver::flush_cache!
24
+ unless includes?(domain, ip)
25
+ delete(domain)
28
26
 
27
+ puts "You may be asked for your password to insert #{@dirname}/#{domain.name} (ip: #{ip})" if @sudo
28
+ system("#{'sudo' if @sudo} sh -c \"echo 'nameserver #{ip.v4}' >> #{@dirname}/#{domain.name}\"")
29
+ Resolver::flush_cache!
30
+ end
29
31
  end
30
32
 
31
33
  def delete(domain)
@@ -38,10 +40,15 @@ class Resolver
38
40
  end
39
41
  end
40
42
 
41
- def includes?(domain)
43
+ def includes?(domain, with_ip = nil)
42
44
  raise ArgumentError, 'invalid domain instance' unless domain.is_a? Domain
43
45
 
44
- File.exists? "#{@dirname}/#{domain.name}"
46
+ unless with_ip.nil?
47
+ raise ArgumentError, 'invalid ip instance' unless with_ip.is_a? Ip
48
+ File.exists?("#{@dirname}/#{domain.name}") && IO.read("#{@dirname}/#{domain.name}").strip == "nameserver #{with_ip.v4}"
49
+ else
50
+ File.exists? "#{@dirname}/#{domain.name}"
51
+ end
45
52
  end
46
53
 
47
54
  end
@@ -1,5 +1,5 @@
1
1
  module Vagrant
2
2
  module Dnsmasq
3
- VERSION = "0.0.6"
3
+ VERSION = "0.0.7"
4
4
  end
5
5
  end
@@ -41,6 +41,17 @@ describe Resolver do
41
41
  @res.includes?(@domain).should eq(false)
42
42
  end
43
43
 
44
+ it "#includes? should verify content of domain file" do
45
+ @res.includes?(@domain).should eq(false)
46
+ @res.includes?(@domain, @ip).should eq(false)
47
+
48
+ @res.insert(@domain, @ip)
49
+
50
+ @res.includes?(@domain).should eq(true)
51
+ @res.includes?(@domain, @ip).should eq(true)
52
+ @res.includes?(@domain, Ip.new('10.10.10.11')).should eq(false)
53
+ end
54
+
44
55
  it "#insert should raise if domain is nil" do
45
56
  expect {
46
57
  @res.insert(nil, nil)
@@ -34,7 +34,10 @@ Vagrant.configure('2') do |config|
34
34
  # overwrite default location for /etc/resolver directory
35
35
  # config.dnsmasq.resolver = '/etc/resolver'
36
36
 
37
- # overwrite default location for /usr/local/etc/dnsmasq.conf
37
+ # 'vagrant destroy' does not delete /etc/resolver nameserver file, defaults to false
38
+ # config.dnsmasq.keep_resolver_on_destroy = true
39
+
40
+ # overwrite default location for /etc/dnsmasq.conf
38
41
  brew_prefix = `brew --prefix`.strip
39
42
  config.dnsmasq.dnsmasqconf = brew_prefix + '/etc/dnsmasq.conf'
40
43
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-dnsmasq
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - mattes
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-06-25 00:00:00.000000000 Z
11
+ date: 2013-06-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler