Class: MotherBrain::Cli::SubCommand::Plugin Private
- Extended by:
- Forwardable
- Defined in:
- lib/mb/cli/sub_command/plugin.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
A set of component tasks collected into a SubCommand to be registered with the CliGateway. This class should not be instantiated, configured, and used by itself. Use Plugin.fabricate to create an anonymous class of this type.
Class Attribute Summary collapse
-
.plugin ⇒ MotherBrain::Plugin
readonly
private
Return the plugin used to generate the anonymous CLI class.
Class Method Summary collapse
- .fabricate(plugin) ⇒ SubCommand::Plugin private
-
.set_plugin(plugin) ⇒ Object
private
Set the plugin for this instance of the class and tailor the class for the given plugin.
Methods inherited from Base
define_task, description, usage
Methods inherited from Base
Class Attribute Details
.plugin ⇒ MotherBrain::Plugin (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return the plugin used to generate the anonymous CLI class
18 19 20 |
# File 'lib/mb/cli/sub_command/plugin.rb', line 18 def plugin @plugin end |
Class Method Details
.fabricate(plugin) ⇒ SubCommand::Plugin
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 |
# File 'lib/mb/cli/sub_command/plugin.rb', line 23 def fabricate(plugin) environment = CliGateway.invoked_opts[:environment] klass = Class.new(self) do include MB::Mixin::Services set_plugin(plugin) end plugin.commands.each do |command| klass.define_task(command) end plugin.components.each do |component| klass.register_subcommand MB::Cli::SubCommand.new(component) end klass.class_eval do desc("nodes", "List all nodes grouped by Component and Group") define_method(:nodes) do nodes = plugin.nodes(environment).each do |component, groups| groups.each do |group, nodes| nodes.collect! { |node| "#{node.public_hostname} (#{node.public_ipv4})" } end end ui.say "\n" ui.say "** listing nodes in #{environment}:" ui.say "\n" ui.say nodes.to_yaml end if plugin.bootstrap_routine.present? method_option :chef_version, type: :string, desc: "The version of Chef to bootstrap the node(s) with" method_option :component_versions, type: :hash, desc: "The component versions to set with default attributes", aliases: "--components" method_option :cookbook_versions, type: :hash, hidden: true, desc: "The cookbook versions to set on the environment", aliases: "--cookbooks" method_option :environment_attributes, type: :hash, desc: "Any additional attributes to set on the environment", aliases: "--attributes" method_option :environment_attributes_file, type: :string, desc: "Any additional attributes to set on the environment via a json file.", aliases: "--attributes-file" method_option :template, type: :string, desc: "Path to bootstrap template (ERB)" method_option :force, type: :boolean, default: false, desc: "Perform bootstrap even if the environment is locked", aliases: "-f" desc("bootstrap MANIFEST", "Bootstrap a manifest of node groups") define_method(:bootstrap) do |manifest_file| = Hash.new.merge().deep_symbolize_keys manifest = MB::Bootstrap::Manifest.from_file(manifest_file) cookbooks_option_deprecated() job = bootstrapper.async_bootstrap( environment.freeze, manifest.freeze, plugin.freeze, .freeze ) CliClient.new(job).display end method_option :chef_version, type: :string, desc: "The version of Chef to bootstrap the node(s) with" method_option :component_versions, type: :hash, desc: "The component versions to set with default attributes", aliases: "--components" method_option :cookbook_versions, type: :hash, hidden: true, desc: "The cookbook versions to set on the environment", aliases: "--cookbooks" method_option :environment_attributes, type: :hash, desc: "Any additional attributes to set on the environment", aliases: "--attributes" method_option :environment_attributes_file, type: :string, desc: "Any additional attributes to set on the environment via a json file.", aliases: "--attributes-file" method_option :skip_bootstrap, type: :boolean, desc: "Nodes will be created and added to the Chef environment but not bootstrapped", default: false method_option :template, type: :string, desc: "Path to bootstrap template (ERB)" method_option :force, type: :boolean, default: false, desc: "Perform bootstrap even if the environment is locked" desc("provision MANIFEST", "Create a cluster of nodes and add them to a Chef environment") define_method(:provision) do |manifest_file| = Hash.new.merge().deep_symbolize_keys manifest = Provisioner::Manifest.from_file(manifest_file) cookbooks_option_deprecated() job = provisioner.async_provision( environment.freeze, manifest.freeze, plugin.freeze, .freeze ) CliClient.new(job).display end method_option :cluster_override, type: :boolean, default: false, desc: "Sets the service operation to execute at the environment level" method_option :force, type: :boolean, default: false, desc: "Perform service change even if the environment is locked", aliases: "-f" method_option :only, type: :array, default: nil, desc: "Run command only on the given hostnames or IPs", aliases: "-o" desc("service [COMPONENT].[SERVICE] [STATE]", "Change the specified service to a new state") define_method(:service) do |service, state| = Hash.new.merge().deep_symbolize_keys [:node_filter] = .delete(:only) job = plugin_manager.async_change_service_state( service.freeze, plugin.freeze, environment.freeze, state.freeze, true, ) CliClient.new(job).display end method_option :component_versions, type: :hash, desc: "The component versions to set with default attributes", aliases: "--components" method_option :cookbook_versions, type: :hash, hide: true, desc: "The cookbook versions to set on the environment", aliases: "--cookbooks" method_option :environment_attributes, type: :hash, desc: "Any additional attributes to set on the environment", aliases: "--attributes" method_option :environment_attributes_file, type: :string, desc: "Any additional attributes to set on the environment via a json file.", aliases: "--attributes-file" method_option :force, type: :boolean, default: false, desc: "Perform upgrade even if the environment is locked", aliases: "-f" method_option :concurrency, type: :numeric, desc: "The max number of nodes to upgrade concurrently.", aliases: "-C" method_option :stack_order, type: :boolean, desc: "The upgrade will be constrained to the order defined in the plugin's stack_order." desc("upgrade", "Upgrade an environment to the specified versions") define_method(:upgrade) do = Hash.new.merge().deep_symbolize_keys cookbooks_option_deprecated() job = upgrade_manager.async_upgrade( environment.freeze, plugin.freeze, .freeze ) CliClient.new(job).display end desc("attributes", "View available attributes for plugin.") define_method(:attributes) do ui.say "\n" ui.say "** listing attributes for #{plugin}:" ui.say "\n" ui.say plugin..attributes.to_yaml end end no_commands do def cookbooks_option_deprecated() if [:cookbook_versions] ui.deprecated "--cookbooks option is deprecated in favor of loading versions from Berksfile.lock" end end end end klass end |
.set_plugin(plugin) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Set the plugin for this instance of the class and tailor the class for the given plugin.
247 248 249 250 |
# File 'lib/mb/cli/sub_command/plugin.rb', line 247 def set_plugin(plugin) self.namespace(plugin.name) @plugin = plugin end |