Method: Rbeapi::Client::Node#get_config

Defined in:
lib/rbeapi/client.rb

#get_config(opts = {}) ⇒ String

This method will retrieve the specified configuration from the node and return it in full text.

Parameters:

  • opts (Hash) (defaults to: {})

    the options to create a message with

Options Hash (opts):

  • config (String)

    The configuration instance to return from the node. Valid values are ‘running-config’ and ‘startup-config’. If no value is specified, then ‘running-config’ is used.

  • param (String)

    Additional parameters to append to the retrieving the configuration. Valid values depend on the config file requested.

    running-config params

    all         Configuration with defaults
    detail      Detail configuration with defaults
    diffs       Differences from startup-config
    interfaces  Filter config to include only the given interfaces
    sanitized   Sanitized Output
    section     Display sections containing matching commands
    

    startup-config params

    errors      Show information about the errors in startup-config
    interfaces  Filter config to include only the given interfaces
    section     Display sections containing matching commands
    

Returns:

  • (String)

    The specified configuration as text or nil if no config is found. When encoding is set to json, returns a hash.



513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
# File 'lib/rbeapi/client.rb', line 513

def get_config(opts = {})
  config = opts.fetch(:config, 'running-config')
  params = opts.fetch(:params, '')
  encoding = opts.fetch(:encoding, 'text')
  as_string = opts.fetch(:as_string, false)
  begin
    result = run_commands("show #{config} #{params}", encoding: encoding)
  rescue Rbeapi::Eapilib::CommandError => error
    # rubocop:disable Style/GuardClause
    if error.to_s =~ /'show (running|startup)-config'/
      return nil
    else
      raise error
    end
    # rubocop:enable Style/GuardClause
  end
  if encoding == 'json' # rubocop:disable Style/GuardClause
    return result.first
  else
    return result.first['output'].strip.split("\n") unless as_string
    result.first['output'].strip
  end
end