{"id":1232,"date":"2009-12-22T14:51:18","date_gmt":"2009-12-22T13:51:18","guid":{"rendered":"http:\/\/www.devco.net\/?p=1232"},"modified":"2010-08-17T12:23:43","modified_gmt":"2010-08-17T11:23:43","slug":"mcollective_simple_rpc","status":"publish","type":"post","link":"https:\/\/www.devco.net\/archives\/2009\/12\/22\/mcollective_simple_rpc.php","title":{"rendered":"MCollective Simple RPC"},"content":{"rendered":"

MCollective<\/a> is a framework for writing RPC style tools that talk to a cloud of servers, till now doing that has been surprisingly hard for non ruby coders. The reason for this is that I was focussing on getting the framework built and feeling my way around the use cases.<\/p>\n

I’ve now spent 2 days working on simplifying actually writing agents and consumers. This code is not released yet – just in SVN trunk – but here’s a taster.<\/p>\n

First writing an agent should be simple, here’s a simple ‘echo’ server that takes a message as input and returns it back.<\/p>\n

<\/p>\n

\r\nclass Rpctest\n

<\/code><\/p>\n

This creates an echo action, does a quick check that a message was received and sends it back. I want to create a few more validators so you can check easily if the data passed to you is sane and secure if you're doing anything like system() calls with it.<\/p>\n

Here's the client code that calls the echo server 4 times:<\/p>\n

<\/p>\n

\r\n#!\/usr\/bin\/ruby\r\n\r\nrequire 'mcollective'\r\n\r\ninclude MCollective::RPC\r\n\r\nrpctest = rpcclient(\"rpctest\")\r\n\r\nputs \"Normal echo output, non verbose, shouldn't produce any output:\"\r\nprintrpc rpctest.echo(:msg => \"hello world\")\r\n\r\nputs \"Flattened echo output, think combined 'mailq' usecase:\"\r\nprintrpc rpctest.echo(:msg => \"hello world\"), :flatten => true\r\n\r\nputs \"Forced verbose output, if you always want to see every result\"\r\nprintrpc rpctest.echo(:msg => \"hello world\"), :verbose => true\r\n\r\nputs \"Did not specify needed input:\"\r\nprintrpc rpctest.echo\r\n<\/pre>\n

<\/code><\/p>\n

This client supports full discovery and all the usual stuff, has pretty --help output and everything else you'd expect in the clients I've supplied with the core mcollective. It caches discovery results so above code will do one discovery only and reuse it for the other calls to the collective.<\/p>\n

When running you'll see a twirling status indicator, something like:<\/p>\n

<\/p>\n

\r\n  - [5 \/ 10]\r\n<\/pre>\n

<\/code><\/p>\n

This will give you a nice non scrolling indicator of progress and should work well for 100s of machines without spamming you with noise, at the end of the run you'll get the output.<\/p>\n

The printrpc<\/em> helper function tries its best to print output for you in a way that makes sense on large amounts of machines.<\/p>\n

    \n
  • By default it doesn't print stuff that succeeds, you do get a overall progress indicator though<\/li>\n
  • If anything does go wrong, useful information gets printed but only for hosts that had problems<\/li>\n
  • If you ran the client with --verbose, or forced it to verbose mode output you'll get a full bit of info of the result from every server.<\/li>\n
  • It supports flags to modify the output, you can flatten the output so hostnames etc aren't showed, just a concat of the data.\n<\/ul>\n

    The script above gives the following output when run in non-verbose mode:<\/p>\n

    <\/p>\n

    \r\n$ rpctest.rb --with-class \/devel\/\r\n\r\nNormal echo output, non verbose, shouldn't produce any output:\r\n\r\nForced verbose output, if you always want to see every result:\r\ndev1.your.com                          : OK\r\n    \"hello world\"\r\n\r\ndev2.your.com                          : OK\r\n    \"hello world\"\r\n\r\ndev3.your.com                          : OK\r\n    \"hello world\"\r\n\r\nFlattened echo output, think combined 'mailq' usecase:\r\nhello world\r\nhello world\r\nhello world\r\n\r\nDid not specify needed input:\r\ndev1.your.com                          : please supply a :msg\r\ndev2.your.com                          : please supply a :msg\r\ndev3.your.com                          : please supply a :msg\r\n<\/pre>\n

    <\/code><\/p>\n

    Still some work to do, specifically stats needs a rethink in a scenario where you are making many calls such as in this script.<\/p>\n

    This will be in mcollective version 0.4 hopefully out early January 2010<\/p>\n","protected":false},"excerpt":{"rendered":"

    MCollective is a framework for writing RPC style tools that talk to a cloud of servers, till now doing that has been surprisingly hard for non ruby coders. The reason for this is that I was focussing on getting the framework built and feeling my way around the use cases. I’ve now spent 2 days […]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","footnotes":""},"categories":[7],"tags":[121,78,13],"_links":{"self":[{"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/posts\/1232"}],"collection":[{"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/comments?post=1232"}],"version-history":[{"count":11,"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/posts\/1232\/revisions"}],"predecessor-version":[{"id":1711,"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/posts\/1232\/revisions\/1711"}],"wp:attachment":[{"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/media?parent=1232"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/categories?post=1232"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/tags?post=1232"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}