ey-core 3.4.4 → 3.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +11 -3
  3. data/bin/ey-core +8 -0
  4. data/features/environment_variables.feature +54 -0
  5. data/features/step_definitions/accounts_steps.rb +14 -0
  6. data/features/step_definitions/applications_steps.rb +7 -14
  7. data/features/step_definitions/environment_variables_steps.rb +51 -0
  8. data/features/step_definitions/environments_steps.rb +15 -0
  9. data/features/support/environment_variable_helpers.rb +20 -0
  10. data/features/support/resource_helpers.rb +12 -0
  11. data/lib/ey-core/cli/environment_variables.rb +71 -0
  12. data/lib/ey-core/cli/helpers/core.rb +29 -0
  13. data/lib/ey-core/cli/main.rb +2 -0
  14. data/lib/ey-core/cli/servers.rb +34 -17
  15. data/lib/ey-core/client.rb +23 -0
  16. data/lib/ey-core/client/mock.rb +3 -0
  17. data/lib/ey-core/collections/auto_scaling_alarms.rb +8 -0
  18. data/lib/ey-core/collections/auto_scaling_policies.rb +33 -0
  19. data/lib/ey-core/collections/environment_variables.rb +8 -0
  20. data/lib/ey-core/models/address.rb +2 -0
  21. data/lib/ey-core/models/application.rb +1 -0
  22. data/lib/ey-core/models/auto_scaling_alarm.rb +54 -0
  23. data/lib/ey-core/models/auto_scaling_group.rb +26 -0
  24. data/lib/ey-core/models/base_auto_scaling_policy.rb +61 -0
  25. data/lib/ey-core/models/environment.rb +53 -47
  26. data/lib/ey-core/models/environment_variable.rb +29 -0
  27. data/lib/ey-core/models/request.rb +4 -0
  28. data/lib/ey-core/models/simple_auto_scaling_policy.rb +24 -0
  29. data/lib/ey-core/models/step_auto_scaling_policy.rb +24 -0
  30. data/lib/ey-core/models/target_auto_scaling_policy.rb +24 -0
  31. data/lib/ey-core/requests/create_account.rb +5 -0
  32. data/lib/ey-core/requests/create_address.rb +1 -0
  33. data/lib/ey-core/requests/create_application.rb +8 -7
  34. data/lib/ey-core/requests/create_auto_scaling_alarm.rb +69 -0
  35. data/lib/ey-core/requests/create_auto_scaling_policy.rb +68 -0
  36. data/lib/ey-core/requests/create_environment.rb +2 -1
  37. data/lib/ey-core/requests/create_environment_variable.rb +39 -0
  38. data/lib/ey-core/requests/create_user.rb +8 -6
  39. data/lib/ey-core/requests/destroy_auto_scaling_alarm.rb +49 -0
  40. data/lib/ey-core/requests/destroy_auto_scaling_policy.rb +49 -0
  41. data/lib/ey-core/requests/get_applications.rb +1 -1
  42. data/lib/ey-core/requests/get_auto_scaling_alarm.rb +27 -0
  43. data/lib/ey-core/requests/get_auto_scaling_alarms.rb +34 -0
  44. data/lib/ey-core/requests/get_auto_scaling_policies.rb +46 -0
  45. data/lib/ey-core/requests/get_auto_scaling_policy.rb +27 -0
  46. data/lib/ey-core/requests/get_environment_variable.rb +19 -0
  47. data/lib/ey-core/requests/get_environment_variables.rb +29 -0
  48. data/lib/ey-core/requests/get_environments.rb +1 -1
  49. data/lib/ey-core/requests/update_auto_scaling_alarm.rb +45 -0
  50. data/lib/ey-core/requests/update_auto_scaling_policy.rb +46 -0
  51. data/lib/ey-core/requests/update_environment_variable.rb +25 -0
  52. data/lib/ey-core/test_helpers.rb +2 -0
  53. data/lib/ey-core/test_helpers/auto_scaling_helpers.rb +35 -0
  54. data/lib/ey-core/version.rb +1 -1
  55. data/spec/addresses_spec.rb +2 -1
  56. data/spec/auto_scaling_alarms_spec.rb +40 -0
  57. data/spec/auto_scaling_policies_spec.rb +94 -0
  58. data/spec/spec_helper.rb +7 -0
  59. metadata +37 -2
