module Rbeapi::Client

Rbeapi::Client

Constants

DEFAULT_TRANSPORT
TRANSPORTS

Public Class Methods

config() click to toggle source

Returns the currently loaded config object. This function will create a new instance of the config object if one doesn't already exist.

@return [Config] Returns an instance of Config used for working

with the eapi.conf file.
# File lib/rbeapi/client.rb, line 60
def config
  return @config if @config
  @config = Config.new
  @config
end
config_for(name) click to toggle source

Returns the configuration options for the named connection from the loaded configuration. The configuration name is specified as the string right of the colon in the section name.

@param name [String] The connection name to return from the loaded

configuration.

@return [Hash, nil] This method will return the configuration hash for

the named configuration if found. If the name is not found, then
nil is returned.
# File lib/rbeapi/client.rb, line 89
def config_for(name)
  config.get_connection(name)
end
connect(opts = {}) click to toggle source

Builds a connection object to a remote node using the specified options and return an instance of Rbeapi::Connection. All configuration options can be passed via the :opts param.

@param opts [Hash] the options to create a message with.

@option opts host [String] The IP address or hostname of the remote

eAPI endpoint.

@option opts username [String] The username to use to authenticate

the eAPI connection with.

@option opts password [String] The password to use to authenticate

the eAPI connection with.

@option opts enablepwd [String] The enable password (if defined) to

pass to the remote node to enter privilege mode.

@option opts use_ssl [String] Specifies whether or not to use the

HTTP or HTTPS protocol.

@option opts port [String] The port to connect to. If not specified

The port is automatically determined based on the protocol used
(443 for https, 80 for http).

@return [Rbeapi::Connection] Returns an instance of Rbeapi::Connection

using the specified configuration options.
# File lib/rbeapi/client.rb, line 144
def connect(opts = {})
  transport = opts.fetch(:transport, DEFAULT_TRANSPORT)
  make_connection(transport, opts)
end
connect_to(name) click to toggle source

Retrieves the node config from the loaded configuration file and returns a Rbeapi::Node instance for working with the remote node.

@param name [String] The named configuration to use for creating the

connection to the remote node.

@return [Rbeapi::Node, nil] Returns an instance of Rbeapi::Node. If

the named configuration is not found then nil is returned.
# File lib/rbeapi/client.rb, line 102
def connect_to(name)
  config_entry = config_for(name)
  return nil unless config_entry
  config = config_entry.dup
  config['host'] = name if config['host'] == '*'
  config = Rbeapi::Utils.transform_keys_to_symbols(config)
  connection = connect config
  Node.new(connection)
  node = Node.new(connection)
  enablepwd = config.fetch(:enablepwd, nil)
  node.enable_authentication(enablepwd) if enablepwd
  node
end
load_config(conf) click to toggle source

load_config overrides the default conf file loaded in the config instances using the supplied conf argument as the conf file. This method will clear out an previously loaded configuration and replace all entries with the contents of the supplied file.

@param conf [String] The full path to the conf file to load into

the config instance.
# File lib/rbeapi/client.rb, line 74
def load_config(conf)
  config.read(conf)
end
make_connection(transport, opts = {}) click to toggle source

Creates a connection instance that can either be used directly or passed to a Node instance.

@param transport [String] The name of the transport to create.

@param opts [Hash] The options used to create the transport.

@return [Rbeapi::EapiConnection] A instance of a connection object.

# File lib/rbeapi/client.rb, line 158
def make_connection(transport, opts = {})
  klass = TRANSPORTS.fetch(transport)
  cls = Rbeapi::Utils.class_from_string(klass)
  cls.new(opts)
end