choria-mcorpc-support 2.22.1 → 2.23.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (145) hide show
  1. checksums.yaml +4 -4
  2. data/lib/mcollective.rb +1 -1
  3. data/lib/mcollective/agent/bolt_tasks.ddl +235 -0
  4. data/lib/mcollective/agent/bolt_tasks.json +347 -0
  5. data/lib/mcollective/agent/bolt_tasks.rb +176 -0
  6. data/lib/mcollective/agent/choria_util.ddl +152 -0
  7. data/lib/mcollective/agent/choria_util.json +244 -0
  8. data/lib/mcollective/agent/rpcutil.ddl +7 -3
  9. data/lib/mcollective/agent/rpcutil.json +333 -0
  10. data/lib/mcollective/agent/scout.ddl +169 -0
  11. data/lib/mcollective/agent/scout.json +224 -0
  12. data/lib/mcollective/agents.rb +7 -6
  13. data/lib/mcollective/aggregate.rb +4 -4
  14. data/lib/mcollective/aggregate/average.rb +2 -2
  15. data/lib/mcollective/aggregate/base.rb +2 -2
  16. data/lib/mcollective/aggregate/result.rb +3 -3
  17. data/lib/mcollective/aggregate/result/collection_result.rb +2 -2
  18. data/lib/mcollective/aggregate/result/numeric_result.rb +2 -2
  19. data/lib/mcollective/aggregate/sum.rb +2 -2
  20. data/lib/mcollective/aggregate/summary.rb +3 -4
  21. data/lib/mcollective/application.rb +57 -21
  22. data/lib/mcollective/application/choria.rb +249 -0
  23. data/lib/mcollective/application/completion.rb +6 -6
  24. data/lib/mcollective/application/describe_filter.rb +20 -20
  25. data/lib/mcollective/application/facts.rb +11 -11
  26. data/lib/mcollective/application/federation.rb +239 -0
  27. data/lib/mcollective/application/find.rb +4 -4
  28. data/lib/mcollective/application/help.rb +3 -3
  29. data/lib/mcollective/application/inventory.rb +3 -341
  30. data/lib/mcollective/application/ping.rb +3 -77
  31. data/lib/mcollective/application/playbook.rb +207 -0
  32. data/lib/mcollective/application/plugin.rb +106 -106
  33. data/lib/mcollective/application/rpc.rb +3 -108
  34. data/lib/mcollective/application/tasks.rb +416 -0
  35. data/lib/mcollective/applications.rb +11 -10
  36. data/lib/mcollective/audit/choria.rb +33 -0
  37. data/lib/mcollective/cache.rb +2 -4
  38. data/lib/mcollective/client.rb +11 -10
  39. data/lib/mcollective/config.rb +21 -26
  40. data/lib/mcollective/connector/base.rb +2 -1
  41. data/lib/mcollective/connector/nats.ddl +9 -0
  42. data/lib/mcollective/connector/nats.rb +450 -0
  43. data/lib/mcollective/data.rb +8 -3
  44. data/lib/mcollective/data/agent_data.rb +1 -1
  45. data/lib/mcollective/data/base.rb +6 -5
  46. data/lib/mcollective/data/bolt_task_data.ddl +90 -0
  47. data/lib/mcollective/data/bolt_task_data.rb +32 -0
  48. data/lib/mcollective/data/collective_data.rb +1 -1
  49. data/lib/mcollective/data/fact_data.rb +6 -6
  50. data/lib/mcollective/data/fstat_data.rb +2 -4
  51. data/lib/mcollective/data/result.rb +7 -2
  52. data/lib/mcollective/ddl/agentddl.rb +5 -17
  53. data/lib/mcollective/ddl/base.rb +10 -13
  54. data/lib/mcollective/discovery.rb +12 -26
  55. data/lib/mcollective/discovery/choria.ddl +11 -0
  56. data/lib/mcollective/discovery/choria.rb +223 -0
  57. data/lib/mcollective/discovery/flatfile.rb +7 -8
  58. data/lib/mcollective/discovery/mc.rb +2 -2
  59. data/lib/mcollective/discovery/stdin.rb +17 -18
  60. data/lib/mcollective/exceptions.rb +13 -0
  61. data/lib/mcollective/facts/base.rb +9 -9
  62. data/lib/mcollective/facts/yaml_facts.rb +12 -12
  63. data/lib/mcollective/generators.rb +3 -3
  64. data/lib/mcollective/generators/agent_generator.rb +3 -4
  65. data/lib/mcollective/generators/base.rb +14 -15
  66. data/lib/mcollective/generators/data_generator.rb +5 -6
  67. data/lib/mcollective/log.rb +2 -2
  68. data/lib/mcollective/logger/base.rb +3 -2
  69. data/lib/mcollective/logger/console_logger.rb +10 -10
  70. data/lib/mcollective/logger/file_logger.rb +7 -7
  71. data/lib/mcollective/logger/syslog_logger.rb +11 -15
  72. data/lib/mcollective/matcher.rb +14 -14
  73. data/lib/mcollective/matcher/parser.rb +31 -41
  74. data/lib/mcollective/matcher/scanner.rb +69 -74
  75. data/lib/mcollective/message.rb +10 -17
  76. data/lib/mcollective/monkey_patches.rb +2 -4
  77. data/lib/mcollective/optionparser.rb +1 -0
  78. data/lib/mcollective/pluginmanager.rb +3 -5
  79. data/lib/mcollective/pluginpackager.rb +1 -3
  80. data/lib/mcollective/pluginpackager/agent_definition.rb +3 -8
  81. data/lib/mcollective/pluginpackager/forge_packager.rb +7 -9
  82. data/lib/mcollective/pluginpackager/standard_definition.rb +1 -2
  83. data/lib/mcollective/registration/base.rb +18 -16
  84. data/lib/mcollective/rpc.rb +2 -4
  85. data/lib/mcollective/rpc/actionrunner.rb +16 -18
  86. data/lib/mcollective/rpc/agent.rb +26 -43
  87. data/lib/mcollective/rpc/audit.rb +1 -0
  88. data/lib/mcollective/rpc/client.rb +67 -85
  89. data/lib/mcollective/rpc/helpers.rb +55 -62
  90. data/lib/mcollective/rpc/progress.rb +2 -2
  91. data/lib/mcollective/rpc/reply.rb +17 -19
  92. data/lib/mcollective/rpc/request.rb +7 -5
  93. data/lib/mcollective/rpc/result.rb +6 -8
  94. data/lib/mcollective/rpc/stats.rb +49 -58
  95. data/lib/mcollective/security/base.rb +29 -36
  96. data/lib/mcollective/security/choria.rb +765 -0
  97. data/lib/mcollective/shell.rb +9 -4
  98. data/lib/mcollective/signer/base.rb +28 -0
  99. data/lib/mcollective/signer/choria.rb +185 -0
  100. data/lib/mcollective/ssl.rb +8 -6
  101. data/lib/mcollective/util.rb +52 -53
  102. data/lib/mcollective/util/bolt_support.rb +176 -0
  103. data/lib/mcollective/util/bolt_support/plan_runner.rb +167 -0
  104. data/lib/mcollective/util/bolt_support/task_result.rb +94 -0
  105. data/lib/mcollective/util/bolt_support/task_results.rb +128 -0
  106. data/lib/mcollective/util/choria.rb +1103 -0
  107. data/lib/mcollective/util/indifferent_hash.rb +12 -0
  108. data/lib/mcollective/util/natswrapper.rb +242 -0
  109. data/lib/mcollective/util/playbook.rb +435 -0
  110. data/lib/mcollective/util/playbook/data_stores.rb +201 -0
  111. data/lib/mcollective/util/playbook/data_stores/base.rb +99 -0
  112. data/lib/mcollective/util/playbook/data_stores/consul_data_store.rb +88 -0
  113. data/lib/mcollective/util/playbook/data_stores/environment_data_store.rb +33 -0
  114. data/lib/mcollective/util/playbook/data_stores/etcd_data_store.rb +42 -0
  115. data/lib/mcollective/util/playbook/data_stores/file_data_store.rb +106 -0
  116. data/lib/mcollective/util/playbook/data_stores/shell_data_store.rb +103 -0
  117. data/lib/mcollective/util/playbook/inputs.rb +265 -0
  118. data/lib/mcollective/util/playbook/nodes.rb +207 -0
  119. data/lib/mcollective/util/playbook/nodes/mcollective_nodes.rb +86 -0
  120. data/lib/mcollective/util/playbook/nodes/pql_nodes.rb +40 -0
  121. data/lib/mcollective/util/playbook/nodes/shell_nodes.rb +55 -0
  122. data/lib/mcollective/util/playbook/nodes/terraform_nodes.rb +65 -0
  123. data/lib/mcollective/util/playbook/nodes/yaml_nodes.rb +47 -0
  124. data/lib/mcollective/util/playbook/playbook_logger.rb +47 -0
  125. data/lib/mcollective/util/playbook/puppet_logger.rb +51 -0
  126. data/lib/mcollective/util/playbook/report.rb +152 -0
  127. data/lib/mcollective/util/playbook/task_result.rb +55 -0
  128. data/lib/mcollective/util/playbook/tasks.rb +196 -0
  129. data/lib/mcollective/util/playbook/tasks/base.rb +45 -0
  130. data/lib/mcollective/util/playbook/tasks/graphite_event_task.rb +64 -0
  131. data/lib/mcollective/util/playbook/tasks/mcollective_task.rb +356 -0
  132. data/lib/mcollective/util/playbook/tasks/shell_task.rb +93 -0
  133. data/lib/mcollective/util/playbook/tasks/slack_task.rb +105 -0
  134. data/lib/mcollective/util/playbook/tasks/webhook_task.rb +136 -0
  135. data/lib/mcollective/util/playbook/template_util.rb +98 -0
  136. data/lib/mcollective/util/playbook/uses.rb +169 -0
  137. data/lib/mcollective/util/tasks_support.rb +733 -0
  138. data/lib/mcollective/util/tasks_support/cli.rb +260 -0
  139. data/lib/mcollective/util/tasks_support/default_formatter.rb +138 -0
  140. data/lib/mcollective/util/tasks_support/json_formatter.rb +108 -0
  141. data/lib/mcollective/validator.rb +6 -1
  142. data/lib/mcollective/validator/bolt_task_name_validator.ddl +7 -0
  143. data/lib/mcollective/validator/bolt_task_name_validator.rb +11 -0
  144. data/lib/mcollective/validator/length_validator.rb +1 -3
  145. metadata +67 -4
