choria-mcorpc-support 2.23.3 → 2.24.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. checksums.yaml +5 -5
  2. data/lib/mcollective.rb +3 -2
  3. data/lib/mcollective/application/find.rb +1 -1
  4. data/lib/mcollective/application/plugin.rb +2 -15
  5. data/lib/mcollective/client.rb +1 -1
  6. data/lib/mcollective/config.rb +135 -103
  7. data/lib/mcollective/discovery.rb +11 -63
  8. data/lib/mcollective/discovery/broadcast.ddl +11 -0
  9. data/lib/mcollective/discovery/choria.ddl +6 -4
  10. data/lib/mcollective/discovery/delegate.ddl +13 -0
  11. data/lib/mcollective/discovery/delegate.rb +73 -0
  12. data/lib/mcollective/discovery/external.ddl +13 -0
  13. data/lib/mcollective/discovery/file.ddl +13 -0
  14. data/lib/mcollective/discovery/flatfile.ddl +7 -5
  15. data/lib/mcollective/discovery/inventory.ddl +13 -0
  16. data/lib/mcollective/discovery/mc.ddl +3 -3
  17. data/lib/mcollective/optionparser.rb +1 -1
  18. data/lib/mcollective/pluginpackager/forge_packager.rb +1 -1
  19. data/lib/mcollective/rpc/client.rb +4 -2
  20. metadata +9 -23
  21. data/lib/mcollective/data.rb +0 -96
  22. data/lib/mcollective/data/agent_data.ddl +0 -22
  23. data/lib/mcollective/data/agent_data.rb +0 -17
  24. data/lib/mcollective/data/base.rb +0 -68
  25. data/lib/mcollective/data/bolt_task_data.ddl +0 -90
  26. data/lib/mcollective/data/bolt_task_data.rb +0 -32
  27. data/lib/mcollective/data/collective_data.ddl +0 -20
  28. data/lib/mcollective/data/collective_data.rb +0 -9
  29. data/lib/mcollective/data/fact_data.ddl +0 -28
  30. data/lib/mcollective/data/fact_data.rb +0 -55
  31. data/lib/mcollective/data/fstat_data.ddl +0 -89
  32. data/lib/mcollective/data/fstat_data.rb +0 -54
  33. data/lib/mcollective/data/result.rb +0 -50
  34. data/lib/mcollective/ddl/dataddl.rb +0 -56
  35. data/lib/mcollective/discovery/choria.rb +0 -223
  36. data/lib/mcollective/discovery/flatfile.rb +0 -47
  37. data/lib/mcollective/discovery/stdin.ddl +0 -11
  38. data/lib/mcollective/discovery/stdin.rb +0 -67
  39. data/lib/mcollective/generators/data_generator.rb +0 -50
  40. data/lib/mcollective/generators/templates/data_input_snippet.erb +0 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 73c63dbc1dacba7b90acdba3141cfedd3731da11
4
- data.tar.gz: 42cfc48d721f69b6ec805e71624a8b8cff0fc141
2
+ SHA256:
3
+ metadata.gz: d257a05d7cf82742e97521bbe9e40f7c20df649c9d65d6eda5ae2bf3993c8598
4
+ data.tar.gz: 2615868ac083003a9ca4f0eb6578f78e10cc5607686050940c6f68cf8da28a08
5
5
  SHA512:
6
- metadata.gz: 2f5370f390815f5881473b6c0e482db4f821f88ecb2616e33af9aa29a91e1561f1306b24945b1df2fe9d7ad05f8f770908298cb9279ae6dedb90658906654454
7
- data.tar.gz: 250ca8bb59baccda7324a4f21f7db4f938c6fc06cdfe968f46263e0fe11ba55214d237dda44a5db0243500007a8ffec856e336880334d5e0df3d2e53903499a9
6
+ metadata.gz: 159da1e1cd128e985466cc105dc1d261be41fa005fd7ef56475972a401cc0274f3ced19fe0c74a912c8d9324b0a41fc12e3e6edb4e251e0e7b76798d297a8c71
7
+ data.tar.gz: dff94f50b37d25b6f7fdbea30591f46a17e2a59186aa512422fe91bbef2350bd9be87d9fa7c5ed81ad6d22ada96f4ed5ff3e43173f05e4f1b80133f6aeaf2634
data/lib/mcollective.rb CHANGED
@@ -15,6 +15,7 @@ require "mcollective/monkey_patches"
15
15
  require "mcollective/cache"
