vagrant-command-dns 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +9 -0
- data/LICENSE.txt +21 -0
- data/README.md +25 -0
- data/Rakefile +14 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/vagrant-command-dns/action/get_ip.rb +78 -0
- data/lib/vagrant-command-dns/action/host/create.rb +49 -0
- data/lib/vagrant-command-dns/action/host/destroy.rb +49 -0
- data/lib/vagrant-command-dns/action/host.rb +31 -0
- data/lib/vagrant-command-dns/action/route53/connect.rb +42 -0
- data/lib/vagrant-command-dns/action/route53/create.rb +71 -0
- data/lib/vagrant-command-dns/action/route53/destroy.rb +69 -0
- data/lib/vagrant-command-dns/action/route53.rb +34 -0
- data/lib/vagrant-command-dns/action/show_ip.rb +23 -0
- data/lib/vagrant-command-dns/action.rb +26 -0
- data/lib/vagrant-command-dns/command/host/create.rb +34 -0
- data/lib/vagrant-command-dns/command/host/destroy.rb +46 -0
- data/lib/vagrant-command-dns/command/host/root.rb +74 -0
- data/lib/vagrant-command-dns/command/ip.rb +34 -0
- data/lib/vagrant-command-dns/command/root.rb +77 -0
- data/lib/vagrant-command-dns/command/route53/create.rb +34 -0
- data/lib/vagrant-command-dns/command/route53/destroy.rb +46 -0
- data/lib/vagrant-command-dns/command/route53/root.rb +74 -0
- data/lib/vagrant-command-dns/config.rb +90 -0
- data/lib/vagrant-command-dns/errors.rb +31 -0
- data/lib/vagrant-command-dns/plugin.rb +69 -0
- data/lib/vagrant-command-dns/version.rb +5 -0
- data/lib/vagrant-command-dns.rb +20 -0
- data/locales/en.yml +43 -0
- data/vagrant-command-dns.gemspec +25 -0
- metadata +119 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9091d62e746bfa1ac32f14792aed653bd4897110
|
4
|
+
data.tar.gz: 93912f062c9535573c51eab4e1da0024230b2f97
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 41ac13370fd2a073ce190974ac479c34503477abd98a3898f0782700165d7da6a9c805afe96898a115a74af0d7672c5bb1bb4bc2f68f6b442b9644eba081dbbe
|
7
|
+
data.tar.gz: fe983024d0b333baebca6021ccf25e1f14bbdf87dfd36985d0531bd0bfc583c8e3ecd57f850206b6aaf515a2de30ef08415fc449edb1c757e37b11404f506cc5
|
data/.gitignore
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 cornfeedhobo
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
VagrantPlugins::CommandDns
|
2
|
+
==========================
|
3
|
+
|
4
|
+
_*Currently in development. DO NOT USE.*_
|
5
|
+
|
6
|
+
|
7
|
+
#
|
8
|
+
- Untested in multi-machine environments
|
9
|
+
|
10
|
+
|
11
|
+
# Development
|
12
|
+
|
13
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake false` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
14
|
+
|
15
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
16
|
+
|
17
|
+
|
18
|
+
# Contributing
|
19
|
+
|
20
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/vagrant-command-dns. 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
|
+
|
22
|
+
|
23
|
+
# License
|
24
|
+
|
25
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler/setup'
|
3
|
+
|
4
|
+
# Immediately sync all stdout so that tools like buildbot can
|
5
|
+
# immediately load in the output.
|
6
|
+
$stdout.sync = true
|
7
|
+
$stderr.sync = true
|
8
|
+
|
9
|
+
# Change to the directory of this file.
|
10
|
+
Dir.chdir(File.expand_path('../', __FILE__))
|
11
|
+
|
12
|
+
# This installs the tasks that help with gem creation and
|
13
|
+
# publishing.
|
14
|
+
Bundler::GemHelper.install_tasks
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'vagrant-command-dns'
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require 'irb'
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'ipaddr'
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module CommandDns
|
5
|
+
module Action
|
6
|
+
class GetIP
|
7
|
+
|
8
|
+
def initialize(app, env)
|
9
|
+
@app = app
|
10
|
+
@logger = Log4r::Logger.new('vagrant_command_dns::action::get_ip')
|
11
|
+
end
|
12
|
+
|
13
|
+
def call(env)
|
14
|
+
if !env[:machine].config.dns.__skip
|
15
|
+
if env[:machine].state.id != :running
|
16
|
+
raise Errors::MachineStateError
|
17
|
+
end
|
18
|
+
|
19
|
+
ip = nil
|
20
|
+
|
21
|
+
case env[:machine].provider_name
|
22
|
+
when :virtualbox
|
23
|
+
# We only operate on the first network defined in the Vagrantfile
|
24
|
+
unless env[:machine].config.vm.networks[1].nil?
|
25
|
+
network = env[:machine].config.vm.networks[1]
|
26
|
+
if network[1][:dns] == 'skip'
|
27
|
+
@logger.info('')
|
28
|
+
env[:ui].info('')
|
29
|
+
else
|
30
|
+
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"
|
31
|
+
begin
|
32
|
+
ip = IPAddr.new(`#{cmd}`.chomp)
|
33
|
+
rescue IPAddr::InvalidAddressError
|
34
|
+
raise Errors::InvalidAddressError
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
else
|
40
|
+
raise Errors::UnsupportedProviderError
|
41
|
+
end
|
42
|
+
|
43
|
+
unless ip.nil?
|
44
|
+
host_names = [env[:machine].config.vm.hostname]
|
45
|
+
env[:machine].config.dns.aliases.each do |a|
|
46
|
+
host_names.push(a)
|
47
|
+
end
|
48
|
+
|
49
|
+
record_map = {}
|
50
|
+
host_names.each do |h|
|
51
|
+
env[:ui].info "#{h} #{ip.to_string}"
|
52
|
+
record_map[h] = ip.to_string
|
53
|
+
end
|
54
|
+
|
55
|
+
env[:record_map] = record_map
|
56
|
+
end
|
57
|
+
|
58
|
+
else
|
59
|
+
host_names = [env[:machine].config.vm.hostname]
|
60
|
+
env[:machine].config.dns.aliases.each do |a|
|
61
|
+
host_names.push(a)
|
62
|
+
end
|
63
|
+
|
64
|
+
record_map = {}
|
65
|
+
host_names.each do |h|
|
66
|
+
record_map[h] = ip
|
67
|
+
end
|
68
|
+
|
69
|
+
env[:record_map] = record_map
|
70
|
+
end
|
71
|
+
|
72
|
+
@app.call(env)
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'log4r'
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module CommandDns
|
5
|
+
module Action
|
6
|
+
module Host
|
7
|
+
class Create
|
8
|
+
|
9
|
+
def initialize(app, env)
|
10
|
+
@app = app
|
11
|
+
@logger = Log4r::Logger.new('vagrant_command_dns::action::host::create')
|
12
|
+
end
|
13
|
+
|
14
|
+
def call(env)
|
15
|
+
if env[:machine].state.id != :running
|
16
|
+
raise Errors::MachineStateError, state: 'running'
|
17
|
+
end
|
18
|
+
|
19
|
+
lines = []
|
20
|
+
env[:record_map].each do |hostname, ip|
|
21
|
+
loose_pattern = Regexp.new('^\s*[0-9]{1,3}[0-9]{1,3}[0-9]{1,3}[0-9]{1,3}\s+' + hostname)
|
22
|
+
precise_pattern = Regexp.new('^\s*' + ip + '\s+' + hostname)
|
23
|
+
File.open('/etc/hosts', 'r') do |f|
|
24
|
+
f.each_line do |line|
|
25
|
+
if line.match(/#{precise_pattern}/)
|
26
|
+
env[:ui].info(I18n.t('vagrant_command_dns.command.host.create_exists_match',
|
27
|
+
ip: ip, hostname: hostname))
|
28
|
+
return
|
29
|
+
elsif line.match(/#{loose_pattern}/)
|
30
|
+
env[:ui].info(I18n.t('vagrant_command_dns.command.host.create_exists_conflict'))
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
lines.push("#{ip} #{hostname}")
|
35
|
+
end
|
36
|
+
|
37
|
+
content = lines.join("\n").strip
|
38
|
+
unless system("sudo sh -c 'echo \"#{content}\" >> /etc/hosts'")
|
39
|
+
env[:ui].error(I18n.t('vagrant_command_dns.command.host.edit_error'))
|
40
|
+
end
|
41
|
+
|
42
|
+
@app.call(env)
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'log4r'
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module CommandDns
|
5
|
+
module Action
|
6
|
+
module Host
|
7
|
+
class Destroy
|
8
|
+
|
9
|
+
def initialize(app, env)
|
10
|
+
@app = app
|
11
|
+
@logger = Log4r::Logger.new('vagrant_command_dns::action::host::destroy')
|
12
|
+
end
|
13
|
+
|
14
|
+
def call(env)
|
15
|
+
unless env[:machine].config.dns.__skip
|
16
|
+
if env[:machine].state.id != :running
|
17
|
+
raise Errors::MachineStateError, state: 'running'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
lines = []
|
22
|
+
env[:record_map].each do |hostname, ip|
|
23
|
+
if env[:machine].config.dns.__skip
|
24
|
+
record_pattern = Regexp.new('^\s*[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\s+' + hostname)
|
25
|
+
else
|
26
|
+
record_pattern = Regexp.new('^\s*' + ip + '\s+' + hostname)
|
27
|
+
end
|
28
|
+
File.open('/etc/hosts', 'r') do |f|
|
29
|
+
f.each_line do |line|
|
30
|
+
unless line.match(/#{record_pattern}/)
|
31
|
+
lines.push(line.chomp)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
content = lines.join("\n").strip
|
38
|
+
unless system("sudo sh -c 'echo \"#{content}\" > /etc/hosts'")
|
39
|
+
env[:ui].error(I18n.t('vagrant_command_dns.command.host.edit_error'))
|
40
|
+
end
|
41
|
+
|
42
|
+
@app.call(env)
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module CommandDns
|
5
|
+
module Action
|
6
|
+
module Host
|
7
|
+
|
8
|
+
def self.host_create
|
9
|
+
Vagrant::Action::Builder.new.tap do |b|
|
10
|
+
b.use Action::ConfigValidate
|
11
|
+
b.use Action::GetIP
|
12
|
+
b.use Host::Create
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.host_destroy
|
17
|
+
Vagrant::Action::Builder.new.tap do |b|
|
18
|
+
b.use Action::ConfigValidate
|
19
|
+
b.use Action::GetIP
|
20
|
+
b.use Host::Destroy
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
host_root = Pathname.new(File.expand_path('../host', __FILE__))
|
25
|
+
autoload :Create, host_root.join('create')
|
26
|
+
autoload :Destroy, host_root.join('destroy')
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'fog'
|
2
|
+
require 'log4r'
|
3
|
+
require 'vagrant/util/ssh'
|
4
|
+
|
5
|
+
module VagrantPlugins
|
6
|
+
module CommandDns
|
7
|
+
module Action
|
8
|
+
module Route53
|
9
|
+
# This action connects to AWS, verifies credentials work, and
|
10
|
+
# puts the AWS connection object into the `:aws_compute` key
|
11
|
+
# in the environment.
|
12
|
+
class Connect
|
13
|
+
|
14
|
+
# For quick access to the `SSH` class.
|
15
|
+
include Vagrant::Util
|
16
|
+
|
17
|
+
def initialize(app, env)
|
18
|
+
@app = app
|
19
|
+
@logger = Log4r::Logger.new('vagrant_command_dns::action::route53::connect')
|
20
|
+
end
|
21
|
+
|
22
|
+
def call(env)
|
23
|
+
# Build the fog config
|
24
|
+
fog_config = {
|
25
|
+
:provider => :aws,
|
26
|
+
:aws_access_key_id => env[:machine].config.dns.route53_access_key_id,
|
27
|
+
:aws_secret_access_key => env[:machine].config.dns.route53_secret_access_key,
|
28
|
+
:aws_session_token => env[:machine].config.dns.route53_session_token
|
29
|
+
}
|
30
|
+
fog_config[:version] = env[:machine].config.dns.route53_version if env[:machine].config.dns.route53_version
|
31
|
+
|
32
|
+
@logger.info('Connecting to AWS...')
|
33
|
+
env[:route53] = Fog::DNS.new(fog_config)
|
34
|
+
|
35
|
+
@app.call(env)
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'log4r'
|
2
|
+
require 'excon'
|
3
|
+
|
4
|
+
module VagrantPlugins
|
5
|
+
module CommandDns
|
6
|
+
module Action
|
7
|
+
module Route53
|
8
|
+
class Create
|
9
|
+
|
10
|
+
def initialize(app, env)
|
11
|
+
@app = app
|
12
|
+
@logger = Log4r::Logger.new('vagrant_command_dns::action::route53::create')
|
13
|
+
end
|
14
|
+
|
15
|
+
def call(env)
|
16
|
+
if env[:machine].state.id != :running
|
17
|
+
raise Errors::MachineStateError, state: 'running'
|
18
|
+
end
|
19
|
+
|
20
|
+
env[:record_map].each do |hostname, ip|
|
21
|
+
@logger.info("Checking for existing '#{hostname}' Route53 record...")
|
22
|
+
|
23
|
+
record_name = hostname + '.' unless hostname.end_with?('.')
|
24
|
+
|
25
|
+
begin
|
26
|
+
zone = env[:route53].zones.get(env[:machine].config.dns.route53_zone_id)
|
27
|
+
record = zone.records.get(record_name)
|
28
|
+
rescue Excon::Errors::SocketError
|
29
|
+
env[:ui].error(I18n.t('vagrant_command_dns.command.route53.fog_error',
|
30
|
+
message: 'Unable to reach AWS. Are you connected to the internet?'))
|
31
|
+
rescue Fog::DNS::AWS::Error => err
|
32
|
+
env[:ui].error(I18n.t('vagrant_command_dns.command.route53.fog_error',
|
33
|
+
message: err.message))
|
34
|
+
end
|
35
|
+
|
36
|
+
if record.nil? || record.attributes[:name] != record_name
|
37
|
+
@logger.info('Creating Route53 record...')
|
38
|
+
begin
|
39
|
+
new_record = zone.records.new({
|
40
|
+
:value => ip,
|
41
|
+
:name => record_name,
|
42
|
+
:type => 'A',
|
43
|
+
:ttl => '60'
|
44
|
+
})
|
45
|
+
new_record.save
|
46
|
+
rescue Fog::DNS::AWS::Error => err
|
47
|
+
env[:ui].error(I18n.t('vagrant_command_dns.command.route53.fog_error',
|
48
|
+
message: err.message))
|
49
|
+
end
|
50
|
+
env[:ui].info(I18n.t('vagrant_command_dns.command.route53.create_success',
|
51
|
+
ip: ip, hostname: hostname))
|
52
|
+
|
53
|
+
elsif record.attributes[:value][0] == ip
|
54
|
+
env[:ui].info(I18n.t('vagrant_command_dns.command.route53.create_exists_match',
|
55
|
+
ip: ip, hostname: hostname))
|
56
|
+
|
57
|
+
elsif record.attributes[:value][0] != ip
|
58
|
+
env[:ui].warn(I18n.t('vagrant_command_dns.command.route53.create_exists_conflict',
|
59
|
+
ip: ip, hostname: hostname))
|
60
|
+
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
@app.call(env)
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'log4r'
|
2
|
+
|
3
|
+
|
4
|
+
module VagrantPlugins
|
5
|
+
module CommandDns
|
6
|
+
module Action
|
7
|
+
module Route53
|
8
|
+
class Destroy
|
9
|
+
|
10
|
+
def initialize(app, env)
|
11
|
+
@app = app
|
12
|
+
@logger = Log4r::Logger.new('vagrant_command_dns::action::route53::destroy')
|
13
|
+
end
|
14
|
+
|
15
|
+
def call(env)
|
16
|
+
unless env[:machine].config.dns.__skip
|
17
|
+
if env[:machine].state.id != :running
|
18
|
+
raise Errors::MachineStateError, state: 'running'
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
env[:record_map].each do |hostname, ip|
|
23
|
+
@logger.info("Checking for existing '#{hostname}' Route53 record...")
|
24
|
+
|
25
|
+
record_name = hostname + '.' unless hostname.end_with?('.')
|
26
|
+
|
27
|
+
begin
|
28
|
+
zone = env[:route53].zones.get(env[:machine].config.dns.route53_zone_id)
|
29
|
+
record = zone.records.get(record_name)
|
30
|
+
rescue Fog::DNS::AWS::Error => err
|
31
|
+
env[:ui].error(I18n.t('vagrant_command_dns.command.route53.fog_error',
|
32
|
+
message: err.message))
|
33
|
+
end
|
34
|
+
|
35
|
+
if !record.nil? && record.attributes[:name] == record_name
|
36
|
+
if env[:machine].config.dns.__skip == true || record.attributes[:value][0] == ip
|
37
|
+
@logger.info("Deleting Route53 record for '#{hostname}'...")
|
38
|
+
begin
|
39
|
+
record.destroy
|
40
|
+
rescue Fog::DNS::AWS::Error => err
|
41
|
+
env[:ui].error(I18n.t('vagrant_command_dns.command.route53.fog_error',
|
42
|
+
message: err.message))
|
43
|
+
end
|
44
|
+
env[:ui].info(I18n.t('vagrant_command_dns.command.route53.destroy_success',
|
45
|
+
ip: ip, hostname: hostname))
|
46
|
+
|
47
|
+
elsif record.attributes[:value][0] != ip
|
48
|
+
env[:ui].warn(I18n.t('vagrant_command_dns.command.route53.destroy_conflict',
|
49
|
+
hostname: hostname,
|
50
|
+
expected: ip,
|
51
|
+
got: record.attributes[:value][0]))
|
52
|
+
else
|
53
|
+
raise Errors::VagrantCommandDnsError
|
54
|
+
end
|
55
|
+
else
|
56
|
+
env[:ui].info(I18n.t('vagrant_command_dns.command.route53.destroy_not_found',
|
57
|
+
hostname: hostname))
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
@app.call(env)
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module CommandDns
|
5
|
+
module Action
|
6
|
+
module Route53
|
7
|
+
|
8
|
+
def self.route53_create
|
9
|
+
Vagrant::Action::Builder.new.tap do |b|
|
10
|
+
b.use Action::ConfigValidate
|
11
|
+
b.use Action::GetIP
|
12
|
+
b.use Route53::Connect
|
13
|
+
b.use Route53::Create
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.route53_destroy
|
18
|
+
Vagrant::Action::Builder.new.tap do |b|
|
19
|
+
b.use Action::ConfigValidate
|
20
|
+
b.use Action::GetIP
|
21
|
+
b.use Route53::Connect
|
22
|
+
b.use Route53::Destroy
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
route53_root = Pathname.new(File.expand_path('../route53', __FILE__))
|
27
|
+
autoload :Connect, route53_root.join('connect')
|
28
|
+
autoload :Create, route53_root.join('create')
|
29
|
+
autoload :Destroy, route53_root.join('destroy')
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module CommandDns
|
3
|
+
module Action
|
4
|
+
class ShowIP
|
5
|
+
|
6
|
+
def initialize(app, env)
|
7
|
+
@app = app
|
8
|
+
@logger = Log4r::Logger.new('vagrant_command_dns::action::show_ip')
|
9
|
+
end
|
10
|
+
|
11
|
+
def call(env)
|
12
|
+
if env[:record_map]
|
13
|
+
ip = env[:record_map].values[0]
|
14
|
+
env[:ui].info("#{ip}")
|
15
|
+
end
|
16
|
+
|
17
|
+
@app.call(env)
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'vagrant/action/builder'
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module CommandDns
|
5
|
+
module Action
|
6
|
+
|
7
|
+
# Include the built-in modules so we can use them as top-level things.
|
8
|
+
include Vagrant::Action::Builtin
|
9
|
+
|
10
|
+
def self.show_ip
|
11
|
+
Vagrant::Action::Builder.new.tap do |b|
|
12
|
+
b.use ConfigValidate
|
13
|
+
b.use GetIP
|
14
|
+
b.use ShowIP
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
action_root = Pathname.new(File.expand_path('../action', __FILE__))
|
19
|
+
autoload :GetIP, action_root.join('get_ip')
|
20
|
+
autoload :ShowIP, action_root.join('show_ip')
|
21
|
+
autoload :Host, action_root.join('host')
|
22
|
+
autoload :Route53, action_root.join('route53')
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module CommandDns
|
5
|
+
module Command
|
6
|
+
module Host
|
7
|
+
class Create < Vagrant.plugin('2', :command)
|
8
|
+
|
9
|
+
def execute
|
10
|
+
opts = OptionParser.new do |o|
|
11
|
+
o.banner = 'Usage: vagrant dns host create'
|
12
|
+
o.separator ''
|
13
|
+
o.separator 'Additional documentation can be found on the plugin homepage'
|
14
|
+
o.separator ''
|
15
|
+
end
|
16
|
+
|
17
|
+
argv = parse_options(opts)
|
18
|
+
return if !argv
|
19
|
+
|
20
|
+
with_target_vms(argv) do |machine|
|
21
|
+
@env.action_runner.run(Action::Host.host_create, {
|
22
|
+
machine: machine,
|
23
|
+
ui: Vagrant::UI::Prefixed.new(@env.ui, 'dns host'),
|
24
|
+
})
|
25
|
+
end
|
26
|
+
|
27
|
+
0
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|