class Object

Public Instance Methods

agent_filter(*args) click to toggle source
# File ext/mc-irb, line 168
def agent_filter(*args)
    @agent.agent_filter(*args)

    print_filter
end
class_filter(*args) click to toggle source
# File ext/mc-irb, line 174
def class_filter(*args)
    @agent.class_filter(*args)

    print_filter
end
consolize() { || ... } click to toggle source
# File ext/mc-irb, line 40
def consolize &block
    yield

    IRB.setup(nil)
    irb = IRB::Irb.new
    IRB.conf[:MAIN_CONTEXT] = irb.context
    irb.context.evaluate("require 'irb/completion'", 0)

    begin
        require 'bond'
        Bond.start

        Bond.complete(:method => "rpc") do |e|
            begin
                if e.argument == 1
                    if e.arguments.last == "?"
                        puts "\n\nActions for #{@agent_name}:\n"

                        @agent.ddl.actions.each do |action|
                           puts "%20s - %s" % [ ":#{action}", @agent.ddl.action_interface(action)[:description] ]
                        end

                        print "\n" + e.line
                    end

                    @agent.ddl.actions

                elsif e.argument > 1
                    action = eval(e.arguments[0]).to_s
                    ddl = @agent.ddl.action_interface(action)

                    if e.arguments.last == "?"
                        puts "\n\nArguments for #{action}:\n"
                        ddl[:input].keys.each do |input|
                            puts "%20s - %s" % [ ":#{input}", ddl[:input][input][:description] ]
                        end

                        print "\n" + e.line
                    end

                    [ddl[:input].keys, :verbose].flatten
                end
            rescue Exception
                []
            end
        end
    rescue Exception
    end

    trap("SIGINT") do
        irb.signal_handle
    end
    catch(:IRB_EXIT) do
        irb.eval_input
    end
end
discover() click to toggle source
# File ext/mc-irb, line 192
def discover
    @agent.discover
end
fact_filter(*args) click to toggle source
# File ext/mc-irb, line 162
def fact_filter(*args)
    @agent.fact_filter(*args)

    print_filter
end
identity_filter(*args) click to toggle source
# File ext/mc-irb, line 156
def identity_filter(*args)
    @agent.identity_filter(*args)

    print_filter
end
instance_variable_defined?(meth) click to toggle source
# File spec/monkey_patches/instance_variable_defined.rb, line 3
def instance_variable_defined?(meth)
    instance_variables.include?(meth)
end
mc?() click to toggle source
# File ext/mc-irb, line 196
def mc?
    puts "    Available Commands:

        rpc                                 - Performs an RPC request
        reset                               - Resets the discovered knowledge
        discover                            - Performs a new discovery showing
                                              hosts that was found
        newagent                            - Switches to a new agent
        mchelp                              - The DDL created help for the agent

    Filter Commands:
        Filter arguments should be enclosed in "your.host.com" if they are strings
        else use /your.host/ to match Regular expressions

        identity_filter [identity]          - Sets an identity filter
        fact_filter [factname], [factvalue] - Sets a fact filter
        class_filter [classname]            - Sets a class filter
        agent_filter [agentname]            - Sets an agent filter
        reset_filter                        - Resets to the filter to blank
        print_filter                        - Displays current filter

    Available Variables:

        @agent_name                         - The name of the active agent
        @agent                              - The active RPC client

    Completions:

        While doing an RPC request, press ?<tab> for a list of actions or
        arguments, do simple :<tab> to get completion on action names and
        arguments without description of each

"
    true
end
mchelp() click to toggle source
# File ext/mc-irb, line 97
def mchelp
    system("mc-rpc --agent-help #{@agent_name}|less")
    true
end
newagent(agent) click to toggle source
# File ext/mc-irb, line 143
def newagent(agent)
    @agent_name = agent

    @options[:filter]["agent"] = []
    @agent = rpcclient(@agent_name, :options => @options)

    discover

    @agent.progress = true

    print_filter
end
print_filter() click to toggle source
reset() click to toggle source
# File ext/mc-irb, line 186
def reset
    @agent.reset

    print_filter
end
reset_filter() click to toggle source
# File ext/mc-irb, line 180
def reset_filter
    @agent.reset_filter

    print_filter
end
rpc(method_name, *args) { |resp| ... } click to toggle source
# File ext/mc-irb, line 102
def rpc(method_name, *args, &block)
    unless block_given?
        if args.size > 0
            args = args.first
        else
            args = {}
        end

        if args[:verbose]
            args.delete(:verbose)

            printrpc(@agent.send(method_name, args), :verbose => true)
            printrpcstats
        else
            printrpc @agent.send(method_name, args)
            printrpcstats
        end

    else
        @agent.send(method_name, args.first).each do |resp|
            yield resp
        end

        printrpcstats
    end

    true
rescue MCollective::DDLValidationError => e
    puts "Request did not pass DDL validation: #{e}"
end
showhelp() click to toggle source
# File ext/stompclient, line 92
def showhelp
    puts("List of commands:")
    puts("\n\t- subscribe /(topic|queue)/foo    subscribes to topic of queue 'foo'")
    puts("\t- /(topic|queue|/foo bar          sends msg 'bar' to topic of queue 'foo'")
    puts("\t- quit|exit|q|^d                  exit")
    puts("\t- detail                          show/dont show time and topic a msg was received on")
    puts("\t- help                            show this help")
end