@@ -28,12 +28,16 @@ module MCollective
28
28
  end
29
29
 
30
30
  # Data.package("httpd").architecture
31
- def self.method_missing(method, *args) # rubocop:disable Style/MethodMissing:
31
+ def self.method_missing(method, *args)
32
32
  super unless PluginManager.include?(pluginname(method))
33
33
 
34
34
  PluginManager[pluginname(method)].lookup(args.first)
35
35
  end
36
36
 
37
+ def self.respond_to_missing?(method, *)
38
+ PluginManager.include?(pluginname(method)) || super
39
+ end
40
+
37
41
  def self.ddl(plugin)
38
42
  DDL.new(pluginname(plugin), :data)
39
43
  end
@@ -55,7 +59,8 @@ module MCollective
55
59
  ddl.validate_input_argument(input, :query, argument)
56
60
  else
57
61
  raise("No data plugin argument was declared in the %s DDL but an input was supplied" % name) if argument
58
- return true
62
+
63
+ true
59
64
  end
60
65
  end
61
66
 
@@ -82,7 +87,7 @@ module MCollective
82
87
  when :number, :integer, :float
83
88
  return DDL.string_to_number(input)
84
89
  end
85
- rescue # rubocop:disable Lint/HandleExceptions
90
+ rescue # rubocop:disable Lint/SuppressedException
86
91
  end
