Chapter 15. Building an Agent

In this chapter, you will build a custom agent. You’ll start with a basic template useful as a starting point for agent development. Then you’ll add more functionality and test it from the mco client application.

We’ll expand the basics to provide additional features and discuss different ways to work with the MCollective plugin ecosystem.

After finishing this chapter, you’ll be able to take this agent template and replace just a few lines of Ruby to build a different custom agent.

SimpleRPC Framework

As we build MCollective clients and agents, we will be utilizing a set of libraries that comprise the SimpleRPC Framework. These libraries give us useful tools and handlers to simplify the tasks of communicating in the MCollective ecosystem. The SimpleRPC Framework provides conventions and standards that make it easy to work with plugins provided by others as well.

The framework isn’t law. You can easily peak beneath the hood using standard Ruby commands. However, it is rarely necessary, and everything we do in this book can be done by someone with little Ruby experience.

In the SimpleRPC Framework, data is passed back and forth in hashes like so:

say_goodbye( 
  :msg     => "So long...",
  :sender => "Dolphins"
)

There are a few simple rules for passing data back and forth:

  • Parameters must always be in a hash.

  • Parameter names can be anything you want (except :process_results, because this has special meaning to the agent and client).

  • Parameter values ...

Get Learning MCollective now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.