choria-mcorpc-support 2.23.0.pre → 2.24.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +5 -5
  2. data/lib/mcollective.rb +3 -3
  3. data/lib/mcollective/agent/bolt_tasks.ddl +18 -0
  4. data/lib/mcollective/agent/bolt_tasks.json +18 -0
  5. data/lib/mcollective/agent/bolt_tasks.rb +4 -2
  6. data/lib/mcollective/agent/rpcutil.ddl +2 -2
  7. data/lib/mcollective/agent/rpcutil.json +2 -2
  8. data/lib/mcollective/application/choria.rb +3 -63
  9. data/lib/mcollective/application/facts.rb +2 -67
  10. data/lib/mcollective/application/federation.rb +1 -3
  11. data/lib/mcollective/application/find.rb +1 -1
  12. data/lib/mcollective/application/ping.rb +31 -3
  13. data/lib/mcollective/application/plugin.rb +2 -15
  14. data/lib/mcollective/application/tasks.rb +9 -0
  15. data/lib/mcollective/client.rb +1 -1
  16. data/lib/mcollective/config.rb +135 -103
  17. data/lib/mcollective/discovery.rb +12 -65
  18. data/lib/mcollective/discovery/broadcast.ddl +11 -0
  19. data/lib/mcollective/discovery/choria.ddl +6 -4
  20. data/lib/mcollective/discovery/delegate.ddl +13 -0
  21. data/lib/mcollective/discovery/delegate.rb +73 -0
  22. data/lib/mcollective/discovery/external.ddl +13 -0
  23. data/lib/mcollective/discovery/file.ddl +13 -0
  24. data/lib/mcollective/discovery/flatfile.ddl +7 -5
  25. data/lib/mcollective/discovery/inventory.ddl +13 -0
  26. data/lib/mcollective/discovery/mc.ddl +3 -3
  27. data/lib/mcollective/message.rb +0 -24
  28. data/lib/mcollective/optionparser.rb +2 -2
  29. data/lib/mcollective/pluginpackager/forge_packager.rb +1 -1
  30. data/lib/mcollective/rpc/client.rb +6 -4
  31. data/lib/mcollective/security/base.rb +1 -37
  32. data/lib/mcollective/util.rb +23 -31
  33. data/lib/mcollective/util/choria.rb +0 -157
  34. data/lib/mcollective/util/tasks_support.rb +22 -3
  35. metadata +11 -29
  36. data/lib/mcollective/application/describe_filter.rb +0 -87
  37. data/lib/mcollective/data.rb +0 -96
  38. data/lib/mcollective/data/agent_data.ddl +0 -22
  39. data/lib/mcollective/data/agent_data.rb +0 -17
  40. data/lib/mcollective/data/base.rb +0 -68
  41. data/lib/mcollective/data/bolt_task_data.ddl +0 -90
  42. data/lib/mcollective/data/bolt_task_data.rb +0 -32
  43. data/lib/mcollective/data/collective_data.ddl +0 -20
  44. data/lib/mcollective/data/collective_data.rb +0 -9
  45. data/lib/mcollective/data/fact_data.ddl +0 -28
  46. data/lib/mcollective/data/fact_data.rb +0 -55
  47. data/lib/mcollective/data/fstat_data.ddl +0 -89
  48. data/lib/mcollective/data/fstat_data.rb +0 -54
  49. data/lib/mcollective/data/result.rb +0 -50
  50. data/lib/mcollective/ddl/dataddl.rb +0 -56
  51. data/lib/mcollective/discovery/choria.rb +0 -223
  52. data/lib/mcollective/discovery/flatfile.rb +0 -47
  53. data/lib/mcollective/discovery/stdin.ddl +0 -11
  54. data/lib/mcollective/discovery/stdin.rb +0 -67
  55. data/lib/mcollective/generators/data_generator.rb +0 -50
  56. data/lib/mcollective/generators/templates/data_input_snippet.erb +0 -7
  57. data/lib/mcollective/matcher.rb +0 -220
  58. data/lib/mcollective/matcher/parser.rb +0 -118
  59. data/lib/mcollective/matcher/scanner.rb +0 -236
@@ -148,6 +148,13 @@ Examples:
148
148
  :required => false,
149
149
  :default => 1,
150
150
  :type => Integer
151
+
152
+ self.class.option :__run_as,
153
+ :arguments => ["--run-as USERNAME"],
154
+ :description => "Run task as user USERNAME",
155
+ :required => false,
156
+ :default => nil,
157
+ :type => String
151
158
  end
152
159
 
153
160
  def say(msg="")
@@ -180,6 +187,8 @@ Examples:
180
187
  :files => meta["files"].to_json
181
188
  }
182
189
 
190
+ request[:run_as] = configuration[:__run_as] if configuration[:__run_as]
191
+
183
192
  request[:input] = input.to_json if input
184
193
 
185
194
  if configuration[:__background]
@@ -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,72 +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
- timeout = 0
89
-
90
- compound_filter.each do |filter|
91
- filter.each do |statement|
92
- next unless statement["fstatement"]
93
-
94
- pluginname = Data.pluginname(statement["fstatement"]["name"])
95
- ddl = DDL.new(pluginname, :data)
96
- timeout += ddl.meta[:timeout]
97
- end
98
- end
99
-
100
- timeout
57
+ 0
101
58
  end
102
59
 
103
60
  def discovery_timeout(timeout, filter)
104
- timeout ||= ddl.meta[:timeout]
105
-
106
- if filter["compound"] && filter["compound"].empty?
107
- timeout
108
- else
109
- timeout + timeout_for_compound_filter(filter["compound"])
110
- end
61
+ timeout || ddl.meta[:timeout]
111
62
  end
112
63
 
113
- def discover(filter, timeout, limit)
64
+ def discover(filter, timeout, limit, client)
114
65
  raise "Limit has to be an integer" unless limit.is_a?(Integer)
115
66
 
116
- force_discovery_method_by_filter(filter)
117
-
118
- check_capabilities(filter)
119
-
120
- discovered = discovery_class.discover(filter, discovery_timeout(timeout, filter), limit, @client)
67
+ discovered = discovery_class.discover(filter, discovery_timeout(timeout, filter), limit, client)
121
68
 
122
69
  if limit > 0
123
70
  discovered[0, limit]
@@ -0,0 +1,11 @@
1
+ metadata :name => "broadcast",
2
+ :description => "Choria Broadcast based discovery",
3
+ :author => "R.I.Pienaar <rip@devco.net>",
4
+ :license => "Apache-2.0",
5
+ :version => "0.1",
6
+ :url => "https://choria.io",
7
+ :timeout => 2
8
+
9
+ discovery do
10
+ capabilities [:classes, :facts, :identity, :agents, :compound]
11
+ end
@@ -1,11 +1,13 @@
1
1
  metadata :name => "choria",
2
- :description => "PuppetDB based discovery for the Choria plugin suite",
2
+ :description => "PuppetDB based discovery method",
3
3
  :author => "R.I.Pienaar <rip@devco.net>",
4
4
  :license => "Apache-2.0",
5
- :version => "0.19.0",
6
- :url => "https://github.com/choria-io",
7
- :timeout => 0
5
+ :version => "0.1",
6
+ :url => "https://choria.io/",
7
+ :timeout => 2
8
8
 
9
9
  discovery do
10
10
  capabilities [:classes, :facts, :identity, :agents]
11
11
  end
12
+
13
+