class MCollective::Application::Controller

Public Instance Methods

main() click to toggle source
# File plugins/mcollective/application/controller.rb, line 52
def main
    client = MCollective::Client.new(options[:config])
    client.options = options

    counter = 0

    command = configuration[:command]
    command += " #{configuration[:argument]}" if configuration[:argument]

    statistics = client.discovered_req(command, 'mcollective') do |response|
        next unless response

        counter += 1

        sender = response[:senderid]
        body   = response[:body]

        case command
            when %r^stats$/
                print_statistics(sender, body[:stats])
            when %r^reload_agent(?:.+)/
                printf("%40s> %s\n", sender, body)
            else
                if options[:verbose]
                    puts "#{sender}>"
                    pp body
                else
                    puts if counter % 4 == 1
                    print "#{sender} "
                end
        end
    end

    client.disconnect

    client.display_stats(statistics, false, "mcollectived controller summary")
end
post_option_parser(configuration) click to toggle source
# File plugins/mcollective/application/controller.rb, line 30
def post_option_parser(configuration)
    configuration[:command] = ARGV.shift if ARGV.size > 0
end
print_statistics(sender, statistics) click to toggle source
validate_configuration(configuration) click to toggle source
# File plugins/mcollective/application/controller.rb, line 34
def validate_configuration(configuration)
    unless configuration.include?(:command)
        raise "Please specify a command and optional arguments"
    end

    #
    # When asked to restart an agent we need to make sure that
    # we have this agent name and set appropriate filters ...
    #
    if configuration[:command].match(%r^reload_agent$/)
        unless configuration.include?(:argument)
            raise "Please specify an agent name to reload with --argument"
        end

        options[:filter]['agent'] << configuration[:argument]
    end
end