cloudformation-tool 1.0.4 → 1.0.5

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
  SHA256:
3
- metadata.gz: f3c901ead020a647c6b7fca5e7c54a87ac460fa40ffea601e57fc679f4e16d48
4
- data.tar.gz: e4a3b0af6b07b111926088777071e180bbf83fe4efc6782a97f1ed5b60683cd3
3
+ metadata.gz: 72b77e70306d3203e76898284edecd89daee64e164329fdb2ab53f3eabcc1559
4
+ data.tar.gz: deef3362134e2aa8edd7969f0307dc0731ed9bb93b3dd4b0143bbc747428ced4
5
5
  SHA512:
6
- metadata.gz: 9b5f8f00b6a8d0c724dc1b7231b063d4b1b4c5807fd7915dcd70b272112266d7d8be75eb88f4576d9d0966b24629ea2d025c336a4f40958b9b3e7adc6fd1dbee
7
- data.tar.gz: dc198485e2c6af34cef73e380fb69e478cf3b09b1512f76263bfb943061b90f16a2b3297bfd157baec7a50960cea8011a32381773081057b2085dbd55494f580
6
+ metadata.gz: 2c519e62fc5bb7288a4be2aa785dffe3e717ec1380befe06d08823e6489474bd26843cc4bf7454cc3b70e3b1559b5efad70d557cf40bd36e7841d767a88b8045
7
+ data.tar.gz: 3e5e245e1387416c4ceaaaabf0ce791a7bf8bc893dd3a4a3fe0fe15b335eb0b0adde6fc59a5d1f4e3d6464ce8afe51971d7e839465768071352490d1276183b6
@@ -0,0 +1,25 @@
1
+ module CloudFormationTool
2
+ module CLI
3
+
4
+ class Groups < Clamp::Command
5
+ include CloudFormationTool
6
+
7
+ parameter "STACK_NAME", "Name of the stack to list Autoscaling groups from"
8
+
9
+ def execute
10
+ st = CloudFormation::Stack.new(stack_name)
11
+ output = st.asgroups.collect do |res|
12
+ {
13
+ name: res.logical_resource_id,
14
+ res: res.physical_resource_id,
15
+ len: res.logical_resource_id.length
16
+ }
17
+ end
18
+ width = output.collect { |g| g[:name].length }.max
19
+ output.collect do |grp|
20
+ puts grp[:name].ljust(width, ' ') + "\t => " + grp[:res]
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -6,6 +6,14 @@ module CloudFormationTool
6
6
  module CLI
7
7
  class Main < Clamp::Command
8
8
 
9
+ logger.formatter = proc { |severity, datetime, progname, msg|
10
+ if Logger::Severity.const_get(severity) > Logger::Severity::INFO
11
+ "#{severity}: "
12
+ else
13
+ ""
14
+ end + msg + "\n"
15
+ }
16
+
9
17
  class CFToolHelper
10
18
  include CloudFormationTool
11
19
  end
@@ -21,9 +29,18 @@ module CloudFormationTool
21
29
  $__profile = s
22
30
  end
23
31
 
32
+ option [ "-d", "--debug" ], :flag, "Enable debug logging" do
33
+ logger.level = Logger::Severity::DEBUG
34
+ logger.formatter = logger.default_formatter
35
+ end
36
+
37
+ option [ "-q", "--quiet" ], :flag, "Enable debug logging" do
38
+ logger.level = Logger::Severity::ERROR
39
+ end
40
+
24
41
  option [ "-v", "--version" ], :flag, "Print the version and exit" do
25
42
  require 'cloud_formation_tool/version'
26
- puts CloudFormationTool::VERSION
43
+ logger.info CloudFormationTool::VERSION
27
44
  exit 0
28
45
  end
29
46
 
@@ -35,6 +52,7 @@ module CloudFormationTool
35
52
  subcommand 'status', "Check the current status of a stack", Status
36
53
  subcommand 'delete', "Delete an existing stack", Delete
37
54
  subcommand 'servers', 'List stack resources', Servers
55
+ subcommand 'groups', 'List stack Autoscaling groups', Groups
38
56
  subcommand 'recycle', 'Recycle servers in an auto scaling group', Recycle
