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,149 @@
1
+ module MotherBrain
2
+ module Upgrade
3
+ # Upgrades a plugin by pinning cookbook versions and default attributes
4
+ # (based on the plugin components' version attributes).
5
+ class Worker
6
+ extend Forwardable
7
+
8
+ include Celluloid
9
+ include MB::Logging
10
+ include MB::Mixin::Locks
11
+ include MB::Mixin::AttributeSetting
12
+ include MB::Mixin::Services
13
+
14
+ # @return [String]
15
+ attr_reader :environment_name
16
+
17
+ # @return [MotherBrain::Job]
18
+ attr_reader :job
19
+
20
+ # @return [Hash]
21
+ attr_reader :options
22
+
23
+ # @return [MotherBrain::Plugin]
24
+ attr_reader :plugin
25
+
26
+ # @param [String] environment_name
27
+ # @param [MotherBrain::Plugin] plugin
28
+ # @param [MotherBrain::Job] job
29
+ #
30
+ # @option options [Hash] component_versions
31
+ # Hash of components and the versions to set them to
32
+ # @option options [Hash] cookbook_versions
33
+ # Hash of cookbooks and the versions to set them to
34
+ # @option options [Hash] environment_attributes
35
+ # any additional attributes to set on the environment
36
+ # @option options [String] environment_attributes_file
37
+ # any additional attributes to set on the environment via a json file
38
+ # @option options [Boolean] :force
39
+ # Force any locks to be overwritten
40
+ def initialize(job, environment_name, plugin, options = {})
41
+ @job = job
42
+ @environment_name = environment_name
43
+ @plugin = plugin
44
+ @options = options
45
+ end
46
+
47
+ # @raise [ComponentNotFound] if a component version is passed that does
48
+ # not have a corresponding component in the plugin
49
+ #
50
+ # @raise [ComponentNotVersioned] if a component version is passed that
51
+ # does not have a version attribute in the corresponding component
52
+ #
53
+ # @raise [EnvironmentNotFound] if the environment does not exist
54
+ def run
55
+ job.set_status("Starting")
56
+ job.report_running
57
+
58
+ assert_environment_exists
59
+
60
+ chef_synchronize(chef_environment: environment_name, force: options[:force], job: job) do
61
+ if component_versions.any?
62
+ job.set_status("Setting component versions")
63
+ set_component_versions(environment_name, plugin, component_versions)
64
+ end
65
+
66
+ if cookbook_versions.any?
67
+ job.set_status("Setting cookbook versions")
68
+ set_cookbook_versions(environment_name, cookbook_versions)
69
+ end
70
+
71
+ if environment_attributes.any?
72
+ job.set_status("Setting environment attributes")
73
+ set_environment_attributes(environment_name, environment_attributes)
74
+ end
75
+
76
+ if environment_attributes_file
77
+ job.set_status("Setting environment attributes from #{environment_attributes_file}")
78
+ set_environment_attributes_from_file(environment_name, environment_attributes_file)
79
+ end
80
+
81
+ run_chef if nodes.any?
82
+ end
83
+
84
+ job.report_success
85
+ rescue => ex
86
+ job.report_failure(ex)
87
+ ensure
88
+ job.terminate if job && job.alive?
89
+ end
90
+
91
+ private
92
+
93
+ # @raise [EnvironmentNotFound]
94
+ def assert_environment_exists
95
+ unless chef_connection.environment.find(environment_name)
96
+ raise EnvironmentNotFound.new(environment_name)
97
+ end
98
+ end
99
+
100
+ # @return [Hash]
101
+ def component_versions
102
+ options[:component_versions] || {}
103
+ end
104
+
105
+ # @return [Hash]
106
+ def cookbook_versions
107
+ options[:cookbook_versions] || {}
108
+ end
109
+
110
+ # @return [Hash]
111
+ def environment_attributes
112
+ options[:environment_attributes] || {}
113
+ end
114
+
115
+ # @return [String, nil]
116
+ def environment_attributes_file
117
+ options[:environment_attributes_file]
118
+ end
119
+
120
+ # @return [Array<String>]
121
+ def nodes
122
+ return @nodes if @nodes
123
+
124
+ job.set_status("Looking for nodes")
125
+
126
+ @nodes = plugin.nodes(environment_name).collect { |component, groups|
127
+ groups.collect { |group, nodes|
128
+ nodes.collect(&:public_hostname)
129
+ }
130
+ }.flatten.compact.uniq
131
+
132
+ unless @nodes.any?
133
+ log.info "No nodes in environment '#{environment_name}'"
134
+ end
135
+
136
+ @nodes
137
+ end
138
+
139
+ def run_chef
140
+ log.info "Running Chef on #{nodes}"
141
+ job.set_status("Running Chef on nodes")
142
+
143
+ nodes.concurrent_map { |node|
144
+ node_querier.chef_run(node)
145
+ }
146
+ end
147
+ end
148
+ end
149
+ end
data/lib/mb/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module MotherBrain
2
- VERSION = "0.0.0.placeholder"
2
+ VERSION = '0.13.1'
3
3
  end
