Class/Module Index [+]

Quicksearch

Rudy::Routines::Handlers::RyeTools

Public Instance Methods

create_box(hostname, opts={}) click to toggle source

Create an instance of Rye::Box for hostname. opts is an optional Hash of options. See Rye::Box.initialize

This method should be used throughout the Rudy::Routines namespace rather than creating instances manually b/c it applies some fancy pants defaults like command hooks.

# File lib/rudy/routines/handlers/rye.rb, line 13
def create_box(hostname, opts={})
  ld [:hostname, hostname, opts, caller[0]]
  opts = {
    :debug => false,
    :user => current_machine_user, 
    :ostype => current_machine_os || :unix,
    :impltype => :linux, 
    :info => STDOUT,
    :paranoid => false  # doesn't get passed through (Rye bug?)
  }.merge opts
  
  nickname = hostname
  if hostname.kind_of? Rudy::Machine
    hostname, nickname = hostname.dns_public, hostname.name
  end
  
  box = ::Rye::Box.new hostname, opts
  box.nickname = nickname
 
  local_keys = Rye.keys
  box.add_keys local_keys if local_keys.is_a?(Array)
  box.add_key user_keypairpath(opts[:user])
  
  # We define hooks so we can still print each command and its output
  # when running the command blocks. NOTE: We only print this in
  # verbosity mode. 
  if !@@global.parallel && !@@global.quiet
    # This block gets called for every command method call.
    box.pre_command_hook do |cmd, user, host, nickname|
      print_command user, nickname, cmd
    end
  end

  if @@global.verbose > 0 && !@@global.quiet
    box.stdout_hook do |content|
      li content
    end
    # And this one gets called after each command method call.
    box.post_command_hook do |ret|
      print_response ret
    end
  end

  box.exception_hook(::Rye::Err, &rbox_exception_handler)
  box.exception_hook(Exception, &rbox_exception_handler)
  
  ## It'd better for unknown commands to be handled elsewhere
  ## because it doesn't make sense to retry a method that doesn't exist
  ##box.exception_hook(Rye::CommandNotFound, &rbox_exception_handler)

  box
end
create_set(hostnames, opts={}) click to toggle source

Create an instance of Rye::Set from a list of hostnames. hostnames can contain hostnames or Rudy::Machine objects. opts is an optional Hash of options. See Rye::Box.initialize

NOTE: Windows machines are skipped and not added to the set.

# File lib/rudy/routines/handlers/rye.rb, line 73
def create_set(hostnames, opts={})
  hostnames ||= []
  
  ld "Creating set from:", hostnames.inspect
  
  opts = {
    :user => (current_machine_user).to_s,
    :parallel => @@global.parallel,
    :quiet => Rudy.quiet?
  }.merge(opts)
  set = ::Rye::Set.new current_machine_group, opts 
  
  opts.delete(:parallel)   # Not used by Rye::Box.new

  hostnames.each do |m| 

    if m.is_a?(Rudy::Machine)
      m.refresh! if m.dns_public.nil? || m.dns_public.empty?
      if m.dns_public.nil? || m.dns_public.empty?
        ld "Cannot find public DNS for #{m.name} (continuing...)"
        rbox = self.create_box('nohost', opts) 
      else
        ld [:dns_public, m.dns_public, m.instid]
        rbox = self.create_box(m.dns_public, opts) 
      end
      rbox.stash = m   # Store the machine instance in the stash
      rbox.nickname = m.name
    else
      # Otherwise we assume it's a hostname
      rbox = self.create_box(m)
    end
    rbox.add_key user_keypairpath(opts[:user])
    set.add_box rbox
  end

  ld "Machines Set: %s" % [set.empty? ? '[empty]' : set.inspect]

  set
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.