kumogata-template 0.0.11 → 0.0.12

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 98ecc2732009db8729e014413122fb339f057592
4
- data.tar.gz: b299501c629511e2751ce2922f143502bd003a55
3
+ metadata.gz: 524f711e9c27851570ed61a4e28d97e379cc6df0
4
+ data.tar.gz: 4f92da4c881b9edda3d10b5f92aad0d7f6b6d2a2
5
5
  SHA512:
6
- metadata.gz: fd0509d6f03d04eeb0e493e07d5b5d90559b5f31ac19a6786062fb749c62f3952abadf05b483d165b11ea2e78481efc0fbc99777e3f9f5d0b3012d5616583803
7
- data.tar.gz: f74154775aef42b6f77b031a32c072287e01e2510fc6d5d8f6ba5a8488e7d16eb76f0ff61c3455a6b4a1fea4fd642e433372873e505d7d8883763f14332395ed
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
- time.utc.strftime("%Y-%m-%dT%H:%M:%SZ")
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.11'
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 = _ref_string("autoscaling", args, "autoscaling group")
9
- desired = args[:desired] || ""
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
- _timestamp_utc_from_string("2016-03-18 00:00")
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
- _timestamp_utc_from_string("2016-03-18 00:00")
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] || 60
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: "0 19 * * *"
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": "0 19 * * *"
20
+ "Recurrence": "00 06 31 03 4",
21
+ "StartTime": "#{start_time}"
20
22
  }
21
23
  }
22
24
  }
@@ -26,7 +26,7 @@ _cloudwatch_alarm "test", actions: "test", alarm_name: "test", namespace: "test"
26
26
  "EvaluationPeriods": "3",
27
27
  "MetricName": "test",
28
28
  "Namespace": "test",
29
- "Period": "60",
29
+ "Period": "300",
30
30
  "Statistic": "Average",
31
31
  "Threshold": "60"
32
32
  }
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.11
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-15 00:00:00.000000000 Z
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.6.4
375
+ rubygems_version: 2.5.2
376
376
  signing_key:
377
377
  specification_version: 4
378
378
  summary: Template for Kumogata.