Module: Rbeapi::Client
- Defined in:
- lib/rbeapi/client.rb
Overview
Rbeapi::Client
Defined Under Namespace
Constant Summary collapse
- DEFAULT_TRANSPORT =
'https'- TRANSPORTS =
{ 'http' => 'Rbeapi::Eapilib::HttpEapiConnection', 'https' => 'Rbeapi::Eapilib::HttpsEapiConnection', 'http_local' => 'Rbeapi::Eapilib::HttpLocalEapiConenction', 'socket' => 'Rbeapi::Eapilib::SocketEapiConnection' }
Class Method Summary collapse
-
.config ⇒ Config
Returns the currently loaded config object.
-
.config_for(name) ⇒ Hash?
Returns the configuration options for the named connection from the loaded configuration.
-
.connect(opts = {}) ⇒ Rbeapi::Connection
Builds a connection object to a remote node using the specified options and return an instance of Rbeapi::Connection.
-
.connect_to(name) ⇒ Rbeapi::Node?
Retrieves the node config form the loaded configuration file and returns a Rbeapi::Node instance for working with the remote node.
-
.load_config(conf) ⇒ Object
load_config overrides the default conf file loaded in the config instances using the supplied conf argument as the conf file.
-
.make_connection(transport, opts = {}) ⇒ Rbeapi::EapiConnection
Creates a connection instance that can either be used directly or passed to a Node instance.
Class Method Details
.config ⇒ Config
Returns the currently loaded config object. This function will create a new instance of the config object if one doesn’t already exist
59 60 61 62 63 |
# File 'lib/rbeapi/client.rb', line 59 def config return @config if @config @config = Config.new @config end |
.config_for(name) ⇒ Hash?
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.
88 89 90 |
# File 'lib/rbeapi/client.rb', line 88 def config_for(name) config.get_connection(name) end |
.connect(opts = {}) ⇒ Rbeapi::Connection
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 or can be overridden using environment variables. Environment variables are specified by prepending EAPI to the option name. For instance to override the host param use EAPI_HOST.
135 136 137 138 |
# File 'lib/rbeapi/client.rb', line 135 def connect(opts = {}) transport = opts.fetch(:transport, DEFAULT_TRANSPORT) make_connection(transport, opts) end |
.connect_to(name) ⇒ Rbeapi::Node?
Retrieves the node config form the loaded configuration file and returns a Rbeapi::Node instance for working with the remote node.
101 102 103 104 105 106 107 108 |
# File 'lib/rbeapi/client.rb', line 101 def connect_to(name) config = config_for(name) return nil unless config config['host'] = name if config['host'] == '*' config = Rbeapi::Utils.transform_keys_to_symbols(config) connection = connect config Node.new(connection) end |
.load_config(conf) ⇒ Object
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.
73 74 75 |
# File 'lib/rbeapi/client.rb', line 73 def load_config(conf) config.read(conf) end |
.make_connection(transport, opts = {}) ⇒ Rbeapi::EapiConnection
Creates a connection instance that can either be used directly or passed to a Node instance.
148 149 150 151 152 |
# File 'lib/rbeapi/client.rb', line 148 def make_connection(transport, opts = {}) klass = TRANSPORTS.fetch(transport) cls = Rbeapi::Utils.class_from_string(klass) cls.new(opts) end |