engineyard-cloud-client 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. data/LICENSE +19 -0
  2. data/README.rdoc +7 -0
  3. data/lib/engineyard-cloud-client.rb +149 -0
  4. data/lib/engineyard-cloud-client/errors.rb +38 -0
  5. data/lib/engineyard-cloud-client/model_registry.rb +21 -0
  6. data/lib/engineyard-cloud-client/models.rb +14 -0
  7. data/lib/engineyard-cloud-client/models/account.rb +38 -0
  8. data/lib/engineyard-cloud-client/models/api_struct.rb +50 -0
  9. data/lib/engineyard-cloud-client/models/app.rb +77 -0
  10. data/lib/engineyard-cloud-client/models/app_environment.rb +85 -0
  11. data/lib/engineyard-cloud-client/models/deployment.rb +105 -0
  12. data/lib/engineyard-cloud-client/models/environment.rb +240 -0
  13. data/lib/engineyard-cloud-client/models/instance.rb +15 -0
  14. data/lib/engineyard-cloud-client/models/keypair.rb +32 -0
  15. data/lib/engineyard-cloud-client/models/log.rb +11 -0
  16. data/lib/engineyard-cloud-client/models/user.rb +11 -0
  17. data/lib/engineyard-cloud-client/resolver_result.rb +19 -0
  18. data/lib/engineyard-cloud-client/rest_client_ext.rb +11 -0
  19. data/lib/engineyard-cloud-client/ruby_ext.rb +9 -0
  20. data/lib/engineyard-cloud-client/test.rb +31 -0
  21. data/lib/engineyard-cloud-client/test/fake_awsm.rb +22 -0
  22. data/lib/engineyard-cloud-client/test/fake_awsm/config.ru +207 -0
  23. data/lib/engineyard-cloud-client/test/fake_awsm/models.rb +9 -0
  24. data/lib/engineyard-cloud-client/test/fake_awsm/models/account.rb +13 -0
  25. data/lib/engineyard-cloud-client/test/fake_awsm/models/app.rb +24 -0
  26. data/lib/engineyard-cloud-client/test/fake_awsm/models/app_environment.rb +19 -0
  27. data/lib/engineyard-cloud-client/test/fake_awsm/models/deployments.rb +15 -0
  28. data/lib/engineyard-cloud-client/test/fake_awsm/models/environment.rb +25 -0
  29. data/lib/engineyard-cloud-client/test/fake_awsm/models/instance.rb +23 -0
  30. data/lib/engineyard-cloud-client/test/fake_awsm/models/user.rb +15 -0
  31. data/lib/engineyard-cloud-client/test/fake_awsm/scenarios.rb +325 -0
  32. data/lib/engineyard-cloud-client/test/fake_awsm/views/accounts.rabl +2 -0
  33. data/lib/engineyard-cloud-client/test/fake_awsm/views/apps.rabl +10 -0
  34. data/lib/engineyard-cloud-client/test/fake_awsm/views/base_app_environment.rabl +13 -0
  35. data/lib/engineyard-cloud-client/test/fake_awsm/views/base_environment.rabl +4 -0
  36. data/lib/engineyard-cloud-client/test/fake_awsm/views/environments.rabl +11 -0
  37. data/lib/engineyard-cloud-client/test/fake_awsm/views/instances.rabl +2 -0
  38. data/lib/engineyard-cloud-client/test/fake_awsm/views/resolve_app_environments.rabl +7 -0
  39. data/lib/engineyard-cloud-client/test/fake_awsm/views/resolve_environments.rabl +7 -0
  40. data/lib/engineyard-cloud-client/test/fake_awsm/views/user.rabl +2 -0
  41. data/lib/engineyard-cloud-client/test/scenario.rb +43 -0
  42. data/lib/engineyard-cloud-client/test/ui.rb +33 -0
  43. data/lib/engineyard-cloud-client/version.rb +7 -0
  44. data/spec/engineyard-cloud-client/api_spec.rb +59 -0
  45. data/spec/engineyard-cloud-client/integration/account_spec.rb +18 -0
  46. data/spec/engineyard-cloud-client/integration/app_environment_spec.rb +38 -0
  47. data/spec/engineyard-cloud-client/integration/app_spec.rb +20 -0
  48. data/spec/engineyard-cloud-client/integration/environment_spec.rb +57 -0
  49. data/spec/engineyard-cloud-client/integration/user_spec.rb +18 -0
  50. data/spec/engineyard-cloud-client/models/api_struct_spec.rb +41 -0
  51. data/spec/engineyard-cloud-client/models/app_spec.rb +64 -0
  52. data/spec/engineyard-cloud-client/models/environment_spec.rb +300 -0
  53. data/spec/engineyard-cloud-client/models/instance_spec.rb +44 -0
  54. data/spec/engineyard-cloud-client/models/keypair_spec.rb +58 -0
  55. data/spec/spec_helper.rb +50 -0
  56. data/spec/support/helpers.rb +16 -0
  57. data/spec/support/matchers.rb +2 -0
  58. metadata +377 -0