39
57
  subcommand 'scale', 'Set the number of desired servesr in an auto scaling group', Scale
40
58
  subcommand 'output', 'Retrieve output values from the stack', Output
@@ -16,7 +16,7 @@ module CloudFormationTool
16
16
  sleep 1
17
17
  end
18
18
  rescue CloudFormationTool::Errors::StackDoesNotExistError => e
19
- log "Stack #{stack_name} does not exist"
19
+ error "Stack #{stack_name} does not exist"
20
20
  rescue SystemExit, Interrupt => e
21
21
  # CTRL-C out of the loop
22
22
  puts "\n"
@@ -1,5 +1,3 @@
1
- require 'set'
2
-
3
1
  module CloudFormationTool
4
2
  module CLI
5
3
 
@@ -33,7 +31,7 @@ module CloudFormationTool
33
31
  puts "#{grp.name}: Left to recycle - #{torecycle}"
34
32
  end
35
33
  end
36
- end.each(&:join)
34
+ end.each(&:join).length > 0 or error "No valid Autoscaling groups found named #{asg_name}"
37
35
  end
38
36
  end
39
37
  end
@@ -22,16 +22,16 @@ module CloudFormationTool
22
22
  end
23
23
 
24
24
  def execute
25
- #log "Starting scale operations"
25
+ debug "Starting scale operations"
26
26
  st = CloudFormation::Stack.new(stack_name)
27
27
  st.asgroups.select do |res|
28
- #log "Checking group #{res.logical_resource_id}"
28
+ debug "Checking group #{res.logical_resource_id}"
29
29
  asg_name.nil? or (res.logical_resource_id == asg_name)
30
30
  end.collect do |res|
31
- #log "Scaling #{res.logical_resource_id}"
31
+ debug "Scaling #{res.logical_resource_id}"
32
32
  Thread.new do
33
33
  grp = res.group
34
- #log "Current capacity: #{grp.desired_capacity}, setting to #{scale}"
34
+ debug "Current capacity: #{grp.desired_capacity}, setting to #{scale}"
35
35
  grp.set_desired_capacity(desired_capacity: scale)
36
36
  last_state = nil
37
37
  until stable_scale(grp, scale)
@@ -9,7 +9,7 @@ module CloudFormationTool
9
9
  if CloudFormation::Stack.new(stack_name).exist?
10
10
  log "OK"
11
11
  else
12
- log "Stack #{stack_name} does not exist"
12
+ error "Stack #{stack_name} does not exist"
13
13
  end
14
14
  end
15
15
 
@@ -11,12 +11,12 @@ module CloudFormationTool
11
11
  @data = code
12
12
  @data['Url'] = @data.delete 'URL' if @data.key? 'URL' # normalize to CF convention if seeing old key
13
13
  if @data.key? 'Url'
14
- log "Trying Lambda code from #{@data['Url']}"
14
+ debug "Trying Lambda code from #{@data['Url']}"
15
15
  @data['Url'] = url = tpl.resolveVal(@data['Url'])
16
16
  return unless url.is_a? String
17
17
  log "Downloading Lambda code from #{url}"
18
18
  if already_in_cache(url)
19
- log "Reusing remote cached object instead of downloading"
19
+ debug "Reusing remote cached object instead of downloading"
20
20
  else
21
21
  res = fetch_from_url(url)
22
22
  @s3_url = URI(upload(make_filename(url.split('.').last), res.body, mime_type: res['content-type'], gzip: false))
@@ -25,7 +25,7 @@ module CloudFormationTool
25
25
  elsif @data.key? 'Path'
26
26
  @data['Path'] = path = tpl.resolveVal(@data['Path'])
27
27
  return unless path.is_a? String
28
- log "Reading Lambda code from #{path}"
28
+ debug "Reading Lambda code from #{path}"
29
29
  path = if path.start_with? "/" then path else "#{tpl.basedir}/#{path}" end
30
30
  if File.directory?(path)
31
31
  @s3_url = URI(upload(make_filename('zip'), zip_path(path), mime_type: 'application/zip', gzip: false))
@@ -40,7 +40,7 @@ module CloudFormationTool
40
40
  def zip_path(path)
41
41
  Zip::OutputStream.write_buffer do |zf|
