choria-mcorpc-support 2.23.3 → 2.24.0

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -1,68 +0,0 @@
1
- module MCollective
2
- module Data
3
- class Base
4
- attr_reader :name, :result, :ddl, :timeout
5
-
6
- # Register plugins that inherits base
7
- def self.inherited(klass)
8
- type = klass.to_s.split("::").last.downcase
9
-
10
- PluginManager << {:type => type, :class => klass.to_s, :single_instance => false}
11
- super
12
- end
13
-
14
- def initialize
15
- @name = self.class.to_s.split("::").last.downcase
16
- @ddl = DDL.new(@name, :data)
17
- @result = Result.new(@ddl.dataquery_interface[:output])
18
- @timeout = @ddl.meta[:timeout] || 1
19
-
20
- startup_hook
21
- end
22
-
23
- def lookup(what)
24
- ddl_validate(what)
25
-
26
- Log.debug("Doing data query %s for '%s'" % [@name, what])
27
-
28
- Timeout.timeout(@timeout) do
29
- query_data(what)
30
- end
31
-
32
- @result
33
- rescue Timeout::Error
34
- # Timeout::Error is a inherited from Interrupt which seems a really
35
- # strange choice, making it an equivelant of ^C and such. Catch it
36
- # and raise something less critical that will not the runner to just
37
- # give up the ghost
38
- msg = "Data plugin %s timed out on query '%s'" % [@name, what]
39
- Log.error(msg)
40
- raise MsgTTLExpired, msg
41
- end
42
-
43
- def self.query(&block)
44
- module_eval { define_method("query_data", &block) }
45
- end
46
-
47
- def ddl_validate(what)
48
- Data.ddl_validate(@ddl, what)
49
- end
50
-
51
- # activate_when do
52
- # file.exist?("/usr/bin/puppet")
53
- # end
54
- def self.activate_when(&block)
55
- (class << self; self; end).instance_eval do
56
- define_method("activate?", &block)
57
- end
58
- end
59
-
60
- # Always be active unless a specific block is given with activate_when
61
- def self.activate?
62
- true
63
- end
64
-
65
- def startup_hook; end
66
- end
67
- end
68
- end
@@ -1,90 +0,0 @@
1
- metadata :name => "bolt_task",
2
- :description => "Information about past Bolt Task",
3
- :author => "R.I.Pienaar <rip@devco.net>",
4
- :license => "Apache-2.0",
5
- :version => "0.19.0",
6
- :url => "https://choria.io",
7
- :timeout => 1
8
-
9
- usage <<-EOU
10
- This data plugin let you extract information about a previously
11
- run Bolt Task for use in discovery and elsewhere.
12
-
13
- To run a task on nodes where one previously failed:
14
-
15
- mco tasks run myapp::update -S "bolt_task('ae561842dc7d5a9dae94f766dfb3d4c8').exitcode > 0"
16
- EOU
17
-
18
- dataquery :description => "Puppet Bolt Task state" do
19
- input :query,
20
- :prompt => "Task ID",
21
- :description => "The Task ID to retrieve",
22
- :type => :string,
23
- :validation => '^[a-z,0-9]{32}$',
24
- :maxlength => 32
25
-
26
- output :known,
27
- :description => "If this is a known task on this node",
28
- :display_as => "Known Task",
29
- :default => false
30
-
31
- output :spool,
32
- :description => "Where on disk the task status is stored",
33
- :display_as => "Spool",
34
- :default => ""
35
-
36
- output :task,
37
- :description => "The name of the task that was run",
38
- :display_as => "Task",
39
- :default => ""
40
-
41
- output :caller,
42
- :description => "The user who invoked the task",
43
- :display_as => "Invoked by",
44
- :default => ""
45
-
46
- output :stdout,
47
- :description => "The STDOUT output from the task",
48
- :display_as => "STDOUT",
49
- :default => ""
50
-
51
- output :stderr,
52
- :description => "The STDERR output from the task",
53
- :display_as => "STDERR",
54
- :default => ""
55
-
56
- output :exitcode,
57
- :description => "The exitcode from the task",
58
- :display_as => "Exit Code",
59
- :default => 127
60
-
61
- output :runtime,
62
- :description => "How long the task took to run",
63
- :display_as => "Runtime",
64
- :default => 0.0
65
-
66
- output :start_time,
67
- :description => "When the task was started, seconds since 1970 in UTC time",
68
- :display_as => "Start Time",
69
- :default => 0
70
-
71
- output :wrapper_spawned,
72
- :description => "Did the wrapper start successfully",
73
- :display_as => "Wrapper Spawned",
74
- :default => false
75
-
76
- output :wrapper_error,
77
- :description => "Error output from the wrapper command",
78
- :display_as => "Wrapper Error",
79
- :default => ""
80
-
81
- output :wrapper_pid,
82
- :description => "The PID of the wrapper that runs the task",
83
- :display_as => "Wrapper PID",
84
- :default => -1
85
-
86
- output :completed,
87
- :description => "Did the task complete running",
88
- :display_as => "Completed",
89
- :default => false
90
- end
@@ -1,32 +0,0 @@
1
- module MCollective
2
- module Data
3
- class Bolt_task_data < Base
4
- activate_when do
5
- Util::Choria.new.tasks_support.tasks_compatible?
6
- end
7
-
8
- query do |taskid|
9
- tasks = Util::Choria.new.tasks_support
10
-
11
- begin
12
- status = tasks.task_status(taskid)
13
-
14
- result[:known] = true
15
-
16
- if status["task"]
17
- tasks.task_status(taskid).each do |item, value|
18
- value = value.utc.to_i if value.is_a?(Time)
19
- value = value.to_json if value.is_a?(Hash)
20
-
21
- result[item.intern] = value
22
- end
23
-
24
- result[:start_time] = result[:start_time].to_i
25
- end
26
- rescue
27
- Log.debug("Task %s was not found, returning default data. Error was: %s" % [taskid, $!.to_s])
28
- end
29
- end
30
- end
31
- end
32
- end
@@ -1,20 +0,0 @@
1
- metadata :name => "Collective",
2
- :description => "Collective membership",
3
- :author => "Puppet Labs",
4
- :license => "ASL 2.0",
5
- :version => "1.0",
6
- :url => "https://docs.puppetlabs.com/mcollective/",
7
- :timeout => 1
8
-
9
- dataquery :description => "Collective" do
10
- input :query,
11
- :prompt => 'Collective',
12
- :description => 'Collective name to ask about, eg mcollective',
13
- :type => :string,
14
- :validation => /./,
15
- :maxlength => 256
16
-
17
- output :member,
18
- :description => 'Node is a member of the named collective',
19
- :display_as => 'member'
20
- end
@@ -1,9 +0,0 @@
1
- module MCollective
2
- module Data
3
- class Collective_data < Base
4
- query do |collective|
5
- result[:member] = Config.instance.collectives.include?(collective)
6
- end
7
- end
8
- end
9
- end
@@ -1,28 +0,0 @@
1
- metadata :name => "Fact",
2
- :description => "Structured fact query",
3
- :author => "Puppet Labs",
4
- :license => "ASL 2.0",
5
- :version => "1.0",
6
- :url => "https://docs.puppetlabs.com/mcollective/",
7
- :timeout => 1
8
-
9
- dataquery :description => "Fact" do
10
- input :query,
11
- :prompt => 'Fact Path',
12
- :description => 'Path to a fact, eg network.eth0.address',
13
- :type => :string,
14
- :validation => /./,
15
- :maxlength => 256
16
-
17
- output :exists,
18
- :description => 'Fact is present',
19
- :display_as => 'exists'
20
-
21
- output :value,
22
- :description => 'Fact value',
23
- :display_as => 'value'
24
-
25
- output :value_encoding,
26
- :description => 'Encoding of the fact value (text/plain or application/json)',
27
- :display_as => 'value_encoding'
28
- end
@@ -1,55 +0,0 @@
1
- module MCollective
2
- module Data
3
- class Fact_data < Base
4
- query do |path|
5
- parts = path.split(/\./)
6
- walk_path(parts)
7
- end
8
-
9
- private
10
-
11
- def walk_path(path)
12
- # Set up results as though we didn't find the value
13
- result[:exists] = false
14
- result[:value] = false
15
- result[:value_encoding] = false
16
-
17
- facts = PluginManager["facts_plugin"].get_facts
18
-
19
- path.each do |level|
20
- case facts
21
- when Array
22
- level = Integer(level)
23
- if level >= facts.size
24
- # array index out would be out of bounds, so we don't have the value
25
- return
26
- end
27
- when Hash
28
- unless facts.include?(level)
29
- # we don't have the key for the next level, so give up
30
- return
31
- end
32
- else
33
- # this isn't a container data type, so we can't walk into it
34
- return
35
- end
36
-
37
- facts = facts[level]
38
- end
39
-
40
- result[:exists] = true
41
- case facts
42
- when Array, Hash
43
- # Currently data plugins cannot return structured data, so until
44
- # this is fixed flatten the data with json and flag that we have
45
- # munged the data
46
- result[:value] = facts.to_json
47
- result[:value_encoding] = "application/json"
48
- else
49
- result[:value] = facts
50
- result[:value_encoding] = "text/plain"
51
- end
52
- end
53
- end
54
- end
55
- end
@@ -1,89 +0,0 @@
1
- metadata :name => "File Stat",
2
- :description => "Retrieve file stat data for a given file",
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 => "File stat information" do
10
- input :query,
11
- :prompt => "File Name",
12
- :description => "Valid File Name",
13
- :type => :string,
14
- :validation => /.+/,
15
- :maxlength => 120
16
-
17
- output :name,
18
- :description => "File name",
19
- :display_as => "Name"
20
-
21
- output :output,
22
- :description => "Human readable information about the file",
23
- :display_as => "Status"
24
-
25
- output :present,
26
- :description => "Indicates if the file exist using 0 or 1",
27
- :display_as => "Present"
28
-
29
- output :size,
30
- :description => "File size",
31
- :display_as => "Size"
32
-
33
- output :mode,
34
- :description => "File mode",
35
- :display_as => "Mode"
36
-
37
- output :md5,
38
- :description => "File MD5 digest",
39
- :display_as => "MD5"
40
-
41
- output :mtime,
42
- :description => "File modification time",
43
- :display_as => "Modification time"
44
-
45
- output :ctime,
46
- :description => "File change time",
47
- :display_as => "Change time"
48
-
49
- output :atime,
50
- :description => "File access time",
51
- :display_as => "Access time"
52
-
53
- output :mtime_seconds,
54
- :description => "File modification time in seconds",
55
- :display_as => "Modification time"
56
-
57
- output :ctime_seconds,
58
- :description => "File change time in seconds",
59
- :display_as => "Change time"
60
-
61
- output :atime_seconds,
62
- :description => "File access time in seconds",
63
- :display_as => "Access time"
64
-
65
- output :mtime_age,
66
- :description => "File modification age in seconds",
67
- :display_as => "Modification age"
68
-
69
- output :ctime_age,
70
- :description => "File change age in seconds",
71
- :display_as => "Change age"
72
-
73
- output :atime_age,
74
- :description => "File access age in seconds",
75
- :display_as => "Access age"
76
-
77
- output :uid,
78
- :description => "File owner",
79
- :display_as => "Owner"
80
-
81
- output :gid,
82
- :description => "File group",
83
- :display_as => "Group"
84
-
85
- output :type,
86
- :description => "File type",
87
- :display_as => "Type"
88
- end
89
-
@@ -1,54 +0,0 @@
1
- module MCollective
2
- module Data
3
- class Fstat_data < Base
4
- query do |file|
5
- result[:name] = file
6
- result[:output] = "not present"
7
- result[:type] = "unknown"
8
- result[:mode] = "0000"
9
- result[:present] = 0
10
- result[:size] = 0
11
- result[:mtime] = 0
12
- result[:ctime] = 0
13
- result[:atime] = 0
14
- result[:mtime_seconds] = 0
15
- result[:ctime_seconds] = 0
16
- result[:atime_seconds] = 0
17
- result[:md5] = 0
18
- result[:uid] = 0
19
- result[:gid] = 0
20
-
21
- if File.exist?(file)
22
- result[:output] = "present"
23
- result[:present] = 1
24
-
25
- if File.symlink?(file)
26
- stat = File.lstat(file)
27
- else
28
- stat = File.stat(file)
29
- end
30
-
31
- [:size, :uid, :gid].each do |item|
32
- result[item] = stat.send(item)
33
- end
34
-
35
- [:mtime, :ctime, :atime].each do |item|
36
- result[item] = stat.send(item).strftime("%F %T")
37
- result["#{item}_seconds".to_sym] = stat.send(item).to_i
38
- result["#{item}_age".to_sym] = Time.now.to_i - stat.send(item).to_i
39
- end
40
-
41
- result[:mode] = "%o" % [stat.mode]
42
- result[:md5] = Digest::MD5.hexdigest(File.read(file)) if stat.file?
43
-
44
- result[:type] = "directory" if stat.directory?
45
- result[:type] = "file" if stat.file?
46
- result[:type] = "symlink" if stat.symlink?
47
- result[:type] = "socket" if stat.socket?
48
- result[:type] = "chardev" if stat.chardev?
49
- result[:type] = "blockdev" if stat.blockdev?
50
- end
51
- end
52
- end
53
- end
54
- end