16
16
  require "mcollective/exceptions"
17
17
  require "systemu"
18
+ require "open3"
18
19
 
19
20
  # == The Marionette Collective
20
21
  #
@@ -34,9 +35,9 @@ module MCollective
34
35
  require "mcollective/client"
35
36
  require "mcollective/config"
36
37
  require "mcollective/connector"
37
- require "mcollective/data"
38
38
  require "mcollective/ddl"
39
39
  require "mcollective/discovery"
40
+ require "mcollective/discovery/delegate"
40
41
  require "mcollective/facts"
41
42
  require "mcollective/logger"
42
43
  require "mcollective/log"
@@ -53,7 +54,7 @@ module MCollective
53
54
  require "mcollective/util"
54
55
  require "mcollective/validator"
55
56
 
56
- VERSION = "2.23.3".freeze
57
+ VERSION = "2.24.0".freeze
57
58
 
58
59
  def self.version
59
60
  VERSION
@@ -16,7 +16,7 @@ class MCollective::Application::Find < MCollective::Application # rubocop:disabl
16
16
 
17
17
  nodes.each {|c| puts c}
18
18
 
19
- warn "\nDiscovered %s nodes in %.2f seconds using the %s discovery plugin" % [nodes.size, discoverytime, mc.client.discoverer.discovery_method] if options[:verbose]
19
+ warn "\nDiscovered %s nodes in %.2f seconds using the %s discovery plugin" % [nodes.size, discoverytime, mc.client.options[:discovery_method]] if options[:verbose]
20
20
 
21
21
  !nodes.empty? ? exit(0) : exit(1)
22
22
  end
@@ -9,7 +9,6 @@ mco plugin package [options] <directory>
9
9
  mco plugin doc <plugin>
10
10
  mco plugin doc <type/plugin>
11
11
  mco plugin generate agent <pluginname> [actions=val,val]
12
- mco plugin generate data <pluginname> [outputs=val,val]
13
12
 
14
13
  info : Display plugin information including package details.
15
14
  package : Create all available plugin packages.
@@ -116,11 +115,6 @@ mco plugin package [options] <directory>
116
115
  :arguments => ["--actions [ACTIONS]"],
117
116
  :type => Array
118
117
 
119
- option :outputs,
120
- :description => "Outputs to be generated for an Data Plugin",
121
- :arguments => ["--outputs [OUTPUTS]"],
122
- :type => Array
123
-
124
118
  option :keep_artifacts,
125
119
  :description => "Don't remove artifacts after building packages",
126
120
  :arguments => ["--keep-artifacts"],
@@ -167,7 +161,7 @@ mco plugin package [options] <directory>
167
161
 
168
162
  # Generate a plugin skeleton
169
163
  def generate_command
170
- raise "undefined plugin type. cannot generate plugin. valid types are 'agent' and 'data'" if configuration["target"] == "."
164
+ raise "undefined plugin type. cannot generate plugin. valid types are 'agent'" if configuration["target"] == "."
171
165
 
172
166
  unless configuration[:pluginname]
173
167
  puts "No plugin name specified. Using 'new_plugin'"
@@ -181,12 +175,6 @@ mco plugin package [options] <directory>
181
175
  Generators::AgentGenerator.new(configuration[:pluginname], configuration[:actions], configuration[:pluginname],
182
176
  configuration[:description], configuration[:author], configuration[:license],
183
177
  configuration[:version], configuration[:url], configuration[:timeout])
184
- when "data"
185
- raise "data plugin must have at least one output" unless configuration[:outputs]
186
-
187
- Generators::DataGenerator.new(configuration[:pluginname], configuration[:outputs], configuration[:pluginname],
188
- configuration[:description], configuration[:author], configuration[:license],
189
- configuration[:version], configuration[:url], configuration[:timeout])
190
178
  else
191
179
  raise "invalid plugin type. cannot generate plugin '#{configuration[:target]}'"
192
180
  end
