Module Rudy::Routines::Handlers::RyeTools

  1. lib/rudy/routines/handlers/rye.rb

Methods

public instance

  1. create_box
  2. create_set

Public instance methods

create_box (hostname, opts={})

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.

[show source]
    # File lib/rudy/routines/handlers/rye.rb, line 13
13:      def create_box(hostname, opts={})
14:        ld [:hostname, hostname, opts, caller[0]]
15:        opts = {
16:          :debug => false,
17:          :user => current_machine_user, 
18:          :ostype => current_machine_os || :unix,
19:          :impltype => :linux, 
20:          :info => STDOUT,
21:          :paranoid => false  # doesn't get passed through (Rye bug?)
22:        }.merge opts
23:        
24:        nickname = hostname
25:        if hostname.kind_of? Rudy::Machine
26:          hostname, nickname = hostname.dns_public, hostname.name
27:        end
28:        
29:        box = ::Rye::Box.new hostname, opts
30:        box.nickname = nickname
31:       
32:        local_keys = Rye.keys
33:        box.add_keys local_keys if local_keys.is_a?(Array)
34:        box.add_key user_keypairpath(opts[:user])
35:        
36:        # We define hooks so we can still print each command and its output
37:        # when running the command blocks. NOTE: We only print this in
38:        # verbosity mode. 
39:        if !@@global.parallel && !@@global.quiet
40:          # This block gets called for every command method call.
41:          box.pre_command_hook do |cmd, user, host, nickname|
42:            print_command user, nickname, cmd
43:          end
44:        end
45: 
46:        if @@global.verbose > 0 && !@@global.quiet
47:          box.stdout_hook do |content|
48:            li content
49:          end
50:          # And this one gets called after each command method call.
51:          box.post_command_hook do |ret|
52:            print_response ret
53:          end
54:        end
55: 
56:        box.exception_hook(::Rye::Err, &rbox_exception_handler)
57:        box.exception_hook(Exception, &rbox_exception_handler)
58:        
59:        ## It'd better for unknown commands to be handled elsewhere
60:        ## because it doesn't make sense to retry a method that doesn't exist
61:        ##box.exception_hook(Rye::CommandNotFound, &rbox_exception_handler)
62: 
63:        box
64:      end
create_set (hostnames, opts={})

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.

[show source]
     # File lib/rudy/routines/handlers/rye.rb, line 73
 73:      def create_set(hostnames, opts={})
 74:        hostnames ||= []
 75:        
 76:        ld "Creating set from:", hostnames.inspect
 77:        
 78:        opts = {
 79:          :user => (current_machine_user).to_s,
 80:          :parallel => @@global.parallel,
 81:          :quiet => Rudy.quiet?
 82:        }.merge(opts)
 83:        set = ::Rye::Set.new current_machine_group, opts 
 84:        
 85:        opts.delete(:parallel)   # Not used by Rye::Box.new
 86: 
 87:        hostnames.each do |m| 
 88: 
 89:          if m.is_a?(Rudy::Machine)
 90:            m.refresh! if m.dns_public.nil? || m.dns_public.empty?
 91:            if m.dns_public.nil? || m.dns_public.empty?
 92:              ld "Cannot find public DNS for #{m.name} (continuing...)"
 93:              rbox = self.create_box('nohost', opts) 
 94:            else
 95:              ld [:dns_public, m.dns_public, m.instid]
 96:              rbox = self.create_box(m.dns_public, opts) 
 97:            end
 98:            rbox.stash = m   # Store the machine instance in the stash
 99:            rbox.nickname = m.name
100:          else
101:            # Otherwise we assume it's a hostname
102:            rbox = self.create_box(m)
103:          end
104:          rbox.add_key user_keypairpath(opts[:user])
105:          set.add_box rbox
106:        end
107: 
108:        ld "Machines Set: %s" % [set.empty? ? '[empty]' : set.inspect]
109: 
110:        set
111:      end