Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
class ShowInterfacesTerseInterface(ShowInterfacesTerse):
""" Parser for:
- 'show interfaces terse {interface}'
"""
cli_command = 'show interfaces terse {interface}'
def cli(self, interface, output=None):
if output is None:
out = self.device.execute(self.cli_command.format(interface=interface))
else:
out = output
return super().cli(output=out)
class ShowInterfacesDescriptionsSchema(MetaParser):
""" Schema for:
* show interfaces descriptions
"""
def validate_physical_interface_list(value):
if not isinstance(value, list):
raise SchemaTypeError('physical-interface is not a list')
entry_schema = Schema(
{
"admin-status": str,
"description": str,
"name": str,
"oper-status": str
}
)
for item in value:
entry_schema.validate(item)
# PID: QSFP-100G-SR4-S , VID: V03 , SN: AVF2243S10A
m = p2.match(line)
if m:
group = m.groupdict()
for key in group.keys():
if group[key]:
final_dict[key] = group[key]
continue
return ret_dict
# ===========================
# Schema for 'show platform'
# ===========================
class ShowPlatformSchema(MetaParser):
"""Schema for show platform"""
schema = {
'chassis': str,
'slot': {
Any(): {
Optional('cpld_ver'): str,
Optional('fw_ver'): str,
'insert_time': str,
'name': str,
'slot': str,
'state': str,
Optional('subslot'): {
Any(): {
'insert_time': str,
class ShowLldpNeighborsDetail(ShowLldpEntry):
'''Parser for show lldp neighbors detail'''
cli_command = 'show lldp neighbors detail'
exclude = ['time_remaining']
def cli(self,output=None):
if output is None:
show_output = self.device.execute(self.cli_command)
else:
show_output = output
return super().cli(output=show_output)
class ShowLldpTrafficSchema(MetaParser):
"""Schema for show lldp traffic"""
schema = {
"frame_in": int,
"frame_out": int,
"frame_error_in": int,
"frame_discard": int,
"tlv_discard": int,
'tlv_unknown': int,
'entries_aged_out': int
}
class ShowLldpTraffic(ShowLldpTrafficSchema):
"""Parser for show lldp traffic"""
cli_command = 'show lldp traffic'
.convert_intf_name(intf=group['local_interface'].strip())
device_dict['hold_time'] = int(group['hold_time'])
device_dict['capability'] = group['capability'].strip()
if group['platform']:
device_dict['platform'] = group['platform'].strip()
elif not group['platform']:
device_dict['platform'] = ''
device_dict['port_id'] = Common \
.convert_intf_name(intf=group['port_id'].strip())
continue
return parsed_dict
class ShowCdpNeighborsDetailSchema(MetaParser):
''' Schema for:
* 'show cdp neighbors detail'
'''
schema = {
'total_entries_displayed': int,
Optional('index'):
{Any():
{'device_id': str,
'platform': str,
Optional('capabilities'): str,
'local_interface': str,
'port_id': str,
'hold_time': int,
'software_version': str,
'entry_addresses':
"""Parser for show routing ipv6 vrf all,
show routing ipv6 vrf """
exclude = [
'uptime']
def cli(self, vrf='', output=None):
return super().cli(ip='ipv6', vrf=vrf, output=output)
# =================================
# Parser for 'show ip route summary'
# Parser for 'show ip route summary vrf {vrf}'
# =================================
class ShowIpRouteSummarySchema(MetaParser):
"""Schema for
* show ip route summary
* show ip route summary vrf {vrf} """
schema = {
'vrf': {
Any(): {
'backup_paths': {
Optional(Any()): int,
},
'best_paths': {
Optional(Any()): int,
},
Optional('num_routes_per_mask'): {
Optional(Any()): int,
},
if 'vrf_interface' not in vrf_interface_dict:
vrf_interface_dict['vrf_interface'] = {}
if interface not in vrf_interface_dict['vrf_interface']:
vrf_interface_dict['vrf_interface'][interface] = {}
vrf_interface_dict['vrf_interface'][interface]['vrf_name'] = \
m.groupdict()['vrf_name']
vrf_interface_dict['vrf_interface'][interface]['vrf_id'] = \
m.groupdict()['vrf_id']
vrf_interface_dict['vrf_interface'][interface]['site_of_origin'] = \
m.groupdict()['site_of_origin']
continue
return vrf_interface_dict
class ShowVrfDetailSchema(MetaParser):
"""Schema for show vrf detail"""
schema = {Any():
{
'vrf_id': int,
Optional('route_distinguisher'): str,
Optional('vpn_id'): str,
'max_routes': int,
'mid_threshold': int,
'state': str,
'address_family': {
Any(): {
'table_id': str,
'fwd_id': str,
'state': str,
},
port_dict = intf_dict.setdefault('members', {})
port_list = re.findall(r'([\w/]+)\((\w+)\)', group['ports'])
for port in port_list:
intf = Common.convert_intf_name(port[0]).capitalize()
port_sub_dict = port_dict.setdefault(intf, {})
port_sub_dict.update({'flags': port[1]})
continue
return parsed_dict
# =====================================
# schema for show port-channel database
# =====================================
class ShowPortChannelDatabaseSchema(MetaParser):
""" schema for : show post-channel database"""
schema = {
'interfaces': {
Any(): {
'last_update_success': bool, # successful => True, else False
'total_ports': int,
'up_ports': int,
'port_channel_age': str,
'time_last_bundle': str,
'last_bundled_member': str,
Optional('first_oper_port'): str,
Optional('time_last_unbundle'): str,
Optional('last_unbundled_member'): str,
'members': {
Any(): {
'activity': str,
# VTP Password: password-string
m = p2.match(line)
if m:
sub_dict = ret_dict.setdefault('vtp', {})
sub_dict['configured'] = True
sub_dict['password'] = m.groupdict()['val']
continue
return ret_dict
# =============================================
# Parser for 'show vtp status'
# =============================================
class ShowVtpStatusSchema(MetaParser):
"""Schema for show vtp status"""
schema = {'vtp': {
Optional('version_capable'): list,
'version': str,
Optional('domain_name'): str,
'pruning_mode': bool,
'traps_generation': bool,
Optional('device_id'): str,
Optional('conf_last_modified_by'): str,
Optional('conf_last_modified_time'): str,
Optional('updater_id'): str,
Optional('updater_interface'): str,
Optional('updater_reason'): str,
Optional('operating_mode'): str,
Optional('enabled'): bool,
# Metaparser
import re
from genie.metaparser import MetaParser
from genie.metaparser.util.schemaengine import Any, Or, Optional
# ==============================
# Schema for 'show dmvpn'
# ==============================
class ShowDmvpnSchema(MetaParser):
"""
Schema for 'show dmvpn'
Schema for 'show dmvpn interface '
"""
# These are the key-value pairs to add to the parsed dictionary
schema = {
'dmvpn': {
Any(): {
'total_peers': str,
'type': str,
'peers': {
Any(): {
Any(): {
'tunnel_addr': str,
'state': str,
gd = match.groupdict()
entry = {'type': gd['type'].strip()}
if gd.get('name') and gd['name'].strip():
entry['name'] = gd['name'].strip()
if gd.get('alias') and gd['alias'].strip():
entry['alias'] = gd['alias'].strip()
device_dict[len(device_dict) + 1] = entry
continue
return services_dict
# ======================================================
# Schema for "show guestshell"
# ======================================================
class ShowGuestshellSchema(MetaParser):
"""Schema for "show guestshell".
This is the same as ShowVirtualServiceDetailSchema, minus the redundant
`["service"]["guestshell+"]` enclosing container.
"""
schema = {
'state': str,
'package_information': {
'name': str,
'path': str,
'application': {
'name': str,
'version': str,
'description': str,
},