@@ -228,7 +216,6 @@ mco plugin package [options] <directory>
228
216
  ["Agents", :agent],
229
217
  ["Aggregate", :aggregate],
230
218
  ["Connectors", :connector],
231
- ["Data Queries", :data],
232
219
  ["Discovery Methods", :discovery],
233
220
  ["Validator Plugins", :validator]
234
221
  ]
@@ -345,7 +332,7 @@ mco plugin package [options] <directory>
345
332
  # Return the name of the type of plugin as a string
346
333
  def identify_plugin
347
334
  plugintype = Dir.glob(File.join(configuration[:target], "*")).select do |file|
348
- File.directory?(file) && file.match(/(connector|facts|registration|security|audit|pluginpackager|data|discovery|validator)/)
335
+ File.directory?(file) && file.match(/(connector|facts|registration|security|audit|pluginpackager|discovery|validator)/)
349
336
  end
350
337
 
351
338
  raise "more than one plugin type detected in directory" if plugintype.size > 1
@@ -150,7 +150,7 @@ module MCollective
150
150
  # of the discovery being cancelled soon as it reached the
151
151
  # requested limit of hosts
152
152
  def discover(filter, timeout, limit=0)
153
- @discoverer.discover(filter.merge("collective" => collective), timeout, limit)
153
+ @discoverer.discover(filter.merge("collective" => collective), timeout, limit, self)
154
154
  end
155
155
 
156
156
  # Send a request, performs the passed block for each response
@@ -17,123 +17,130 @@ module MCollective
17
17
  @configured = false
18
18
  end
19
19
 
20
- def loadconfig(configfile) # rubocop:disable Metrics/MethodLength
21
- set_config_defaults(configfile)
20
+ def parse_config_file(configfile, libdirs) # rubocop:disable Metrics/MethodLength
21
+ File.readlines(configfile).each do |line|
22
+ # strip blank spaces, tabs etc off the end of all lines
23
+ line.gsub!(/\s*$/, "")
22
24
 
23
- if File.exist?(configfile)
24
- libdirs = []
25
- File.readlines(configfile).each do |line|
26
- # strip blank spaces, tabs etc off the end of all lines
27
- line.gsub!(/\s*$/, "")
25
+ next if line =~ /^#|^$/
26
+ next unless line =~ /(.+?)\s*=\s*(.+)/
28
27
 
29
- next if line =~ /^#|^$/
30
- next unless line =~ /(.+?)\s*=\s*(.+)/
28
+ key = $1.strip
29
+ val = $2
31
30
 
32
- key = $1.strip
33
- val = $2
31
+ begin
32
+ case key
33
+ when "collectives"
34
+ @collectives = val.split(",").map(&:strip)
35
+ when "main_collective"
36
+ @main_collective = val
37
+ when "logfile"
38
+ @logfile = val
39
+ when "keeplogs"
40
+ @keeplogs = Integer(val)
41
+ when "max_log_size"
42
+ @max_log_size = Integer(val)
43
+ when "loglevel"
44
+ @loglevel = val
45
+ when "logfacility"
46
+ @logfacility = val
47
+ when "libdir"
48
+ paths = val.split(File::PATH_SEPARATOR)
49
+ paths.each do |path|
50
+ raise("libdir paths should be absolute paths but '%s' is relative" % path) unless Util.absolute_path?(path)
34
51
 
