lono 6.1.11 → 7.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (240) hide show
  1. checksums.yaml +4 -4
  2. data/.cody/acceptance.sh +19 -3
  3. data/.gitignore +2 -2
  4. data/CHANGELOG.md +16 -1
  5. data/README.md +18 -20
  6. data/Rakefile +1 -0
  7. data/lib/lono.rb +7 -5
  8. data/lib/lono/abstract_base.rb +25 -0
  9. data/lib/lono/api/client.rb +30 -0
  10. data/lib/lono/api/proxy.rb +58 -0
  11. data/lib/lono/api/repos.rb +8 -0
  12. data/lib/lono/api/verify.rb +13 -0
  13. data/lib/lono/app_file/base.rb +4 -11
  14. data/lib/lono/app_file/build.rb +1 -1
  15. data/lib/lono/app_file/upload.rb +1 -4
  16. data/lib/lono/autoloader.rb +3 -1
  17. data/lib/lono/aws_services.rb +9 -9
  18. data/lib/lono/aws_services/helper.rb +14 -0
  19. data/lib/lono/aws_services/{util.rb → stack.rb} +1 -9
  20. data/lib/lono/aws_services/stack_set.rb +41 -0
  21. data/lib/lono/blueprint.rb +2 -2
  22. data/lib/lono/blueprint/configset/loader.rb +7 -0
  23. data/lib/lono/blueprint/helper.rb +8 -2
  24. data/lib/lono/blueprint/meta.rb +4 -12
  25. data/lib/lono/blueprint/new.rb +3 -3
  26. data/lib/lono/blueprint/root.rb +6 -26
  27. data/lib/lono/bundle.rb +54 -0
  28. data/lib/lono/cfn.rb +31 -75
  29. data/lib/lono/cfn/base.rb +39 -136
  30. data/lib/lono/cfn/cancel.rb +14 -9
  31. data/lib/lono/cfn/create.rb +15 -19
  32. data/lib/lono/cfn/delete.rb +9 -9
  33. data/lib/lono/cfn/deploy.rb +4 -4
  34. data/lib/lono/cfn/download.rb +27 -9
  35. data/lib/lono/cfn/opts.rb +80 -0
  36. data/lib/lono/cfn/preview/changeset.rb +23 -23
  37. data/lib/lono/cfn/preview/codediff.rb +5 -6
  38. data/lib/lono/cfn/preview/param.rb +10 -10
  39. data/lib/lono/cfn/rollback.rb +5 -5
  40. data/lib/lono/cfn/status.rb +0 -10
  41. data/lib/lono/cfn/update.rb +22 -27
  42. data/lib/lono/clean.rb +3 -3
  43. data/lib/lono/cli.rb +69 -34
  44. data/lib/lono/code.rb +22 -0
  45. data/lib/lono/command.rb +7 -0
  46. data/lib/lono/config_location.rb +6 -13
  47. data/lib/lono/configset.rb +9 -0
  48. data/lib/lono/configset/combiner.rb +128 -0
  49. data/lib/lono/configset/evaluate_file.rb +8 -0
  50. data/lib/lono/configset/list.rb +67 -0
  51. data/lib/lono/configset/loader.rb +98 -0
  52. data/lib/lono/configset/loader/dsl.rb +9 -0
  53. data/lib/lono/configset/materializer/final.rb +10 -0
  54. data/lib/lono/configset/materializer/gems_builder.rb +81 -0
  55. data/lib/lono/configset/materializer/jade.rb +15 -0
  56. data/lib/lono/configset/materializer/source.rb +54 -0
  57. data/lib/lono/configset/meta.rb +19 -0
  58. data/lib/lono/configset/meta/dsl.rb +12 -0
  59. data/lib/lono/configset/new.rb +84 -0
  60. data/lib/lono/configset/preparer.rb +44 -0
  61. data/lib/lono/configset/register/base.rb +121 -0
  62. data/lib/lono/configset/register/blueprint.rb +16 -0
  63. data/lib/lono/configset/register/dsl.rb +15 -0
  64. data/lib/lono/configset/register/project.rb +12 -0
  65. data/lib/lono/configset/registry.rb +34 -0
  66. data/lib/lono/configset/resolver.rb +42 -0
  67. data/lib/lono/conventions.rb +18 -7
  68. data/lib/lono/core.rb +16 -20
  69. data/lib/lono/default/settings.yml +2 -3
  70. data/lib/lono/ext/bundler.rb +7 -0
  71. data/lib/lono/file_uploader.rb +8 -5
  72. data/lib/lono/finder/base.rb +140 -0
  73. data/lib/lono/finder/blueprint.rb +11 -0
  74. data/lib/lono/finder/blueprint/configset.rb +17 -0
  75. data/lib/lono/finder/configset.rb +11 -0
  76. data/lib/lono/generate.rb +93 -0
  77. data/lib/lono/help/blueprint/new.md +0 -1
  78. data/lib/lono/help/cfn/delete.md +1 -1
  79. data/lib/lono/help/cfn/deploy.md +5 -76
  80. data/lib/lono/help/cfn/status.md +0 -4
  81. data/lib/lono/help/cfn/update.md +1 -1
  82. data/lib/lono/help/code/convert.md +51 -0
  83. data/lib/lono/help/code/import.md +30 -0
  84. data/lib/lono/help/configsets.md +24 -0
  85. data/lib/lono/help/generate.md +4 -4
  86. data/lib/lono/help/new.md +1 -2
  87. data/lib/lono/help/sets/delete.md +8 -0
  88. data/lib/lono/help/sets/deploy.md +76 -0
  89. data/lib/lono/help/sets/instances/delete.md +21 -0
  90. data/lib/lono/help/sets/instances/list.md +14 -0
  91. data/lib/lono/help/sets/instances/status.md +15 -0
  92. data/lib/lono/help/sets/instances/sync.md +88 -0
  93. data/lib/lono/help/sets/status.md +23 -0
  94. data/lib/lono/help/upgrade.md +1 -0
  95. data/lib/lono/importer.rb +22 -0
  96. data/lib/lono/importer/base.rb +59 -0
  97. data/lib/lono/importer/converter.rb +19 -0
  98. data/lib/lono/importer/download.rb +46 -0
  99. data/lib/lono/importer/dsl.rb +36 -0
  100. data/lib/lono/importer/erb.rb +31 -0
  101. data/lib/lono/importer/params.rb +56 -0
  102. data/lib/lono/importer/service/coder.rb +81 -0
  103. data/lib/lono/inspector/base.rb +12 -22
  104. data/lib/lono/inspector/graph.rb +1 -1
  105. data/lib/lono/inspector/summary.rb +41 -17
  106. data/lib/lono/jade.rb +103 -0
  107. data/lib/lono/jade/circular.rb +26 -0
  108. data/lib/lono/jadespec.rb +41 -0
  109. data/lib/lono/new.rb +2 -2
  110. data/lib/lono/opts.rb +43 -0
  111. data/lib/lono/output/template.rb +48 -0
  112. data/lib/lono/param.rb +3 -5
  113. data/lib/lono/param/generator.rb +13 -33
  114. data/lib/lono/pro.rb +15 -0
  115. data/lib/lono/pro/base.rb +16 -0
  116. data/lib/lono/pro/repo.rb +27 -0
  117. data/lib/lono/project_checker.rb +4 -29
  118. data/lib/lono/registration.rb +15 -0
  119. data/lib/lono/registration/base.rb +37 -0
  120. data/lib/lono/registration/check.rb +15 -0
  121. data/lib/lono/registration/temp.rb +60 -0
  122. data/lib/lono/registration/user.rb +54 -0
  123. data/lib/lono/script/base.rb +1 -10
  124. data/lib/lono/script/upload.rb +2 -12
  125. data/lib/lono/seed.rb +2 -11
  126. data/lib/lono/seed/base.rb +55 -110
  127. data/lib/lono/sets.rb +38 -0
  128. data/lib/lono/sets/base.rb +45 -0
  129. data/lib/lono/sets/create.rb +30 -0
  130. data/lib/lono/sets/delete.rb +47 -0
  131. data/lib/lono/sets/deploy.rb +11 -0
  132. data/lib/lono/sets/instances.rb +33 -0
  133. data/lib/lono/sets/instances/base.rb +30 -0
  134. data/lib/lono/sets/instances/delete.rb +69 -0
  135. data/lib/lono/sets/instances/list.rb +13 -0
  136. data/lib/lono/sets/instances/opts.rb +29 -0
  137. data/lib/lono/sets/instances/status.rb +12 -0
  138. data/lib/lono/sets/instances/sync.rb +182 -0
  139. data/lib/lono/sets/list.rb +35 -0
  140. data/lib/lono/sets/opts.rb +18 -0
  141. data/lib/lono/sets/preview/codediff.rb +35 -0
  142. data/lib/lono/sets/preview/param.rb +32 -0
  143. data/lib/lono/sets/status.rb +116 -0
  144. data/lib/lono/sets/status/instance.rb +20 -0
  145. data/lib/lono/sets/status/instance/base.rb +120 -0
  146. data/lib/lono/sets/status/instance/completed.rb +35 -0
  147. data/lib/lono/sets/status/instance/deleted.rb +32 -0
  148. data/lib/lono/sets/status/instance/show.rb +7 -0
  149. data/lib/lono/sets/status/instances.rb +111 -0
  150. data/lib/lono/sets/summarize.rb +20 -0
  151. data/lib/lono/sets/time_spent.rb +11 -0
  152. data/lib/lono/sets/update.rb +81 -0
  153. data/lib/lono/template.rb +5 -7
  154. data/lib/lono/template/configset_injector.rb +50 -0
  155. data/lib/lono/template/context.rb +4 -4
  156. data/lib/lono/template/context/loader.rb +4 -16
  157. data/lib/lono/template/evaluate.rb +2 -1
  158. data/lib/lono/template/generator.rb +17 -15
  159. data/lib/lono/template/helper.rb +7 -7
  160. data/lib/lono/template/post_processor.rb +2 -12
  161. data/lib/lono/template/strategy/base.rb +4 -0
  162. data/lib/lono/template/{dsl.rb → strategy/dsl.rb} +4 -6
  163. data/lib/lono/template/{dsl → strategy/dsl}/builder.rb +11 -15
  164. data/lib/lono/template/{dsl → strategy/dsl}/builder/fn.rb +1 -1
  165. data/lib/lono/template/strategy/dsl/builder/helpers.rb +11 -0
  166. data/lib/lono/template/strategy/dsl/builder/helpers/core_helper.rb +14 -0
  167. data/lib/lono/template/strategy/dsl/builder/helpers/file_helper.rb +48 -0
  168. data/lib/lono/template/strategy/dsl/builder/helpers/lookup_helper.rb +27 -0
  169. data/lib/lono/template/strategy/dsl/builder/helpers/s3_helper.rb +13 -0
  170. data/lib/lono/template/strategy/dsl/builder/helpers/tags_helper.rb +39 -0
  171. data/lib/lono/template/{dsl/builder → strategy/dsl/builder/section}/base.rb +6 -17
  172. data/lib/lono/template/{dsl/builder → strategy/dsl/builder/section}/condition.rb +1 -1
  173. data/lib/lono/template/strategy/dsl/builder/section/extensions.rb +9 -0
  174. data/lib/lono/template/{dsl/builder → strategy/dsl/builder/section}/mapping.rb +1 -1
  175. data/lib/lono/template/{dsl/builder/section_methods.rb → strategy/dsl/builder/section/methods.rb} +9 -2
  176. data/lib/lono/template/{dsl/builder → strategy/dsl/builder/section}/output.rb +1 -1
  177. data/lib/lono/template/strategy/dsl/builder/section/parameter.rb +69 -0
  178. data/lib/lono/template/{dsl/builder → strategy/dsl/builder/section}/resource.rb +1 -1
  179. data/lib/lono/template/{dsl/builder → strategy/dsl/builder/section}/resource/property_mover.rb +1 -1
  180. data/lib/lono/template/{dsl/builder → strategy/dsl/builder/section}/section.rb +1 -1
  181. data/lib/lono/template/{dsl → strategy/dsl}/builder/squeezer.rb +1 -1
  182. data/lib/lono/template/strategy/dsl/builder/stringify.rb +15 -0
  183. data/lib/lono/template/{dsl → strategy/dsl}/builder/syntax.rb +3 -2
  184. data/lib/lono/template/strategy/dsl/finalizer.rb +12 -0
  185. data/lib/lono/template/strategy/dsl/finalizer/parameter_groups.rb +56 -0
  186. data/lib/lono/template/{erb.rb → strategy/erb.rb} +5 -5
  187. data/lib/lono/template/strategy/source.rb +8 -0
  188. data/lib/lono/template/template.rb +1 -1
  189. data/lib/lono/template/upload.rb +4 -9
  190. data/lib/lono/template/util.rb +0 -40
  191. data/lib/lono/upgrade.rb +12 -10
  192. data/lib/lono/user_data.rb +4 -4
  193. data/lib/lono/utils/pretty_time.rb +14 -0
  194. data/lib/lono/utils/sure.rb +23 -0
  195. data/lib/lono/version.rb +1 -1
  196. data/lib/lono/yamler/loader.rb +52 -0
  197. data/lib/lono/yamler/validator.rb +51 -0
  198. data/lib/templates/blueprint/%blueprint_name%.gemspec.tt +4 -0
  199. data/lib/templates/blueprint/README.md.tt +1 -1
  200. data/lib/templates/blueprint/seed/configs.rb +2 -2
  201. data/lib/templates/blueprint_types/dsl/app/templates/%blueprint_name%.rb +17 -18
  202. data/lib/templates/blueprint_types/erb/app/templates/%blueprint_name%.yml +63 -4
  203. data/lib/templates/configset/%configset_name%.gemspec.tt +41 -0
  204. data/lib/templates/configset/.gitignore +11 -0
  205. data/lib/templates/configset/CHANGELOG.md +7 -0
  206. data/lib/templates/configset/Gemfile +4 -0
  207. data/lib/templates/configset/README.md.tt +3 -0
  208. data/lib/templates/configset/Rakefile.tt +9 -0
  209. data/lib/templates/configset/lib/configset.yml +20 -0
  210. data/lib/templates/skeleton/.gitignore +1 -0
  211. data/lib/templates/skeleton/Gemfile +0 -1
  212. data/lib/templates/skeleton/README.md +4 -4
  213. data/lib/templates/skeleton/configs/settings.yml +1 -1
  214. data/lono.gemspec +1 -4
  215. metadata +146 -79
  216. data/Guardfile +0 -19
  217. data/lib/lono/app_file.rb +0 -5
  218. data/lib/lono/blueprint/find.rb +0 -90
  219. data/lib/lono/blueprint/info.rb +0 -10
  220. data/lib/lono/blueprint/list.rb +0 -14
  221. data/lib/lono/cfn/current.rb +0 -95
  222. data/lib/lono/cfn/preview.rb +0 -4
  223. data/lib/lono/cfn/suffix.rb +0 -67
  224. data/lib/lono/cfn/util.rb +0 -27
  225. data/lib/lono/help/cfn/current.md +0 -18
  226. data/lib/lono/help/upgrade4.md +0 -25
  227. data/lib/lono/inspector.rb +0 -4
  228. data/lib/lono/output_template.rb +0 -35
  229. data/lib/lono/template/base.rb +0 -13
  230. data/lib/lono/template/dsl/builder/helpers.rb +0 -8
  231. data/lib/lono/template/dsl/builder/helpers/core_helper.rb +0 -107
  232. data/lib/lono/template/dsl/builder/helpers/param_helper.rb +0 -61
  233. data/lib/lono/template/dsl/builder/parameter.rb +0 -39
  234. data/lib/lono/upgrade/upgrade4.rb +0 -175
  235. data/lib/lono/upgrade/upgrade42.rb +0 -36
  236. data/lib/lono/upgrade/upgrade5.rb +0 -55
  237. data/lib/templates/blueprint/.meta/config.yml.tt +0 -4
  238. data/lib/templates/skeleton/Guardfile +0 -12
  239. data/lib/templates/upgrade5/blueprints/main/.lono/config.yml +0 -3
  240. data/lib/templates/upgrade5/blueprints/main/.meta/config.yml +0 -3