87
92
 
88
93
  input
@@ -1,6 +1,6 @@
1
1
  module MCollective
2
2
  module Data
3
- class Agent_data<Base
3
+ class Agent_data < Base
4
4
  query do |plugin|
5
5
  raise "No agent called #{plugin} found" unless PluginManager.include?("#{plugin}_agent")
6
6
 
@@ -8,6 +8,7 @@ module MCollective
8
8
  type = klass.to_s.split("::").last.downcase
9
9
 
10
10
  PluginManager << {:type => type, :class => klass.to_s, :single_instance => false}
11
+ super
11
12
  end
12
13
 
13
14
  def initialize
@@ -22,9 +23,9 @@ module MCollective
22
23
  def lookup(what)
23
24
  ddl_validate(what)
24
25
 
25
- Log.debug("Doing data query %s for '%s'" % [ @name, what ])
26
+ Log.debug("Doing data query %s for '%s'" % [@name, what])
26
27
 
27
- Timeout::timeout(@timeout) do
28
+ Timeout.timeout(@timeout) do
28
29
  query_data(what)
29
30
  end
30
31
 
@@ -40,7 +41,7 @@ module MCollective
40
41
  end
41
42
 
42
43
  def self.query(&block)
43
- self.module_eval { define_method("query_data", &block) }
44
+ module_eval { define_method("query_data", &block) }
44
45
  end
