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
@@ -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
+
@@ -0,0 +1,13 @@
1
+ metadata :name => "delegate",
2
+ :description => "Choria CLI based delegated 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
12
+
13
+
@@ -0,0 +1,73 @@
1
+ module MCollective
2
+ class Discovery
3
+ class Delegate
4
+ def self.binary_name
5
+ "choria"
6
+ end
7
+
8
+ def self.discover(filter, timeout, limit, client)
9
+ raise("Cannot find the choria binary in your path") unless Util.command_in_path?("choria")
10
+
11
+ cmd = [binary_name, "discover", "-j", "--silent"]
12
+
13
+ cmd << "-T" << filter["collective"] if filter["collective"]
14
+
15
+ filter.fetch("identity", []).each do |i|
16
+ cmd << "-I" << i
17
+ end
18
+
19
+ filter.fetch("cf_class", []).each do |c|
20
+ cmd << "-C" << c
21
+ end
22
+
23
+ filter.fetch("fact", []).each do |f|
24
+ cmd << "-F" << "%s%s%s" % [f[:fact], f[:operator], f[:value]]
25
+ end
26
+
27
+ filter.fetch("agent", []).each do |a|
28
+ cmd << "-A" << a
29
+ end
30
+
31
+ filter.fetch("compound", []).each do |c|
32
+ next unless c.is_a?(Array)
33
+
34
+ cmd << "-S" << c.first["expr"]
35
+ end
36
+
37
+ client.options.fetch(:discovery_options, []).each do |opt|
38
+ cmd << "--do" << opt
39
+ end
40
+
41
+ cmd << "--dm" << (client.options.fetch(:discovery_method, "broadcast") rescue "broadcast")
42
+
43
+ run_discover(cmd, timeout)
44
+ end
45
+
46
+ def self.run_discover(cmd, timeout)
47
+ nodes = []
48
+
49
+ Log.debug("Executing choria for discovery using: %s" % cmd.join(" "))
50
+
51
+ Open3.popen3(ENV, *cmd) do |stdin, stdout, stderr, wait_thr|
52
+ stdin.close
53
+
54
+ begin
55
+ Timeout.timeout(timeout + 0.5) do
56
+ status = wait_thr.value
57
+
58
+ raise("Choria discovery failed: %s" % stderr.read) unless status.exitstatus == 0
59
+ end
60
+ rescue Timeout::Error
61
+ Log.warn("Timeout waiting for Choria to perform discovery")
62
+ Process.kill("KILL", wait_thr[:pid])
63
+ raise("Choria failed to complete discovery within %d timeout" % timeout)
64
+ end
65
+
66
+ nodes.concat(JSON.parse(stdout.read))
67
+ end
68
+
69
+ nodes
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,13 @@
1
+ metadata :name => "external",
2
+ :description => "External executable 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
12
+
13
+
@@ -0,0 +1,13 @@
1
+ metadata :name => "file",
2
+ :description => "Discovers from JSON, YAML and Text files",
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 [:identity]
11
+ end
12
+
13
+
@@ -1,11 +1,13 @@
1
1
  metadata :name => "flatfile",
2
- :description => "Flatfile based discovery for node identities",
2
+ :description => "Discovers from JSON, YAML and Text files",
3
3
  :author => "R.I.Pienaar <rip@devco.net>",
4
- :license => "ASL 2.0",
4
+ :license => "Apache-2.0",
5
5
  :version => "0.1",
6
- :url => "https://docs.puppetlabs.com/mcollective/",
7
- :timeout => 0
6
+ :url => "https://choria.io/",
7
+ :timeout => 2
8
8
 
9
9
  discovery do
10
- capabilities :identity
10
+ capabilities [:identity]
11
11
  end
12
+
13
+
@@ -0,0 +1,13 @@
1
+ metadata :name => "delegate",
2
+ :description => "Choria CLI based delegated 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
12
+
13
+
@@ -1,9 +1,9 @@
1
1
  metadata :name => "mc",
2
- :description => "MCollective Broadcast based discovery",
2
+ :description => "Choria Broadcast based discovery",
3
3
  :author => "R.I.Pienaar <rip@devco.net>",
4
- :license => "ASL 2.0",
4
+ :license => "Apache-2.0",
5
5
  :version => "0.1",
6
- :url => "https://docs.puppetlabs.com/mcollective/",
6
+ :url => "https://choria.io",
7
7
  :timeout => 2
8
8
 
9
9
  discovery do
@@ -168,7 +168,7 @@ module MCollective
168
168
  raise "Cannot read the discovery file #{v}" unless File.readable?(v)
169
169
 
170
170
  @options[:discovery_method] = "flatfile"
171
- @options[:discovery_options] << v
171
+ @options[:discovery_options] << "file=%s" % v
172
172
  end
173
173
 
174
174
  @parser.on("--publish_timeout TIMEOUT", Integer, "Timeout for publishing requests to remote agents.") do |pt|
