Class: MCollective::Application::Plugin
- Inherits:
-
MCollective::Application
- Object
- MCollective::Application
- MCollective::Application::Plugin
- Defined in:
- lib/mcollective/application/plugin.rb
Overview
rubocop:disable Style/ClassAndModuleChildren
Instance Attribute Summary
Attributes inherited from MCollective::Application
Instance Method Summary collapse
-
#doc_command ⇒ Object
Show application list and plugin help.
-
#generate_command ⇒ Object
Generate a plugin skeleton.
-
#identify_plugin ⇒ Object
If plugintype is StandardDefinition, identify which of the special plugin types we are dealing with based on directory structure.
-
#load_plugin_ddl(plugin, type) ⇒ Object
Agents are just called ‘agent’ but newer plugin types are called plugin_plugintype for example facter_facts etc so this will first try the old way then the new way.
- #main ⇒ Object
-
#package_command ⇒ Object
Package plugin.
- #plugin_directory_exists?(plugin_type) ⇒ Boolean
-
#post_option_parser(configuration) ⇒ Object
Handle alternative format that optparser can’t parse.
-
#prepare_plugin ⇒ Object
Creates the correct package plugin object.
-
#set_plugin_type ⇒ Object
Identify plugin type if not provided.
Methods inherited from MCollective::Application
[], []=, #application_cli_arguments, #application_description, #application_failure, application_options, #application_options, #application_parse_options, #application_usage, #clioptions, #configuration, description, #disconnect, exclude_argument_sections, external, external_help, #external_help, #external_main, #halt, #halt_code, #help, intialize_application_options, option, #rpcclient, #run, usage, #validate_cli_options, #validate_option
Methods included from RPC
const_missing, discovered, #empty_filter?, #printrpc, #printrpcstats, #rpcclient, #rpcoptions, stats
Instance Method Details
#doc_command ⇒ Object
Show application list and plugin help
139 140 141 142 143 |
# File 'lib/mcollective/application/plugin.rb', line 139 def doc_command puts "WARNING: mco plugin doc is deprecated, please use choria plugin doc" exec("choria plugin doc %s" % [configuration[:target]]) end |
#generate_command ⇒ Object
Generate a plugin skeleton
104 105 106 |
# File 'lib/mcollective/application/plugin.rb', line 104 def generate_command puts "CRITICAL: mco plugin generate is deprecated, please use 'choria plugin generate'" end |
#identify_plugin ⇒ Object
If plugintype is StandardDefinition, identify which of the special plugin types we are dealing with based on directory structure. To keep it simple we limit it to one type per target directory. Return the name of the type of plugin as a string
193 194 195 196 197 198 199 200 201 202 |
# File 'lib/mcollective/application/plugin.rb', line 193 def identify_plugin plugintype = Dir.glob(File.join(configuration[:target], "*")).select do |file| File.directory?(file) && file.match(/(connector|facts|registration|security|audit|pluginpackager|discovery|validator)/) end raise "more than one plugin type detected in directory" if plugintype.size > 1 raise "no plugins detected in directory" if plugintype.empty? File.basename(plugintype[0]) end |
#load_plugin_ddl(plugin, type) ⇒ Object
Agents are just called ‘agent’ but newer plugin types are called plugin_plugintype for example facter_facts etc so this will first try the old way then the new way.
126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/mcollective/application/plugin.rb', line 126 def load_plugin_ddl(plugin, type) [plugin, "#{plugin}_#{type}"].each do |p| ddl = DDL.new(p, type, false) if ddl.client_activated? && ddl.findddlfile(p, type) ddl.loadddlfile return ddl end end nil end |
#main ⇒ Object
204 205 206 207 208 209 210 211 212 213 214 |
# File 'lib/mcollective/application/plugin.rb', line 204 def main abort "No action specified, please run 'mco help plugin' for help" unless configuration.include?(:action) cmd = "#{configuration[:action]}_command" if respond_to? cmd send cmd else abort "Invalid action #{configuration[:action]}, please run 'mco help plugin' for help." end end |
#package_command ⇒ Object
Package plugin
109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/mcollective/application/plugin.rb', line 109 def package_command if configuration[:sign] && Config.instance.pluginconf.include?("debian_packager.keyname") configuration[:sign] = Config.instance.pluginconf["debian_packager.keyname"] configuration[:sign] = "\"#{configuration[:sign]}\"" unless configuration[:sign].match(/".*"/) end plugin = prepare_plugin (configuration[:pluginpath] = "#{configuration[:pluginpath]}/") if configuration[:pluginpath] && !configuration[:pluginpath].match(/^.*\/$/) packager = PluginPackager["#{configuration[:format].capitalize}Packager"] packager.new(plugin, configuration[:pluginpath], configuration[:sign], [:verbose], configuration[:keep_artifacts], configuration[:module_template]).create_packages end |
#plugin_directory_exists?(plugin_type) ⇒ Boolean
172 173 174 |
# File 'lib/mcollective/application/plugin.rb', line 172 def plugin_directory_exists?(plugin_type) File.directory?(File.join(PluginPackager.get_plugin_path(configuration[:target]), plugin_type)) end |
#post_option_parser(configuration) ⇒ Object
Handle alternative format that optparser can’t parse.
95 96 97 98 99 100 101 |
# File 'lib/mcollective/application/plugin.rb', line 95 def post_option_parser(configuration) if ARGV.length >= 1 configuration[:action] = ARGV.delete_at(0) configuration[:target] = ARGV.delete_at(0) || "." end end |
#prepare_plugin ⇒ Object
Creates the correct package plugin object.
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 |
# File 'lib/mcollective/application/plugin.rb', line 146 def prepare_plugin plugintype = set_plugin_type unless configuration[:plugintype] configuration[:format] = "forge" unless configuration[:format] PluginPackager.load_packagers plugin_class = PluginPackager[configuration[:plugintype]] if configuration[:dependency] && configuration[:dependency].size == 1 configuration[:dependency] = configuration[:dependency][0].split(" ") elsif configuration[:dependency] configuration[:dependency].map! {|dep| {:name => dep, :version => nil}} end mcdependency = { :mcname => configuration[:mcname], :mcversion => configuration[:mcversion] } # Deprecation warning for --iteration if configuration[:iteration] puts "Warning. The --iteration flag has been deprecated. Please use --revision instead." configuration[:revision] = configuration[:iteration] unless configuration[:revision] end plugin_class.new(configuration, mcdependency, plugintype) end |
#set_plugin_type ⇒ Object
Identify plugin type if not provided.
177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/mcollective/application/plugin.rb', line 177 def set_plugin_type if plugin_directory_exists?("agent") || plugin_directory_exists?("application") configuration[:plugintype] = "AgentDefinition" "Agent" elsif plugin_directory_exists?(plugintype = identify_plugin) configuration[:plugintype] = "StandardDefinition" plugintype else raise "target directory is not a valid mcollective plugin" end end |