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

#configure, #get_block, #initialize, instance

Constructor Details

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

Instance Method Details

#getHash

Returns the system settings

Examples:

{
  hostname: <string>
}

Returns:

  • (Hash)

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


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

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

#parse_hostname(config) ⇒ Object


59
60
61
62
# File 'lib/rbeapi/api/system.rb', line 59

def parse_hostname(config)
  mdata = /(?<=^hostname\s)(.+)$/.match(config)
  { hostname: mdata.nil? ? '' : mdata[1] }
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

  • :default (Boolean)

    The value should be set to default

Returns:

  • (Boolean)

    returns true if the command completed successfully


72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/rbeapi/api/system.rb', line 72

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

  case default
  when true
    cmds = ['default hostname']
  when false
    cmds = (value.nil? ? 'no hostname' : \
                         "hostname #{value}")
  end
  configure(cmds)
end