vagrant-rubydns 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+
19
+ .vagrant
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in vagrant-rubydns.gemspec
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
+
12
+ gem "debugger"
13
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Paul Hinze
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,42 @@
1
+ # Vagrant RubyDNS Plugin
2
+
3
+ Spins up a small RubyDNS server that you can point your VMs at, automatically
4
+ registers/deregisters IP addresseses of guests as they come up and down.
5
+
6
+ **Goal**: simple DNS that's visible on both the guest and the host
7
+
8
+ ## Installation
9
+
10
+ Install under Vagrant (1.1 or later):
11
+
12
+ $ vagrant plugin install vagrant-rubydns
13
+
14
+ ## Usage
15
+
16
+ Spin up the DNS server
17
+
18
+ $ vagrant rubydns
19
+
20
+ Bring up a machine that has a private network IP address and a hostname (see the `Vagrantfile` for an example)
21
+
22
+ $ vagrant up
23
+
24
+ And you should be able to get your hostname from the local server:
25
+
26
+ $ dig -p 10053 @localhost myhost.vagrant.dev
27
+
28
+ If you shut down your guest, the entry will be gone! Any DNS queries that do not match will be passed through to an upstream DNS server, so this will be able to serve as the one-stop shop for your guests DNS needs.
29
+
30
+ ## Work in Progress - Lots to do!
31
+
32
+ * There's a stub provisioner in here - we'll use that to automatically point guests to our DNS server as they come up.
33
+ * Lots of static values that need configurin' - config location, ports, TLD, etc.
34
+ * Tests tests tests.
35
+
36
+ ## Contributing
37
+
38
+ 1. Fork it
39
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
40
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
41
+ 4. Push to the branch (`git push origin my-new-feature`)
42
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/Vagrantfile ADDED
@@ -0,0 +1,23 @@
1
+ #
2
+ # This serves as a simple example, and it's what I'm using for testing locally.
3
+ #
4
+ # If you're doing development and want to run this locally you can simply
5
+ # `bundle install`, then prefix all your vagrant commands with `bundle exec`, like so:
6
+ #
7
+ # bundle exec vagrant up
8
+ # bundle exce vagrant halt
9
+ #
10
+
11
+ # This line is unnecessary when the plugin is installed normally; it's just
12
+ # here for the development / testing use case.
13
+ Vagrant.require_plugin "vagrant-rubydns"
14
+
15
+ Vagrant.configure("2") do |config|
16
+ config.vm.box = "precise64"
17
+
18
+ config.vm.provision :rubydns
19
+
20
+ config.vm.network :private_network, ip: '172.16.32.111'
21
+
22
+ config.vm.hostname = "myhost.vagrant.dev"
23
+ end
@@ -0,0 +1,40 @@
1
+ module VagrantRubydns
2
+ module Action
3
+ class Setup
4
+ def initialize(app, env)
5
+ @app = app
6
+ end
7
+
8
+ def call(env)
9
+ @env = env
10
+
11
+ configfile = ".vagrant_dns.json"
12
+
13
+ config = JSON.parse(File.read(configfile))
14
+
15
+ config[hostname] = ip_address
16
+
17
+ File.open(configfile, "w") do |f|
18
+ f.write(JSON.pretty_generate(config))
19
+ end
20
+
21
+ @app.call(env)
22
+ end
23
+
24
+ def hostname
25
+ @env[:machine].config.vm.hostname
26
+ end
27
+
28
+ def ip_address
29
+ @env[:machine].config.vm.networks.each do |type, options|
30
+ if type == :private_network && options[:ip].is_a?(String)
31
+ return options[:ip]
32
+ end
33
+ end
34
+
35
+ nil
36
+ end
37
+
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,31 @@
1
+ module VagrantRubydns
2
+ module Action
3
+ class Teardown
4
+ def initialize(app, env)
5
+ @app = app
6
+ puts "I AM RUBYDNS TEARDOWN init"
7
+ end
8
+
9
+ def call(env)
10
+ @env = env
11
+
12
+ configfile = ".vagrant_dns.json"
13
+
14
+ config = JSON.parse(File.read(configfile))
15
+
16
+ config.delete hostname
17
+
18
+ File.open(configfile, "w") do |f|
19
+ f.write(JSON.pretty_generate(config))
20
+ end
21
+
22
+ @app.call(env)
23
+ end
24
+
25
+ def hostname
26
+ @env[:machine].config.vm.hostname
27
+ end
28
+
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,10 @@
1
+ module VagrantRubydns
2
+ class Command < Vagrant.plugin('2', :command)
3
+ def execute
4
+ puts "i am rubydns command"
5
+ require_relative 'server'
6
+ Server.run
7
+ 0
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,25 @@
1
+ module VagrantRubydns
2
+ class Plugin < Vagrant.plugin('2')
3
+ name "vagrant-rubydns"
4
+
5
+ command "rubydns" do
6
+ require_relative "command"
7
+ Command
8
+ end
9
+
10
+ provisioner "rubydns" do
11
+ require_relative "provisioner"
12
+ Provisioner
13
+ end
14
+
15
+ action_hook 'rubydns_setup', :machine_action_up do |hook|
16
+ require_relative 'action/setup'
17
+ hook.before(VagrantPlugins::ProviderVirtualBox::Action::Boot, Action::Setup)
18
+ end
19
+
20
+ action_hook 'rubydns_teardown', :machine_action_halt do |hook|
21
+ require_relative 'action/teardown'
22
+ hook.after(Vagrant::Action::Builtin::GracefulHalt, Action::Teardown)
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,25 @@
1
+ module VagrantRubydns
2
+ class Provisioner < Vagrant.plugin('2', :provisioner)
3
+ def initialize(machine, config)
4
+ super
5
+ end
6
+
7
+ def configure(root_config)
8
+ end
9
+
10
+ def ip_addresses
11
+ @machine.config.vm.networks.map { |type, params|
12
+ params if type == :private_network
13
+ }.compact.map { |params| params[:ip] }
14
+ end
15
+
16
+ def hostname
17
+ @machine.config.vm.hostname
18
+ end
19
+
20
+ def provision
21
+ puts "hi i am rubydns provisioner"
22
+ puts "i wanna set #{ip_addresses.inspect} to #{hostname}"
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,48 @@
1
+ require 'rubydns'
2
+
3
+ module VagrantRubydns
4
+ class Server
5
+
6
+ INTERFACES = [
7
+ [:udp, "0.0.0.0", 10053],
8
+ [:tcp, "0.0.0.0", 10053]
9
+ ]
10
+ Name = Resolv::DNS::Name
11
+ IN = Resolv::DNS::Resource::IN
12
+
13
+ def self.upstream
14
+ @upstream ||= RubyDNS::Resolver.new([[:udp, "8.8.8.8", 53], [:tcp, "8.8.8.8", 53]])
15
+ end
16
+
17
+ def self.configfile
18
+ Pathname('.vagrant_dns.json')
19
+ end
20
+
21
+ def self.entries
22
+ if configfile.exist?
23
+ JSON.parse(File.read('.vagrant_dns.json'))
24
+ else
25
+ {}
26
+ end
27
+ end
28
+
29
+ def self.run
30
+ # Start the RubyDNS server
31
+ server = self
32
+ RubyDNS::run_server(:listen => INTERFACES) do
33
+ match(/vagrant.dev/, IN::A) do |transaction|
34
+ if server.entries.has_key? transaction.name
35
+ transaction.respond!(server.entries[transaction.name])
36
+ else
37
+ transaction.passthrough!(server.upstream)
38
+ end
39
+ end
40
+
41
+ # Default DNS handler
42
+ otherwise do |transaction|
43
+ transaction.passthrough!(server.upstream)
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,5 @@
1
+ module Vagrant
2
+ module Rubydns
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,12 @@
1
+ begin
2
+ require "vagrant"
3
+ rescue LoadError
4
+ raise "The Vagrant RubyDNS plugin must be run within Vagrant."
5
+ end
6
+
7
+ require "vagrant-rubydns/version"
8
+ require "vagrant-rubydns/plugin"
9
+
10
+ module VagrantRubydns
11
+ end
12
+
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'vagrant-rubydns/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "vagrant-rubydns"
8
+ spec.version = Vagrant::Rubydns::VERSION
9
+ spec.authors = ["Paul Hinze"]
10
+ spec.email = ["paul.t.hinze@gmail.com"]
11
+ spec.description = %q{see https://github.com/phinze/vagrant-rubydns}
12
+ spec.summary = %q{a simple dns server for vagrant guests}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "rubydns"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.3"
24
+ spec.add_development_dependency "rake"
25
+ end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vagrant-rubydns
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Paul Hinze
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-03-19 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rubydns
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: bundler
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '1.3'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '1.3'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
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: see https://github.com/phinze/vagrant-rubydns
63
+ email:
64
+ - paul.t.hinze@gmail.com
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - .gitignore
70
+ - Gemfile
71
+ - LICENSE.txt
72
+ - README.md
73
+ - Rakefile
74
+ - Vagrantfile
75
+ - lib/vagrant-rubydns.rb
76
+ - lib/vagrant-rubydns/action/setup.rb
77
+ - lib/vagrant-rubydns/action/teardown.rb
78
+ - lib/vagrant-rubydns/command.rb
79
+ - lib/vagrant-rubydns/plugin.rb
80
+ - lib/vagrant-rubydns/provisioner.rb
81
+ - lib/vagrant-rubydns/server.rb
82
+ - lib/vagrant-rubydns/version.rb
83
+ - vagrant-rubydns.gemspec
84
+ homepage: ''
85
+ licenses:
86
+ - MIT
87
+ post_install_message:
88
+ rdoc_options: []
89
+ require_paths:
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ none: false
93
+ requirements:
94
+ - - ! '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ! '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ requirements: []
104
+ rubyforge_project:
105
+ rubygems_version: 1.8.23
106
+ signing_key:
107
+ specification_version: 3
108
+ summary: a simple dns server for vagrant guests
109
+ test_files: []
110
+ has_rdoc: