engineyard-metadata 0.1.1 → 0.1.2

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/README.rdoc CHANGED
@@ -13,29 +13,33 @@ To define an unchanging interface to useful metadata (passwords, IP addresses, e
13
13
 
14
14
  Here's the current method list:
15
15
 
16
- EY::Metadata.present_instance_id (only works from cloud instances)
17
- EY::Metadata.present_security_group (only works from cloud instances)
18
- EY::Metadata.present_instance_role (only works from cloud instances)
19
- EY::Metadata.present_public_hostname (only works from cloud instances)
20
- EY::Metadata.database_password (only works from cloud instances)
21
- EY::Metadata.database_username
22
- EY::Metadata.database_name
23
- EY::Metadata.database_host
24
- EY::Metadata.ssh_username
25
- EY::Metadata.ssh_password (only works from cloud instances)
26
- EY::Metadata.app_servers
27
- EY::Metadata.db_servers
28
- EY::Metadata.utilities
29
- EY::Metadata.app_master
30
- EY::Metadata.db_master
31
- EY::Metadata.mysql_command (only works from cloud instances)
32
- EY::Metadata.mysqldump_command (only works from cloud instances)
33
- EY::Metadata.app_slaves
34
- EY::Metadata.db_slaves
35
- EY::Metadata.solo
36
- EY::Metadata.environment_name
37
- EY::Metadata.stack_name
38
- EY::Metadata.repository_uri
16
+ EY::Metadata.app_master
17
+ EY::Metadata.app_name
18
+ EY::Metadata.app_servers
19
+ EY::Metadata.app_slaves
20
+ EY::Metadata.current_path
21
+ EY::Metadata.database_host
22
+ EY::Metadata.database_name
23
+ EY::Metadata.database_password (only works from cloud instances)
24
+ EY::Metadata.database_username
25
+ EY::Metadata.db_master
26
+ EY::Metadata.db_servers
27
+ EY::Metadata.db_slaves
28
+ EY::Metadata.environment_name
29
+ EY::Metadata.mysql_command (only works from cloud instances)
30
+ EY::Metadata.mysqldump_command (only works from cloud instances)
31
+ EY::Metadata.present_instance_id (only works from cloud instances)
32
+ EY::Metadata.present_instance_role (only works from cloud instances)
33
+ EY::Metadata.present_public_hostname (only works from cloud instances)
34
+ EY::Metadata.present_security_group (only works from cloud instances)
35
+ EY::Metadata.repository_uri
36
+ EY::Metadata.shared_path
37
+ EY::Metadata.solo
38
+ EY::Metadata.ssh_aliases
39
+ EY::Metadata.ssh_password (only works from cloud instances)
40
+ EY::Metadata.ssh_username
41
+ EY::Metadata.stack_name
42
+ EY::Metadata.utilities
39
43
 
40
44
  == Use
41
45
 
@@ -69,8 +73,24 @@ Metadata getters are defined directly on <tt>EY::Metadata</tt> (which in turn de
69
73
  => [ 'db_master.compute-1.amazonaws.com', 'db_slave_1.compute-1.amazonaws.com' ]
70
74
  [...and many more...]
71
75
 
76
+ == SSH alias helper
77
+
78
+ You can put the output of <tt>ey_ssh_aliases</tt> into <tt>~/.ssh/config</tt>:
79
+
80
+ $ EY_ENVIRONMENT_NAME=my_env ey_ssh_aliases
81
+ Host my_env-app_master
82
+ Hostname ec2-11-11-111-11.compute-1.amazonaws.com
83
+ User deploy
84
+ StrictHostKeyChecking no
85
+
86
+ Host my_env-db_master
87
+ Hostname ec2-111-11-11-11.compute-1.amazonaws.com
88
+ User deploy
89
+ StrictHostKeyChecking no
90
+
72
91
  == Known issues
73
92
 
93
+ * Doesn't work with multiple apps per environment.
74
94
  * It's not always clear what environment you're running in. For example, you say <tt>EY::Metadata.something</tt> and you're just supposed to know what environment you're in. You can use <tt>.environment_name=</tt>, but you might not remember.
75
95
  * There are no factory methods. If we fully fleshed this out, it might be like <tt>my_env = EY::Environment.find('my_env')</tt> and <tt>my_app_master = my_env.app_master</tt>. Not sure that complexity would add a lot of value.
76
96
 
data/Rakefile CHANGED
@@ -15,6 +15,7 @@ begin
15
15
  gem.add_development_dependency "fakeweb"
16
16
  gem.add_development_dependency "fakefs"
17
17
  gem.add_development_dependency "rspec", "~>2"
18
+ gem.executables = ['ey_ssh_aliases']
18
19
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
19
20
  end
20
21
  Jeweler::GemcutterTasks.new
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.2
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ unless RUBY_VERSION >= '1.9'
3
+ require 'rubygems'
4
+ end
5
+ require 'engineyard-metadata'
6
+ puts EY::Metadata.ssh_aliases
@@ -5,13 +5,15 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{engineyard-metadata}
8
- s.version = "0.1.1"
8
+ s.version = "0.1.2"
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-10-18}
12
+ s.date = %q{2010-10-21}
13
+ s.default_executable = %q{ey_ssh_aliases}
13
14
  s.description = %q{Pulls metadata from EC2 and EngineYard so that your EngineYard AppCloud (Amazon EC2) instances know about each other.}
14
15
  s.email = %q{seamus@abshere.net}
16
+ s.executables = ["ey_ssh_aliases"]
15
17
  s.extra_rdoc_files = [
16
18
  "LICENSE",
17
19
  "README.rdoc"
@@ -23,6 +25,7 @@ Gem::Specification.new do |s|
23
25
  "README.rdoc",
24
26
  "Rakefile",
25
27
  "VERSION",
28
+ "bin/ey_ssh_aliases",
26
29
  "engineyard-metadata.gemspec",
27
30
  "lib/engineyard-metadata.rb",
28
31
  "lib/engineyard-metadata/amazon_ec2_api.rb",
@@ -31,6 +34,7 @@ Gem::Specification.new do |s|
31
34
  "lib/engineyard-metadata/insider.rb",
32
35
  "lib/engineyard-metadata/metadata.rb",
33
36
  "lib/engineyard-metadata/outsider.rb",
37
+ "lib/engineyard-metadata/ssh_alias_helper.rb",
34
38
  "spec/metadata_spec.rb",
35
39
  "spec/spec_helper.rb",
36
40
  "spec/support/dna.json",
@@ -12,6 +12,8 @@ module EY
12
12
  class ChefDna
13
13
  PATH = '/etc/chef/dna.json'
14
14
 
15
+ include SshAliasHelper
16
+
15
17
  def data # :nodoc:
16
18
  @data ||= ActiveSupport::JSON.decode File.read(PATH)
17
19
  end
@@ -45,7 +47,24 @@ module EY
45
47
  def repository_uri
46
48
  data['engineyard']['environment']['apps'][0]['repository_name']
47
49
  end
48
-
50
+
51
+ # The name of the single app that runs in this environment.
52
+ #
53
+ # Warning: this gem currently doesn't support multiple apps per environment.
54
+ def app_name
55
+ data['engineyard']['environment']['apps'][0]['name']
56
+ end
57
+
58
+ # The path to the current deploy on app servers.
59
+ def current_path
60
+ "/data/#{app_name}/current"
61
+ end
62
+
63
+ # The path to the shared directory on app servers.
64
+ def shared_path
65
+ "/data/#{app_name}/shared"
66
+ end
67
+
49
68
  # Public hostname where you should connect to the database.
50
69
  #
51
70
  # Currently the db master public hostname.
@@ -16,6 +16,8 @@ module EY
16
16
  class EngineYardCloudApi
17
17
  URL = 'https://cloud.engineyard.com/api/v2/environments'
18
18
 
19
+ include SshAliasHelper
20
+
19
21
  # Currently the same as the SSH username.
20
22
  def database_username
21
23
  data['ssh_username']
@@ -28,9 +30,9 @@ module EY
28
30
 
29
31
  # Currently the same as the app name, at least for recently-created environments.
30
32
  #
31
- # It used to be named after the environment.
33
+ # This is less reliable that the answer you would get running from an instance, because databases used to be named after environments.
32
34
  def database_name
33
- data['apps'][0]['name']
35
+ app_name
34
36
  end
35
37
 
36
38
  # The hostname of the database host.
@@ -118,6 +120,23 @@ module EY
118
120
  environments.map { |environment| environment['name'] }
119
121
  end
120
122
 
123
+ # The name of the single app that runs in this environment.
124
+ #
125
+ # Warning: this gem currently doesn't support multiple apps per environment.
126
+ def app_name
127
+ data['apps'][0]['name']
128
+ end
129
+
130
+ # The path to the current deploy on app servers.
131
+ def current_path
132
+ "/data/#{app_name}/current"
133
+ end
134
+
135
+ # The path to the shared directory on app servers.
136
+ def shared_path
137
+ "/data/#{app_name}/shared"
138
+ end
139
+
121
140
  # Used internally to determine whether we've decoded the API response yet.
122
141
  def data_loaded?
123
142
  defined?(@data) and @data.is_a? Hash
@@ -6,36 +6,42 @@ module EY
6
6
  # instead of trying to call it from a particular adapter.
7
7
  module Metadata
8
8
  KEYS = %w{
9
- present_instance_id
10
- present_security_group
11
- present_instance_role
12
- present_public_hostname
9
+ app_master
10
+ app_name
11
+ app_servers
12
+ app_slaves
13
+ current_path
14
+ database_host
15
+ database_name
13
16
  database_password
14
17
  database_username
15
- database_name
16
- database_host
17
- ssh_username
18
- ssh_password
19
- app_servers
20
- db_servers
21
- utilities
22
- app_master
23
18
  db_master
19
+ db_servers
20
+ db_slaves
21
+ environment_name
22
+ environment_names
24
23
  mysql_command
25
24
  mysqldump_command
26
- app_slaves
27
- db_slaves
25
+ present_instance_id
26
+ present_instance_role
27
+ present_public_hostname
28
+ present_security_group
29
+ repository_uri
30
+ shared_path
28
31
  solo
29
- environment_name
32
+ ssh_aliases
33
+ ssh_password
34
+ ssh_username
30
35
  stack_name
31
- repository_uri
32
- environment_names
36
+ utilities
33
37
  } unless defined?(KEYS)
34
38
 
35
39
  # This gets raised when you can't get a particular piece of metadata from the execution environment you're in.
36
40
  class CannotGetFromHere < RuntimeError
37
41
  end
38
42
 
43
+ autoload :SshAliasHelper, 'engineyard-metadata/ssh_alias_helper'
44
+
39
45
  autoload :Insider, 'engineyard-metadata/insider'
40
46
  autoload :Outsider, 'engineyard-metadata/outsider'
41
47
  autoload :ChefDna, 'engineyard-metadata/chef_dna'
@@ -0,0 +1,36 @@
1
+ module EY
2
+ module Metadata
3
+ module SshAliasHelper
4
+ # Aliases like 'my_env-app_master' or 'my_env-utilities-5' that go in .ssh/config
5
+ #
6
+ # For example:
7
+ # Host my_env-app_master
8
+ # Hostname ec2-111-111-111-111.compute-1.amazonaws.com
9
+ # User deploy
10
+ # StrictHostKeyChecking no
11
+ def ssh_aliases
12
+ counter = Hash.new 0
13
+ %w{ app_master db_master db_slaves app_slaves utilities }.map do |role_group|
14
+ send(role_group).map do |public_hostname|
15
+ ssh_alias counter, role_group, public_hostname
16
+ end
17
+ end.flatten.join("\n")
18
+ end
19
+
20
+ # Used internally to generate a single ssh alias.
21
+ def ssh_alias(counter, role_group, public_hostname)
22
+ id = case role_group
23
+ when 'db_slaves', 'app_slaves', 'utilities'
24
+ "#{role_group}-#{counter[role_group] += 1}"
25
+ else
26
+ role_group
27
+ end
28
+ %{Host #{environment_name}-#{id}
29
+ Hostname #{public_hostname}
30
+ User #{ssh_username}
31
+ StrictHostKeyChecking no
32
+ }
33
+ end
34
+ end
35
+ end
36
+ end
@@ -60,6 +60,22 @@ shared_examples_for "it does in all execution environments" do
60
60
  it 'get the repository URI' do
61
61
  EY::Metadata.repository_uri.should == 'FAKE_REPOSITORY_URI'
62
62
  end
63
+
64
+ it 'gets the app name' do
65
+ EY::Metadata.app_name.should == 'FAKE_APP_NAME'
66
+ end
67
+
68
+ it 'gets the current path' do
69
+ EY::Metadata.current_path.should == '/data/FAKE_APP_NAME/current'
70
+ end
71
+
72
+ it 'gets the shared path' do
73
+ EY::Metadata.shared_path.should == '/data/FAKE_APP_NAME/shared'
74
+ end
75
+
76
+ it 'gets helpful ssh aliases' do
77
+ EY::Metadata.ssh_aliases.should =~ /Host FAKE_ENVIRONMENT_NAME-app_master\n Hostname app_master.compute-1.amazonaws.com/
78
+ end
63
79
  end
64
80
 
65
81
  shared_examples_for "it's executing outside the cloud" do
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: 25
4
+ hash: 31
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 1
10
- version: 0.1.1
9
+ - 2
10
+ version: 0.1.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Seamus Abshere
@@ -15,8 +15,8 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-10-18 00:00:00 -05:00
19
- default_executable:
18
+ date: 2010-10-21 00:00:00 -05:00
19
+ default_executable: ey_ssh_aliases
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  name: activesupport
@@ -93,8 +93,8 @@ dependencies:
93
93
  version_requirements: *id005
94
94
  description: Pulls metadata from EC2 and EngineYard so that your EngineYard AppCloud (Amazon EC2) instances know about each other.
95
95
  email: seamus@abshere.net
96
- executables: []
97
-
96
+ executables:
97
+ - ey_ssh_aliases
98
98
  extensions: []
99
99
 
100
100
  extra_rdoc_files:
@@ -107,6 +107,7 @@ files:
107
107
  - README.rdoc
108
108
  - Rakefile
109
109
  - VERSION
110
+ - bin/ey_ssh_aliases
110
111
  - engineyard-metadata.gemspec
111
112
  - lib/engineyard-metadata.rb
112
113
  - lib/engineyard-metadata/amazon_ec2_api.rb
@@ -115,6 +116,7 @@ files:
115
116
  - lib/engineyard-metadata/insider.rb
116
117
  - lib/engineyard-metadata/metadata.rb
117
118
  - lib/engineyard-metadata/outsider.rb
119
+ - lib/engineyard-metadata/ssh_alias_helper.rb
118
120
  - spec/metadata_spec.rb
119
121
  - spec/spec_helper.rb
120
122
  - spec/support/dna.json