landrush 0.13.1 → 0.14.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/Gemfile +1 -1
- data/README.md +1 -1
- data/examples/Vagrantfile +2 -2
- data/lib/landrush.rb +1 -0
- data/lib/landrush/action/setup.rb +8 -5
- data/lib/landrush/action/teardown.rb +8 -7
- data/lib/landrush/cap/linux/read_host_visible_ip_address.rb +11 -3
- data/lib/landrush/config.rb +32 -22
- data/lib/landrush/resolver_config.rb +1 -6
- data/lib/landrush/store.rb +8 -0
- data/lib/landrush/version.rb +1 -1
- data/test/landrush/action/setup_test.rb +1 -2
- data/test/landrush/cap/linux/read_host_visible_ip_address_test.rb +39 -0
- data/test/landrush/config_test.rb +23 -0
- data/test/test_helper.rb +2 -2
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ec605e64f20e01e018e99697a30959d6e853e08c
|
4
|
+
data.tar.gz: 9f277d17166bf5519773ef74a504a54599624ddf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8b0f812b769d51e99b15402c0a8caf65e901f1b6055b1dbe4e1e788cfd1f1a4125a2337a9b67b667ab312186dc4b41da51b61261fcb5b4f9893881745bdde15f
|
7
|
+
data.tar.gz: 045f68ee5fd1ab4aea77c88a8ef53f16be68c415f97bf9763a406cd2ba3b1384cc0a0f7d21948a3feab29575e87e5bef68a5b25f0fed80d06ac80a2202050e5a
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
data/examples/Vagrantfile
CHANGED
data/lib/landrush.rb
CHANGED
@@ -52,8 +52,10 @@ module Landrush
|
|
52
52
|
def setup_static_dns
|
53
53
|
config.hosts.each do |hostname, dns_value|
|
54
54
|
dns_value ||= machine.guest.capability(:read_host_visible_ip_address)
|
55
|
-
|
56
|
-
|
55
|
+
if !Store.hosts.has?(hostname, dns_value)
|
56
|
+
info "adding static entry: #{hostname} => #{dns_value}"
|
57
|
+
Store.hosts.set hostname, dns_value
|
58
|
+
end
|
57
59
|
end
|
58
60
|
end
|
59
61
|
|
@@ -61,14 +63,15 @@ module Landrush
|
|
61
63
|
ip_address = machine.config.landrush.host_ip_address ||
|
62
64
|
machine.guest.capability(:read_host_visible_ip_address)
|
63
65
|
|
64
|
-
info "adding machine entry: #{machine_hostname} => #{ip_address}"
|
65
|
-
|
66
66
|
if not machine_hostname.match(config.tld)
|
67
67
|
log :error, "hostname #{machine_hostname} does not match the configured TLD: #{config.tld}"
|
68
68
|
log :error, "You will not be able to access #{machine_hostname} from the host"
|
69
69
|
end
|
70
70
|
|
71
|
-
Store.hosts.
|
71
|
+
if !Store.hosts.has?(machine_hostname, ip_address)
|
72
|
+
info "adding machine entry: #{machine_hostname} => #{ip_address}"
|
73
|
+
Store.hosts.set(machine_hostname, ip_address)
|
74
|
+
end
|
72
75
|
end
|
73
76
|
|
74
77
|
def private_network_exists?
|
@@ -16,21 +16,22 @@ module Landrush
|
|
16
16
|
if DependentVMs.none?
|
17
17
|
teardown_static_dns
|
18
18
|
teardown_server
|
19
|
-
else
|
20
|
-
info "there are #{DependentVMs.count} VMs left, leaving DNS server and static entries"
|
21
|
-
info DependentVMs.list.map { |dvm| " - #{dvm}" }.join("\n")
|
22
19
|
end
|
23
20
|
end
|
24
21
|
|
25
22
|
def teardown_machine_dns
|
26
|
-
|
27
|
-
|
23
|
+
if Store.hosts.has? machine_hostname
|
24
|
+
info "removing machine entry: #{machine_hostname}"
|
25
|
+
Store.hosts.delete(machine_hostname)
|
26
|
+
end
|
28
27
|
end
|
29
28
|
|
30
29
|
def teardown_static_dns
|
31
30
|
config.hosts.each do |static_hostname, _|
|
32
|
-
|
33
|
-
|
31
|
+
if Store.hosts.has? static_hostname
|
32
|
+
info "removing static entry: #{static_hostname}"
|
33
|
+
Store.hosts.delete static_hostname
|
34
|
+
end
|
34
35
|
end
|
35
36
|
end
|
36
37
|
|
@@ -22,16 +22,24 @@ module Landrush
|
|
22
22
|
# TODO: Find a better heuristic for this implementation.
|
23
23
|
#
|
24
24
|
def self.read_host_visible_ip_address(machine)
|
25
|
-
result
|
25
|
+
result = ""
|
26
26
|
machine.communicate.execute(command) do |type, data|
|
27
27
|
result << data if type == :stdout
|
28
28
|
end
|
29
29
|
|
30
|
-
result.chomp.split("\n").last
|
30
|
+
last_line = result.chomp.split("\n").last || ''
|
31
|
+
addresses = last_line.split(/\s+/).map { |address| IPAddr.new(address) }
|
32
|
+
addresses = addresses.reject { |address| address.ipv6? }
|
33
|
+
|
34
|
+
if addresses.empty?
|
35
|
+
raise "Cannot detect IP address, command `#{command}` returned `#{result}`"
|
36
|
+
end
|
37
|
+
|
38
|
+
addresses.last.to_s
|
31
39
|
end
|
32
40
|
|
33
41
|
def self.command
|
34
|
-
%Q(hostname -I
|
42
|
+
%Q(hostname -I)
|
35
43
|
end
|
36
44
|
end
|
37
45
|
end
|
data/lib/landrush/config.rb
CHANGED
@@ -1,19 +1,30 @@
|
|
1
1
|
module Landrush
|
2
2
|
class Config < Vagrant.plugin('2', :config)
|
3
3
|
attr_accessor :hosts
|
4
|
+
attr_accessor :enabled
|
5
|
+
attr_accessor :tld
|
4
6
|
attr_accessor :upstream_servers
|
5
7
|
attr_accessor :host_ip_address
|
8
|
+
attr_accessor :guest_redirect_dns
|
9
|
+
|
10
|
+
DEFAULTS = {
|
11
|
+
:enabled => false,
|
12
|
+
:tld => 'vagrant.dev',
|
13
|
+
:upstream_servers => [[:udp, '8.8.8.8', 53], [:tcp, '8.8.8.8', 53]],
|
14
|
+
:host_ip_address => nil,
|
15
|
+
:guest_redirect_dns => true
|
16
|
+
}
|
6
17
|
|
7
18
|
def initialize
|
8
19
|
@hosts = {}
|
9
|
-
@enabled =
|
10
|
-
@
|
11
|
-
@
|
12
|
-
@
|
13
|
-
@guest_redirect_dns =
|
20
|
+
@enabled = UNSET_VALUE
|
21
|
+
@tld = UNSET_VALUE
|
22
|
+
@upstream_servers = UNSET_VALUE
|
23
|
+
@host_ip_address = UNSET_VALUE
|
24
|
+
@guest_redirect_dns = UNSET_VALUE
|
14
25
|
end
|
15
26
|
|
16
|
-
def enable
|
27
|
+
def enable
|
17
28
|
@enabled = true
|
18
29
|
end
|
19
30
|
|
@@ -22,11 +33,7 @@ module Landrush
|
|
22
33
|
end
|
23
34
|
|
24
35
|
def enabled?
|
25
|
-
|
26
|
-
end
|
27
|
-
|
28
|
-
def guest_redirect_dns=(guest_redirect_dns=true)
|
29
|
-
@guest_redirect_dns=guest_redirect_dns
|
36
|
+
!!@enabled
|
30
37
|
end
|
31
38
|
|
32
39
|
def guest_redirect_dns?
|
@@ -37,16 +44,8 @@ module Landrush
|
|
37
44
|
@hosts[hostname] = ip_address
|
38
45
|
end
|
39
46
|
|
40
|
-
def tld
|
41
|
-
@tld ||= @default_tld
|
42
|
-
end
|
43
|
-
|
44
|
-
def tld=(tld)
|
45
|
-
@tld = tld
|
46
|
-
end
|
47
|
-
|
48
47
|
def upstream(ip, port=53, protocol=nil)
|
49
|
-
if @upstream_servers ==
|
48
|
+
if @upstream_servers == UNSET_VALUE
|
50
49
|
@upstream_servers = []
|
51
50
|
end
|
52
51
|
|
@@ -64,13 +63,24 @@ module Landrush
|
|
64
63
|
end
|
65
64
|
end
|
66
65
|
|
66
|
+
def finalize!
|
67
|
+
DEFAULTS.each do |name, value|
|
68
|
+
if instance_variable_get('@' + name.to_s) == UNSET_VALUE
|
69
|
+
instance_variable_set '@' + name.to_s, value
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
67
74
|
def validate(machine)
|
75
|
+
errors = _detected_errors
|
76
|
+
|
68
77
|
if enabled?
|
69
78
|
unless machine.config.vm.hostname.to_s.length > 0
|
70
|
-
|
79
|
+
errors << 'you must specify a hostname so we can make a DNS entry for it'
|
71
80
|
end
|
72
81
|
end
|
73
|
-
|
82
|
+
|
83
|
+
{ 'landrush' => errors }
|
74
84
|
end
|
75
85
|
end
|
76
86
|
end
|
@@ -23,7 +23,7 @@ module Landrush
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def info(msg)
|
26
|
-
@env[:ui].info(msg)
|
26
|
+
@env[:ui].info("[landrush] #{msg}")
|
27
27
|
end
|
28
28
|
|
29
29
|
def desired_contents; <<-EOS.gsub(/^ /, '')
|
@@ -61,11 +61,6 @@ module Landrush
|
|
61
61
|
end
|
62
62
|
|
63
63
|
def ensure_config_exists!
|
64
|
-
unless osx?
|
65
|
-
puts "Not an OSX machine, so skipping host DNS resolver config."
|
66
|
-
return
|
67
|
-
end
|
68
|
-
|
69
64
|
if contents_match?
|
70
65
|
info "Host DNS resolver config looks good."
|
71
66
|
else
|
data/lib/landrush/store.rb
CHANGED
@@ -26,6 +26,14 @@ module Landrush
|
|
26
26
|
write(current_config.reject { |k, _| k == key })
|
27
27
|
end
|
28
28
|
|
29
|
+
def has?(key, value = nil)
|
30
|
+
if value.nil?
|
31
|
+
current_config.has_key? key
|
32
|
+
else
|
33
|
+
current_config[key] == value
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
29
37
|
def find(search)
|
30
38
|
current_config.keys.detect do |key|
|
31
39
|
key.casecmp(search) == 0 ||
|
data/lib/landrush/version.rb
CHANGED
@@ -77,9 +77,8 @@ module Landrush
|
|
77
77
|
it "does nothing if it is not enabled via config" do
|
78
78
|
app = Proc.new {}
|
79
79
|
setup = Setup.new(app, nil)
|
80
|
-
env = fake_environment
|
80
|
+
env = fake_environment(enabled: false)
|
81
81
|
|
82
|
-
env[:machine].config.landrush.disable
|
83
82
|
setup.call(env)
|
84
83
|
|
85
84
|
Store.hosts.get('somehost.vagrant.dev').must_equal nil
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Landrush
|
4
|
+
module Cap
|
5
|
+
module Linux
|
6
|
+
|
7
|
+
describe ReadHostVisibleIpAddress do
|
8
|
+
describe 'read_host_visible_ip_address' do
|
9
|
+
let (:machine) { fake_machine }
|
10
|
+
|
11
|
+
it 'should read the last address' do
|
12
|
+
machine.communicate.stub_command(Landrush::Cap::Linux::ReadHostVisibleIpAddress.command, "1.2.3.4 5.6.7.8\n")
|
13
|
+
machine.guest.capability(:read_host_visible_ip_address).must_equal '5.6.7.8'
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should ignore IPv6 addresses' do
|
17
|
+
machine.communicate.stub_command(Landrush::Cap::Linux::ReadHostVisibleIpAddress.command, "1.2.3.4 5.6.7.8 fdb2:2c26:f4e4:0:21c:42ff:febc:ea4f\n")
|
18
|
+
machine.guest.capability(:read_host_visible_ip_address).must_equal '5.6.7.8'
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'should fail on invalid address' do
|
22
|
+
machine.communicate.stub_command(Landrush::Cap::Linux::ReadHostVisibleIpAddress.command, "hello world\n")
|
23
|
+
lambda {
|
24
|
+
machine.guest.capability(:read_host_visible_ip_address)
|
25
|
+
}.must_raise(IPAddr::InvalidAddressError)
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should fail without address' do
|
29
|
+
machine.communicate.stub_command(Landrush::Cap::Linux::ReadHostVisibleIpAddress.command, "\n")
|
30
|
+
lambda {
|
31
|
+
machine.guest.capability(:read_host_visible_ip_address)
|
32
|
+
}.must_raise(RuntimeError, 'Cannot detect IP address, command `hostname -I` returned ``')
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
describe 'Landrush::Config' do
|
4
|
+
it "supports enabling via accessor style" do
|
5
|
+
machine = fake_machine
|
6
|
+
config = machine.config.landrush
|
7
|
+
|
8
|
+
machine.config.landrush.enabled = true
|
9
|
+
config.enabled?.must_equal true
|
10
|
+
machine.config.landrush.enabled = false
|
11
|
+
config.enabled?.must_equal false
|
12
|
+
end
|
13
|
+
|
14
|
+
it "is backwards-compatible with the old method call style" do
|
15
|
+
machine = fake_machine
|
16
|
+
config = machine.config.landrush
|
17
|
+
|
18
|
+
machine.config.landrush.enable
|
19
|
+
config.enabled?.must_equal true
|
20
|
+
machine.config.landrush.disable
|
21
|
+
config.enabled?.must_equal false
|
22
|
+
end
|
23
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -8,7 +8,7 @@ require 'landrush/cap/linux/read_host_visible_ip_address'
|
|
8
8
|
|
9
9
|
require 'minitest/autorun'
|
10
10
|
|
11
|
-
def fake_environment(options={})
|
11
|
+
def fake_environment(options = { enabled: true })
|
12
12
|
{ machine: fake_machine(options), ui: FakeUI }
|
13
13
|
end
|
14
14
|
|
@@ -89,7 +89,7 @@ def fake_machine(options={})
|
|
89
89
|
"#{options.fetch(:ip, '1.2.3.4')}\n"
|
90
90
|
)
|
91
91
|
|
92
|
-
machine.config.landrush.
|
92
|
+
machine.config.landrush.enabled = options.fetch(:enabled, false)
|
93
93
|
machine.config.vm.hostname = options.fetch(:hostname, 'somehost.vagrant.dev')
|
94
94
|
|
95
95
|
machine
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: landrush
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.14.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul Hinze
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-05-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubydns
|
@@ -80,6 +80,8 @@ files:
|
|
80
80
|
- lib/landrush/version.rb
|
81
81
|
- test/landrush/action/setup_test.rb
|
82
82
|
- test/landrush/action/teardown_test.rb
|
83
|
+
- test/landrush/cap/linux/read_host_visible_ip_address_test.rb
|
84
|
+
- test/landrush/config_test.rb
|
83
85
|
- test/landrush/dependent_vms_test.rb
|
84
86
|
- test/landrush/resolver_config_test.rb
|
85
87
|
- test/landrush/server_test.rb
|
@@ -110,13 +112,15 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
110
112
|
version: '0'
|
111
113
|
requirements: []
|
112
114
|
rubyforge_project:
|
113
|
-
rubygems_version: 2.2.
|
115
|
+
rubygems_version: 2.2.2
|
114
116
|
signing_key:
|
115
117
|
specification_version: 4
|
116
118
|
summary: a vagrant plugin providing consistent DNS visible on host and guests
|
117
119
|
test_files:
|
118
120
|
- test/landrush/action/setup_test.rb
|
119
121
|
- test/landrush/action/teardown_test.rb
|
122
|
+
- test/landrush/cap/linux/read_host_visible_ip_address_test.rb
|
123
|
+
- test/landrush/config_test.rb
|
120
124
|
- test/landrush/dependent_vms_test.rb
|
121
125
|
- test/landrush/resolver_config_test.rb
|
122
126
|
- test/landrush/server_test.rb
|