motherbrain 0.0.0.placeholder → 0.13.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (259) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/.ruby-version +1 -0
  4. data/.travis.yml +9 -0
  5. data/CHANGELOG.md +196 -0
  6. data/COMMANDS.md +9 -0
  7. data/CONTRIBUTING.md +24 -0
  8. data/Dockerfile +26 -0
  9. data/Gemfile +60 -2
  10. data/Guardfile +30 -0
  11. data/LICENSE +10 -0
  12. data/MANIFESTS.md +90 -0
  13. data/OPERATORS_GUIDE.md +195 -0
  14. data/PLUGINS.md +268 -0
  15. data/README.md +304 -16
  16. data/Thorfile +123 -0
  17. data/VAGRANT.md +116 -0
  18. data/bin/boot +9 -0
  19. data/bin/mb +5 -0
  20. data/bin/mbsrv +5 -0
  21. data/config.json +32 -0
  22. data/features/cli/bootstrap_command/configurable_scripts.feature +32 -0
  23. data/features/cli/configure_command.feature +57 -0
  24. data/features/cli/environment_command/create_command.feature +22 -0
  25. data/features/cli/environment_command/destroy_command.feature +33 -0
  26. data/features/cli/environment_command/from_command.feature +29 -0
  27. data/features/cli/environment_command/list_command.feature +0 -0
  28. data/features/cli/node_limiting.feature +47 -0
  29. data/features/cli/plugin_command/list_command.feature +46 -0
  30. data/features/cli/service_command/service_command.feature +21 -0
  31. data/features/cli/template_command.feature +10 -0
  32. data/features/cli/validate_config.feature +46 -0
  33. data/features/step_definitions/bootstrap_steps.rb +57 -0
  34. data/features/step_definitions/chef_server_steps.rb +3 -0
  35. data/features/step_definitions/configuration_steps.rb +18 -0
  36. data/features/step_definitions/core_cli_steps.rb +33 -0
  37. data/features/step_definitions/environment_steps.rb +43 -0
  38. data/features/step_definitions/node_steps.rb +3 -0
  39. data/features/step_definitions/plugin_steps.rb +15 -0
  40. data/features/step_definitions/template_steps.rb +7 -0
  41. data/features/support/env.rb +68 -0
  42. data/lib/mb/api.rb +8 -0
  43. data/lib/mb/api/application.rb +7 -0
  44. data/lib/mb/api/endpoint.rb +5 -0
  45. data/lib/mb/api/helpers.rb +38 -0
  46. data/lib/mb/api/v1.rb +56 -0
  47. data/lib/mb/api/v1/config_endpoint.rb +12 -0
  48. data/lib/mb/api/v1/environments_endpoint.rb +174 -0
  49. data/lib/mb/api/v1/jobs_endpoint.rb +31 -0
  50. data/lib/mb/api/v1/plugins_endpoint.rb +90 -0
  51. data/lib/mb/api/validators.rb +5 -0
  52. data/lib/mb/api/validators/sem_ver.rb +18 -0
  53. data/lib/mb/application.rb +148 -0
  54. data/lib/mb/berkshelf.rb +50 -0
  55. data/lib/mb/bootstrap.rb +9 -0
  56. data/lib/mb/bootstrap/manager.rb +250 -0
  57. data/lib/mb/bootstrap/manifest.rb +131 -0
  58. data/lib/mb/bootstrap/routine.rb +199 -0
  59. data/lib/mb/bootstrap/template.rb +73 -0
  60. data/lib/mb/bootstrap/worker.rb +227 -0
  61. data/lib/mb/chef.rb +6 -0
  62. data/lib/mb/chef/config.rb +69 -0
  63. data/lib/mb/chef/run_list_item.rb +115 -0
  64. data/lib/mb/chef_mutex.rb +304 -0
  65. data/lib/mb/clean_room_base.rb +39 -0
  66. data/lib/mb/cli.rb +50 -0
  67. data/lib/mb/cli/base.rb +51 -0
  68. data/lib/mb/cli/shell.rb +29 -0
  69. data/lib/mb/cli/shell/basic.rb +11 -0
  70. data/lib/mb/cli/shell/color.rb +11 -0
  71. data/lib/mb/cli/shell/ext.rb +41 -0
  72. data/lib/mb/cli/sub_command.rb +95 -0
  73. data/lib/mb/cli/sub_command/component.rb +56 -0
  74. data/lib/mb/cli/sub_command/plugin.rb +232 -0
  75. data/lib/mb/cli_client.rb +178 -0
  76. data/lib/mb/cli_gateway.rb +426 -0
  77. data/lib/mb/cli_gateway/sub_commands.rb +3 -0
  78. data/lib/mb/cli_gateway/sub_commands/environment.rb +124 -0
  79. data/lib/mb/cli_gateway/sub_commands/plugin.rb +148 -0
  80. data/lib/mb/command.rb +88 -0
  81. data/lib/mb/command_invoker.rb +235 -0
  82. data/lib/mb/command_invoker/worker.rb +40 -0
  83. data/lib/mb/command_runner.rb +233 -0
  84. data/lib/mb/component.rb +245 -0
  85. data/lib/mb/config.rb +275 -0
  86. data/lib/mb/config_manager.rb +75 -0
  87. data/lib/mb/console.rb +35 -0
  88. data/lib/mb/cookbook_metadata.rb +73 -0
  89. data/lib/mb/core_ext.rb +3 -0
  90. data/lib/mb/core_ext/dir.rb +37 -0
  91. data/lib/mb/core_ext/enumerable.rb +48 -0
  92. data/lib/mb/core_ext/file.rb +24 -0
  93. data/lib/mb/core_ext/signal.rb +11 -0
  94. data/lib/mb/environment_manager.rb +195 -0
  95. data/lib/mb/error_handler.rb +212 -0
  96. data/lib/mb/errors.rb +693 -0
  97. data/lib/mb/file_system.rb +60 -0
  98. data/lib/mb/file_system/tempfile.rb +25 -0
  99. data/lib/mb/gear.rb +154 -0
  100. data/lib/mb/gears.rb +8 -0
  101. data/lib/mb/gears/dynamic_service.rb +218 -0
  102. data/lib/mb/gears/jmx.rb +24 -0
  103. data/lib/mb/gears/jmx/action.rb +46 -0
  104. data/lib/mb/gears/mysql.rb +20 -0
  105. data/lib/mb/gears/mysql/action.rb +190 -0
  106. data/lib/mb/gears/service.rb +163 -0
  107. data/lib/mb/gears/service/action.rb +58 -0
  108. data/lib/mb/gears/service/action_runner.rb +161 -0
  109. data/lib/mb/grape_ext.rb +3 -0
  110. data/lib/mb/grape_ext/endpoint.rb +13 -0
  111. data/lib/mb/group.rb +143 -0
  112. data/lib/mb/job.rb +183 -0
  113. data/lib/mb/job/state_machine.rb +34 -0
  114. data/lib/mb/job/states.rb +46 -0
  115. data/lib/mb/job_manager.rb +96 -0
  116. data/lib/mb/job_record.rb +67 -0
  117. data/lib/mb/job_ticket.rb +25 -0
  118. data/lib/mb/lock_manager.rb +116 -0
  119. data/lib/mb/logging.rb +134 -0
  120. data/lib/mb/logging/basic_format.rb +31 -0
  121. data/lib/mb/manifest.rb +128 -0
  122. data/lib/mb/mixin.rb +3 -0
  123. data/lib/mb/mixin/attribute_setting.rb +265 -0
  124. data/lib/mb/mixin/coded_exit.rb +49 -0
  125. data/lib/mb/mixin/locks.rb +54 -0
  126. data/lib/mb/mixin/services.rb +100 -0
  127. data/lib/mb/node_filter.rb +97 -0
  128. data/lib/mb/node_querier.rb +527 -0
  129. data/lib/mb/plugin.rb +300 -0
  130. data/lib/mb/plugin_manager.rb +589 -0
  131. data/lib/mb/provisioner.rb +186 -0
  132. data/lib/mb/provisioner/manager.rb +213 -0
  133. data/lib/mb/provisioner/manifest.rb +125 -0
  134. data/lib/mb/provisioner/provision_data.rb +96 -0
  135. data/lib/mb/provisioners.rb +5 -0
  136. data/lib/mb/provisioners/aws.rb +395 -0
  137. data/lib/mb/rest_gateway.rb +72 -0
  138. data/lib/mb/ridley_ext.rb +5 -0
  139. data/lib/mb/ridley_ext/cookbook_object.rb +15 -0
  140. data/lib/mb/srv_ctl.rb +183 -0
  141. data/lib/mb/test.rb +104 -0
  142. data/lib/mb/thor_ext.rb +49 -0
  143. data/lib/mb/upgrade.rb +6 -0
  144. data/lib/mb/upgrade/manager.rb +85 -0
  145. data/lib/mb/upgrade/worker.rb +149 -0
  146. data/lib/mb/version.rb +1 -1
  147. data/lib/motherbrain.rb +166 -2
  148. data/man/man_helper.rb +81 -0
  149. data/man/mb.1 +494 -0
  150. data/man/mb.1.html +300 -0
  151. data/man/mb.1.ronn.erb +62 -0
  152. data/motherbrain.gemspec +56 -20
  153. data/scripts/node_name.rb +14 -0
  154. data/spec/fixtures/cb_metadata.json +7 -0
  155. data/spec/fixtures/cb_metadata.rb +14 -0
  156. data/spec/fixtures/fake_id_rsa +27 -0
  157. data/spec/fixtures/fake_key.pem +27 -0
  158. data/spec/fixtures/myface-0.1.0/metadata.rb +14 -0
  159. data/spec/fixtures/myface-0.1.0/motherbrain.rb +0 -0
  160. data/spec/fixtures/test_env.json +15 -0
  161. data/spec/spec_helper.rb +67 -0
  162. data/spec/support/actor_mocking.rb +7 -0
  163. data/spec/support/berkshelf.rb +24 -0
  164. data/spec/support/chef_server.rb +102 -0
  165. data/spec/support/doubles.rb +11 -0
  166. data/spec/support/klass.rb +10 -0
  167. data/spec/support/matchers/each.rb +12 -0
  168. data/spec/support/matchers/error_codes.rb +5 -0
  169. data/spec/support/matchers/exit_codes.rb +57 -0
  170. data/spec/support/matchers/jobs.rb +11 -0
  171. data/spec/support/spec_helpers.rb +145 -0
  172. data/spec/unit/mb/api/application_spec.rb +11 -0
  173. data/spec/unit/mb/api/helpers_spec.rb +5 -0
  174. data/spec/unit/mb/api/v1/config_endpoint_spec.rb +19 -0
  175. data/spec/unit/mb/api/v1/environments_endpoint_spec.rb +71 -0
  176. data/spec/unit/mb/api/v1/jobs_endpoint_spec.rb +24 -0
  177. data/spec/unit/mb/api/v1/plugins_endpoint_spec.rb +298 -0
  178. data/spec/unit/mb/api/v1_spec.rb +37 -0
  179. data/spec/unit/mb/api/validators/sem_ver_spec.rb +5 -0
  180. data/spec/unit/mb/application_spec.rb +19 -0
  181. data/spec/unit/mb/berkshelf_spec.rb +38 -0
  182. data/spec/unit/mb/bootstrap/manager_spec.rb +347 -0
  183. data/spec/unit/mb/bootstrap/manifest_spec.rb +333 -0
  184. data/spec/unit/mb/bootstrap/routine_spec.rb +393 -0
  185. data/spec/unit/mb/bootstrap/template_spec.rb +100 -0
  186. data/spec/unit/mb/bootstrap/worker_spec.rb +194 -0
  187. data/spec/unit/mb/chef/config_spec.rb +33 -0
  188. data/spec/unit/mb/chef/run_list_item_spec.rb +34 -0
  189. data/spec/unit/mb/chef_mutex_spec.rb +314 -0
  190. data/spec/unit/mb/clean_room_base_spec.rb +31 -0
  191. data/spec/unit/mb/cli/base_spec.rb +43 -0
  192. data/spec/unit/mb/cli/shell/basic_spec.rb +5 -0
  193. data/spec/unit/mb/cli/shell/color_spec.rb +5 -0
  194. data/spec/unit/mb/cli/shell/ext_spec.rb +11 -0
  195. data/spec/unit/mb/cli/shell_spec.rb +38 -0
  196. data/spec/unit/mb/cli/sub_command/base_spec.rb +102 -0
  197. data/spec/unit/mb/cli/sub_command/component_spec.rb +5 -0
  198. data/spec/unit/mb/cli/sub_command/plugin_spec.rb +91 -0
  199. data/spec/unit/mb/cli/sub_command_spec.rb +43 -0
  200. data/spec/unit/mb/cli/ui.rb +0 -0
  201. data/spec/unit/mb/cli_client_spec.rb +51 -0
  202. data/spec/unit/mb/cli_gateway_spec.rb +386 -0
  203. data/spec/unit/mb/command_invoker/worker_spec.rb +43 -0
  204. data/spec/unit/mb/command_invoker_spec.rb +230 -0
  205. data/spec/unit/mb/command_runner_spec.rb +299 -0
  206. data/spec/unit/mb/command_spec.rb +76 -0
  207. data/spec/unit/mb/component_spec.rb +185 -0
  208. data/spec/unit/mb/config_manager_spec.rb +31 -0
  209. data/spec/unit/mb/config_spec.rb +408 -0
  210. data/spec/unit/mb/cookbook_metadata_spec.rb +89 -0
  211. data/spec/unit/mb/core_ext/dir_spec.rb +92 -0
  212. data/spec/unit/mb/core_ext/enumerable_spec.rb +104 -0
  213. data/spec/unit/mb/core_ext/file_spec.rb +58 -0
  214. data/spec/unit/mb/core_ext/signal_spec.rb +24 -0
  215. data/spec/unit/mb/environment_manager_spec.rb +166 -0
  216. data/spec/unit/mb/error_handler_spec.rb +173 -0
  217. data/spec/unit/mb/errors_spec.rb +132 -0
  218. data/spec/unit/mb/file_system/tempfile_spec.rb +14 -0
  219. data/spec/unit/mb/file_system_spec.rb +69 -0
  220. data/spec/unit/mb/gear_spec.rb +125 -0
  221. data/spec/unit/mb/gears/dynamic_service_spec.rb +187 -0
  222. data/spec/unit/mb/gears/jmx/action_spec.rb +34 -0
  223. data/spec/unit/mb/gears/jmx_spec.rb +32 -0
  224. data/spec/unit/mb/gears/mysql/action_spec.rb +118 -0
  225. data/spec/unit/mb/gears/mysql_spec.rb +21 -0
  226. data/spec/unit/mb/gears/service/action_runner_spec.rb +182 -0
  227. data/spec/unit/mb/gears/service/action_spec.rb +44 -0
  228. data/spec/unit/mb/gears/service_spec.rb +124 -0
  229. data/spec/unit/mb/group_spec.rb +280 -0
  230. data/spec/unit/mb/job_manager_spec.rb +56 -0
  231. data/spec/unit/mb/job_record_spec.rb +60 -0
  232. data/spec/unit/mb/job_spec.rb +201 -0
  233. data/spec/unit/mb/locks_manager_spec.rb +88 -0
  234. data/spec/unit/mb/logging_spec.rb +133 -0
  235. data/spec/unit/mb/manifest_spec.rb +105 -0
  236. data/spec/unit/mb/mixin/attribute_setting_spec.rb +180 -0
  237. data/spec/unit/mb/mixin/coded_exit_spec.rb +25 -0
  238. data/spec/unit/mb/mixin/locks_spec.rb +32 -0
  239. data/spec/unit/mb/mixin/services_spec.rb +75 -0
  240. data/spec/unit/mb/node_filter_spec.rb +86 -0
  241. data/spec/unit/mb/node_querier_spec.rb +532 -0
  242. data/spec/unit/mb/plugin_manager_spec.rb +724 -0
  243. data/spec/unit/mb/plugin_spec.rb +247 -0
  244. data/spec/unit/mb/provisioner/manager_spec.rb +141 -0
  245. data/spec/unit/mb/provisioner/manifest_spec.rb +182 -0
  246. data/spec/unit/mb/provisioner/provision_data_spec.rb +113 -0
  247. data/spec/unit/mb/provisioner_spec.rb +251 -0
  248. data/spec/unit/mb/provisioners/aws_spec.rb +392 -0
  249. data/spec/unit/mb/provisioners/environment_factory_spec.rb +108 -0
  250. data/spec/unit/mb/rest_gateway_spec.rb +13 -0
  251. data/spec/unit/mb/ridley_ext/cookbook_object_spec.rb +105 -0
  252. data/spec/unit/mb/srv_ctl_spec.rb +142 -0
  253. data/spec/unit/mb/upgrade/manager_spec.rb +37 -0
  254. data/spec/unit/mb/upgrade/worker_spec.rb +219 -0
  255. data/spec/unit/motherbrain_spec.rb +58 -0
  256. data/templates/bootstrap.json +8 -0
  257. data/templates/motherbrain.rb +44 -0
  258. metadata +694 -15
  259. data/Rakefile +0 -1