@@ -191,7 +191,7 @@ module MCollective
191
191
  end
192
192
 
193
193
  def render_template(infile, outfile)
194
- erb = ERB.new(File.read(infile), 0, "%")
194
+ erb = ERB.new(File.read(infile), 0, "-")
195
195
  File.open(outfile, "w") do |f|
196
196
  f.puts erb.result(binding)
197
197
  end
@@ -533,6 +533,8 @@ module MCollective
533
533
 
534
534
  # All else fails we do it the hard way using a traditional broadcast
535
535
  unless @discovered_agents
536
+ raise("Invalid discovery method %s" % discovery_method) unless @client.discoverer.find_known_methods.include?(discovery_method)
537
+
536
538
  @stats.time_discovery :start
537
539
 
538
540
  @client.options = options
@@ -548,9 +550,9 @@ module MCollective
548
550
  actual_timeout = @client.discoverer.discovery_timeout(discovery_timeout, options[:filter])
549
551
 
550
552
  if actual_timeout > 0
551
- @stderr.print("Discovering hosts using the %s method for %d second(s) .... " % [@client.discoverer.discovery_method, actual_timeout])
553
+ @stderr.print("Discovering hosts using the %s method for %d second(s) .... " % [discovery_method, actual_timeout])
552
554
  else
553
- @stderr.print("Discovering hosts using the %s method .... " % [@client.discoverer.discovery_method])
555
+ @stderr.print("Discovering hosts using the %s method .... " % discovery_method)
554
556
  end
555
557
  end
556
558
 
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.23.3
4
+ version: 2.24.0
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-01-13 00:00:00.000000000 Z
11
+ date: 2021-02-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: systemu
@@ -98,34 +98,22 @@ files:
98
98
  - lib/mcollective/connector/base.rb
99
99
  - lib/mcollective/connector/nats.ddl
100
100
  - lib/mcollective/connector/nats.rb
101
- - lib/mcollective/data.rb
102
- - lib/mcollective/data/agent_data.ddl
103
- - lib/mcollective/data/agent_data.rb
104
- - lib/mcollective/data/base.rb
105
- - lib/mcollective/data/bolt_task_data.ddl
106
- - lib/mcollective/data/bolt_task_data.rb
107
- - lib/mcollective/data/collective_data.ddl
108
- - lib/mcollective/data/collective_data.rb
109
- - lib/mcollective/data/fact_data.ddl
110
- - lib/mcollective/data/fact_data.rb
111
- - lib/mcollective/data/fstat_data.ddl
112
- - lib/mcollective/data/fstat_data.rb
113
- - lib/mcollective/data/result.rb
114
101
  - lib/mcollective/ddl.rb
115
102
  - lib/mcollective/ddl/agentddl.rb
116
103
  - lib/mcollective/ddl/base.rb
117
- - lib/mcollective/ddl/dataddl.rb
118
104
  - lib/mcollective/ddl/discoveryddl.rb
119
105
  - lib/mcollective/ddl/validatorddl.rb
120
106
  - lib/mcollective/discovery.rb
107
+ - lib/mcollective/discovery/broadcast.ddl
121
108
  - lib/mcollective/discovery/choria.ddl
122
- - lib/mcollective/discovery/choria.rb
109
+ - lib/mcollective/discovery/delegate.ddl
110
+ - lib/mcollective/discovery/delegate.rb
111
+ - lib/mcollective/discovery/external.ddl
112
+ - lib/mcollective/discovery/file.ddl
123
113
  - lib/mcollective/discovery/flatfile.ddl
124
- - lib/mcollective/discovery/flatfile.rb
114
+ - lib/mcollective/discovery/inventory.ddl
125
115
  - lib/mcollective/discovery/mc.ddl
126
116
  - lib/mcollective/discovery/mc.rb
127
- - lib/mcollective/discovery/stdin.ddl
128
- - lib/mcollective/discovery/stdin.rb
129
117
  - lib/mcollective/exceptions.rb
130
118
  - lib/mcollective/facts.rb
131
119
  - lib/mcollective/facts/base.rb
@@ -133,9 +121,7 @@ files:
133
121
  - lib/mcollective/generators.rb
134
122
  - lib/mcollective/generators/agent_generator.rb
135
123
  - lib/mcollective/generators/base.rb
136
- - lib/mcollective/generators/data_generator.rb
137
124
  - lib/mcollective/generators/templates/action_snippet.erb
138
- - lib/mcollective/generators/templates/data_input_snippet.erb
139
125
  - lib/mcollective/generators/templates/ddl.erb
140
126
  - lib/mcollective/generators/templates/plugin.erb
141
127
  - lib/mcollective/log.rb
@@ -255,7 +241,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
255
241
  version: '0'
256
242
  requirements: []
257
243
  rubyforge_project:
258
- rubygems_version: 2.6.13
244
+ rubygems_version: 2.7.6.2
259
245
  signing_key:
