Class: Cisco::Vtp

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

Overview

Vtp - node utility class for VTP configuration management

Constant Summary collapse

MAX_VTP_DOMAIN_NAME_SIZE =
32
MAX_VTP_PASSWORD_SIZE =
64

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(instantiate = true) ⇒ Vtp

Constructor for Vtp


29
30
31
# File 'lib/cisco_node_utils/vtp.rb', line 29

def initialize(instantiate=true)
  Feature.vtp_enable if instantiate
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name


23
24
25
# File 'lib/cisco_node_utils/vtp.rb', line 23

def name
  @name
end

Class Method Details

.domainObject

Get vtp domain name


34
35
36
37
38
39
40
41
42
# File 'lib/cisco_node_utils/vtp.rb', line 34

def self.domain
  dom_def = config_get_default('vtp', 'domain')
  if Feature.vtp_enabled?
    dom = config_get('vtp', 'domain')
    return dom == '-' ? dom_def : dom
  else
    dom_def
  end
end

Instance Method Details

#default_filenameObject

Get default vtp filename


105
106
107
# File 'lib/cisco_node_utils/vtp.rb', line 105

def default_filename
  config_get_default('vtp', 'filename')
end

#default_passwordObject

Get default vtp password


85
86
87
# File 'lib/cisco_node_utils/vtp.rb', line 85

def default_password
  config_get_default('vtp', 'password')
end

#default_versionObject

Get default vtp version


121
122
123
# File 'lib/cisco_node_utils/vtp.rb', line 121

def default_version
  config_get_default('vtp', 'version')
end

#destroyObject

The only way to remove a vtp domain is to turn the vtp feature off.


46
47
48
# File 'lib/cisco_node_utils/vtp.rb', line 46

def destroy
  Feature.vtp_disable
end

#domainObject


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

def domain
  Vtp.domain
end

#domain=(d) ⇒ Object

Set vtp domain name


55
56
57
58
59
# File 'lib/cisco_node_utils/vtp.rb', line 55

def domain=(d)
  d = d.to_s
  fail ArgumentError unless d.length.between?(1, MAX_VTP_DOMAIN_NAME_SIZE)
  config_set('vtp', 'domain', domain: d)
end

#filenameObject

Get vtp filename


90
91
92
93
# File 'lib/cisco_node_utils/vtp.rb', line 90

def filename
  filename = config_get('vtp', 'filename') if Feature.vtp_enabled?
  filename.nil? ? default_filename : filename
end

#filename=(uri) ⇒ Object

Set vtp filename


96
97
98
99
100
101
102
# File 'lib/cisco_node_utils/vtp.rb', line 96

def filename=(uri)
  fail TypeError if uri.nil?
  Feature.vtp_enable
  uri = uri.to_s
  state = uri.empty? ? 'no' : ''
  config_set('vtp', 'filename', state: state, uri: uri)
end

#passwordObject

Get vtp password


62
63
64
65
66
67
68
69
70
71
72
# File 'lib/cisco_node_utils/vtp.rb', line 62

def password
  # Unfortunately nxapi returns "\\" when the password is not set
  password = config_get('vtp', 'password') if Feature.vtp_enabled?
  return '' if password.nil? || password == '\\'
  password
rescue Cisco::RequestNotSupported => e
  # Certain platforms generate a Cisco::RequestNotSupported when the
  # vtp password is not set.  We catch this specific error and
  # return empty '' for the password.
  return '' if e.message[/Structured output not supported/]
end

#password=(password) ⇒ Object

Set vtp password


75
76
77
78
79
80
81
82
# File 'lib/cisco_node_utils/vtp.rb', line 75

def password=(password)
  fail TypeError if password.nil?
  fail TypeError unless password.is_a? String
  fail ArgumentError if password.length > MAX_VTP_PASSWORD_SIZE
  Feature.vtp_enable
  state = (password == default_password) ? 'no' : ''
  config_set('vtp', 'password', state: state, password: password)
end

#versionObject

Get vtp version


110
111
112
# File 'lib/cisco_node_utils/vtp.rb', line 110

def version
  Feature.vtp_enabled? ? config_get('vtp', 'version') : default_version
end

#version=(v) ⇒ Object

Set vtp version


115
116
117
118
# File 'lib/cisco_node_utils/vtp.rb', line 115

def version=(v)
  Feature.vtp_enable
  config_set('vtp', 'version', version: v)
end