cloudformation-tool 1.0.4 → 1.0.5
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.
- checksums.yaml +4 -4
- data/lib/cloud_formation_tool/cli/groups.rb +25 -0
- data/lib/cloud_formation_tool/cli/main.rb +19 -1
- data/lib/cloud_formation_tool/cli/monitor.rb +1 -1
- data/lib/cloud_formation_tool/cli/recycle.rb +1 -3
- data/lib/cloud_formation_tool/cli/scale.rb +4 -4
- data/lib/cloud_formation_tool/cli/status.rb +1 -1
- data/lib/cloud_formation_tool/cloud_formation/lambda_code.rb +7 -7
- data/lib/cloud_formation_tool/storable.rb +1 -1
- data/lib/cloud_formation_tool/version.rb +1 -1
- data/lib/cloud_formation_tool.rb +29 -2
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 72b77e70306d3203e76898284edecd89daee64e164329fdb2ab53f3eabcc1559
|
|
4
|
+
data.tar.gz: deef3362134e2aa8edd7969f0307dc0731ed9bb93b3dd4b0143bbc747428ced4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
25
|
+
debug "Starting scale operations"
|
|
26
26
|
st = CloudFormation::Stack.new(stack_name)
|
|
27
27
|
st.asgroups.select do |res|
|
|
28
|
-
|
|
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
|
-
|
|
31
|
+
debug "Scaling #{res.logical_resource_id}"
|
|
32
32
|
Thread.new do
|
|
33
33
|
grp = res.group
|
|
34
|
-
|
|
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)
|
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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}"
|
data/lib/cloud_formation_tool.rb
CHANGED
|
@@ -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
|
-
|
|
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
|
|
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
|
+
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.
|
|
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
|