X-Git-Url: https://review.fuel-infra.org/gitweb?a=blobdiff_plain;f=doc%2FMCollective%2FUtil.html;fp=doc%2Fclasses%2FMCollective%2FUtil.html;h=64584ee3790d6163d123af7e9533a8ffe7635e03;hb=7c9314f502cde8daad23b61d10b24a542e04154a;hp=a7a701895307ba4adfd7c63c72d3f0fd3cdfcf08;hpb=d1f1649ba43c5cbc43c4beb2380096ba051d646a;p=packages%2Fprecise%2Fmcollective.git diff --git a/doc/classes/MCollective/Util.html b/doc/MCollective/Util.html similarity index 65% rename from doc/classes/MCollective/Util.html rename to doc/MCollective/Util.html index a7a7018..64584ee 100644 --- a/doc/classes/MCollective/Util.html +++ b/doc/MCollective/Util.html @@ -1,159 +1,421 @@ - - - + + - Module: MCollective::Util - - - - - - - - - - -
- - - - - - - - - + -
ModuleMCollective::Util
In: - - lib/mcollective/util.rb - -
-
-
- + Module: MCollective::Util -
+ + + + + - -
- -
-

+ + + +

+
+
+

In Files

+ +
+ + +
+ + + +
+ + + + + +
+

Class Index + [+]

+
+
+ Quicksearch + +
+
+ + + +
+ + +
+
+ +
+

MCollective::Util

+ +
+

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

-
- - -
- -
-

Methods

+
- -
+ + -
+ + + + +
+

Public Class Methods

- + +
+ -
+
+ + absolute_path?(path, separator=File::SEPARATOR, alt_separator=File::ALT_SEPARATOR) + click to toggle source + +
- - - - - - - - -
-

Public Class methods

- -
- - - - -
-

-we should really use Pathname#absolute? but it‘s not in all the ruby +

+ +

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

-

[Source]

-
+ + + +
      # File lib/mcollective/util.rb, line 464
 464:     def self.absolute_path?(path, separator=File::SEPARATOR, alt_separator=File::ALT_SEPARATOR)
@@ -164,23 +426,29 @@ versions we support and it comes down to roughly this
 469:       end
 470: 
 471:       !!path.match(path_matcher)
-472:     end
-
-
-
-
- - + + +
+ + +
+ + +
+ + align_text(text, console_cols = nil, preamble = 5) + click to toggle source + +
+ +
+ +

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 @@ -191,9 +459,11 @@ 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.

-

[Source]

-
+ + + +
      # File lib/mcollective/util.rb, line 310
 310:     def self.align_text(text, console_cols = nil, preamble = 5)
@@ -276,29 +546,37 @@ by default.
 387:       end
 388: 
 389:       text.join("\n")
-390:     end
-
-
-
-
- -
- - - - -
-

-Return color codes, if the config color= -option is false just return a empty string +390: end +

+ +
+ + +
+ + +
+ + +
+ + color(code) + click to toggle source + +
+ +
+ +

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

-

[Source]

-
+ + + +
      # File lib/mcollective/util.rb, line 270
 270:     def self.color(code)
@@ -316,54 +594,70 @@ option is false just return a empty string
 282:       else
 283:         return ""
 284:       end
-285:     end
-
-
-
-
- -
- - - - -
-

-Helper to return a string in specific color +285: end +

+ +
+ + +
+ + +
+ + +
+ + colorize(code, msg) + click to toggle source + +
+ +
+ +

+Helper to return a string in specific color

-

[Source]

-
+ + + +
      # File lib/mcollective/util.rb, line 288
 288:     def self.colorize(code, msg)
 289:       "%s%s%s" % [ color(code), msg, color(:reset) ]
-290:     end
-
-
-
-
- -
- - - - -
-

+290: end +

+ +
+ + +
+ + +
+ + +
+ + command_in_path?(command) + click to toggle source + +
+ +
+ +

Checks in PATH returns true if the command is found

-

[Source]

-
+ + + +
      # File lib/mcollective/util.rb, line 417
 417:     def self.command_in_path?(command)
@@ -372,29 +666,37 @@ Checks in PATH returns true if the command is found
 420:       end
 421: 
 422:       found.include?(true)
-423:     end
-
-
-
-
- -
- - - - -
-

+423: end +

