kumogata 0.1.1 → 0.1.2

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: 947bc579f201dfda38abb8996854b92fd80e558a
4
- data.tar.gz: 97c93892827122b20a3cdb739842aeab9aef6934
3
+ metadata.gz: 58505fd69f4767540e2830de48d42a07605781d9
4
+ data.tar.gz: dbed8f02373d8f06f284009b9c3e0b4126b4bf10
5
5
  SHA512:
6
- metadata.gz: 3d791a48469552c5a5bde3dcf7cdb738ec86e484ae65cf713a81678e4e1a5cf2325c78ec678956da57550c3cf9ee2c4ad3e0391adaf2558f70ab13052b43b1cf
7
- data.tar.gz: b2e53f42d81fded35dcb8b426ab93b725aa9059d22feba4789acc088062e42e031cbfb9c6713e0916ae58f05f99522648d942fb6c7b42717f2fb5c11f58c3a30
6
+ metadata.gz: db73cef84452369b64bc6284f65672120b4f62720c6ac9abcb92cf6bfc26dfe5709035a11aaeca72a7cd6788d09aa1cea2b30ea710f63390fde352996543b0d6
7
+ data.tar.gz: e40c5f04d96bafbf34f721a4f46f116ac65786fdc4f7c308d330dbb85e826592ea3929d60720311716cacfef9ab486b0a4ed09b64859ae9af2822016173e647e
data/README.md CHANGED
@@ -2,8 +2,8 @@
2
2
 
3
3
  Kumogata is a tool for AWS CroudFormation.
4
4
 
