choria-mcorpc-support 2.24.2 → 2.24.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8c9b96995926bcb736c4d7340f1e35c82673db5ce74de15443a79fba36873a2a
4
- data.tar.gz: f00bd913097f164271403440750015b73041d61b54712dadc728f0b56859d9c9
3
+ metadata.gz: cda09be3dbdb88b142247d02b8ee0f03d8198a1b4138b3b4d77b1143f692400a
4
+ data.tar.gz: c86ce219df50736213dd3da1915869c2971316f454f1377564c3147a48670c55
5
5
  SHA512:
6
- metadata.gz: 996376fe60e4d07d576f18900fb17c062888e467dc04354b58665d7f16ac55dbd44a778146d70e517ea4e5c5ba11cc3437a83ac83644ff9493fcb3c48cc5fece
7
- data.tar.gz: 217bcb3d3b7ec754dcb0756c68d68ec539546b44f084191b5abd47a21628b1029deabe118ab356db34a5727565734d34bf74c15d4c518a9fcc8109a066442fab
6
+ metadata.gz: a799daf56ba217197c4e3b66ae81e583eb4f5e88229b3f9e0b3e99ae4b666eb29388f7fa21c7cc8f9dbd5731c78016277978d1ed084c02593ae120694877a40d
7
+ data.tar.gz: 1bd34b265c722b9170d8a530caab0581809dbd812fae49bfa1337ee5e06eda441b22a0dcc67dd8b4341963ec85890d2442a5432bb34278cd0813f3ab5642b5e9
data/lib/mcollective.rb CHANGED
@@ -43,7 +43,6 @@ module MCollective
43
43
  require "mcollective/log"
44
44
  require "mcollective/message"
45
45
  require "mcollective/optionparser"
46
- require "mcollective/generators"
47
46
  require "mcollective/pluginmanager"
48
47
  require "mcollective/pluginpackager"
49
48
  require "mcollective/rpc"
@@ -8,18 +8,14 @@ mco plugin package [options] <directory>
8
8
  mco plugin info <directory>
9
9
  mco plugin doc <plugin>
10
10
  mco plugin doc <type/plugin>
11
- mco plugin generate agent <pluginname> [actions=val,val]
11
+ mco plugin generate client <ddl> <target>
12
+ mco plugin generate ddl <json_output> <ruby_output>
12
13
 
13
14
  info : Display plugin information including package details.
14
15
  package : Create all available plugin packages.
15
16
  doc : Display documentation for a specific plugin.
16
17
  END_OF_USAGE
17
18
 
18
- option :pluginname,
19
- :description => "Plugin name",
20
- :arguments => ["-n", "--name NAME"],
21
- :type => String
22
-
23
19
  option :postinstall,
24
20
  :description => "Post install script",
25
21
  :arguments => ["--postinstall POSTINSTALL"],
@@ -66,7 +62,7 @@ mco plugin package [options] <directory>
66
62
  :type => :array
67
63
 
68
64
  option :format,
69
- :description => "Package output format. Defaults to rpmpackage or debpackage",
65
+ :description => "Package output format. Defaults to forge",
70
66
  :arguments => ["--format OUTPUTFORMAT"],
71
67
  :type => String
72
68
 
@@ -80,41 +76,11 @@ mco plugin package [options] <directory>
80
76
  :arguments => ["--template HELPTEMPLATE"],
81
77
  :type => String
82
78
 
83
- option :description,
84
- :description => "Plugin description",
85
- :arguments => ["--description DESCRIPTION"],
86
- :type => String
87
-
88
- option :author,
89
- :description => "The author of the plugin",
90
- :arguments => ["--author AUTHOR"],
91
- :type => String
92
-
93
- option :license,
94
- :description => "The license under which the plugin is distributed",
95
- :arguments => ["--license LICENSE"],
96
- :type => String
97
-
98
79
  option :version,
99
80
  :description => "The version of the plugin",
100
81
  :arguments => ["--pluginversion VERSION"],
101
82
  :type => String
102
83
 
103
- option :url,
104
- :description => "Url at which information about the plugin can be found",
105
- :arguments => ["--url URL"],
106
- :type => String
107
-
108
- option :timeout,
109
- :description => "The plugin's timeout",
110
- :arguments => ["--timeout TIMEOUT"],
111
- :type => Integer
112
-
113
- option :actions,
114
- :description => "Actions to be generated for an Agent Plugin",
115
- :arguments => ["--actions [ACTIONS]"],
116
- :type => Array
117
-
118
84
  option :keep_artifacts,