+ +
+ + +
+ + +
+ + +
+ + config_file_for_user() + click to toggle source + +
+ +
+ +

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

-

[Source]

-
+ + + +
      # File lib/mcollective/util.rb, line 148
 148:     def self.config_file_for_user
@@ -420,28 +722,36 @@ Picks a config file defaults to ~/.mcollective else
 168:       end
 169: 
 170:       return config
-171:     end
-
-
-
-
- -
- - - - -
-

+171: end +

+ +
+ + +
+ + +
+ + +
+ + default_options() + click to toggle source + +
+ +
+ +

Creates a standard options hash

-

[Source]

-
+ + + +
      # File lib/mcollective/util.rb, line 174
 174:     def self.default_options
@@ -453,28 +763,36 @@ Creates a standard options hash
 180:        :discovery_method  => nil,
 181:        :discovery_options => Config.instance.default_discovery_options,
 182:        :filter            => empty_filter}
-183:     end
-
-
-
-
- -
- - - - -
-

+183: end +

+ +
+ + +
+ + +
+ + +
+ + empty_filter() + click to toggle source + +
+ +
+ +

Creates an empty filter

-

[Source]

-
+ + + +
      # File lib/mcollective/util.rb, line 132
 132:     def self.empty_filter
@@ -483,87 +801,111 @@ Creates an empty filter
 135:        "agent"    => [],
 136:        "identity" => [],
 137:        "compound" => []}
-138:     end
-
-
-
-
- -
- - - - -
-

+138: end +

+ +
+ + +
+ + +
+ + +
+ + empty_filter?(filter) + click to toggle source + +
+ +
+ +

Checks if the passed in filter is an empty one

-

[Source]

-
+ + + +
      # File lib/mcollective/util.rb, line 127
 127:     def self.empty_filter?(filter)
 128:       filter == empty_filter || filter == {}
-129:     end
-
-
-
-
- -
- - - - -
-

+129: end +

+ +
+ + +
+ + +
+ + +
+ + get_fact(fact) + click to toggle source + +
+ +
+ +

Gets the value of a specific fact, mostly just a duplicate of MCollective::Facts.get_fact but it kind of +href="Facts.html#M000483">MCollective::Facts.get_fact but it kind of goes with the other classes here

-

[Source]

-
+ + + +
     # File lib/mcollective/util.rb, line 63
 63:     def self.get_fact(fact)
 64:       Facts.get_fact(fact)
-65:     end
-
-
-
-
- -
- - - - -
-

+65: end +

+ +
+ + +
+ + +
+ + +
+ + has_agent?(agent) + click to toggle source + +
+ +
+ +

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 +If the passed name starts with a / it’s assumed to be regex and will use regex to match

-

[Source]

-
+ + + +
     # File lib/mcollective/util.rb, line 10
 10:     def self.has_agent?(agent)
@@ -580,34 +922,42 @@ use regex to match
 21:       end
 22: 
 23:       false
-24:     end
-
-
-
-
- -
- - - - -
-

+24: end +

+ +
+ + +
+ + +
+ + +
+ + has_cf_class?(klass) + click to toggle source + +
+ +
+ +

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 +If the passed name starts with a / it’s assumed to be regex and will use regex to match

-

[Source]

-
+ + + +
     # File lib/mcollective/util.rb, line 40
 40:     def self.has_cf_class?(klass)
@@ -629,32 +979,40 @@ use regex to match
 56:       end
 57: 
 58:       false
-59:     end
-
-
-
-
- -
- - - - -
-

+59: end +

+ +
+ + +
+ + +
+ + +
+ + has_fact?(fact, value, operator) + click to toggle source + +
+ +
+ +

Compares fact == value,

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

-

[Source]

-
+ + + +
      # File lib/mcollective/util.rb, line 71
  71:     def self.has_fact?(fact, value, operator)
@@ -694,32 +1052,40 @@ use regex to match
 105:       end
 106: 
 107:       false
-108:     end
-
-
-
-
- -
- - - - -
-

+108: end +

+ +
+ + +
+ + +
+ + +
+ + has_identity?(identity) + click to toggle source + +
+ +
+ +

Checks if the configured identity matches the one supplied

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

-

[Source]

-
+ + + +
      # File lib/mcollective/util.rb, line 114
 114:     def self.has_identity?(identity)
@@ -732,52 +1098,69 @@ use regex to match
 121:       end
 122: 
 123:       false
