Class MCollective::Application::Rpc
In: plugins/mcollective/application/rpc.rb
Parent: MCollective::Application

Methods

Public Instance methods

As we‘re taking arguments on the command line we need a way to input booleans, true on the cli is a string so this method will take the ddl, find all arguments that are supposed to be boolean and if they are the strings "true"/"yes" or "false"/"no" turn them into the matching boolean

[Source]

    # File plugins/mcollective/application/rpc.rb, line 68
68:     def booleanish_to_boolean(arguments, ddl)
69:         arguments.keys.each do |key|
70:             if ddl[:input].keys.include?(key)
71:                 if ddl[:input][key][:type] == :boolean
72:                     arguments[key] = true if arguments[key] == "true"
73:                     arguments[key] = true if arguments[key] == "yes"
74:                     arguments[key] = true if arguments[key] == "1"
75:                     arguments[key] = false if arguments[key] == "false"
76:                     arguments[key] = false if arguments[key] == "no"
77:                     arguments[key] = false if arguments[key] == "0"
78:                 end
79:             end
80:         end
81:     rescue
82:         true
83:     end

[Source]

     # File plugins/mcollective/application/rpc.rb, line 85
 85:     def main
 86:         if configuration[:no_results]
 87:             configuration[:arguments][:process_results] = false
 88: 
 89:             mc = rpcclient(configuration[:agent])
 90: 
 91:             booleanish_to_boolean(configuration[:arguments], mc.ddl.action_interface(configuration[:action])) unless mc.ddl.nil?
 92: 
 93:             mc.agent_filter(configuration[:agent])
 94: 
 95:             puts "Request sent with id: " + mc.send(configuration[:action], configuration[:arguments])
 96:         else
 97:             mc = rpcclient(configuration[:agent])
 98: 
 99:             booleanish_to_boolean(configuration[:arguments], mc.ddl.action_interface(configuration[:action])) unless mc.ddl.nil?
100: 
101:             mc.agent_filter(configuration[:agent])
102:             mc.discover :verbose => true
103: 
104:             printrpc mc.send(configuration[:action], configuration[:arguments])
105: 
106:             printrpcstats :caption => "#{configuration[:agent]}##{configuration[:action]} call stats"
107:         end
108:     end

[Source]

    # File plugins/mcollective/application/rpc.rb, line 28
28:     def post_option_parser(configuration)
29:         # handle the alternative format that optparse cant parse
30:         unless (configuration.include?(:agent) && configuration.include?(:action))
31:             if ARGV.length >= 2
32:                 configuration[:agent] = ARGV[0]
33:                 ARGV.delete_at(0)
34: 
35:                 configuration[:action] = ARGV[0]
36:                 ARGV.delete_at(0)
37: 
38:                 ARGV.each do |v|
39:                     if v =~ /^(.+?)=(.+)$/
40:                         configuration[:arguments] = [] unless configuration.include?(:arguments)
41:                         configuration[:arguments] << v
42:                     else
43:                         STDERR.puts("Could not parse --arg #{v}")
44:                     end
45:                 end
46:             else
47:                 STDERR.puts("No agent, action and arguments specified")
48:                 exit!
49:             end
50:         end
51: 
52:         # convert arguments to symbols for keys to comply with simplerpc conventions
53:         args = configuration[:arguments].clone
54:         configuration[:arguments] = {}
55: 
56:         args.each do |v|
57:             if v =~ /^(.+?)=(.+)$/
58:                 configuration[:arguments][$1.to_sym] = $2
59:             end
60:         end
61:     end

[Validate]