Module: Cisco

Defined in:
lib/cisco_node_utils/vpc.rb,
lib/cisco_node_utils/ace.rb,
lib/cisco_node_utils/acl.rb,
lib/cisco_node_utils/bgp.rb,
lib/cisco_node_utils/pim.rb,
lib/cisco_node_utils/vdc.rb,
lib/cisco_node_utils/vni.rb,
lib/cisco_node_utils/vrf.rb,
lib/cisco_node_utils/vtp.rb,
lib/cisco_node_utils/yum.rb,
lib/cisco_node_utils/node.rb,
lib/cisco_node_utils/vlan.rb,
lib/cisco_node_utils/bgp_af.rb,
lib/cisco_node_utils/vrf_af.rb,
lib/cisco_node_utils/feature.rb,
lib/cisco_node_utils/evpn_vni.rb,
lib/cisco_node_utils/platform.rb,
lib/cisco_node_utils/snmpuser.rb,
lib/cisco_node_utils/interface.rb,
lib/cisco_node_utils/node_util.rb,
lib/cisco_node_utils/snmpgroup.rb,
lib/cisco_node_utils/dns_domain.rb,
lib/cisco_node_utils/ntp_config.rb,
lib/cisco_node_utils/ntp_server.rb,
lib/cisco_node_utils/snmpserver.rb,
lib/cisco_node_utils/vxlan_vtep.rb,
lib/cisco_node_utils/domain_name.rb,
lib/cisco_node_utils/name_server.rb,
lib/cisco_node_utils/router_ospf.rb,
lib/cisco_node_utils/bgp_neighbor.rb,
lib/cisco_node_utils/radius_global.rb,
lib/cisco_node_utils/radius_server.rb,
lib/cisco_node_utils/snmpcommunity.rb,
lib/cisco_node_utils/syslog_server.rb,
lib/cisco_node_utils/tacacs_server.rb,
lib/cisco_node_utils/interface_ospf.rb,
lib/cisco_node_utils/overlay_global.rb,
lib/cisco_node_utils/pim_group_list.rb,
lib/cisco_node_utils/pim_rp_address.rb,
lib/cisco_node_utils/vxlan_vtep_vni.rb,
lib/cisco_node_utils/bgp_neighbor_af.rb,
lib/cisco_node_utils/cisco_cmn_utils.rb,
lib/cisco_node_utils/router_ospf_vrf.rb,
lib/cisco_node_utils/syslog_settings.rb,
lib/cisco_node_utils/configparser_lib.rb,
lib/cisco_node_utils/snmpnotification.rb,
lib/cisco_node_utils/command_reference.rb,
lib/cisco_node_utils/fabricpath_global.rb,
lib/cisco_node_utils/portchannel_global.rb,
lib/cisco_node_utils/tacacs_server_host.rb,
lib/cisco_node_utils/fabricpath_topology.rb,
lib/cisco_node_utils/radius_server_group.rb,
lib/cisco_node_utils/tacacs_server_group.rb,
lib/cisco_node_utils/interface_portchannel.rb,
lib/cisco_node_utils/interface_service_vni.rb,
lib/cisco_node_utils/interface_channel_group.rb,
lib/cisco_node_utils/aaa_authentication_login.rb,
lib/cisco_node_utils/aaa_authorization_service.rb,
lib/cisco_node_utils/snmp_notification_receiver.rb,
lib/cisco_node_utils/aaa_authentication_login_service.rb

Overview

Add some interface-specific constants to the Cisco namespace

Defined Under Namespace

