engineyard-metadata 0.1.0 → 0.1.1

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
@@ -69,6 +69,11 @@ Metadata getters are defined directly on <tt>EY::Metadata</tt> (which in turn de
69
69
  => [ 'db_master.compute-1.amazonaws.com', 'db_slave_1.compute-1.amazonaws.com' ]
70
70
  [...and many more...]
71
71
 
72
+ == Known issues
73
+
74
+ * 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
+ * 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
+
72
77
  == History
73
78
 
74
79
  This is the second generation of http://rubygems.org/gems/ey_cloud_awareness.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{engineyard-metadata}
8
- s.version = "0.1.0"
8
+ s.version = "0.1.1"
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-14}
12
+ s.date = %q{2010-10-18}
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 = [
@@ -112,24 +112,37 @@ module EY
112
112
  def repository_uri
113
113
  data['apps'][0]['repository_uri']
114
114
  end
115
+
116
+ # A list of all the environment names belonging to this account.
117
+ def environment_names
118
+ environments.map { |environment| environment['name'] }
119
+ end
115
120
 
121
+ # Used internally to determine whether we've decoded the API response yet.
116
122
  def data_loaded?
117
123
  defined?(@data) and @data.is_a? Hash
118
124
  end
119
125
 
120
- def data
121
- return @data if data_loaded?
126
+ # Used internally to store the full list of environments that the API gives us.
127
+ def environments
128
+ return @environments if @environments.is_a? Array
122
129
  raw_json = REST.get(URL, 'X-EY-Cloud-Token' => EY::Metadata.ey_cloud_token).body
123
130
  raw_data = ActiveSupport::JSON.decode raw_json
124
- matching_environment_hshs = raw_data['environments'].select do |environment_hsh|
131
+ @environments = raw_data['environments']
132
+ end
133
+
134
+ # Used internally to store data about the specific environment we're working with.
135
+ def data
136
+ return @data if data_loaded?
137
+ matching_environments = environments.select do |environment|
125
138
  if EY::Metadata.environment_name
126
- environment_hsh['name'] == EY::Metadata.environment_name
139
+ environment['name'] == EY::Metadata.environment_name
127
140
  else
128
- environment_hsh['apps'].any? { |app_hsh| app_hsh['repository_uri'] == EY::Metadata.repository_uri }
141
+ environment['apps'].any? { |app| app['repository_uri'] == EY::Metadata.repository_uri }
129
142
  end
130
143
  end
131
- raise RuntimeError, "[engineyard-metadata gem] Found too many environments: #{matching_environment_hshs.map { |hsh| hsh['name'] }.join(', ')}" if matching_environment_hshs.length > 1
132
- @data = matching_environment_hshs[0]
144
+ raise RuntimeError, "[engineyard-metadata gem] Found too many environments: #{matching_environments.map { |environment| environments['name'] }.join(', ')}" if matching_environments.length > 1
145
+ @data = matching_environments[0]
133
146
  raise RuntimeError, "[engineyard-metadata gem] Couldn't find an EngineYard environment with the repository uri #{repository_uri}" unless data_loaded?
134
147
  @data
135
148
  end
@@ -26,6 +26,11 @@ module EY
26
26
  @amazon_ec2_api = nil
27
27
  end
28
28
 
29
+ # You can't get the list of environment names while you're on the instances themselves.
30
+ def environment_names
31
+ raise CannotGetFromHere
32
+ end
33
+
29
34
  # An adapter that reads from the EngineYard AppCloud /etc/chef/dna.json file.
30
35
  def chef_dna
31
36
  @chef_dna ||= ChefDna.new
@@ -29,6 +29,7 @@ module EY
29
29
  environment_name
30
30
  stack_name
31
31
  repository_uri
32
+ environment_names
32
33
  } unless defined?(KEYS)
33
34
 
34
35
  # This gets raised when you can't get a particular piece of metadata from the execution environment you're in.
@@ -63,6 +63,10 @@ shared_examples_for "it does in all execution environments" do
63
63
  end
64
64
 
65
65
  shared_examples_for "it's executing outside the cloud" do
66
+ it 'gets the list of all environment names' do
67
+ EY::Metadata.environment_names.should == [ 'WRONG_ENVIRONMENT_NAME', 'FAKE_ENVIRONMENT_NAME' ]
68
+ end
69
+
66
70
  it 'not get the present instance ID' do
67
71
  lambda {
68
72
  EY::Metadata.present_instance_id
@@ -117,6 +121,12 @@ shared_examples_for "it's executing outside the cloud" do
117
121
  end
118
122
 
119
123
  shared_examples_for "it's executing inside the cloud" do
124
+ it 'not get the list of all environment names' do
125
+ lambda {
126
+ EY::Metadata.environment_names
127
+ }.should raise_error(EY::Metadata::CannotGetFromHere)
128
+ end
129
+
120
130
  it 'get the present instance ID' do
121
131
  EY::Metadata.present_instance_id.should == PRESENT_INSTANCE_ID
122
132
  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: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 0
10
- version: 0.1.0
9
+ - 1
10
+ version: 0.1.1
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-10-14 00:00:00 -05:00
18
+ date: 2010-10-18 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency