vagrant-dns 0.1.0
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.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +75 -0
- data/Rakefile +2 -0
- data/Vagrantfile +20 -0
- data/lib/vagrant-dns.rb +7 -0
- data/lib/vagrant-dns/command.rb +110 -0
- data/lib/vagrant-dns/config.rb +26 -0
- data/lib/vagrant-dns/version.rb +5 -0
- data/lib/vagrant_init.rb +1 -0
- data/vagrant-dns.gemspec +21 -0
- metadata +106 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Florian Gilcher
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
# vagrant-dns
|
2
|
+
|
3
|
+
`vagrant-dns` allows you to configure a dns-server managing a development subdomain. It works much like pow, but manages Vagrant machines.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
If you use the gem version of Vagrant, use:
|
8
|
+
|
9
|
+
$ gem install vagrant-dns
|
10
|
+
|
11
|
+
otherwise, use:
|
12
|
+
|
13
|
+
$ vagrant gem install vagrant-dns
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
In addition to your networking config, configure a toplevel domain and a `host_name` for your machine. Optionally configure a logger and the listen options for the DNS server, this setting is global:
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
Vagrant::Config.run do |config|
|
21
|
+
#...
|
22
|
+
|
23
|
+
config.dns.tld = "dev"
|
24
|
+
|
25
|
+
config.vm.host_name = "machine"
|
26
|
+
config.vm.network :hostonly, "33.33.33.60"
|
27
|
+
end
|
28
|
+
|
29
|
+
# optional
|
30
|
+
VagrantDNS::Config.logger = Logger.new("dns.log")
|
31
|
+
VagrantDNS::Config.listen = [[:udp, "0.0.0.0", 5300]]
|
32
|
+
```
|
33
|
+
|
34
|
+
Then, register the DNS server as a resolver:
|
35
|
+
|
36
|
+
```bash
|
37
|
+
$ sudo vagrant dns --install
|
38
|
+
```
|
39
|
+
|
40
|
+
On OS X, this will create a file `/etc/resolver/dev`, which tells OS X to resolve the TLD `.dev` by using the resolver given in this file.
|
41
|
+
|
42
|
+
You can delete this file by running:
|
43
|
+
|
44
|
+
```bash
|
45
|
+
$ sudo vagrant dns --uninstall
|
46
|
+
```
|
47
|
+
|
48
|
+
Then, run the DNS server:
|
49
|
+
|
50
|
+
```bash
|
51
|
+
$ vagrant dns --start
|
52
|
+
```
|
53
|
+
|
54
|
+
And test it:
|
55
|
+
|
56
|
+
```bash
|
57
|
+
$ dig @localhost -p 5300 test.machine.dev
|
58
|
+
```
|
59
|
+
|
60
|
+
You can now reach the server under the given domain.
|
61
|
+
|
62
|
+
Finally, stop the server using:
|
63
|
+
|
64
|
+
```bash
|
65
|
+
$ vagrant dns --stop
|
66
|
+
```
|
67
|
+
|
68
|
+
# Issues
|
69
|
+
|
70
|
+
* Currently, you need one TLD per environment
|
71
|
+
* Only A and AAAA records at the moment
|
72
|
+
* Only one record per machine ("hostname.tld")
|
73
|
+
* Advanced customization of record rules is not supported at the moment
|
74
|
+
* OS X only
|
75
|
+
* Alpha code
|
data/Rakefile
ADDED
data/Vagrantfile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- mode: ruby -*-
|
2
|
+
# vi: set ft=ruby :
|
3
|
+
|
4
|
+
|
5
|
+
Vagrant::Config.run do |config|
|
6
|
+
# All Vagrant configuration is done here. The most common configuration
|
7
|
+
# options are documented and commented below. For a complete reference,
|
8
|
+
# please see the online documentation at vagrantup.com.
|
9
|
+
|
10
|
+
# Every Vagrant virtual environment requires a box to build off of.
|
11
|
+
config.vm.box = "base"
|
12
|
+
|
13
|
+
config.dns.tld = "dev"
|
14
|
+
|
15
|
+
config.vm.host_name = "machine"
|
16
|
+
config.vm.network :hostonly, "33.33.33.60"
|
17
|
+
|
18
|
+
VagrantDNS::Config.logger = Logger.new("dns.log")
|
19
|
+
VagrantDNS::Config.listen = [[:udp, "0.0.0.0", 5300]]
|
20
|
+
end
|
data/lib/vagrant-dns.rb
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
require 'daemons'
|
3
|
+
|
4
|
+
module VagrantDNS
|
5
|
+
|
6
|
+
class Command < Vagrant::Command::Base
|
7
|
+
|
8
|
+
# Runs the vbguest installer on the VMs that are represented
|
9
|
+
# by this environment.
|
10
|
+
def execute
|
11
|
+
options = {}
|
12
|
+
opts = OptionParser.new do |opts|
|
13
|
+
opts.banner = "Usage: vagrant dns [vm-name] [-i|--install] [-u|--uninstall] [-s|--start] [-S|--stop]"
|
14
|
+
opts.separator ""
|
15
|
+
|
16
|
+
opts.on("--install", "-i", "Install DNS config for machine domain") do
|
17
|
+
options[:install] = true
|
18
|
+
end
|
19
|
+
|
20
|
+
opts.on("--uninstall", "-u", "Uninstall DNS config for machine domain") do
|
21
|
+
options[:uninstall] = true
|
22
|
+
end
|
23
|
+
|
24
|
+
opts.on("--start", "-s", "Start the DNS service") do
|
25
|
+
options[:start] = true
|
26
|
+
end
|
27
|
+
|
28
|
+
opts.on("--stop", "-s", "Stop the DNS service") do
|
29
|
+
options[:stop] = true
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
argv = parse_options(opts)
|
35
|
+
return if !argv
|
36
|
+
|
37
|
+
dns_options = []
|
38
|
+
|
39
|
+
if argv.empty?
|
40
|
+
with_target_vms(nil) { |vm| dns_options << get_dns_options(vm) }
|
41
|
+
else
|
42
|
+
argv.each do |vm_name|
|
43
|
+
with_target_vms(vm_name) { |vm| dns_options << get_dns_options(vm) }
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
if options[:start]
|
48
|
+
run_options = {:ARGV => ["start"]}
|
49
|
+
elsif options[:stop]
|
50
|
+
run_options = {:ARGV => ["stop"]}
|
51
|
+
end
|
52
|
+
|
53
|
+
if options[:start] || options[:stop]
|
54
|
+
Daemons.run_proc("dnsserver.rb", run_options) do
|
55
|
+
require 'rubydns'
|
56
|
+
|
57
|
+
RubyDNS::run_server(:listen => VagrantDNS::Config.listen) do
|
58
|
+
self.logger = VagrantDNS::Config.logger if VagrantDNS::Config.logger
|
59
|
+
|
60
|
+
dns_options.each do |opts|
|
61
|
+
pattern = /^.*#{opts[:host_name]}.#{opts[:tld]}$/
|
62
|
+
|
63
|
+
network = opts[:networks].first
|
64
|
+
ip = network.last.first
|
65
|
+
|
66
|
+
action = lambda { |match_data, transaction| transaction.respond!(ip) }
|
67
|
+
|
68
|
+
match(pattern, :A, &action)
|
69
|
+
match(pattern, :AAAA, &action)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
if options[:install]
|
76
|
+
require 'fileutils'
|
77
|
+
dns_options.each do |opts|
|
78
|
+
port = VagrantDNS::Config.listen.first.last
|
79
|
+
tld = opts[:tld]
|
80
|
+
contents = <<-FILE
|
81
|
+
nameserver 127.0.0.1
|
82
|
+
port #{port}
|
83
|
+
FILE
|
84
|
+
FileUtils.mkdir_p("/etc/resolver")
|
85
|
+
File.open(File.join("/etc/resolver", tld), "w") do |f|
|
86
|
+
f << contents
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
if options[:uninstall]
|
92
|
+
require 'fileutils'
|
93
|
+
|
94
|
+
dns_options.each do |opts|
|
95
|
+
tld = opts[:tld]
|
96
|
+
FileUtils.rm(File.join("/etc/resolver", tld))
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
protected
|
102
|
+
|
103
|
+
def get_dns_options(vm)
|
104
|
+
dns_options = vm.config.dns.to_hash
|
105
|
+
dns_options[:host_name] = vm.config.vm.host_name
|
106
|
+
dns_options[:networks] = vm.config.vm.networks
|
107
|
+
dns_options
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'logger'
|
2
|
+
|
3
|
+
module VagrantDNS
|
4
|
+
|
5
|
+
class Config < Vagrant::Config::Base
|
6
|
+
class << self
|
7
|
+
attr_accessor :listen, :logger
|
8
|
+
|
9
|
+
def listen
|
10
|
+
@listen ||= [[:udp, "127.0.0.1", 5300]]
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
attr_accessor :records, :tld
|
15
|
+
|
16
|
+
# explicit hash, to get symbols in hash keys
|
17
|
+
def to_hash
|
18
|
+
{
|
19
|
+
:records => records,
|
20
|
+
:tld => tld
|
21
|
+
}
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
data/lib/vagrant_init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'vagrant-dns'
|
data/vagrant-dns.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/vagrant-dns/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Florian Gilcher"]
|
6
|
+
gem.email = ["florian.gilcher@asquera.de"]
|
7
|
+
gem.description = %q{vagrant-dns is a vagrant plugin that manages DNS records associated with local machines.}
|
8
|
+
gem.summary = %q{vagrant-dns manages DNS records of vagrant machines}
|
9
|
+
gem.homepage = ""
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "vagrant-dns"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Vagrant::Dns::VERSION
|
17
|
+
|
18
|
+
gem.add_dependency "vagrant"
|
19
|
+
gem.add_dependency "daemons"
|
20
|
+
gem.add_dependency "rubydns"
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: vagrant-dns
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Florian Gilcher
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-04-28 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: vagrant
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: daemons
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rubydns
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
description: vagrant-dns is a vagrant plugin that manages DNS records associated with
|
63
|
+
local machines.
|
64
|
+
email:
|
65
|
+
- florian.gilcher@asquera.de
|
66
|
+
executables: []
|
67
|
+
extensions: []
|
68
|
+
extra_rdoc_files: []
|
69
|
+
files:
|
70
|
+
- .gitignore
|
71
|
+
- Gemfile
|
72
|
+
- LICENSE
|
73
|
+
- README.md
|
74
|
+
- Rakefile
|
75
|
+
- Vagrantfile
|
76
|
+
- lib/vagrant-dns.rb
|
77
|
+
- lib/vagrant-dns/command.rb
|
78
|
+
- lib/vagrant-dns/config.rb
|
79
|
+
- lib/vagrant-dns/version.rb
|
80
|
+
- lib/vagrant_init.rb
|
81
|
+
- vagrant-dns.gemspec
|
82
|
+
homepage: ''
|
83
|
+
licenses: []
|
84
|
+
post_install_message:
|
85
|
+
rdoc_options: []
|
86
|
+
require_paths:
|
87
|
+
- lib
|
88
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
none: false
|
96
|
+
requirements:
|
97
|
+
- - ! '>='
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
requirements: []
|
101
|
+
rubyforge_project:
|
102
|
+
rubygems_version: 1.8.21
|
103
|
+
signing_key:
|
104
|
+
specification_version: 3
|
105
|
+
summary: vagrant-dns manages DNS records of vagrant machines
|
106
|
+
test_files: []
|