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 19. Making a Standalone Client

In Chapter 15, we documented how to build an agent and in Chapter 17 how to build an application to extend the built-in mco command. Although that is useful for sending requests interactively or in a small shell script, it may not meet your needs for programatic usage.  

Baseline Client Program

You can build stand-alone Ruby scripts that utilize the same client libraries. The structure for these scripts is very similar, and you can use every option shown in the previous sections. Let’s walk you through an example here:  

#!/usr/bin/ruby
require 'mcollective'
include MCollective::RPC

options = rpcoptions do |parser, options|
  parser.define_head "Script for the Thanks agent"
  parser.banner = "Usage: thanks.rb [options] person"

  parser.on('-p', '--person NAME', 'Person to say goodbye to.') do |name|
    options[:person] = name
  end
end

# This is probably covered by the validation in the DDL
unless options.include?(:person)
  puts("You need to specify a person's name with --person")
  exit! 1
end

# Create an MCollective client utilizing our agent
client = rpcclient("thanks", :options => options)

# Enable to see discovery results
#client.discover :verbose => true

# To disable the progress indicator
#client.progress = false

# Two different ways to get results
# 1. Simple verbose output
printrpc client.say_goodbye(:person => options[:person]), :verbose => true

# 2. Format the output as you like
#client.say_goodbye(:person => options[:person]).each do |resp| ...
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