class MCollective::Application::Rpc - mcollective version 2.12.5

# class MCollective::Application::Rpc

### Public Instance Methods

main() click to toggle source

        # File lib/mcollective/application/rpc.rb
     80 def main
     81   mc = rpcclient(configuration[:agent])
     82
     83   mc.agent_filter(configuration[:agent])
     84
     85   string_to_ddl_type(configuration[:arguments], mc.ddl.action_interface(configuration[:action])) if mc.ddl
     86
     87   mc.validate_request(configuration[:action], configuration[:arguments])
     88
     89   if mc.reply_to
     90     configuration[:arguments][:process_results] = true
     91
     92     puts "Request sent with id: " + mc.send(configuration[:action], configuration[:arguments]) + " replies to #{mc.reply_to}"
     93   elsif !configuration[:show_results]
     94     configuration[:arguments][:process_results] = false
     95
     96     puts "Request sent with id: " + mc.send(configuration[:action], configuration[:arguments])
     97   else
     98     discover_args = {:verbose => true}
     99
    100     mc.detect_and_set_stdin_discovery
    101
    102     mc.discover discover_args
    103
    104     printrpc mc.send(configuration[:action], configuration[:arguments])
    105
    106     printrpcstats :summarize => true, :caption => "#{configuration[:agent]}##{configuration[:action]} call stats" if mc.discover.size > 0
    107
    108     halt mc.stats
    109   end
    110 end

post_option_parser(configuration) click to toggle source

       # File lib/mcollective/application/rpc.rb
    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           exit(1)
    45         end
    46       end
    47     else
    48       STDERR.puts("No agent, action and arguments specified")
    49       exit(1)
    50     end
    51   end
    52
    53   # convert arguments to symbols for keys to comply with simplerpc conventions
    54   args = configuration[:arguments].clone
    55   configuration[:arguments] = {}
    56
    57   args.each do |v|
    58     if v =~ /^(.+?)=(.+)$/
    59       configuration[:arguments][$1.to_sym] = $2
    60     end
    61   end
    62 end

string_to_ddl_type(arguments, ddl) click to toggle source

       # File lib/mcollective/application/rpc.rb
    64 def string_to_ddl_type(arguments, ddl)
    65   return if ddl.empty?
    66
    67   arguments.keys.each do |key|
    68     if ddl[:input].keys.include?(key)
    69       case ddl[:input][key][:type]
    70         when :boolean
    71           arguments[key] = MCollective::DDL.string_to_boolean(arguments[key])
    72
    73         when :number, :integer, :float
    74           arguments[key] = MCollective::DDL.string_to_number(arguments[key])
    75       end
    76     end
    77   end
    78 end