35
- begin
36
- case key
37
- when "collectives"
38
- @collectives = val.split(",").map(&:strip)
39
- when "main_collective"
40
- @main_collective = val
41
- when "logfile"
42
- @logfile = val
43
- when "keeplogs"
44
- @keeplogs = Integer(val)
45
- when "max_log_size"
46
- @max_log_size = Integer(val)
47
- when "loglevel"
48
- @loglevel = val
49
- when "logfacility"
50
- @logfacility = val
51
- when "libdir"
52
- paths = val.split(File::PATH_SEPARATOR)
53
- paths.each do |path|
54
- raise("libdir paths should be absolute paths but '%s' is relative" % path) unless Util.absolute_path?(path)
55
-
56
- libdirs << path
57
- end
58
- when "identity"
59
- @identity = val
60
- when "direct_addressing"
61
- @direct_addressing = Util.str_to_bool(val)
62
- when "direct_addressing_threshold"
63
- @direct_addressing_threshold = Integer(val)
64
- when "color"
65
- @color = Util.str_to_bool(val)
66
- when "daemonize"
67
- @daemonize = Util.str_to_bool(val)
68
- when "securityprovider"
69
- @securityprovider = val.capitalize
70
- when "factsource"
71
- @factsource = val.capitalize
72
- when "connector"
73
- @connector = val.capitalize
74
- when "classesfile"
75
- @classesfile = val
76
- when /^plugin.(.+)$/
77
- @pluginconf[$1] = val
78
- when "discovery_timeout"
79
- @discovery_timeout = Integer(val)
80
- when "publish_timeout"
81
- @publish_timeout = Integer(val)
82
- when "connection_timeout"
83
- @connection_timeout = Integer(val)
84
- when "rpcaudit"
85
- @rpcaudit = Util.str_to_bool(val)
86
- when "rpcauditprovider"
87
- @rpcauditprovider = val.capitalize
88
- when "rpcauthorization"
89
- @rpcauthorization = Util.str_to_bool(val)
90
- when "rpcauthprovider"
91
- @rpcauthprovider = val.capitalize
92
- when "rpclimitmethod"
93
- @rpclimitmethod = val.to_sym
94
- when "logger_type"
95
- @logger_type = val
96
- when "fact_cache_time"
97
- @fact_cache_time = Integer(val)
98
- when "ssl_cipher"
99
- @ssl_cipher = val
100
- when "threaded"
101
- @threaded = Util.str_to_bool(val)
102
- when "ttl"
103
- @ttl = Integer(val)
104
- when "default_discovery_options"
105
- @default_discovery_options << val
106
- when "default_discovery_method"
107
- @default_discovery_method = val
108
- when "soft_shutdown"
109
- @soft_shutdown = Util.str_to_bool(val)
110
- when "soft_shutdown_timeout"
111
- @soft_shutdown_timeout = Integer(val)
112
- when "activate_agents"
113
- @activate_agents = Util.str_to_bool(val)
114
- when "default_batch_size"
115
- @default_batch_size = Integer(val)
116
- when "default_batch_sleep_time"
117
- @default_batch_sleep_time = Float(val)
118
- else
119
- # server config might now be choria config which will divirge from mcollective
120
- # in time, so we only raise this error when it looks like we aren't loading
121
- # a server config else we try our best to load as much as we can
122
- raise("Unknown config parameter '#{key}'") unless configfile =~ /server/
52
+ libdirs << path
123
53
  end
124
- rescue ArgumentError
125
- raise("Could not parse value for configuration option '%s' with value '%s'" % [key, val])
54
+ when "identity"
55
+ @identity = val
56
+ when "direct_addressing"
57
+ @direct_addressing = Util.str_to_bool(val)
58
+ when "direct_addressing_threshold"
59
+ @direct_addressing_threshold = Integer(val)
60
+ when "color"
61
+ @color = Util.str_to_bool(val)
62
+ when "daemonize"
63
+ @daemonize = Util.str_to_bool(val)
64
+ when "securityprovider"
65
+ @securityprovider = val.capitalize
66
+ when "factsource"
67
+ @factsource = val.capitalize
68
+ when "connector"
69
+ @connector = val.capitalize
70
+ when "classesfile"
71
+ @classesfile = val
72
+ when /^plugin.(.+)$/
73
+ @pluginconf[$1] = val
74
+ when "discovery_timeout"
75
+ @discovery_timeout = Integer(val)
76
+ when "publish_timeout"
77
+ @publish_timeout = Integer(val)
78
+ when "connection_timeout"
79
+ @connection_timeout = Integer(val)
80
+ when "rpcaudit"
81
+ @rpcaudit = Util.str_to_bool(val)
82
+ when "rpcauditprovider"
83
+ @rpcauditprovider = val.capitalize
84
+ when "rpcauthorization"
85
+ @rpcauthorization = Util.str_to_bool(val)
86
+ when "rpcauthprovider"
87
+ @rpcauthprovider = val.capitalize
88
+ when "rpclimitmethod"
89
+ @rpclimitmethod = val.to_sym
90
+ when "logger_type"
91
+ @logger_type = val
92
+ when "fact_cache_time"
93
+ @fact_cache_time = Integer(val)
94
+ when "ssl_cipher"
95
+ @ssl_cipher = val
96
+ when "threaded"
97
+ @threaded = Util.str_to_bool(val)
98
+ when "ttl"
99
+ @ttl = Integer(val)
100
+ when "default_discovery_options"
101
+ @default_discovery_options << val
102
+ when "default_discovery_method"
103
+ @default_discovery_method = val
104
+ when "soft_shutdown"
105
+ @soft_shutdown = Util.str_to_bool(val)
106
+ when "soft_shutdown_timeout"
107
+ @soft_shutdown_timeout = Integer(val)
108
+ when "activate_agents"
109
+ @activate_agents = Util.str_to_bool(val)
110
+ when "default_batch_size"
111
+ @default_batch_size = Integer(val)
112
+ when "default_batch_sleep_time"
113
+ @default_batch_sleep_time = Float(val)
114
+ else
115
+ # server config might now be choria config which will divirge from mcollective
116
+ # in time, so we only raise this error when it looks like we aren't loading
117
+ # a server config else we try our best to load as much as we can
118
+ raise("Unknown config parameter '#{key}'") unless configfile =~ /server/
126
119
  end
