automan 2.1.2

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 (70) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/.rvmrc +1 -0
  4. data/.travis.yml +5 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE.txt +21 -0
  7. data/README.md +29 -0
  8. data/Rakefile +6 -0
  9. data/automan.gemspec +30 -0
  10. data/bin/baker +4 -0
  11. data/bin/mover +4 -0
  12. data/bin/scanner +4 -0
  13. data/bin/snapper +4 -0
  14. data/bin/stacker +4 -0
  15. data/bin/stalker +4 -0
  16. data/lib/automan.rb +27 -0
  17. data/lib/automan/base.rb +64 -0
  18. data/lib/automan/beanstalk/application.rb +74 -0
  19. data/lib/automan/beanstalk/configuration.rb +137 -0
  20. data/lib/automan/beanstalk/deployer.rb +193 -0
  21. data/lib/automan/beanstalk/errors.rb +22 -0
  22. data/lib/automan/beanstalk/package.rb +39 -0
  23. data/lib/automan/beanstalk/router.rb +102 -0
  24. data/lib/automan/beanstalk/terminator.rb +60 -0
  25. data/lib/automan/beanstalk/uploader.rb +58 -0
  26. data/lib/automan/beanstalk/version.rb +100 -0
  27. data/lib/automan/chef/uploader.rb +30 -0
  28. data/lib/automan/cli/baker.rb +63 -0
  29. data/lib/automan/cli/base.rb +14 -0
  30. data/lib/automan/cli/mover.rb +47 -0
  31. data/lib/automan/cli/scanner.rb +24 -0
  32. data/lib/automan/cli/snapper.rb +78 -0
  33. data/lib/automan/cli/stacker.rb +106 -0
  34. data/lib/automan/cli/stalker.rb +279 -0
  35. data/lib/automan/cloudformation/errors.rb +40 -0
  36. data/lib/automan/cloudformation/launcher.rb +196 -0
  37. data/lib/automan/cloudformation/replacer.rb +102 -0
  38. data/lib/automan/cloudformation/terminator.rb +61 -0
  39. data/lib/automan/cloudformation/uploader.rb +57 -0
  40. data/lib/automan/ec2/errors.rb +4 -0
  41. data/lib/automan/ec2/image.rb +137 -0
  42. data/lib/automan/ec2/instance.rb +83 -0
  43. data/lib/automan/mixins/aws_caller.rb +115 -0
  44. data/lib/automan/mixins/utils.rb +18 -0
  45. data/lib/automan/rds/errors.rb +7 -0
  46. data/lib/automan/rds/snapshot.rb +244 -0
  47. data/lib/automan/s3/downloader.rb +25 -0
  48. data/lib/automan/s3/uploader.rb +20 -0
  49. data/lib/automan/version.rb +3 -0
  50. data/lib/automan/wait_rescuer.rb +17 -0
  51. data/spec/beanstalk/application_spec.rb +49 -0
  52. data/spec/beanstalk/configuration_spec.rb +98 -0
  53. data/spec/beanstalk/deployer_spec.rb +162 -0
  54. data/spec/beanstalk/package_spec.rb +9 -0
  55. data/spec/beanstalk/router_spec.rb +65 -0
  56. data/spec/beanstalk/terminator_spec.rb +67 -0
  57. data/spec/beanstalk/uploader_spec.rb +53 -0
  58. data/spec/beanstalk/version_spec.rb +60 -0
  59. data/spec/chef/uploader_spec.rb +9 -0
  60. data/spec/cloudformation/launcher_spec.rb +240 -0
  61. data/spec/cloudformation/replacer_spec.rb +58 -0
  62. data/spec/cloudformation/templates/worker_role.json +337 -0
  63. data/spec/cloudformation/terminator_spec.rb +63 -0
  64. data/spec/cloudformation/uploader_spec.rb +50 -0
  65. data/spec/ec2/image_spec.rb +158 -0
  66. data/spec/ec2/instance_spec.rb +57 -0
  67. data/spec/mixins/aws_caller_spec.rb +39 -0
  68. data/spec/mixins/utils_spec.rb +44 -0
  69. data/spec/rds/snapshot_spec.rb +152 -0
  70. metadata +278 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 51034f65211eb254e16dda913be2911ab509932e
