Skip to Content
Learning MCollective
book

Learning MCollective

by Jo Rhett
August 2014
Intermediate to advanced
284 pages
5h 24m
English
O'Reilly Media, Inc.
Content preview from Learning MCollective

Chapter 18. Processing Multiple Actions

In this chapter, we’re going to expand our agent and client to handle multiple distinct actions. This adds just one small layer on what you already know, but it provides you great flexibility in how you build and package your agents going forward. 

Recalling what you learned in Chapter 15, go back and open up thanks/agent/thanks.rb to add another action. Let’s call this new action get_towel. Add it just after the very first end so it will remain inside the Thanks class. You can put anything you want in this new action (just remember to set a message and a statuscode):

module MCollective
  module Agent
    class Thanks<RPC::Agent
      action "say_goodbye" do
        blah blah blah
      end
      action "get_towel" do
        something amazing
      end
    end
  end
end

Next, we need to update the DDL file to know about the new action. Do yourself a favor and copy/paste the entire action block for say_goodbye and then edit the title. Change your input and output for whatever amazing thing you’ve done with the get_towel action:

action "say_goodbye", :description => "Says Goodbye" do
  blah blah blah
end

action "get_towel", :description => "Grabs Towel" do
  display :always   # could be :ok or :failed

  input :color,
        :prompt      => "Which color towel to grab",
  amazing inputs
end

That was all pretty easy, right? Now let’s get dirty with the only nontrivial bit of supporting multiple actions, which is adding multiaction smarts into your application. Open up the thanks/application/thanks.rb file and ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Russell Rules

Russell Rules

Bill Russell
What Employees Want Most in Uncertain Times

What Employees Want Most in Uncertain Times

Kristine W. Powers, Jessica B.B. Diaz
How to Become a Game-Changing Leader

How to Become a Game-Changing Leader

Douglas A. Ready, Alan Mulally
How You Play the Game

How You Play the Game

Jerry Colangelo, Len Sherman

Publisher Resources

ISBN: 9781491945681Errata