@@ -1,14 +1,5 @@
1
1
  class Lono::Script
2
- class Base
2
+ class Base < Lono::AbstractBase
3
3
  SCRIPTS_INFO_PATH = "#{Lono.config.output_path}/data/scripts_info.txt"
4
- include Lono::Blueprint::Root
5
-
6
- def initialize(blueprint, options={})
7
- @blueprint, @options = blueprint, options
8
- @template = @options[:template] || @blueprint
9
- Lono::ProjectChecker.check
10
- set_blueprint_root(@blueprint)
11
- Lono::ProjectChecker.empty_templates
12
- end
13
4
  end
14
5
  end
@@ -3,6 +3,7 @@ require "filesize"
3
3
  class Lono::Script
4
4
  class Upload < Base
5
5
  include Lono::AwsServices
6
+ include Lono::Utils::PrettyTime
6
7
 
7
8
  def run
8
9
  Lono::ProjectChecker.check
@@ -18,7 +19,7 @@ class Lono::Script
18
19
  start_time = Time.now
19
20
  obj.upload_file(tarball_path)
20
21
  time_took = pretty_time(Time.now-start_time).color(:green)
21
- puts "Time to upload code to s3: #{time_took}"
22
+ puts "Time took to upload code to s3: #{time_took}"
22
23
  end
