class Rbeapi::Api::Managementdefaults

The Managementdefaults class provides a configuration instance for configuring management defaults of the node.

Constants

DEFAULT_SECRET_HASH

Public Instance Methods

get() click to toggle source

get scans the current nodes configuration and returns the values as a Hash describing the current state.

@example

{
  secret_hash: <string>
}

@return [nil, Hash<Symbol, Object] returns the nodes current running

configuration as a Hash. If management defaults are not configured
on the node this method will return nil.
# File lib/rbeapi/api/managementdefaults.rb, line 58
def get
  config = get_block('management defaults')

  settings = {}
  settings.merge!(parse_secret_hash(config))
end
set_secret_hash(opts = {}) click to toggle source

set_secret_hash configures the management defaults secret hash value in the current nodes running configuration. If the default keyword is provided, the configuration is defaulted using the default keyword.

@since eos_version 4.13.7M

Commands

management defaults
  secret hash <value>
  no secret hash
  default secret hash

@param opts [Hash] Optional keyword arguments

@option opts value [String] The value to configure the secret hash to.

@option opts enable [Boolean] If false then the command is

negated. Default is true.

@option opts default [Boolean] Configure the secret hash value using

the default keyword.

@return [Boolean] Returns true if the command completed successfully.

# File lib/rbeapi/api/managementdefaults.rb, line 109
def set_secret_hash(opts = {})
  unless ['md5', 'sha512', nil].include?(opts[:value])
    raise ArgumentError, 'secret hash must be md5 or sha512'
  end
  cmd = command_builder("secret hash #{opts[:value]}")
  cmds = ['management defaults', cmd]
  configure(cmds)
end

Private Instance Methods

parse_secret_hash(config) click to toggle source

parse_secret_hash scans the current nodes running configuration and extracts the value of secret hash from the management defaults. If the parse_secret has not been configured, then this method will return DEFAULT_SECRET_HASH. The return value is intended to be merged into the resource hash.

@api private

@param config [String] The management defaults configuration block

retrieved from the nodes current running configuration.

@return [Hash<Symbol, Object>] Returns the resource hash attribute.

# File lib/rbeapi/api/managementdefaults.rb, line 78
def parse_secret_hash(config)
  mdata = /(?<=\s{3}secret hash\s)(md5|sha512)$/.match(config)
  { secret_hash: mdata.nil? ? DEFAULT_SECRET_HASH : mdata[1] }
end