45
46
 
46
47
  def ddl_validate(what)
@@ -58,10 +59,10 @@ module MCollective
58
59
 
59
60
  # Always be active unless a specific block is given with activate_when
60
61
  def self.activate?
61
- return true
62
+ true
62
63
  end
63
64
 
64
- def startup_hook;end
65
+ def startup_hook; end
65
66
  end
66
67
  end
67
68
  end
@@ -0,0 +1,90 @@
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
@@ -0,0 +1,32 @@
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,6 +1,6 @@
1
1
  module MCollective
2
2
  module Data
3
- class Collective_data<Base
3
+ class Collective_data < Base
4
4
  query do |collective|
5
5
  result[:member] = Config.instance.collectives.include?(collective)
6
6
  end
@@ -1,8 +1,8 @@
1
1
  module MCollective
2
2
  module Data
3
- class Fact_data<Base
3
+ class Fact_data < Base
4
4
  query do |path|
5
- parts = path.split /\./
5
+ parts = path.split(/\./)
6
6
  walk_path(parts)
7
7
  end
8
8
 
@@ -14,7 +14,7 @@ module MCollective
14
14
  result[:value] = false
15
15
  result[:value_encoding] = false
16
16
 
17
- facts = PluginManager['facts_plugin'].get_facts
17
+ facts = PluginManager["facts_plugin"].get_facts
18
18
 
19
19
  path.each do |level|
20
20
  case facts
@@ -25,7 +25,7 @@ module MCollective
25
25
  return
26
26
  end
27
27
  when Hash
28
- if !facts.include?(level)
28
+ unless facts.include?(level)
29
29
  # we don't have the key for the next level, so give up
30
30
  return
31
31
  end
@@ -44,10 +44,10 @@ module MCollective
44
44
  # this is fixed flatten the data with json and flag that we have
45
45
  # munged the data
46
46
  result[:value] = facts.to_json
47
- result[:value_encoding] = 'application/json'
47
+ result[:value_encoding] = "application/json"
48
48
  else
49
49
  result[:value] = facts
50
- result[:value_encoding] = 'text/plain'
50
+ result[:value_encoding] = "text/plain"
51
51
  end
52
52
  end
53
53
  end
@@ -1,6 +1,6 @@
1
1
  module MCollective
2
2
  module Data
3
- class Fstat_data<Base
3
+ class Fstat_data < Base
4
4
  query do |file|
5
5
  result[:name] = file
6
6
  result[:output] = "not present"
@@ -18,8 +18,7 @@ module MCollective
18
18
  result[:uid] = 0
19
19
  result[:gid] = 0
20
20
 
21
-
22
- if File.exists?(file)
21
+ if File.exist?(file)
23
22
  result[:output] = "present"
24
23
  result[:present] = 1
25
24
 
@@ -53,4 +52,3 @@ module MCollective
53
52
  end
54
53
  end
55
54
  end
56
-
@@ -9,7 +9,7 @@ module MCollective
9
9
  def initialize(outputs)
10
10
  @data = {}
11
11
 
12
- outputs.keys.each do |output|
12
+ outputs.each_key do |output|
13
13
  @data[output] = Marshal.load(Marshal.dump(outputs[output].fetch(:default, nil)))
14
14
  end
15
15
  end
@@ -24,7 +24,8 @@ module MCollective
24
24
 
25
25
  def []=(key, val)
26
26
  # checks using the string representation of the class name to avoid deprecations on Bignum and Fixnum
27
- raise "Can only store String, Integer, Float or Boolean data but got #{val.class} for key #{key}" unless ["String", "Integer", "Bignum", "Fixnum", "Float", "TrueClass", "FalseClass"].include?(val.class.to_s)
27
+ raise "Can only store String, Integer, Float or Boolean data but got #{val.class} for key #{key}" unless ["String", "Integer", "Bignum", "Fixnum", "Float", "TrueClass",
28
+ "FalseClass"].include?(val.class.to_s)
28
29
 
29
30
  @data[key.to_sym] = val
30
31
  end
@@ -33,6 +34,10 @@ module MCollective
33
34
  @data.keys
34
35
  end
35
36
 
37
+ def respond_to_missing?(method, *)
38
+ include?(method)
39
+ end
40
+
36
41
  def method_missing(method, *args)