5
- [![Gem Version](https://badge.fury.io/rb/kumogata.png?201403022336)](http://badge.fury.io/rb/kumogata)
6
- [![Build Status](https://drone.io/github.com/winebarrel/kumogata/status.png?201403022336)](https://drone.io/github.com/winebarrel/kumogata/latest)
5
+ [![Gem Version](https://badge.fury.io/rb/kumogata.png?201403030250)](http://badge.fury.io/rb/kumogata)
6
+ [![Build Status](https://drone.io/github.com/winebarrel/kumogata/status.png?201403030250)](https://drone.io/github.com/winebarrel/kumogata/latest)
7
7
 
8
8
  It can define a template in Ruby DSL, such as:
9
9
 
@@ -58,6 +58,7 @@ Commands:
58
58
  update PATH_OR_URL STACK_NAME Update a stack as specified in the template
59
59
  delete STACK_NAME Delete a specified stack
60
60
  list [STACK_NAME] List summary information for stacks
61
+ export STACK_NAME Export a template from a specified stack
61
62
 
62
63
  Options:
63
64
  -k, --access-key ACCESS_KEY
@@ -27,13 +27,17 @@ class Kumogata::ArgumentParser
27
27
  :arguments => [:path_or_url, :stack_name]
28
28
  },
29
29
  :delete => {
30
- :description => 'Deletes a specified stack',
30
+ :description => 'Delete a specified stack',
31
31
  :arguments => [:stack_name]
32
32
  },
33
33
  :list => {
34
34
  :description => 'List summary information for stacks',
35
35
  :arguments => [:stack_name?]
36
36
  },
37
+ :export => {
38
+ :description => 'Export a template from a specified stack',
39
+ :arguments => [:stack_name]
40
+ },
37
41
  }
38
42
 
39
43
  class << self
@@ -57,6 +57,11 @@ class Kumogata::Client
57
57
  JSON.pretty_generate(stacks)
58
58
  end
59
59
 
60
+ def export(stack_name = nil)
61
+ template = export_template(stack_name)
62
+ devaluate_template(template).chomp
63
+ end
64
+
60
65
  private ###########################################################
61
66
 
62
67
  def open_template(path_or_url)
@@ -146,22 +151,6 @@ class Kumogata::Client
146
151
  end
147
152
  end
148
153
 
149
- def describe_stacks(stack_name)
150
- AWS.memoize do
151
- stacks = @cloud_formation.stacks
152
- stacks = stacks.select {|i| i.name == stack_name } if stack_name
153
-
154
- stacks.map do |stack|
155
- {
156
- 'StackName' => stack.name,
157
- 'CreationTime' => stack.creation_time,
158
- 'StackStatus' => stack.status,
159
- 'Description' => stack.description,
160
- }
161
- end
162
- end
163
- end
164
-
165
154
  def create_stack(template, stack_name)
166
155
  stack_name = stack_name || 'kumogata-' + UUIDTools::UUID.timestamp_create
167
156
 
@@ -229,6 +218,28 @@ class Kumogata::Client
229
218
  end
230
219
  end
231
220
 
221
+ def describe_stacks(stack_name)
222
+ AWS.memoize do
223
+ stacks = @cloud_formation.stacks
224
+ stacks = stacks.select {|i| i.name == stack_name } if stack_name
225
+
226
+ stacks.map do |stack|
227
+ {
228
+ 'StackName' => stack.name,
229
+ 'CreationTime' => stack.creation_time,
230
+ 'StackStatus' => stack.status,
231
+ 'Description' => stack.description,
232
+ }
233
+ end
234
+ end
235
+ end
236
+
237
+ def export_template(stack_name)
238
+ stack = @cloud_formation.stacks[stack_name]
239
+ stack.status
240
+ JSON.parse(stack.template)
241
+ end
242
+
232
243
  def while_in_progress(stack, complete_status)
233
244
  while stack.status =~ /_IN_PROGRESS\Z/
234
245
  print '.'.intense_black unless @options.debug?
@@ -1,3 +1,3 @@
1
1
  module Kumogata
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
@@ -22,7 +22,6 @@ end
22
22
 
23
23
  run_client(:create, :template => template) do |client, cf|
24
24
  json = eval_template(template, :update_deletion_policy => true).to_json
25
- stacks = double('status')
26
25
 
27
26
  output = make_double('output') do |obj|
28
27
  obj.should_receive(:key) { 'AZ' }
@@ -89,7 +88,6 @@ end
89
88
 
90
89
  run_client(:create, :template => template, :options => {:parameters => ['InstanceType=m1.large']}) do |client, cf|
91
90
  json = eval_template(template, :update_deletion_policy => true).to_json
92
- stacks = double('stacks')
93
91
 
94
92
  output = make_double('output') do |obj|
95
93
  obj.should_receive(:key) { 'AZ' }
@@ -148,7 +146,6 @@ end
148
146
 
149
147
  run_client(:create, :arguments => ['MyStack'], :template => template) do |client, cf|
150
148
  json = eval_template(template).to_json
151
- stacks = double('status')
152
149
 
153
150
  output = make_double('output') do |obj|
154
151
  obj.should_receive(:key) { 'AZ' }
@@ -1,8 +1,6 @@
1
1
  describe 'Kumogata::Client#delete' do
2
2
  it 'update a stack from Ruby template' do
3
3
  run_client(:delete, :arguments => ['MyStack'], :options => {:force => true}) do |client, cf|
4
- stacks = double('status')
5
-
6
4
  stack = make_double('stack') do |obj|
7
5
  obj.should_receive(:delete).with(no_args())
8
6
  obj.should_receive(:status).and_return(
@@ -0,0 +1,59 @@
1
+ describe 'Kumogata::Client#export' do
2
+ it 'export a template' do
3
+ json = <<-EOS
4
+ {
5
+ "Resources": {
6
+ "myEC2Instance": {
7
+ "Type": "AWS::EC2::Instance",
8
+ "Properties": {
9
+ "ImageId": "ami-XXXXXXXX",
10
+ "InstanceType": "t1.micro"
11
+ }
12
+ }
13
+ },
14
+ "Outputs": {
15
+ "AZ": {
16
+ "Value": {
17
+ "Fn::GetAtt": [
18
+ "myEC2Instance",
19
+ "AvailabilityZone"
20
+ ]
21
+ }
22
+ }
23
+ }
24
+ }
25
+ EOS
26
+
27
+ template = run_client(:export, :arguments => ['MyStack']) do |client, cf|
28
+ stack = make_double('stack') do |obj|
29
+ obj.should_receive(:status) { 'CREATE_COMPLETE' }
30
+ obj.should_receive(:template) { json }
31
+ end
32
+
33
+ stacks = make_double('stacks') do |obj|
34
+ obj.should_receive(:[]).with('MyStack') { stack }
35
+ end
36
+
37
+ cf.should_receive(:stacks) { stacks }
38
+ end
39
+
40
+ expect(template).to eq((<<-EOS).chomp)
41
+ Resources do
42
+ myEC2Instance do
43
+ Type "AWS::EC2::Instance"
44
+ Properties do
45
+ ImageId "ami-XXXXXXXX"
46
+ InstanceType "t1.micro"
47
+ end
48
+ end
49
+ end
50
+ Outputs do
51
+ AZ do
52
+ Value do
53
+ Fn__GetAtt "myEC2Instance", "AvailabilityZone"
54
+ end
55
+ end
56
+ end
57
+ EOS
58
+ end
59
+ end
@@ -0,0 +1,67 @@
1
+ describe 'Kumogata::Client#list' do
2
+ it 'list stacks' do
3
+ json = run_client(:list) do |client, cf|
4
+ stack1 = make_double('stack1') do |obj|
5
+ obj.should_receive(:name) { 'stack1' }
6
+ obj.should_receive(:creation_time) { '2014-03-02 16:17:18 UTC' }
7
+ obj.should_receive(:status) { 'CREATE_COMPLETE' }
8
+ obj.should_receive(:description) { nil }
9
+ end
10
+
11
+ stack2 = make_double('stack2') do |obj|
12
+ obj.should_receive(:name) { 'stack2' }
13
+ obj.should_receive(:creation_time) { '2014-03-02 16:17:19 UTC' }
14
+ obj.should_receive(:status) { 'CREATE_COMPLETE' }
15
+ obj.should_receive(:description) { nil }
16
+ end
17
+
18
+ cf.should_receive(:stacks) { [stack1, stack2] }
19
+ end
20
+
21
+ expect(json).to eq((<<-EOS).chomp)
22
+ [
23
+ {
24
+ "StackName": "stack1",
25
+ "CreationTime": "2014-03-02 16:17:18 UTC",
26
+ "StackStatus": "CREATE_COMPLETE",
27
+ "Description": null
28
+ },
29
+ {
30
+ "StackName": "stack2",
31
+ "CreationTime": "2014-03-02 16:17:19 UTC",
32
+ "StackStatus": "CREATE_COMPLETE",
33
+ "Description": null
34
+ }
35
+ ]
36
+ EOS
37
+ end
38
+
39
+ it 'list a specified stack' do
40
+ json = run_client(:list, :arguments => ['stack1']) do |client, cf|
41
+ stack1 = make_double('stack1') do |obj|
42
+ obj.should_receive(:name).twice { 'stack1' }
43
+ obj.should_receive(:creation_time) { '2014-03-02 16:17:18 UTC' }
44
+ obj.should_receive(:status) { 'CREATE_COMPLETE' }
45
+ obj.should_receive(:description) { nil }
46
+ end
47
+
48
+ stack2 = make_double('stack2') do |obj|
49
+ obj.should_receive(:name) { 'stack2' }
50
+ end
51
+
52
+ cf.should_receive(:stacks) { [stack1, stack2] }
53
+ end
54
+
55
+ expect(json).to eq((<<-EOS).chomp)
56
+ [
57
+ {
58
+ "StackName": "stack1",
59
+ "CreationTime": "2014-03-02 16:17:18 UTC",
60
+ "StackStatus": "CREATE_COMPLETE",
61
+ "Description": null
62
+ }
63
+ ]
64
+ EOS
65
+ end
66
+
67
+ end
@@ -22,7 +22,6 @@ end
22
22
 
23
23
  run_client(:update, :arguments => ['MyStack'], :template => template) do |client, cf|
24
24
  json = eval_template(template).to_json
25
- stacks = double('status')
26
25
 
27
26
  output = make_double('output') do |obj|
28
27
  obj.should_receive(:key) { 'AZ' }
@@ -86,7 +85,6 @@ end
86
85
 
87
86
  run_client(:update, :arguments => ['MyStack'], :template => template, :options => {:parameters => ['InstanceType=m1.large']}) do |client, cf|
88
87
  json = eval_template(template).to_json
89
- stacks = double('status')
90
88
 
91
89
  output = make_double('output') do |obj|
92
90
  obj.should_receive(:key) { 'AZ' }
data/spec/spec_helper.rb CHANGED
@@ -19,7 +19,7 @@ def tempfile(content, template_ext)
19
19
  end
20
20
 
21
21
  def run_client(command, options = {})
22
- $stdout = open('/dev/null', 'w')
22
+ $stdout = open('/dev/null', 'w') unless ENV['DEBUG']
23
23
 
24
24
  kumogata_template = options[:template]
25
25
  kumogata_arguments = options[:arguments] || []
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kumogata
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Genki Sugawara
@@ -177,6 +177,8 @@ files:
177
177
  - spec/kumogata_convert_spec.rb
178
178
  - spec/kumogata_create_spec.rb
179
179
  - spec/kumogata_delete_spec.rb
180
+ - spec/kumogata_export_spec.rb
181
+ - spec/kumogata_list_spec.rb
180
182
  - spec/kumogata_update_spec.rb
181
183
  - spec/kumogata_validate_spec.rb
182
184
  - spec/spec_helper.rb
@@ -208,6 +210,8 @@ test_files:
208
210
  - spec/kumogata_convert_spec.rb
209
211
  - spec/kumogata_create_spec.rb
210
212
  - spec/kumogata_delete_spec.rb
213
+ - spec/kumogata_export_spec.rb
214
+ - spec/kumogata_list_spec.rb
211
215
  - spec/kumogata_update_spec.rb
212
216
  - spec/kumogata_validate_spec.rb
213
217
  - spec/spec_helper.rb