vagrant-dns 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ # v0.4.0
2
+
3
+ **This version is not compatible to vagrant < 1.2**
4
+
5
+ * Supports vagrant 1.2.x
6
+ * Update RubyDNS ~> 0.6.0
7
+
1
8
  # v0.3.0
2
9
 
3
10
  * Using RubyDNS ~> 0.5.3
@@ -37,4 +44,4 @@
37
44
  # v0.1.0
38
45
 
39
46
  * Initial Release
40
- * Support for A and AAAA configuration
47
+ * Support for A and AAAA configuration
data/Gemfile CHANGED
@@ -2,3 +2,10 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in vagrant-dns.gemspec
4
4
  gemspec
5
+
6
+ group :development do
7
+ # We depend on Vagrant for development, but we don't add it as a
8
+ # gem dependency because we expect to be installed within the
9
+ # Vagrant environment itself using `vagrant plugin`.
10
+ gem "vagrant", :git => "git://github.com/mitchellh/vagrant.git"
11
+ end
@@ -0,0 +1,61 @@
1
+ Platform Support
2
+ ================
3
+
4
+ Vagrant-DNS only supports OS X at the moment. This has 2 main reasons:
5
+
6
+ 1) All main developers are on OS X and have no good idea how to properly implement such a system for other OSes. Also, OS X makes it incredibly easy to do what vagrant-dns does.
7
+
8
+ 2) We spoke to multiple Linux and Windows-Developers and found that a half-baked implementation of people not invested at the respective platform as a _convenient development_ platform is only harmful and might at worst mess with users systems in unintended ways. None of them have supplied us with a proper way to implement this.
9
+
10
+ That said, we will happily accept any patches and want to encourage platform support beyond OS X, including ensuring further development of those solutions. Some of the groundwork for this has been layed. It might not be 100% finished, but we happily apply any changes necessary.
11
+
12
+ This document aims to be a guide to implementing support for other platforms.
13
+
14
+ How Vagrant-DNS currently works
15
+ ===============================
16
+
17
+ In a nutshell, Vagrant-DNS starts a DNS server on a non-privileged port (5300 by default) and makes sure that the host operating system knows this server. If possible, it only does so for a specific, free, TLD (.dev). As a fallback, it also supports pass-through, if you really want to play with ICANN domains.
18
+
19
+ The DNS server runs on all platforms.
20
+
21
+ Design Goals
22
+ ============
23
+
24
+ Vagrant-DNS should not require superuser access for anything except reconfiguring the hosts DNS system. This is why there is a seperate "install" step that registers the Vagrant-DNS server to your system (for the configured TLDs). (Re)starts of the server (happening at startup of the machine) need to happen without superuser access.
25
+
26
+ Mac OS X
27
+ ========
28
+
29
+ As a reference, here is how this works on OS X:
30
+
31
+ * `install` places a symlink in `/etc/resolver/{tld}` that links to a corresponding file in `.vagrant.d` with content similar to this one:
32
+
33
+ ```
34
+ nameserver 127.0.0.1
35
+ port 5300
36
+ ```
37
+
38
+ From then on, OS X will resolve all requests to that top level domain using the given resolver.
39
+
40
+ Linux
41
+ =====
42
+
43
+ To help anyone that attempts a Linux implementation, here is what has already been tried.
44
+
45
+ * Editing resolv.conf: Linux resolv.conf (in contrast to, say OpenBSD) does not allow you to set a port number for the DNS server. Also, its size is limited to 3 servers and the file is often under OS control, so messing around with it might not be advisable.
46
+ * Setting up dnsmasq: this is certainly an option, but we couldn't find out how invasive this was, which Linux flavors might already come with dnsmasq configurations and how not to shoot other people in the foot with it. User help is needed.
47
+
48
+ (Open)BSD
49
+ =========
50
+
51
+ Here, the question is simple: Is editing resolv.conf an option? Any takers?
52
+
53
+ Windows
54
+ =======
55
+
56
+ Quite frankly, I have not enough understanding on how to implement this properly on Windows.
57
+
58
+ General Notes
59
+ =============
60
+
61
+ mDNS is not an option. It doesn't support subdomains and most implementations do not support multiple servers per machine. Thats sad, as all platforms come with good solutions for it.
data/README.md CHANGED
@@ -6,15 +6,11 @@
6
6
 
7
7
  If you use the gem version of Vagrant, use:
8
8
 
