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
data/lib/mb/config.rb ADDED
@@ -0,0 +1,275 @@
1
+ require 'buff/config/json'
2
+
3
+ module MotherBrain
4
+ class Config < Buff::Config::JSON
5
+ class << self
6
+ # The default location for motherbrain's config file
7
+ #
8
+ # @return [String]
9
+ def default_path
10
+ FileSystem.root.join("config.json").to_s
11
+ end
12
+
13
+ # @see Buff::Config::JSON.from_json
14
+ #
15
+ # @raise [MB::ConfigNotFound]
16
+ def from_file(*args)
17
+ super
18
+ rescue Buff::Errors::ConfigNotFound => ex
19
+ raise MB::ConfigNotFound, ex
20
+ rescue Buff::Errors::InvalidConfig => ex
21
+ raise MB::InvalidConfig.new(syntax_error: [ex.message])
22
+ end
23
+
24
+ def from_hash(hash)
25
+ super
26
+ rescue Buff::Errors::ConfigNotFound => ex
27
+ raise MB::ConfigNotFound, ex
28
+ rescue Buff::Errors::InvalidConfig => ex
29
+ raise MB::InvalidConfig.new(syntax_error: [ex.message])
30
+ end
31
+
32
+ # @raise [Celluloid::DeadActorError] if ConfigManager has not been started
33
+ #
34
+ # @return [Celluloid::Actor(ConfigManager)]
35
+ def manager
36
+ ConfigManager.instance
37
+ end
38
+
39
+ # Validate the given config
40
+ #
41
+ # @param [MB::Config] config
42
+ #
43
+ # @raise [MB::InvalidConfig] if the given configuration is invalid
44
+ def validate!(config)
45
+ unless config.valid?
46
+ raise InvalidConfig.new(config.errors)
47
+ end
48
+ end
49
+
50
+ def chef_config
51
+ MB::Chef::Config.new.parse
52
+ end
53
+ end
54
+
55
+ attribute 'berkshelf.path',
56
+ default: MB::Berkshelf.default_path,
57
+ type: String,
58
+ required: true
59
+
60
+ attribute 'chef.api_url',
61
+ default: (ENV['CHEF_API_URL'] || chef_config[:chef_server_url]),
62
+ type: String,
63
+ required: true
64
+
65
+ attribute 'chef.api_client',
66
+ default: chef_config[:node_name],
67
+ type: String,
68
+ required: true
69
+
70
+ attribute 'chef.api_key',
71
+ default: chef_config[:client_key],
72
+ type: String,
73
+ required: true
74
+
75
+ attribute 'chef.validator_client',
76
+ default: chef_config[:validation_client_name],
77
+ type: String
78
+
79
+ attribute 'chef.validator_path',
80
+ default: chef_config[:validation_key],
81
+ type: String
82
+
83
+ attribute 'chef.bootstrap_proxy',
84
+ type: String
85
+
86
+ attribute 'chef.encrypted_data_bag_secret_path',
87
+ type: String
88
+
89
+ attribute 'ssh.user',
90
+ type: String
91
+
92
+ attribute 'ssh.password',
93
+ type: String
94
+
95
+ attribute 'ssh.keys',
96
+ type: [ Set, Array ],
97
+ coerce: lambda { |m| m.to_set }
98
+
99
+ attribute 'ssh.sudo',
100
+ default: true,
101
+ type: Boolean
102
+
103
+ attribute 'ssh.timeout',
104
+ default: 10.0,
105
+ type: [ Integer, Float ]
106
+
107
+ attribute 'ssh.verbose',
108
+ type: String
109
+
110
+ attribute 'winrm.user',
111
+ type: String
112
+
113
+ attribute 'winrm.password',
114
+ type: String
115
+
116
+ attribute 'winrm.port',
117
+ default: 5985,
118
+ type: Integer
119
+
120
+ attribute 'ssl.verify',
121
+ default: true,
122
+ type: Boolean
123
+
124
+ attribute 'log.level',
125
+ default: 'INFO',
126
+ type: String,
127
+ coerce: lambda { |m|
128
+ m = m.is_a?(String) ? m.upcase : m
129
+ case m
130
+ when Logger::DEBUG
131
+ 'DEBUG'
132
+ when Logger::INFO
133
+ 'INFO'
134
+ when Logger::WARN
135
+ 'WARN'
136
+ when Logger::ERROR
137
+ 'ERROR'
138
+ when Logger::FATAL
139
+ 'FATAL'
140
+ when 'DEBUG', 'INFO', 'WARN', 'ERROR', 'FATAL'
141
+ m
142
+ else; nil
143
+ end
144
+ }
145
+
146
+ attribute 'log.location',
147
+ default: 'STDOUT',
148
+ type: String,
149
+ coerce: lambda { |m|
150
+ o = m
151
+ m = m.is_a?(String) ? m.upcase : m
152
+ case m
153
+ when STDOUT; 'STDOUT'
154
+ when STDERR; 'STDERR'
155
+ when 'STDOUT', 'STDERR'; m
156
+ else; o
157
+ end
158
+ }
159
+
160
+ attribute 'server.daemonize',
161
+ default: false,
162
+ type: Boolean
163
+
164
+ attribute 'server.pid',
165
+ default: "/var/run/motherbrain/mb.pid",
166
+ type: String
167
+
168
+ attribute 'rest_gateway.enable',
169
+ default: false,
170
+ type: Boolean
171
+
172
+ attribute 'rest_gateway.host',
173
+ default: RestGateway::DEFAULT_OPTIONS[:host],
174
+ type: String
175
+
176
+ attribute 'rest_gateway.port',
177
+ default: RestGateway::DEFAULT_OPTIONS[:port],
178
+ type: Integer
179
+
180
+ # Enables the plugin manager to automatically populate its set of plugins
181
+ # from cookbooks present on the remote Chef server that contain plugins
182
+ attribute 'plugin_manager.eager_loading',
183
+ default: false,
184
+ type: Boolean
185
+
186
+ # How long the plugin manager will wait before polling the Chef Server to eagerly
187
+ # load any new plugins
188
+ attribute 'plugin_manager.eager_load_interval',
189
+ default: 300, # 5 minutes
190
+ type: Integer
191
+
192
+ # Allows the plugin manager load it's plugins asynchronously in the background during startup
193
+ attribute 'plugin_manager.async_loading',
194
+ default: false,
195
+ type: Boolean
196
+
197
+ attribute 'ef.api_url',
198
+ type: String
199
+
200
+ attribute 'ef.api_key',
201
+ type: String
202
+
203
+ attribute 'aws.access_key',
204
+ type: String,
205
+ default: ENV['AWS_ACCESS_KEY']
206
+
207
+ attribute 'aws.secret_key',
208
+ type: String,
209
+ default: ENV['AWS_SECRET_KEY']
210
+
211
+ attribute 'aws.endpoint',
212
+ type: String,
213
+ default: ENV['EC2_URL']
214
+
215
+ attribute 'bootstrap.default_template',
216
+ type: String
217
+
218
+ # Validate the instantiated config
219
+ #
220
+ # @raise [MB::InvalidConfig] if the given configuration is invalid
221
+ def validate!
222
+ self.class.validate!(self)
223
+ end
224
+
225
+ # Returns a connection hash for Ridley from the instance's attributes
226
+ #
227
+ # @example
228
+ # config = MB::Config.new.tap do |o|
229
+ # o.chef_api_url = "https://api.opscode.com/organizations/vialstudios"
230
+ # o.chef_api_client = "reset"
231
+ # o.chef_api_key = "/Users/reset/.chef/reset.pem"
232
+ # end
233
+ #
234
+ # config.to_ridley =>
235
+ # {
236
+ # server_url: "https://api.opscode.com/organizations/vialstudios",
237
+ # client_name: "reset",
238
+ # client_key: "/Users/reset/.chef/reset.pem",
239
+ # validator_client: nil,
240
+ # validator_path: nil
241
+ # }
242
+ #
243
+ # @return [Hash]
244
+ def to_ridley
245
+ {}.tap do |ridley_opts|
246
+ ridley_opts[:server_url] = self.chef.api_url
247
+ ridley_opts[:client_name] = self.chef.api_client
248
+ ridley_opts[:client_key] = self.chef.api_key
249
+ ridley_opts[:encrypted_data_bag_secret_path] = self.chef.encrypted_data_bag_secret_path
250
+ ridley_opts[:validator_path] = self.chef.validator_path
251
+ ridley_opts[:validator_client] = self.chef.validator_client
252
+ ridley_opts[:ssh] = self.ssh
253
+ ridley_opts[:winrm] = self.winrm
254
+ ridley_opts[:ssl] = {
255
+ verify: self.ssl.verify
256
+ }
257
+ ridley_opts[:ssh][:verbose] = ridley_opts[:ssh][:verbose].to_sym if ridley_opts[:ssh][:verbose]
258
+ end
259
+ end
260
+
261
+ def to_rest_gateway
262
+ {}.tap do |rest_opts|
263
+ rest_opts[:host] = self.rest_gateway.host
264
+ rest_opts[:port] = self.rest_gateway.port
265
+ end
266
+ end
267
+
268
+ def to_logger
269
+ {}.tap do |opts|
270
+ opts[:level] = self.log.level
271
+ opts[:location] = self.log.location
272
+ end
273
+ end
274
+ end
275
+ end
@@ -0,0 +1,75 @@
1
+ module MotherBrain
2
+ class ConfigManager
3
+ class << self
4
+ # @raise [Celluloid::DeadActorError] if ConfigManager has not been started
5
+ #
6
+ # @return [Celluloid::Actor(ConfigManager)]
7
+ def instance
8
+ MB::Application[:config_manager] or raise Celluloid::DeadActorError, "config manager not running"
9
+ end
10
+ end
11
+
12
+ include Celluloid
13
+ include Celluloid::Notifications
14
+ include MB::Logging
15
+
16
+ UPDATE_MSG = 'config_manager.configure'.freeze
17
+
18
+ # @return [MB::Config]
19
+ attr_reader :config
20
+
21
+ finalizer :finalize_callback
22
+
23
+ # @param [MB::Config] new_config
24
+ def initialize(new_config)
25
+ log.debug { "Config Manager starting..." }
26
+ @reload_mutex = Mutex.new
27
+ @reloading = false
28
+ set_config(new_config)
29
+ end
30
+
31
+ # Update the current configuration
32
+ #
33
+ # @param [MB::Config] new_config
34
+ def update(new_config)
35
+ set_config(new_config)
36
+
37
+ MB.log.info "[ConfigManager] Configuration has changed: notifying subscribers..."
38
+ publish(UPDATE_MSG, self.config)
39
+ end
40
+
41
+ # Reload the current configuration from disk
42
+ def reload
43
+ reload_mutex.synchronize do
44
+ unless reloading?
45
+ @reloading = true
46
+ update(config.reload)
47
+ end
48
+ end
49
+
50
+ @reloading = false
51
+ end
52
+
53
+ # Check if the config manager is already attempting to reload it's configuration
54
+ #
55
+ # @return [Boolean]
56
+ def reloading?
57
+ @reloading
58
+ end
59
+
60
+ private
61
+
62
+ # @return [Mutex]
63
+ attr_reader :reload_mutex
64
+
65
+ def finalize_callback
66
+ log.debug { "Config Manager stopping..." }
67
+ end
68
+
69
+ # @param [MB::Config] new_config
70
+ def set_config(new_config)
71
+ new_config.validate!
72
+ @config = new_config
73
+ end
74
+ end
75
+ end
data/lib/mb/console.rb ADDED
@@ -0,0 +1,35 @@
1
+ require 'pry'
2
+ require 'pry/repl'
3
+
4
+ module MotherBrain
5
+ class Console < Pry::REPL
6
+ class << self
7
+ # @option options [Object] :target ({MB::Application})
8
+ # The initial context for this session.
9
+ # @option options [Array<Proc>] :prompt ({Console.default_prompt})
10
+ # The array of Procs to use for prompts.
11
+ # @option options [#readline] :input
12
+ # The object to use for input.
13
+ # @option options [#puts] :output
14
+ # The object to use for output.
15
+ # @option options [Pry::CommandBase] :commands
16
+ # The object to use for commands.
17
+ # @option options [Hash] :hooks
18
+ # The defined hook Procs.
19
+ # @option options [Proc] :print
20
+ # The Proc to use for printing return values.
21
+ # @option options [Boolean] :quiet
22
+ # Omit the `whereami` banner when starting.
23
+ # @option options [Array<String>] :backtrace
24
+ # The backtrace of the session's `binding.pry` line, if applicable.
25
+ def start(options = {})
26
+ options = options.reverse_merge(target: MB::Application, prompt: method(:default_prompt))
27
+ super(options)
28
+ end
29
+
30
+ def default_prompt(target, nest_level, pry)
31
+ "mb(#{Pry.view_clip(target.class)}: #{Pry.view_clip(target)}):[#{nest_level}] >> "
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,73 @@
1
+ module MotherBrain
2
+ class CookbookMetadata < ::Ridley::Chef::Cookbook::Metadata
3
+
4
+ RUBY_FILENAME = 'metadata.rb'.freeze
5
+ JSON_FILENAME = 'metadata.json'.freeze
6
+
7
+ class << self
8
+ # @return [Cookbook::Metadata]
9
+ def load(&block)
10
+ klass = new()
11
+ klass.instance_eval(&block) if block_given?
12
+ klass
13
+ end
14
+
15
+ # @param [#to_s] filepath
16
+ #
17
+ # @return [Cookbook::Metadata]
18
+ def from_file(filepath)
19
+ filepath = filepath.to_s
20
+
21
+ if File.extname(filepath) =~ /\.json/
22
+ from_json_file(filepath)
23
+ else
24
+ from_ruby_file(filepath)
25
+ end
26
+ end
27
+
28
+ # @param [#to_s] path
29
+ #
30
+ # @return [Cookbook::Metadata]
31
+ def from_path(path)
32
+ ruby_file = File.join(path, RUBY_FILENAME)
33
+ json_file = File.join(path, JSON_FILENAME)
34
+ metadata_file = File.exists?(json_file) ? json_file : ruby_file
35
+
36
+ from_file(metadata_file)
37
+ end
38
+
39
+ private
40
+
41
+ def from_ruby_file(filepath)
42
+ load { eval(File.read(filepath), binding, filepath, 1) }
43
+ end
44
+
45
+ def from_json_file(filepath)
46
+ load { from_json(File.read(filepath)) }
47
+ end
48
+ end
49
+
50
+ # @param [Cookbook::Metadata]
51
+ def initialize(&block)
52
+ super
53
+
54
+ begin
55
+ self.instance_eval(&block) if block_given?
56
+ rescue => e
57
+ raise MotherBrain::InvalidCookbookMetadata, e
58
+ end
59
+ end
60
+
61
+ # Override the default version with [Solve::Version]
62
+ #
63
+ # @return [Solve::Version]
64
+ def version(data = nil)
65
+ @version = data.nil? ? @version : Solve::Version.new(data)
66
+ end
67
+
68
+ private
69
+
70
+ def method_missing(*args); nil end
71
+
72
+ end
73
+ end