data/lib/motherbrain.rb CHANGED
@@ -1,5 +1,169 @@
1
- require "mb/version"
1
+ require 'celluloid'
2
+ require 'varia_model'
3
+ require 'buff/extensions'
4
+ require 'buff/ruby_engine/kernel_ext'
5
+ require 'buff/platform/kernel_ext'
6
+ require 'grape'
7
+ require 'ridley-connectors'
8
+ require 'solve'
9
+ require 'thor'
10
+ require 'thor/group'
11
+ require 'fileutils'
12
+ require 'pathname'
13
+ require 'forwardable'
14
+ require 'set'
15
+ require 'ostruct'
16
+ require 'multi_json'
17
+ require 'mb/version'
18
+ require 'mb/errors'
19
+ require 'mb/core_ext'
20
+ require 'mb/grape_ext'
21
+ require 'mb/ridley_ext'
22
+ require 'mb/thor_ext'
2
23
 
3
24
  module MotherBrain
4
- # Your code goes here...
25
+ autoload :API, 'mb/api'
26
+ autoload :Application, 'mb/application'
27
+ autoload :Berkshelf, 'mb/berkshelf'
28
+ autoload :Bootstrap, 'mb/bootstrap'
29
+ autoload :Chef, 'mb/chef'
30
+ autoload :ChefMutex, 'mb/chef_mutex'
31
+ autoload :CleanRoomBase, 'mb/clean_room_base'
32
+ autoload :Cli, 'mb/cli'
33
+ autoload :CliClient, 'mb/cli_client'
34
+ autoload :CliGateway, 'mb/cli_gateway'
35
+ autoload :Command, 'mb/command'
36
+ autoload :CommandInvoker, 'mb/command_invoker'
37
+ autoload :CommandRunner, 'mb/command_runner'
38
+ autoload :Component, 'mb/component'
39
+ autoload :Config, 'mb/config'
40
+ autoload :ConfigManager, 'mb/config_manager'
41
+ autoload :CookbookMetadata, 'mb/cookbook_metadata'
42
+ autoload :EnvironmentManager, 'mb/environment_manager'
43
+ autoload :ErrorHandler, 'mb/error_handler'
44
+ autoload :FileSystem, 'mb/file_system'
45
+ autoload :Gear, 'mb/gear'
46
+ autoload :Group, 'mb/group'
47
+ autoload :Job, 'mb/job'
48
+ autoload :JobManager, 'mb/job_manager'
49
+ autoload :JobRecord, 'mb/job_record'
50
+ autoload :JobTicket, 'mb/job_ticket'
51
+ autoload :LockManager, 'mb/lock_manager'
52
+ autoload :Logging, 'mb/logging'
53
+ autoload :NodeFilter, 'mb/node_filter'
54
+ autoload :Manifest, 'mb/manifest'
55
+ autoload :Mixin, 'mb/mixin'
56
+ autoload :NodeQuerier, 'mb/node_querier'
57
+ autoload :Plugin, 'mb/plugin'
58
+ autoload :PluginManager, 'mb/plugin_manager'
59
+ autoload :Provisioner, 'mb/provisioner'
60
+ autoload :SrvCtl, 'mb/srv_ctl'
61
+ autoload :Upgrade, 'mb/upgrade'
62
+
63
+ class << self
64
+ extend Forwardable
65
+
66
+ attr_writer :ui
67
+
68
+ def_delegator "MB::Application.instance", :application
69
+ alias_method :app, :application
70
+
71
+ # Path to the root directory of the motherbrain application
72
+ #
73
+ # @return [Pathname]
74
+ def app_root
75
+ @app_root ||= Pathname.new(File.expand_path('../', File.dirname(__FILE__)))
76
+ end
77
+
78
+ # Path to the scripts directory
79
+ #
80
+ # @return [Pathname]
81
+ def scripts
82
+ app_root.join('scripts')
83
+ end
84
+
85
+ # @return [Logger]
86
+ def logger
87
+ MB::Logging.logger
88
+ end
89
+ alias_method :log, :logger
90
+
91
+ # @param [Logger, nil] obj
92
+ #
93
+ # @return [Logger]
94
+ def set_logger(obj)
95
+ MB::Logging.set_logger(obj)
96
+ end
97
+
98
+ # Is motherbrain executing in test mode?
99
+ #
100
+ # @return [Boolean]
101
+ def testing?
102
+ ENV['RUBY_ENV'] == 'test'
103
+ end
104
+
105
+ # Takes an array of procs or a an array of arrays of procs and calls them returning their evaluated
106
+ # values in an array at the same depth.
107
+ #
108
+ # @example
109
+ # procs = [
110
+ # -> { :one },
111
+ # -> { :two },
112
+ # [
113
+ # -> { :nested },
114
+ # [
115
+ # -> { :deep_nested }
116
+ # ]
117
+ # ]
118
+ # ]
119
+ #
120
+ # expand_procs(procs) => [
121
+ # :one,
122
+ # :two,
123
+ # [
124
+ # :nested,
125
+ # [
126
+ # :deep_nested
127
+ # ]
128
+ # ]
129
+ # ]
130
+ #
131
+ # @param [Array<Proc>, Array<Array<Proc>>] procs
132
+ # an array of nested arrays and procs
133
+ #
134
+ # @return [Array]
135
+ # an array of nested arrays and their evaluated values
136
+ def expand_procs(procs)
137
+ procs.map! do |l_proc|
138
+ if l_proc.is_a?(Array)
139
+ expand_procs(l_proc)
140
+ else
141
+ l_proc.call
142
+ end
143
+ end
144
+ end
145
+
146
+ def require_or_exit(library, message = nil)
147
+ begin
148
+ require library
149
+ rescue LoadError
150
+ message ||=
151
+ "#{library} was not found. Please add it to your Gemfile, " +
152
+ "and then run `bundle install`."
153
+ raise PrerequisiteNotInstalled, message
154
+ end
155
+ end
156
+ end
157
+ end
158
+
159
+ # Alias for {MotherBrain}
160
+ MB = MotherBrain
161
+ require_relative 'mb/gears'
162
+ require_relative 'mb/provisioners'
163
+ require_relative 'mb/rest_gateway'
164
+
165
+ if MB.testing?
166
+ require 'mb/test'
167
+ else
168
+ class MB::Test ; end # Make the constant exist
5
169
  end
