vagrant-command-dns 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/vagrant-command-dns/action/get_ip.rb +21 -12
- data/lib/vagrant-command-dns/action/host/create.rb +5 -1
- data/lib/vagrant-command-dns/action/host/destroy.rb +1 -1
- data/lib/vagrant-command-dns/action/route53/connect.rb +7 -0
- data/lib/vagrant-command-dns/action/route53/create.rb +5 -1
- data/lib/vagrant-command-dns/action/route53/destroy.rb +1 -1
- data/lib/vagrant-command-dns/config.rb +18 -16
- data/lib/vagrant-command-dns/errors.rb +10 -10
- data/lib/vagrant-command-dns/version.rb +1 -1
- data/locales/en.yml +35 -38
- 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: b411197419ba64b4a43e66157cae7983eea8fa08
|
4
|
+
data.tar.gz: f4285387240a7f19431a60306937d1f80427e084
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cdc10966cde761d47c266c74f463cf352b505b5c7d82798a7a7e0b0cb02097881eeadecfbaa5ab245d586a0d0326fa0f904e922b08667f54a935b7766b160873
|
7
|
+
data.tar.gz: 41e08550046de23227dc4af2a457174078d3b04cc39141862d33fc57c1f8c38647b4a1da0eb1a47f018df99ee103d726a798d157cbb608c3b66fedfba630a599
|
@@ -13,35 +13,44 @@ module VagrantPlugins
|
|
13
13
|
def call(env)
|
14
14
|
if !env[:machine].config.dns.__skip
|
15
15
|
if env[:machine].state.id != :running
|
16
|
-
raise Errors::
|
16
|
+
raise Errors::MachineState, state: 'running'
|
17
17
|
end
|
18
18
|
|
19
19
|
ip = nil
|
20
|
+
unable = true
|
20
21
|
|
21
22
|
case env[:machine].provider_name
|
22
23
|
when :virtualbox
|
23
24
|
env[:machine].config.vm.networks.each do |network|
|
24
25
|
key, options = network[0], network[1]
|
25
26
|
if key == :private_network or key == :public_network
|
27
|
+
unable = false
|
26
28
|
if options[:dns] != 'skip'
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
29
|
+
if options[:ip] # static ip specified
|
30
|
+
ip = IPAddr.new(options[:ip])
|
31
|
+
else
|
32
|
+
case key
|
33
|
+
when :private_network
|
34
|
+
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"
|
35
|
+
when :public_network
|
36
|
+
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"
|
37
|
+
end
|
38
|
+
begin
|
39
|
+
ip = IPAddr.new(`#{cmd}`.chomp)
|
40
|
+
rescue IPAddr::InvalidAddressError
|
41
|
+
raise Errors::InvalidAddress
|
42
|
+
end
|
37
43
|
end
|
38
44
|
else
|
39
45
|
env[:ui].info(I18n.t('vagrant_command_dns.config.network_skip'))
|
40
46
|
end
|
41
47
|
end
|
42
48
|
end
|
49
|
+
if unable
|
50
|
+
raise Errors::NoNetwork
|
51
|
+
end
|
43
52
|
else
|
44
|
-
raise Errors::
|
53
|
+
raise Errors::UnsupportedProvider
|
45
54
|
end
|
46
55
|
|
47
56
|
unless ip.nil?
|
@@ -13,7 +13,7 @@ module VagrantPlugins
|
|
13
13
|
|
14
14
|
def call(env)
|
15
15
|
if env[:machine].state.id != :running
|
16
|
-
raise Errors::
|
16
|
+
raise Errors::MachineState, state: 'running'
|
17
17
|
end
|
18
18
|
|
19
19
|
record_map = env[:record_map]
|
@@ -21,6 +21,10 @@ module VagrantPlugins
|
|
21
21
|
File.open('/etc/hosts', 'r') do |file|
|
22
22
|
file.each_line do |line|
|
23
23
|
env[:record_map].each do |hostname, ip|
|
24
|
+
if env[:machine].config.dns.skip_aliases.include? hostname
|
25
|
+
env[:ui].info(I18n.t('vagrant_command_dns.command.common.skip_alias', hostname: hostname))
|
26
|
+
next
|
27
|
+
end
|
24
28
|
precise_pattern = Regexp.new('^\s*' + ip + '\s+' + hostname)
|
25
29
|
loose_pattern = Regexp.new('^\s*[0-9]{1,3}[0-9]{1,3}[0-9]{1,3}[0-9]{1,3}\s+' + hostname)
|
26
30
|
if line.match(/#{precise_pattern}/)
|
@@ -20,6 +20,13 @@ module VagrantPlugins
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def call(env)
|
23
|
+
errors = []
|
24
|
+
errors << I18n.t('vagrant_command_dns.config.route53.access_key_id_required') if env[:machine].config.dns.route53_access_key_id.nil?
|
25
|
+
errors << I18n.t('vagrant_command_dns.config.route53.secret_access_key_required') if env[:machine].config.dns.route53_secret_access_key.nil?
|
26
|
+
if errors.length > 0
|
27
|
+
raise Errors::ConfigInvalid, errors: errors
|
28
|
+
end
|
29
|
+
|
23
30
|
# Build the fog config
|
24
31
|
fog_config = {
|
25
32
|
:provider => :aws,
|
@@ -14,10 +14,14 @@ module VagrantPlugins
|
|
14
14
|
|
15
15
|
def call(env)
|
16
16
|
if env[:machine].state.id != :running
|
17
|
-
raise Errors::
|
17
|
+
raise Errors::MachineState, state: 'running'
|
18
18
|
end
|
19
19
|
|
20
20
|
env[:record_map].each do |hostname, ip|
|
21
|
+
if env[:machine].config.dns.skip_aliases.include? hostname
|
22
|
+
env[:ui].info(I18n.t('vagrant_command_dns.command.common.skip_alias', hostname: hostname))
|
23
|
+
next
|
24
|
+
end
|
21
25
|
@logger.info("Checking for existing '#{hostname}' Route53 record...")
|
22
26
|
|
23
27
|
record_name = hostname + '.' unless hostname.end_with?('.')
|
@@ -7,6 +7,11 @@ module VagrantPlugins
|
|
7
7
|
# @return [Array<String>]
|
8
8
|
attr_accessor :aliases
|
9
9
|
|
10
|
+
# List of disallowed aliases in FQDN format
|
11
|
+
#
|
12
|
+
# @return [Array<String>]
|
13
|
+
attr_accessor :skip_aliases
|
14
|
+
|
10
15
|
# AWS Route53 Settings
|
11
16
|
|
12
17
|
# The version of the AWS api to use
|
@@ -35,10 +40,10 @@ module VagrantPlugins
|
|
35
40
|
attr_accessor :route53_zone_id
|
36
41
|
|
37
42
|
attr_accessor :__skip
|
38
|
-
attr_reader :__available_providers
|
39
43
|
|
40
44
|
def initialize
|
41
45
|
@aliases = UNSET_VALUE
|
46
|
+
@skip_aliases = UNSET_VALUE
|
42
47
|
|
43
48
|
@route53_version = UNSET_VALUE
|
44
49
|
@route53_access_key_id = UNSET_VALUE
|
@@ -48,11 +53,11 @@ module VagrantPlugins
|
|
48
53
|
|
49
54
|
# Internal
|
50
55
|
@__skip = false
|
51
|
-
@__available_providers = %w(local route53)
|
52
56
|
end
|
53
57
|
|
54
58
|
def finalize!
|
55
|
-
@aliases
|
59
|
+
@aliases = [] if @aliases == UNSET_VALUE
|
60
|
+
@skip_aliases = [] if @skip_aliases == UNSET_VALUE
|
56
61
|
|
57
62
|
@route53_version = nil if @route53_version == UNSET_VALUE
|
58
63
|
@route53_zone_id = nil if @route53_zone_id == UNSET_VALUE
|
@@ -67,21 +72,18 @@ module VagrantPlugins
|
|
67
72
|
def validate(machine)
|
68
73
|
errors = _detected_errors
|
69
74
|
|
70
|
-
if
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
@route53_session_token = aws_config.session_token if @route53_session_token == nil
|
78
|
-
end
|
79
|
-
|
80
|
-
errors << I18n.t('vagrant_command_dns.config.route53_zone_id_required') if @route53_zone_id.nil?
|
81
|
-
errors << I18n.t('vagrant_command_dns.config.route53_access_key_id_required') if @route53_access_key_id.nil?
|
82
|
-
errors << I18n.t('vagrant_command_dns.config.route53_secret_access_key_required') if @route53_secret_access_key.nil?
|
75
|
+
if machine.provider_name == :aws
|
76
|
+
aws_config = machine.provider_config
|
77
|
+
# If these values are still not set and the AWS provider is being used, borrow it's config values
|
78
|
+
@route53_version = aws_config.version if @route53_version == nil
|
79
|
+
@route53_access_key_id = aws_config.access_key_id if @route53_access_key_id == nil
|
80
|
+
@route53_secret_access_key = aws_config.secret_access_key if @route53_secret_access_key == nil
|
81
|
+
@route53_session_token = aws_config.session_token if @route53_session_token == nil
|
83
82
|
end
|
84
83
|
|
84
|
+
errors << I18n.t('vagrant_command_dns.config.aliases_list_required') unless @aliases.kind_of? Array
|
85
|
+
errors << I18n.t('vagrant_command_dns.config.skip_aliases_list_required') unless @skip_aliases.kind_of? Array
|
86
|
+
|
85
87
|
{ 'DNS' => errors }
|
86
88
|
end
|
87
89
|
|
@@ -6,24 +6,24 @@ module VagrantPlugins
|
|
6
6
|
error_namespace('vagrant_command_dns.errors')
|
7
7
|
end
|
8
8
|
|
9
|
-
class
|
10
|
-
error_key(:
|
9
|
+
class ConfigInvalid < VagrantCommandDnsError
|
10
|
+
error_key(:config_invalid)
|
11
11
|
end
|
12
12
|
|
13
|
-
class
|
14
|
-
error_key(:
|
13
|
+
class MachineState < VagrantCommandDnsError
|
14
|
+
error_key(:machine_state)
|
15
15
|
end
|
16
16
|
|
17
|
-
class
|
18
|
-
error_key(:
|
17
|
+
class UnsupportedProvider < VagrantCommandDnsError
|
18
|
+
error_key(:unsupported_provider)
|
19
19
|
end
|
20
20
|
|
21
|
-
class
|
22
|
-
error_key(:
|
21
|
+
class InvalidAddress < VagrantCommandDnsError
|
22
|
+
error_key(:invalid_address)
|
23
23
|
end
|
24
24
|
|
25
|
-
class
|
26
|
-
error_key(:
|
25
|
+
class NoNetwork < VagrantCommandDnsError
|
26
|
+
error_key(:no_network)
|
27
27
|
end
|
28
28
|
|
29
29
|
end
|
data/locales/en.yml
CHANGED
@@ -2,48 +2,45 @@ en:
|
|
2
2
|
vagrant_command_dns:
|
3
3
|
|
4
4
|
config:
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
5
|
+
common:
|
6
|
+
config_invalid: |-
|
7
|
+
There are errors in the configuration of this machine. Please fix
|
8
|
+
the following errors and try again:
|
9
|
+
|
10
|
+
%{errors}
|
11
|
+
missing_field: "The following settings are missing: %{field}"
|
12
|
+
aliases_list_required: "'aliases' must be a list of FQDNs."
|
13
|
+
skip_aliases_list_required: "'skip_aliases' must be a list of FQDNs."
|
14
|
+
network_skip: "Skip requested for network in Vagrantfile."
|
15
|
+
|
16
|
+
route53:
|
17
|
+
access_key_id_required: "An access key ID must be specified via 'route53_access_key_id'"
|
18
|
+
secret_access_key_required: "A secret access key is required via 'route53_secret_access_key'"
|
19
|
+
|
13
20
|
|
14
21
|
errors:
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
invalid_address_error
|
22
|
+
machine_state: "Machine must be %{state} to preform this action."
|
23
|
+
unsupported_provider: "Machine provider not supported. Pull requests and testers are welcome."
|
24
|
+
invalid_address: "Invalid IP address detected. This could be a bug."
|
25
|
+
no_network: "Vagrantfile has no available :private_network or :public_network specified."
|
26
|
+
|
21
27
|
|
22
28
|
command:
|
29
|
+
common:
|
30
|
+
skip_alias: "Desired hostname alias '%{hostname}' is a reserved namespace specified via 'skip_aliases'. Skipping...'"
|
31
|
+
|
23
32
|
host:
|
24
|
-
edit_error:
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
/etc/hosts record exists for %{ip} %{hostname}
|
30
|
-
create_exists_conflict: |-
|
31
|
-
Potentially conflicting entries found in /etc/hosts. Please update manually...
|
32
|
-
destroy_success: |-
|
33
|
-
/etc/hosts record destroyed for %{hostname}
|
33
|
+
edit_error: "Unable to edit /etc/hosts. Consult documentation or submit a pull request."
|
34
|
+
create_success: "/etc/hosts record created for %{ip} %{hostname}."
|
35
|
+
create_exists_match: "/etc/hosts record exists for %{ip} %{hostname}."
|
36
|
+
create_exists_conflict: "Potentially conflicting entries found in /etc/hosts. Please update manually..."
|
37
|
+
destroy_success: "/etc/hosts record destroyed for %{hostname}."
|
34
38
|
|
35
39
|
route53:
|
36
|
-
fog_error:
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
Route53 record exists for %{ip} %{hostname}. Please update manually.
|
44
|
-
destroy_success: |-
|
45
|
-
Route53 record destroyed for %{hostname}
|
46
|
-
destroy_conflict: |-
|
47
|
-
Route53 record for %{hostname} does not match. Expected %{expected} got %{got}. Please update manually...
|
48
|
-
destroy_not_found: |-
|
49
|
-
Route53 record for %{hostname} not found. Skipping...
|
40
|
+
fog_error: "AWS error: %{message}"
|
41
|
+
create_success: "Route53 record created for %{ip} %{hostname}."
|
42
|
+
create_exists_match: "Route53 record exists for %{ip} %{hostname}."
|
43
|
+
create_exists_conflict: "Route53 record exists for %{ip} %{hostname}. Please update manually."
|
44
|
+
destroy_success: "Route53 record destroyed for %{hostname}."
|
45
|
+
destroy_conflict: "Route53 record for %{hostname} does not match. Expected %{expected} got %{got}. Please update manually..."
|
46
|
+
destroy_not_found: "Route53 record for %{hostname} not found. Skipping..."
|
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.2.
|
4
|
+
version: 0.2.1
|
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-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fog
|