vagrant-dnsmasq 0.0.5 → 0.0.6
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.
- checksums.yaml +4 -4
- data/.travis.yml +4 -0
- data/Gemfile.lock +11 -1
- data/README.md +32 -13
- data/Rakefile +5 -0
- data/lib/vagrant-dnsmasq/actions.rb +61 -43
- data/lib/vagrant-dnsmasq/config.rb +63 -16
- data/lib/vagrant-dnsmasq/includes/{Dnsmasq.class.rb → DnsmasqConf.class.rb} +0 -0
- data/lib/vagrant-dnsmasq/includes/Domain.class.rb +3 -4
- data/lib/vagrant-dnsmasq/includes/Ip.class.rb +6 -2
- data/lib/vagrant-dnsmasq/includes/Resolver.class.rb +7 -6
- data/lib/vagrant-dnsmasq/includes/helper.rb +3 -4
- data/lib/vagrant-dnsmasq/version.rb +1 -1
- data/lib/vagrant-dnsmasq.rb +13 -6
- data/test/Dnsmasq.class.spec.rb +63 -0
- data/test/Domain.class.spec.rb +61 -0
- data/test/Ip.class.spec.rb +43 -0
- data/test/Resolver.class.spec.rb +62 -0
- data/test/Vagrantfile +27 -10
- data/test/helper.spec.rb +34 -0
- data/vagrant-dnsmasq.gemspec +1 -0
- metadata +28 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 835c9917b38e165f4a5b04c593c11d8ad88c1b45
|
4
|
+
data.tar.gz: 2a0dd01d6baafd68a189d3526f4db622c839d53f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f5918efdad10112169ddae03bbb89b23f2cdd7805336867a196ffb0a69817e49fa8f6d12fa7fcade4bacf8a527cbe69adc35f0a4cdc9329621745e7f9c651795
|
7
|
+
data.tar.gz: e62960e4ec379a5302b204d3f3ab35911094d32fb85214b4810adafbb5b76ea8c810776e8fbcf31507aba21f65eaf278c237df467347d1953c04f0c4ce3effb3
|
data/.travis.yml
ADDED
data/Gemfile.lock
CHANGED
@@ -15,13 +15,14 @@ GIT
|
|
15
15
|
PATH
|
16
16
|
remote: .
|
17
17
|
specs:
|
18
|
-
vagrant-dnsmasq (0.0.
|
18
|
+
vagrant-dnsmasq (0.0.6)
|
19
19
|
|
20
20
|
GEM
|
21
21
|
remote: https://rubygems.org/
|
22
22
|
specs:
|
23
23
|
childprocess (0.3.9)
|
24
24
|
ffi (~> 1.0, >= 1.0.11)
|
25
|
+
diff-lcs (1.2.4)
|
25
26
|
erubis (2.7.0)
|
26
27
|
ffi (1.9.0)
|
27
28
|
i18n (0.6.4)
|
@@ -31,6 +32,14 @@ GEM
|
|
31
32
|
net-ssh (>= 2.6.5)
|
32
33
|
net-ssh (2.6.7)
|
33
34
|
rake (10.1.0)
|
35
|
+
rspec (2.13.0)
|
36
|
+
rspec-core (~> 2.13.0)
|
37
|
+
rspec-expectations (~> 2.13.0)
|
38
|
+
rspec-mocks (~> 2.13.0)
|
39
|
+
rspec-core (2.13.1)
|
40
|
+
rspec-expectations (2.13.0)
|
41
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
42
|
+
rspec-mocks (2.13.1)
|
34
43
|
|
35
44
|
PLATFORMS
|
36
45
|
ruby
|
@@ -38,5 +47,6 @@ PLATFORMS
|
|
38
47
|
DEPENDENCIES
|
39
48
|
bundler (~> 1.3)
|
40
49
|
rake
|
50
|
+
rspec
|
41
51
|
vagrant!
|
42
52
|
vagrant-dnsmasq!
|
data/README.md
CHANGED
@@ -1,12 +1,14 @@
|
|
1
|
-
vagrant-dnsmasq
|
2
|
-
===============
|
1
|
+
# vagrant-dnsmasq [](https://travis-ci.org/mattes/vagrant-dnsmasq)
|
3
2
|
|
4
3
|
A Dnsmasq Vagrant plugin that manages the dnsmasq.conf file and /etc/resolver directory on your host system.
|
5
4
|
|
6
5
|
## Prerequisites
|
7
|
-
*
|
8
|
-
* [
|
9
|
-
|
6
|
+
* [Vagrant](http://www.vagrantup.com)
|
7
|
+
* [Dnsmasq](http://www.thekelleys.org.uk/dnsmasq/doc.html)
|
8
|
+
|
9
|
+
Easily install dnsmasq with [brew](http://mxcl.github.io/homebrew/) under Mac OS:
|
10
|
+
```brew install dnsmasq```
|
11
|
+
|
10
12
|
|
11
13
|
## Installation
|
12
14
|
```
|
@@ -15,19 +17,36 @@ vagrant plugin install vagrant-dnsmasq
|
|
15
17
|
|
16
18
|
## Usage
|
17
19
|
in your Vagrantfile
|
18
|
-
```
|
19
|
-
#
|
20
|
+
```ruby
|
21
|
+
# set domain ending (required)
|
22
|
+
# adding this line enables dnsmasq handling
|
23
|
+
config.dnsmasq.domain = '.dev'
|
20
24
|
|
21
|
-
# enable dnsmasq?
|
22
|
-
# set to false or delete line to disable dnsmasq handling
|
23
|
-
config.dnsmasq.enable = true
|
24
25
|
|
25
|
-
#
|
26
|
-
config.dnsmasq.domain = '.dev'
|
26
|
+
# optional configuration ...
|
27
27
|
|
28
28
|
# this plugin runs 'hostname -I' on the guest machine to obtain
|
29
|
-
# the guest ip address. you
|
29
|
+
# the guest ip address. you can overwrite this behaviour.
|
30
30
|
# config.dnsmasq.ip = '192.168.59.100'
|
31
|
+
|
32
|
+
# config.dnsmasq.ip = proc do |guest_machine|
|
33
|
+
# guest_machine.communicate.sudo("command to obtain ip somehow") do |type, data|
|
34
|
+
# # return something like '192.168.59.100' or ['192.168.59.100', '192.168.59.103']
|
35
|
+
# end
|
36
|
+
# end
|
37
|
+
|
38
|
+
# this will prompt you during 'vagrant up' to choose an IP
|
39
|
+
# config.dnsmasq.ip = ['192.168.59.100', '192.168.59.103']
|
40
|
+
|
41
|
+
# overwrite default location for /etc/resolver directory
|
42
|
+
# config.dnsmasq.resolver = '/etc/resolver'
|
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'
|
47
|
+
|
48
|
+
# disable dnsmasq handling
|
49
|
+
# config.dnsmasq.disable = true
|
31
50
|
```
|
32
51
|
|
33
52
|
## Uninstall
|
data/Rakefile
CHANGED
@@ -3,55 +3,65 @@ module Vagrant
|
|
3
3
|
|
4
4
|
class Up
|
5
5
|
def initialize(app, env)
|
6
|
-
inc_path = Pathname.new(File.expand_path("../includes", __FILE__))
|
7
|
-
require inc_path.join("Domain.class.rb")
|
8
|
-
require inc_path.join("Ip.class.rb")
|
9
|
-
require inc_path.join("Dnsmasq.class.rb")
|
10
|
-
require inc_path.join("Resolver.class.rb")
|
11
|
-
require inc_path.join("helper.rb")
|
12
|
-
|
13
6
|
@app = app
|
14
7
|
@machine = env[:machine]
|
15
|
-
@
|
8
|
+
@ips = nil
|
16
9
|
end
|
17
10
|
|
18
11
|
def call(env)
|
19
12
|
if @machine.config.dnsmasq.enabled?
|
13
|
+
# env[:ui].info "Dnsmasq handler actived"
|
14
|
+
|
15
|
+
@ip = @machine.config.dnsmasq.ip
|
16
|
+
|
17
|
+
# is a proc?
|
18
|
+
if @ip.is_a? Proc
|
19
|
+
ips = @ip.call(@machine)
|
20
|
+
ips = [ips] unless ips.is_a? Array
|
21
|
+
ips.map!{|ip| begin Ip.new(ip) rescue nil end}.compact! # dismiss invalid ips
|
22
|
+
@ip = ips
|
23
|
+
end
|
20
24
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
25
|
+
if @ip.is_a?(Array) && @ip.count > 0
|
26
|
+
# @ip is an array with domain instances ...
|
27
|
+
|
28
|
+
if @ip.count > 1
|
29
|
+
# prompt: choose ip
|
30
|
+
ask = true
|
31
|
+
while(ask)
|
32
|
+
env[:ui].info "Dnsmasq handler asks: Which IP would you like to use?"
|
33
|
+
i = 0
|
34
|
+
@ip.each do |ip|
|
35
|
+
i += 1
|
36
|
+
env[:ui].info "(#{i}) #{ip.v4}"
|
37
|
+
end
|
38
|
+
env[:ui].info "Please type number [1-#{i}]: "
|
39
|
+
answer = $stdin.gets.strip.to_i - 1
|
40
|
+
use_ip = @ip.at(answer)
|
41
|
+
ask = false unless use_ip.nil?
|
42
|
+
end
|
43
|
+
|
44
|
+
else
|
45
|
+
use_ip = @ip[0]
|
29
46
|
end
|
30
|
-
@ip.map!{|ip| begin Ip.new(ip) rescue nil end}.compact!
|
31
|
-
end
|
32
47
|
|
33
|
-
|
34
|
-
if @ip.count > 0
|
48
|
+
# use ip to update dnsmasq.conf and /etc/resolver
|
35
49
|
|
36
50
|
# update dnsmasq.conf
|
37
|
-
|
38
|
-
|
39
|
-
dnsmasq_conf_file = brew_prefix + "/etc/dnsmasq.conf"
|
40
|
-
|
41
|
-
dnsmasq = DnsmasqConf.new(dnsmasq_conf_file)
|
42
|
-
@ip.each do |ip|
|
43
|
-
dnsmasq.insert(@machine.config.dnsmasq.domain, ip)
|
44
|
-
end
|
51
|
+
dnsmasq = DnsmasqConf.new(@machine.config.dnsmasq.dnsmasqconf)
|
52
|
+
dnsmasq.insert(@machine.config.dnsmasq.domain, use_ip)
|
45
53
|
|
46
54
|
# update /etc/resolver
|
47
|
-
resolver = Resolver.new(
|
48
|
-
@
|
49
|
-
resolver.insert(@machine.config.dnsmasq.domain, ip)
|
50
|
-
end
|
55
|
+
resolver = Resolver.new(@machine.config.dnsmasq.resolver, true) # true for sudo
|
56
|
+
resolver.insert(@machine.config.dnsmasq.domain, use_ip)
|
51
57
|
|
52
|
-
env[:ui].
|
53
|
-
|
58
|
+
env[:ui].success "Dnsmasq handler set IP '#{use_ip}' for domain '#{@machine.config.dnsmasq.domain.dotted}'"
|
59
|
+
|
60
|
+
else
|
61
|
+
env[:ui].warn "Dnsmasq handler was not able to determine an IP address"
|
54
62
|
end
|
63
|
+
|
64
|
+
@app.call(env)
|
55
65
|
end
|
56
66
|
end
|
57
67
|
end
|
@@ -59,19 +69,27 @@ module Vagrant
|
|
59
69
|
|
60
70
|
class Destroy
|
61
71
|
def initialize(app, env)
|
62
|
-
inc_path = Pathname.new(File.expand_path("../includes", __FILE__))
|
63
|
-
require inc_path.join("Domain.class.rb")
|
64
|
-
require inc_path.join("Ip.class.rb")
|
65
|
-
require inc_path.join("Dnsmasq.class.rb")
|
66
|
-
require inc_path.join("Resolver.class.rb")
|
67
|
-
require inc_path.join("helper.rb")
|
68
|
-
|
69
72
|
@app = app
|
73
|
+
@machine = env[:machine]
|
70
74
|
end
|
71
75
|
|
72
76
|
def call(env)
|
73
|
-
|
74
|
-
|
77
|
+
if @machine.config.dnsmasq.enabled?
|
78
|
+
|
79
|
+
# remove records from dnsmasq.conf and /etc/resolver
|
80
|
+
|
81
|
+
# update dnsmasq.conf
|
82
|
+
dnsmasq = DnsmasqConf.new(@machine.config.dnsmasq.dnsmasqconf)
|
83
|
+
dnsmasq.delete(@machine.config.dnsmasq.domain)
|
84
|
+
|
85
|
+
# update /etc/resolver
|
86
|
+
resolver = Resolver.new(@machine.config.dnsmasq.resolver, true) # true for sudo
|
87
|
+
resolver.delete(@machine.config.dnsmasq.domain)
|
88
|
+
|
89
|
+
env[:ui].success "Dnsmasq handler removed domain '#{@machine.config.dnsmasq.domain}'"
|
90
|
+
|
91
|
+
@app.call(env)
|
92
|
+
end
|
75
93
|
end
|
76
94
|
end
|
77
95
|
|
@@ -2,34 +2,81 @@ module Vagrant
|
|
2
2
|
module Dnsmasq
|
3
3
|
class Config < Vagrant.plugin("2", :config)
|
4
4
|
|
5
|
-
attr_accessor :enable
|
6
5
|
attr_accessor :domain
|
7
6
|
attr_accessor :ip
|
8
|
-
|
9
|
-
|
7
|
+
attr_accessor :resolver
|
8
|
+
attr_accessor :dnsmasqconf
|
9
|
+
attr_accessor :disable
|
10
10
|
|
11
11
|
def initialize
|
12
|
-
inc_path = Pathname.new(File.expand_path("../includes", __FILE__))
|
13
|
-
require inc_path.join("Domain.class.rb")
|
14
|
-
require inc_path.join("Ip.class.rb")
|
15
|
-
|
16
|
-
@enable = UNSET_VALUE
|
17
12
|
@domain = UNSET_VALUE
|
18
13
|
@ip = UNSET_VALUE
|
14
|
+
@resolver = UNSET_VALUE
|
15
|
+
@dnsmasqconf = UNSET_VALUE
|
16
|
+
@disable = UNSET_VALUE
|
19
17
|
end
|
20
18
|
|
21
19
|
def finalize!
|
22
|
-
@enable = false if @enable == UNSET_VALUE
|
23
20
|
@domain = nil if @domain == UNSET_VALUE
|
24
|
-
@
|
21
|
+
@resolver = '/etc/resolver' if @resolver == UNSET_VALUE
|
22
|
+
@dnsmasqconf = "/etc/dnsmasq.conf" if @dnsmasqconf == UNSET_VALUE
|
23
|
+
@disable = false if @disable == UNSET_VALUE
|
24
|
+
|
25
|
+
# default way to obtain ip address
|
26
|
+
if @ip == UNSET_VALUE
|
27
|
+
@ip = proc do |guest_machine|
|
28
|
+
ips = nil
|
29
|
+
guest_machine.communicate.sudo("hostname -I") do |type, data|
|
30
|
+
ips = data.scan /[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/
|
31
|
+
end
|
32
|
+
ips
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
def enabled?
|
39
|
+
not @disable and not @domain.nil?
|
40
|
+
end
|
41
|
+
|
42
|
+
def validate(machine)
|
43
|
+
return unless enabled?
|
44
|
+
|
45
|
+
errors = []
|
46
|
+
|
47
|
+
# verify @disable
|
48
|
+
if @disable != true and @disable != false then errors << 'invalid disable setting' end
|
49
|
+
|
50
|
+
# verify domain
|
51
|
+
begin @domain = Domain.new @domain; rescue => e; errors << e.message end
|
52
|
+
|
53
|
+
# verify ip
|
54
|
+
if @ip.is_a? Array
|
55
|
+
@ip.map!{|ip| begin Ip.new(ip); rescue => e; errors << e.message end}
|
56
|
+
|
57
|
+
elsif @ip.is_a? String
|
58
|
+
begin @ip = Ip.new(@ip); rescue => e; errors << e.message end
|
59
|
+
@ip = [@ip]
|
60
|
+
|
61
|
+
elsif @ip.is_a? Proc
|
62
|
+
# okay, there is nothing to verify at the moment
|
63
|
+
else
|
64
|
+
@ip = nil
|
65
|
+
end
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
# verify resolver
|
70
|
+
if @resolver
|
71
|
+
errors << "directory '#{@resolver}' does not exist" unless Dir.exists? @resolver
|
72
|
+
end
|
25
73
|
|
26
|
-
#
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
@ip = [@ip] unless @ip.kind_of? Array
|
31
|
-
@ip.map!{|ip| begin Ip.new(ip) rescue nil end}.compact!
|
74
|
+
# verify dnsmasqconf
|
75
|
+
if @dnsmasqconf
|
76
|
+
errors << "file '#{@dnsmasqconf}' does not exist" unless File.exists? @dnsmasqconf
|
77
|
+
end
|
32
78
|
|
79
|
+
return { 'Dnsmasq configuration' => errors }
|
33
80
|
end
|
34
81
|
|
35
82
|
end
|
File without changes
|
@@ -6,11 +6,10 @@ class Domain
|
|
6
6
|
@name = nil
|
7
7
|
|
8
8
|
if name.is_a? Domain
|
9
|
-
|
10
|
-
return
|
9
|
+
name = name.dotted
|
11
10
|
end
|
12
11
|
|
13
|
-
raise ArgumentError, "no domain name given"
|
12
|
+
raise ArgumentError, "no domain name given" if name.blank?
|
14
13
|
|
15
14
|
# parse domain name ...
|
16
15
|
name = name.to_s
|
@@ -21,7 +20,7 @@ class Domain
|
|
21
20
|
end
|
22
21
|
|
23
22
|
def self.valid?(name)
|
24
|
-
Domain::MATCH.match(name.downcase)
|
23
|
+
if not name.blank? and Domain::MATCH.match(name.downcase) then true else false end
|
25
24
|
end
|
26
25
|
|
27
26
|
def dotted
|
@@ -1,16 +1,20 @@
|
|
1
1
|
class Ip
|
2
2
|
|
3
|
-
MATCH_IP4 =
|
3
|
+
MATCH_IP4 = /^(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[0-9]{1,2})(\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[0-9]{1,2})){3}$/
|
4
4
|
|
5
5
|
def initialize(ipv4)
|
6
6
|
|
7
|
+
if ipv4.is_a? Ip
|
8
|
+
ipv4 = ipv4.v4
|
9
|
+
end
|
10
|
+
|
7
11
|
raise ArgumentError, "IPv4 '#{ipv4}' must match #{MATCH_IP4}" unless Ip::ipv4_valid?(ipv4)
|
8
12
|
|
9
13
|
@ipv4 = ipv4
|
10
14
|
end
|
11
15
|
|
12
16
|
def self.ipv4_valid?(ipv4)
|
13
|
-
Ip::MATCH_IP4.match(ipv4)
|
17
|
+
if not ipv4.blank? and Ip::MATCH_IP4.match(ipv4) then true else false end
|
14
18
|
end
|
15
19
|
|
16
20
|
def v4
|
@@ -2,14 +2,15 @@ class Resolver
|
|
2
2
|
|
3
3
|
attr_reader :dirname
|
4
4
|
|
5
|
-
def initialize(dirname)
|
5
|
+
def initialize(dirname, sudo = false)
|
6
6
|
raise ArgumentError, 'wrong dirname' if dirname.blank?
|
7
7
|
raise IOError unless Dir.exists? dirname
|
8
8
|
@dirname = dirname
|
9
|
+
@sudo = sudo
|
9
10
|
end
|
10
11
|
|
11
12
|
def self.flush_cache!
|
12
|
-
system 'sudo dscacheutil -flushcache'
|
13
|
+
system 'sudo dscacheutil -flushcache' if @sudo
|
13
14
|
end
|
14
15
|
|
15
16
|
def list
|
@@ -21,8 +22,8 @@ class Resolver
|
|
21
22
|
|
22
23
|
delete(domain) if includes?(domain)
|
23
24
|
|
24
|
-
puts "You may be asked for your password to insert #{@dirname}/#{domain.name} (ip: #{ip})"
|
25
|
-
system("sudo sh -c \"echo 'nameserver #{ip.v4}' >> #{@dirname}/#{domain.name}\"")
|
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}\"")
|
26
27
|
Resolver::flush_cache!
|
27
28
|
|
28
29
|
end
|
@@ -31,8 +32,8 @@ class Resolver
|
|
31
32
|
raise ArgumentError, 'invalid domain instance' unless domain.is_a? Domain
|
32
33
|
|
33
34
|
if includes? domain
|
34
|
-
puts "You may be asked for your password to delete #{@dirname}/#{domain.name}"
|
35
|
-
system("sudo rm -rf #{@dirname}/#{domain.name}")
|
35
|
+
puts "You may be asked for your password to delete #{@dirname}/#{domain.name}" if @sudo
|
36
|
+
system("#{'sudo' if @sudo} rm -rf #{@dirname}/#{domain.name}")
|
36
37
|
Resolver::flush_cache!
|
37
38
|
end
|
38
39
|
end
|
@@ -1,10 +1,10 @@
|
|
1
|
-
def delete_line_from_file(filename,
|
1
|
+
def delete_line_from_file(filename, regex)
|
2
2
|
# create empty file string
|
3
3
|
tmp_file = ''
|
4
4
|
|
5
5
|
# iterate over every line and skip lines that match
|
6
6
|
File.open(filename, "r").each_line do |l|
|
7
|
-
tmp_file += l unless
|
7
|
+
tmp_file += l unless regex.match(l.strip)
|
8
8
|
end
|
9
9
|
|
10
10
|
# write tmp file without matching lines
|
@@ -14,9 +14,8 @@ def delete_line_from_file(filename, line)
|
|
14
14
|
tmp_file = nil
|
15
15
|
end
|
16
16
|
|
17
|
-
|
18
17
|
class Object
|
19
18
|
def blank?
|
20
|
-
|
19
|
+
respond_to?(:empty?) ? empty? : !self
|
21
20
|
end
|
22
21
|
end
|
data/lib/vagrant-dnsmasq.rb
CHANGED
@@ -1,17 +1,24 @@
|
|
1
1
|
module Vagrant
|
2
2
|
module Dnsmasq
|
3
|
-
|
4
3
|
class Plugin < Vagrant.plugin("2")
|
5
4
|
name "vagrant-dnsmasq"
|
5
|
+
description "A Dnsmasq Vagrant plugin that manages the dnsmasq.conf file and /etc/resolver directory on your host system."
|
6
|
+
|
7
|
+
lib_path = Pathname.new(File.expand_path("../vagrant-dnsmasq", __FILE__))
|
8
|
+
require lib_path.join("actions")
|
9
|
+
|
10
|
+
inc_path = Pathname.new(File.expand_path("../vagrant-dnsmasq/includes", __FILE__))
|
11
|
+
require inc_path.join("Domain.class.rb")
|
12
|
+
require inc_path.join("Ip.class.rb")
|
13
|
+
require inc_path.join("DnsmasqConf.class.rb")
|
14
|
+
require inc_path.join("Resolver.class.rb")
|
15
|
+
require inc_path.join("helper.rb")
|
6
16
|
|
7
17
|
config "dnsmasq" do
|
8
|
-
require "
|
18
|
+
require lib_path.join("config")
|
9
19
|
Config
|
10
20
|
end
|
11
21
|
|
12
|
-
lib_path = Pathname.new(File.expand_path("../vagrant-dnsmasq", __FILE__))
|
13
|
-
require lib_path.join("actions")
|
14
|
-
|
15
22
|
action_hook(:dnsmasq, :machine_action_up) do |hook|
|
16
23
|
hook.append(Vagrant::Action::Up)
|
17
24
|
end
|
@@ -23,4 +30,4 @@ module Vagrant
|
|
23
30
|
end
|
24
31
|
end
|
25
32
|
|
26
|
-
end
|
33
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require './lib/vagrant-dnsmasq/includes/DnsmasqConf.class.rb'
|
2
|
+
require './lib/vagrant-dnsmasq/includes/Domain.class.rb'
|
3
|
+
require './lib/vagrant-dnsmasq/includes/Ip.class.rb'
|
4
|
+
|
5
|
+
random = (0...50).map{ ('a'..'z').to_a[rand(26)] }.join
|
6
|
+
|
7
|
+
describe "At first" do
|
8
|
+
it "should fail if there is no conf file" do
|
9
|
+
expect {
|
10
|
+
DnsmasqConf.new("/tmp/some-non-existing-file-#{random}-h25hch345b3k5")
|
11
|
+
}.to raise_error IOError
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
|
16
|
+
describe DnsmasqConf do
|
17
|
+
before(:each) do
|
18
|
+
system "touch /tmp/dnsmasq-conf-#{random}"
|
19
|
+
@dnsm = DnsmasqConf.new("/tmp/dnsmasq-conf-#{random}")
|
20
|
+
@domain = Domain.new('.foobar')
|
21
|
+
@ip = Ip.new('10.10.10.10')
|
22
|
+
end
|
23
|
+
|
24
|
+
after(:each) do
|
25
|
+
system("rm /tmp/dnsmasq-conf-#{random}") if File.exists? "/tmp/dnsmasq-conf-#{random}"
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should insert a domain" do
|
29
|
+
@dnsm.insert(@domain, @ip)
|
30
|
+
@dnsm.includes?(@domain).should eq(true)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should return false if no domain is found" do
|
34
|
+
@dnsm.includes?(Domain.new('.doesntexist')).should eq(false)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should delete a domain" do
|
38
|
+
@dnsm.includes?(@domain).should eq(false)
|
39
|
+
@dnsm.insert(@domain, @ip)
|
40
|
+
@dnsm.includes?(@domain).should eq(true)
|
41
|
+
@dnsm.delete(@domain)
|
42
|
+
@dnsm.includes?(@domain).should eq(false)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "#insert should raise if domain is nil" do
|
46
|
+
expect {
|
47
|
+
@dnsm.insert(nil, nil)
|
48
|
+
}.to raise_error ArgumentError
|
49
|
+
end
|
50
|
+
|
51
|
+
it "#delete should raise if domain is nil" do
|
52
|
+
expect {
|
53
|
+
@dnsm.delete(nil)
|
54
|
+
}.to raise_error ArgumentError
|
55
|
+
end
|
56
|
+
|
57
|
+
it "#includes? should raise if domain is nil" do
|
58
|
+
expect {
|
59
|
+
@dnsm.includes?(nil)
|
60
|
+
}.to raise_error ArgumentError
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require './lib/vagrant-dnsmasq/includes/Domain.class.rb'
|
2
|
+
|
3
|
+
describe Domain do
|
4
|
+
|
5
|
+
it "should return normal domain" do
|
6
|
+
Domain.new('foobar').name.should eq('foobar')
|
7
|
+
Domain.new('.foobar').name.should eq('foobar')
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should return dotted domain" do
|
11
|
+
Domain.new('foobar').dotted.should eq('.foobar')
|
12
|
+
Domain.new('.foobar').dotted.should eq('.foobar')
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should return valid domain if domain is passed" do
|
16
|
+
Domain.new(Domain.new('foobar')).name.should eq('foobar')
|
17
|
+
Domain.new(Domain.new('.foobar')).name.should eq('foobar')
|
18
|
+
Domain.new(Domain.new('foobar')).dotted.should eq('.foobar')
|
19
|
+
Domain.new(Domain.new('.foobar')).dotted.should eq('.foobar')
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should make the domain lowercase" do
|
23
|
+
Domain.new('FOOBAR').name.should eq('foobar')
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should fail for invalid domains" do
|
27
|
+
expect {
|
28
|
+
Domain.new('foo1')
|
29
|
+
}.to raise_error ArgumentError
|
30
|
+
|
31
|
+
expect {
|
32
|
+
Domain.new('foo_')
|
33
|
+
}.to raise_error ArgumentError
|
34
|
+
|
35
|
+
expect {
|
36
|
+
Domain.new('foo.')
|
37
|
+
}.to raise_error ArgumentError
|
38
|
+
|
39
|
+
expect {
|
40
|
+
Domain.new('foo-')
|
41
|
+
}.to raise_error ArgumentError
|
42
|
+
|
43
|
+
expect {
|
44
|
+
Domain.new('')
|
45
|
+
}.to raise_error ArgumentError
|
46
|
+
|
47
|
+
expect {
|
48
|
+
Domain.new(nil)
|
49
|
+
}.to raise_error ArgumentError
|
50
|
+
end
|
51
|
+
|
52
|
+
it "#valid? should fail for invalid domains" do
|
53
|
+
Domain::valid?('foo1').should eq(false)
|
54
|
+
Domain::valid?('foo_').should eq(false)
|
55
|
+
Domain::valid?('foo.').should eq(false)
|
56
|
+
Domain::valid?('foo-').should eq(false)
|
57
|
+
Domain::valid?('').should eq(false)
|
58
|
+
Domain::valid?(nil).should eq(false)
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require './lib/vagrant-dnsmasq/includes/Ip.class.rb'
|
2
|
+
|
3
|
+
describe Ip do
|
4
|
+
|
5
|
+
it "should return ipv4" do
|
6
|
+
Ip.new('10.10.10.10').v4.should eq('10.10.10.10')
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should return ipv4 if ip is passed" do
|
10
|
+
Ip.new(Ip.new('10.10.10.10')).v4.should eq('10.10.10.10')
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should fail for invalid ips" do
|
14
|
+
expect {
|
15
|
+
Ip.new('10.10.10')
|
16
|
+
}.to raise_error ArgumentError
|
17
|
+
|
18
|
+
expect {
|
19
|
+
Ip.new('300.0.0.1')
|
20
|
+
}.to raise_error ArgumentError
|
21
|
+
|
22
|
+
expect {
|
23
|
+
Ip.new('10-10-10-10')
|
24
|
+
}.to raise_error ArgumentError
|
25
|
+
|
26
|
+
expect {
|
27
|
+
Ip.new('')
|
28
|
+
}.to raise_error ArgumentError
|
29
|
+
|
30
|
+
expect {
|
31
|
+
Ip.new(nil)
|
32
|
+
}.to raise_error ArgumentError
|
33
|
+
end
|
34
|
+
|
35
|
+
it "#valid? should fail for invalid ips" do
|
36
|
+
Ip::ipv4_valid?('10.10.10').should eq(false)
|
37
|
+
Ip::ipv4_valid?('300.0.0.1').should eq(false)
|
38
|
+
Ip::ipv4_valid?('10-10-10-10').should eq(false)
|
39
|
+
Ip::ipv4_valid?('').should eq(false)
|
40
|
+
Ip::ipv4_valid?(nil).should eq(false)
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require './lib/vagrant-dnsmasq/includes/Resolver.class.rb'
|
2
|
+
require './lib/vagrant-dnsmasq/includes/Domain.class.rb'
|
3
|
+
require './lib/vagrant-dnsmasq/includes/Ip.class.rb'
|
4
|
+
|
5
|
+
random = (0...50).map{ ('a'..'z').to_a[rand(26)] }.join
|
6
|
+
|
7
|
+
describe "At first" do
|
8
|
+
it "should fail if there is no dir" do
|
9
|
+
expect {
|
10
|
+
Resolver.new("/tmp/some-non-existing-dir-#{random}-j2335n3kjfs3ap")
|
11
|
+
}.to raise_error IOError
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe Resolver do
|
16
|
+
before(:each) do
|
17
|
+
system("mkdir -p /tmp/resolver-dir-#{random}")
|
18
|
+
@res = Resolver.new("/tmp/resolver-dir-#{random}")
|
19
|
+
@domain = Domain.new('.foobar')
|
20
|
+
@ip = Ip.new('10.10.10.10')
|
21
|
+
end
|
22
|
+
|
23
|
+
after(:each) do
|
24
|
+
system("rm -R /tmp/resolver-dir-#{random}") if File.exists? "/tmp/resolver-dir-#{random}"
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should insert a domain" do
|
28
|
+
@res.insert(@domain, @ip)
|
29
|
+
@res.includes?(@domain).should eq(true)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should return false if no domain is found" do
|
33
|
+
@res.includes?(Domain.new('.doesntexist')).should eq(false)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should delete a domain" do
|
37
|
+
@res.includes?(@domain).should eq(false)
|
38
|
+
@res.insert(@domain, @ip)
|
39
|
+
@res.includes?(@domain).should eq(true)
|
40
|
+
@res.delete(@domain)
|
41
|
+
@res.includes?(@domain).should eq(false)
|
42
|
+
end
|
43
|
+
|
44
|
+
it "#insert should raise if domain is nil" do
|
45
|
+
expect {
|
46
|
+
@res.insert(nil, nil)
|
47
|
+
}.to raise_error ArgumentError
|
48
|
+
end
|
49
|
+
|
50
|
+
it "#delete should raise if domain is nil" do
|
51
|
+
expect {
|
52
|
+
@res.delete(nil)
|
53
|
+
}.to raise_error ArgumentError
|
54
|
+
end
|
55
|
+
|
56
|
+
it "#includes? should raise if domain is nil" do
|
57
|
+
expect {
|
58
|
+
@res.includes?(nil)
|
59
|
+
}.to raise_error ArgumentError
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
data/test/Vagrantfile
CHANGED
@@ -1,27 +1,44 @@
|
|
1
1
|
# -*- mode: ruby -*-
|
2
2
|
# vi: set ft=ruby :
|
3
3
|
|
4
|
-
Vagrant.require_plugin('vagrant-dnsmasq')
|
5
|
-
|
6
4
|
Vagrant.configure('2') do |config|
|
7
5
|
config.vm.box = 'precise64'
|
8
6
|
config.vm.box_url = "http://files.vagrantup.com/precise64.box"
|
9
7
|
|
8
|
+
# dnsmasq works with both, private network as well as public network
|
10
9
|
# config.vm.network :private_network, ip: "192.168.59.100"
|
11
10
|
config.vm.network :public_network
|
12
11
|
|
13
12
|
|
14
13
|
# dnsmasq ...
|
15
14
|
|
16
|
-
#
|
17
|
-
#
|
18
|
-
config.dnsmasq.
|
15
|
+
# set domain ending (required)
|
16
|
+
# adding this line enables dnsmasq handling
|
17
|
+
config.dnsmasq.domain = '.dnsmasqplugintest'
|
19
18
|
|
20
|
-
#
|
21
|
-
config.dnsmasq.domain = '.dev'
|
19
|
+
# optional configuration ...
|
22
20
|
|
23
21
|
# this plugin runs 'hostname -I' on the guest machine to obtain
|
24
|
-
# the guest ip address. you
|
25
|
-
# config.dnsmasq.ip = '192.168.59.
|
22
|
+
# the guest ip address. you can overwrite this behaviour.
|
23
|
+
# config.dnsmasq.ip = '192.168.59.109'
|
24
|
+
|
25
|
+
# config.dnsmasq.ip = proc do |guest_machine|
|
26
|
+
# guest_machine.communicate.sudo("command to obtain ip somehow") do |type, data|
|
27
|
+
# # return something like '192.168.59.100' or ['192.168.59.100', '192.168.59.103']
|
28
|
+
# end
|
29
|
+
# end
|
30
|
+
|
31
|
+
# this will prompt you during 'vagrant up' to choose an IP
|
32
|
+
# config.dnsmasq.ip = ['192.168.59.100', '192.168.59.103']
|
33
|
+
|
34
|
+
# overwrite default location for /etc/resolver directory
|
35
|
+
# config.dnsmasq.resolver = '/etc/resolver'
|
36
|
+
|
37
|
+
# overwrite default location for /usr/local/etc/dnsmasq.conf
|
38
|
+
brew_prefix = `brew --prefix`.strip
|
39
|
+
config.dnsmasq.dnsmasqconf = brew_prefix + '/etc/dnsmasq.conf'
|
40
|
+
|
41
|
+
# disable dnsmasq handling
|
42
|
+
# config.dnsmasq.disable = true
|
26
43
|
|
27
|
-
end
|
44
|
+
end
|
data/test/helper.spec.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require './lib/vagrant-dnsmasq/includes/helper.rb'
|
2
|
+
|
3
|
+
random = (0...50).map{ ('a'..'z').to_a[rand(26)] }.join
|
4
|
+
|
5
|
+
|
6
|
+
describe "Helper" do
|
7
|
+
|
8
|
+
it "#delete_line_from_file should delete a line from a file" do
|
9
|
+
tmp_file = "/tmp/helper-delete-line-from-file-test-#{random}"
|
10
|
+
system "echo \"line 1\n another line\n\na line after an empty line \nline5\" > #{tmp_file}"
|
11
|
+
delete_line_from_file(tmp_file, Regexp.new("an"))
|
12
|
+
IO.read(tmp_file).should eq("line 1\n\nline5\n")
|
13
|
+
system("rm #{tmp_file}") if File.exists? tmp_file
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
describe Object do
|
19
|
+
it "#blank? should work" do
|
20
|
+
"".blank?.should eq(true)
|
21
|
+
nil.blank?.should eq(true)
|
22
|
+
[].blank?.should eq(true)
|
23
|
+
false.blank?.should eq(true)
|
24
|
+
|
25
|
+
0.blank?.should eq(false)
|
26
|
+
|
27
|
+
'foo'.blank?.should eq(false)
|
28
|
+
[1].blank?.should eq(false)
|
29
|
+
true.blank?.should eq(false)
|
30
|
+
1.blank?.should eq(false)
|
31
|
+
-1.blank?.should eq(false)
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
data/vagrant-dnsmasq.gemspec
CHANGED
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.
|
4
|
+
version: 0.0.6
|
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-
|
11
|
+
date: 2013-06-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
description: A Dnsmasq Vagrant plugin that manages the dnsmasq.conf file and /etc/resolver
|
42
56
|
directory on your host system.
|
43
57
|
email:
|
@@ -47,6 +61,7 @@ extensions: []
|
|
47
61
|
extra_rdoc_files: []
|
48
62
|
files:
|
49
63
|
- .gitignore
|
64
|
+
- .travis.yml
|
50
65
|
- Gemfile
|
51
66
|
- Gemfile.lock
|
52
67
|
- LICENSE.txt
|
@@ -56,13 +71,18 @@ files:
|
|
56
71
|
- lib/vagrant-dnsmasq.rb
|
57
72
|
- lib/vagrant-dnsmasq/actions.rb
|
58
73
|
- lib/vagrant-dnsmasq/config.rb
|
59
|
-
- lib/vagrant-dnsmasq/includes/
|
74
|
+
- lib/vagrant-dnsmasq/includes/DnsmasqConf.class.rb
|
60
75
|
- lib/vagrant-dnsmasq/includes/Domain.class.rb
|
61
76
|
- lib/vagrant-dnsmasq/includes/Ip.class.rb
|
62
77
|
- lib/vagrant-dnsmasq/includes/Resolver.class.rb
|
63
78
|
- lib/vagrant-dnsmasq/includes/helper.rb
|
64
79
|
- lib/vagrant-dnsmasq/version.rb
|
80
|
+
- test/Dnsmasq.class.spec.rb
|
81
|
+
- test/Domain.class.spec.rb
|
82
|
+
- test/Ip.class.spec.rb
|
83
|
+
- test/Resolver.class.spec.rb
|
65
84
|
- test/Vagrantfile
|
85
|
+
- test/helper.spec.rb
|
66
86
|
- vagrant-dnsmasq.gemspec
|
67
87
|
homepage: https://github.com/mattes/vagrant-dnsmasq
|
68
88
|
licenses:
|
@@ -90,4 +110,9 @@ specification_version: 4
|
|
90
110
|
summary: A Dnsmasq Vagrant plugin that manages the dnsmasq.conf file and /etc/resolver
|
91
111
|
directory on your host system.
|
92
112
|
test_files:
|
113
|
+
- test/Dnsmasq.class.spec.rb
|
114
|
+
- test/Domain.class.spec.rb
|
115
|
+
- test/Ip.class.spec.rb
|
116
|
+
- test/Resolver.class.spec.rb
|
93
117
|
- test/Vagrantfile
|
118
|
+
- test/helper.spec.rb
|