Class: Cisco::Feature

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

Overview

Feature - node util class for managing common features

Class 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?

Class Method Details

.bfd_enableObject

Note that in most cases the enable methods should only enable; however, for test purposes it is sometimes convenient to support feature disablement for cleanup purposes.




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

def self.bfd_enable
  return if bfd_enabled?
  config_set('feature', 'bfd')
end

.bfd_enabled?Boolean

Returns:

  • (Boolean)


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

def self.bfd_enabled?
  config_get('feature', 'bfd')
rescue Cisco::CliError => e
  # cmd will syntax reject when feature is not enabled.
  raise unless e.clierror =~ /Syntax error/
  return false
end

.bgp_enableObject




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

def self.bgp_enable
  return if bgp_enabled?
  config_set('feature', 'bgp')
end

.bgp_enabled?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/cisco_node_utils/feature.rb', line 45

def self.bgp_enabled?
  config_get('feature', 'bgp')
end

.cli_error_check(result) ⇒ Object




263
264
265
266
267
268
269
270
271
272
273
274
275
276
# File 'lib/cisco_node_utils/feature.rb', line 263

def self.cli_error_check(result)
  # The NXOS feature cli may not raise an exception in some conditions and
  # instead just displays a STDOUT error message; thus NXAPI does not detect
  # the failure and we must catch it by inspecting the "body" hash entry
  # returned by NXAPI. This cli behavior is unlikely to change soon.
  fail result[2]['body'] if
    result[2].is_a?(Hash) &&
    /Hardware is not capable of supporting/.match(result[2]['body'].to_s)

  # Some test environments get result as a string instead of a hash
  fail result if
    result.is_a?(String) &&
    /Hardware is not capable of supporting/.match(result)
end

.compatible_interfaces(feature, property = 'supported_module_pids') ⇒ Object




279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
# File 'lib/cisco_node_utils/feature.rb', line 279

def self.compatible_interfaces(feature, property='supported_module_pids')
  # Figure out the interfaces in a modular switch that are
  # compatible with the given feature (or property within a feature)
  # and return an array of such interfaces
  module_pids = config_get(feature, property)
  return [] if module_pids.nil?
  module_regex = Regexp.new module_pids
  # first get the compatible modules present in the switch
  slots = Platform.slots.select do |_slot, filt_mod|
    filt_mod['pid'] =~ module_regex
  end
  return [] if slots.empty?
  # get the slot numbers only into filtered slots array
  filt_slots = slots.keys.map { |key| key[/\d+/] }
  # now filter interfaces in the vdc based on compatible slots
  vdc = Vdc.new(Vdc.default_vdc_name)
  filt_intfs = vdc.interface_membership.select do |intf|
    filt_slots.include? intf[/\d+/]
  end
  filt_intfs
end

.dhcp_enableObject




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

def self.dhcp_enable
  return if dhcp_enabled?
  config_set('feature', 'dhcp')
end

.dhcp_enabled?Boolean

Returns:

  • (Boolean)


55
56
57
58
59
60
61
# File 'lib/cisco_node_utils/feature.rb', line 55

def self.dhcp_enabled?
  config_get('feature', 'dhcp')
rescue Cisco::CliError => e
  # cmd will syntax reject when feature is not enabled.
  raise unless e.clierror =~ /Syntax error/
  return false
end

.fabric_enableObject




64
65
66
67
68
69
# File 'lib/cisco_node_utils/feature.rb', line 64

def self.fabric_enable
  # install feature-set and enable it
  return if fabric_enabled?
  config_set('feature', 'fabric', state: 'install') unless fabric_installed?
  config_set('feature', 'fabric', state: '')
end

.fabric_enabled?Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/cisco_node_utils/feature.rb', line 71

def self.fabric_enabled?
  config_get('feature', 'fabric') =~ /^enabled/
end

.fabric_forwarding_enableObject




84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/cisco_node_utils/feature.rb', line 84

def self.fabric_forwarding_enable
  return if fabric_forwarding_enabled?
  Feature.fabric_enable if Feature.fabric_supported?
  # The feature fabric-forwarding cli is required in some older nxos images
  # but is not present in newer images because nv_overlay_evpn handles
  # both features; therefore feature fabric-forwarding is best-effort
  # and ignored on cli failure.
  begin
    config_set('feature', 'fabric_forwarding')
  rescue Cisco::CliError
    Cisco::Logger.debug '"feature fabric forwarding" CLI was rejected'
  end