9
- $ gem install vagrant-dns
10
-
11
- otherwise, use:
12
-
13
- $ vagrant gem install vagrant-dns
9
+ $ vagrant plugin install vagrant-dns
14
10
 
15
11
  ## Usage
16
12
 
17
- In addition to your networking config, configure a toplevel domain and a `host_name` for your machine. Optionally, configure a set of free matching patterns. Global configuration options can be given through the `VagrantDNS::Config` object:
13
+ In addition to your networking config, configure a toplevel domain and a `hostname` for your machine. Optionally, configure a set of free matching patterns. Global configuration options can be given through the `VagrantDNS::Config` object:
18
14
 
19
15
  ```ruby
20
16
  Vagrant::Config.run do |config|
@@ -22,11 +18,11 @@ Vagrant::Config.run do |config|
22
18
 
23
19
  config.dns.tld = "dev"
24
20
 
25
- config.vm.host_name = "machine"
21
+ config.vm.hostname = "machine"
26
22
 
27
23
  config.dns.patterns = [/^.*mysite.dev$/, /^.*myothersite.dev$/]
28
24
 
29
- config.vm.network :hostonly, "33.33.33.60"
25
+ config.vm.network :private_network, ip: "33.33.33.60"
30
26
  end
31
27
 
32
28
  # optional
@@ -36,7 +32,7 @@ VagrantDNS::Config.logger = Logger.new("dns.log")
36
32
  Then, register the DNS server as a resolver. RVM users must use `rvmsudo` instead of `sudo`:
37
33
 
38
34
  ```bash
39
- $ sudo vagrant dns --install
35
+ $ vagrant dns --install
40
36
  ```
41
37
 
42
38
  On OS X, this will create a file `/etc/resolver/dev`, which tells OS X to resolve the TLD `.dev` by using the nameserver given in this file. You will have to rerun --install every time a tld is added.
@@ -44,7 +40,7 @@ On OS X, this will create a file `/etc/resolver/dev`, which tells OS X to resolv
44
40
  You can delete this file by running:
45
41
 
46
42
  ```bash