@@ -14,7 +14,9 @@ class Ey::Core::Client < Cistern::Service
14
14
  collection :application_archives
15
15
  collection :application_deployments
16
16
  collection :applications
17
+ collection :auto_scaling_alarms
17
18
  collection :auto_scaling_groups
19
+ collection :auto_scaling_policies
18
20
  collection :backup_files
19
21
  collection :blueprints
20
22
  collection :components
@@ -29,6 +31,7 @@ class Ey::Core::Client < Cistern::Service
29
31
  collection :deployments
30
32
  collection :environment_plan_usages
31
33
  collection :environments
34
+ collection :environment_variables
32
35
  collection :features
33
36
  collection :firewall_rules
34
37
  collection :firewalls
@@ -71,8 +74,10 @@ class Ey::Core::Client < Cistern::Service
71
74
  model :application
72
75
  model :application_archive
73
76
  model :application_deployment
77
+ model :auto_scaling_alarm
74
78
  model :auto_scaling_group
75
79
  model :backup_file
80
+ model :base_auto_scaling_policy
76
81
  model :billing
77
82
  model :blueprint
78
83
  model :component
@@ -87,6 +92,7 @@ class Ey::Core::Client < Cistern::Service
87
92
  model :deployment
88
93
  model :environment
89
94
  model :environment_plan_usage
95
+ model :environment_variable
90
96
  model :feature
91
97
  model :firewall
92
98
  model :firewall_rule
@@ -109,10 +115,13 @@ class Ey::Core::Client < Cistern::Service
109
115
  model :server_event
110
116
  model :server_usage
111
117
  model :service
118
+ model :simple_auto_scaling_policy
112
119
  model :ssl_certificate
120
+ model :step_auto_scaling_policy
113
121
  model :storage
114
122
  model :storage_user
115
123
  model :support_trial
124
+ model :target_auto_scaling_policy
116
125
  model :task
117
126
  model :token
118
127
  model :untracked_address
@@ -136,12 +145,14 @@ class Ey::Core::Client < Cistern::Service
136
145
  request :create_alert
137
146
  request :create_application
138
147
  request :create_application_archive
148
+ request :create_auto_scaling_alarm
139
149
  request :create_auto_scaling_group
140
150
  request :create_backup_file
141
151
  request :create_database_server
142
152
  request :create_database_service
143
153
  request :create_database_service_snapshot
144
154
  request :create_environment
155
+ request :create_environment_variable
145
156
  request :create_firewall
146
157
  request :create_firewall_rule
147
158
  request :create_keypair
@@ -154,6 +165,7 @@ class Ey::Core::Client < Cistern::Service
154
165
  request :create_password_reset
155
166
  request :create_provider
156
167
  request :create_server
168
+ request :create_auto_scaling_policy
157
169
  request :create_ssl_certificate
158
170
  request :create_storage
159
171
  request :create_storage_user
@@ -165,6 +177,7 @@ class Ey::Core::Client < Cistern::Service
165
177
  request :deploy_environment_application
166
178
  request :deprovision_environment
167
179
  request :destroy_addon
180
+ request :destroy_auto_scaling_alarm
168
181
  request :destroy_auto_scaling_group
169
182
  request :destroy_blueprint
170
183
  request :destroy_database_server
@@ -177,6 +190,7 @@ class Ey::Core::Client < Cistern::Service
177
190
  request :destroy_logical_database
178
191
  request :destroy_provider
179
192
  request :destroy_server
193
+ request :destroy_auto_scaling_policy
180
194
  request :destroy_ssl_certificate
181
195
  request :destroy_storage
182
196
  request :destroy_storage_user
@@ -208,6 +222,8 @@ class Ey::Core::Client < Cistern::Service
208
222
  request :get_application_deployment