42
42
  rdir path do |ent|
43
- #log "Deflating #{ent}"
43
+ debug "Deflating #{ent}"
44
44
  filepath = File.join(path,ent)
45
45
  zf.put_next_entry ::Zip::Entry.new(nil, ent, nil, nil, nil, nil, nil, nil, ::Zip::DOSTime.at(File.mtime(filepath).to_i))
46
46
  zf.write File.read(filepath)
@@ -64,12 +64,12 @@ module CloudFormationTool
64
64
  http.finish if check_cached(response['ETag'])
65
65
  when Net::HTTPRedirection then
66
66
  location = response['location']
67
- log "Cache check redirected to #{location}"
67
+ debug "Cache check redirected to #{location}"
68
68
  limit = limit - 1
69
69
  response.body
70
70
  url = URI(location)
71
71
  else
72
- log "arg err"
72
+ error "arg err"
73
73
  raise ArgumentError, "Error getting response: #{response}"
74
74
  end
75
75
  end
@@ -107,7 +107,7 @@ module CloudFormationTool
107
107
  response
108
108
  when Net::HTTPRedirection then
109
109
  location = response['location']
110
- log "redirected to #{location}"
110
+ debug "redirected to #{location}"
111
111
  fetch_from_url_real(location, limit - 1)
112
112
  else
113
113
  raise CloudFormationTool::Errors::AppError, "Error downloading #{url}: #{response.value}"
@@ -41,7 +41,7 @@ module CloudFormationTool
41
41
  file_opts.merge!({content_encoding: 'gzip'}) if gzip
42
42
  o.put(file_opts)
43
43
  else
44
- log "re-using cached object"
44
+ debug "re-using cached object"
45
45
  end
46
46
  o.public_url
47
47
  end
@@ -1,3 +1,3 @@
1
1
  module CloudFormationTool
2
- VERSION = '1.0.4'
2
+ VERSION = '1.0.5'
3
3
  end
@@ -1,9 +1,36 @@
1
1
  require 'logger'
2
2
  require 'autoloaded'
3
3
 
4
+ def logger
5
+ ($__logger ||= Logger.new(STDERR))
6
+ end
4
7
 
5
8
  def log(message = nil, &block)
6
- ($__logger ||= Logger.new(STDERR)).info(if message.nil?
9
+ logger.info(if message.nil?
10
+ yield
11
+ else
12
+ message
13
+ end)
14
+ end
15
+
16
+ def debug(message = nul, &block)
17
+ logger.debug(if message.nil?
18
+ yield
19
+ else
20
+ message
21
+ end)
22
+ end
23
+
24
+ def warn(message = nul, &block)
25
+ logger.warn(if message.nil?
26
+ yield
27
+ else
28
+ message
29
+ end)
30
+ end
31
+
32
+ def error(message = nul, &block)
33
+ logger.error(if message.nil?
7
34
  yield
8
35
  else
9
36
  message
@@ -78,7 +105,7 @@ module CloudFormationTool
78
105
  # otherwise try to create one
79
106
  if bucket.nil?
80
107
  name = cf_bucket_name(region)
81
- log("Creating CF template bucket #{name}")
108
+ log "Creating CF template bucket #{name}"
82
109
  awss3.create_bucket({
83
110
  acl: "private",
84
111
  bucket: name
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloudformation-tool
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oded Arbel
@@ -139,6 +139,7 @@ files:
139
139
  - lib/cloud_formation_tool/cli/compile.rb
140
140
  - lib/cloud_formation_tool/cli/create.rb
141
141
  - lib/cloud_formation_tool/cli/delete.rb
142
+ - lib/cloud_formation_tool/cli/groups.rb
142
143
  - lib/cloud_formation_tool/cli/list_stacks.rb
143
144
  - lib/cloud_formation_tool/cli/main.rb
144
145
  - lib/cloud_formation_tool/cli/monitor.rb
@@ -176,7 +177,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
176
177
  version: '0'
177
178
  requirements: []
178
179
  rubyforge_project:
179
- rubygems_version: 2.7.6
180
+ rubygems_version: 2.7.7
180
181
  signing_key:
181
182
  specification_version: 4
182
183
  summary: A pre-compiler tool for CloudFormation YAML templates