Module MCollective::Util
In: lib/mcollective/util.rb

Some basic utility helper methods useful to clients, agents, runner etc.

Methods

Public Class methods

we should really use Pathname#absolute? but it‘s not in all the ruby versions we support and it comes down to roughly this

Returns an aligned_string of text relative to the size of the terminal window. If a line in the string exceeds the width of the terminal window the line will be chopped off at the whitespace chacter closest to the end of the line and prepended to the next line, keeping all indentation.

The terminal size is detected by default, but custom line widths can passed. All strings will also be left aligned with 5 whitespace characters by default.

Return color codes, if the config color= option is false just return a empty string

Helper to return a string in specific color

Checks in PATH returns true if the command is found

Picks a config file defaults to ~/.mcollective else /etc/mcollective/client.cfg

Creates a standard options hash

Creates an empty filter

Checks if the passed in filter is an empty one

Calculate number of fields for printing

Get field size for printing

Gets the value of a specific fact, mostly just a duplicate of MCollective::Facts.get_fact but it kind of goes with the other classes here

Finds out if this MCollective has an agent by the name passed

If the passed name starts with a / it‘s assumed to be regex and will use regex to match

Checks if this node has a configuration management class by parsing the a text file with just a list of classes, recipes, roles etc. This is ala the classes.txt from puppet.

If the passed name starts with a / it‘s assumed to be regex and will use regex to match

Compares fact == value,

If the passed value starts with a / it‘s assumed to be regex and will use regex to match

Checks if the configured identity matches the one supplied

If the passed name starts with a / it‘s assumed to be regex and will use regex to match

Parse a fact filter string like foo=bar into the tuple hash thats needed

Returns the current ruby version as per RUBY_VERSION, mostly doing this here to aid testing

On windows ^c can‘t interrupt the VM if its blocking on IO, so this sets up a dummy thread that sleeps and this will have the end result of being interruptable at least once a second. This is a common pattern found in Rails etc

Escapes a string so it‘s safe to use in system() or backticks

Taken from Shellwords#shellescape since it‘s only in a few ruby versions

Converts a string into a boolean value Strings matching 1,y,yes,true or t will return TrueClass Any other value will return FalseClass

Helper to subscribe to a topic on multiple collectives or just one

Looks up the template directory and returns its full path

Figures out the columns and lines of the current tty

Returns [0, 0] if it can‘t figure it out or if you‘re not running on a tty

Helper to unsubscribe to a topic on multiple collectives or just one

compare two software versions as commonly found in package versions.

returns 0 if a == b returns -1 if a < b returns 1 if a > b

Code originally from Puppet

Returns the PuppetLabs mcollective path for windows

[Validate]