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.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.ruby-version +1 -0
- data/.travis.yml +9 -0
- data/CHANGELOG.md +196 -0
- data/COMMANDS.md +9 -0
- data/CONTRIBUTING.md +24 -0
- data/Dockerfile +26 -0
- data/Gemfile +60 -2
- data/Guardfile +30 -0
- data/LICENSE +10 -0
- data/MANIFESTS.md +90 -0
- data/OPERATORS_GUIDE.md +195 -0
- data/PLUGINS.md +268 -0
- data/README.md +304 -16
- data/Thorfile +123 -0
- data/VAGRANT.md +116 -0
- data/bin/boot +9 -0
- data/bin/mb +5 -0
- data/bin/mbsrv +5 -0
- data/config.json +32 -0
- data/features/cli/bootstrap_command/configurable_scripts.feature +32 -0
- data/features/cli/configure_command.feature +57 -0
- data/features/cli/environment_command/create_command.feature +22 -0
- data/features/cli/environment_command/destroy_command.feature +33 -0
- data/features/cli/environment_command/from_command.feature +29 -0
- data/features/cli/environment_command/list_command.feature +0 -0
- data/features/cli/node_limiting.feature +47 -0
- data/features/cli/plugin_command/list_command.feature +46 -0
- data/features/cli/service_command/service_command.feature +21 -0
- data/features/cli/template_command.feature +10 -0
- data/features/cli/validate_config.feature +46 -0
- data/features/step_definitions/bootstrap_steps.rb +57 -0
- data/features/step_definitions/chef_server_steps.rb +3 -0
- data/features/step_definitions/configuration_steps.rb +18 -0
- data/features/step_definitions/core_cli_steps.rb +33 -0
- data/features/step_definitions/environment_steps.rb +43 -0
- data/features/step_definitions/node_steps.rb +3 -0
- data/features/step_definitions/plugin_steps.rb +15 -0
- data/features/step_definitions/template_steps.rb +7 -0
- data/features/support/env.rb +68 -0
- data/lib/mb/api.rb +8 -0
- data/lib/mb/api/application.rb +7 -0
- data/lib/mb/api/endpoint.rb +5 -0
- data/lib/mb/api/helpers.rb +38 -0
- data/lib/mb/api/v1.rb +56 -0
- data/lib/mb/api/v1/config_endpoint.rb +12 -0
- data/lib/mb/api/v1/environments_endpoint.rb +174 -0
- data/lib/mb/api/v1/jobs_endpoint.rb +31 -0
- data/lib/mb/api/v1/plugins_endpoint.rb +90 -0
- data/lib/mb/api/validators.rb +5 -0
- data/lib/mb/api/validators/sem_ver.rb +18 -0
- data/lib/mb/application.rb +148 -0
- data/lib/mb/berkshelf.rb +50 -0
- data/lib/mb/bootstrap.rb +9 -0
- data/lib/mb/bootstrap/manager.rb +250 -0
- data/lib/mb/bootstrap/manifest.rb +131 -0
- data/lib/mb/bootstrap/routine.rb +199 -0
- data/lib/mb/bootstrap/template.rb +73 -0
- data/lib/mb/bootstrap/worker.rb +227 -0
- data/lib/mb/chef.rb +6 -0
- data/lib/mb/chef/config.rb +69 -0
- data/lib/mb/chef/run_list_item.rb +115 -0
- data/lib/mb/chef_mutex.rb +304 -0
- data/lib/mb/clean_room_base.rb +39 -0
- data/lib/mb/cli.rb +50 -0
- data/lib/mb/cli/base.rb +51 -0
- data/lib/mb/cli/shell.rb +29 -0
- data/lib/mb/cli/shell/basic.rb +11 -0
- data/lib/mb/cli/shell/color.rb +11 -0
- data/lib/mb/cli/shell/ext.rb +41 -0
- data/lib/mb/cli/sub_command.rb +95 -0
- data/lib/mb/cli/sub_command/component.rb +56 -0
- data/lib/mb/cli/sub_command/plugin.rb +232 -0
- data/lib/mb/cli_client.rb +178 -0
- data/lib/mb/cli_gateway.rb +426 -0
- data/lib/mb/cli_gateway/sub_commands.rb +3 -0
- data/lib/mb/cli_gateway/sub_commands/environment.rb +124 -0
- data/lib/mb/cli_gateway/sub_commands/plugin.rb +148 -0
- data/lib/mb/command.rb +88 -0
- data/lib/mb/command_invoker.rb +235 -0
- data/lib/mb/command_invoker/worker.rb +40 -0
- data/lib/mb/command_runner.rb +233 -0
- data/lib/mb/component.rb +245 -0
- data/lib/mb/config.rb +275 -0
- data/lib/mb/config_manager.rb +75 -0
- data/lib/mb/console.rb +35 -0
- data/lib/mb/cookbook_metadata.rb +73 -0
- data/lib/mb/core_ext.rb +3 -0
- data/lib/mb/core_ext/dir.rb +37 -0
- data/lib/mb/core_ext/enumerable.rb +48 -0
- data/lib/mb/core_ext/file.rb +24 -0
- data/lib/mb/core_ext/signal.rb +11 -0
- data/lib/mb/environment_manager.rb +195 -0
- data/lib/mb/error_handler.rb +212 -0
- data/lib/mb/errors.rb +693 -0
- data/lib/mb/file_system.rb +60 -0
- data/lib/mb/file_system/tempfile.rb +25 -0
- data/lib/mb/gear.rb +154 -0
- data/lib/mb/gears.rb +8 -0
- data/lib/mb/gears/dynamic_service.rb +218 -0
- data/lib/mb/gears/jmx.rb +24 -0
- data/lib/mb/gears/jmx/action.rb +46 -0
- data/lib/mb/gears/mysql.rb +20 -0
- data/lib/mb/gears/mysql/action.rb +190 -0
- data/lib/mb/gears/service.rb +163 -0
- data/lib/mb/gears/service/action.rb +58 -0
- data/lib/mb/gears/service/action_runner.rb +161 -0
- data/lib/mb/grape_ext.rb +3 -0
- data/lib/mb/grape_ext/endpoint.rb +13 -0
- data/lib/mb/group.rb +143 -0
- data/lib/mb/job.rb +183 -0
- data/lib/mb/job/state_machine.rb +34 -0
- data/lib/mb/job/states.rb +46 -0
- data/lib/mb/job_manager.rb +96 -0
- data/lib/mb/job_record.rb +67 -0
- data/lib/mb/job_ticket.rb +25 -0
- data/lib/mb/lock_manager.rb +116 -0
- data/lib/mb/logging.rb +134 -0
- data/lib/mb/logging/basic_format.rb +31 -0
- data/lib/mb/manifest.rb +128 -0
- data/lib/mb/mixin.rb +3 -0
- data/lib/mb/mixin/attribute_setting.rb +265 -0
- data/lib/mb/mixin/coded_exit.rb +49 -0
- data/lib/mb/mixin/locks.rb +54 -0
- data/lib/mb/mixin/services.rb +100 -0
- data/lib/mb/node_filter.rb +97 -0
- data/lib/mb/node_querier.rb +527 -0
- data/lib/mb/plugin.rb +300 -0
- data/lib/mb/plugin_manager.rb +589 -0
- data/lib/mb/provisioner.rb +186 -0
- data/lib/mb/provisioner/manager.rb +213 -0
- data/lib/mb/provisioner/manifest.rb +125 -0
- data/lib/mb/provisioner/provision_data.rb +96 -0
- data/lib/mb/provisioners.rb +5 -0
- data/lib/mb/provisioners/aws.rb +395 -0
- data/lib/mb/rest_gateway.rb +72 -0
- data/lib/mb/ridley_ext.rb +5 -0
- data/lib/mb/ridley_ext/cookbook_object.rb +15 -0
- data/lib/mb/srv_ctl.rb +183 -0
- data/lib/mb/test.rb +104 -0
- data/lib/mb/thor_ext.rb +49 -0
- data/lib/mb/upgrade.rb +6 -0
- data/lib/mb/upgrade/manager.rb +85 -0
- data/lib/mb/upgrade/worker.rb +149 -0
- data/lib/mb/version.rb +1 -1
- data/lib/motherbrain.rb +166 -2
- data/man/man_helper.rb +81 -0
- data/man/mb.1 +494 -0
- data/man/mb.1.html +300 -0
- data/man/mb.1.ronn.erb +62 -0
- data/motherbrain.gemspec +56 -20
- data/scripts/node_name.rb +14 -0
- data/spec/fixtures/cb_metadata.json +7 -0
- data/spec/fixtures/cb_metadata.rb +14 -0
- data/spec/fixtures/fake_id_rsa +27 -0
- data/spec/fixtures/fake_key.pem +27 -0
- data/spec/fixtures/myface-0.1.0/metadata.rb +14 -0
- data/spec/fixtures/myface-0.1.0/motherbrain.rb +0 -0
- data/spec/fixtures/test_env.json +15 -0
- data/spec/spec_helper.rb +67 -0
- data/spec/support/actor_mocking.rb +7 -0
- data/spec/support/berkshelf.rb +24 -0
- data/spec/support/chef_server.rb +102 -0
- data/spec/support/doubles.rb +11 -0
- data/spec/support/klass.rb +10 -0
- data/spec/support/matchers/each.rb +12 -0
- data/spec/support/matchers/error_codes.rb +5 -0
- data/spec/support/matchers/exit_codes.rb +57 -0
- data/spec/support/matchers/jobs.rb +11 -0
- data/spec/support/spec_helpers.rb +145 -0
- data/spec/unit/mb/api/application_spec.rb +11 -0
- data/spec/unit/mb/api/helpers_spec.rb +5 -0
- data/spec/unit/mb/api/v1/config_endpoint_spec.rb +19 -0
- data/spec/unit/mb/api/v1/environments_endpoint_spec.rb +71 -0
- data/spec/unit/mb/api/v1/jobs_endpoint_spec.rb +24 -0
- data/spec/unit/mb/api/v1/plugins_endpoint_spec.rb +298 -0
- data/spec/unit/mb/api/v1_spec.rb +37 -0
- data/spec/unit/mb/api/validators/sem_ver_spec.rb +5 -0
- data/spec/unit/mb/application_spec.rb +19 -0
- data/spec/unit/mb/berkshelf_spec.rb +38 -0
- data/spec/unit/mb/bootstrap/manager_spec.rb +347 -0
- data/spec/unit/mb/bootstrap/manifest_spec.rb +333 -0
- data/spec/unit/mb/bootstrap/routine_spec.rb +393 -0
- data/spec/unit/mb/bootstrap/template_spec.rb +100 -0
- data/spec/unit/mb/bootstrap/worker_spec.rb +194 -0
- data/spec/unit/mb/chef/config_spec.rb +33 -0
- data/spec/unit/mb/chef/run_list_item_spec.rb +34 -0
- data/spec/unit/mb/chef_mutex_spec.rb +314 -0
- data/spec/unit/mb/clean_room_base_spec.rb +31 -0
- data/spec/unit/mb/cli/base_spec.rb +43 -0
- data/spec/unit/mb/cli/shell/basic_spec.rb +5 -0
- data/spec/unit/mb/cli/shell/color_spec.rb +5 -0
- data/spec/unit/mb/cli/shell/ext_spec.rb +11 -0
- data/spec/unit/mb/cli/shell_spec.rb +38 -0
- data/spec/unit/mb/cli/sub_command/base_spec.rb +102 -0
- data/spec/unit/mb/cli/sub_command/component_spec.rb +5 -0
- data/spec/unit/mb/cli/sub_command/plugin_spec.rb +91 -0
- data/spec/unit/mb/cli/sub_command_spec.rb +43 -0
- data/spec/unit/mb/cli/ui.rb +0 -0
- data/spec/unit/mb/cli_client_spec.rb +51 -0
- data/spec/unit/mb/cli_gateway_spec.rb +386 -0
- data/spec/unit/mb/command_invoker/worker_spec.rb +43 -0
- data/spec/unit/mb/command_invoker_spec.rb +230 -0
- data/spec/unit/mb/command_runner_spec.rb +299 -0
- data/spec/unit/mb/command_spec.rb +76 -0
- data/spec/unit/mb/component_spec.rb +185 -0
- data/spec/unit/mb/config_manager_spec.rb +31 -0
- data/spec/unit/mb/config_spec.rb +408 -0
- data/spec/unit/mb/cookbook_metadata_spec.rb +89 -0
- data/spec/unit/mb/core_ext/dir_spec.rb +92 -0
- data/spec/unit/mb/core_ext/enumerable_spec.rb +104 -0
- data/spec/unit/mb/core_ext/file_spec.rb +58 -0
- data/spec/unit/mb/core_ext/signal_spec.rb +24 -0
- data/spec/unit/mb/environment_manager_spec.rb +166 -0
- data/spec/unit/mb/error_handler_spec.rb +173 -0
- data/spec/unit/mb/errors_spec.rb +132 -0
- data/spec/unit/mb/file_system/tempfile_spec.rb +14 -0
- data/spec/unit/mb/file_system_spec.rb +69 -0
- data/spec/unit/mb/gear_spec.rb +125 -0
- data/spec/unit/mb/gears/dynamic_service_spec.rb +187 -0
- data/spec/unit/mb/gears/jmx/action_spec.rb +34 -0
- data/spec/unit/mb/gears/jmx_spec.rb +32 -0
- data/spec/unit/mb/gears/mysql/action_spec.rb +118 -0
- data/spec/unit/mb/gears/mysql_spec.rb +21 -0
- data/spec/unit/mb/gears/service/action_runner_spec.rb +182 -0
- data/spec/unit/mb/gears/service/action_spec.rb +44 -0
- data/spec/unit/mb/gears/service_spec.rb +124 -0
- data/spec/unit/mb/group_spec.rb +280 -0
- data/spec/unit/mb/job_manager_spec.rb +56 -0
- data/spec/unit/mb/job_record_spec.rb +60 -0
- data/spec/unit/mb/job_spec.rb +201 -0
- data/spec/unit/mb/locks_manager_spec.rb +88 -0
- data/spec/unit/mb/logging_spec.rb +133 -0
- data/spec/unit/mb/manifest_spec.rb +105 -0
- data/spec/unit/mb/mixin/attribute_setting_spec.rb +180 -0
- data/spec/unit/mb/mixin/coded_exit_spec.rb +25 -0
- data/spec/unit/mb/mixin/locks_spec.rb +32 -0
- data/spec/unit/mb/mixin/services_spec.rb +75 -0
- data/spec/unit/mb/node_filter_spec.rb +86 -0
- data/spec/unit/mb/node_querier_spec.rb +532 -0
- data/spec/unit/mb/plugin_manager_spec.rb +724 -0
- data/spec/unit/mb/plugin_spec.rb +247 -0
- data/spec/unit/mb/provisioner/manager_spec.rb +141 -0
- data/spec/unit/mb/provisioner/manifest_spec.rb +182 -0
- data/spec/unit/mb/provisioner/provision_data_spec.rb +113 -0
- data/spec/unit/mb/provisioner_spec.rb +251 -0
- data/spec/unit/mb/provisioners/aws_spec.rb +392 -0
- data/spec/unit/mb/provisioners/environment_factory_spec.rb +108 -0
- data/spec/unit/mb/rest_gateway_spec.rb +13 -0
- data/spec/unit/mb/ridley_ext/cookbook_object_spec.rb +105 -0
- data/spec/unit/mb/srv_ctl_spec.rb +142 -0
- data/spec/unit/mb/upgrade/manager_spec.rb +37 -0
- data/spec/unit/mb/upgrade/worker_spec.rb +219 -0
- data/spec/unit/motherbrain_spec.rb +58 -0
- data/templates/bootstrap.json +8 -0
- data/templates/motherbrain.rb +44 -0
- metadata +694 -15
- data/Rakefile +0 -1
@@ -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
|