engineyard-metadata 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +15 -3
- data/VERSION +1 -1
- data/engineyard-metadata.gemspec +2 -2
- data/lib/engineyard-metadata/chef_dna.rb +18 -0
- data/lib/engineyard-metadata/metadata.rb +3 -0
- data/spec/metadata_spec.rb +13 -1
- metadata +4 -4
data/README.rdoc
CHANGED
@@ -4,12 +4,24 @@ Pulls metadata from EC2 and EngineYard so that your EngineYard Cloud instances k
|
|
4
4
|
|
5
5
|
== Purpose
|
6
6
|
|
7
|
-
To define an unchanging interface to
|
7
|
+
To define an unchanging interface to useful metadata (passwords, IP addresses, etc.) that is otherwise buried deep inside EngineYard's chef config files and EC2 API calls.
|
8
8
|
|
9
|
-
==
|
9
|
+
== Examples
|
10
10
|
|
11
|
-
|
11
|
+
* Get a dynamically updated list of all running app servers so that you can pool memcached over all of them. (<tt>EY::Metadata.app_servers</tt>)
|
12
|
+
* Get the current database password so that you can write a script that connects to it. (<tt>EY::Metadata.database_password</tt>)
|
12
13
|
|
14
|
+
== Use
|
15
|
+
|
16
|
+
Get the full method list in {the engineyard-metadata rdoc}[http://rdoc.info/github/seamusabshere/engineyard-metadata].
|
17
|
+
|
18
|
+
Metadata getters are defined directly on <tt>EY::Metadata</tt>. Even if EngineYard changes the structure of the config files or Amazon EC2's API changes, these methods will stay the same.
|
19
|
+
|
20
|
+
This only runs on EngineYard AppCloud instances (running on Amazon EC2).
|
21
|
+
|
22
|
+
[...]
|
23
|
+
>> require 'rubygems'
|
24
|
+
[...]
|
13
25
|
>> require 'engineyard-metadata'
|
14
26
|
[...]
|
15
27
|
>> EY::Metadata.database_host
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.3
|
data/engineyard-metadata.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{engineyard-metadata}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Seamus Abshere"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-10-08}
|
13
13
|
s.description = %q{Pulls metadata from EC2 and EngineYard so that your EngineYard AppCloud (Amazon EC2) instances know about each other.}
|
14
14
|
s.email = %q{seamus@abshere.net}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'active_support'
|
1
2
|
require 'active_support/version'
|
2
3
|
%w{
|
3
4
|
active_support/json
|
@@ -9,11 +10,18 @@ module EY
|
|
9
10
|
module Metadata
|
10
11
|
class ChefDna
|
11
12
|
PATH = '/etc/chef/dna.json'
|
13
|
+
MYSQL_BIN = '/usr/bin/mysql'
|
14
|
+
MYSQLDUMP_BIN = '/usr/bin/mysqldump'
|
12
15
|
|
13
16
|
def data # :nodoc:
|
14
17
|
@data ||= ActiveSupport::JSON.decode File.read(PATH)
|
15
18
|
end
|
16
19
|
|
20
|
+
# The present instance's role
|
21
|
+
def present_instance_role
|
22
|
+
data['instance_role']
|
23
|
+
end
|
24
|
+
|
17
25
|
# The present instance's public hostname.
|
18
26
|
def present_public_hostname
|
19
27
|
data['engineyard']['environment']['instances'].detect { |i| i['id'] == EY::Metadata.present_instance_id }['public_hostname']
|
@@ -85,6 +93,16 @@ module EY
|
|
85
93
|
data['engineyard']['environment']['instances'].detect { |i| i['role'] == 'solo' }
|
86
94
|
i['public_hostname']
|
87
95
|
end
|
96
|
+
|
97
|
+
# The shell command for mysql, including username, password, hostname and database
|
98
|
+
def mysql_command
|
99
|
+
"#{MYSQL_BIN} -h #{database_host} -u #{database_username} -p#{database_password} #{database_name}"
|
100
|
+
end
|
101
|
+
|
102
|
+
# The shell command for mysql, including username, password, hostname and database
|
103
|
+
def mysqldump_command
|
104
|
+
"#{MYSQLDUMP_BIN} -h #{database_host} -u #{database_username} -p#{database_password} #{database_name}"
|
105
|
+
end
|
88
106
|
end
|
89
107
|
end
|
90
108
|
end
|
@@ -6,6 +6,7 @@ module EY
|
|
6
6
|
}
|
7
7
|
|
8
8
|
DELEGATED_TO_CHEF_DNA = %w{
|
9
|
+
present_instance_role
|
9
10
|
present_public_hostname
|
10
11
|
database_password
|
11
12
|
database_username
|
@@ -18,6 +19,8 @@ module EY
|
|
18
19
|
utilities
|
19
20
|
app_master
|
20
21
|
db_master
|
22
|
+
mysql_command
|
23
|
+
mysqldump_command
|
21
24
|
}
|
22
25
|
|
23
26
|
DELEGATED_TO_AMAZON_EC2_API.each do |name|
|
data/spec/metadata_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe EY do
|
4
|
-
it 'has a dna.json' do
|
4
|
+
it 'has a FakeFS dna.json' do
|
5
5
|
File.exist?('/etc/chef/dna.json').should == true
|
6
6
|
end
|
7
7
|
end
|
@@ -11,6 +11,10 @@ describe EY::Metadata do
|
|
11
11
|
EY::Metadata.present_instance_id.should == PRESENT_INSTANCE_ID
|
12
12
|
end
|
13
13
|
|
14
|
+
it 'gets the present instance role (as a string)' do
|
15
|
+
EY::Metadata.present_instance_role.should == 'app_master'
|
16
|
+
end
|
17
|
+
|
14
18
|
it 'gets the present public hostname' do
|
15
19
|
EY::Metadata.present_public_hostname.should == PRESENT_PUBLIC_HOSTNAME
|
16
20
|
end
|
@@ -62,4 +66,12 @@ describe EY::Metadata do
|
|
62
66
|
it 'gets the db master hostname' do
|
63
67
|
EY::Metadata.db_master.should == 'db_master.compute-1.amazonaws.com'
|
64
68
|
end
|
69
|
+
|
70
|
+
it 'gets the mysql command' do
|
71
|
+
EY::Metadata.mysql_command.should == '/usr/bin/mysql -h external_db_master.compute-1.amazonaws.com -u USERS-0-USERNAME -pUSERS-0-PASSWORD APPS-0-DATABASE_NAME'
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'gets the mysqldump command' do
|
75
|
+
EY::Metadata.mysqldump_command.should == '/usr/bin/mysqldump -h external_db_master.compute-1.amazonaws.com -u USERS-0-USERNAME -pUSERS-0-PASSWORD APPS-0-DATABASE_NAME'
|
76
|
+
end
|
65
77
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: engineyard-metadata
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 3
|
10
|
+
version: 0.0.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Seamus Abshere
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-10-08 00:00:00 -05:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|