37
42
  key = method.to_sym
38
43
 
@@ -87,14 +87,10 @@ module MCollective
87
87
  # Sets the display preference to either :ok, :failed, :flatten or :always
88
88
  # operates on action level
89
89
  def display(pref)
90
- if pref == :flatten
91
- Log.warn("The display option :flatten is being deprecated and will be removed in the next minor release.")
92
- end
90
+ Log.warn("The display option :flatten is being deprecated and will be removed in the next minor release.") if pref == :flatten
93
91
 
94
92
  # defaults to old behavior, complain if its supplied and invalid
95
- unless [:ok, :failed, :flatten, :always].include?(pref)
96
- raise "Display preference #{pref} is not valid, should be :ok, :failed, :flatten or :always"
97
- end
93
+ raise "Display preference #{pref} is not valid, should be :ok, :failed, :flatten or :always" unless [:ok, :failed, :flatten, :always].include?(pref)
98
94
 
99
95
  action = @current_entity
100
96
  @entities[action][:display] = pref
@@ -223,23 +219,15 @@ module MCollective
223
219
  # agent should be allowed based on action name and inputs.
224
220
  def validate_rpc_request(action, arguments)
225
221
  # is the action known?
226
- unless actions.include?(action)
227
- raise DDLValidationError, "Attempted to call action #{action} for #{@pluginname} but it's not declared in the DDL"
228
- end
222
+ raise DDLValidationError, "Attempted to call action #{action} for #{@pluginname} but it's not declared in the DDL" unless actions.include?(action)
229
223
 
230
224
  input = action_interface(action)[:input] || {}
231
225
  compatible_args = symbolize_basic_input_arguments(input, arguments)
232
226
 
233
227
  input.each_key do |key|
234
- unless input[key][:optional]
235
- unless compatible_args.include?(key)
236
- raise DDLValidationError, "Action #{action} needs a #{key} argument"
237
- end
238
- end
228
+ raise DDLValidationError, "Action #{action} needs a #{key} argument" if !input[key][:optional] && !compatible_args.include?(key)
239
229
 
240
- if compatible_args.include?(key)
241
- validate_input_argument(input, key, compatible_args[key])
242
- end
230
+ validate_input_argument(input, key, compatible_args[key]) if compatible_args.include?(key)
243
231
  end
244
232
 
245
233
  true
@@ -64,6 +64,7 @@ module MCollective
64
64
  def usage(usage_text)
65
65
  @usage = usage_text
66
66
  end
67
+ # rubocop:enable Lint/DuplicateMethods, Style/TrivialAccessors
67
68
 
68
69
  def template_for_plugintype
69
70
  case @plugintype
@@ -80,9 +81,7 @@ module MCollective
80
81
  end
81
82
 
82
83
  def loadddlfile
83
- if @config.mode == :client && !client_activated?
84
- raise("%s/%s is disabled, cannot load DDL file" % [@plugintype, @pluginname])
85
- end
84
+ raise("%s/%s is disabled, cannot load DDL file" % [@plugintype, @pluginname]) if @config.mode == :client && !client_activated?
86
85
 
87
86
  if ddlfile = findddlfile
88
87
  instance_eval(File.read(ddlfile), ddlfile, 1)
@@ -111,10 +110,10 @@ module MCollective
111
110
  end
112
111
 
113
112
  def validate_requirements
114
- if requirement = @requirements[:mcollective]
115
- if Util.versioncmp(Util.mcollective_version, requirement) < 0
116
- raise DDLValidationError, "%s plugin '%s' requires MCollective version %s or newer" % [@plugintype.to_s.capitalize, @pluginname, requirement]
117
- end
113
+ requirement = @requirements[:mcollective]
114
+
115
+ if requirement && (Util.versioncmp(Util.mcollective_version, requirement) < 0)
116
+ raise DDLValidationError, "%s plugin '%s' requires MCollective version %s or newer" % [@plugintype.to_s.capitalize, @pluginname, requirement]
118
117
  end
119
118
 
120
119
  true
@@ -147,7 +146,7 @@ module MCollective
147
146
  Validator.validate(argument, input[key][:type])
148
147
  end
149
148
 
150
- return true
149
+ true
151
150
  rescue => e
152
151
  raise DDLValidationError, "Cannot validate input %s: %s" % [key, e.to_s], e.backtrace
153
152
  end