23
24
 
24
25
  def filesize
@@ -50,16 +51,5 @@ class Lono::Script
50
51
  def tarball_path
51
52
  IO.read(SCRIPTS_INFO_PATH).strip
52
53
  end
53
-
54
- # http://stackoverflow.com/questions/4175733/convert-duration-to-hoursminutesseconds-or-similar-in-rails-3-or-ruby
55
- def pretty_time(total_seconds)
56
- minutes = (total_seconds / 60) % 60
57
- seconds = total_seconds % 60
58
- if total_seconds < 60
59
- "#{seconds.to_i}s"
60
- else
61
- "#{minutes.to_i}m #{seconds.to_i}s"
62
- end
63
- end
64
54
  end
65
55
  end
@@ -1,18 +1,9 @@
1
1
  module Lono
2
- class Seed
3
- include Lono::Blueprint::Root
4
- include Lono::Conventions
5
-
6
- def initialize(blueprint, options={})
7
- @blueprint, @options = blueprint, options
8
- set_blueprint_root(@blueprint)
9
- @template, @param = template_param_convention(options)
10
- end
11
-
2
+ class Seed < AbstractBase
12
3
  def create
13
4
  puts "Creating starter config files for #{@blueprint}"
14
5
  configs_class = load_configs_class # ::Configs or Lono::Seed::Base
