Class: Rbeapi::Api::Logging

Inherits:
Entity
  • Object
show all
Defined in:
lib/rbeapi/api/logging.rb

Instance Attribute Summary

Attributes inherited from Entity

#config, #error, #node

Instance Method Summary collapse

Methods inherited from Entity

#configure, #get_block, #initialize, instance

Constructor Details

This class inherits a constructor from Rbeapi::Api::Entity

Instance Method Details

#add_host(name) ⇒ Boolean

add_host configures a new logging destination host address or hostname to the list of logging destinations. If the host is already configured in the list of destinations, this method will return successfully.

Parameters:

  • :name (String)

    The host name or ip address of the destination node to send logging information to.

Returns:

  • (Boolean)

    returns true if the command completed successfully


134
135
136
# File 'lib/rbeapi/api/logging.rb', line 134

def add_host(name)
  configure "logging host #{name}"
end

#getHash<Symbol, Object>

get returns the current logging configuration hash extracted from the nodes running configuration.

Examples:

{
  enable: [true, false]
  hosts: array<strings>
}

Returns:

  • (Hash<Symbol, Object>)

    returns the logging resource as a hash object from the nodes current configuration


52
53
54
55
56
57
# File 'lib/rbeapi/api/logging.rb', line 52

def get
  response = {}
  response.merge!(parse_enable)
  response.merge!(parse_hosts)
  response
end

#parse_enableObject

parse_enable scans the nodes current running configuration and extracts the current enabled state of the logging facility. The logging enable command is expected to always be in the node's configuration. This methods return value is intended to be merged into the logging resource hash.


65
66
67
68
# File 'lib/rbeapi/api/logging.rb', line 65

def parse_enable
  value = /no logging on/ !~ config
  { enable: value }
end

#parse_hostsObject

parse_hosts scans the nodes current running configuration and extracts the configured logging host destinations if any are configured. If no logging hosts are configured, then the value for hosts will be an empty array. The return value is intended to be merged into the logging resource hash


76
77
78
79
# File 'lib/rbeapi/api/logging.rb', line 76

def parse_hosts
  hosts = config.scan(/(?<=^logging\shost\s)[^\s]+/)
  { hosts: hosts }
end

#remove_host(name) ⇒ Boolean

remove_host deletes a logging destination host name or address form the list of logging destinations. If the host is not in the list of configured hosts, this method will still return successfully.

Parameters:

  • :name (String)

    The host name or ip address of the destination host to remove from the nodes current configuration

Returns:

  • (Boolean)

    returns true if the commands completed successfully


152
153
154
# File 'lib/rbeapi/api/logging.rb', line 152

def remove_host(name)
  configure "no logging host #{name}"
end

#set_enable(opts = {}) ⇒ Boolean

set_enable configures the global logging instance on the node as either enabled or disabled. If the value is set to true then logging is globally enabled and if set to false, it is globally disabled. If no value is specified, then the no keyword is used to configure the logging enable value. If the default keyword is specified and set to true, then the configuration is defaulted using the default keyword. The default keyword option takes precedence over the value keyword if both options are specified.

Parameters:

  • :opts (Hash)

    Optional keyword arguments

Returns:

  • (Boolean)

    returns true if the command completed successfully


107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/rbeapi/api/logging.rb', line 107

def set_enable(opts = {})
  value = opts[:value]
  default = opts[:default] || false

  case default
  when true
    cmd = 'default logging on'
  when false
    cmd = value ? 'logging on' : 'no logging on'
  end
  configure cmd
end