47
- $ sudo vagrant dns --uninstall
43
+ $ vagrant dns --uninstall
48
44
  ```
49
45
 
50
46
  Then, run the DNS server:
@@ -84,5 +80,6 @@ The DNS server will start automatically once the first VM is started.
84
80
 
85
81
  * A records only
86
82
  * no ipv6 support
87
- * OS X only
88
- * Alpha code
83
+ * OS X only (please read: [Platform
84
+ Support](https://github.com/BerlinVagrant/vagrant-dns/blob/master/PLATFORM_SUPPORT.md) before ranting about this).
85
+ * Not visible inside the box
data/Vagrantfile CHANGED
@@ -2,7 +2,7 @@
2
2
  # vi: set ft=ruby :
3
3
 
4
4
 
5
- Vagrant::Config.run do |config|
5
+ Vagrant.configure("2") do |config|
6
6
  # All Vagrant configuration is done here. The most common configuration
7
7
  # options are documented and commented below. For a complete reference,
8
8
  # please see the online documentation at vagrantup.com.
@@ -13,8 +13,8 @@ Vagrant::Config.run do |config|
13
13
  config.dns.tld = "dev"
14
14
  config.dns.patterns = /^.*machine.dev$/
15
15
 
16
- config.vm.host_name = "machine"
17
- config.vm.network :hostonly, "33.33.33.60"
16
+ config.vm.hostname = "machine"
17
+ config.vm.network :private_network, ip: "33.33.33.60"
18
18
 
19
19
 
20
20
  VagrantDNS::Config.listen = [[:udp, "0.0.0.0", 5300]]
@@ -4,14 +4,14 @@ require 'rbconfig'
4
4
 
5
5
  module VagrantDNS
6
6
 
7
- class Command < Vagrant::Command::Base
7
+ class Command < Vagrant.plugin(2, :command)
8
8
 
9
9
  # Runs the vbguest installer on the VMs that are represented
10
10
  # by this environment.
11
11
  def execute
12
12
  options = {}
13
13
  opts = OptionParser.new do |opts|
14
- opts.banner = "Usage: vagrant dns [vm-name] [-i|--install] [-u|--uninstall] [-s|--start] [-S|--stop] [-r|--restart] [-o|--ontop]"
14
+ opts.banner = "Usage: vagrant dns [vm-name] [-i|--install] [-u|--uninstall] [--pruge] [-s|--start] [-S|--stop] [-r|--restart] [-o|--ontop]"
15
15
  opts.separator ""
16
16
 
17
17
  opts.on("--install", "-i", "Install DNS config for machine domain") do
@@ -22,6 +22,11 @@ module VagrantDNS
22
22
  options[:uninstall] = true
23
23
  end
24
24
 
25
+ opts.on("--purge", "Uninstall DNS config and remove DNS configurations of all machines.") do
26
+ options[:uninstall] = true
27
+ options[:purge] = true
28
+ end
29
+
25
30
  opts.on("--start", "-s", "Start the DNS service") do
26
31
  options[:start] = true
27
32
  end
@@ -29,11 +34,11 @@ module VagrantDNS
29
34
  opts.on("--stop", "-s", "Stop the DNS service") do
30
35
  options[:stop] = true
31
36
  end
32
-
37
+
33
38
  opts.on("--restart", "-r", "Restart the DNS service") do
34
39
  options[:restart] = true
35
40
  end
36
-
41
+
37
42
  opts.on("--ontop", "-o", "Start the DNS service on top. Debugging only, this blocks Vagrant!") do
38
43
  options[:ontop] = true
39
44
  end
@@ -42,15 +47,43 @@ module VagrantDNS
42
47
  argv = parse_options(opts)
43
48
  return if !argv
44
49
 
45
- dns_options = []
46
-
47
50
  vms = argv unless argv.empty?
48
- tmp_path = File.join(@env.tmp_path, "dns")
49
-
50
- with_target_vms(vms) { |vm| VagrantDNS::Configurator.new(vm, tmp_path).run! }
51
51
 
52
+ if options[:uninstall]
53
+ manage_service(vms, options.merge(stop: true))
54
+ manage_installation(vms, options)
55
+
56
+ if options[:purge]
57
+ require 'fileutils'
58
+ FileUtils.rm_r(tmp_path)
59
+ end
60
+ else
61
+ build_config(vms, options)
62
+ manage_service(vms, options)
63
+ manage_installation(vms, options) if options[:install]
64
+ end
65
+
66
+ end
67
+
68
+ protected
69
+
70
+ def manage_installation(vms, options)
71
+ if RbConfig::CONFIG["host_os"].match /darwin/
72
+ installer = VagrantDNS::Installers::Mac.new(tmp_path)
73
+
74
+ if options[:install]
75
+ installer.install!
76
+ elsif options[:uninstall]
77
+ installer.uninstall!
78
+ end
79
+ else
80
+ raise 'installing and uninstalling is only supported on Mac OS X at the moment.'
81
+ end
82
+ end
83
+
84
+ def manage_service(vms, options)
52
85
  service = VagrantDNS::Service.new(tmp_path, options)
53
-
86
+
54
87
  if options[:start]
55
88
  service.start!
56
89
  elsif options[:stop]
@@ -58,20 +91,14 @@ module VagrantDNS
58
91
  elsif options[:restart]
59
92
  service.restart!
60
93
  end
94
+ end
61
95
 
62
- if options[:install] || options[:uninstall]
63
- if RbConfig::CONFIG["host_os"].match /darwin/
64
- installer = VagrantDNS::Installers::Mac.new(tmp_path)
65
-
66
- if options[:install]
67
- installer.install!
68
- elsif options[:uninstall]
69
- installer.uninstall!
70
- end
71
- else
72
- raise 'installing and uninstalling is only supported on Mac OS X at the moment.'
73
- end
74
- end
96
+ def build_config(vms, options)
97
+ with_target_vms(vms) { |vm| VagrantDNS::Configurator.new(vm, tmp_path).run! }
98
+ end
99
+
100
+ def tmp_path
101
+ File.join(@env.tmp_path, "dns")
75
102
  end
76
103
  end
77
- end
104
+ end
@@ -1,7 +1,7 @@
1
1
  require 'logger'
2
2
 
3
3
  module VagrantDNS
4
- class Config < Vagrant::Config::Base
4
+ class Config < Vagrant.plugin(2, :config)
5
5
  class << self
6
6
  attr_accessor :listen, :logger, :ipv4only, :auto_run
7
7
 
@@ -35,25 +35,29 @@ module VagrantDNS
35
35
  registry ||= {}
36
36
  opts = dns_options(vm)
37
37
  patterns = opts[:patterns] || default_patterns(opts)
38
- network = opts[:networks].first
38
+ networks = opts[:networks]
39
+ network = {}
40
+ networks.each do |nw|
41
+ network = nw if nw.first == :private_network
42
+ end
39
43
 
40
44
  if network
41
- ip = network.last.first
45
+ ip = network.last[:ip]
42
46
  else
43
47
  ip = '127.0.0.1'
44
48
  end
45
49
 
46
50
  patterns.each do |p|
47
51
  p = p.source if p.respond_to? :source # Regexp#to_s is unusable
48
- registry[p] = ip
52
+ registry[p] = ip
49
53
  end
50
-
54
+
51
55
  File.open(config_file, "w") { |f| f << YAML.dump(registry) }
52
56
  end
53
57
 
54
58
  def dns_options(vm)
55
59
  dns_options = vm.config.dns.to_hash
56
- dns_options[:host_name] = vm.config.vm.host_name
60
+ dns_options[:host_name] = vm.config.vm.hostname
57
61
  dns_options[:networks] = vm.config.vm.networks
58
62
  dns_options
59
63
  end
@@ -74,17 +78,17 @@ nameserver 127.0.0.1
74
78
  port #{port}
75
79
  FILE
76
80
  end
77
-
81
+
78
82
  def resolver_folder
79
83
  File.join(tmp_path, "resolver")
80
84
  end
81
-
85
+
82
86
  def ensure_deamon_env!
83
87
  FileUtils.mkdir_p(File.join(tmp_path, "daemon"))
84
88
  end
85
-
89
+
86
90
  def config_file
87
91
  File.join(tmp_path, "config")
88
92
  end
89
93
  end
90
- end
94
+ end
@@ -9,29 +9,25 @@ module VagrantDNS
9
9
 
10
10
  def install!
11
11
  require 'fileutils'
12
- FileUtils.mkdir_p('/etc/resolver')
13
12
 
14
- FileUtils.ln_s(registered_resolvers, "/etc/resolver", :force => true)
15
- rescue Errno::EACCES => e
16
- warn "vagrant-dns needs superuser access to manipulate DNS settings"
17
- raise e
13
+ `sudo mkdir -p #{install_path}`
14
+ registered_resolvers.each do |resolver|
15
+ `sudo ln -sf #{resolver} #{install_path}`
16
+ end
18
17
  end