15
- configs = configs_class.new(@blueprint, @options)
6
+ configs = configs_class.new(@options)
16
7
  # The Configs class implements: variables
17
8
  configs.run # setup the instance variables
18
9
  end
@@ -12,27 +12,23 @@ require "yaml"
12
12
  # Note there is no params method to hook. The Base class handles params well.
13
13
  #
14
14
  class Lono::Seed
15
- class Base
16
- include Lono::Blueprint::Root
15
+ class Base < Lono::AbstractBase
17
16
  include Lono::AwsServices
18
- include Lono::Conventions
19
17
  include ServiceRole
20
18
 
21
19
  # What's needed for a Thor::Group or "Sequence"
22
20
  # Gives us Thor::Actions commands like create_file
23
21
  include Thor::Actions
24
22
  include Thor::Base
23
+ # Override Thor::Base initialize
24
+ def initialize(options={})
25
+ reinitialize(options)
26
+ end
25
27
 
26
28
  extend Memoist
27
29
 
28
- # attr_reader :options
29
- def initialize(blueprint, options)
30
- @blueprint, @options = blueprint, options
31
- @template, @param = template_param_convention(options)
32
- end
33
-
34
30
  def run
35
- check_dsl_type!
31
+ generate_template
36
32
  setup
37
33
  self.destination_root = Dir.pwd # Thor::Actions require destination_root to be set