4
+ data.tar.gz: 3af18906f79765fde866c0deb13998930e7bf9fb
5
+ SHA512:
6
+ metadata.gz: e0004f92017b780b531561e2edd234d7f99f77ed8ae27680f3dd0d93535e5337cc88dac6a5214a1fa52f9438cc641df5bb4f5cc1a32947537e8bb3c8c34bb046
7
+ data.tar.gz: 47f1121011e1e4f4c50e17d55ed81a713c4dc8d43295e14f2f7012aeade25660050c1f35ca31943be861f91119483f265856ea54d4e5c960f09757551710a41c
@@ -0,0 +1,17 @@
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
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm --create use ruby-2.1.2@automan
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - "2.1.2"
4
+ # uncomment this line if your project needs to run something other than `rake`:
5
+ # script: bundle exec rspec spec
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in automan.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Leaf Sofware Solutions
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ # Automan
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'automan'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install automan
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,6 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'automan/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "automan"
8
+ spec.version = Automan::VERSION
9
+ spec.authors = ["Chris Chalfant", "Andrew Kaczorek"]
10
+ spec.email = ["cchalfant@leafsoftwaresolutions.com", "akaczorek@leafsoftwaresolutions.com"]
11
+ spec.description = %q{Automates common AWS ops}
12
+ spec.summary = %q{Automates common AWS ops}
13
+ spec.homepage = ""
14
+
15
+ spec.files = `git ls-files`.split($/)
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.3"
21
+ spec.add_development_dependency "rake"
22
+ spec.add_development_dependency "rspec-core", "~> 2.12.2"
23
+ spec.add_development_dependency "rspec-mocks", "~> 2.12.2"
24
+ spec.add_development_dependency "rspec-expectations", "~> 2.12.1"
25
+ spec.add_dependency "aws-sdk", "< 2.0"
26
+ spec.add_dependency "thor"
27
+ spec.add_dependency "json"
28
+ spec.add_dependency "wait"
29
+ spec.add_dependency "minitar"
30
+ end
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require 'automan/cli/baker'
3
+
4
+ Automan::Cli::Baker.start ARGV
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require 'automan/cli/mover'
3
+
4
+ Automan::Cli::Mover.start ARGV
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require 'automan/cli/scanner'
3
+
4
+ Automan::Cli::Scanner.start ARGV
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require 'automan/cli/snapper'
3
+
4
+ Automan::Cli::Snapper.start ARGV
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require 'automan/cli/stacker'
3
+
4
+ Automan::Cli::Stacker.start ARGV
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require 'automan/cli/stalker'
3
+
4
+ Automan::Cli::Stalker.start ARGV
@@ -0,0 +1,27 @@
1
+ require 'automan/version'
2
+ require 'automan/wait_rescuer'
3
+ require 'automan/mixins/aws_caller'
4
+ require 'automan/mixins/utils'
5
+ require 'automan/base'
6
+ require 'automan/cli/base'
7
+ require 'automan/beanstalk/deployer'
8
+ require 'automan/beanstalk/router'
9
+ require 'automan/beanstalk/application'
10
+ require 'automan/beanstalk/terminator'
11
+ require 'automan/beanstalk/configuration'
12
+ require 'automan/beanstalk/version'
13
+ require 'automan/beanstalk/package'
14
+ require 'automan/beanstalk/uploader'
15
+ require 'automan/beanstalk/errors'
16
+ require 'automan/chef/uploader'
17
+ require 'automan/cloudformation/launcher'
18
+ require 'automan/cloudformation/terminator'
19
+ require 'automan/cloudformation/replacer'
20
+ require 'automan/cloudformation/uploader'
21
+ require 'automan/cloudformation/errors'
22
+ require 'automan/rds/snapshot'
23
+ require 'automan/rds/errors'
24
+ require 'automan/ec2/instance'
25
+ require 'automan/ec2/image'
26
+ require 'automan/s3/uploader'
27
+ require 'automan/s3/downloader'
@@ -0,0 +1,64 @@
1
+ require 'automan'
2
+ require 'logger'
3
+ require 'wait'
4
+
5
+ module Automan
6
+ class Base
7
+ class << self
8
+ attr_accessor :option_names
9
+ end
10
+
11
+ attr_accessor :logger, :wait
12
+
13
+ include Automan::Mixins::AwsCaller
14
+
15
+ def initialize(options=nil)
16
+ $stdout.sync = true
17
+ @logger = Logger.new(STDOUT)
18
+ @log_aws_calls = false
19
+ #@wait = Wait.new(rescuer: WaitRescuer.new, logger: @logger)
20
+
21
+ if !options.nil?
22
+ options.each_pair do |k,v|
23
+ accessor = (k.to_s + '=').to_sym
24
+ send(accessor, v) if respond_to? accessor
25
+ end
26
+ end
27
+ end
28
+
29
+ def self.add_option(*args)
30
+ args.each do |arg|
31
+ self.class_eval("def #{arg};@#{arg};end")
32
+ self.class_eval("def #{arg}=(val);@#{arg}=val;end")
33
+ if self.option_names.nil?
34
+ self.option_names = []
35
+ end
36
+ self.option_names << arg
37
+ end
38
+ end
39
+
40
+ def log_options
41
+ biggest_opt_name_length = self.class.option_names.max_by(&:length).length
42
+ message = "called with:\n"
43
+ self.class.option_names.each do |opt|
44
+ opt_name = opt.to_s.concat(':').ljust(biggest_opt_name_length)
45
+ message += "#{opt_name} #{send(opt)}\n"
46
+ end
47
+ logger.info message
48
+ end
49
+
50
+ def wait_until(raise_on_fail=nil, &block)
51
+ begin
52
+ wait.until do
53
+ yield
54
+ end
55
+ rescue Wait::ResultInvalid => e
56
+ if raise_on_fail.nil?
57
+ raise e
58
+ else
59
+ raise raise_on_fail
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,74 @@
1
+ require 'automan'
2
+
3
+ module Automan::Beanstalk
4
+ class Application < Automan::Base
5
+ add_option :name
6
+
7
+ def application_exists?
8
+ opts = {
9
+ application_names: [ name ]
10
+ }
11
+
12
+ response = eb.describe_applications opts
13
+
14
+ unless response.successful?
15
+ raise RequestFailedError, "describe_applications failed: #{response.error}"
16
+ end
17
+
18
+ response.data[:applications].each do |app|
19
+ if app[:application_name] == name
20
+ return true
21
+ end
22
+ end
23
+
24
+ return false
25
+ end
26
+
27
+ def create_application
28
+ logger.info "creating application #{name}"
29
+
30
+ opts = {
31
+ application_name: name
32
+ }
33
+
34
+ response = eb.create_application opts
35
+
36
+ unless response.successful?
37
+ raise RequestFailedError, "create_application failed: #{response.error}"
38
+ end
39
+ end
40
+
41
+ def delete_application
42
+ logger.info "deleting application #{name}"
43
+
44
+ opts = {
45
+ application_name: name
46
+ }
47
+
48
+ response = eb.delete_application opts
49
+
50
+ unless response.successful?
51
+ raise RequestFailedError, "delete_application failed: #{response.error}"
52
+ end
53
+ end
54
+
55
+ def create
56
+ log_options
57
+ if application_exists?
58
+ logger.warn "Application #{name} already exists. Doing nothing."
59
+ return
60
+ end
61
+ create_application
62
+ end
63
+
64
+ def delete
65
+ log_options
66
+ if !application_exists?
67
+ logger.warn "Application #{name} does not exist. Doing nothing."
68
+ return
69
+ end
70
+ delete_application
71
+ end
72
+ end
73
+
74
+ end
@@ -0,0 +1,137 @@
1
+ require 'json'
2
+ require 'automan'
3
+
4
+ module Automan::Beanstalk
5
+ class Configuration < Automan::Base
6
+ add_option :name,
7
+ :application,
8
+ :template,
9
+ :platform
10
+
11
+ include Automan::Mixins::Utils
12
+
13
+ def config_template_exists?
14
+ opts = {
15
+ application_name: application,
16
+ template_name: name
17
+ }
18
+
19
+ begin
20
+ response = eb.describe_configuration_settings opts
21
+ rescue AWS::ElasticBeanstalk::Errors::InvalidParameterValue => e
22
+ if e.message.start_with? "No Configuration Template named"
23
+ return false
24
+ end
25
+ end
26
+
27
+ unless response.successful?
28
+ raise RequestFailedError, "describe_configuration_settings failed: #{response.error}"
29
+ end
30
+
31
+ response.data[:configuration_settings].each do |settings|
32
+ if settings[:application_name] == application && settings[:template_name] == name
33
+ return true
34
+ end
35
+ end
36
+
37
+ return false
38
+ end
39
+
40
+ def delete_config_template
41
+ opts = {
42
+ application_name: application,
43
+ template_name: name
44
+ }
45
+
46
+ response = eb.delete_configuration_template opts
47
+
48
+ unless response.successful?
49
+ raise RequestFailedError, "delete_configuration_template failed: #{response.error}"
50
+ end
51
+ end
52
+
53
+ # config_option files are stored in json format compatible
54
+ # with elastic-beanstalk-create-configuration-template cli.
55
+ # The keys of each object are in json CamelCase.
56
+ # We need to convert them to ruby snake_case to work with aws-sdk
57
+ def fix_config_keys(config_array)
58
+ result = []
59
+ config_array.each do |i|
60
+ fixed_hash = {}
61
+ i.each do |key, value|
62
+ fixed_key = key.underscore
63
+ fixed_hash[ fixed_key ] = value.to_s
64
+ end
65
+ result << fixed_hash
66
+ end
67
+ result
68
+ end
69
+
70
+ # TODO: read options file (from local or s3) into array of hashes
71
+ # http://docs.aws.amazon.com/AWSRubySDK/latest/AWS/ElasticBeanstalk/Client/V20101201.html#create_configuration_template-instance_method
72
+ def configuration_options
73
+ json_config = ""
74
+
75
+ if looks_like_s3_path? template
76
+ bucket, key = parse_s3_path template
77
+ json_config = s3.buckets[bucket].objects[key].read
78
+ else
79
+ json_config = File.read template
80
+ end
81
+
82
+ config = JSON.parse json_config
83
+ config = fix_config_keys config
84
+
85
+ config
86
+ end
87
+
88
+ # where are we getting configuration data?
89
+ def create_config_template
90
+ opts = {
91
+ application_name: application,
92
+ template_name: name,
93
+ solution_stack_name: platform,
94
+ option_settings: configuration_options
95
+ }
96
+
97
+ response = eb.create_configuration_template opts
98
+
99
+ unless response.successful?
100
+ raise RequestFailedError, "create_configuration_template failed: #{response.error}"
101
+ end
102
+ end
103
+
104
+ def create
105
+ log_options
106
+ if config_template_exists?
107
+ logger.warn "Configuration template #{name} for #{application} already exists. Doing nothing."
108
+ return
109
+ end
110
+ logger.info "Creating configuration template #{name} for #{application}."
111
+ create_config_template
112
+ end
113
+
114
+ def delete
115
+ log_options
116
+ if !config_template_exists?
117
+ logger.warn "Configuration #{name} for #{application} does not exist. Doing nothing."
118
+ return
119
+ end
120
+ logger.info "Deleting configuration template #{name} for #{application}."
121
+ delete_config_template
122
+ end
123
+
124
+ def update
125
+ log_options
126
+
127
+ if config_template_exists?
128
+ logger.info "Configuration template #{name} for #{application} exists. Deleting it."
129
+ delete_config_template
130
+ end
131
+
132
+ logger.info "Creating configuration template #{name} for #{application}"
133
+ create_config_template
134
+ end
135
+ end
136
+
137
+ end