end

.fabric_forwarding_enabled?Boolean

Returns:

  • (Boolean)


98
99
100
# File 'lib/cisco_node_utils/feature.rb', line 98

def self.fabric_forwarding_enabled?
  config_get('feature', 'fabric_forwarding')
end

.fabric_installed?Boolean

Returns:

  • (Boolean)


75
76
77
# File 'lib/cisco_node_utils/feature.rb', line 75

def self.fabric_installed?
  config_get('feature', 'fabric') !~ /^uninstalled/
end

.fabric_supported?Boolean

Returns:

  • (Boolean)


79
80
81
# File 'lib/cisco_node_utils/feature.rb', line 79

def self.fabric_supported?
  config_get('feature', 'fabric')
end

.fex_enableObject




103
104
105
106
107
108
# File 'lib/cisco_node_utils/feature.rb', line 103

def self.fex_enable
  # install feature-set and enable it
  return if fex_enabled?
  config_set('feature', 'fex', state: 'install') unless fex_installed?
  config_set('feature', 'fex', state: '')
end

.fex_enabled?Boolean

Returns:

  • (Boolean)


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

def self.fex_enabled?
  config_get('feature', 'fex') =~ /^enabled/
end

.fex_installed?Boolean

Returns:

  • (Boolean)


114
115
116
# File 'lib/cisco_node_utils/feature.rb', line 114

def self.fex_installed?
  config_get('feature', 'fex') !~ /^uninstalled/
end

.fex_supported?Boolean

Returns:

  • (Boolean)


118
119
120
# File 'lib/cisco_node_utils/feature.rb', line 118

def self.fex_supported?
  config_get('feature', 'fex')
end

.itd_enableObject




123
124
125
126
# File 'lib/cisco_node_utils/feature.rb', line 123

def self.itd_enable
  return if itd_enabled?
  config_set('feature', 'itd')
end

.itd_enabled?Boolean

Returns:

  • (Boolean)


128
129
130
131
132
133
134
# File 'lib/cisco_node_utils/feature.rb', line 128

def self.itd_enabled?
  config_get('feature', 'itd')
rescue Cisco::CliError => e
  # cmd will syntax reject when feature is not enabled.
  raise unless e.clierror =~ /Syntax error/
  return false
end

.nv_overlay_disableObject



144
145
146
147
148
149
150
# File 'lib/cisco_node_utils/feature.rb', line 144

def self.nv_overlay_disable
  # Note: vdc platforms restrict this feature to F3 or newer linecards
  # Note: this is for test purposes only
  return unless nv_overlay_enabled?
  config_set('feature', 'nv_overlay', state: 'no')
  sleep 1
end

.nv_overlay_enableObject




137
138
139
140
141
142
# File 'lib/cisco_node_utils/feature.rb', line 137

def self.nv_overlay_enable
  # Note: vdc platforms restrict this feature to F3 or newer linecards
  return if nv_overlay_enabled?
  config_set('feature', 'nv_overlay', state: '')
  sleep 1
end

.nv_overlay_enabled?Boolean

Returns:

  • (Boolean)


152
153
154
155
156
157
158
# File 'lib/cisco_node_utils/feature.rb', line 152

def self.nv_overlay_enabled?
  config_get('feature', 'nv_overlay')
rescue Cisco::CliError => e
  # cmd will syntax reject when feature is not enabled.
  raise unless e.clierror =~ /Syntax error/
  return false
end

.nv_overlay_evpn_enableObject




165
166
167
168
# File 'lib/cisco_node_utils/feature.rb', line 165

def self.nv_overlay_evpn_enable
  return if nv_overlay_evpn_enabled?
  config_set('feature', 'nv_overlay_evpn')
end

.nv_overlay_evpn_enabled?Boolean

Returns:

  • (Boolean)


170
171
172
# File 'lib/cisco_node_utils/feature.rb', line 170

def self.nv_overlay_evpn_enabled?
  config_get('feature', 'nv_overlay_evpn')
end

.nv_overlay_evpn_supported?Boolean

Returns:

  • (Boolean)