38
34
  create_params
@@ -40,74 +36,71 @@ class Lono::Seed
40
36
  finish
41
37
  end
42
38
 
43
- def create_params
44
- return unless params
45
-
46
- # Only supporting the main blueprint for now
47
- path = "#{Lono.config.templates_path}/#{@blueprint}.rb"
48
- if File.exist?(path)
49
- create_param_file(path)
50
- end
51
-
52
- # TODO: detect and write multiple templates to different paths
53
- # with_each_template do |path|
54
- # create_param_file(path)
55
- # end
39
+ def generate_template
40
+ Lono::Template::Generator.new(@options).run
56
41
  end
57
42
 
58
- def params
59
- true
43
+ def create_params
44
+ return unless params
45
+ create_param_file
60
46
  end
61
47
 
62
- def create_param_file(app_template_path)
63
- parameters = parameters(app_template_path)
64
-
65
- lines = []
66
- required = required(parameters)
67
- lines << "# Required parameters:" unless required.empty?
68
- required.each do |name, data|
69
- example = description_example(data["Description"])
70
- lines << "#{name}=#{example}"
71
- end
72
- optional = optional(parameters)
73
- lines << "# Optional parameters:" unless optional.empty?
74
- optional.each do |name, data|
75
- value = default_value(data)
76
- lines << "# #{name}=#{value}"
77
- end
78
-
79
- if lines.empty?
48
+ def create_param_file
49
+ @output_template = Lono::Output::Template.new(@blueprint, @template)
50
+ if @output_template.parameters.empty?
80
51
  puts "Template has no parameters."