19
18
 
20
19
  def uninstall!
21
20
  require 'fileutils'
22
21
 
23
22
  registered_resolvers.each do |r|
24
- resolver = File.join("/etc/resolver", File.basename(r))
25
- FileUtils.rm_f(resolver)
23
+ installed_resolver = File.join(install_path, File.basename(r))
24
+ `sudo rm -rf #{installed_resolver}`
26
25
  end
27
- rescue Errno::EACCES => e
28
- warn "vagrant-dns needs superuser access to manipulate DNS settings"
29
- raise e
30
26
  end
31
-
27
+
32
28
  def registered_resolvers
33
29
  Dir[File.join(tmp_path, "resolver", "*")]
34
30
  end
35
31
  end
36
32
  end
37
- end
33
+ end
@@ -6,9 +6,11 @@ module VagrantDNS
6
6
  end
7
7
 
8
8
  def call(env)
9
+ @env = env
10
+ vm = env[:machine]
9
11
  if VagrantDNS::Config.auto_run
10
- tmp_path = File.join(env[:vm].env.tmp_path, "dns")
11
- VagrantDNS::Configurator.new(env[:vm], tmp_path).run!
12
+ tmp_path = File.join(vm.env.tmp_path, "dns")
13
+ VagrantDNS::Configurator.new(vm, tmp_path).run!
12
14
  VagrantDNS::Service.new(tmp_path).restart!
13
15
  env[:ui].info "Restarted DNS Service"
14
16
  end
@@ -16,4 +18,4 @@ module VagrantDNS
16
18
  @app.call(env)
17
19
  end
18
20
  end
19
- end
21
+ end
@@ -1,3 +1,6 @@
1
+ require 'daemons'
2
+
3
+
1
4
  module VagrantDNS
2
5
  class Service
3
6
  attr_accessor :tmp_path, :options
@@ -27,7 +30,7 @@ module VagrantDNS
27
30
 
28
31
  RubyDNS::run_server(:listen => VagrantDNS::Config.listen) do
29
32
  registry.each do |pattern, ip|
30
- match(Regexp.new(pattern), Resolv::DNS::Resource::IN::A) do |match_data, transaction|
33
+ match(Regexp.new(pattern), Resolv::DNS::Resource::IN::A) do |transaction, match_data|
31
34
  transaction.respond!(ip)
32
35
  end
