Class: Cisco::Banner

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

Overview

Banner - node utility class for Banner configuration management

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) ⇒ Banner


26
27
28
29
30
31
32
# File 'lib/cisco_node_utils/banner.rb', line 26

def initialize(name)
  fail TypeError unless name.is_a?(String)
  fail ArgumentError,
       "This provider only accepts an id of 'default'" \
       unless name.eql?('default')
  @name = name
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name


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

def name
  @name
end

Class Method Details

.bannersObject


34
35
36
37
38
# File 'lib/cisco_node_utils/banner.rb', line 34

def self.banners
  hash = {}
  hash['default'] = Banner.new('default')
  hash
end

Instance Method Details

#==(other) ⇒ Object


40
41
42
# File 'lib/cisco_node_utils/banner.rb', line 40

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

#default_motdObject


59
60
61
# File 'lib/cisco_node_utils/banner.rb', line 59

def default_motd
  config_get_default('banner', 'motd')
end

#motdObject


44
45
46
# File 'lib/cisco_node_utils/banner.rb', line 44

def motd
  config_get('banner', 'motd')
end

#motd=(val) ⇒ Object


48
49
50
51
52
53
54
55
56
57
# File 'lib/cisco_node_utils/banner.rb', line 48

def motd=(val)
  if val.nil? && (motd != default_motd)
    config_set('banner', 'motd', state: 'no', motd: '')
  elsif !val.nil?
    config_set('banner',
               'motd',
               state: '',
               motd:  "^#{val.gsub(/\n/, '\\n')}^")
  end
end