174
175
176
# File 'lib/cisco_node_utils/feature.rb', line 174

def self.nv_overlay_evpn_supported?
  node.cmd_ref.supports?('feature', 'nv_overlay_evpn')
end

.nv_overlay_supported?Boolean

Returns:

  • (Boolean)


160
161
162
# File 'lib/cisco_node_utils/feature.rb', line 160

def self.nv_overlay_supported?
  node.cmd_ref.supports?('feature', 'nv_overlay')
end

.ospf_enableObject




179
180
181
182
# File 'lib/cisco_node_utils/feature.rb', line 179

def self.ospf_enable
  return if ospf_enabled?
  config_set('feature', 'ospf')
end

.ospf_enabled?Boolean

Returns:

  • (Boolean)


184
185
186
# File 'lib/cisco_node_utils/feature.rb', line 184

def self.ospf_enabled?
  config_get('feature', 'ospf')
end

.pim_enableObject




189
190
191
192
# File 'lib/cisco_node_utils/feature.rb', line 189

def self.pim_enable
  return if pim_enabled?
  config_set('feature', 'pim')
end

.pim_enabled?Boolean

Returns:

  • (Boolean)


194
195
196
# File 'lib/cisco_node_utils/feature.rb', line 194

def self.pim_enabled?
  config_get('feature', 'pim')
end

.private_vlan_enableObject




199
200
201
202
# File 'lib/cisco_node_utils/feature.rb', line 199

def self.private_vlan_enable
  return if private_vlan_enabled?
  config_set('feature', 'private_vlan')
end

.private_vlan_enabled?Boolean

Returns:

  • (Boolean)


204
205
206
# File 'lib/cisco_node_utils/feature.rb', line 204

def self.private_vlan_enabled?
  config_get('feature', 'private_vlan')
end

.tacacs_enableObject




209
210
211
212
# File 'lib/cisco_node_utils/feature.rb', line 209

def self.tacacs_enable
  return if tacacs_enabled? || platform == :ios_xr
  config_set('feature', 'tacacs')
end

.tacacs_enabled?Boolean

Returns:

  • (Boolean)


214
215
216
# File 'lib/cisco_node_utils/feature.rb', line 214

def self.tacacs_enabled?
  config_get('feature', 'tacacs')
end

.vn_segment_vlan_based_enableObject




219
220
221
222
223
# File 'lib/cisco_node_utils/feature.rb', line 219

def self.vn_segment_vlan_based_enable
  return if vn_segment_vlan_based_enabled?
  result = config_set('feature', 'vn_segment_vlan_based')
  cli_error_check(result)
end

.vn_segment_vlan_based_enabled?Boolean

Returns:

  • (Boolean)


225
226
227
# File 'lib/cisco_node_utils/feature.rb', line 225

def self.vn_segment_vlan_based_enabled?
  config_get('feature', 'vn_segment_vlan_based')
end

.vni_enableObject




230
231
232
233
234
# File 'lib/cisco_node_utils/feature.rb', line 230

def self.vni_enable
  return if vni_enabled?
  result = config_set('feature', 'vni')
  cli_error_check(result)
end

.vni_enabled?Boolean

Returns:

  • (Boolean)


236
237
238
# File 'lib/cisco_node_utils/feature.rb', line 236

def self.vni_enabled?
  config_get('feature', 'vni')
end

.vtp_disableObject

Special Case: The only way to remove a vtp instance is by disabling the feature.



249
250
251
252
# File 'lib/cisco_node_utils/feature.rb', line 249

def self.vtp_disable
  return unless vtp_enabled?
  config_set('feature', 'vtp', state: 'no')
end

.vtp_enableObject




241
242
243
244
245
# File 'lib/cisco_node_utils/feature.rb', line 241

def self.vtp_enable
  return if vtp_enabled?
  result = config_set('feature', 'vtp', state: '')
  cli_error_check(result)
end

.vtp_enabled?Boolean

Returns:

  • (Boolean)


254
255
256
257
258
259
260
# File 'lib/cisco_node_utils/feature.rb', line 254

def self.vtp_enabled?
  config_get('feature', 'vtp')
rescue Cisco::CliError => e
  # cmd will syntax reject when feature is not enabled.
  raise unless e.clierror =~ /Syntax error/
  return false
end