119
85
  :description => "Don't remove artifacts after building packages",
120
86
  :arguments => ["--keep-artifacts"],
@@ -131,53 +97,12 @@ mco plugin package [options] <directory>
131
97
  configuration[:action] = ARGV.delete_at(0)
132
98
 
133
99
  configuration[:target] = ARGV.delete_at(0) || "."
134
-
135
- if configuration[:action] == "generate"
136
- unless ARGV[0] && ARGV[0].match(/(actions|outputs)=(.+)/i)
137
- if configuration[:pluginname] # rubocop:disable Metrics/BlockNesting
138
- ARGV.delete_at(0)
139
- else
140
- configuration[:pluginname] = ARGV.delete_at(0)
141
- end
142
- end
143
-
144
- ARGV.each do |argument|
145
- if argument.match(/(actions|outputs)=(.+)/i)
146
- configuration[$1.downcase.to_sym] = $2.split(",")
147
- else
148
- raise "Could not parse --arg '#{argument}'"
149
- end
150
- end
151
- end
152
100
  end
153
101
  end
154
102
 
155
- # Display info about plugin
156
- def info_command
157
- plugin = prepare_plugin
158
- packager = PluginPackager["#{configuration[:format].capitalize}Packager"]
159
- packager.new(plugin).package_information
160
- end
161
-
162
103
  # Generate a plugin skeleton
163
104
  def generate_command
164
- raise "undefined plugin type. cannot generate plugin. valid types are 'agent'" if configuration["target"] == "."
165
-
166
- unless configuration[:pluginname]
167
- puts "No plugin name specified. Using 'new_plugin'"
168
- configuration[:pluginname] = "new_plugin"
169
- end
170
-
171
- load_plugin_config_values
172
-
173
- case configuration[:target].downcase
174
- when "agent"
175
- Generators::AgentGenerator.new(configuration[:pluginname], configuration[:actions], configuration[:pluginname],
176
- configuration[:description], configuration[:author], configuration[:license],
177
- configuration[:version], configuration[:url], configuration[:timeout])
178
- else
179
- raise "invalid plugin type. cannot generate plugin '#{configuration[:target]}'"
180
- end
105
+ puts "CRITICAL: mco plugin generate is deprecated, please use 'choria plugin generate'"
181
106
  end
182
107
 
183
108
  # Package plugin
@@ -211,75 +136,10 @@ mco plugin package [options] <directory>
211
136
  end
212
137
 
213
138
  # Show application list and plugin help