260
246
  specification_version: 4
261
247
  summary: Support libraries the Choria Server
@@ -1,96 +0,0 @@
1
- module MCollective
2
- module Data
3
- require "mcollective/data/base"
4
- require "mcollective/data/result"
5
-
6
- def self.load_data_sources
7
- PluginManager.find_and_load("data")
8
-
9
- PluginManager.grep(/_data$/).each do |plugin|
10
- begin
11
- unless PluginManager[plugin].class.activate?
12
- Log.debug("Disabling data plugin %s due to plugin activation policy" % plugin)
13
- PluginManager.delete(plugin)
14
- end
15
- rescue Exception => e # rubocop:disable Lint/RescueException
16
- Log.debug("Disabling data plugin %s due to exception %s: %s" % [plugin, e.class, e])
17
- PluginManager.delete(plugin)
18
- end
19
- end
20
- end
21
-
22
- def self.pluginname(plugin)
23
- plugin.to_s =~ /_data$/i ? plugin.to_s.downcase : "%s_data" % plugin.to_s.downcase
24
- end
25
-
26
- def self.[](plugin)
27
- PluginManager[pluginname(plugin)]
28
- end
29
-
30
- # Data.package("httpd").architecture
31
- def self.method_missing(method, *args)
32
- super unless PluginManager.include?(pluginname(method))
33
-
34
- PluginManager[pluginname(method)].lookup(args.first)
35
- end
36
-
37
- def self.respond_to_missing?(method, *)
38
- PluginManager.include?(pluginname(method)) || super
39
- end
40
-
41
- def self.ddl(plugin)
42
- DDL.new(pluginname(plugin), :data)
43
- end
44
-
45
- def self.ddl_validate(ddl, argument)
46
- name = ddl.meta[:name]
47
- query = ddl.entities[:data]
48
-
49
- raise DDLValidationError, "No dataquery has been defined in the DDL for data plugin #{name}" unless query
50
-
51
- input = query.fetch(:input, {})
52
- output = query.fetch(:output, {})
53
-
54
- raise DDLValidationError, "No output has been defined in the DDL for data plugin #{name}" if output.keys.empty?
55
-
56
- if input[:query]
57
- return true if argument.nil? && input[:query][:optional]
58
-
59
- ddl.validate_input_argument(input, :query, argument)
60
- else
61
- raise("No data plugin argument was declared in the %s DDL but an input was supplied" % name) if argument
62
-
63
- true
64
- end
65
- end
66
-
67
- def self.ddl_has_output?(ddl, output)
68
- ddl.entities[:data][:output].include?(output.to_sym) rescue false
69
- end
70
-
71
- # For an input where the DDL requests a boolean or some number
72
- # this will convert the input to the right type where possible
73
- # else just returns the origin input unedited
74
- #
75
- # if anything here goes wrong just return the input value
76
- # this is not really the end of the world or anything since
77
- # all that will happen is that DDL validation will fail and
78
- # the user will get an error, no need to be too defensive here
79
- def self.ddl_transform_input(ddl, input)
80
- begin
81
- type = ddl.entities[:data][:input][:query][:type]
82
-
83
- case type
84
- when :boolean
85
- return DDL.string_to_boolean(input)
86
-
87
- when :number, :integer, :float
88
- return DDL.string_to_number(input)
89
- end
90
- rescue # rubocop:disable Lint/SuppressedException
91
- end
92
-
93
- input
94
- end
95
- end
96
- end
@@ -1,22 +0,0 @@
1
- metadata :name => "Agent",
2
- :description => "Meta data about installed MColletive Agents",
3
- :author => "R.I.Pienaar <rip@devco.net>",
4
- :license => "ASL 2.0",
5
- :version => "1.0",
6
- :url => "https://docs.puppetlabs.com/mcollective/",
7
- :timeout => 1
8
-
9
- dataquery :description => "Agent Meta Data" do
10
- input :query,
11
- :prompt => "Agent Name",
12
- :description => "Valid agent name",
13
- :type => :string,
14
- :validation => /^[\w\_]+$/,
15
- :maxlength => 20
16
-
17
- [:license, :timeout, :description, :url, :version, :author].each do |item|
18
- output item,
19
- :description => "Agent #{item}",
20
- :display_as => item.to_s.capitalize
21
- end
22
- end
@@ -1,17 +0,0 @@
1
- module MCollective
2
- module Data
3
- class Agent_data < Base
4
- query do |plugin|
5
- raise "No agent called #{plugin} found" unless PluginManager.include?("#{plugin}_agent")
6
-
7
- agent = PluginManager["#{plugin}_agent"]
8
-
9
- result[:agent] = plugin
10
-
11
- [:license, :timeout, :description, :url, :version, :author].each do |item|
12
- result[item] = agent.meta[item]
13
- end
14
- end
15
- end
16
- end
17
- end