209
223
  request :get_application_deployments
210
224
  request :get_applications
225
+ request :get_auto_scaling_alarm
226
+ request :get_auto_scaling_alarms
211
227
  request :get_auto_scaling_group
212
228
  request :get_auto_scaling_groups
213
229
  request :get_backup_file
@@ -236,6 +252,8 @@ class Ey::Core::Client < Cistern::Service
236
252
  request :get_environment_database_services
237
253
  request :get_environment_logical_databases
238
254
  request :get_environment_plan_usages
255
+ request :get_environment_variable
256
+ request :get_environment_variables
239
257
  request :get_environments
240
258
  request :get_feature
241
259
  request :get_features
@@ -278,6 +296,8 @@ class Ey::Core::Client < Cistern::Service
278
296
  request :get_server_events
279
297
  request :get_server_usages
280
298
  request :get_servers
299
+ request :get_auto_scaling_policy
300
+ request :get_auto_scaling_policies
281
301
  request :get_ssl_certificate
282
302
  request :get_ssl_certificates
283
303
  request :get_storage
@@ -312,10 +332,13 @@ class Ey::Core::Client < Cistern::Service
312
332
  request :update_address
313
333
  request :update_alert
314
334
  request :update_application_archive
335
+ request :update_auto_scaling_alarm
315
336
  request :update_auto_scaling_group
337
+ request :update_auto_scaling_policy
316
338
  request :update_billing
317
339
  request :update_blueprint
318
340
  request :update_environment
341
+ request :update_environment_variable
319
342
  request :update_membership
320
343
  request :update_provider_location
321
344
  request :update_server
@@ -116,7 +116,9 @@ class Ey::Core::Client::Mock
116
116
  :application_archives => {},
117
117
  :application_deployments => {},
118
118
  :applications => {},
119
+ :auto_scaling_alarms => {},
119
120
  :auto_scaling_groups => {},
121
+ :auto_scaling_policies => {},
120
122
  :backup_files => {},
121
123
  :backups => {},
122
124
  :billing => {},
@@ -137,6 +139,7 @@ class Ey::Core::Client::Mock
137
139
  :deployments => {},
138
140
  :environment_plan_usages => Hash.new { |h1,k1| h1[k1] = {} },
139
141
  :environments => {},
142
+ :environment_variables => {},
140
143
  :features => {},
141
144
  :firewall_rules => {},
142
145
  :firewalls => {},
@@ -0,0 +1,8 @@
1
+ class Ey::Core::Client::AutoScalingAlarms < Ey::Core::Collection
2
+ model Ey::Core::Client::AutoScalingAlarm
3
+
4
+ self.model_root = "auto_scaling_alarm"
5
+ self.model_request = :get_auto_scaling_alarm
6
+ self.collection_root = "auto_scaling_alarms"
7
+ self.collection_request = :get_auto_scaling_alarms
8
+ end
@@ -0,0 +1,33 @@
1
+ class Ey::Core::Client::AutoScalingPolicies < Ey::Core::Collection
2
+ model Ey::Core::Client::BaseAutoScalingPolicy
3
+
4
+ MODELS_TO_TYPE = {
5
+ "simple" => Ey::Core::Client::SimpleAutoScalingPolicy,
6
+ "step" => Ey::Core::Client::StepAutoScalingPolicy,
7
+ "target" => Ey::Core::Client::TargetAutoScalingPolicy
8
+ }.freeze
9
+
10
+ self.model_root = "auto_scaling_policy"
11
+ self.model_request = :get_auto_scaling_policy
12
+ self.collection_root = "auto_scaling_policies"
13
+ self.collection_request = :get_auto_scaling_policies
14
+
15
+ def new(attributes = {})
16
+ unless attributes.is_a?(::Hash)
17
+ raise(ArgumentError.new("Initialization parameters must be an attributes hash, got #{attributes.class} #{attributes.inspect}"))
18
+ end
19
+
20
+ params = Cistern::Hash.stringify_keys(attributes)
21
+ type = params["type"] ||= "simple"
22
+ model = MODELS_TO_TYPE[type]
23
+ unless model
24
+ raise(ArgumentError.new("Unrecognized policy type #{type}. Allowed types are: #{MODELS_TO_TYPE.keys.join(', ')}"))
25
+ end
26
+ model.new(
27
+ {
28
+ :collection => self,
29
+ :connection => connection,
30
+ }.merge(params)
31
+ )
32
+ end
33
+ end
@@ -0,0 +1,8 @@
1
+ class Ey::Core::Client::EnvironmentVariables < Ey::Core::Collection
2
+ model Ey::Core::Client::EnvironmentVariable
3
+
4
+ self.model_root = "environment_variable"
5
+ self.model_request = :get_environment_variable
6
+ self.collection_root = "environment_variables"
7
+ self.collection_request = :get_environment_variables
8
+ end
@@ -7,6 +7,7 @@ class Ey::Core::Client::Address < Ey::Core::Model
7
7
  attribute :ip_address
