CfnTools 0.0.8

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.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/CfnTools.rb +116 -0
  3. metadata +44 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 617bac92d83934eaf80b720b36324083f2a2068d
4
+ data.tar.gz: fc6442060861a21282c366f377d4cda685344288
5
+ SHA512:
6
+ metadata.gz: e5a84c127af12447202561c663ce6eaf9879b94724442ec3141d6678519b7dc2a57128275bdb9b591b2d18703c2d9f60b26b338784befdd5811dfd26bff1eb28
7
+ data.tar.gz: c65eec58ed4df4f7cfbd379bd77fde8a0236927b313e698cba7fb089582b074abf0cb7b59344fdeba3a523249833e465035b46a49a3f06d7360962acdcd05e18
data/lib/CfnTools.rb ADDED
@@ -0,0 +1,116 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'aws-sdk'
4
+
5
+ class CfnTools
6
+
7
+ def initialize( stack)
8
+
9
+ @stack_name = stack
10
+ @cfn = AWS::CloudFormation.new()
11
+ unless @cfn.stacks[@stack_name].exists?
12
+ puts "Stack does not exist: #{@stack_name}"
13
+ exit 1
14
+ end
15
+
16
+ @substacks = Array.new()
17
+ @stack_as = Array.new()
18
+ @stack_events = Set.new()
19
+
20
+ get_sub_stacks()
21
+ get_stack_as()
22
+
23
+ end
24
+
25
+ def ret_stack_name()
26
+ return @stack_name
27
+ end
28
+
29
+ def ret_substacks()
30
+ return @substacks
31
+ end
32
+
33
+ def ret_stack_as()
34
+ return @stack_as
35
+ end
36
+
37
+ def ret_stack_events()
38
+ return @stack_events
39
+ end
40
+
41
+ def get_template( stack)
42
+ cfn_template = @cfn.stacks[stack].template
43
+ parsed_cfn_template = JSON.load( cfn_template)
44
+ template = YAML::dump( parsed_cfn_template)
45
+ return template
46
+ end
47
+
48
+ def get_sub_stacks()
49
+ AWS.memoize do
50
+ stack = @cfn.stacks[@stack_name]
51
+ stack.resource_summaries.each do |resource|
52
+ if resource[:resource_type] == 'AWS::CloudFormation::Stack'
53
+ if resource[:physical_resource_id].is_a? String
54
+ @substacks.push( resource[:physical_resource_id] )
55
+ end
56
+ end
57
+ end
58
+ end
59
+ return @substacks
60
+ end
61
+
62
+ def get_stack_as()
63
+ AWS.memoize do
64
+ stack = @cfn.stacks[@stack_name]
65
+ stack.resource_summaries.each do |resource|
66
+ if resource[:resource_type] == 'AWS::AutoScaling::AutoScalingGroup'
67
+ @stack_as.push( resource[:physical_resource_id])
68
+ end
69
+ end
70
+ @substacks.each do |substack|
71
+ stack = @cfn.stacks[substack]
72
+ stack.resource_summaries.each do |resource|
73
+ if resource[:resource_type] == 'AWS::AutoScaling::AutoScalingGroup'
74
+ @stack_as.push( resource[:physical_resource_id])
75
+ end
76
+ end
77
+ end
78
+ end
79
+ return @stack_as
80
+ end
81
+
82
+ def get_as_instances( as_name)
83
+ instances = Array.new()
84
+ as = AWS::AutoScaling.new()
85
+ myAS = as.groups[ as_name ]
86
+ myAS.auto_scaling_instances.each do |instance|
87
+ old_lc = 0
88
+ if instance.launch_configuration_name != myAS.launch_configuration.name
89
+ #old_lc = "** has old LaunchConfiguration ** "
90
+ old_lc = 1
91
+ end
92
+ myInstance = instance.ec2_instance
93
+ instances.push( { 'ip_address' => myInstance.private_ip_address, 'instance_id' => instance.ec2_instance.instance_id, 'old_lc' => old_lc } )
94
+ end
95
+ return instances
96
+ end
97
+
98
+ def get_stack_events()
99
+ events = Array.new()
100
+ stacks = @substacks
101
+ stacks.push( @stack_name)
102
+ AWS.memoize do
103
+ stacks.each do |stack|
104
+ stack = @cfn.stacks[stack]
105
+ stack.events.each do |event|
106
+ if @stack_events.add?(event.event_id)
107
+ events.push(event)
108
+ end
109
+ end
110
+ end
111
+ end
112
+ events.sort! { |a,b| a.timestamp <=> b.timestamp }
113
+ return events
114
+ end
115
+
116
+ end
metadata ADDED
@@ -0,0 +1,44 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: CfnTools
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.8
5
+ platform: ruby
6
+ authors:
7
+ - Brian Schrock
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-06-14 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Utilities for AWS cloudformation stack information
14
+ email: bschrock@manta.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/CfnTools.rb
20
+ homepage: http://github.com/mantacode/CfnTools
21
+ licenses:
22
+ - MIT
23
+ metadata: {}
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ requirements: []
39
+ rubyforge_project:
40
+ rubygems_version: 2.2.2
41
+ signing_key:
42
+ specification_version: 4
43
+ summary: CfnTools
44
+ test_files: []