convection 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 960beb9e1cd6a6aa3ee610fcb04bd5a79df77952
4
- data.tar.gz: 96d9893838cd569601e1c4cbe49ff773b1f60002
3
+ metadata.gz: 67115b7f8c9dafb09f93733a248cfa00ffdd2564
4
+ data.tar.gz: e2d9813955f988796f198c68b3047ea812a1b172
5
5
  SHA512:
6
- metadata.gz: 751c1d98cbb197e21d03f20345eb94933a2f5464a0dc2eb20ea91ea0121e4a627aa519afe755bb3bea9528c8aaf355cfc853d8159cde896b2e78f0336580ea70
7
- data.tar.gz: 4b8fdc713d35a2b00e7080e02603dccaf5df472d90a6f6438762333d7d7eb467114d2613ecabc4c713cd2ef1cfb97ba5ccc7a7124fd32fd4301244c904ddaf47
6
+ metadata.gz: 7c2ee15ff3d16828ab27635ba94fb5dc286092414d10340330daae7f01ddb0d1735cb6f797a615e0e25086b1d3cbf3ab1591be3ebf8f098226a428f2b60b613b
7
+ data.tar.gz: b3e3c5b978aabfc409e1e619c20e539dce2dbb369c0b9e734c094717ca67f299856d1191045c65012e2bd35f681cbeec7e1bbfa74bb2ada7986274ee4be2cf9b
data/bin/convection CHANGED
@@ -2,6 +2,8 @@
2
2
  require 'thor'
3
3
  require_relative '../lib/convection/control/cloud'
4
4
  require 'thread'
5
+ require 'yaml'
6
+
5
7
  module Convection
6
8
  ##
7
9
  # Convection CLI
@@ -97,6 +99,17 @@ module Convection
97
99
  @cloud.stacks[stack].validate
98
100
  end
99
101
 
102
+ desc 'describe-resources', 'Describe resources for a stack'
103
+ option :cloudfile, :type => :string, :default => 'Cloudfile'
104
+ option :stack, :desc => 'The stack to be described', :required => true
105
+ option :type, :desc => 'An optional filter on the types of resources to be described', default: '*'
106
+ option :properties, :type => :array, :desc => 'A space-separated list of properties to include in the output', default: %w(*)
107
+ option :format, :type => :string, :default => 'json', :enum => %w(json yaml)
108
+ def describe_resources
109
+ init_cloud
110
+ describe_stack_resources(options[:stack], options[:format], options[:properties], options[:type])
111
+ end
112
+
100
113
  no_commands do
101
114
  attr_accessor :last_event
102
115
 
@@ -178,6 +191,35 @@ module Convection
178
191
  end
179
192
  end
180
193
 
194
+ def describe_stack_resources(stack, format, properties_to_include, type)
195
+ stack_template = @cloud.stacks[stack].current_template
196
+ raise "No template defined for [#{stack}] stack" if stack_template.nil?
197
+
198
+ stack_resources = stack_template['Resources']
199
+ stack_resources.select! { |_name, attrs| attrs['Type'] == type } unless type == '*'
200
+
201
+ described_resources = {}
202
+
203
+ stack_resources.each do |name, attrs|
204
+ # Only include the resource type if we asked for all resource types
205
+ attrs.reject! { |attr| attr == 'Type' } unless type == '*'
206
+
207
+ # Only include those properties that were explicitly requested
208
+ unless properties_to_include.size == 1 && properties_to_include[0] == '*'
209
+ attrs['Properties'].select! { |prop| properties_to_include.include? prop }
210
+ end
211
+
212
+ described_resources[name] = attrs
213
+ end
214
+
215
+ case format
216
+ when 'json'
217
+ puts JSON.pretty_generate(described_resources)
218
+ when 'yaml'
219
+ puts described_resources.to_yaml
220
+ end
221
+ end
222
+
181
223
  def emit_events(event, *errors, region: nil)
182
224
  if event.is_a? Model::Event
183
225
  if options[:'very-verbose'] || event.name == :error
@@ -197,7 +239,8 @@ module Convection
197
239
  end
198
240
 
199
241
  errors.each do |error|
200
- say "* #{ error.message }"
242
+ error = RuntimeError.new(error) if error.is_a?(String)
243
+ say "* #{ error_message }"
201
244
  error.backtrace.each { |trace| say " #{ trace }" }
202
245
  end
203
246
  end
@@ -22,6 +22,8 @@ module Convection
22
22
  attr_reader :status
23
23
  alias_method :exist?, :exist
24
24
 
25
+ attr_reader :current_template
26
+
25
27
  attr_reader :attributes
26
28
  attr_reader :errors
27
29
  attr_reader :options
@@ -38,7 +38,7 @@ module Convection::Control
38
38
  it 'is executed on Stack#apply' do
39
39
  subject.apply
40
40
 
41
- expect(task.availability_zones).to include('eu-central-1')
41
+ expect(task.availability_zones).to include(a_string_starting_with('eu-central-1'))
42
42
  end
43
43
 