8
8
  attribute :provisioned_id
9
9
  attribute :location
10
+ attribute :scope
10
11
  attribute :disappeared_at, type: :time
11
12
 
12
13
  has_one :provider
@@ -37,6 +38,7 @@ class Ey::Core::Client::Address < Ey::Core::Model
37
38
  "provider" => self.provider_id,
38
39
  "address" => {
39
40
  "location" => self.location,
41
+ "scope" => self.scope,
40
42
  },
41
43
  }
42
44
 
@@ -12,6 +12,7 @@ class Ey::Core::Client::Application < Ey::Core::Model
12
12
 
13
13
  has_many :archives, key: :application_archives
14
14
  has_many :keypairs
15
+ has_many :environment_variables
15
16
 
16
17
  def save!
17
18
  params = {
@@ -0,0 +1,54 @@
1
+ class Ey::Core::Client::AutoScalingAlarm < Ey::Core::Model
2
+ extend Ey::Core::Associations
3
+
4
+ identity :id
5
+
6
+ attribute :deleted_at, type: :time
7
+ attribute :created_at, type: :time
8
+ attribute :updated_at, type: :time
9
+ attribute :auto_scaling_policy_id, aliases: "auto_scaling_policy", squash: ["id"]
10
+ attribute :name
11
+ attribute :aggregation_type
12
+ attribute :metric_type
13
+ attribute :operand
14
+ attribute :trigger_value, type: :float
15
+ attribute :number_of_periods, type: :integer
16
+ attribute :period_length, type: :integer
17
+ attribute :provisioned_id
18
+
19
+ has_one :auto_scaling_policy
20
+
21
+ def save!
22
+ requires :auto_scaling_policy_id, :trigger_value, :period_length
23
+ params = {
24
+ "auto_scaling_alarm" => {
25
+ "name" => name,
26
+ "trigger_value" => trigger_value,
27
+ "aggregation_type" => aggregation_type,
28
+ "metric_type" => metric_type,
29
+ "operand" => operand,
30
+ "period_length" => period_length,
31
+ "number_of_periods" => number_of_periods
32
+ },
33
+ "auto_scaling_policy_id" => auto_scaling_policy_id
34
+ }
35
+
36
+ if new_record?
37
+ requires :name
38
+ request_attributes = connection.create_auto_scaling_alarm(params).body["request"]
39
+ connection.requests.new(request_attributes)
40
+ else
41
+ requires :identity
42
+ params.merge!("id" => identity)
43
+ connection.requests.new(connection.update_auto_scaling_alarm(params).body["request"])
44
+ end
45
+ end
46
+
47
+ def destroy!
48
+ requires :identity
49
+
50
+ connection.requests.new(
51
+ connection.destroy_auto_scaling_alarm("id" => identity).body["request"]
52
+ )
53
+ end
54
+ end
@@ -10,6 +10,8 @@ class Ey::Core::Client::AutoScalingGroup < Ey::Core::Model
10
10
  attribute :minimum_size
11
11
  attribute :maximum_size
12
12
  attribute :desired_capacity
13
+ attribute :default_cooldown
14
+ attribute :grace_period
13
15
 
14
16
  has_one :environment
15
17
 
@@ -46,4 +48,28 @@ class Ey::Core::Client::AutoScalingGroup < Ey::Core::Model
46
48
  connection.requests.new(connection.update_auto_scaling_group(params).body["request"])
47
49
  end
48
50
  end
51
+
52
+ def simple_auto_scaling_policies
53
+ auto_scaling_policies("simple")
54
+ end
55
+
56
+ def step_auto_scaling_policies
57
+ auto_scaling_policies("step")
58
+ end
59
+
60
+ def target_auto_scaling_policies
61
+ auto_scaling_policies("target")
62
+ end
63
+
64
+ private
65
+
66
+ def auto_scaling_policies(types = nil)
67
+ requires :identity
68
+ data = connection.get_auto_scaling_policies(
69
+ "auto_scaling_group" => identity,
70
+ "types" => [*types]
71
+ ).body["auto_scaling_policies"]
72
+
73
+ connection.auto_scaling_policies.load(data)
74
+ end
49
75
  end
@@ -0,0 +1,61 @@
1
+ class Ey::Core::Client::BaseAutoScalingPolicy < Ey::Core::Model
2
+ extend Ey::Core::Associations
3
+
4
+ identity :id, type: :integer
5
+
6
+ attribute :provisioned_id
7
+ attribute :provisioner_id
8
+ attribute :type
9
+ attribute :name
10
+ attribute :configuration
11
+ attribute :auto_scaling_group_id
12
+
13
+ has_one :auto_scaling_group
14
+
15
+ def save!
16
+ requires :auto_scaling_group_id, :type
17
+ params = {
18
+ "url" => self.collection.url,
19
+ "auto_scaling_policy" => {
20
+ "name" => self.name
21
+ }.merge(policy_params),
22
+ "auto_scaling_group_id" => self.auto_scaling_group_id
23
+ }
24
+
25
+ if new_record?
26
+ policy_requires
27
+ requires :name
28
+ connection.requests.new(connection.create_auto_scaling_policy(params).body["request"])
29
+ else
30
+ requires :identity
31
+ params.merge("id" => identity)
32
+ connection.requests.new(connection.update_auto_scaling_policy(params).body["request"])
33
+ end
34
+ end
35
+
36
+ def destroy!
37
+ connection.requests.new(
38
+ self.connection.destroy_auto_scaling_policy("id" => self.id).body["request"]
39
+ )
40
+ end
41
+
42
+ def alarm
43
+ requires :identity
44
+
45
+ data = self.connection.get_auto_scaling_alarms(
46
+ "auto_scaling_policy_id" => identity
47
+ ).body["auto_scaling_alarms"]
48
+
49
+ self.connection.auto_scaling_alarms.load(data).first
50
+ end
51
+
52
+ private
53
+
54
+ def policy_params
55
+ raise NotImplementedError
56
+ end
57
+
58
+ def policy_requires
59
+ raise NotImplementedError
60
+ end
61
+ end
@@ -33,6 +33,7 @@ class Ey::Core::Client::Environment < Ey::Core::Model
33
33
  has_many :applications
34
34
  has_many :logical_databases
35
35
  has_many :deployments
36
+ has_many :environment_variables
36
37
 
37
38
  attr_accessor :application_id
38
39
 
@@ -129,6 +130,54 @@ class Ey::Core::Client::Environment < Ey::Core::Model
129
130
 
130
131
  def boot(options={})
131
132
  options = Cistern::Hash.stringify_keys(options)
133
+ connection.requests.new(self.connection.boot_environment(boot_params(options)).body["request"])
134
+ end
135
+
136
+ def unassign!
137
+ requires :id
138
+ merge_attributes(self.connection.unassign_environment("id" => self.id).body["environment"])
139
+ end
140
+
141
+ def save!
142
+ if new_record?
143
+ requires :application_id, :account_id, :region
144
+
145
+ params = {
146
+ "url" => self.collection.url,
147
+ "account" => self.account_id,
148
+ "environment" => {
149
+ "name" => self.name,
150
+ "application_id" => self.application_id,
151
+ "region" => self.region,
152
+ "stack_name" => self.stack_name,
153
+ "database_stack" => self.database_stack,
154
+ "release_label" => self.release_label,
155
+ "language" => self.language,
156
+ "database_backup_limit" => self.database_backup_limit,
157
+ "encrypted_ebs_for_everything" => self.encrypted_ebs_for_everything,
158
+ },
159
+ }
160
+
161
+ params["environment"].merge!("database_service" => self.database_service.id) if self.database_service
162
+
163
+ merge_attributes(self.connection.create_environment(params).body["environment"])
164
+ else
165
+ requires :identity
166
+ attributes = Cistern::Hash.slice(Cistern::Hash.stringify_keys(self.attributes), "nane", "release_label")
167
+ connection.update_environment(
168
+ "id" => self.identity,
169
+ "environment" => attributes,
170
+ )
171
+ end
172
+ end
173
+
174
+ private
175
+
176
+ def boot_params(options)
177
+ params = {
178
+ "cluster_configuration" => {}
179
+ }
180
+
132
181
  if options["blueprint_id"]
133
182
  params = {
134
183
  "cluster_configuration" => {
@@ -139,12 +188,12 @@ class Ey::Core::Client::Environment < Ey::Core::Model
139
188
  if ip_id = options["ip_id"]
140
189
  params["cluster_configuration"]["configuration"]["ip_id"] = ip_id
141
190
  end
142
-
143
- self.connection.requests.new(self.connection.boot_environment(params.merge("id" => self.id)).body["request"])
144
191
  else
145
192
  raise "configuration is a required key" unless options["configuration"]
146
193
  raise "configuration['type'] is required" unless options["configuration"]["type"]
194
+ end
147
195
 
196
+ if options['configuration']
148
197
  missing_keys = []
149
198
 
150
199
  configuration = options["configuration"]
@@ -192,51 +241,8 @@ class Ey::Core::Client::Environment < Ey::Core::Model
192
241
  raise "Invalid configuration - The following keys are missing from the configuration:\n#{missing_keys.join(",\n")}"
193
242
  end
194
243
 
195
- params = {
196
- "cluster_configuration" => {
197
- "configuration" => configuration
198
- }
199
- }
200
-
201
- connection.requests.new(self.connection.boot_environment(params.merge("id" => self.id)).body["request"])
202
- end
203
- end
204
-
205
- def unassign!
206
- requires :id
207
- merge_attributes(self.connection.unassign_environment("id" => self.id).body["environment"])
208
- end
209
-
210
- def save!
211
- if new_record?
212
- requires :application_id, :account_id, :region
213
-
214
- params = {
215
- "url" => self.collection.url,
216
- "account" => self.account_id,
217
- "environment" => {
218
- "name" => self.name,
219
- "application_id" => self.application_id,
220
- "region" => self.region,
221
- "stack_name" => self.stack_name,
222
- "database_stack" => self.database_stack,
223
- "release_label" => self.release_label,
224
- "language" => self.language,
225
- "database_backup_limit" => self.database_backup_limit,
226
- "encrypted_ebs_for_everything" => self.encrypted_ebs_for_everything,
227
- },
228
- }
229
-
230
- params["environment"].merge!("database_service" => self.database_service.id) if self.database_service
231
-
232
- merge_attributes(self.connection.create_environment(params).body["environment"])
233
- else
234
- requires :identity
235
- attributes = Cistern::Hash.slice(Cistern::Hash.stringify_keys(self.attributes), "nane", "release_label")
236
- connection.update_environment(
237
- "id" => self.identity,
238
- "environment" => attributes,
239
- )
244
+ params["cluster_configuration"]["configuration"] = configuration
240
245
  end
246
+ params.merge("id" => self.id)
241
247
  end
242
248
  end