120
+ rescue ArgumentError
121
+ raise("Could not parse value for configuration option '%s' with value '%s'" % [key, val])
127
122
  end
123
+ end
124
+ end
125
+
126
+ def loadconfig(configfile)
127
+ set_config_defaults(configfile)
128
+
129
+ if File.exist?(configfile)
130
+ libdirs = []
131
+
132
+ parse_config_file(configfile, libdirs)
128
133
 
129
134
  read_plugin_config_dir("#{@configdir}/plugin.d")
130
135
 
131
- raise 'Identities can only match /\w\.\-/' unless @identity =~ /^[\w.\-]+$/
136
+ parse_project_config(libdirs)
137
+
138
+ raise('Identities can only match /\w\.\-/') unless @identity =~ /^[\w.\-]+$/
132
139
 
133
140
  @configured = true
134
141
 
135
142
  libdirs.each do |dir|
136
- Log.debug("Cannot find libdir: #{dir}") unless File.directory?(dir)
143
+ Log.debug("Cannot find libdir: %s" % dir) unless File.directory?(dir)
137
144
 
138
145
  # remove the old one if it exists, we're moving it to the front
139
146
  $LOAD_PATH.reject! { |elem| elem == dir }
@@ -154,6 +161,31 @@ module MCollective
154
161
  end
155
162
  end
156
163
 
164
+ def project_root
165
+ Dir.pwd
166
+ end
167
+
168
+ def parse_project_config(libdirs)
169
+ project_config_files(project_root).each do |pfile|
170
+ parse_config_file(pfile, libdirs)
171
+ end
172
+ end
173
+
174
+ def project_config_files(path)
175
+ paths = []
176
+
177
+ path = File.expand_path(path)
178
+ parent = File.expand_path("..", path)
179
+
180
+ paths << project_config_files(parent) if parent != path
181
+
182
+ config = File.join(path, "choria.conf")
183
+
184
+ paths << config if File.exist?(config)
185
+
186
+ paths.flatten
187
+ end
188
+
157
189
  def set_config_defaults(configfile) # rubocop:disable Naming/AccessorMethodName
158
190
  @subscribe = []
159
191
  @pluginconf = {}
@@ -1,30 +1,26 @@
1
1
  module MCollective
2
2
  class Discovery
3
3
  def initialize(client)
4
- @known_methods = find_known_methods
5
- @default_method = Config.instance.default_discovery_method
6
4
  @client = client
7
5
  end
8
6
 
9
7
  def find_known_methods
10
- PluginManager.find("discovery")
8
+ ["broadcast", "mc", "inventory", "flatfile", "external", "choria", "file"]
11
9
  end
12
10
 
13
11
  def has_method?(method)
14
- @known_methods.include?(method)
12
+ find_known_methods.include?(method)
15
13
  end
16
14
 
17
15
  def force_direct_mode?