Modules: ConfigParser Classes: AaaAuthenticationLogin, AaaAuthenticationLoginService, AaaAuthorizationService, Ace, Acl, ChefUtils, CliError, CmdRef, CommandReference, DnsDomain, DomainName, Encryption, EvpnVni, FabricpathGlobal, FabricpathTopo, Feature, Interface, InterfaceChannelGroup, InterfaceOspf, InterfacePortChannel, InterfaceServiceVni, NameServer, Node, NodeUtil, NtpConfig, NtpServer, OverlayGlobal, Pim, PimGroupList, PimRpAddress, Platform, PortChannelGlobal, RadiusGlobal, RadiusServer, RadiusServerGroup, RouterBgp, RouterBgpAF, RouterBgpNeighbor, RouterBgpNeighborAF, RouterOspf, RouterOspfVrf, SnmpCommunity, SnmpGroup, SnmpNotification, SnmpNotificationReceiver, SnmpServer, SnmpUser, SyslogServer, SyslogSettings, TacacsServer, TacacsServerGroup, TacacsServerHost, UnsupportedCmdRef, UnsupportedError, Utils, Vdc, Vlan, Vni, Vpc, Vrf, VrfAF, Vtp, VxlanVtep, VxlanVtepVni, Yum

Constant Summary collapse

VLAN_NAME_SIZE =
33
IF_SWITCHPORT_MODE =
{
  disabled:   '',
  access:     'access',
  trunk:      'trunk',
  fex_fabric: 'fex-fabric',
  tunnel:     'dot1q-tunnel',
  fabricpath: 'fabricpath',
}
TACACS_SERVER_ENC_NONE =
0
TACACS_SERVER_ENC_CISCO_TYPE_7 =
7
TACACS_SERVER_ENC_UNKNOWN =
8
DEFAULT_INSTANCE_NAME =

global constants

'default'

Class Method Summary collapse

Class Method Details

.find_ascii(body, regex_query, *parent_cfg) ⇒ [String]?

Method for working with hierarchical show command output such as “show running-config”. Searches the given multi-line string for all matches to the given regex_query. If parents is provided, the matches will be filtered to only those that are located “under” the given parent sequence (as determined by indentation).

Examples:

Find all OSPF router names in the running-config

ospf_names = find_ascii(running_cfg, /^router ospf (\d+)/)

Find all address-family types under the given BGP router

bgp_afs = find_ascii(show_run_bgp, /^address-family (.*)/,
                     /^router bgp #{ASN}/)

Parameters:

  • body (String)

    The body of text to search

  • regex_query (Regex)

    The regular expression to match

  • parents (*Regex)

    zero or more regular expressions defining the parent configs to filter by.

Returns:

  • ([String], nil)

    array of matching (sub)strings, else nil.



387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
# File 'lib/cisco_node_utils/node.rb', line 387

def find_ascii(body, regex_query, *parent_cfg)
  return nil if body.nil? || regex_query.nil?

  # get subconfig
  parent_cfg.each { |p| body = find_subconfig(body, p) }
  if body.nil? || body.empty?
    return nil
  else
    # find matches and return as array of String if it only does one
    # match in the regex. Otherwise return array of array
    match = body.split("\n").map { |s| s.scan(regex_query) }
    match = match.flatten(1)
    return nil if match.empty?
    match = match.flatten if match[0].is_a?(Array) && match[0].length == 1
    return match
  end
end

.find_subconfig(body, regex_query) ⇒ String?

Returns the subsection associated with the given line of config to retrieve the subsection appropriately, or nil if no such subsection exists.

Parameters:

  • the (String)

    body of text to search

  • the (Regex)

    regex key of the config for which

Returns:

  • (String, nil)

    the subsection of body, de-indented



413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
# File 'lib/cisco_node_utils/node.rb', line 413

def find_subconfig(body, regex_query)
  return nil if body.nil? || regex_query.nil?

  rows = body.split("\n")
  match_row_index = rows.index { |row| regex_query =~ row }
  return nil if match_row_index.nil?

  cur = match_row_index + 1
  subconfig = []

  until (/\A\s+.*/ =~ rows[cur]).nil? || cur == rows.length
    subconfig << rows[cur]
    cur += 1
  end
  return nil if subconfig.empty?
  # Strip an appropriate minimal amount of leading whitespace from
  # all lines in the subconfig
  min_leading = subconfig.map { |line| line[/\A */].size }.min
  subconfig = subconfig.map { |line| line[min_leading..-1] }
  subconfig.join("\n")
end