@@ -0,0 +1,11 @@
1
+ module MotherBrain
2
+ module Cli
3
+ module Shell
4
+ class Basic < Thor::Shell::Basic
5
+ include MB::Cli::Shell::Ext
6
+
7
+ alias_method :fatal, :error
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module MotherBrain
2
+ module Cli
3
+ module Shell
4
+ class Color < Thor::Shell::Color
5
+ include MB::Cli::Shell::Ext
6
+
7
+ alias_method :fatal, :error
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,41 @@
1
+ module MotherBrain
2
+ module Cli
3
+ module Shell
4
+ module Ext
5
+ class << self
6
+ def included(base)
7
+ base.send(:include, ClassMethods)
8
+ base.extend(ClassMethods)
9
+ end
10
+ end
11
+
12
+ module ClassMethods
13
+ # Mute the output of this instance of UI until {#unmute!} is called
14
+ def mute!
15
+ @mute = true
16
+ end
17
+
18
+ # Unmute the output of this instance of UI until {#mute!} is called
19
+ def unmute!
20
+ @mute = false
21
+ end
22
+
23
+ def say(message = "", color = nil, force_new_line = nil)
24
+ return if quiet?
25
+
26
+ super(message, color)
27
+ end
28
+ alias_method :info, :say
29
+
30
+ def warn(message)
31
+ say(message, :yellow)
32
+ end
33
+
34
+ def deprecated(message)
35
+ warn("[DEPRECATION] #{message}")
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,95 @@
1
+ module MotherBrain
2
+ module Cli
3
+ # Generates SubCommands for Thor from motherbrain plugins or pieces of motherbrain plugins
4
+ module SubCommand
5
+ autoload :Component, 'mb/cli/sub_command/component'
6
+ autoload :Plugin, 'mb/cli/sub_command/plugin'
7
+
8
+ class << self
9
+ # Generate a new SubCommand for Thor from a motherbrain plugin or component
10
+ #
11
+ # @param [MB::Plugin, MB::Component] object
12
+ #
13
+ # @raise [ArgumentError]
14
+ #
15
+ # @return [SubCommand::Plugin, SubCommand::Component]
16
+ def new(object)
17
+ case object
18
+ when MB::Plugin
19
+ SubCommand::Plugin.fabricate(object)
20
+ when MB::Component
21
+ SubCommand::Component.fabricate(object)
22
+ else
23
+ raise ::ArgumentError, "don't know how to fabricate a subcommand for a '#{object.class}'"
24
+ end
25
+ end
26
+ end
27
+
28
+ # A base class that all dynamically generated SubCommands inherit from
29
+ class Base < Cli::Base
30
+ class << self
31
+ alias_method :name, :namespace
32
+
33
+ # @raise [AbstractFunction] if the inheriting class does not implement this function
34
+ def fabricate(*args)
35
+ raise AbstractFunction, "Class '#{self}' must implement abstract function"
36
+ end
37
+
38
+ def usage
39
+ "#{name} [COMMAND]"
40
+ end
41
+
42
+ def description
43
+ raise AbstractFunction
44
+ end
45
+
46
+ # Define a new Thor task from the given {MotherBrain::Command}
47
+ #
48
+ # @param [MB::Command] command
49
+ def define_task(command)
50
+ plugin_name = command.plugin.name
51
+ plugin_version = command.plugin.version.to_s
52
+ component_name = nil
53
+
54
+ if command.type == :component
55
+ component_name = command.scope.name
56
+ end
57
+
58
+ environment = CliGateway.invoked_opts[:environment]
59
+ execute_args = command.execute.parameters.collect { |type, parameter| parameter }
60
+
61
+ usage = command.name
62
+ if execute_args.any?
63
+ usage += " #{execute_args.map(&:upcase).join(' ')}"
64
+ end
65
+
66
+ method_option :force,
67
+ type: :boolean,
68
+ default: false,
69
+ desc: "Run command even if the environment is locked",
70
+ aliases: "-f"
71
+ method_option :only,
72
+ type: :array,
73
+ default: nil,
74
+ desc: "Run command only on the given hostnames or IPs",
75
+ aliases: "-o"
76
+ desc(usage, command.description)
77
+ define_method command.name.to_sym, ->(*task_args) do
78
+ job = command_invoker.async_invoke(command.name,
79
+ plugin: plugin_name,
80
+ component: component_name,
81
+ version: plugin_version,
82
+ environment: environment,
83
+ arguments: task_args,
84
+ force: options[:force],
85
+ node_filter: options[:only]
86
+ )
87
+
88
+ display_job(job)
89
+ end
90
+ end
91
+ end
92
+ end
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,56 @@
1
+ module MotherBrain
2
+ module Cli
3
+ module SubCommand
4
+ # A set of component tasks collected into a SubCommand to be registered with the
5
+ # CliGateway. This class should not be instantiated, configured, and used by itself.
6
+ # Use {SubCommand::Component.fabricate} to create an anonymous class of this type.
7
+ #
8
+ # @api private
9
+ class Component < SubCommand::Base
10
+ class << self
11
+ extend Forwardable
12
+
13
+ def_delegator :component, :description
14
+
15
+ # Return the component associated with this instance of the class
16
+ #
17
+ # @return [MB::Component]
18
+ attr_reader :component
19
+
20
+ # @param [MB::Component] component
21
+ #
22
+ # @return [SubCommand::Component]
23
+ def fabricate(component)
24
+ environment = CliGateway.invoked_opts[:environment]
25
+
26
+ Class.new(self) do
27
+ set_component(component)
28
+
29
+ component.commands.each do |command|
30
+ define_task(command)
31
+ end
32
+
33
+ desc("nodes", "List all nodes grouped by Group")
34
+ define_method(:nodes) do
35
+ ui.say "Listing nodes for '#{component.name}' in '#{environment}':"
36
+ nodes = component.nodes(environment).each do |group, nodes|
37
+ nodes.collect! { |node| "#{node.public_hostname} (#{node.public_ipv4})" }
38
+ end
39
+ ui.say nodes.to_yaml
40
+ end
41
+ end
42
+ end
43
+
44
+ # Set the component for this instance of the class and tailor the class for the
45
+ # given component.
46
+ #
47
+ # @param [MB::Component] component
48
+ def set_component(component)
49
+ self.namespace(component.name)
50
+ @component = component
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,232 @@
1
+ module MotherBrain
2
+ module Cli
3
+ module SubCommand
4
+ # A set of component tasks collected into a SubCommand to be registered with the
5
+ # CliGateway. This class should not be instantiated, configured, and used by itself.
6
+ # Use {SubCommand::Plugin.fabricate} to create an anonymous class of this type.
7
+ #
8
+ # @api private
9
+ class Plugin < SubCommand::Base
10
+ class << self
11
+ extend Forwardable
12
+
13
+ def_delegator :plugin, :description
14
+
15
+ # Return the plugin used to generate the anonymous CLI class
16
+ #
17
+ # @return [MotherBrain::Plugin]
18
+ attr_reader :plugin
19
+
20
+ # @param [MotherBrain::Plugin] plugin
21
+ #
22
+ # @return [SubCommand::Plugin]
23
+ def fabricate(plugin)
24
+ environment = CliGateway.invoked_opts[:environment]
25
+
26
+ klass = Class.new(self) do
27
+ include MB::Mixin::Services
28
+ set_plugin(plugin)
29
+ end
30
+
31
+ plugin.commands.each do |command|
32
+ klass.define_task(command)
33
+ end
34
+
35
+ plugin.components.each do |component|
36
+ klass.register_subcommand MB::Cli::SubCommand.new(component)
37
+ end
38
+
39
+ klass.class_eval do
40
+ desc("nodes", "List all nodes grouped by Component and Group")
41
+ define_method(:nodes) do
42
+ nodes = plugin.nodes(environment).each do |component, groups|
43
+ groups.each do |group, nodes|
44
+ nodes.collect! { |node| "#{node.public_hostname} (#{node.public_ipv4})" }
45
+ end
46
+ end
47
+
48
+ ui.say "\n"
49
+ ui.say "** listing nodes in #{environment}:"
50
+ ui.say "\n"
51
+ ui.say nodes.to_yaml
52
+ end
53
+
54
+ if plugin.bootstrap_routine.present?
55
+ method_option :chef_version,
56
+ type: :string,
57
+ desc: "The version of Chef to bootstrap the node(s) with"
58
+ method_option :component_versions,
59
+ type: :hash,
60
+ desc: "The component versions to set with default attributes",
61
+ aliases: "--components"
62
+ method_option :cookbook_versions,
63
+ type: :hash,
64
+ desc: "The cookbook versions to set on the environment",
65
+ aliases: "--cookbooks"
66
+ method_option :environment_attributes,
67
+ type: :hash,
68
+ desc: "Any additional attributes to set on the environment",
69
+ aliases: "--attributes"
70
+ method_option :environment_attributes_file,
71
+ type: :string,
72
+ desc: "Any additional attributes to set on the environment via a json file.",
73
+ aliases: "--attributes-file"
74
+ method_option :template,
75
+ type: :string,
76
+ desc: "Path to bootstrap template (ERB)"
77
+ method_option :force,
78
+ type: :boolean,
79
+ default: false,
80
+ desc: "Perform bootstrap even if the environment is locked",
81
+ aliases: "-f"
82
+ desc("bootstrap MANIFEST", "Bootstrap a manifest of node groups")
83
+ define_method(:bootstrap) do |manifest_file|
84
+ boot_options = Hash.new.merge(options).deep_symbolize_keys
85
+ manifest = MB::Bootstrap::Manifest.from_file(manifest_file)
86
+
87
+ job = bootstrapper.async_bootstrap(
88
+ environment.freeze,
89
+ manifest.freeze,
90
+ plugin.freeze,
91
+ boot_options.freeze
92
+ )
93
+
94
+ CliClient.new(job).display
95
+ end
96
+
97
+ method_option :chef_version,
98
+ type: :string,
99
+ desc: "The version of Chef to bootstrap the node(s) with"
100
+ method_option :component_versions,
101
+ type: :hash,
102
+ desc: "The component versions to set with default attributes",
103
+ aliases: "--components"
104
+ method_option :cookbook_versions,
105
+ type: :hash,
106
+ desc: "The cookbook versions to set on the environment",
107
+ aliases: "--cookbooks"
108
+ method_option :environment_attributes,
109
+ type: :hash,
110
+ desc: "Any additional attributes to set on the environment",
111
+ aliases: "--attributes"
112
+ method_option :environment_attributes_file,
113
+ type: :string,
114
+ desc: "Any additional attributes to set on the environment via a json file.",
115
+ aliases: "--attributes-file"
116
+ method_option :skip_bootstrap,
117
+ type: :boolean,
118
+ desc: "Nodes will be created and added to the Chef environment but not bootstrapped",
119
+ default: false
120
+ method_option :template,
121
+ type: :string,
122
+ desc: "Path to bootstrap template (ERB)"
123
+ method_option :force,
124
+ type: :boolean,
125
+ default: false,
126
+ desc: "Perform bootstrap even if the environment is locked"
127
+ desc("provision MANIFEST", "Create a cluster of nodes and add them to a Chef environment")
128
+ define_method(:provision) do |manifest_file|
129
+ prov_options = Hash.new.merge(options).deep_symbolize_keys
130
+ manifest = Provisioner::Manifest.from_file(manifest_file)
131
+
132
+ job = provisioner.async_provision(
133
+ environment.freeze,
134
+ manifest.freeze,
135
+ plugin.freeze,
136
+ prov_options.freeze
137
+ )
138
+
139
+ CliClient.new(job).display
140
+ end
141
+
142
+ method_option :cluster_override,
143
+ type: :boolean,
144
+ default: false,
145
+ desc: "Sets the service operation to execute at the environment level"
146
+ method_option :force,
147
+ type: :boolean,
148
+ default: false,
149
+ desc: "Perform service change even if the environment is locked",
150
+ aliases: "-f"
151
+ desc("service [COMPONENT].[SERVICE] [STATE]", "Change the specified service to a new state")
152
+ define_method(:service) do |service, state|
153
+ service_options = Hash.new.merge(options).deep_symbolize_keys
154
+
155
+ job = MB::Gear::DynamicService.change_service_state(
156
+ service.freeze,
157
+ plugin.freeze,
158
+ environment.freeze,
159
+ state.freeze,
160
+ service_options
161
+ )
162
+
163
+ CliClient.new(job).display
164
+ end
165
+
166
+ method_option :component_versions,
167
+ type: :hash,
168
+ desc: "The component versions to set with default attributes",
169
+ aliases: "--components"
170
+ method_option :cookbook_versions,
171
+ type: :hash,
172
+ desc: "The cookbook versions to set on the environment",
173
+ aliases: "--cookbooks"
174
+ method_option :environment_attributes,
175
+ type: :hash,
176
+ desc: "Any additional attributes to set on the environment",
177
+ aliases: "--attributes"
178
+ method_option :environment_attributes_file,
179
+ type: :string,
180
+ desc: "Any additional attributes to set on the environment via a json file.",
181
+ aliases: "--attributes-file"
182
+ method_option :force,
183
+ type: :boolean,
184
+ default: false,
185
+ desc: "Perform upgrade even if the environment is locked",
186
+ aliases: "-f"
187
+ desc("upgrade", "Upgrade an environment to the specified versions")
188
+ define_method(:upgrade) do
189
+ upgrade_options = Hash.new.merge(options).deep_symbolize_keys
190
+
191
+ requires_one_of [
192
+ :component_versions,
193
+ :cookbook_versions,
194
+ :environment_attributes,
195
+ :environment_attributes_file
196
+ ]
197
+
198
+ job = upgrade_manager.async_upgrade(
199
+ environment.freeze,
200
+ plugin.freeze,
201
+ upgrade_options.freeze
202
+ )
203
+
204
+ CliClient.new(job).display
205
+ end
206
+
207
+ desc("attributes", "View available attributes for plugin.")
208
+ define_method(:attributes) do
209
+ ui.say "\n"
210
+ ui.say "** listing attributes for #{plugin}:"
211
+ ui.say "\n"
212
+ ui.say plugin.metadata.attributes.to_yaml
213
+ end
214
+ end
215
+ end
216
+
217
+ klass
218
+ end
219
+
220
+ # Set the plugin for this instance of the class and tailor the class for the
221
+ # given plugin.
222
+ #
223
+ # @param [MotherBrain::Plugin] plugin
224
+ def set_plugin(plugin)
225
+ self.namespace(plugin.name)
226
+ @plugin = plugin
227
+ end
228
+ end
229
+ end
230
+ end
231
+ end
232
+ end