cloudformer 0.0.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a5f7850bb470ec43a1b2ae9fa9be8a817efe019f
4
+ data.tar.gz: 2f817edaf0c9c5cf9349ef62ade9c9f32469a347
5
+ SHA512:
6
+ metadata.gz: 24198299c271bb371227d774616243f40139c683c4263f44a6a2312dcf6ba31b7d3e0de0f99ee70ddc800c3a90df57c02132598579953d9eb3a98b415ff28e8f
7
+ data.tar.gz: 616f302afc972f8c360b1e13de7b7268b17b1ce6e97075ea04126a063678ecabcd07300e5185195319f0adda8e631f62c26823464e3d6152f1801d1861de4c4d
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .DS_Store
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Arvind Kunday
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ # Cloudformer
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'cloudformer'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install cloudformer
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'cloudformer/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "cloudformer"
8
+ spec.version = Cloudformer::VERSION
9
+ spec.authors = ["Arvind Kunday"]
10
+ spec.email = ["hi@kunday.com"]
11
+ spec.description = %q{Rake helper tasks for Cloudformation}
12
+ spec.summary = %q{Helper tools for aws cloudformation}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_dependency "rake"
23
+ spec.add_dependency "aws-sdk"
24
+ end
@@ -0,0 +1,5 @@
1
+ require "cloudformer/version"
2
+
3
+ module Cloudformer
4
+ # Your code goes here...
5
+ end
@@ -0,0 +1,137 @@
1
+ class Stack
2
+ attr_accessor :stack, :name, :deployed
3
+ def initialize(stack_name)
4
+ @name = stack_name
5
+ @cf = AWS::CloudFormation.new
6
+ @stack = @cf.stacks[name]
7
+ end
8
+
9
+ def deployed
10
+ return stack.exists?
11
+ end
12
+
13
+ def apply(template_file, parameters)
14
+ template = File.read(template_file)
15
+ validation = validate(template)
16
+ unless validation["valid"]
17
+ puts "Unable to update - #{validation["response"][:code]} - #{validation["response"][:message]}"
18
+ return 1
19
+ end
20
+ pending_operations = false
21
+ if deployed
22
+ pending_operations = update(template, parameters)
23
+ else
24
+ pending_operations = create(template, parameters)
25
+ end
26
+ wait_until_end if pending_operations
27
+ if stack.status == "ROLLBACK_COMPLETE"
28
+ puts "Unable to update template. Check log for more information."
29
+ return 1
30
+ else
31
+ return 0
32
+ end
33
+ end
34
+
35
+ def delete
36
+ with_highlight do
37
+ puts "Attempting to delete stack - #{name}"
38
+ stack.delete
39
+ wait_until_end
40
+ end
41
+ end
42
+
43
+ def status
44
+ with_highlight do
45
+ if deployed
46
+ puts "#{stack.name} - #{stack.status} - #{stack.status_reason}"
47
+ else
48
+ puts "#{name} - Not Deployed"
49
+ end
50
+ end
51
+ end
52
+
53
+ def events(options = {})
54
+ with_highlight do
55
+ if !deployed
56
+ puts "Stack not up."
57
+ return
58
+ end
59
+ stack.events.sort_by {|a| a.timestamp}.each do |event|
60
+ puts "#{event.timestamp} - #{event.resource_type} - #{event.resource_status} - #{event.resource_status_reason.to_s}"
61
+ end
62
+ end
63
+ end
64
+
65
+ def outputs
66
+ with_highlight do
67
+ if !deployed
68
+ puts "Stack not up."
69
+ return 1
70
+ end
71
+ stack.outputs.each do |output|
72
+ puts "#{output.key} - #{output.description} - #{output.value}"
73
+ end
74
+ end
75
+ return 0
76
+ end
77
+
78
+ private
79
+ def wait_until_end
80
+ printed = []
81
+ with_highlight do
82
+ if !deployed
83
+ puts "Stack not up."
84
+ return
85
+ end
86
+ loop do
87
+ exit_loop = false
88
+ printable_events = stack.events.sort_by {|a| a.timestamp}.reject {|a| a if printed.include?(a.event_id)}
89
+ printable_events.each do |event|
90
+ puts "#{event.timestamp} - #{event.resource_type} - #{event.resource_status} - #{event.resource_status_reason.to_s}"
91
+ if event.resource_type == "AWS::CloudFormation::Stack" && !event.resource_status.match(/_COMPLETE$/).nil?
92
+ exit_loop = true
93
+ end
94
+ end
95
+ printed.concat(printable_events.map(&:event_id))
96
+ break if !stack.status.match(/_COMPLETE$/).nil?
97
+ sleep(5)
98
+ end
99
+ end
100
+ end
101
+
102
+ def with_highlight &block
103
+ cols = `tput cols`.chomp!.to_i
104
+ puts "="*cols
105
+ yield
106
+ puts "="*cols
107
+ end
108
+
109
+ def validate(template)
110
+ response = @cf.validate_template(template)
111
+ return {
112
+ "valid" => response[:code].nil?,
113
+ "response" => response
114
+ }
115
+ end
116
+
117
+ def update(template, parameters)
118
+ stack.update({
119
+ :template => template,
120
+ :parameters => parameters
121
+ })
122
+ return true
123
+ rescue ::AWS::CloudFormation::Errors::ValidationError => e
124
+ puts e.message
125
+ return false
126
+ end
127
+
128
+ def create(template, parameters)
129
+ puts "Initializing stack creation..."
130
+ @cf.stacks.create(name, template, :parameters => parameters)
131
+ sleep 10
132
+ return true
133
+ rescue ::AWS::CloudFormation::Errors::ValidationError => e
134
+ puts e.message
135
+ return false
136
+ end
137
+ end
@@ -0,0 +1,63 @@
1
+ require 'cloudformer/version'
2
+ require 'cloudformer/stack'
3
+
4
+ module Cloudformer
5
+ class Tasks < Rake::TaskLib
6
+ def initialize(stack_name)
7
+ @stack_name = stack_name
8
+ @stack =Stack.new(stack_name)
9
+ if block_given?
10
+ yield self
11
+ define_tasks
12
+ end
13
+ end
14
+
15
+ attr_accessor :template, :parameters
16
+
17
+ private
18
+ def define_tasks
19
+ define_create_task
20
+ define_delete_task
21
+ define_events_task
22
+ define_status_task
23
+ define_outputs_task
24
+ define_recreate_task
25
+ end
26
+
27
+ def define_create_task
28
+ desc "Apply Stack with Cloudformation script and parameters."
29
+ task :apply do
30
+ p template
31
+ @stack.apply(template, parameters)
32
+ end
33
+ end
34
+ def define_delete_task
35
+ desc "Delete stack from CloudFormation"
36
+ task :delete do
37
+ @stack.delete
38
+ end
39
+ end
40
+ def define_status_task
41
+ desc "Get the deployed app status."
42
+ task :status do
43
+ @stack.status
44
+ end
45
+ end
46
+ def define_events_task
47
+ desc "Get the recent events from the stack."
48
+ task :events do
49
+ @stack.events
50
+ end
51
+ end
52
+ def define_outputs_task
53
+ desc "Get the outputs of stack."
54
+ task :outputs do
55
+ @stack.outputs
56
+ end
57
+ end
58
+ def define_recreate_task
59
+ desc "Recreate stack."
60
+ task :recreate => [:delete, :apply, :outputs]
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,3 @@
1
+ module Cloudformer
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cloudformer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Arvind Kunday
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-10-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: aws-sdk
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Rake helper tasks for Cloudformation
56
+ email:
57
+ - hi@kunday.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - cloudformer.gemspec
68
+ - lib/cloudformer.rb
69
+ - lib/cloudformer/stack.rb
70
+ - lib/cloudformer/tasks.rb
71
+ - lib/cloudformer/version.rb
72
+ homepage: ''
73
+ licenses:
74
+ - MIT
75
+ metadata: {}
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubyforge_project:
92
+ rubygems_version: 2.0.6
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: Helper tools for aws cloudformation
96
+ test_files: []