vagrant-dns-server 0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/.rvmrc +1 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +20 -0
- data/README.md +17 -0
- data/Rakefile +1 -0
- data/bin/vagrant_dns +20 -0
- data/lib/constants.rb +3 -0
- data/lib/dns.rb +47 -0
- data/lib/middleware/network_binder.rb +23 -0
- data/lib/middleware/update.rb +20 -0
- data/lib/pub.ruby +15 -0
- data/lib/server.rb +40 -0
- data/lib/vagrant_init.rb +9 -0
- data/lib/version.rb +3 -0
- data/vagrant-dns-server.gemspec +25 -0
- metadata +158 -0
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
pkg
|
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use 1.9.3@dns --create
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
GEM
|
2
|
+
remote: https://rubygems.org/
|
3
|
+
specs:
|
4
|
+
eventmachine (1.0.0)
|
5
|
+
rainbow (1.1.4)
|
6
|
+
rexec (1.5.1)
|
7
|
+
rainbow
|
8
|
+
rubydns (0.5.3)
|
9
|
+
eventmachine (~> 1.0.0)
|
10
|
+
rexec (~> 1.5.1)
|
11
|
+
thor (0.16.0)
|
12
|
+
zmq (2.1.4)
|
13
|
+
|
14
|
+
PLATFORMS
|
15
|
+
ruby
|
16
|
+
|
17
|
+
DEPENDENCIES
|
18
|
+
rubydns
|
19
|
+
thor
|
20
|
+
zmq
|
data/README.md
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# Intro
|
2
|
+
vagrant-dns enables easy dns management of multiple local Vagrant machines.
|
3
|
+
|
4
|
+
It composed from a Vagrant plugin and standalone dns server, the plugin auto registers the host and ip of the VM once it boots up making it available for lookup on both the host and guest machines.
|
5
|
+
|
6
|
+
# Usage
|
7
|
+
|
8
|
+
Add the plugin to the project Gemfile, use vagrant_dns server to boot the local dns server
|
9
|
+
|
10
|
+
|
11
|
+
# Alternatives
|
12
|
+
|
13
|
+
There are two existing project that aim to provide similar functionality:
|
14
|
+
|
15
|
+
* BerlinVagran [vagrant-dns](https://github.com/BerlinVagrant/vagrant-dns) which seems to be able to manage only a single machine and is OSX only.
|
16
|
+
|
17
|
+
* [vagrant-hostname](https://github.com/mosaicxm/vagrant-hostmaster) which manipulates /etc/hosts, this requires to enter sudo password for each machine (not an option when starting numerous machines).
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/vagrant_dns
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$:.push 'lib'
|
4
|
+
require 'rubygems'
|
5
|
+
require 'thor'
|
6
|
+
require 'server'
|
7
|
+
|
8
|
+
class Main < Thor
|
9
|
+
|
10
|
+
desc 'server','Starts the dns server that will accept dns changes from vagrant machines'
|
11
|
+
def server
|
12
|
+
@server = VagrantDns::Server.new
|
13
|
+
@server.process
|
14
|
+
trap("INT") { @server.shutdown;exit 0}
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
Main.start(ARGV)
|
data/lib/constants.rb
ADDED
data/lib/dns.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'rubydns'
|
2
|
+
|
3
|
+
HOSTS = Hash[%w(jenkins artifactory x2.takadu.com).zip(15..17)]
|
4
|
+
IN = Resolv::DNS::Resource::IN
|
5
|
+
UPSTREAM = RubyDNS::Resolver.new([[:tcp, "8.8.8.8", 53]])
|
6
|
+
|
7
|
+
module VagrantDns
|
8
|
+
|
9
|
+
class Registry
|
10
|
+
def initialize
|
11
|
+
@reg = {}
|
12
|
+
end
|
13
|
+
def register(host,ip)
|
14
|
+
@reg[host] = ip
|
15
|
+
end
|
16
|
+
|
17
|
+
def unregister(host)
|
18
|
+
@reg[host] = nil
|
19
|
+
end
|
20
|
+
|
21
|
+
def read(host)
|
22
|
+
@reg[host]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
class DnsServer
|
27
|
+
def initialize
|
28
|
+
RubyDNS::run_server(:listen => [[:tcp, "localhost", 53]]) do
|
29
|
+
otherwise do |transaction|
|
30
|
+
ip = REG.read(transaction.name)
|
31
|
+
if(ip)
|
32
|
+
transaction.respond!(ip)
|
33
|
+
else
|
34
|
+
puts "not found moving to UPSTREAM"
|
35
|
+
begin
|
36
|
+
transaction.passthrough!(UPSTREAM)
|
37
|
+
rescue Exception => e
|
38
|
+
puts e
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
REG = VagrantDns::Registry.new
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module VagrantDns
|
2
|
+
class NetworkBinder
|
3
|
+
def bind(vm)
|
4
|
+
networks = vm.config.vm.networks.find_all do |type,network_parameters|
|
5
|
+
type == :hostonly
|
6
|
+
end
|
7
|
+
ips = networks.map {|type,params| params.first}
|
8
|
+
host = vm.config.vm.host_name
|
9
|
+
Status.new.up(host,ips.first)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
class Status
|
13
|
+
# if socket is created on middleware initialization vagrant will get stuck
|
14
|
+
def up(host,ip)
|
15
|
+
context = ZMQ::Context.new
|
16
|
+
pub = context.socket ZMQ::PUB
|
17
|
+
puts "connecting to #{URL}"
|
18
|
+
pub.connect URL
|
19
|
+
pub.send "#{CHANNEL} #{host} #{ip} up"
|
20
|
+
pub.close
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
|
2
|
+
module VagrantDns
|
3
|
+
module Middleware
|
4
|
+
class Update
|
5
|
+
def initialize(app, env)
|
6
|
+
@app = app
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
@app.call(env)
|
11
|
+
update env[:vm] if env["vm"].state == :running
|
12
|
+
end
|
13
|
+
|
14
|
+
protected
|
15
|
+
def update(vm)
|
16
|
+
VagrantDns::NetworkBinder.new.bind(vm)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/pub.ruby
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# pub.rb
|
2
|
+
require 'zmq'
|
3
|
+
|
4
|
+
context = ZMQ::Context.new
|
5
|
+
chan = ARGV[0]
|
6
|
+
user = ARGV[1]
|
7
|
+
pub = context.socket ZMQ::PUB
|
8
|
+
# pub.bind 'ipc:///tmp/2'
|
9
|
+
pub.connect 'tcp://127.0.0.1:5004'
|
10
|
+
|
11
|
+
while msg = STDIN.gets
|
12
|
+
msg.strip!
|
13
|
+
pub.send "#{chan} #{user} #{msg}"
|
14
|
+
end
|
15
|
+
|
data/lib/server.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'zmq'
|
2
|
+
require 'constants'
|
3
|
+
require 'dns'
|
4
|
+
require 'eventmachine'
|
5
|
+
|
6
|
+
module VagrantDns
|
7
|
+
class Server
|
8
|
+
def initialize
|
9
|
+
context = ZMQ::Context.new
|
10
|
+
@sub = context.socket ZMQ::SUB
|
11
|
+
puts "binding to #{URL}"
|
12
|
+
@sub.bind URL
|
13
|
+
@sub.setsockopt ZMQ::SUBSCRIBE, CHANNEL
|
14
|
+
end
|
15
|
+
|
16
|
+
def process
|
17
|
+
Thread.new {
|
18
|
+
@dns = VagrantDns::DnsServer.new
|
19
|
+
}
|
20
|
+
puts "processing "
|
21
|
+
begin
|
22
|
+
while line = @sub.recv
|
23
|
+
chan, host, ip, msg = line.split ' ', 4
|
24
|
+
puts "#{chan} [#{ip}->#{host}]: is #{msg}"
|
25
|
+
REG.register(host,ip)
|
26
|
+
end
|
27
|
+
catch Execption => e
|
28
|
+
$stderr.puts e
|
29
|
+
rescue
|
30
|
+
shutdown
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def shutdown
|
35
|
+
$stderr.puts "Cleaning up server"
|
36
|
+
@sub.close
|
37
|
+
EM::stop()
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/lib/vagrant_init.rb
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'vagrant'
|
2
|
+
require 'constants'
|
3
|
+
require 'middleware/update'
|
4
|
+
require 'middleware/network_binder'
|
5
|
+
require 'zmq'
|
6
|
+
|
7
|
+
Vagrant.actions[:provision].insert_after(Vagrant::Action::VM::Provision, VagrantDns::Middleware::Update)
|
8
|
+
Vagrant.actions[:start].insert_after(Vagrant::Action::VM::Provision, VagrantDns::Middleware::Update)
|
9
|
+
|
data/lib/version.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Ronen Narkis"]
|
6
|
+
gem.email = ["narkisr@gmail.com"]
|
7
|
+
gem.description = %q{A vagrant plugin to automanage dns registration on local machine}
|
8
|
+
gem.summary = %q{A vagrant plugin that sets up a local dns server}
|
9
|
+
gem.homepage = "https://github.com/narkisr/vagrant-dns"
|
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-server"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = VagrantDns::VERSION
|
17
|
+
|
18
|
+
gem.add_dependency 'vagrant', '~>1.0.3'
|
19
|
+
gem.add_dependency 'rubydns'
|
20
|
+
gem.add_dependency 'zmq'
|
21
|
+
gem.add_development_dependency 'bundler'
|
22
|
+
gem.add_development_dependency 'mocha', '~>0.12.3'
|
23
|
+
gem.add_development_dependency 'rake'
|
24
|
+
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,158 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: vagrant-dns-server
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Ronen Narkis
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-01-09 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: 1.0.3
|
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: 1.0.3
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rubydns
|
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: zmq
|
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
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: bundler
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: mocha
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ~>
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 0.12.3
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ~>
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: 0.12.3
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: rake
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
description: A vagrant plugin to automanage dns registration on local machine
|
111
|
+
email:
|
112
|
+
- narkisr@gmail.com
|
113
|
+
executables:
|
114
|
+
- vagrant_dns
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- .gitignore
|
119
|
+
- .rvmrc
|
120
|
+
- Gemfile
|
121
|
+
- Gemfile.lock
|
122
|
+
- README.md
|
123
|
+
- Rakefile
|
124
|
+
- bin/vagrant_dns
|
125
|
+
- lib/constants.rb
|
126
|
+
- lib/dns.rb
|
127
|
+
- lib/middleware/network_binder.rb
|
128
|
+
- lib/middleware/update.rb
|
129
|
+
- lib/pub.ruby
|
130
|
+
- lib/server.rb
|
131
|
+
- lib/vagrant_init.rb
|
132
|
+
- lib/version.rb
|
133
|
+
- vagrant-dns-server.gemspec
|
134
|
+
homepage: https://github.com/narkisr/vagrant-dns
|
135
|
+
licenses: []
|
136
|
+
post_install_message:
|
137
|
+
rdoc_options: []
|
138
|
+
require_paths:
|
139
|
+
- lib
|
140
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
141
|
+
none: false
|
142
|
+
requirements:
|
143
|
+
- - ! '>='
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
147
|
+
none: false
|
148
|
+
requirements:
|
149
|
+
- - ! '>='
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: '0'
|
152
|
+
requirements: []
|
153
|
+
rubyforge_project:
|
154
|
+
rubygems_version: 1.8.24
|
155
|
+
signing_key:
|
156
|
+
specification_version: 3
|
157
|
+
summary: A vagrant plugin that sets up a local dns server
|
158
|
+
test_files: []
|