@@ -196,8 +195,8 @@ module MCollective
196
195
  action = @current_entity
197
196
 
198
197
  @entities[action][:output][argument] = {:description => properties[:description],
199
- :display_as => properties[:display_as],
200
- :default => properties[:default]}
198
+ :display_as => properties[:display_as],
199
+ :default => properties[:default]}
201
200
 
202
201
  @entities[action][:output][argument][:type] = properties[:type] if properties[:type]
203
202
  end
@@ -208,9 +207,7 @@ module MCollective
208
207
  valid_requirements = [:mcollective]
209
208
 
210
209
  requirement.each_key do |key|
211
- unless valid_requirements.include?(key)
212
- raise "Requirement %s is not a valid requirement, only %s is supported" % [key, valid_requirements.join(", ")]
213
- end
210
+ raise "Requirement %s is not a valid requirement, only %s is supported" % [key, valid_requirements.join(", ")] unless valid_requirements.include?(key)
214
211
 
215
212
  @requirements[key] = requirement[key]
216
213
  end
@@ -29,9 +29,7 @@ module MCollective
29
29
 
30
30
  raise "Unknown discovery method %s" % method unless has_method?(method)
31
31
 
32
- unless method == "mc"
33
- raise "Custom discovery methods require direct addressing mode" unless Config.instance.direct_addressing
34
- end
32
+ raise "Custom discovery methods require direct addressing mode" if method != "mc" && !Config.instance.direct_addressing
35
33
 
36
34
  method
37
35
  end
@@ -49,9 +47,7 @@ module MCollective
49
47
 
50
48
  # if the discovery method got changed we might have an old DDL cached
51
49
  # this will detect that and reread the correct DDL from disk
52
- unless @ddl.meta[:name] == discovery_method
53
- @ddl = DDL.new(discovery_method, :discovery)
54
- end
50
+ @ddl = DDL.new(discovery_method, :discovery) unless @ddl.meta[:name] == discovery_method
55
51
 
56
52
  @ddl
57
53
  end
@@ -62,32 +58,22 @@ module MCollective
62
58
  def check_capabilities(filter)
63
59
  capabilities = ddl.discovery_interface[:capabilities]
64
60
 
65
- unless capabilities.include?(:classes)
66
- raise "Cannot use class filters while using the '%s' discovery method" % discovery_method unless filter["cf_class"].empty?
67
- end
61
+ raise "Cannot use class filters while using the '%s' discovery method" % discovery_method if !capabilities.include?(:classes) && !filter["cf_class"].empty?
68
62
 
69
- unless capabilities.include?(:facts)
70
- raise "Cannot use fact filters while using the '%s' discovery method" % discovery_method unless filter["fact"].empty?
71
- end
63
+ raise "Cannot use fact filters while using the '%s' discovery method" % discovery_method if !capabilities.include?(:facts) && !filter["fact"].empty?
72
64
 
73
- unless capabilities.include?(:identity)
74
- raise "Cannot use identity filters while using the '%s' discovery method" % discovery_method unless filter["identity"].empty?
75
- end
65
+ raise "Cannot use identity filters while using the '%s' discovery method" % discovery_method if !capabilities.include?(:identity) && !filter["identity"].empty?
76
66
 
77
- unless capabilities.include?(:compound)
78
- raise "Cannot use compound filters while using the '%s' discovery method" % discovery_method unless filter["compound"].empty?
79
- end
67
+ raise "Cannot use compound filters while using the '%s' discovery method" % discovery_method if !capabilities.include?(:compound) && !filter["compound"].empty?
80
68
  end
81
69
 
82
70
  # checks if compound filters are used and then forces the 'mc' discovery plugin
83
71
  def force_discovery_method_by_filter(filter)
84
- unless discovery_method == "mc"
85
- unless filter["compound"].empty?
86
- Log.info "Switching to mc discovery method because compound filters are used"
87
- @client.options[:discovery_method] = "mc"
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"
88
75
 
89
- return true
90
- end
76
+ return true
91
77
  end
92
78
 
93
79
  false
@@ -134,9 +120,9 @@ module MCollective
134
120
  discovered = discovery_class.discover(filter, discovery_timeout(timeout, filter), limit, @client)
135
121
 
136
122
  if limit > 0
137
- return discovered[0, limit]
123
+ discovered[0, limit]
138
124
  else
139
- return discovered
125
+ discovered
140
126
  end
141
127
  end
142
128
  end