-124:     end
-
-
-
-
- -
- - - - -
-

+124: end +

+ +
+ + +
+ + +
+ + +
+ + loadclass(klass) + click to toggle source + +
+ +
+ +

Wrapper around PluginManager.loadclass +href="PluginManager.html#M000084">PluginManager.loadclass

-

[Source]

-
+ + + +
      # File lib/mcollective/util.rb, line 224
 224:     def self.loadclass(klass)
 225:       PluginManager.loadclass(klass)
-226:     end
-
-
-
-
- -
- - - - -
-

[Source]

-
+226: end +
+ +
+ + +
+ + +
+ + +
+ + make_subscriptions(agent, type, collective=nil) + click to toggle source + +
+ +
+ +

(Not documented)

+ + + +
      # File lib/mcollective/util.rb, line 185
 185:     def self.make_subscriptions(agent, type, collective=nil)
@@ -794,51 +1177,68 @@ href="PluginManager.html#M000034">PluginManager.loadclass
 196: 
 197:         [{:agent => agent, :type => type, :collective => collective}]
 198:       end
-199:     end
-
-
-
-
- -
- - - - -
-

[Source]

-
+199: end +
+ +
+ + +
+ + +
+ + +
+ + mcollective_version() + click to toggle source + +
+ +
+ +

(Not documented)

+ + + +
      # File lib/mcollective/util.rb, line 298
 298:     def self.mcollective_version
 299:       MCollective::VERSION
-300:     end
-
-
-
-
- -
- - - - -
-

+300: end +

+ +
+ + +
+ + +
+ + +
+ + parse_fact_string(fact) + click to toggle source + +
+ +
+ +

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

-

[Source]

-
+ + + +
      # File lib/mcollective/util.rb, line 229
 229:     def self.parse_fact_string(fact)
@@ -855,88 +1255,112 @@ Parse a fact filter string like foo=bar into the tuple hash thats needed
 240:       else
 241:         raise "Could not parse fact #{fact} it does not appear to be in a valid format"
 242:       end
-243:     end
-
-
-
-
- -
- - - - -
-

+243: end +

+ +
+ + +
+ + +
+ + +
+ + ruby_version() + click to toggle source + +
+ +
+ +

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

-

[Source]

-
+ + + +
      # File lib/mcollective/util.rb, line 294
 294:     def self.ruby_version
 295:       RUBY_VERSION
-296:     end
-
-
-
-
- -
- - - - -
-

-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 +296: end +

+ +
+ + +
+ + +
+ + +
+ + setup_windows_sleeper() + click to toggle source + +
+ +
+ +

+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

-

[Source]

-
+ + + +
     # File lib/mcollective/util.rb, line 30
 30:     def self.setup_windows_sleeper
 31:       Thread.new { loop { sleep 1 } } if Util.windows?
-32:     end
-
-
-
-
- -
- - - - -
-

-Escapes a string so it‘s safe to use in system() or backticks +32: end +

+ +
+ + +
+ + +
+ + +
+ + shellescape(str) + click to toggle source + +
+ +
+ +

+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 +Taken from Shellwords#shellescape since it’s only in a few ruby versions

-

[Source]

-
+ + + +
      # File lib/mcollective/util.rb, line 248
 248:     def self.shellescape(str)
@@ -953,30 +1377,37 @@ versions
 259:       str.gsub!(/\n/, "'\n'")
 260: 
 261:       return str
-262:     end
-
-
-
-
- -
- - - - -
-

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

+ +
+ + +
+ + +
+ + +
+ + str_to_bool(val) + click to toggle source + +
+ +
+ +

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

-

[Source]

-
+ + + +
      # File lib/mcollective/util.rb, line 477
 477:     def self.str_to_bool(val)
@@ -988,29 +1419,36 @@ return FalseClass
 483:       else
 484:         raise_code(:PLMC42, "Cannot convert string value '%{value}' into a boolean.", :error, :value => clean_val)
 485:       end
-486:     end
-
-
-
-
- -
- - - - -
-

-Helper to subscribe to a topic on multiple -collectives or just one +486: end +

+ +
+ + +
+ + +
+ + +
+ + subscribe(targets) + click to toggle source + +
+ +
+ +

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

-

[Source]

-
+ + + +
      # File lib/mcollective/util.rb, line 202
 202:     def self.subscribe(targets)
