vagrant-command-dns 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +101 -8
- data/lib/vagrant-command-dns/action/get_ip.rb +21 -18
- data/lib/vagrant-command-dns/action/host/create.rb +22 -12
- data/lib/vagrant-command-dns/action/host/destroy.rb +22 -8
- data/lib/vagrant-command-dns/action/show_ip.rb +3 -2
- data/lib/vagrant-command-dns/version.rb +1 -1
- data/locales/en.yml +7 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cd77fab9b2c0d0d39c8b38f2db26615e58c27c84
|
4
|
+
data.tar.gz: 8cfd993bbc28ced4e07711752166157fa8bdf7b6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 42520e3d9c9fc2332455695663dfafdc7b246f2df7d74b9a43765943b2c38cf5f3e93864a50ad3d841e9de45d7b7d15b9e5588d7498dfca46e528dbbf54f196c
|
7
|
+
data.tar.gz: e5725a24eb19b3b81b90d90aa9598fbcedc131830d9822f7774cd0dc9d0ff452fd2b6c5768e2fe0794bafda492e87ef78565f2675d2a41e71933aef733d030c9
|
data/README.md
CHANGED
@@ -1,25 +1,118 @@
|
|
1
1
|
VagrantPlugins::CommandDns
|
2
2
|
==========================
|
3
3
|
|
4
|
-
|
4
|
+
[![Gem Version](https://badge.fury.io/rb/vagrant-command-dns.svg)](https://badge.fury.io/rb/vagrant-command-dns)
|
5
5
|
|
6
|
+
Todo:
|
7
|
+
- add confirm to destroy subcommands
|
8
|
+
- add windows support
|
6
9
|
|
7
|
-
#
|
8
|
-
- Untested in multi-machine environments
|
9
10
|
|
11
|
+
# Installation
|
12
|
+
```
|
13
|
+
vagrant plugin install vagrant-command-dns
|
14
|
+
```
|
10
15
|
|
11
|
-
# Development
|
12
16
|
|
13
|
-
|
17
|
+
# Configuration
|
18
|
+
- [optional] `aliases` List of FQDNs to register this box's ip with
|
19
|
+
- [optional] `route53_version` The version of the AWS api to use
|
20
|
+
- [optional] `route53_access_key_id` The access key ID for accessing AWS
|
21
|
+
- [optional] `route53_secret_access_key` The secret access key for accessing AWS
|
22
|
+
- [optional] `route53_session_token` The token associated with the key for accessing AWS
|
23
|
+
- [optional] `route53_zone_id` The Route53 Zone ID
|
14
24
|
|
15
|
-
|
25
|
+
|
26
|
+
# Usage
|
27
|
+
```
|
28
|
+
vagrant dns
|
29
|
+
Usage: vagrant dns <subcommand>
|
30
|
+
|
31
|
+
Available subcommands:
|
32
|
+
host
|
33
|
+
ip
|
34
|
+
route53
|
35
|
+
|
36
|
+
For help on any individual subcommand run `vagrant dns <subcommand> -h`
|
37
|
+
```
|
38
|
+
|
39
|
+
|
40
|
+
## Hostname and Aliases
|
41
|
+
The hostname and any aliases will be used to create records
|
42
|
+
```
|
43
|
+
config.vm.hostname = "www.example.com"
|
44
|
+
config.route53.aliases = ["alias.example.com", "alias2.example.com"]
|
45
|
+
```
|
46
|
+
|
47
|
+
|
48
|
+
## Network
|
49
|
+
This plugin works only for `:private_network` and `:public_network`.
|
50
|
+
```
|
51
|
+
config.vm.network :private_network, ip: "172.18.7.1"
|
52
|
+
```
|
53
|
+
|
54
|
+
or
|
55
|
+
|
56
|
+
```
|
57
|
+
config.vm.network :public_network
|
58
|
+
```
|
59
|
+
|
60
|
+
|
61
|
+
## Box Providers
|
62
|
+
Currently only VirtualBox is supported, because that is what I have to test with.
|
63
|
+
|
64
|
+
Pull requests are welcome.
|
65
|
+
|
66
|
+
|
67
|
+
## DNS Providers
|
68
|
+
Currently only editing the host's (linux/osx) `/etc/hosts` file and AWS Route53 are supported.
|
69
|
+
|
70
|
+
Pull requests are welcome.
|
71
|
+
|
72
|
+
|
73
|
+
# Route53
|
74
|
+
## IAM Permissions
|
75
|
+
```
|
76
|
+
{
|
77
|
+
"Version": "2012-10-17",
|
78
|
+
"Statement": [
|
79
|
+
{
|
80
|
+
"Effect": "Allow",
|
81
|
+
"Action": [
|
82
|
+
"route53:CreateHostedZone",
|
83
|
+
"route53:GetHostedZone",
|
84
|
+
"route53:ListHostedZones",
|
85
|
+
"route53:ChangeResourceRecordSets",
|
86
|
+
"route53:ListResourceRecordSets"
|
87
|
+
],
|
88
|
+
"Resource": [
|
89
|
+
"arn:aws:route53:::hostedzone/1A2B3C4D5E6F"
|
90
|
+
]
|
91
|
+
}
|
92
|
+
]
|
93
|
+
}
|
94
|
+
```
|
95
|
+
|
96
|
+
|
97
|
+
# FAQ
|
98
|
+
Q) I reloaded my box and the `dns` command is only returning the VirtualBox NAT interface.
|
99
|
+
A) Run reload once more. This is a known issue with no workaround at the moment.
|
100
|
+
|
101
|
+
|
102
|
+
# Shortfalls
|
103
|
+
- Untested in multi-machine environments
|
104
|
+
- Does not support Windows hosts or guests
|
105
|
+
|
106
|
+
|
107
|
+
# Sponsors
|
108
|
+
This plugin was made possible by [Shiftgig](https://www.shiftgig.com)
|
16
109
|
|
17
110
|
|
18
111
|
# Contributing
|
112
|
+
Pull requests are welcome on GitHub at https://github.com/cornfeedhobo/vagrant-command-dns.
|
19
113
|
|
20
|
-
|
114
|
+
This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
21
115
|
|
22
116
|
|
23
117
|
# License
|
24
|
-
|
25
118
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
@@ -19,25 +19,29 @@ module VagrantPlugins
|
|
19
19
|
ip = nil
|
20
20
|
|
21
21
|
case env[:machine].provider_name
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
22
|
+
when :virtualbox
|
23
|
+
env[:machine].config.vm.networks.each do |network|
|
24
|
+
key, options = network[0], network[1]
|
25
|
+
if key == :private_network or key == :public_network
|
26
|
+
if options[:dns] != 'skip'
|
27
|
+
case key
|
28
|
+
when :private_network
|
29
|
+
cmd = "vagrant ssh -c \"ip -4 addr show \\$(ip -4 route | tail -n1 | awk '{print \\$3}') | grep -oP '(?<=inet\\s)\\d+(\\.\\d+){3}'\" 2>/dev/null"
|
30
|
+
when :public_network
|
31
|
+
cmd = "vagrant ssh -c \"ip -4 addr show \\$(ip -4 route | head -n2 | tail -n1 | awk '{print \\$5}') | grep -oP '(?<=inet\\s)\\d+(\\.\\d+){3}'\" 2>/dev/null"
|
32
|
+
end
|
33
|
+
begin
|
34
|
+
ip = IPAddr.new(`#{cmd}`.chomp)
|
35
|
+
rescue IPAddr::InvalidAddressError
|
36
|
+
raise Errors::InvalidAddressError
|
37
|
+
end
|
38
|
+
else
|
39
|
+
env[:ui].info(I18n.t('vagrant_command_dns.config.network_skip'))
|
40
|
+
end
|
35
41
|
end
|
36
42
|
end
|
37
|
-
|
38
|
-
|
39
|
-
else
|
40
|
-
raise Errors::UnsupportedProviderError
|
43
|
+
else
|
44
|
+
raise Errors::UnsupportedProviderError
|
41
45
|
end
|
42
46
|
|
43
47
|
unless ip.nil?
|
@@ -48,7 +52,6 @@ module VagrantPlugins
|
|
48
52
|
|
49
53
|
record_map = {}
|
50
54
|
host_names.each do |h|
|
51
|
-
env[:ui].info "#{h} #{ip.to_string}"
|
52
55
|
record_map[h] = ip.to_string
|
53
56
|
end
|
54
57
|
|
@@ -16,27 +16,37 @@ module VagrantPlugins
|
|
16
16
|
raise Errors::MachineStateError, state: 'running'
|
17
17
|
end
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
19
|
+
record_map = env[:record_map]
|
20
|
+
|
21
|
+
File.open('/etc/hosts', 'r') do |file|
|
22
|
+
file.each_line do |line|
|
23
|
+
env[:record_map].each do |hostname, ip|
|
24
|
+
precise_pattern = Regexp.new('^\s*' + ip + '\s+' + hostname)
|
25
|
+
loose_pattern = Regexp.new('^\s*[0-9]{1,3}[0-9]{1,3}[0-9]{1,3}[0-9]{1,3}\s+' + hostname)
|
25
26
|
if line.match(/#{precise_pattern}/)
|
26
|
-
|
27
|
-
|
28
|
-
return
|
27
|
+
record_map.delete(hostname)
|
28
|
+
env[:ui].info(I18n.t('vagrant_command_dns.command.host.create_exists_match', ip: ip, hostname: hostname))
|
29
29
|
elsif line.match(/#{loose_pattern}/)
|
30
30
|
env[:ui].info(I18n.t('vagrant_command_dns.command.host.create_exists_conflict'))
|
31
31
|
end
|
32
32
|
end
|
33
33
|
end
|
34
|
+
end
|
35
|
+
|
36
|
+
lines = []
|
37
|
+
record_map.each do |hostname, ip|
|
34
38
|
lines.push("#{ip} #{hostname}")
|
35
39
|
end
|
36
40
|
|
37
|
-
|
38
|
-
|
39
|
-
|
41
|
+
if lines.length > 0
|
42
|
+
content = lines.join("\n").strip
|
43
|
+
if system("sudo sh -c 'echo \"#{content}\" >> /etc/hosts'")
|
44
|
+
record_map.each do |hostname, ip|
|
45
|
+
env[:ui].info(I18n.t('vagrant_command_dns.command.host.create_success', ip: ip, hostname: hostname))
|
46
|
+
end
|
47
|
+
else
|
48
|
+
env[:ui].error(I18n.t('vagrant_command_dns.command.host.edit_error'))
|
49
|
+
end
|
40
50
|
end
|
41
51
|
|
42
52
|
@app.call(env)
|
@@ -18,25 +18,39 @@ module VagrantPlugins
|
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
+
# read the file into memory to save reading it for each alias
|
21
22
|
lines = []
|
23
|
+
File.open('/etc/hosts', 'r') do |file|
|
24
|
+
file.each_line do |line|
|
25
|
+
lines.push(line.chomp)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
destroyed = {}
|
22
30
|
env[:record_map].each do |hostname, ip|
|
23
31
|
if env[:machine].config.dns.__skip
|
24
32
|
record_pattern = Regexp.new('^\s*[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\s+' + hostname)
|
25
33
|
else
|
26
34
|
record_pattern = Regexp.new('^\s*' + ip + '\s+' + hostname)
|
27
35
|
end
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
36
|
+
|
37
|
+
lines.each do |line|
|
38
|
+
if line.match(/#{record_pattern}/)
|
39
|
+
lines.delete(line)
|
40
|
+
destroyed[hostname] = ip
|
33
41
|
end
|
34
42
|
end
|
35
43
|
end
|
36
44
|
|
37
|
-
|
38
|
-
|
39
|
-
|
45
|
+
if destroyed.length > 0
|
46
|
+
content = lines.join("\n").strip
|
47
|
+
if system("sudo sh -c 'echo \"#{content}\" > /etc/hosts'")
|
48
|
+
destroyed.each do |hostname, ip|
|
49
|
+
env[:ui].info(I18n.t('vagrant_command_dns.command.host.destroy_success', hostname: hostname))
|
50
|
+
end
|
51
|
+
else
|
52
|
+
env[:ui].error(I18n.t('vagrant_command_dns.command.host.edit_error'))
|
53
|
+
end
|
40
54
|
end
|
41
55
|
|
42
56
|
@app.call(env)
|
data/locales/en.yml
CHANGED
@@ -2,6 +2,8 @@ en:
|
|
2
2
|
vagrant_command_dns:
|
3
3
|
|
4
4
|
config:
|
5
|
+
network_skip: |-
|
6
|
+
Skip requested for network in Vagrantfile
|
5
7
|
route53_zone_id_required: |-
|
6
8
|
A zone ID must be specified via "route53_zone_id"
|
7
9
|
route53_access_key_id_required: |-
|
@@ -21,10 +23,14 @@ en:
|
|
21
23
|
host:
|
22
24
|
edit_error: |-
|
23
25
|
Unable to edit /etc/hosts. Consult documentation or submit a pull request.
|
26
|
+
create_success: |-
|
27
|
+
/etc/hosts record created for %{ip} %{hostname}
|
24
28
|
create_exists_match: |-
|
25
29
|
/etc/hosts record exists for %{ip} %{hostname}
|
26
30
|
create_exists_conflict: |-
|
27
|
-
|
31
|
+
Potentially conflicting entries found in /etc/hosts. Please update manually...
|
32
|
+
destroy_success: |-
|
33
|
+
/etc/hosts record destroyed for %{hostname}
|
28
34
|
|
29
35
|
route53:
|
30
36
|
fog_error: |-
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vagrant-command-dns
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- cornfeedhobo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-03-
|
11
|
+
date: 2016-03-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fog
|