81
52
  return
82
53
  end
83
54
 
84
- content = lines.join("\n") + "\n"
55
+ # Generate by parameter group first
56
+ lines, shown = [], []
57
+ @output_template.parameter_groups.each do |label, parameters|
58
+ lines << "# Parameter Group: #{label}"
59
+ parameters.each do |name|
60
+ lines << parameter_line(name)
61
+ shown << name
62
+ end
63
+ lines << ""
64
+ end if @output_template.parameter_groups
65
+
66
+ # Then generate the rest
67
+ @output_template.parameters.each do |name, data|
68
+ lines << parameter_line(name) unless shown.include?(name)
69
+ end
70
+
71
+ content = lines.join("\n")
85
72
  dest_path = "configs/#{@blueprint}/params/#{Lono.env}.txt" # only support environment level parameters for now
86
73
  create_file(dest_path, content) # Thor::Action
87
74
  end
88
75
 
89
- def create_variables
90
- return unless variables
91
- dest_path = "configs/#{@blueprint}/variables/#{Lono.env}.rb"
92
- create_file(dest_path, variables) # Thor::Action
76
+ def parameter_line(name)
77
+ data = @output_template.parameters[name]
78
+ example = description_example(data["Description"])
79
+ if data["Default"].nil?
80
+ line = "#{name}=#{example} # (required)"
81
+ else
82
+ default = data["Default"]
83
+ line = "# #{name}=#{default}"
84
+ line = "#{line} # #{example}" if example
85
+ end
86
+ line
93
87
  end
94
88
 
95
- def check_dsl_type!
96
- dsl_type = template_type == 'dsl'
97
- unless dsl_type
98
- puts "Detected template_type: #{template_type}"
99
- puts "lono seed only supports dsl template types currently."
100
- exit 1
101
- end
89
+ def description_example(description)
90
+ return unless description
91
+ md = description.match(/(Example|IE): (.*)/)
92
+ return unless md
93
+ md[2]
102
94
  end
103
95
 
104
- def template_type
105
- blueprint_root = find_blueprint_root(@blueprint)
106
- meta_config = "#{blueprint_root}/.meta/config.yml"
107
- return false unless File.exist?(meta_config)
96
+ def params
97
+ true
98
+ end
108
99
 