@@ -1021,28 +1459,36 @@ collectives or just one
 207:       targets.each do |target|
 208:         connection.subscribe(target[:agent], target[:type], target[:collective])
 209:       end
-210:     end
-
-
-
-
- -
- - - - -
-

+210: end +

+ +
+ + +
+ + +
+ + +
+ + t(msgid, args={}) + click to toggle source + +
+ +
+ +

Looks up and interprolate the hash values into a i18n string

-

[Source]

-
+ + + +
      # File lib/mcollective/util.rb, line 489
 489:     def self.t(msgid, args={})
@@ -1051,28 +1497,36 @@ Looks up and interprolate the hash values into a i18n string
 492:       else
 493:         I18n.t(msgid, args)
 494:       end
-495:     end
-
-
-
-
- -
- - - - -
-

+495: end +

+ +
+ + +
+ + +
+ + +
+ + templatepath(template_file) + click to toggle source + +
+ +
+ +

Looks up the template directory and returns its full path

-

[Source]

-
+ + + +
      # File lib/mcollective/util.rb, line 498
 498:     def self.templatepath(template_file)
@@ -1082,32 +1536,40 @@ Looks up the template directory and returns its full path
 502: 
 503:       template_path = File.join("/etc/mcollective", template_file)
 504:       return template_path
-505:     end
-
-
-
-
- - + + +
+ + +
+ + +
+ + terminal_dimensions(stdout = STDOUT, environment = ENV) + click to toggle source + +
+ +
+ +

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 +Returns [0, 0] if it can’t figure it out or if you’re not +running on a tty

-

[Source]

-
+ + + +
      # File lib/mcollective/util.rb, line 396
 396:     def self.terminal_dimensions(stdout = STDOUT, environment = ENV)
@@ -1128,29 +1590,36 @@ out or if you‘re not running on a tty
 411:       end
 412:     rescue
 413:       [0, 0]
-414:     end
-
-
-
-
- -
- - - - -
-

-Helper to unsubscribe to a topic on -multiple collectives or just one +414: end +

+ +
+ + +
+ + +
+ + +
+ + unsubscribe(targets) + click to toggle source + +
+ +
+ +

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

-

[Source]

-
+ + + +
      # File lib/mcollective/util.rb, line 213
 213:     def self.unsubscribe(targets)
@@ -1161,34 +1630,42 @@ multiple collectives or just one
 218:       targets.each do |target|
 219:         connection.unsubscribe(target[:agent], target[:type], target[:collective])
 220:       end
-221:     end
-
-
-
-
- -
- - - - -
-

+221: end +

+ +
+ + +
+ + +
+ + +
+ + versioncmp(version_a, version_b) + click to toggle source + +
+ +
+ +

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 +returns 0 if a == b returns -1 if a < b returns 1 if a > b

Code originally from Puppet

-

[Source]

-
+ + + +
      # File lib/mcollective/util.rb, line 433
 433:     def self.versioncmp(version_a, version_b)
@@ -1218,72 +1695,100 @@ Code originally from Puppet
 457:       end
 458: 
 459:       version_a <=> version_b;
-460:     end
-
-
-
-
- -
- - - - -
-

[Source]

-
+460: end +
+ +
+ + +
+ + +
+ + +
+ + windows?() + click to toggle source + +
+ +
+ +

(Not documented)

+ + + +
      # File lib/mcollective/util.rb, line 264
 264:     def self.windows?
 265:       !!(RbConfig::CONFIG['host_os'] =~ /mswin|win32|dos|mingw|cygwin/i)
-266:     end
-
-
-
-
- -
- - - - -
-

+266: end +

+ +
+ + +
+ + +
+ + +
+ + windows_prefix() + click to toggle source + +
+ +
+ +

Returns the PuppetLabs mcollective path for windows

-

[Source]

-
+ + + +
      # File lib/mcollective/util.rb, line 141
 141:     def self.windows_prefix
 142:       require 'win32/dir'
 143:       prefix = File.join(Dir::COMMON_APPDATA, "PuppetLabs", "mcollective")
-144:     end
-
-
-
-
+144: end +
+ +
+ +
-
+ +
+ +
-
+
+ +

Disabled; run with --debug to generate this.

+ +
-
-

[Validate]

-
+
+

[Validate]

+

Generated with the Darkfish + Rdoc Generator 1.1.6.

+
- \ No newline at end of file + +