August 2014
Intermediate to advanced
284 pages
5h 24m
English
We’ve done a bit of testing with the agent, doing direct RPCUtil queries against it. That’s a bit long of a command isn’t it? And look at all that messy RPCUtil output.
Why don’t we build a proper client plugin to interface with our new agent?
Unfortunately, there’s no easy command to generate a template for us, so we’ll just have to do this ourselves. This application will be thanks/application/thanks.rb. Assuming you are still inside the thanks/agent/ directory from earlier:
$ mkdir ../application $ cd ../application $ $EDITOR thanks.rb
Now let’s populate the file like so (you can find this file in the source code supplied with the book):
classMCollective::Application::Thanks<MCollective::Applicationdescription"Sends a thanks message."usage"mco thanks [OPTIONS]"# This options parser updates the help pageoption:person,:description=>"The person the dolphins say Goodbye to.",:arguments=>["-p NAME","--person NAME"],:type=>String,:require=>true# another hook where we could throw exceptions if the input isn't validdefvalidate_configuration(configuration)# this shouldn't happen since the option is mandatory aboveraise"Need to supply a person to get a reply."\unlessconfiguration.include?(:person)end# Now we enter main processingdefmainclient=rpcclient("thanks")printrpcclient.say_goodbye(:person=>configuration[:person],:options=>options)# Exit using halt and it will pass on the ...