109
- meta = YAML.load_file(meta_config)
110
- meta['template_type']
100
+ def create_variables
101
+ return unless variables
102
+ dest_path = "configs/#{@blueprint}/variables/#{Lono.env}.rb"
103
+ create_file(dest_path, variables) # Thor::Action
111
104
  end
112
105
 
113
106
  def setup; end
@@ -118,53 +111,5 @@ class Lono::Seed
118
111
  def variables
119
112
  false
120
113
  end
121
-
122
- def write(path, content)
123
- FileUtils.mkdir_p(File.dirname(path))
124
- IO.write(path, content)
125
- end
126
-
127
- def description_example(description)
128
- default = ''
129
- return default unless description
130
- md = description.match(/(Example|IE): (.*)/)
131
- return default unless md
132
- md[2]
133
- end
134
-
135
- def default_value(data)
136
- value = data["Default"]
137
- # Dont use !blank? since there can be false optional values
138
- # Also dont use .empty? since value can be an Integer
139
- if value.nil? || value == ''
140
- description_example(data["Description"])
141
- else
142
- value
143
- end
144
- end
145
-
146
- def parameters(app_template_path)
147
- builder = Lono::Template::Dsl::Builder.new(app_template_path, @blueprint, quiet: false)
148
- template = builder.template
149
- template["Parameters"] || []
150
- end
151
- memoize :parameters
152
-
153
- def required(parameters)
154
- parameters.select { |logical_id, p| p["Default"].nil? } # allow for false
155
- end
156
-
157
- def optional(parameters)
158
- parameters.select { |logical_id, p| !p["Default"].nil? } # allow for false
159
- end
160
-
161
- private
162
- def with_each_template
163
- paths = Dir.glob("#{Lono.config.templates_path}/**/*.rb")
164
- files = paths.select{ |e| File.file?(e) }
165
- files.each do |path|
166
- yield(path)
167
- end
168
- end
169
114
  end
