kumogata-template 0.0.11 → 0.0.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/kumogata/template/cloudwatch.rb +20 -0
- data/lib/kumogata/template/helper.rb +15 -4
- data/lib/kumogata/template/version.rb +1 -1
- data/template/autoscaling-scheduled-action.rb +34 -8
- data/template/cloudwatch-alarm.rb +1 -1
- data/test/helper_test.rb +1 -0
- data/test/template/autoscaling-scheduled-action_test.rb +4 -2
- data/test/template/cloudwatch-alarm_test.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 524f711e9c27851570ed61a4e28d97e379cc6df0
|
4
|
+
data.tar.gz: 4f92da4c881b9edda3d10b5f92aad0d7f6b6d2a2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4e164fd9a9f3e17c4cdf54ecda9eb212a9aace8b65a01f399349affd30c0c750dbbadc90d61e2b34ccd61fdb857b73c00fed27ad2595e671d441cc85117ded23
|
7
|
+
data.tar.gz: 2e2ebec43d2e1de5c75158671be53cec1db95dd1eea44d341d0bf06dd16ac6dd8448ec8b968a5c6471c8b1059a7eaf9fc6744a22aa07250e02da754dc2e14b97
|
@@ -2,6 +2,26 @@
|
|
2
2
|
# Helper - CloudWatch
|
3
3
|
#
|
4
4
|
|
5
|
+
def _cloudwatch_to_period(value)
|
6
|
+
return value if value.nil?
|
7
|
+
case value
|
8
|
+
when "1m"
|
9
|
+
60
|
10
|
+
when "5m"
|
11
|
+
300
|
12
|
+
when "15m"
|
13
|
+
900
|
14
|
+
when "1h"
|
15
|
+
3600
|
16
|
+
when "6h"
|
17
|
+
21600
|
18
|
+
when "1d"
|
19
|
+
86400
|
20
|
+
else
|
21
|
+
value.to_i
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
5
25
|
def _cloudwatch_to_statistic(value)
|
6
26
|
return value if value.nil?
|
7
27
|
case value.downcase
|
@@ -88,6 +88,10 @@ def _ref_name(name, args, ref_name = "")
|
|
88
88
|
end
|
89
89
|
end
|
90
90
|
|
91
|
+
def _ref_resource_name(args, ref_name = "")
|
92
|
+
_{ Ref _resource_name(args[:name], ref_name) }
|
93
|
+
end
|
94
|
+
|
91
95
|
def _attr_string(name, attr, ref_name = "")
|
92
96
|
_{ Fn__GetAtt [ _resource_name(name, ref_name), attr ] }
|
93
97
|
end
|
@@ -172,12 +176,19 @@ def _availability_zones(args, use_subnet = true)
|
|
172
176
|
end
|
173
177
|
end
|
174
178
|
|
175
|
-
def _timestamp_utc(time = Time.now)
|
176
|
-
|
179
|
+
def _timestamp_utc(time = Time.now, type = nil)
|
180
|
+
format =
|
181
|
+
case type
|
182
|
+
when "cron"
|
183
|
+
"%M %H %d %m %w"
|
184
|
+
else
|
185
|
+
"%Y-%m-%dT%H:%M:%SZ"
|
186
|
+
end
|
187
|
+
time.utc.strftime(format)
|
177
188
|
end
|
178
189
|
|
179
|
-
def _timestamp_utc_from_string(time)
|
180
|
-
_timestamp_utc(Time.strptime(time, "%Y-%m-%d %H:%M"))
|
190
|
+
def _timestamp_utc_from_string(time, type= nil)
|
191
|
+
_timestamp_utc(Time.strptime(time, "%Y-%m-%d %H:%M"), type)
|
181
192
|
end
|
182
193
|
|
183
194
|
def _maintenance_window(service, start_time)
|
@@ -1 +1 @@
|
|
1
|
-
KUMOGATA_TEMPLATE_VERSION = '0.0.
|
1
|
+
KUMOGATA_TEMPLATE_VERSION = '0.0.12'
|
@@ -5,22 +5,48 @@
|
|
5
5
|
require 'kumogata/template/helper'
|
6
6
|
|
7
7
|
name = _resource_name(args[:name], "autoscaling scheduled action")
|
8
|
-
autoscaling =
|
9
|
-
|
8
|
+
autoscaling =
|
9
|
+
if args.key? :autoscaling
|
10
|
+
_ref_string("autoscaling", args, "autoscaling group")
|
11
|
+
else
|
12
|
+
_ref_resource_name(args, "autoscaling group")
|
13
|
+
end
|
14
|
+
desired = args[:desired].to_s || ""
|
10
15
|
end_time =
|
11
16
|
if args.key? :end_time
|
12
|
-
|
17
|
+
_timestamp_utc(args[:end_time])
|
18
|
+
else
|
19
|
+
""
|
20
|
+
end
|
21
|
+
max = args[:max].to_s || ""
|
22
|
+
min = args[:min].to_s || ""
|
23
|
+
min = desired.to_s if args.key? :desired and desired.to_i < min.to_i
|
24
|
+
recurrence =
|
25
|
+
if args.key? :recurrence
|
26
|
+
case args[:recurrence]
|
27
|
+
when "every 5 min"
|
28
|
+
"*/5 * * * *"
|
29
|
+
when "every 30 min"
|
30
|
+
"0,30 * * * *"
|
31
|
+
when "every 1 hour"
|
32
|
+
"0 * * * *"
|
33
|
+
when "every day"
|
34
|
+
"0 0 * * *"
|
35
|
+
when "every week"
|
36
|
+
"0 0 * * Tue"
|
37
|
+
when /\*/
|
38
|
+
args[:recurrence]
|
39
|
+
else
|
40
|
+
_timestamp_utc(args[:recurrence], "cron")
|
41
|
+
end
|
13
42
|
else
|
14
43
|
""
|
15
44
|
end
|
16
|
-
min = args[:min] || ""
|
17
|
-
max = args[:max] || ""
|
18
|
-
recurrence = args[:recurrence] || ""
|
19
45
|
start_time =
|
20
46
|
if args.key? :start_time
|
21
|
-
|
47
|
+
_timestamp_utc(args[:start_time])
|
22
48
|
else
|
23
|
-
|
49
|
+
_timestamp_utc(Time.now + 3600)
|
24
50
|
end
|
25
51
|
|
26
52
|
_(name) do
|
@@ -17,7 +17,7 @@ insufficients = args[:insufficients] || []
|
|
17
17
|
metric = args[:metric]
|
18
18
|
namespace = args[:namespace]
|
19
19
|
ok_actions = args[:ok_actions] || []
|
20
|
-
period = args[:period] ||
|
20
|
+
period = _cloudwatch_to_period(args[:period] || "5m")
|
21
21
|
statistic = _valid_values(_cloudwatch_to_statistic(args[:statistic]),
|
22
22
|
%w(SampleCount Average Sum Minimum Maximum), "Average")
|
23
23
|
threshold = args[:threshold] || 60
|
data/test/helper_test.rb
CHANGED
@@ -542,6 +542,7 @@ Test _availability_zones({})
|
|
542
542
|
|
543
543
|
def test_timestamp_utc
|
544
544
|
assert_equal _timestamp_utc(Time.local(2016, 4, 1)), "2016-03-31T15:00:00Z"
|
545
|
+
assert_equal _timestamp_utc(Time.local(2016, 4, 1), "cron"), "00 15 31 03 4"
|
545
546
|
end
|
546
547
|
|
547
548
|
def test_timestamp_utc_from_string
|
@@ -3,9 +3,10 @@ require 'abstract_unit'
|
|
3
3
|
class AutoscalingScheduledActionTest < Minitest::Test
|
4
4
|
def test_normal
|
5
5
|
template = <<-EOS
|
6
|
-
_autoscaling_scheduled_action "test", ref_autoscaling: "test", max: "1", min: "1", recurrence:
|
6
|
+
_autoscaling_scheduled_action "test", ref_autoscaling: "test", max: "1", min: "1", recurrence: Time.local(2016, 3, 31, 15)
|
7
7
|
EOS
|
8
8
|
act_template = run_client_as_json(template)
|
9
|
+
start_time = _timestamp_utc(Time.now + 3600)
|
9
10
|
exp_template = <<-EOS
|
10
11
|
{
|
11
12
|
"TestAutoscalingScheduledAction": {
|
@@ -16,7 +17,8 @@ _autoscaling_scheduled_action "test", ref_autoscaling: "test", max: "1", min: "1
|
|
16
17
|
},
|
17
18
|
"MaxSize": "1",
|
18
19
|
"MinSize": "1",
|
19
|
-
"Recurrence": "
|
20
|
+
"Recurrence": "00 06 31 03 4",
|
21
|
+
"StartTime": "#{start_time}"
|
20
22
|
}
|
21
23
|
}
|
22
24
|
}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kumogata-template
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Naoya Nakazawa
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-12-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk
|
@@ -372,7 +372,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
372
372
|
version: '0'
|
373
373
|
requirements: []
|
374
374
|
rubyforge_project:
|
375
|
-
rubygems_version: 2.
|
375
|
+
rubygems_version: 2.5.2
|
376
376
|
signing_key:
|
377
377
|
specification_version: 4
|
378
378
|
summary: Template for Kumogata.
|