@@ -0,0 +1,9 @@
1
+ class Object
2
+ unless respond_to?(:tap)
3
+ # Ruby 1.9 has it, 1.8 doesn't
4
+ def tap
5
+ yield self
6
+ self
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,31 @@
1
+ require 'engineyard-cloud-client'
2
+
3
+ module EY::CloudClient::Test
4
+ end
5
+
6
+ begin
7
+ require 'dm-core'
8
+ require 'dm-migrations'
9
+ require 'dm-aggregates'
10
+ require 'dm-sqlite-adapter'
11
+ require 'ey_resolver'
12
+ require 'rabl'
13
+ rescue LoadError
14
+ raise LoadError, <<-ERROR
15
+ engineyard-cloud-client needs the following gems to run in test mode:
16
+
17
+ group 'engineyard-cloud-client-test' do
18
+ gem 'dm-core'
19
+ gem 'dm-migrations'
20
+ gem 'dm-aggregates'
21
+ gem 'dm-sqlite-adapter'
22
+ gem 'ey_resolver', '~>0.2.1'
23
+ gem 'rabl'
24
+ end
25
+
26
+ Please add the above to your Gemfile.
27
+ ERROR
28
+ end
29
+
30
+ require 'engineyard-cloud-client/test/ui'
31
+ require 'engineyard-cloud-client/test/scenario'
@@ -0,0 +1,22 @@
1
+ require 'engineyard-cloud-client/test'
2
+ require 'engineyard-cloud-client/test'
3
+ require 'realweb'
4
+
5
+ module EY::CloudClient::Test
6
+ module FakeAwsm
7
+ def self.uri
8
+ @uri ||= load_server
9
+ end
10
+
11
+ protected
12
+
13
+ def self.load_server
14
+ config_ru = File.expand_path("fake_awsm/config.ru", File.dirname(__FILE__))
15
+ unless system("ruby -c '#{config_ru}' > /dev/null")
16
+ raise SyntaxError, "There is a syntax error in fake_awsm/config.ru! FIX IT!"
17
+ end
18
+ @server = RealWeb.start_server_in_fork(config_ru)
19
+ @server.base_uri.to_s
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,207 @@
1
+ require 'rubygems'
2
+ require 'sinatra/base'
3
+ require 'json'
4
+ require 'rabl'
5
+ require 'gitable'
6
+ require 'ey_resolver'
7
+ require File.expand_path('../scenarios', __FILE__)
8
+ require File.expand_path('../models', __FILE__)
9
+
10
+ Rabl.register!
11
+
12
+ class FakeAwsm < Sinatra::Base
13
+ disable :show_exceptions
14
+ enable :raise_errors
15
+ set :views, File.expand_path('../views', __FILE__)
16
+
17
+ SCENARIOS = [
18
+ Scenario::Base.new,
19
+ Scenario::AppWithoutEnv.new,
20
+ Scenario::UnlinkedApp.new,
21
+ Scenario::TwoApps.new,
22
+ Scenario::LinkedApp.new,
23
+ Scenario::MultipleAmbiguousAccounts.new,
24
+ Scenario::LinkedAppNotRunning.new,
25
+ Scenario::LinkedAppRedMaster.new,
26
+ Scenario::OneAppManyEnvs.new,
27
+ Scenario::OneAppManySimilarlyNamedEnvs.new,
28
+ Scenario::TwoAppsSameGitUri.new,
29
+ ]
30
+
31
+ def initialize(*)
32
+ super
33
+ @user = Scenario::Base.new.user
34
+ end
35
+
36
+ before do
37
+ content_type "application/json"
38
+ token = request.env['HTTP_X_EY_CLOUD_TOKEN']
39
+ if token
40
+ @user = User.first(:api_token => token)
41
+ end
42
+ end
43
+
44
+ get "/" do
45
+ content_type :html
46
+ "OMG"
47
+ end
48
+
49
+ get "/scenario" do
50
+ new_scenario = SCENARIOS.detect { |scen| scen.user.name == params[:scenario] }
51
+ unless new_scenario
52
+ status(404)
53
+ return {"ok" => "false", "message" => "wtf is the #{params[:scenario]} scenario?"}.to_json
54
+ end
55
+ user = new_scenario.user
56
+ {
57
+ "scenario" => {
58
+ "email" => user.email,
59
+ "password" => user.password,
60
+ "api_token" => user.api_token,
61
+ }
62
+ }.to_json
63
+ end
64
+
65
+ get "/scenarios" do
66
+ scenarios = SCENARIOS.map do |scen|
67
+ user = scen.user
68
+ {
69
+ :name => user.name,
70
+ :email => user.email,
71
+ :password => user.password,
72
+ :api_token => user.api_token,
73
+ }
74
+ end
75
+ {'scenarios' => scenarios}.to_json
76
+ end
77
+
78
+ get "/api/v2/current_user" do
79
+ render :rabl, :user, :format => "json"
80
+ end
81
+
82
+ get "/api/v2/accounts" do
83
+ @accounts = @user.accounts
84
+ render :rabl, :accounts, :format => "json"
85
+ end
86
+
87
+ get "/api/v2/apps" do
88
+ raise('No user agent header') unless env['HTTP_USER_AGENT'] =~ %r#^EngineYardCloudClient/#
89
+ @apps = @user.accounts.apps
90
+ render :rabl, :apps, :format => "json"
91
+ end
92
+
93
+ get "/api/v2/environments" do
94
+ @environments = @user.accounts.environments
95
+ render :rabl, :environments, :format => "json"
96
+ end
97
+
98
+ get "/api/v2/environments/resolve" do
99
+ @resolver = EY::Resolver.environment_resolver(@user, params['constraints'])
100
+ render :rabl, :resolve_environments, :format => "json"
101
+ end
102
+
103
+ get "/api/v2/app_environments/resolve" do
104
+ @resolver = EY::Resolver.app_env_resolver(@user, params['constraints'])
105
+ render :rabl, :resolve_app_environments, :format => "json"
106
+ end
107
+
108
+ get "/api/v2/environments/:env_id/instances" do
109
+ environment = @user.accounts.environments.get(params['env_id'])
110
+ @instances = environment.instances
111
+ render :rabl, :instances, :format => "json"
112
+ end
113
+
114
+ get "/api/v2/environments/:env_id/logs" do
115
+ {
116
+ "logs" => [
117
+ {
118
+ "id" => params['env_id'].to_i,
119
+ "role" => "app_master",
120
+ "main" => "MAIN LOG OUTPUT",
121
+ "custom" => "CUSTOM LOG OUTPUT"
122
+ }
123
+ ]
124
+ }.to_json
125
+ end
126
+
127
+ get "/api/v2/environments/:env_id/recipes" do
128
+ redirect '/fakes3/recipe'
129
+ end
130
+
131
+ get "/fakes3/recipe" do
132
+ content_type "binary/octet-stream"
133
+ status(200)
134
+
135
+ tempdir = File.join(Dir.tmpdir, "ey_test_cmds_#{Time.now.tv_sec}#{Time.now.tv_usec}_#{$$}")
136
+ Dir.mkdir(tempdir)
137
+ Dir.mkdir("#{tempdir}/cookbooks")
138
+ File.open("#{tempdir}/cookbooks/README", 'w') do |f|
139
+ f.write "Remove this file to clone an upstream git repository of cookbooks\n"
140
+ end
141
+
142
+ Dir.chdir(tempdir) { `tar czf - cookbooks` }
143
+ end
144
+
145
+ post "/api/v2/environments/:env_id/recipes" do
146
+ if params[:file][:tempfile]
147
+ files = `tar --list -z -f "#{params[:file][:tempfile].path}"`.split(/\n/)
148
+ if files.empty?
149
+ status(400)
150
+ "No files in uploaded tarball"
151
+ else
152
+ status(204)
153
+ ""
154
+ end
155
+ else
156
+ status(400)
157
+ "Recipe file not uploaded"
158
+ end
159
+ end
160
+
161
+ put "/api/v2/environments/:env_id/update_instances" do
162
+ status(202)
163
+ ""
164
+ end
165
+
166
+ put "/api/v2/environments/:env_id/run_custom_recipes" do
167
+ status(202)
168
+ ""
169
+ end
170
+
171
+ get "/api/v2/apps/:app_id/environments/:environment_id/deployments/last" do
172
+ {
173
+ "deployment" => {
174
+ "id" => 3,
175
+ "ref" => "HEAD",
176
+ "resolved_ref" => "HEAD",
177
+ "commit" => 'a'*40,
178
+ "user_name" => "User Name",
179
+ "migrate_command" => "rake db:migrate --trace",
180
+ "created_at" => Time.now.utc - 3600,
181
+ "finished_at" => Time.now.utc - 3400,
182
+ "successful" => true,
183
+ }
184
+ }.to_json
185
+ end
186
+
187
+ post "/api/v2/apps/:app_id/environments/:environment_id/deployments" do
188
+ {"deployment" => params[:deployment].merge({"id" => 2, "commit" => 'a'*40, "resolved_ref" => "resolved-#{params[:deployment][:ref]}"})}.to_json
189
+ end
190
+
191
+ put "/api/v2/apps/:app_id/environments/:environment_id/deployments/:deployment_id/finished" do
192
+ {"deployment" => params[:deployment].merge({"id" => 2, "finished_at" => Time.now})}.to_json
193
+ end
194
+
195
+ post "/api/v2/authenticate" do
196
+ user = User.first(:email => params[:email], :password => params[:password])
197
+ if user
198
+ {"api_token" => user.api_token, "ok" => true}.to_json
199
+ else
200
+ status(401)
201
+ {"ok" => false}.to_json
202
+ end
203
+ end
204
+
205
+ end
206
+
207
+ run FakeAwsm.new
@@ -0,0 +1,9 @@
1
+ Dir[File.expand_path('../models/*.rb', __FILE__)].each do |model|
2
+ require model
3
+ end
4
+
5
+ require 'dm-migrations'
6
+ require 'dm-aggregates'
7
+ DataMapper.setup(:default, "sqlite::memory:")
8
+ DataMapper.finalize
9
+ DataMapper.auto_migrate!
@@ -0,0 +1,13 @@
1
+ require 'dm-core'
2
+
3
+ class Account
4
+ include DataMapper::Resource
5
+
6
+ property :id, Serial
7
+ property :name, String
8
+
9
+ belongs_to :user
10
+ has n, :environments
11
+ has n, :apps
12
+
13
+ end
@@ -0,0 +1,24 @@
1
+ require 'gitable'
2
+ require 'dm-core'
3
+
4
+ class App
5
+ include DataMapper::Resource
6
+
7
+ property :id, Serial
8
+ property :name, String
9
+ property :repository_uri, String
10
+ property :app_type_id, String
11
+
12
+ belongs_to :account
13
+ has n, :app_environments
14
+ has n, :environments, :through => :app_environments
15
+
16
+ def gitable_uri
17
+ Gitable::URI.parse(repository_uri)
18
+ end
19
+
20
+ def inspect
21
+ "#<App name:#{name} account:#{account.name}>"
22
+ end
23
+
24
+ end
@@ -0,0 +1,19 @@
1
+ require 'dm-core'
2
+
3
+ class AppEnvironment
4
+ include DataMapper::Resource
5
+
6
+ property :id, Serial
7
+ property :app_id, Integer
8
+ property :environment_id, Integer
9
+
10
+ belongs_to :app
11
+ belongs_to :environment
12
+
13
+ has n, :deployments
14
+
15
+ def inspect
16
+ "#<AppEnvironment app:#{app.name} env:#{environment.name}>"
17
+ end
18
+
19
+ end
@@ -0,0 +1,15 @@
1
+ require 'dm-core'
2
+
3
+ class Deployment
4
+ include DataMapper::Resource
5
+
6
+ property :id, Serial
7
+ property :app_environment_id, Integer
8
+
9
+ belongs_to :app_environment
10
+
11
+ def inspect
12
+ "#<Deployment app_environment:#{app_environment.inspect}>"
13
+ end
14
+
15
+ end
@@ -0,0 +1,25 @@
1
+ require 'dm-core'
2
+
3
+ class Environment
4
+ include DataMapper::Resource
5
+
6
+ property :id, Serial
7
+ property :name, String
8
+ property :ssh_username, String
9
+ property :app_server_stack_name, String
10
+ property :load_balancer_ip_address, String
11
+ property :framework_env, String
12
+
13
+ belongs_to :account
14
+ has n, :app_environments
15
+ has n, :apps, :through => :app_environments
16
+ has n, :instances
17
+
18
+ def inspect
19
+ "#<Environment name:#{name} account:#{account.name}>"
20
+ end
21
+
22
+ def instances_count
23
+ instances.size
24
+ end
25
+ end
@@ -0,0 +1,23 @@
1
+ require 'dm-core'
2
+
3
+ class Instance
4
+ include DataMapper::Resource
5
+
6
+ property :id, Serial
7
+ property :name, String
8
+ property :role, String
9
+ property :status, String
10
+ property :amazon_id, String
11
+ property :public_hostname, String
12
+
13
+ belongs_to :environment
14
+
15
+ def inspect
16
+ "#<Instance environment:#{environment.name} role:#{role} name:#{name}>"
17
+ end
18
+
19
+ def bridge
20
+ %w[app_master solo].include?(role)
21
+ end
22
+
23
+ end
@@ -0,0 +1,15 @@
1
+ require 'dm-core'
2
+
3
+ class User
4
+ include DataMapper::Resource
5
+
6
+ property :id, Serial
7
+ property :name, String
8
+ property :email, String, :default => 'test@test.test'
9
+ property :password, String, :default => 'test'
10
+ property :api_token, String,
11
+ :default => lambda { |r, p| File.open('/dev/urandom', 'r') { |fh| fh.read(16).unpack('H*').first }}
12
+
13
+ has n, :accounts
14
+
15
+ end
@@ -0,0 +1,325 @@
1
+ require 'engineyard-cloud-client/test/fake_awsm'
2
+
3
+ module Scenario
4
+ class Base
5
+ attr_accessor :git_remote
6
+ attr_reader :user
7
+
8
+ def initialize(name = "User Name", email = "test@test.test", pass = "test")
9
+ @git_remote = "user@git.host:path/to/repo.git"
10
+ @user = User.create(:name => name, :email => email, :password => pass)
11
+ @account = @user.accounts.create({"name" => "main"})
12
+ end
13
+ end
14
+
15
+ class LinkedApp < Base
16
+ def initialize(name = 'Linked App', email = 'linked.app@test.local', pass = 'linked')
17
+ super
18
+ @app = @account.apps.create("name" => "rails232app", "repository_uri" => git_remote)
19
+ @env = @account.environments.create({
20
+ "name" => "giblets",
21
+ "ssh_username" => "turkey",
22
+ "app_server_stack_name" => "nginx_mongrel",
23
+ "load_balancer_ip_address" => '127.0.0.0',
24
+ "framework_env" => "production"
25
+ })
26
+
27
+ _instances.each do |inst|
28
+ @env.instances.create(inst)
29
+ end
30
+ @app_env = @app.app_environments.create(:environment => @env)
31
+ end
32
+
33
+ private
34
+
35
+ def _instances
36
+ [{
37
+ "role" => "app_master",
38
+ "name" => nil,
39
+ "status" => "running",
40
+ "amazon_id" => 'i-ddbbdd92',
41
+ "public_hostname" => "app_master_hostname.compute-1.amazonaws.com",
42
+ }, {
43
+ "name" => nil,
44
+ "role" => "db_master",
45
+ "status" => "running",
46
+ "amazon_id" => "i-d4cdddbf",
47
+ "public_hostname" => "db_master_hostname.compute-1.amazonaws.com",
48
+ }, {
49
+ "name" => nil,
50
+ "role" => "db_slave",
51
+ "status" => "running",
52
+ "amazon_id" => "i-asdfasdfaj",
53
+ "public_hostname" => "db_slave_1_hostname.compute-1.amazonaws.com",
54
+ }, {
55
+ "name" => nil,
56
+ "role" => "db_slave",
57
+ "status" => "running",
58
+ "amazon_id" => "i-asdfasdfaj",
59
+ "public_hostname" => "db_slave_2_hostname.compute-1.amazonaws.com",
60
+ }, {
61
+ "role" => "app",
62
+ "name" => nil,
63
+ "status" => "building",
64
+ "amazon_id" => "i-d2e3f1b9",
65
+ "public_hostname" => "app_hostname.compute-1.amazonaws.com",
66
+ }, {
67
+ "role" => "util",
68
+ "name" => "fluffy",
69
+ "status" => "running",
70
+ "amazon_id" => "i-80e3f1eb",
71
+ "public_hostname" => "util_fluffy_hostname.compute-1.amazonaws.com",
72
+ }, {
73
+ "role" => "util",
74
+ "name" => "rocky",
75
+ "status" => "running",
76
+ "amazon_id" => "i-80etf1eb",
77
+ "public_hostname" => "util_rocky_hostname.compute-1.amazonaws.com",
78
+ }]
79
+ end
80
+ end # LinkedApp
81
+
82
+ class MultipleAmbiguousAccounts < LinkedApp
83
+ def initialize(name = 'Multiple Ambiguous Accounts', email = 'multiple.ambiguous.accounts@test.local', pass = 'multi')
84
+ super
85
+ @account2 = @user.accounts.create("name" => "account_2")
86
+ @app2 = @account2.apps.create("name" => "rails232app", "repository_uri" => git_remote)
87
+ @env2 = @account2.environments.create({
88
+ "name" => "giblets",
89
+ "ssh_username" => "turkey",
90
+ "app_server_stack_name" => "nginx_mongrel",
91
+ "load_balancer_ip_address" => '127.0.0.0',
92
+ "framework_env" => "production"
93
+ })
94
+
95
+ _instances.each do |inst|
96
+ @env2.instances.create(inst)
97
+ end
98
+ @app_env2 = @app2.app_environments.create(:environment => @env2)
99
+ end
100
+ end
101
+
102
+ class AppWithoutEnv < Base
103
+ def initialize(name = 'App Without Env', email = 'app.without.env@test.local', pass = 'without')
104
+ super
105
+
106
+ @app = @account.apps.create({
107
+ "name" => "rails232app",
108
+ "repository_uri" => git_remote
109
+ })
110
+ end
111
+ end # AppWithoutEnv
112
+
113
+
114
+ class UnlinkedApp < Base
115
+ def initialize(name = 'Unlinked App', email = 'unlinked.app@test.local', pass = 'unlinked')
116
+ super
117
+
118
+ @app = @account.apps.create({
119
+ "name" => "rails232app",
120
+ "repository_uri" => git_remote
121
+ })
122
+
123
+ @other = @account.environments.create({
124
+ "name" => "chickenwings",
125
+ "ssh_username" => "ham",
126
+ "app_server_stack_name" => "nginx_mongrel",
127
+ "load_balancer_ip_address" => '127.0.0.0',
128
+ "framework_env" => "production"
129
+ })
130
+ @app_env = @app.app_environments.create(:environment => @other)
131
+
132
+ @env = @account.environments.create({
133
+ "name" => "giblets",
134
+ "ssh_username" => "turkey",
135
+ "app_server_stack_name" => "nginx_mongrel",
136
+ "load_balancer_ip_address" => '127.0.0.0',
137
+ "framework_env" => "production"
138
+ })
139
+
140
+ @env.instances.create({
141
+ "status" => "running",
142
+ "amazon_id" => 'i-ddbbdd92',
143
+ "role" => "solo",
144
+ "public_hostname" => "ec2-174-129-198-124.compute-1.amazonaws.com"
145
+ })
146
+ end
147
+ end # UnlinkedApp
148
+
149
+ class LinkedAppNotRunning < Base
150
+ def initialize(name = 'Linked App Not Running', email = 'linked.app.not.running@test.local', pass = 'linked.stopped')
151
+ super
152
+ @app = @account.apps.create({
153
+ "name" => "rails232app",
154
+ "repository_uri" => git_remote
155
+ })
156
+
157
+ @env = @account.environments.create({
158
+ "ssh_username" => "turkey",
159
+ "instances" => [],
160
+ "name" => "giblets",
161
+ "app_server_stack_name" => "nginx_mongrel",
162
+ "load_balancer_ip_address" => '127.0.0.0',
163
+ "framework_env" => "production"
164
+ })
165
+
166
+ @app.app_environments.create(:environment => @env)
167
+ end
168
+ end # LinkedAppNotRunning
169
+
170
+ class LinkedAppRedMaster < LinkedApp
171
+ def initialize(name = 'Linked App Red Master', email = 'linked.app.red.master@test.local', pass = 'linked.red')
172
+ super
173
+ @env.instances.first.update(:status => "error")
174
+ end
175
+ end
176
+
177
+ class OneAppManyEnvs < Base
178
+ def initialize(name = 'One App Many Envs', email = 'one.app.many.envs@test.local', pass = '1app2cups')
179
+ super
180
+ @app = @account.apps.create({
181
+ "name" => "rails232app",
182
+ "repository_uri" => git_remote
183
+ })
184
+
185
+ @env1 = @account.environments.create({
186
+ "ssh_username" => "turkey",
187
+ "name" => "giblets",
188
+ "app_server_stack_name" => "nginx_mongrel",
189
+ "load_balancer_ip_address" => '127.0.0.0',
190
+ "framework_env" => "production",
191
+ })
192
+ @env1.app_environments.create(:app => @app)
193
+
194
+ @env1.instances.create({
195
+ "status" => "running",
196
+ "amazon_id" => 'i-ddbbdd92',
197
+ "role" => "solo",
198
+ "public_hostname" => "app_master_hostname.compute-1.amazonaws.com"
199
+ })
200
+ @env2 = @account.environments.create({
201
+ "ssh_username" => "ham",
202
+ "instances" => [],
203
+ "name" => "bakon",
204
+ "app_server_stack_name" => "nginx_passenger",
205
+ "load_balancer_ip_address" => '127.0.0.0',
206
+ })
207
+ @env2.app_environments.create(:app => @app)
208
+
209
+ @env3 = @account.environments.create({
210
+ "ssh_username" => "hamburger",
211
+ "instances" => [],
212
+ "name" => "beef",
213
+ "app_server_stack_name" => "nginx_passenger",
214
+ "load_balancer_ip_address" => '127.0.0.0',
215
+ })
216
+ end
217
+ end # OneAppTwoEnvs
218
+
219
+ class TwoApps < Base
220
+ def initialize(name = 'Two Apps', email = 'two.apps@test.local', pass = '2apps')
221
+ super
222
+ @env1 = @account.environments.create({
223
+ "name" => "giblets",
224
+ "framework_env" => "staging",
225
+ "ssh_username" => "turkey",
226
+ "app_server_stack_name" => "nginx_unicorn",
227
+ "load_balancer_ip_address" => '127.0.0.0',
228
+ })
229
+ @app1 = @account.apps.create({
230
+ "name" => "rails232app",
231
+ "repository_uri" => "git://github.com/smerritt/rails232app.git"
232
+ })
233
+ @env1.app_environments.create(:app => @app1)
234
+ @env1.instances.create({
235
+ "status" => "running",
236
+ "name" => nil,
237
+ "role" => "solo",
238
+ "public_hostname" => "ec2-174-129-7-113.compute-1.amazonaws.com",
239
+ "amazon_id" => "i-0911f063",
240
+ })
241
+
242
+ @env2 = @account.environments.create({
243
+ "framework_env" => "production",
244
+ "name" => "keycollector_production",
245
+ "ssh_username" => "deploy",
246
+ "load_balancer_ip_address" => '127.0.0.0',
247
+ "app_server_stack_name" => "nginx_mongrel",
248
+ })
249
+ @app2 = @account.apps.create({
250
+ "name" => "keycollector",
251
+ "repository_uri" => "git@github.com:smerritt/keycollector.git",
252
+ })
253
+ @env2.app_environments.create(:app => @app2)
254
+ @env2.instances.create({
255
+ "status" => "running",
256
+ "name" => nil,
257
+ "role" => "solo",
258
+ "public_hostname" => "app_master_hostname.compute-1.amazonaws.com",
259
+ "amazon_id" => "i-051195b9",
260
+ })
261
+ end
262
+ end # TwoApps
263
+
264
+ class TwoAppsSameGitUri < TwoApps
265
+ def initialize(name = 'Two Apps Same Git URI', email = 'two.apps.same.git.uri@test.local', pass = '2apps1repo')
266
+ super
267
+ @app1.update(:repository_uri => "git://github.com/engineyard/dup.git")
268
+ @app2.update(:repository_uri => "git://github.com/engineyard/dup.git")
269
+ end
270
+ end # TwoAppsSameGitUri
271
+
272
+ class OneAppManySimilarlyNamedEnvs < Base
273
+ def initialize(name = 'One App Similarly Named Envs', email = 'one.app.similarly.named.envs@test.local', pass = '1apptwinrepos')
274
+ super
275
+ @app = @account.apps.create({
276
+ "name" => "rails232app",
277
+ "repository_uri" => git_remote
278
+ })
279
+
280
+ @env1 = @account.environments.create({
281
+ "ssh_username" => "turkey",
282
+ "name" => "railsapp_production",
283
+ "load_balancer_ip_address" => '127.0.0.0',
284
+ "app_server_stack_name" => "nginx_mongrel",
285
+ "framework_env" => "production",
286
+ })
287
+ @env1.instances.create({
288
+ "status" => "running",
289
+ "amazon_id" => 'i-ddbbdd92',
290
+ "role" => "solo",
291
+ "public_hostname" => "app_master_hostname.compute-1.amazonaws.com"
292
+ })
293
+
294
+ @env2 = @account.environments.create({
295
+ "ssh_username" => "ham",
296
+ "name" => "railsapp_staging",
297
+ "load_balancer_ip_address" => '127.3.2.1',
298
+ "app_server_stack_name" => "nginx_passenger",
299
+ "framework_env" => "production",
300
+ })
301
+
302
+ @env2.instances.create({
303
+ "public_hostname" => '127.3.2.1',
304
+ "status" => "running",
305
+ "role" => "solo",
306
+ })
307
+ @env3 = @account.environments.create({
308
+ "ssh_username" => "ham",
309
+ "name" => "railsapp_staging_2",
310
+ "app_server_stack_name" => "nginx_passenger",
311
+ "load_balancer_ip_address" => '127.0.0.2',
312
+ "framework_env" => "production",
313
+ })
314
+ @env3.instances.create({
315
+ "status" => "running",
316
+ "role" => "solo",
317
+ "public_hostname" => "ec2-174-129-198-124.compute-1.amazonaws.com",
318
+ })
319
+
320
+ @app.app_environments.create(:environment => @env1)
321
+ @app.app_environments.create(:environment => @env2)
322
+ @app.app_environments.create(:environment => @env3)
323
+ end
324
+ end # OneAppManySimilarlyNamedEnvs
325
+ end