170
- end
115
+ end
@@ -0,0 +1,38 @@
1
+ module Lono
2
+ class Sets < Command
3
+ opts = Opts.new(self)
4
+
5
+ desc "deploy STACK_SET", "Deploy CloudFormation stack set."
6
+ long_desc Help.text("sets/deploy")
7
+ opts.deploy
8
+ def deploy(stack)
9
+ Deploy.new(options.merge(stack: stack)).run
10
+ end
11
+
12
+ desc "status STACK_SET", "Show current status of stack set."
13
+ long_desc Help.text("sets/status")
14
+ def status(stack)
15
+ status = Status.new(@options.merge(stack: stack, delay_for_threads: false))
16
+ success = status.show
17
+ exit 3 unless success
18
+ end
19
+
20
+ desc "delete STACK_SET", "Delete CloudFormation stack set."
21
+ long_desc Lono::Help.text("sets/delete")
22
+ option :sure, type: :boolean, desc: "Skips are you sure prompt"
23
+ def delete(stack)
24
+ Delete.new(options.merge(stack: stack)).run
25
+ end
26
+
27
+ desc "list", "List CloudFormation stack sets."
28
+ long_desc Lono::Help.text("sets/list")
29
+ option :status, default: "active", desc: "active, all or deleted"
30
+ def list
31
+ List.new(options).run
32
+ end
33
+
34
+ desc "instances SUBCOMMAND", "instances subcommands"
35
+ long_desc Help.text("sets/instances")
36
+ subcommand "instances", Instances
37
+ end
38
+ end
@@ -0,0 +1,45 @@
1
+ class Lono::Sets
2
+ class Base < Lono::Cfn::Base
3
+ def run
4
+ generate_all
5
+ save
6
+ end
7
+
8
+ def exit_unless_updatable!
9
+ return true if ENV['LONO_ENV']
10
+ return false if @options[:noop]
11
+
12
+ status = Status.new(@options) # using status for completed?
13
+ return if status.stack_instances.empty?
14
+ completed = status.completed?(status.stack_set_status)
15
+ unless completed
16
+ puts "Cannot update stack set because #{@stack} is not in an updatable state. Stack set status: #{status.stack_set_status}".color(:red)
17
+ quit(1)
18
+ end
19
+ end
20
+
21
+ def build_options
22
+ parameters = generate_all
23
+ options = {
24
+ stack_set_name: @stack,
25
+ parameters: parameters,
26
+ capabilities: capabilities, # ["CAPABILITY_IAM", "CAPABILITY_NAMED_IAM"]
27
+ }
28
+ options[:tags] = tags unless tags.empty?
29
+ options[:operation_preferences] = operation_preferences unless operation_preferences.empty?
30
+ options.reject! {|k, v| v.nil? }
31
+ set_template_url!(options)
32
+ options
33
+ end
34
+
35
+ def operation_preferences
36
+ o = {}
37
+ o[:failure_tolerance_count] = @options[:failure_tolerance_count]
38
+ o[:failure_tolerance_percentage] = @options[:failure_tolerance_percentage]
39
+ o[:max_concurrent_count] = @options[:max_concurrent_count]
40
+ o[:max_concurrent_percentage] = @options[:max_concurrent_percentage]
41
+ o.reject! {|k, v| v.nil? }
42
+ o
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,30 @@
1
+ class Lono::Sets
2
+ class Create < Base
3
+ def save
4
+ message = "Creating #{@stack.color(:green)} stack set."
5
+ if @options[:noop]
6
+ puts "NOOP #{message}"
7
+ return
8
+ end
9
+
10
+ if stack_set_exists?(@stack)
11
+ puts "Cannot create #{@stack.color(:green)} stack set because it already exists.".color(:red)
12
+ return
13
+ end
14
+
15
+ unless File.exist?(template_path)
16
+ puts "Cannot create #{@stack.color(:green)} template not found: #{template_path}."
17
+ return
18
+ end
19
+
20
+ options = build_options
21
+ show_options(options, "cfn.create_stack_set")
22
+
23
+ sure?("Are you sure you want to create the #{@stack} stack set?")
24
+
25
+ cfn.create_stack_set(options) # resp.stack_set_id => String. There is no resp.operation_id
26
+ puts message unless @options[:mute]
27
+ true # There is no resp.operation_id
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,47 @@
1
+ class Lono::Sets
2
+ class Delete
3
+ include Lono::AwsServices
4
+ include Lono::Sets::Summarize
5
+ include Lono::Utils::Sure
6
+
7
+ def initialize(options={})
8
+ @options = options
9
+ @stack = options.delete(:stack)
10
+ end
11
+
12
+ def run
13
+ message = "Deleting #{@stack} stack set."
14
+ if @options[:noop]
15
+ puts "NOOP #{message}"
16
+ else
17
+ sure?("Are you sure you want to delete the #{@stack} stack set?", "Be sure that it emptied of stack instances first.")
18
+
19
+ if stack_set_exists?(@stack)
20
+ cfn.delete_stack_set(stack_set_name: @stack) # resp is an Empty structure, so much get operation_id from status
21
+ puts message
22
+ else
23
+ puts "#{@stack.inspect} stack set does not exist".color(:red)
24
+ return
25
+ end
26
+ end
27
+
28
+ return true if @options[:noop] || !@options[:wait]
29
+
30
+ status = Status.new(@options)
31
+ success = status.wait
32
+ operation_id = status.operation_id # getting operation_id from status because cfn.delete_stack_set resp is an Empty structure
33
+ summarize(operation_id)
34
+ exit 1 unless success
35
+
36
+ rescue Aws::CloudFormation::Errors::StackSetNotEmptyException => e
37
+ puts "ERROR: #{e.class}: #{e.message}".color(:red)
38
+ puts <<~EOL
39
+ The stack set must be empty before deleting. Cannot delete stack set until all stack instances are first
40
+ deleted. If you want to delete all stack instances you can use:
41
+
42
+ lono sets instances delete #{@stack} --all
43
+
44
+ EOL
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,11 @@
1
+ class Lono::Sets
2
+ class Deploy < Base
3
+ def run
4
+ if stack_set_exists?(@stack)
5
+ Update.new(@options).run
6
+ else
7
+ Create.new(@options).run
8
+ end
9
+ end
10
+ end
11
+ end