Class: Rbeapi::Api::System

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

Overview

The System class configures the node system services such as hostname and domain name.

Instance Attribute Summary

Attributes inherited from Entity

#config, #error, #node

Instance Method Summary collapse

Methods inherited from Entity

#command_builder, #configure, #configure_interface, #get_block, instance

Constructor Details

#initialize(node) ⇒ System

Returns a new instance of System.



44
45
46
47
# File 'lib/rbeapi/api/system.rb', line 44

def initialize(node)
  super(node)
  @banners_re = Regexp.new(/^banner\s+(login|motd)\s?$\n(.*?)$\nEOF$\n/m)
end

Instance Method Details

#getHash

Returns the system settings for hostname, iprouting, and banners.

Examples:

{
  hostname: <string>,
  iprouting: <boolean>,
  banner_motd: <string>,
  banner_login: <string>
}

Returns:

  • (Hash)

    A Ruby hash object that provides the system settings as key/value pairs.



62
63
64
65
66
67
68
69
# File 'lib/rbeapi/api/system.rb', line 62

def get
  response = {}
  response.merge!(parse_hostname(config))
  response.merge!(parse_iprouting(config))
  response.merge!(parse_timezone(config))
  response.merge!(parse_banners(config))
  response
end

#set_banner(banner_type, opts = {}) ⇒ Boolean

Configures system banners.

Parameters:

  • banner_type (String)

    Banner to be changed (likely either login or motd).

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

    The configuration parameters.

Options Hash (opts):

  • value (string)

    The value to set for the banner.

  • enable (Boolean)

    If false then the command is negated. Default is true.

  • default (Boolean)

    If true configure the command using the default keyword. Default is false.

Returns:

  • (Boolean)

    Returns true if the command completed successfully.



213
214
215
216
217
218
219
220
221
222
223
# File 'lib/rbeapi/api/system.rb', line 213

def set_banner(banner_type, opts = {})
  value = opts[:value]
  cmd_string = "banner #{banner_type}"
  if value
    value += "\n" if value[-1, 1] != "\n"
    cmd = [{ cmd: cmd_string, input: value }]
  else
    cmd = command_builder(cmd_string, opts)
  end
  configure(cmd)
end

#set_hostname(opts = {}) ⇒ Boolean

Configures the system hostname value in the running-config.

Parameters:

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

    The configuration parameters.

Options Hash (opts):

  • value (string)

    The value to set the hostname to.

  • enable (Boolean)

    If false then the command is negated. Default is true.

  • default (Boolean)

    If true configure the command using the default keyword. Default is false.

Returns:

  • (Boolean)

    Returns true if the command completed successfully.



155
156
157
158
# File 'lib/rbeapi/api/system.rb', line 155

def set_hostname(opts = {})
  cmd = command_builder('hostname', opts)
  configure(cmd)
end

#set_iprouting(opts = {}) ⇒ Boolean

Configures the state of global ip routing.

Parameters:

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

    The configuration parameters.

Options Hash (opts):

  • enable (Boolean)

    True if ip routing should be enabled or False if ip routing should be disabled. Default is true.

  • default (Boolean)

    If true configure the command using the default keyword. Default is false.

Returns:

  • (Boolean)

    Returns true if the command completed successfully.



172
173
174
175
# File 'lib/rbeapi/api/system.rb', line 172

def set_iprouting(opts = {})
  cmd = command_builder('ip routing', opts)
  configure(cmd)
end

#set_timezone(opts = {}) ⇒ Boolean

Configures the value of clock timezone in the running-config.

Parameters:

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

    The configuration parameters.

Options Hash (opts):

  • value (string)

    The value to set the clock timezone to.

  • enable (Boolean)

    If false then the command is negated. Default is true.

  • default (Boolean)

    If true configure the command using the default keyword. Default is false.

Returns:

  • (Boolean)

    Returns true if the command completed successfully.



191
192
193
194
# File 'lib/rbeapi/api/system.rb', line 191

def set_timezone(opts = {})
  cmd = command_builder('clock timezone', opts)
  configure(cmd)
end