33
36
  end
@@ -58,4 +61,4 @@ module VagrantDNS
58
61
  File.join(tmp_path, "config")
59
62
  end
60
63
  end
61
- end
64
+ end
@@ -1,5 +1,5 @@
1
1
  module Vagrant
2
2
  module Dns
3
- VERSION = "0.3.0"
3
+ VERSION = "0.4.0"
4
4
  end
5
5
  end
data/lib/vagrant-dns.rb CHANGED
@@ -1,13 +1,32 @@
1
1
  require "vagrant-dns/version"
2
- require "vagrant-dns/command"
3
2
  require "vagrant-dns/config"
3
+
4
4
  require "vagrant-dns/service"
5
5
  require "vagrant-dns/installers/mac"
6
6
  require "vagrant-dns/restart_middleware"
7
7
  require "vagrant-dns/configurator"
8
8
 
9
- Vagrant.config_keys.register(:dns) { VagrantDNS::Config }
9
+ module VagrantDNS
10
+
11
+ class Plugin < Vagrant.plugin("2")
12
+
13
+ name "vagrant-dns"
14
+
15
+ config "dns" do
16
+ Config
17
+ end
18
+
19
+ command "dns" do
20
+ require File.expand_path("../vagrant-dns/command", __FILE__)
21
+ Command
22
+ end
23
+
24
+ %w{up reload}.each do |action|
25
+ action_hook(:restart_host_dns, "machine_action_#{action}".to_sym) do |hook|
26
+ hook.append VagrantDNS::RestartMiddleware
27
+ end
28
+ end
10
29
 
11
- Vagrant.commands.register(:dns) { VagrantDNS::Command }
30
+ end
12
31
 
13
- Vagrant.actions[:start].insert Vagrant::Action::VM::Customize, VagrantDNS::RestartMiddleware
32
+ end
data/vagrant-dns.gemspec CHANGED
@@ -15,7 +15,6 @@ Gem::Specification.new do |gem|
15
15
  gem.require_paths = ["lib"]
16
16
  gem.version = Vagrant::Dns::VERSION
17
17
 
18
- gem.add_dependency "vagrant"
19
18
  gem.add_dependency "daemons"
20
- gem.add_dependency "rubydns", "~> 0.5.3"
19
+ gem.add_dependency "rubydns", "~> 0.6.0"
21
20
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-dns
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,24 +9,8 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-03 00:00:00.000000000 Z
12
+ date: 2013-06-03 00:00:00.000000000 Z
13
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
14
  - !ruby/object:Gem::Dependency
31
15
  name: daemons
32
16
  requirement: !ruby/object:Gem::Requirement
@@ -50,7 +34,7 @@ dependencies:
50
34
  requirements:
51
35
  - - ~>
52
36
  - !ruby/object:Gem::Version
53
- version: 0.5.3
37
+ version: 0.6.0
54
38
  type: :runtime
55
39
  prerelease: false
56
40
  version_requirements: !ruby/object:Gem::Requirement
@@ -58,7 +42,7 @@ dependencies:
58
42
  requirements:
59
43
  - - ~>
60
44
  - !ruby/object:Gem::Version
61
- version: 0.5.3
45
+ version: 0.6.0
62
46
  description: vagrant-dns is a vagrant plugin that manages DNS records associated with
63
47
  local machines.
64
48
  email:
@@ -71,6 +55,7 @@ files:
71
55
  - CHANGELOG.md
72
56
  - Gemfile
73
57
  - LICENSE
58
+ - PLATFORM_SUPPORT.md
74
59
  - README.md
75
60
  - Rakefile
76
61
  - Vagrantfile
@@ -82,7 +67,6 @@ files:
82
67
  - lib/vagrant-dns/restart_middleware.rb
83
68
  - lib/vagrant-dns/service.rb
84
69
  - lib/vagrant-dns/version.rb
85
- - lib/vagrant_init.rb
86
70
  - vagrant-dns.gemspec
87
71
  homepage: ''
88
72
  licenses: []
@@ -104,7 +88,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
104
88
  version: '0'
105
89
  requirements: []
106
90
  rubyforge_project:
107
- rubygems_version: 1.8.24
91
+ rubygems_version: 1.8.23
108
92
  signing_key:
109
93
  specification_version: 3
110
94
  summary: vagrant-dns manages DNS records of vagrant machines
data/lib/vagrant_init.rb DELETED
@@ -1 +0,0 @@
1
- require 'vagrant-dns'