Class: Cisco::HostName

Inherits:
NodeUtil show all
Defined in:
lib/cisco_node_utils/hostname.rb

Overview

Hostname- node utility class for hostname configuration

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from NodeUtil

#client, client, #config_get, config_get, #config_get_default, config_get_default, config_set, #config_set, #get, #ios_xr?, #nexus?, node, #node, platform, #platform, supports?, #supports?

Constructor Details

#initialize(name, instantiate = true) ⇒ HostName

Returns a new instance of HostName


26
27
28
29
# File 'lib/cisco_node_utils/hostname.rb', line 26

def initialize(name, instantiate=true)
  @name = name
  create if instantiate
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name


24
25
26
# File 'lib/cisco_node_utils/hostname.rb', line 24

def name
  @name
end

Class Method Details

.hostnameObject


31
32
33
34
35
36
# File 'lib/cisco_node_utils/hostname.rb', line 31

def self.hostname
  hash = {}
  hostname = config_get('hostname', 'name')
  hash[hostname] = HostName.new(hostname, false)
  hash
end

Instance Method Details

#==(other) ⇒ Object


50
51
52
# File 'lib/cisco_node_utils/hostname.rb', line 50

def ==(other)
  name == other.name
end

#createObject


54
55
56
# File 'lib/cisco_node_utils/hostname.rb', line 54

def create
  config_set('hostname', 'name', state: '', name: @name)
end

#destroyObject


58
59
60
# File 'lib/cisco_node_utils/hostname.rb', line 58

def destroy
  config_set('hostname', 'name', state: 'no', name: @name)
end

#hostname=(host) ⇒ Object


38
39
40
41
42
43
44
45
46
47
48
# File 'lib/cisco_node_utils/hostname.rb', line 38

def hostname=(host)
  if host
    config_set(
      'hostname', 'name',
      state: '', name: host)
  else
    config_set(
      'hostname', 'name',
      state: 'no', name: '')
  end
end