Method: Rbeapi::Client::Node#config

Defined in:
lib/rbeapi/client.rb

#config(commands, opts = {}) ⇒ Array<Hash>

The config method is a convenience method that will handling putting the switch into config mode prior to executing commands. The method will insert ‘config’ at the top of the command stack and then pop the empty hash from the response output before return the array to the caller.

Parameters:

  • commands (Array<String, Hash>)

    An ordered list of commands to execute. A string in the list is an eapi command. A Hash entry in the array consists of the following key value pairs:

    { cmd: 'eapi command', input: 'text passed into stdin for command' }
    
  • opts (Hash) (defaults to: {})

    a customizable set of options

Options Hash (opts):

  • encoding (String)

    The encoding scheme to use for sending and receive eAPI messages. Valid values are json and text. The default value is json.

  • open_timeout (Float)

    Number of seconds to wait for the eAPI connection to open.

  • read_timeout (Float)

    Number of seconds to wait for one block of eAPI results to be read (via one read(2) call).

Returns:

  • (Array<Hash>)

    Ordered list of output from commands.



362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
# File 'lib/rbeapi/client.rb', line 362

def config(commands, opts = {})
  commands = [*commands] unless commands.respond_to?('each')

  commands.insert(0, 'configure terminal')

  if @dry_run
    puts '[rbeapi dry-run commands]'
    puts commands
  else
    response = run_commands(commands, opts)

    refresh if @autorefresh

    response.shift
    response
  end
end