18
- discovery_method != "mc"
16
+ true
19
17
  end
20
18
 
21
19
  def discovery_method
22
- method = "mc"
23
-
24
20
  if @client.options[:discovery_method]
25
21
  method = @client.options[:discovery_method]
26
22
  else
27
- method = @default_method
23
+ method = Config.instance.default_discovery_method
28
24
  end
29
25
 
30
26
  raise "Unknown discovery method %s" % method unless has_method?(method)
@@ -35,11 +31,11 @@ module MCollective
35
31
  end
36
32
 
37
33
  def discovery_class
38
- method = discovery_method.capitalize
39
-
40
- PluginManager.loadclass("MCollective::Discovery::#{method}") unless self.class.const_defined?(method)
34
+ Delegate
35
+ end
41
36
 
42
- self.class.const_get(method)
37
+ def check_capabilities(filter)
38
+ true
43
39
  end
44
40
 
45
41
  def ddl
@@ -52,71 +48,23 @@ module MCollective
52
48
  @ddl
53
49
  end
54
50
 
55
- # Agent filters are always present no matter what, so we cant raise an error if the capabilities
56
- # suggest the discovery method cant do agents we just have to rely on the discovery plugin to not
57
- # do stupid things in the presense of a agent filter
58
- def check_capabilities(filter)
59
- capabilities = ddl.discovery_interface[:capabilities]
60
-
61
- raise "Cannot use class filters while using the '%s' discovery method" % discovery_method if !capabilities.include?(:classes) && !filter["cf_class"].empty?
62
-
63
- raise "Cannot use fact filters while using the '%s' discovery method" % discovery_method if !capabilities.include?(:facts) && !filter["fact"].empty?
64
-
65
- raise "Cannot use identity filters while using the '%s' discovery method" % discovery_method if !capabilities.include?(:identity) && !filter["identity"].empty?
66
-
67
- raise "Cannot use compound filters while using the '%s' discovery method" % discovery_method if !capabilities.include?(:compound) && !filter["compound"].empty?
68
- end
69
-
70
51
  # checks if compound filters are used and then forces the 'mc' discovery plugin
71
52
  def force_discovery_method_by_filter(filter)
72
- if discovery_method != "mc" && !filter["compound"].empty?
73
- Log.info "Switching to mc discovery method because compound filters are used"
74
- @client.options[:discovery_method] = "mc"
75
-
76
- return true
77
- end
78
-
79
53
  false
80
54
  end
81
55
 
82
- # if a compound filter is specified and it has any function
83
- # then we read the DDL for each of those plugins and sum up
84
- # the timeout declared in the DDL
85
56
  def timeout_for_compound_filter(compound_filter)
86
- return 0 if compound_filter.nil? || compound_filter.empty?
87
-
88
- # disabled while bringing in new compound filters
89
- # compound_filter.each do |filter|
90
- # filter.each do |statement|
91
- # next unless statement["fstatement"]
92
- #
93
- # pluginname = Data.pluginname(statement["fstatement"]["name"])
94
- # ddl = DDL.new(pluginname, :data)
95
- # timeout += ddl.meta[:timeout]
96
- # end
97
- # end
98
-
99
57
  0
100
58
  end
101
59
 
102
60
  def discovery_timeout(timeout, filter)
103
- timeout ||= ddl.meta[:timeout]
104
-
105
- if filter["compound"] && filter["compound"].empty?
106
- timeout
107
- else
108
- timeout + timeout_for_compound_filter(filter["compound"])
109
- end
61
+ timeout || ddl.meta[:timeout]
110
62
  end
111
63
 
112
- def discover(filter, timeout, limit)
64
+ def discover(filter, timeout, limit, client)
113
65
  raise "Limit has to be an integer" unless limit.is_a?(Integer)
114
66
 
115
- force_discovery_method_by_filter(filter)
116
-
117
- check_capabilities(filter)
118
-
119
- discovered = discovery_class.discover(filter, discovery_timeout(timeout, filter), limit, @client)
67
+ discovered = discovery_class.discover(filter, discovery_timeout(timeout, filter), limit, client)
120
68
 
121
69
  if limit > 0
122
70
  discovered[0, limit]