Class Rye::Hop
In: lib/rye/hop.rb
Parent: Object

Rye::Hop

The Rye::Hop class represents a machine. This class allows boxes to by accessed via it.

    rhop = Rye::Hop.new('firewall.lan')
    rbox = Rye::Box.new('filibuster', :via => rhop)
    rbox.uptime     # => 20:53  up 1 day,  1:52, 4 users

Or

    rbox = Rye::Box.new('filibuster', :via => 'firewall.lan')

Methods

==   add_key   add_keys   connect   debug?   disconnect   error?   exception_hook=   fetch_port   host   host=   host_key   info?   inspect   keys   new   nickname   nickname=   opts   opts=   remove_hops!   remove_key   remove_keys   root?   ssh_config_options   switch_user   to_s   user   via   via?   via_hop  

Constants

MAX_PORT = 65535   The maximum port number that the gateway will attempt to use to forward connections from.
MIN_PORT = 1024   The minimum port number that the gateway will attempt to use to forward connections from.

Public Class methods

  • host The hostname to connect to. Default: localhost.
  • user The username to connect as. Default: SSH config file or current shell user.
  • opts a hash of optional arguments.

The opts hash excepts the following keys:

  • :port => remote server ssh port. Default: SSH config file or 22
  • :keys => one or more private key file paths (passwordless login)
  • :via => the Rye::Hop to access this host through
  • :info => an IO object to print Rye::Box command info to. Default: nil
  • :debug => an IO object to print Rye::Box debugging info to. Default: nil
  • :error => an IO object to print Rye::Box errors to. Default: STDERR
  • :getenv => pre-fetch host environment variables? (default: true)
  • :password => the user‘s password (ignored if there‘s a valid private key)
  • :templates => the template engine to use for uploaded files. One of: :erb (default)
  • :sudo => Run all commands via sudo (default: false)

NOTE: opts can also contain any parameter supported by Net::SSH.start that is not already mentioned above.

Public Instance methods

Compares itself with the other box. If the hostnames are the same, this will return true. Otherwise false.

add_key(*keys)

Alias for add_keys

Add one or more private keys to the list of key paths.

  • keys is a list of file paths to private keys

Returns the instance of Box

Open an SSH session with +@rye_host+. This called automatically when you the first comamnd is run if it‘s not already connected. Raises a Rye::NoHost exception if +@rye_host+ is not specified. Will attempt a password login up to 3 times if the initial authentication fails.

  • reconnect Disconnect first if already connected. The default

is true. When set to false, connect will do nothing if already connected.

Close the SSH session with +@rye_host+. This is called automatically at exit if the connection is open.

A Hash. The keys are exception classes, the values are Procs to execute

instance method, that will setup a forward, and return the port used

Returns the host SSH keys for this box

Cancel the port forward on all active local forwards

remove_key(*keys)

Alias for remove_keys

Remove one or more private keys fromt he list of key paths.

  • keys is a list of file paths to private keys

Returns the instance of Box

Parse SSH config files for use with Net::SSH

Reconnect as another user. This is different from su= which executes subsequent commands via +su -c COMMAND USER+.

  • newuser The username to reconnect as

NOTE: if there is an open connection, it‘s disconnected but not reconnected because it‘s possible it wasn‘t connected yet in the first place (if you create the instance with default settings for example)

Returns +user@rye_host+

  • hops Rye::Hop objects will be added directly

to the set. Hostnames will be used to create new instances of Rye::Hop h1 = Rye::Hop.new "host1" h1.via_hop "host2", :user => "service_user"

OR

h1 = Rye::Hop.new "host1" h2 = Rye::Hop.new "host2" h1.via_hop h2

[Validate]