ey_cloud_awareness 0.1.0
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.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.rdoc +18 -0
- data/Rakefile +50 -0
- data/VERSION +1 -0
- data/ey_cloud_awareness.gemspec +63 -0
- data/lib/engine_yard_cloud_chef.rb +9 -0
- data/lib/engine_yard_cloud_instance.rb +105 -0
- data/lib/ey_cloud_awareness.rb +15 -0
- data/spec/ey_cloud_awareness_spec.rb +7 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +9 -0
- metadata +98 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Seamus Abshere
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
= ey_cloud_awareness
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Note on Patches/Pull Requests
|
6
|
+
|
7
|
+
* Fork the project.
|
8
|
+
* Make your feature addition or bug fix.
|
9
|
+
* Add tests for it. This is important so I don't break it in a
|
10
|
+
future version unintentionally.
|
11
|
+
* Commit, do not mess with rakefile, version, or history.
|
12
|
+
(if you want to have your own version, that is fine but
|
13
|
+
bump version in a commit by itself I can ignore when I pull)
|
14
|
+
* Send me a pull request. Bonus points for topic branches.
|
15
|
+
|
16
|
+
== Copyright
|
17
|
+
|
18
|
+
Copyright (c) 2009 Seamus Abshere. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "ey_cloud_awareness"
|
8
|
+
gem.summary = %Q{Make your EngineYard cloud instances aware of each other.}
|
9
|
+
gem.description = %Q{Make your EngineYard cloud instances aware of each other.}
|
10
|
+
gem.email = "seamus@abshere.net"
|
11
|
+
gem.homepage = "http://github.com/seamusabshere/ey_cloud_awareness"
|
12
|
+
gem.authors = ["Seamus Abshere"]
|
13
|
+
# gem.rubyforge_project = "ey_cloud_awareness"
|
14
|
+
%w{ activesupport right_aws }.each { |name| gem.add_dependency name }
|
15
|
+
gem.add_development_dependency "rspec", ">= 1.2.9"
|
16
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
17
|
+
end
|
18
|
+
Jeweler::GemcutterTasks.new
|
19
|
+
Jeweler::RubyforgeTasks.new do |rubyforge|
|
20
|
+
rubyforge.doc_task = "rdoc"
|
21
|
+
end
|
22
|
+
rescue LoadError
|
23
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
24
|
+
end
|
25
|
+
|
26
|
+
require 'spec/rake/spectask'
|
27
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
28
|
+
spec.libs << 'lib' << 'spec'
|
29
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
30
|
+
end
|
31
|
+
|
32
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
33
|
+
spec.libs << 'lib' << 'spec'
|
34
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
35
|
+
spec.rcov = true
|
36
|
+
end
|
37
|
+
|
38
|
+
task :spec => :check_dependencies
|
39
|
+
|
40
|
+
task :default => :spec
|
41
|
+
|
42
|
+
require 'rake/rdoctask'
|
43
|
+
Rake::RDocTask.new do |rdoc|
|
44
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
45
|
+
|
46
|
+
rdoc.rdoc_dir = 'rdoc'
|
47
|
+
rdoc.title = "ey_cloud_awareness #{version}"
|
48
|
+
rdoc.rdoc_files.include('README*')
|
49
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
50
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{ey_cloud_awareness}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Seamus Abshere"]
|
12
|
+
s.date = %q{2009-11-03}
|
13
|
+
s.description = %q{Make your EngineYard cloud instances aware of each other.}
|
14
|
+
s.email = %q{seamus@abshere.net}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
"LICENSE",
|
23
|
+
"README.rdoc",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"ey_cloud_awareness.gemspec",
|
27
|
+
"lib/engine_yard_cloud_chef.rb",
|
28
|
+
"lib/engine_yard_cloud_instance.rb",
|
29
|
+
"lib/ey_cloud_awareness.rb",
|
30
|
+
"spec/ey_cloud_awareness_spec.rb",
|
31
|
+
"spec/spec.opts",
|
32
|
+
"spec/spec_helper.rb"
|
33
|
+
]
|
34
|
+
s.homepage = %q{http://github.com/seamusabshere/ey_cloud_awareness}
|
35
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
36
|
+
s.require_paths = ["lib"]
|
37
|
+
s.rubygems_version = %q{1.3.5}
|
38
|
+
s.summary = %q{Make your EngineYard cloud instances aware of each other.}
|
39
|
+
s.test_files = [
|
40
|
+
"spec/ey_cloud_awareness_spec.rb",
|
41
|
+
"spec/spec_helper.rb"
|
42
|
+
]
|
43
|
+
|
44
|
+
if s.respond_to? :specification_version then
|
45
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
46
|
+
s.specification_version = 3
|
47
|
+
|
48
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
49
|
+
s.add_runtime_dependency(%q<activesupport>, [">= 0"])
|
50
|
+
s.add_runtime_dependency(%q<right_aws>, [">= 0"])
|
51
|
+
s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
|
52
|
+
else
|
53
|
+
s.add_dependency(%q<activesupport>, [">= 0"])
|
54
|
+
s.add_dependency(%q<right_aws>, [">= 0"])
|
55
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
56
|
+
end
|
57
|
+
else
|
58
|
+
s.add_dependency(%q<activesupport>, [">= 0"])
|
59
|
+
s.add_dependency(%q<right_aws>, [">= 0"])
|
60
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
@@ -0,0 +1,9 @@
|
|
1
|
+
module EngineYardCloudChef
|
2
|
+
DNA_PATH = '/etc/chef/dna.json'
|
3
|
+
# Load the Chef DNA file from /etc/chef/dna.json
|
4
|
+
# >> JSON.load(IO.read('/etc/chef/dna.json')).keys
|
5
|
+
# => ["aws_secret_key", "db_slaves", "user_ssh_key", "admin_ssh_key", "backup_interval", "instance_role", "mailserver", "utility_instances", "crons", "backup_window", "removed_applications", "alert_email", "applications", "gems_to_install", "members", "reporting_url", "aws_secret_id", "environment", "users", "master_app_server", "db_host", "packages_to_install", "haproxy"]
|
6
|
+
def self.dna
|
7
|
+
JSON.load(IO.read(DNA_PATH)).recursive_symbolize_keys!
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
class EngineYardCloudInstance
|
2
|
+
INSTANCE_DESCRIPTIONS_CACHE_PATH = defined?(RAILS_ROOT) ? "#{RAILS_ROOT}/config/engine_yard_instance_descriptions.yml" : '/etc/engine_yard_instance_descriptions.yml'
|
3
|
+
|
4
|
+
attr_accessor :instance_id
|
5
|
+
def initialize(instance_id)
|
6
|
+
@instance_id = instance_id.to_sym
|
7
|
+
end
|
8
|
+
|
9
|
+
def refresh
|
10
|
+
self.class.refresh
|
11
|
+
end
|
12
|
+
|
13
|
+
def method_missing(name, *args, &block)
|
14
|
+
name = name.to_sym
|
15
|
+
if me = self.class.data[instance_id] and me.has_key?(name)
|
16
|
+
me[name]
|
17
|
+
else
|
18
|
+
super
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class << self
|
23
|
+
def app
|
24
|
+
find_all_by_instance_roles :app, :app_master
|
25
|
+
end
|
26
|
+
|
27
|
+
def db
|
28
|
+
find_all_by_instance_roles :db
|
29
|
+
end
|
30
|
+
|
31
|
+
def utility
|
32
|
+
find_all_by_instance_roles :utility
|
33
|
+
end
|
34
|
+
|
35
|
+
def all
|
36
|
+
data.map { |k, _| new k }
|
37
|
+
end
|
38
|
+
|
39
|
+
def first
|
40
|
+
new data.to_a.first.first
|
41
|
+
end
|
42
|
+
|
43
|
+
def find_by_instance_id(instance_id)
|
44
|
+
new instance_id.to_sym
|
45
|
+
end
|
46
|
+
|
47
|
+
def find_all_by_instance_roles(*args)
|
48
|
+
data.select { |_, v| Array.wrap(args).include? v[:instance_role] }.map { |k, _| new k }
|
49
|
+
end
|
50
|
+
|
51
|
+
def refresh
|
52
|
+
@_data = nil
|
53
|
+
@_dna = nil
|
54
|
+
refresh_instance_descriptions true
|
55
|
+
end
|
56
|
+
|
57
|
+
def data
|
58
|
+
return @_data if @_data
|
59
|
+
hash = Hash.new
|
60
|
+
cached_instance_descriptions.each do |instance_description|
|
61
|
+
key = instance_description[:aws_instance_id].dup
|
62
|
+
hash[key] ||= Hash.new
|
63
|
+
current = hash[key]
|
64
|
+
# using current as a pointer
|
65
|
+
if dna[:db_host] == instance_description[:dns_name] or dna[:db_host] == instance_description[:private_dns_name]
|
66
|
+
current[:instance_role] = :db
|
67
|
+
elsif Array.wrap(dna[:utility_instances]).include? instance_description[:private_dns_name]
|
68
|
+
current[:instance_role] = :utility
|
69
|
+
elsif dna[:master_app_server][:private_dns_name] == instance_description[:private_dns_name]
|
70
|
+
current[:instance_role] = :app_master
|
71
|
+
else
|
72
|
+
current[:instance_role] = :app
|
73
|
+
end
|
74
|
+
current[:private_dns_name] = instance_description[:private_dns_name]
|
75
|
+
current[:dns_name] = instance_description[:dns_name]
|
76
|
+
current[:aws_instance_id] = instance_description[:aws_instance_id]
|
77
|
+
current[:aws_state] = instance_description[:aws_state]
|
78
|
+
end
|
79
|
+
@_data = hash.recursive_symbolize_keys!
|
80
|
+
end
|
81
|
+
|
82
|
+
private
|
83
|
+
|
84
|
+
def dna
|
85
|
+
@_dna ||= EngineYardCloudChef.dna
|
86
|
+
end
|
87
|
+
|
88
|
+
def cached_instance_descriptions(refresh = false)
|
89
|
+
refresh_instance_descriptions refresh
|
90
|
+
@_cached_instance_descriptions ||= YAML.load(IO.read(INSTANCE_DESCRIPTIONS_CACHE_PATH))
|
91
|
+
end
|
92
|
+
|
93
|
+
def refresh_instance_descriptions(refresh)
|
94
|
+
if refresh or !File.readable?(INSTANCE_DESCRIPTIONS_CACHE_PATH)
|
95
|
+
ec2 = RightAws::Ec2.new dna[:aws_secret_id], dna[:aws_secret_key]
|
96
|
+
@_cached_instance_descriptions = ec2.describe_instances.map(&:recursive_symbolize_keys!)
|
97
|
+
begin
|
98
|
+
File.open(INSTANCE_DESCRIPTIONS_CACHE_PATH, 'w') { |f| f.write @_cached_instance_descriptions.to_yaml }
|
99
|
+
rescue Errno::EACCES
|
100
|
+
$stderr.puts "[EY CLOUD AWARENESS GEM] Not caching instance data because #{INSTANCE_DESCRIPTIONS_CACHE_PATH} can't be written to"
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'active_support'
|
2
|
+
require 'right_aws'
|
3
|
+
|
4
|
+
%w{ engine_yard_cloud_instance engine_yard_cloud_chef }.each do |lib|
|
5
|
+
require File.expand_path(File.join(File.dirname(__FILE__), lib))
|
6
|
+
end
|
7
|
+
|
8
|
+
# http://pragmatig.wordpress.com/2009/04/14/recursive-symbolize_keys/
|
9
|
+
class Hash
|
10
|
+
def recursive_symbolize_keys!
|
11
|
+
symbolize_keys!
|
12
|
+
values.select { |v| v.is_a?(Hash) }.each { |h| h.recursive_symbolize_keys! }
|
13
|
+
self
|
14
|
+
end
|
15
|
+
end
|
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ey_cloud_awareness
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Seamus Abshere
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-11-03 00:00:00 -05:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: activesupport
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: right_aws
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: "0"
|
34
|
+
version:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: rspec
|
37
|
+
type: :development
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 1.2.9
|
44
|
+
version:
|
45
|
+
description: Make your EngineYard cloud instances aware of each other.
|
46
|
+
email: seamus@abshere.net
|
47
|
+
executables: []
|
48
|
+
|
49
|
+
extensions: []
|
50
|
+
|
51
|
+
extra_rdoc_files:
|
52
|
+
- LICENSE
|
53
|
+
- README.rdoc
|
54
|
+
files:
|
55
|
+
- .document
|
56
|
+
- .gitignore
|
57
|
+
- LICENSE
|
58
|
+
- README.rdoc
|
59
|
+
- Rakefile
|
60
|
+
- VERSION
|
61
|
+
- ey_cloud_awareness.gemspec
|
62
|
+
- lib/engine_yard_cloud_chef.rb
|
63
|
+
- lib/engine_yard_cloud_instance.rb
|
64
|
+
- lib/ey_cloud_awareness.rb
|
65
|
+
- spec/ey_cloud_awareness_spec.rb
|
66
|
+
- spec/spec.opts
|
67
|
+
- spec/spec_helper.rb
|
68
|
+
has_rdoc: true
|
69
|
+
homepage: http://github.com/seamusabshere/ey_cloud_awareness
|
70
|
+
licenses: []
|
71
|
+
|
72
|
+
post_install_message:
|
73
|
+
rdoc_options:
|
74
|
+
- --charset=UTF-8
|
75
|
+
require_paths:
|
76
|
+
- lib
|
77
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: "0"
|
82
|
+
version:
|
83
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: "0"
|
88
|
+
version:
|
89
|
+
requirements: []
|
90
|
+
|
91
|
+
rubyforge_project:
|
92
|
+
rubygems_version: 1.3.5
|
93
|
+
signing_key:
|
94
|
+
specification_version: 3
|
95
|
+
summary: Make your EngineYard cloud instances aware of each other.
|
96
|
+
test_files:
|
97
|
+
- spec/ey_cloud_awareness_spec.rb
|
98
|
+
- spec/spec_helper.rb
|