214
- def doc_command # rubocop:disable Metrics/MethodLength
215
- known_plugin_types = [
216
- ["Agents", :agent],
217
- ["Aggregate", :aggregate],
218
- ["Connectors", :connector],
219
- ["Discovery Methods", :discovery],
220
- ["Validator Plugins", :validator]
221
- ]
222
-
223
- if configuration.include?(:target) && configuration[:target] != "."
224
- if configuration[:target] =~ /^(.+?)\/(.+)$/
225
- ddl = load_plugin_ddl($2.to_sym, $1)
226
- else
227
- found_plugin_type = nil
228
-
229
- known_plugin_types.each do |plugin_type|
230
- PluginManager.find(plugin_type[1], "ddl").each do |ddlf|
231
- pluginname = ddlf.gsub(/_#{plugin_type[1]}$/, "")
232
-
233
- abort "Duplicate plugin name found, please specify a full path like agent/rpcutil" if pluginname == configuration[:target] && found_plugin_type
234
-
235
- found_plugin_type = plugin_type[1] if pluginname == configuration[:target]
236
- end
237
- end
238
-
239
- abort "Could not find a plugin named '%s' in any supported plugin type" % configuration[:target] unless found_plugin_type
240
- ddl = load_plugin_ddl(configuration[:target], found_plugin_type)
241
- end
242
-
243
- if ddl
244
- puts ddl.help(configuration[:rpctemplate])
245
- else
246
- abort "Could not find a '%s' plugin named '%s'" % configuration[:target].split("/")
247
- end
248
-
249
- else
250
- puts "Please specify a plugin. Available plugins are:"
251
- puts
252
-
253
- load_errors = []
254
-
255
- known_plugin_types.each do |plugin_type|
256
- puts "%s:" % plugin_type[0]
257
-
258
- PluginManager.find(plugin_type[1], "ddl").each do |ddlf|
259
- begin
260
- help = DDL.new(ddlf, plugin_type[1], false)
139
+ def doc_command
140
+ puts "WARNING: mco plugin doc is deprecated, please use choria plugin doc"
261
141
 
262
- next unless help.client_activated?
263
-
264
- help.loadddlfile
265
- pluginname = ddlf.gsub(/_#{plugin_type[1]}$/, "")
266
- puts " %-25s %s" % [pluginname, help.meta[:description]]
267
- rescue => e
268
- load_errors << [plugin_type[1], ddlf, e]
269
- end
270
- end
271
-
272
- puts
273
- end
274
-
275
- unless load_errors.empty?
276
- puts "Plugin Load Errors:"
277
-
278
- load_errors.each do |e|
279
- puts " %-25s %s" % ["#{e[0]}/#{e[1]}", Util.colorize(:yellow, e[2])]
280
- end
281
- end
282
- end
142
+ exec("choria plugin doc %s" % [configuration[:target]])
283
143
  end
284
144
 
285
145
  # Creates the correct package plugin object.
@@ -341,18 +201,6 @@ mco plugin package [options] <directory>
341
201
  File.basename(plugintype[0])
342
202
  end
343
203
 
344
- # Load preset metadata values from config if they are present
345
- # This makes it possible to override metadata values in a local
346
- # client config file.
347
- #
348
- # Example : plugin.metadata.license = Apache 2
349
- def load_plugin_config_values
350
- config = Config.instance
351
- [:pluginname, :description, :author, :license, :version, :url, :timeout].each do |confoption|
352
- configuration[confoption] = config.pluginconf["metadata.#{confoption}"] unless configuration[confoption]
353
- end
354
- end
355
-
356
204
  def main
357
205
  abort "No action specified, please run 'mco help plugin' for help" unless configuration.include?(:action)
358
206
 
@@ -137,6 +137,8 @@ module MCollective
137
137
 
138
138
  raise('Identities can only match /\w\.\-/') unless @identity =~ /^[\w.\-]+$/
139
139
 
140
+ check_deprecations
141
+
140
142
  @configured = true
141
143
 
142
144
  libdirs.each do |dir|
@@ -254,5 +256,13 @@ module MCollective
254
256
  end
255
257
  end
256
258
  end
259
+
260
+ def check_deprecations
261
+ if @pluginconf["choria.use_srv_records"]
262
+ Log.warn("Configuration set 'choria.use_srv_records' which is deprecated in favor of 'choria.use_srv'.")
263
+ @pluginconf["choria.use_srv"] = @pluginconf["choria.use_srv_records"]
264
+ @pluginconf.delete("choria.use_srv_records")
265
+ end
266
+ end
257
267
  end
258
268
  end
@@ -96,9 +96,8 @@ module MCollective
96
96
  end
97
97
 
98
98
  @logger.start
99
- rescue Exception => e # rubocop:disable Lint/RescueException
99
+ rescue Exception # rubocop:disable Lint/RescueException
100
100
  @configured = false
101
- warn "Could not start logger: #{e.class} #{e}"
102
101
  end
103
102
 
104
103
  # figures out the filename that called us
@@ -157,19 +157,19 @@ module MCollective
157
157
 
158
158
  # Determines if SRV records should be used
159
159
  #
160
- # Setting choria.use_srv_records to anything other than t, true, yes or 1 will disable
160
+ # Setting choria.use_srv to anything other than t, true, yes or 1 will disable
161
161
  # SRV records
162
162
  #
163
163
  # @return [Boolean]
164
164
  def should_use_srv?
165
- ["t", "true", "yes", "1"].include?(get_option("choria.use_srv_records", "1").downcase)
165
+ ["t", "true", "yes", "1"].include?(get_option("choria.use_srv", "1").downcase)
166
166
  end
167
167
 
168
168
  # Query DNS for a series of records
169
169
  #
170
170
  # The given records will be passed through {#srv_records} to figure out the domain to query in.
171
171
  #
172
- # Querying of records can be bypassed by setting choria.use_srv_records to false
172
+ # Querying of records can be bypassed by setting choria.use_srv to false
173
173
  #
174
174
  # @yield [Hash] each record for modification by the caller
175
175
  # @param records [Array<String>] the records to query without their domain parts
@@ -634,21 +634,27 @@ module MCollective
634
634
 
635
635
  # The PuppetDB server to connect to
636
636
  #
637
- # Will consult _x-puppet-db._tcp.example.net then _x-puppet._tcp.example.net
638
- # then configurable using choria.puppetdb_host and choria.puppetdb_port, defaults
639
- # to puppet:8081
637
+ # Use choria.puppetdb_host if set, otherwise query
638
+ # _x-puppet-db._tcp.example.net then _x-puppet._tcp.example.net if SRV
639
+ # lookup is enabled, and fallback to puppet:8081 if nothing else worked.
640
640
  #
641
641
  # @return [Hash] with :target and :port
642
642
  def puppetdb_server
643
- d_host = get_option("choria.puppetdb_host", "puppet")
644
643
  d_port = get_option("choria.puppetdb_port", "8081")
645
644
 
645
+ answer = {
646
+ :target => get_option("choria.puppetdb_host", nil),
647
+ :port => d_port
648
+ }
649
+
650
+ return answer if answer[:target]
651
+
646
652
  answer = try_srv(["_x-puppet-db._tcp"], nil, nil)
647
653
  return answer if answer[:target]
648
654
 
649
655
  # In the case where we take _x-puppet._tcp SRV records we unfortunately have
650
656
  # to force the port else it uses the one from Puppet which will 404
651
- answer = try_srv(["_x-puppet._tcp"], d_host, d_port)
657
+ answer = try_srv(["_x-puppet._tcp"], "puppet", d_port)
652
658
  answer[:port] = d_port
653
659
 
654
660
  answer
@@ -186,6 +186,7 @@ module MCollective
186
186
  environment["PT_%s" % k] = v.to_s
187
187
  end
188
188
 
189
+ environment["PT__task"] = task["task"]
189
190
  environment["PT__installdir"] = File.join(request_spooldir(task_id), "files")
190
191
 
191
192
  environment
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: choria-mcorpc-support
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.24.2
4
+ version: 2.24.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - R.I.Pienaar
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-29 00:00:00.000000000 Z
11
+ date: 2021-04-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: systemu
@@ -118,12 +118,6 @@ files:
118
118
  - lib/mcollective/facts.rb
119
119
  - lib/mcollective/facts/base.rb
120
120
  - lib/mcollective/facts/yaml_facts.rb
121
- - lib/mcollective/generators.rb
122
- - lib/mcollective/generators/agent_generator.rb
123
- - lib/mcollective/generators/base.rb
124
- - lib/mcollective/generators/templates/action_snippet.erb
125
- - lib/mcollective/generators/templates/ddl.erb
126
- - lib/mcollective/generators/templates/plugin.erb
127
121
  - lib/mcollective/log.rb
128
122
  - lib/mcollective/logger.rb
129
123
  - lib/mcollective/logger/base.rb
@@ -1,6 +0,0 @@
1
- module MCollective
2
- module Generators
3
- require "mcollective/generators/base"
4
- require "mcollective/generators/agent_generator"
5
- end
6
- end
@@ -1,50 +0,0 @@
1
- module MCollective
2
- module Generators
3
- class AgentGenerator < Base
4
- attr_accessor :ddl, :content
5
-
6
- def initialize(plugin_name, actions=[], name=nil, description=nil, author=nil,
7
- license=nil, version=nil, url=nil, timeout=nil)
8
-
9
- super(name, description, author, license, version, url, timeout)
10
- @plugin_name = plugin_name
11
- @actions = actions || []
12
- @ddl = create_ddl
13
- @mod_name = "Agent"
14
- @pclass = "RPC::Agent"
15
- @content = create_plugin_content
16
- @plugin = create_plugin_string
17
- write_plugins
18
- end
19
-
20
- def create_ddl
21
- action_text = ""
22
- @actions.each_with_index do |action, i|
23
- action_text += "action \"#{action}\", :description => \"%ACTIONDESCRIPTION%\" do\n"
24
- action_text += action_help if i == 0
25
- action_text += "end\n"
26
- action_text += "\n" unless @actions.size == (i + 1)
27
- end
28
- # Use inherited method to create metadata part of the ddl
29
- create_metadata_string + action_text
30
- end
31
-
32
- def create_plugin_content
33
- content_text = ""
34
-
35
- # Add actions to agent file
36
- @actions.each_with_index do |action, i|
37
- content_text += "%6s%s" % [" ", "action \"#{action}\" do\n"]
38
- content_text += "%6s%s" % [" ", "end\n"]
39
- content_text += "\n" unless @actions.size == (i + 1)
40
- end
41
- content_text
42
- end
43
-
44
- def action_help
45
- action_snippet = File.read(File.join(File.dirname(__FILE__), "templates", "action_snippet.erb"))
46
- ERB.new(action_snippet).result
47
- end
48
- end
49
- end
50
- end
@@ -1,45 +0,0 @@
1
- module MCollective
2
- module Generators
3
- class Base
4
- attr_accessor :meta, :plugin_name, :mod_name
5
-
6
- def initialize(name, description, author, license, version, url, timeout)
7
- @meta = {:name => name,
8
- :description => description,
9
- :author => author,
10
- :license => license,
11
- :version => version,
12
- :url => url,
13
- :timeout => timeout}
14
- end
15
-
16
- def create_metadata_string
17
- ddl_template = File.read(File.join(File.dirname(__FILE__), "templates", "ddl.erb"))
18
- ERB.new(ddl_template, nil, "-").result(binding)
19
- end
20
-
21
- def create_plugin_string
22
- plugin_template = File.read(File.join(File.dirname(__FILE__), "templates", "plugin.erb"))
23
- ERB.new(plugin_template, nil, "-").result(binding)
24
- end
25
-
26
- def write_plugins
27
- Dir.mkdir @plugin_name
28
- dirname = File.join(@plugin_name, @mod_name.downcase)
29
- Dir.mkdir dirname
30
- puts "Created plugin directory : #{@plugin_name}"
31
-
32
- File.open(File.join(dirname, "#{@plugin_name}.ddl"), "w") {|f| f.puts @ddl}
33
- puts "Created DDL file : #{File.join(dirname, "#{@plugin_name}.ddl")}"
34
-
35
- File.open(File.join(dirname, "#{@plugin_name}.rb"), "w") {|f| f.puts @plugin}
36
- puts "Created #{@mod_name} file : #{File.join(dirname, "#{@plugin_name}.rb")}"
37
- rescue Errno::EEXIST
38
- raise "cannot generate '#{@plugin_name}' : plugin directory already exists."
39
- rescue Exception => e # rubocop:disable Lint/RescueException
40
- FileUtils.rm_rf(@plugin_name) if File.directory?(@plugin_name)
41
- raise "cannot generate plugin - #{e}"
42
- end
43
- end
44
- end
45
- end
@@ -1,13 +0,0 @@
1
- # Example Input
2
- input :name,
3
- :prompt => "%PROMPT%",
4
- :description => "%DESCRIPTION%",
5
- :type => %TYPE%,
6
- :validation => '%VALIDATION%',
7
- :optional => %OPTIONAL%,
8
- :maxlength => %MAXLENGTH%
9
-
10
- # Example output
11
- output :name,
12
- :description => "%DESCRIPTION%",
13
- :display_as => "%DISPLAYAS%"
@@ -1,8 +0,0 @@
1
- metadata :name => "<%= meta[:name] || "%FULLNANE%" -%>",
2
- :description => "<%= meta[:description] || "%DESCRIPTION%" -%>",
3
- :author => "<%= meta[:author] || "%AUTHOR%" -%>",
4
- :license => "<%= meta[:license] || "%LICENSE%" -%>",
5
- :version => "<%= meta[:version] || "%VERSION%" -%>",
6
- :url => "<%= meta[:url] || "%URL%" -%>",
7
- :timeout => <%= meta[:timeout] || "%TIMEOUT%" %>
8
-
@@ -1,7 +0,0 @@
1
- module MCollective
2
- module <%= @mod_name%>
3
- class <%= @plugin_name.capitalize -%><<%= @pclass%>
4
- <%= @content%>
5
- end
6
- end
7
- end