vagrant-route53 0.0.10

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.
@@ -0,0 +1,21 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ InstalledFiles
7
+ lib/bundler/man
8
+ pkg
9
+ rdoc
10
+ spec/reports
11
+ test/tmp
12
+ test/version_tmp
13
+ tmp
14
+
15
+ # YARD artifacts
16
+ .yardoc
17
+ _yardoc
18
+ doc/
19
+
20
+ .idea/
21
+ .vagrant/
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ script: bundle exec rspec spec/
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in vagrant-route53.gemspec
4
+ gemspec
5
+
6
+ group :development do
7
+ # We depend on Vagrant for development, but we don't add it as a
8
+ # gem dependency because we expect to be installed within the
9
+ # Vagrant environment itself using `vagrant plugin`.
10
+ gem "vagrant", :git => "git://github.com/mitchellh/vagrant.git"
11
+ end
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2013 Anthony Scalisi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ 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, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,4 @@
1
+ vagrant-route53
2
+ ===============
3
+
4
+ Delete Route53 record associated to the EC2 node when destroying Vagrant VM using AWS provider.
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,14 @@
1
+ require 'vagrant'
2
+ require 'vagrant-route53/version'
3
+ require 'vagrant-route53/errors'
4
+
5
+ module Vagrant
6
+ module Route53
7
+ autoload :Action, 'vagrant-route53/action'
8
+ autoload :Config, 'vagrant-route53/config'
9
+ autoload :Env, 'vagrant-route53/env'
10
+ autoload :EnvHelpers, 'vagrant-route53/env_helpers'
11
+ end
12
+ end
13
+
14
+ require 'vagrant-route53/plugin'
@@ -0,0 +1,20 @@
1
+ module Vagrant
2
+ module Route53
3
+ module Action
4
+ autoload :Cleanup, 'vagrant-route53/action/cleanup'
5
+
6
+ def self.cleanup
7
+ ::Vagrant::Action::Builder.new.tap do |b|
8
+ b.use setup
9
+ b.use Vagrant::Route53::Action::Cleanup
10
+ end
11
+ end
12
+
13
+ def self.setup
14
+ @setup ||= ::Vagrant::Action::Builder.new.tap do |b|
15
+ b.use ::Vagrant::Action::Builtin::EnvSet, route53: Vagrant::Route53::Env.new
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,46 @@
1
+ require 'chef/config'
2
+ require 'chef/rest'
3
+ require 'chef/api_client'
4
+
5
+ module Vagrant
6
+ module Route53
7
+ module Action
8
+ class Cleanup
9
+ include ::Vagrant::Route53::EnvHelpers
10
+
11
+ def initialize(app, env)
12
+ @app = app
13
+ end
14
+
15
+ def old_record(env)
16
+ # Need to move old_record format to config in Vagrant
17
+ # Audax one: #{node.name}-#{node[:ec2][:instance_id]}.#{node.chef_environment}.#{node[:ec2][:placement_availability_zone]}.#{node[:route53][:infra_domain]}
18
+ @old_record ||= chef_provisioner(env).node_name || vm_config(env).hostname || vm_config(env).box
19
+ end
20
+
21
+ def delete_resource(resource, env)
22
+ begin
23
+ # route53_api(env).delete_rest("#{resource}s/#{old_record(env)}")
24
+ env[:route53].ui.success "Chef #{resource} '#{old_record(env)}' successfully purged from Route53..."
25
+ rescue Exception => e
26
+ env[:route53].ui.warn "Could not remove #{resource} #{old_record(env)}: #{e.message}"
27
+ end
28
+ end
29
+
30
+ def call(env)
31
+ if chef_client?(env)
32
+ begin
33
+ ::Chef::Config.from_file knife_config_file(env)
34
+ rescue Errno::ENOENT => e
35
+ raise ::Vagrant::Route53::VagrantWrapperError.new(e)
36
+ end
37
+
38
+ %w(record).each { |resource| delete_resource(resource, env) }
39
+ end
40
+
41
+ @app.call(env)
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,27 @@
1
+ module Vagrant
2
+ module Route53
3
+ class Config < ::Vagrant.plugin('2', :config)
4
+ attr_accessor :knife_config_file
5
+
6
+ def initialize
7
+ super
8
+ @knife_config_file = UNSET_VALUE
9
+ end
10
+
11
+ def knife_config_file=(value)
12
+ @knife_config_file = File.expand_path(value)
13
+ end
14
+
15
+ def validate(machine)
16
+ errors = []
17
+ errors << "Knife configuration not found at #{@knife_config_file}." if !File.exists?(@knife_config_file)
18
+
19
+ { "route53 configuration" => errors }
20
+ end
21
+
22
+ def finalize!
23
+ @knife_config_file = File.expand_path "#{ENV['HOME']}/.chef/knife.rb" if @knife_config_file == UNSET_VALUE
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,15 @@
1
+ module Vagrant
2
+ module Route53
3
+ class Env
4
+ attr_accessor :ui
5
+
6
+ def initialize
7
+ if Gem::Version.new(::Vagrant::VERSION) >= Gem::Version.new("1.2")
8
+ @ui = ::Vagrant::UI::Colored.new.scope('Route53')
9
+ else
10
+ @ui = ::Vagrant::UI::Colored.new('Route53')
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,31 @@
1
+ module Vagrant
2
+ module Route53
3
+ module EnvHelpers
4
+ def vm_config(env)
5
+ @vm_config ||= env[:machine].config.vm
6
+ end
7
+
8
+ def route53_api(env)
9
+ # ROUTE53 AWS LOGIC
10
+ end
11
+
12
+ def chef_provisioner(env)
13
+ @chef_provisioner ||= vm_config(env).provisioners.find do |p|
14
+ p.config.is_a? VagrantPlugins::Chef::Config::ChefClient
15
+ end.config
16
+ end
17
+
18
+ def chef_client?(env)
19
+ vm_config(env).provisioners.select { |p| p.name == :chef_client }.any?
20
+ end
21
+
22
+ def knife_config_file(env)
23
+ # Make sure that the default is set
24
+ env[:machine].config.route53.finalize!
25
+
26
+ env[:route53].ui.info "knife.rb location set to '#{env[:machine].config.route53.knife_config_file}'"
27
+ env[:machine].config.route53.knife_config_file
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,38 @@
1
+ require 'vagrant/errors'
2
+
3
+ module Vagrant
4
+ module Route53
5
+ # This is a copy/adaptation of the VagrantWrapperError class of berkshelf-vagrant
6
+ # The original can be found on https://github.com/RiotGames/berkshelf-vagrant
7
+
8
+ # @author Jamie Winsor <reset@riotgames.com>
9
+ #
10
+ # A wrapper for a BerkshelfError for Vagrant. All Berkshelf exceptions should be
11
+ # wrapped in this proxy object so they are properly handled when Vagrant encounters
12
+ # an exception.
13
+ #
14
+ # @example wrapping an error encountered within the Vagrant plugin
15
+ # rescue BerkshelfError => e
16
+ # VagrantWrapperError.new(e)
17
+ # end
18
+ class VagrantWrapperError < ::Vagrant::Errors::VagrantError
19
+ # @param [BerkshelfError]
20
+ attr_reader :original
21
+
22
+ # @param [BerkshelfError] original
23
+ def initialize(original)
24
+ @original = original
25
+ end
26
+
27
+ def to_s
28
+ "#{original.class}: #{original.to_s}"
29
+ end
30
+
31
+ private
32
+
33
+ def method_missing(fun, *args, &block)
34
+ original.send(fun, *args, &block)
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,18 @@
1
+ module Vagrant
2
+ module Route53
3
+ class Plugin < Vagrant.plugin('2')
4
+ name "vagrant-route53"
5
+ description <<-DESC
6
+ Delete Route53 record associated to the EC2 node when destroying Vagrant VM using AWS provider.
7
+ DESC
8
+
9
+ action_hook(:vagrant_route53_cleanup, :machine_action_destroy) do |hook|
10
+ hook.after(::Vagrant::Action::Builtin::ConfigValidate, Vagrant::Route53::Action.cleanup)
11
+ end
12
+
13
+ config("route53") do
14
+ Config
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,5 @@
1
+ module Vagrant
2
+ module Route53
3
+ VERSION = "0.0.10"
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'vagrant-route53'
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'vagrant-route53/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "vagrant-route53"
8
+ gem.version = Vagrant::Route53::VERSION
9
+ gem.authors = ["Anthony Scalisi"]
10
+ gem.email = ["scalisia@gmail.com"]
11
+ gem.description = %q{Delete Route53 record associated to the EC2 node when destroying Vagrant VM using AWS provider.}
12
+ gem.summary = %q{If a Vagrant VM that was spun up using the AWS provider is destroyed and uses the route53 cookbook, it will leave behind the node route53 record. What vagrant-route53 does is to clean up those previous records during the destroy operation.}
13
+ gem.homepage = "https://github.com/scalp42/vagrant-route53"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency "chef", ">= 11.2.0"
21
+
22
+ gem.add_development_dependency "rspec"
23
+ gem.add_development_dependency "pry-debugger"
24
+ gem.add_development_dependency "bundler", "~> 1.3"
25
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vagrant-route53
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.10
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Anthony Scalisi
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-07-26 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: chef
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 11.2.0
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: 11.2.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: pry-debugger
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
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: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: bundler
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: '1.3'
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: '1.3'
78
+ description: Delete Route53 record associated to the EC2 node when destroying Vagrant
79
+ VM using AWS provider.
80
+ email:
81
+ - scalisia@gmail.com
82
+ executables: []
83
+ extensions: []
84
+ extra_rdoc_files: []
85
+ files:
86
+ - .gitignore
87
+ - .travis.yml
88
+ - Gemfile
89
+ - LICENSE
90
+ - README.md
91
+ - Rakefile
92
+ - lib/vagrant-route53.rb
93
+ - lib/vagrant-route53/action.rb
94
+ - lib/vagrant-route53/action/cleanup.rb
95
+ - lib/vagrant-route53/config.rb
96
+ - lib/vagrant-route53/env.rb
97
+ - lib/vagrant-route53/env_helpers.rb
98
+ - lib/vagrant-route53/errors.rb
99
+ - lib/vagrant-route53/plugin.rb
100
+ - lib/vagrant-route53/version.rb
101
+ - spec/unit/spec_helper.rb
102
+ - vagrant-route53.gemspec
103
+ homepage: https://github.com/scalp42/vagrant-route53
104
+ licenses: []
105
+ post_install_message:
106
+ rdoc_options: []
107
+ require_paths:
108
+ - lib
109
+ required_ruby_version: !ruby/object:Gem::Requirement
110
+ none: false
111
+ requirements:
112
+ - - ! '>='
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ none: false
117
+ requirements:
118
+ - - ! '>='
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ requirements: []
122
+ rubyforge_project:
123
+ rubygems_version: 1.8.25
124
+ signing_key:
125
+ specification_version: 3
126
+ summary: If a Vagrant VM that was spun up using the AWS provider is destroyed and
127
+ uses the route53 cookbook, it will leave behind the node route53 record. What vagrant-route53
128
+ does is to clean up those previous records during the destroy operation.
129
+ test_files:
130
+ - spec/unit/spec_helper.rb