44
44
  it 'is deregistered after Stack#apply is called' do
@@ -38,7 +38,7 @@ module Convection::Control
38
38
  it 'is executed on Stack#delete' do
39
39
  subject.delete
40
40
 
41
- expect(task.availability_zones).to include('eu-central-1')
41
+ expect(task.availability_zones).to include(a_string_starting_with('eu-central-1'))
42
42
  end
43
43
 
44
44
  it 'is deregistered after Stack#delete is called' do
@@ -41,7 +41,7 @@ module Convection::Control
41
41
  it 'is executed on Stack#apply' do
42
42
  subject.apply
43
43
 
44
- expect(task.availability_zones).to include('eu-central-1')
44
+ expect(task.availability_zones).to include(a_string_starting_with('eu-central-1'))
45
45
  end
46
46
 
47
47
  it 'is deregistered after Stack#apply is called' do
@@ -39,7 +39,7 @@ module Convection::Control
39
39
  it 'is executed on Stack#apply' do
40
40
  subject.apply
41
41
 
42
- expect(task.availability_zones).to include('eu-central-1')
42
+ expect(task.availability_zones).to include(a_string_starting_with('eu-central-1'))
43
43
  end
44
44
 
45
45
  it 'is deregistered after Stack#apply is called' do
@@ -38,7 +38,7 @@ module Convection::Control
38
38
  it 'is executed on Stack#delete' do
39
39
  subject.delete
40
40
 
41
- expect(task.availability_zones).to include('eu-central-1')
41
+ expect(task.availability_zones).to include(a_string_starting_with('eu-central-1'))
42
42
  end
43
43
 
44
44
  it 'is deregistered after Stack#delete is called' do
@@ -42,7 +42,7 @@ module Convection::Control
42
42
  it 'is executed on Stack#apply' do
43
43
  subject.apply
44
44
 
45
- expect(task.availability_zones).to include('eu-central-1')
45
+ expect(task.availability_zones).to include(a_string_starting_with('eu-central-1'))
46
46
  end
47
47
 
48
48
  it 'is deregistered after Stack#apply is called' do
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ module Convection::Control
4
+ describe Stack do
5
+ let(:template) do
6
+ Convection.template do
7
+ description 'EC2 VPC Test Template'
8
+
9
+ ec2_vpc 'TargetVPC' do
10
+ network '10.0.0.0'
11
+ subnet_length 24
12
+ enable_dns
13
+ end
14
+ end
15
+ end
16
+
17
+ describe 'stack' do
18
+ include_context 'with a mock CloudFormation client'
19
+ include_context 'with a mock EC2 client'
20
+
21
+ before do
22
+ allow(Aws::CloudFormation::Client).to receive(:new).and_return(cf_client)
23
+ allow(Aws::EC2::Client).to receive(:new).and_return(ec2_client)
24
+ end
25
+ subject do
26
+ Convection::Control::Stack.new('EC2 VPC Test Stack', template)
27
+ end
28
+
29
+ it 'availability_zones are stored in an array' do
30
+ expect(subject.availability_zones).to be_a(Array)
31
+ end
32
+
33
+ it 'availability_zones are in the same region' do
34
+ azs = subject.availability_zones
35
+ azs.map! { |r| r.match(/(\w{2}-\w+-\d)/)[1] }
36
+ azs.uniq!
37
+ expect(azs.size).to be(1)
38
+ end
39
+ end
40
+ end
41
+ end
@@ -1,6 +1,6 @@
1
1
  RSpec.shared_context 'with a mock EC2 client' do
2
2
  let(:ec2_availability_zone_description) do
3
- zones = %w(eu-central-1 eu-west-1).map do |name|
3
+ zones = %w(eu-central-1a eu-central-1b).map do |name|
4
4
  double("availability zone (#{name})", zone_name: name)
5
5
  end
6
6
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: convection
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Manero
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-03 00:00:00.000000000 Z
11
+ date: 2017-01-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk
@@ -273,6 +273,7 @@ files:
273
273
  - spec/convection/control/stack/before_create_tasks_spec.rb
274
274
  - spec/convection/control/stack/before_delete_tasks_spec.rb
275
275
  - spec/convection/control/stack/before_update_tasks_spec.rb
276
+ - spec/convection/control/stack_spec.rb
276
277
  - spec/convection/dsl/intrinsic_functions_spec.rb
277
278
  - spec/convection/model/attributes_spec.rb
278
279
  - spec/convection/model/template/condition_spec.rb
@@ -340,6 +341,7 @@ test_files:
340
341
  - spec/convection/control/stack/before_create_tasks_spec.rb
341
342
  - spec/convection/control/stack/before_delete_tasks_spec.rb
342
343
  - spec/convection/control/stack/before_update_tasks_spec.rb
344
+ - spec/convection/control/stack_spec.rb
343
345
  - spec/convection/dsl/intrinsic_functions_spec.rb
344
346
  - spec/convection/model/attributes_spec.rb
345
347
  - spec/convection/model/template/condition_spec.rb