data/man/man_helper.rb ADDED
@@ -0,0 +1,81 @@
1
+ require 'motherbrain'
2
+ require 'erb'
3
+
4
+ module MB
5
+ class CliGateway
6
+ def self.basename
7
+ "`mb`"
8
+ end
9
+ end
10
+
11
+ class ManHelper
12
+ def self.generate(template_path="./man/man.1.ronn.erb",output_path="./man/man.1.ronn")
13
+ commands = []
14
+ extended_commands = []
15
+
16
+ shell = Thor::Shell::Basic.new
17
+
18
+ metadata = MB::CookbookMetadata.new
19
+ metadata.name = "plugin"
20
+ metadata.version = Solve::Version.new("1.0.0")
21
+
22
+ plugin = MB::Plugin.new(metadata)
23
+
24
+ plugin.bootstrap_routine = MB::Bootstrap::Routine.new(plugin)
25
+
26
+ environment_command = MB::CliGateway::SubCommand::Environment
27
+ plugin_command = MB::CliGateway::SubCommand::Plugin
28
+ dynamic_plugin_command = MB::Cli::SubCommand::Plugin.fabricate(plugin)
29
+ def environment_command.basename
30
+ "`mb` `environment`"
31
+ end
32
+ def plugin_command.basename
33
+ "`mb` `plugin`"
34
+ end
35
+ def dynamic_plugin_command.basename
36
+ "`mb` `<plugin>`"
37
+ end
38
+ subcmds = [
39
+ environment_command,
40
+ plugin_command,
41
+ dynamic_plugin_command
42
+ ]
43
+
44
+ banner_proc = lambda { |klass, command_name|
45
+ klass.instance_eval do
46
+ meth = normalize_command_name(command_name)
47
+ command = all_commands[meth]
48
+ banner(command).sub(/\S+:/,'')
49
+ end
50
+ }
51
+
52
+ documentation_proc = lambda { |klass, command_name|
53
+ klass.instance_eval do
54
+ meth = normalize_command_name(command_name)
55
+ command = all_commands[meth]
56
+ [banner(command).sub(/\S+:/,''), command.description, command.long_description, command.options]
57
+ end
58
+ }
59
+
60
+ MB::CliGateway.commands.each do |command|
61
+ commands << banner_proc.call(MB::CliGateway, command[0])
62
+ extended_commands << documentation_proc.call(MB::CliGateway, command[0])
63
+ end
64
+
65
+ subcmds.each do |subcmd|
66
+ subcmd.commands.each do |command|
67
+ commands << banner_proc.call(subcmd, command[0])
68
+ extended_commands << documentation_proc.call(subcmd, command[0])
69
+ end
70
+ end
71
+
72
+ class_options = MB::CliGateway.class_options
73
+
74
+ template = ERB.new(File.read(File.expand_path(template_path)), nil, '-')
75
+ File.open(output_path, 'w') do |file|
76
+ file.puts template.result(binding)
77
+ end
78
+ end
79
+ end
80
+ end
81
+
data/man/mb.1 ADDED
@@ -0,0 +1,494 @@
1
+ .\" generated with Ronn/v0.7.3
2
+ .\" http://github.com/rtomayko/ronn/tree/0.7.3
3
+ .
4
+ .TH "MB" "1" "September 2013" "" ""
5
+ .
6
+ .SH "NAME"
7
+ \fBmb\fR \- command and control clusters of machines with Chef
8
+ .
9
+ .SH "SYNOPSIS"
10
+ \fBmb\fR configure
11
+ .
12
+ .br
13
+ \fBmb\fR console
14
+ .
15
+ .br
16
+ \fBmb\fR purge HOST
17
+ .
18
+ .br
19
+ \fBmb\fR version
20
+ .
21
+ .br
22
+ \fBmb\fR template NAME PATH_OR_URL
23
+ .
24
+ .br
25
+ \fBmb\fR environment
26
+ .
27
+ .br
28
+ \fBmb\fR plugin
29
+ .
30
+ .br
31
+ \fBmb\fR \fBenvironment\fR configure ENVIRONMENT FILE
32
+ .
33
+ .br
34
+ \fBmb\fR \fBenvironment\fR destroy ENVIRONMENT
35
+ .
36
+ .br
37
+ \fBmb\fR \fBenvironment\fR list
38
+ .
39
+ .br
40
+ \fBmb\fR \fBenvironment\fR lock ENVIRONMENT
41
+ .
42
+ .br
43
+ \fBmb\fR \fBenvironment\fR unlock ENVIRONMENT
44
+ .
45
+ .br
46
+ \fBmb\fR \fBenvironment\fR create ENVIRONMENT
47
+ .
48
+ .br
49
+ \fBmb\fR \fBenvironment\fR help [COMMAND]
50
+ .
51
+ .br
52
+ \fBmb\fR \fBplugin\fR init [PATH]
53
+ .
54
+ .br
55
+ \fBmb\fR \fBplugin\fR install NAME
56
+ .
57
+ .br
58
+ \fBmb\fR \fBplugin\fR list
59
+ .
60
+ .br
61
+ \fBmb\fR \fBplugin\fR show NAME
62
+ .
63
+ .br
64
+ \fBmb\fR \fBplugin\fR uninstall NAME \-\-version=VERSION
65
+ .
66
+ .br
67
+ \fBmb\fR \fBplugin\fR help [COMMAND]
68
+ .
69
+ .br
70
+ \fBmb\fR \fB<plugin>\fR nodes
71
+ .
72
+ .br
73
+ \fBmb\fR \fB<plugin>\fR bootstrap MANIFEST
74
+ .
75
+ .br
76
+ \fBmb\fR \fB<plugin>\fR provision MANIFEST
77
+ .
78
+ .br
79
+ \fBmb\fR \fB<plugin>\fR upgrade
80
+ .
81
+ .br
82
+ \fBmb\fR \fB<plugin>\fR \fB<component>\fR \fB<command>\fR
83
+ .
84
+ .br
85
+ .
86
+ .SH "DESCRIPTION"
87
+ motherbrain is an orchestration framework for Chef\. In the same way that you would use Chef\'s Knife command to create a single node, you can use motherbrain to create and control an entire application environment\.
88
+ .
89
+ .P
90
+ With the exception of a few top\-level commands, most motherbrain interactions use the commands defined in the selected plugin\.
91
+ .
92
+ .SH "FILES"
93
+ Provisioning and bootstrapping nodes require manifests\. Insert manifest documentation\.
94
+ .
95
+ .SH "OPTIONS"
96
+ The following global options can be used on any motherbrain command to change the behavior\.
97
+ .
98
+ .TP
99
+ \fB\-c\fR, \fB\-\-config\fR
100
+ Path to a motherbrain JSON configuration file\.
101
+ .
102
+ .TP
103
+ \fB\-v\fR, \fB\-\-verbose\fR
104
+ Increase verbosity of output\.
105
+ .
106
+ .TP
107
+ \fB\-d\fR, \fB\-\-debug\fR
108
+ Output all log messages\.
109
+ .
110
+ .TP
111
+ \fB\-L\fR, \fB\-\-logfile\fR
112
+ Set the log file location\.
113
+ .
114
+ .TP
115
+ \fB\-p\fR, \fB\-\-plugin_version\fR
116
+ Plugin version to use
117
+ .
118
+ .TP
119
+ \fB\-e\fR, \fB\-\-environment\fR
120
+ Chef environment
121
+ .
122
+ .TP
123
+ \fB\-\-on_environment_missing\fR
124
+ What to do when the environment doesn\'t exist (Default: prompt)Possible values: prompt, create, quit
125
+ .
126
+ .SH "COMMANDS"
127
+ \fBmb\fR configure
128
+ .
129
+ .br
130
+ create a new configuration file based on a set of interactive questions
131
+ .
132
+ .TP
133
+ \-f, \-\-force
134
+ create a new configuration file even if one already exists\.
135
+ .
136
+ .br
137
+
138
+ .
139
+ .P
140
+ \fBmb\fR console
141
+ .
142
+ .br
143
+ Start an interactive motherbrain console
144
+ .
145
+ .P
146
+ \fBmb\fR purge HOST
147
+ .
148
+ .br
149
+ Remove Chef from node and purge it\'s data from the Chef server
150
+ .
151
+ .TP
152
+ \-\-skip\-chef
153
+ Skip removing the Chef installation from the node
154
+ .
155
+ .br
156
+
157
+ .
158
+ .P
159
+ \fBmb\fR version
160
+ .
161
+ .br
162
+ Display version and license information
163
+ .
164
+ .P
165
+ \fBmb\fR template NAME PATH_OR_URL
166
+ .
167
+ .br
168
+ Download and install a bootstrap template
169
+ .
170
+ .P
171
+ \fBmb\fR environment
172
+ .
173
+ .br
174
+ Environment level commands
175
+ .
176
+ .P
177
+ \fBmb\fR plugin
178
+ .
179
+ .br
180
+ Plugin level commands
181
+ .
182
+ .P
183
+ \fBmb\fR \fBenvironment\fR configure ENVIRONMENT FILE
184
+ .
185
+ .br
186
+ configure a Chef environment
187
+ .
188
+ .TP
189
+ \-f, \-\-force
190
+ perform the configuration even if the environment is locked
191
+ .
192
+ .br
193
+
194
+ .
195
+ .P
196
+ \fBmb\fR \fBenvironment\fR destroy ENVIRONMENT
197
+ .
198
+ .br
199
+ Destroy a provisioned environment
200
+ .
201
+ .TP
202
+ \-y, \-\-yes
203
+ Don\'t confirm, just destroy the environment
204
+ .
205
+ .br
206
+
207
+ .
208
+ .TP
209
+ \-f, \-\-force
210
+ Force destruction of a locked environment
211
+ .
212
+ .br
213
+
214
+ .
215
+ .TP
216
+ \-\-provisioner=PROVISIONER
217
+ Provisioner to use for destroying the environment
218
+ .
219
+ .br
220
+
221
+ .
222
+ .P
223
+ \fBmb\fR \fBenvironment\fR list
224
+ .
225
+ .br
226
+ List all environments
227
+ .
228
+ .P
229
+ \fBmb\fR \fBenvironment\fR lock ENVIRONMENT
230
+ .
231
+ .br
232
+ Lock an environment
233
+ .
234
+ .P
235
+ \fBmb\fR \fBenvironment\fR unlock ENVIRONMENT
236
+ .
237
+ .br
238
+ Unlock an environment
239
+ .
240
+ .P
241
+ \fBmb\fR \fBenvironment\fR create ENVIRONMENT
242
+ .
243
+ .br
244
+ Create an empty environment
245
+ .
246
+ .P
247
+ \fBmb\fR \fBenvironment\fR help [COMMAND]
248
+ .
249
+ .br
250
+ Describe subcommands or one specific subcommand
251
+ .
252
+ .P
253
+ \fBmb\fR \fBplugin\fR init [PATH]
254
+ .
255
+ .br
256
+ Generate a new motherbrain plugin in the target cookbook
257
+ .
258
+ .P
259
+ \fBmb\fR \fBplugin\fR install NAME
260
+ .
261
+ .br
262
+ Install a plugin from the remote Chef server
263
+ .
264
+ .TP
265
+ \-\-version=VERSION
266
+ The version of the plugin to install
267
+ .
268
+ .br
269
+
270
+ .
271
+ .P
272
+ \fBmb\fR \fBplugin\fR list
273
+ .
274
+ .br
275
+ List all installed plugins
276
+ .
277
+ .TP
278
+ \-\-remote
279
+ search the remote Chef server and include plugins from the results
280
+ .
281
+ .br
282
+
283
+ .
284
+ .P
285
+ \fBmb\fR \fBplugin\fR show NAME
286
+ .
287
+ .br
288
+ Show information about a plugin
289
+ .
290
+ .TP
291
+ \-\-version=VERSION
292
+ The version of the plugin to display information for
293
+ .
294
+ .br
295
+
296
+ .
297
+ .TP
298
+ \-\-remote
299
+ Include plugins found on the remote Chef server
300
+ .
301
+ .br
302
+
303
+ .
304
+ .P
305
+ \fBmb\fR \fBplugin\fR uninstall NAME \-\-version=VERSION
306
+ .
307
+ .br
308
+ Uninstall a plugin from your Berkshelf
309
+ .
310
+ .TP
311
+ \-\-version=VERSION (REQUIRED)
312
+ The version of the plugin to install
313
+ .
314
+ .br
315
+
316
+ .
317
+ .P
318
+ \fBmb\fR \fBplugin\fR help [COMMAND]
319
+ .
320
+ .br
321
+ Describe subcommands or one specific subcommand
322
+ .
323
+ .P
324
+ \fBmb\fR \fB<plugin>\fR nodes
325
+ .
326
+ .br
327
+ List all nodes grouped by Component and Group
328
+ .
329
+ .P
330
+ \fBmb\fR \fB<plugin>\fR bootstrap MANIFEST
331
+ .
332
+ .br
333
+ Bootstrap a manifest of node groups
334
+ .
335
+ .TP
336
+ \-\-chef\-version=CHEF_VERSION
337
+ The version of Chef to bootstrap the node(s) with
338
+ .
339
+ .br
340
+
341
+ .
342
+ .TP
343
+ \-\-components, \-\-component\-versions=key:value
344
+ The component versions to set with default attributes
345
+ .
346
+ .br
347
+
348
+ .
349
+ .TP
350
+ \-\-cookbooks, \-\-cookbook\-versions=key:value
351
+ The cookbook versions to set on the environment
352
+ .
353
+ .br
354
+
355
+ .
356
+ .TP
357
+ \-\-attributes, \-\-environment\-attributes=key:value
358
+ Any additional attributes to set on the environment
359
+ .
360
+ .br
361
+
362
+ .
363
+ .TP
364
+ \-\-attributes\-file, \-\-environment\-attributes\-file=ENVIRONMENT_ATTRIBUTES_FILE
365
+ Any additional attributes to set on the environment via a json file\.
366
+ .
367
+ .br
368
+
369
+ .
370
+ .TP
371
+ \-\-template=TEMPLATE
372
+ Path to bootstrap template (ERB)
373
+ .
374
+ .br
375
+
376
+ .
377
+ .TP
378
+ \-f, \-\-force
379
+ Perform bootstrap even if the environment is locked
380
+ .
381
+ .br
382
+
383
+ .
384
+ .P
385
+ \fBmb\fR \fB<plugin>\fR provision MANIFEST
386
+ .
387
+ .br
388
+ Create a cluster of nodes and add them to a Chef environment
389
+ .
390
+ .TP
391
+ \-\-chef\-version=CHEF_VERSION
392
+ The version of Chef to bootstrap the node(s) with
393
+ .
394
+ .br
395
+
396
+ .
397
+ .TP
398
+ \-\-components, \-\-component\-versions=key:value
399
+ The component versions to set with default attributes
400
+ .
401
+ .br
402
+
403
+ .
404
+ .TP
405
+ \-\-cookbooks, \-\-cookbook\-versions=key:value
406
+ The cookbook versions to set on the environment
407
+ .
408
+ .br
409
+
410
+ .
411
+ .TP
412
+ \-\-attributes, \-\-environment\-attributes=key:value
413
+ Any additional attributes to set on the environment
414
+ .
415
+ .br
416
+
417
+ .
418
+ .TP
419
+ \-\-attributes\-file, \-\-environment\-attributes\-file=ENVIRONMENT_ATTRIBUTES_FILE
420
+ Any additional attributes to set on the environment via a json file\.
421
+ .
422
+ .br
423
+
424
+ .
425
+ .TP
426
+ \-\-skip\-bootstrap
427
+ Nodes will be created and added to the Chef environment but not bootstrapped
428
+ .
429
+ .br
430
+
431
+ .
432
+ .TP
433
+ \-\-template=TEMPLATE
434
+ Path to bootstrap template (ERB)
435
+ .
436
+ .br
437
+
438
+ .
439
+ .TP
440
+ \-\-force
441
+ Perform bootstrap even if the environment is locked
442
+ .
443
+ .br
444
+
445
+ .
446
+ .P
447
+ \fBmb\fR \fB<plugin>\fR upgrade
448
+ .
449
+ .br
450
+ Upgrade an environment to the specified versions
451
+ .
452
+ .TP
453
+ \-\-components, \-\-component\-versions=key:value
454
+ The component versions to set with default attributes
455
+ .
456
+ .br
457
+
458
+ .
459
+ .TP
460
+ \-\-cookbooks, \-\-cookbook\-versions=key:value
461
+ The cookbook versions to set on the environment
462
+ .
463
+ .br
464
+
465
+ .
466
+ .TP
467
+ \-\-attributes, \-\-environment\-attributes=key:value
468
+ Any additional attributes to set on the environment
469
+ .
470
+ .br
471
+
472
+ .
473
+ .TP
474
+ \-\-attributes\-file, \-\-environment\-attributes\-file=ENVIRONMENT_ATTRIBUTES_FILE
475
+ Any additional attributes to set on the environment via a json file\.
476
+ .
477
+ .br
478
+
479
+ .
480
+ .TP
481
+ \-f, \-\-force
482
+ Perform upgrade even if the environment is locked
483
+ .
484
+ .br
485
+
486
+ .
487
+ .P
488
+ \fBmb\fR \fB<plugin>\fR \fB<component>\fR \fB<command>\fR
489
+ .
490
+ .br
491
+ Run a command defined in a component in the specified plugin\. Options and usage are plugin\-defined\.
492
+ .
493
+ .SH "COPYRIGHT"
494
+ motherbrain is Copyright (C) 2012\-2013 Riot Games, Inc\.