lh-vagrant-dns 0.0.1.dev
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +19 -0
- data/Gemfile +7 -0
- data/LICENSE.txt +22 -0
- data/README.md +53 -0
- data/Rakefile +1 -0
- data/lib/vagrant-dns/action/create_daemons_dir.rb +24 -0
- data/lib/vagrant-dns/action/create_resolvers.rb +42 -0
- data/lib/vagrant-dns/action/register_patterns.rb +56 -0
- data/lib/vagrant-dns/action/setup_env.rb +22 -0
- data/lib/vagrant-dns/action/start_dns_server.rb +20 -0
- data/lib/vagrant-dns/action/stop_dns_server.rb +21 -0
- data/lib/vagrant-dns/action.rb +46 -0
- data/lib/vagrant-dns/command.rb +44 -0
- data/lib/vagrant-dns/config.rb +19 -0
- data/lib/vagrant-dns/dns_server.rb +61 -0
- data/lib/vagrant-dns/env.rb +31 -0
- data/lib/vagrant-dns/env_helper.rb +6 -0
- data/lib/vagrant-dns/plugin.rb +45 -0
- data/lib/vagrant-dns/version.rb +5 -0
- data/lib/vagrant-dns.rb +29 -0
- data/vagrant-dns.gemspec +58 -0
- metadata +131 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Lin He
|
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,53 @@
|
|
1
|
+
# Vagrant dns plugin
|
2
|
+
|
3
|
+
A Vagrant **1.1.x** plugin to manage DNS records on **Mac systems**. It is
|
4
|
+
heavily based on https://github.com/BerlinVagrant/vagrant-dns (which doesn't
|
5
|
+
seem to support Vagrant 1.1.x currently), so credit goes to the author of that
|
6
|
+
lib.
|
7
|
+
|
8
|
+
## TODOs
|
9
|
+
|
10
|
+
* Add specs
|
11
|
+
* Add config validation
|
12
|
+
* Add DNS resolver uninstall command
|
13
|
+
* Add Vagrant destroy action hook to clean dns tmp path
|
14
|
+
|
15
|
+
## Installation
|
16
|
+
|
17
|
+
It is only used as a plugin for Vagrant, so to install:
|
18
|
+
|
19
|
+
$ vagrant plugin install lh-vagrant-dns
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
Vagrant.configure("2") do |config|
|
24
|
+
|
25
|
+
# Configure DNS tlds
|
26
|
+
config.dns.tld = "dev"
|
27
|
+
# or config.dns.tlds = ["dev", "stag"]
|
28
|
+
|
29
|
+
# This will be used to construct dns patterns, unless if
|
30
|
+
# config.dns.patterns option is explicity defined. Otherwise, given tld
|
31
|
+
# to be 'dev', we would get DNS pattern /^.*machine.dev$/
|
32
|
+
config.vm.hostname = "machine"
|
33
|
+
|
34
|
+
# Optional configuration
|
35
|
+
config.dns.patterns = [/^.*mysite.dev$/, /^.*myothersite.dev$/]
|
36
|
+
|
37
|
+
config.vm.network :private_network, ip: "33.33.33.100"
|
38
|
+
end
|
39
|
+
|
40
|
+
After `vagrant up`, install DNS resolver on mac:
|
41
|
+
|
42
|
+
$ sudo vagrant dns --install
|
43
|
+
|
44
|
+
Now, `vagrant halt` stops a DNS server, while `vagrant up` or `vagrant provision`
|
45
|
+
starts a DNS server.
|
46
|
+
|
47
|
+
## Contributing
|
48
|
+
|
49
|
+
1. Fork it
|
50
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
51
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
52
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
53
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module DNS
|
3
|
+
module Action
|
4
|
+
class CreateDaemonsDir
|
5
|
+
def initialize(app, env)
|
6
|
+
@app = app
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
daemon_path = env[:dns].daemon_path
|
11
|
+
|
12
|
+
if File.directory?(daemon_path)
|
13
|
+
env[:dns].ui.info "Existed daemons dir #{daemon_path}"
|
14
|
+
else
|
15
|
+
env[:dns].ui.info "Creating daemons dir #{daemon_path}"
|
16
|
+
FileUtils.mkdir_p(daemon_path)
|
17
|
+
end
|
18
|
+
|
19
|
+
@app.call(env)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module DNS
|
3
|
+
module Action
|
4
|
+
# Create resolver files in ~/.vagrant.d/tmp/dns/resolver
|
5
|
+
class CreateResolvers
|
6
|
+
def initialize(app, env)
|
7
|
+
@app = app
|
8
|
+
end
|
9
|
+
|
10
|
+
def call(env)
|
11
|
+
tmp_dns_path = env[:dns].tmp_path
|
12
|
+
resolver_folder = File.join(tmp_dns_path, "resolver")
|
13
|
+
|
14
|
+
port = VagrantPlugins::DNS.listen.first.last # 5300
|
15
|
+
tlds = env[:machine].config.dns.tlds
|
16
|
+
|
17
|
+
FileUtils.mkdir_p(resolver_folder)
|
18
|
+
|
19
|
+
tlds.each do |tld|
|
20
|
+
File.open(File.join(resolver_folder, tld), "w") do |f|
|
21
|
+
f << resolver_file(port)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
env[:dns].ui.info "Created resolvers for tlds #{tlds}"
|
26
|
+
|
27
|
+
@app.call(env)
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def resolver_file(port)
|
33
|
+
contents = <<-FILE
|
34
|
+
# this file is generated by vagrant-dns
|
35
|
+
nameserver 127.0.0.1
|
36
|
+
port #{port}
|
37
|
+
FILE
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module DNS
|
3
|
+
module Action
|
4
|
+
# Write dns patterns to ~/.vagrant.d/dns/config file.
|
5
|
+
class RegisterPatterns
|
6
|
+
def initialize(app, env)
|
7
|
+
@app = app
|
8
|
+
end
|
9
|
+
|
10
|
+
def call(env)
|
11
|
+
config_file = env[:dns].config_file
|
12
|
+
registry = File.exists?(config_file) ? \
|
13
|
+
YAML.load(File.read(config_file)) : {}
|
14
|
+
opts = prepare_opts(env[:machine].config)
|
15
|
+
patterns = opts[:patterns] || default_patterns(opts)
|
16
|
+
networks = opts[:networks].select { |i| i[0] == :private_network }
|
17
|
+
.flatten
|
18
|
+
|
19
|
+
ip = networks.empty? ? '127.0.0.1' : networks[1][:ip]
|
20
|
+
|
21
|
+
patterns.each do |p|
|
22
|
+
p = p.source if p.respond_to? :source # Regexp#to_s is unusable
|
23
|
+
registry[p] = ip
|
24
|
+
end
|
25
|
+
|
26
|
+
env[:dns].ui.info "Registering patterns #{registry}"
|
27
|
+
|
28
|
+
File.open(config_file, "w") { |f| f << YAML.dump(registry) }
|
29
|
+
|
30
|
+
@app.call(env)
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def prepare_opts(config)
|
36
|
+
{
|
37
|
+
tlds: config.dns.tlds,
|
38
|
+
patterns: config.dns.patterns,
|
39
|
+
host_name: config.vm.hostname,
|
40
|
+
networks: config.vm.networks
|
41
|
+
}
|
42
|
+
end
|
43
|
+
|
44
|
+
def default_patterns(opts)
|
45
|
+
if opts[:host_name]
|
46
|
+
opts[:tlds].map { |tld| /^.*#{opts[:host_name]}.#{tld}$/ }
|
47
|
+
else
|
48
|
+
env[:dns].ui.warn 'TLD but no host_name given. No patterns will \
|
49
|
+
be configured.'
|
50
|
+
[]
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module DNS
|
3
|
+
module Action
|
4
|
+
class SetupEnv
|
5
|
+
def initialize(app, env)
|
6
|
+
@app = app
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
env[:dns].tmp_path = File.join(env[:tmp_path], DNS.namespace)
|
11
|
+
env[:dns].daemon_path = File.join(env[:dns].tmp_path, "daemon")
|
12
|
+
env[:dns].config_file = File.join(env[:dns].tmp_path, "config")
|
13
|
+
env[:dns].dns_server = DNSServer.new \
|
14
|
+
dir: env[:dns].daemon_path,
|
15
|
+
config: env[:dns].config_file
|
16
|
+
|
17
|
+
@app.call(env)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require "vagrant-dns/dns_server"
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module DNS
|
5
|
+
module Action
|
6
|
+
class StartDNSServer
|
7
|
+
def initialize(app, env)
|
8
|
+
@app = app
|
9
|
+
end
|
10
|
+
|
11
|
+
def call(env)
|
12
|
+
env[:dns].ui.info "Restarting dns server..."
|
13
|
+
env[:dns].dns_server.restart!
|
14
|
+
|
15
|
+
@app.call(env)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require "vagrant-dns/dns_server"
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module DNS
|
5
|
+
module Action
|
6
|
+
class StopDNSServer
|
7
|
+
def initialize(app, env)
|
8
|
+
@app = app
|
9
|
+
end
|
10
|
+
|
11
|
+
def call(env)
|
12
|
+
env[:dns].ui.info "Stopping dns server..."
|
13
|
+
env[:dns].dns_server.stop!
|
14
|
+
|
15
|
+
@app.call(env)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require "pathname"
|
2
|
+
require "vagrant/action/builder"
|
3
|
+
|
4
|
+
require_relative "env"
|
5
|
+
|
6
|
+
module VagrantPlugins
|
7
|
+
module DNS
|
8
|
+
module Action
|
9
|
+
class << self
|
10
|
+
def setup
|
11
|
+
@setup ||= ::Vagrant::Action::Builder.new.tap do |b|
|
12
|
+
b.use ::Vagrant::Action::Builtin::EnvSet, dns: VagrantPlugins::DNS::Env.new
|
13
|
+
b.use SetupEnv
|
14
|
+
b.use CreateResolvers
|
15
|
+
b.use CreateDaemonsDir
|
16
|
+
b.use RegisterPatterns
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def clean
|
21
|
+
@clean ||= ::Vagrant::Action::Builder.new.tap do |b|
|
22
|
+
b.use ::Vagrant::Action::Builtin::EnvSet, dns: VagrantPlugins::DNS::Env.new
|
23
|
+
b.use SetupEnv
|
24
|
+
b.use StopDNSServer
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def start
|
29
|
+
@start ||= ::Vagrant::Action::Builder.new.tap do |b|
|
30
|
+
b.use ::Vagrant::Action::Builtin::EnvSet, dns: VagrantPlugins::DNS::Env.new
|
31
|
+
b.use SetupEnv
|
32
|
+
b.use StartDNSServer
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
action_root = Pathname.new(File.expand_path("../action", __FILE__))
|
38
|
+
autoload :SetupEnv, action_root.join("setup_env")
|
39
|
+
autoload :CreateResolvers, action_root.join("create_resolvers")
|
40
|
+
autoload :CreateDaemonsDir, action_root.join("create_daemons_dir")
|
41
|
+
autoload :RegisterPatterns, action_root.join("register_patterns")
|
42
|
+
autoload :StartDNSServer, action_root.join("start_dns_server")
|
43
|
+
autoload :StopDNSServer, action_root.join("stop_dns_server")
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module DNS
|
3
|
+
class Command < ::Vagrant.plugin("2", :command)
|
4
|
+
INSTALL_PATH = "/etc/resolver".freeze
|
5
|
+
|
6
|
+
def execute
|
7
|
+
tmp_dns_path = File.join @env.tmp_path, DNS.namespace
|
8
|
+
options = {}
|
9
|
+
|
10
|
+
opts = OptionParser.new do |o|
|
11
|
+
o.banner = "Usage: vagrant destroy [vm-name]"
|
12
|
+
o.separator ""
|
13
|
+
|
14
|
+
o.on("-f", "--install", "Install dns resolver on mac.") do |f|
|
15
|
+
begin
|
16
|
+
if File.directory?(INSTALL_PATH)
|
17
|
+
@env.ui.info "Existed install dir #{INSTALL_PATH}"
|
18
|
+
else
|
19
|
+
@env.ui.info "Creating install dir #{INSTALL_PATH}"
|
20
|
+
FileUtils.mkdir_p(INSTALL_PATH)
|
21
|
+
end
|
22
|
+
|
23
|
+
registered_resolvers = Dir[File.join(tmp_dns_path, "resolver", "*")]
|
24
|
+
|
25
|
+
@env.ui.info "Installing DNS resolvers #{registered_resolvers} to #{INSTALL_PATH}"
|
26
|
+
|
27
|
+
FileUtils.ln_s(registered_resolvers, INSTALL_PATH, force: true)
|
28
|
+
|
29
|
+
rescue Errno::EACCES => e
|
30
|
+
@env.ui.error "vagrant-dns needs superuser access to manipulate DNS settings"
|
31
|
+
@env.ui.error "DNS resolvers not installed"
|
32
|
+
|
33
|
+
rescue Errno::EEXIST => e
|
34
|
+
@env.ui.error "#{INSTALL_PATH} exists. Please remove it first to force override"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# Parse the options
|
40
|
+
argv = parse_options(opts)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module DNS
|
3
|
+
class Config < ::Vagrant.plugin("2", :config)
|
4
|
+
# config.dns.tld = "dev"
|
5
|
+
# config.dns.tlds = ["dev", "dom"]
|
6
|
+
#
|
7
|
+
def tld=(tlds)
|
8
|
+
@tlds = Array(tlds)
|
9
|
+
end
|
10
|
+
alias :tlds= :tld=
|
11
|
+
|
12
|
+
attr_reader :tlds
|
13
|
+
|
14
|
+
# config.dns.patterns = [/^.*promojam.dev$/, /^.*coca-cola.dev$/]
|
15
|
+
#
|
16
|
+
attr_accessor :patterns
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module DNS
|
3
|
+
class DNSServer
|
4
|
+
def initialize(options)
|
5
|
+
@config = options.fetch(:config) { raise "" }
|
6
|
+
@dir = options.fetch(:dir) { raise "" }
|
7
|
+
@log_dir = options.fetch(:dir, @dir)
|
8
|
+
|
9
|
+
@run_options = {
|
10
|
+
dir_mode: :normal,
|
11
|
+
dir: @dir,
|
12
|
+
log_output: true,
|
13
|
+
log_dir: @log_dir,
|
14
|
+
}
|
15
|
+
end
|
16
|
+
|
17
|
+
def start!
|
18
|
+
run! @run_options.merge ARGV: ["start"]
|
19
|
+
end
|
20
|
+
|
21
|
+
def stop!
|
22
|
+
run! @run_options.merge ARGV: ["stop"]
|
23
|
+
end
|
24
|
+
|
25
|
+
def run!(run_options)
|
26
|
+
require "daemons"
|
27
|
+
|
28
|
+
Daemons.run_proc("vagrant-dns", run_options) do
|
29
|
+
require 'rubydns'
|
30
|
+
require 'rubydns/system'
|
31
|
+
|
32
|
+
# Here the registry file has been created, so we can read it and
|
33
|
+
# respond!
|
34
|
+
registry = YAML.load(File.read(@config))
|
35
|
+
std_resolver = RubyDNS::Resolver.new(RubyDNS::System::nameservers)
|
36
|
+
|
37
|
+
RubyDNS::run_server(listen: VagrantPlugins::DNS.listen) do
|
38
|
+
registry.each do |pattern, ip|
|
39
|
+
match(Regexp.new(pattern), Resolv::DNS::Resource::IN::A) \
|
40
|
+
do |match_data, transaction|
|
41
|
+
transaction.respond!(ip)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
otherwise do |transaction|
|
46
|
+
transaction.passthrough!(std_resolver) do |reply, reply_name|
|
47
|
+
puts reply
|
48
|
+
puts reply_name
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def restart!
|
56
|
+
stop!
|
57
|
+
start!
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module DNS
|
3
|
+
# Environment data to build up and persist through the middleware chain
|
4
|
+
class Env
|
5
|
+
|
6
|
+
# Returns a scoped vagrant ui
|
7
|
+
#
|
8
|
+
# @return [Vagrant::UI::Interface]
|
9
|
+
attr_accessor :ui
|
10
|
+
|
11
|
+
# Returns the tmp path for this plugin.
|
12
|
+
#
|
13
|
+
# @return [Pathname]
|
14
|
+
attr_accessor :tmp_path
|
15
|
+
|
16
|
+
attr_accessor :daemon_path
|
17
|
+
|
18
|
+
attr_accessor :config_file
|
19
|
+
|
20
|
+
attr_accessor :dns_server
|
21
|
+
|
22
|
+
def initialize
|
23
|
+
@ui = ::Vagrant::UI::Colored.new.scope("dns")
|
24
|
+
end
|
25
|
+
|
26
|
+
def tmp_path
|
27
|
+
@tmp_path || raise("@tmp_path has not been set")
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
begin
|
2
|
+
require "vagrant"
|
3
|
+
rescue LoadError
|
4
|
+
raise "The Vagrant DNS plugin must be run within Vagrant."
|
5
|
+
end
|
6
|
+
|
7
|
+
# This is a sanity check to make sure no one is attempting to install
|
8
|
+
# this into an early Vagrant version.
|
9
|
+
if Vagrant::VERSION < "1.1.0"
|
10
|
+
raise "The Vagrant DNS plugin is only compatible with Vagrant 1.1+"
|
11
|
+
end
|
12
|
+
|
13
|
+
module VagrantPlugins
|
14
|
+
module DNS
|
15
|
+
class Plugin < ::Vagrant.plugin("2")
|
16
|
+
name "DNS"
|
17
|
+
|
18
|
+
class << self
|
19
|
+
def provision(hook)
|
20
|
+
hook.before ::Vagrant::Action::Builtin::ConfigValidate, Action.setup
|
21
|
+
hook.after ::Vagrant::Action::Builtin::Provision, Action.start
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
name "vagrant-dns"
|
26
|
+
|
27
|
+
action_hook(:rubydns_provision, :machine_action_up, &method(:provision))
|
28
|
+
action_hook(:rubydns_provision, :machine_action_provision, &method(:provision))
|
29
|
+
action_hook(:rubydns_cleanup, :machine_action_halt) do |hook|
|
30
|
+
hook.after(::Vagrant::Action::Builtin::GracefulHalt,
|
31
|
+
VagrantPlugins::DNS::Action.clean)
|
32
|
+
end
|
33
|
+
|
34
|
+
config(:dns) do
|
35
|
+
require_relative "config"
|
36
|
+
Config
|
37
|
+
end
|
38
|
+
|
39
|
+
command(:dns) do
|
40
|
+
require_relative "command"
|
41
|
+
Command
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
data/lib/vagrant-dns.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require "pathname"
|
2
|
+
require "vagrant-dns/plugin"
|
3
|
+
|
4
|
+
module VagrantPlugins
|
5
|
+
module DNS
|
6
|
+
lib_path = Pathname.new(File.expand_path("../vagrant-dns", __FILE__))
|
7
|
+
|
8
|
+
autoload :Action, lib_path.join("action")
|
9
|
+
# autoload :Errors, lib_path.join("errors")
|
10
|
+
|
11
|
+
# This returns the path to the source of this plugin.
|
12
|
+
#
|
13
|
+
# @return [Pathname]
|
14
|
+
def self.source_root
|
15
|
+
@source_root ||= Pathname.new(File.expand_path("../../", __FILE__))
|
16
|
+
end
|
17
|
+
|
18
|
+
# Returns the default interfaces that a ruby dns server listens to.
|
19
|
+
#
|
20
|
+
# @return [Array]
|
21
|
+
def self.listen
|
22
|
+
@listen ||= [[:udp, "127.0.0.1", 5300]]
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.namespace
|
26
|
+
@namespace ||= "dns"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/vagrant-dns.gemspec
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'vagrant-dns/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "lh-vagrant-dns"
|
8
|
+
spec.version = VagrantPlugins::DNS::VERSION
|
9
|
+
spec.authors = ["Lin He"]
|
10
|
+
spec.email = ["he9lin@gmail.com"]
|
11
|
+
spec.description = %q{A RubyDns plugin for Vagrant 1.1.x}
|
12
|
+
spec.summary = %q{A RubyDns plugin for Vagrant 1.1.x}
|
13
|
+
spec.homepage = "http://heyook.com"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.required_rubygems_version = ">= 1.3.6"
|
17
|
+
|
18
|
+
spec.add_runtime_dependency "rubydns", "~> 0.6.1"
|
19
|
+
spec.add_runtime_dependency "daemons", "~> 1.1.9"
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
|
24
|
+
# The following block of code determines the files that should be included
|
25
|
+
# in the gem. It does this by reading all the files in the directory where
|
26
|
+
# this gemspec is, and parsing out the ignored files from the gitignore.
|
27
|
+
# Note that the entire gitignore(5) syntax is not supported, specifically
|
28
|
+
# the "!" syntax, but it should mostly work correctly.
|
29
|
+
root_path = File.dirname(__FILE__)
|
30
|
+
all_files = Dir.chdir(root_path) { Dir.glob("**/{*,.*}") }
|
31
|
+
all_files.reject! { |file| [".", ".."].include?(File.basename(file)) }
|
32
|
+
gitignore_path = File.join(root_path, ".gitignore")
|
33
|
+
gitignore = File.readlines(gitignore_path)
|
34
|
+
gitignore.map! { |line| line.chomp.strip }
|
35
|
+
gitignore.reject! { |line| line.empty? || line =~ /^(#|!)/ }
|
36
|
+
|
37
|
+
unignored_files = all_files.reject do |file|
|
38
|
+
# Ignore any directories, the gemspec only cares about files
|
39
|
+
next true if File.directory?(file)
|
40
|
+
|
41
|
+
# Ignore any paths that match anything in the gitignore. We do
|
42
|
+
# two tests here:
|
43
|
+
#
|
44
|
+
# - First, test to see if the entire path matches the gitignore.
|
45
|
+
# - Second, match if the basename does, this makes it so that things
|
46
|
+
# like '.DS_Store' will match sub-directories too (same behavior
|
47
|
+
# as git).
|
48
|
+
#
|
49
|
+
gitignore.any? do |ignore|
|
50
|
+
File.fnmatch(ignore, file, File::FNM_PATHNAME) ||
|
51
|
+
File.fnmatch(ignore, File.basename(file), File::FNM_PATHNAME)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
spec.files = unignored_files
|
56
|
+
spec.executables = unignored_files.map { |f| f[/^bin\/(.*)/, 1] }.compact
|
57
|
+
spec.require_path = 'lib'
|
58
|
+
end
|
metadata
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lh-vagrant-dns
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1.dev
|
5
|
+
prerelease: 6
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Lin He
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-04-14 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.6.1
|
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.6.1
|
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: 1.1.9
|
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: 1.1.9
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: bundler
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '1.3'
|
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: '1.3'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rake
|
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
|
+
description: A RubyDns plugin for Vagrant 1.1.x
|
79
|
+
email:
|
80
|
+
- he9lin@gmail.com
|
81
|
+
executables: []
|
82
|
+
extensions: []
|
83
|
+
extra_rdoc_files: []
|
84
|
+
files:
|
85
|
+
- Gemfile
|
86
|
+
- lib/vagrant-dns/action/create_daemons_dir.rb
|
87
|
+
- lib/vagrant-dns/action/create_resolvers.rb
|
88
|
+
- lib/vagrant-dns/action/register_patterns.rb
|
89
|
+
- lib/vagrant-dns/action/setup_env.rb
|
90
|
+
- lib/vagrant-dns/action/start_dns_server.rb
|
91
|
+
- lib/vagrant-dns/action/stop_dns_server.rb
|
92
|
+
- lib/vagrant-dns/action.rb
|
93
|
+
- lib/vagrant-dns/command.rb
|
94
|
+
- lib/vagrant-dns/config.rb
|
95
|
+
- lib/vagrant-dns/dns_server.rb
|
96
|
+
- lib/vagrant-dns/env.rb
|
97
|
+
- lib/vagrant-dns/env_helper.rb
|
98
|
+
- lib/vagrant-dns/plugin.rb
|
99
|
+
- lib/vagrant-dns/version.rb
|
100
|
+
- lib/vagrant-dns.rb
|
101
|
+
- LICENSE.txt
|
102
|
+
- Rakefile
|
103
|
+
- README.md
|
104
|
+
- vagrant-dns.gemspec
|
105
|
+
- .gitignore
|
106
|
+
homepage: http://heyook.com
|
107
|
+
licenses:
|
108
|
+
- MIT
|
109
|
+
post_install_message:
|
110
|
+
rdoc_options: []
|
111
|
+
require_paths:
|
112
|
+
- lib
|
113
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
114
|
+
none: false
|
115
|
+
requirements:
|
116
|
+
- - ! '>='
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
120
|
+
none: false
|
121
|
+
requirements:
|
122
|
+
- - ! '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 1.3.6
|
125
|
+
requirements: []
|
126
|
+
rubyforge_project:
|
127
|
+
rubygems_version: 1.8.23
|
128
|
+
signing_key:
|
129
|
+
specification_version: 3
|
130
|
+
summary: A RubyDns plugin for Vagrant 1.1.x
|
131
|
+
test_files: []
|