Skip to content

Commit 308388f

Browse files
authored
Merge pull request #796 from cherifimehdi/master
Add IOS Parser "show vlan internal usage"
2 parents 1e2e381 + 3c70e59 commit 308388f

File tree

6 files changed

+89
-4
lines changed

6 files changed

+89
-4
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
--------------------------------------------------------------------------------
2+
New
3+
--------------------------------------------------------------------------------
4+
* IOS
5+
* Added ShowVlanInternalUsage:
6+
* show vlan internal usage

src/genie/libs/parser/ios/show_vlan.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@
66
ShowVlanMtu as ShowVlanMtu_iosxe,\
77
ShowVlanAccessMap as ShowVlanAccessMap_iosxe,\
88
ShowVlanRemoteSpan as ShowVlanRemoteSpan_iosxe,\
9-
ShowVlanFilter as ShowVlanFilter_iosxe
9+
ShowVlanFilter as ShowVlanFilter_iosxe,\
10+
ShowVlanInternalUsage as ShowVlanInternalUsage_iosxe
1011

1112

1213
class ShowVlan(ShowVlan_iosxe):
1314
pass
1415

1516
class ShowVlanMtu(ShowVlanMtu_iosxe):
16-
pass
17+
pass
1718

1819

1920
class ShowVlanAccessMap(ShowVlanAccessMap_iosxe):
@@ -24,4 +25,7 @@ class ShowVlanRemoteSpan(ShowVlanRemoteSpan_iosxe):
2425
pass
2526

2627
class ShowVlanFilter(ShowVlanFilter_iosxe):
27-
pass
28+
pass
29+
30+
class ShowVlanInternalUsage(ShowVlanInternalUsage_iosxe):
31+
pass

src/genie/libs/parser/iosxe/show_vlan.py

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1212,4 +1212,61 @@ def cli(self, output=None):
12121212
vlan['vlan_port'] = dict_val['vlan_port']
12131213
continue
12141214

1215-
return ret_dict
1215+
return ret_dict
1216+
1217+
# =================================================
1218+
# Parser for 'show vlan internal usage' command
1219+
#Author: Mehdi Cherifi
1220+
#Twitter: https://twitter.com/LocketKeepsake
1221+
#Github: https://github.com/cherifimehdi
1222+
# =================================================
1223+
1224+
class ShowVlanInternalUsageSchema(MetaParser):
1225+
"""Schema for: show vlan internal usage"""
1226+
1227+
schema = {
1228+
'internal_vlan': {
1229+
Any(): {
1230+
'usage': str,
1231+
},
1232+
}
1233+
}
1234+
1235+
class ShowVlanInternalUsage(ShowVlanInternalUsageSchema):
1236+
"""Parser for: show vlan internal usage"""
1237+
1238+
cli_command = 'show vlan internal usage'
1239+
1240+
def cli(self, output=None):
1241+
1242+
if output is None:
1243+
1244+
out = self.device.execute(self.cli_command)
1245+
1246+
else:
1247+
1248+
out = output
1249+
1250+
1251+
#VLAN Usage
1252+
#---- --------------------
1253+
#1006 GigabitEthernet0/0
1254+
#1007 GigabitEthernet0/1
1255+
#1008 GigabitEthernet0/2
1256+
1257+
#pattern to capture 'VLAN' and 'Usage'
1258+
p0 = re.compile(r'^(?P<VLAN>[0-9]+)\s+(?P<Usage>.+)$')
1259+
parsed_dict = {}
1260+
1261+
for line in out.splitlines():
1262+
line = line.strip()
1263+
1264+
m = p0.match(line)
1265+
if m:
1266+
internal_vlan_dict = parsed_dict.setdefault('internal_vlan', {})
1267+
usage = m.groupdict()['Usage']
1268+
vlan = m.groupdict()['VLAN']
1269+
internal_vlan_dict[vlan] = {}
1270+
internal_vlan_dict[vlan]['usage'] = usage
1271+
continue
1272+
return parsed_dict

src/genie/libs/parser/iosxe/tests/ShowVlanInternalUsage/cli/empty/empty_output_output.txt

Whitespace-only changes.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
expected_output = {
2+
"internal_vlan":{
3+
"1006":{
4+
"usage":"GigabitEthernet0/0"
5+
},
6+
"1007":{
7+
"usage":"GigabitEthernet0/1"
8+
},
9+
"1008":{
10+
"usage":"GigabitEthernet0/2"
11+
}
12+
}
13+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
VLAN Usage
2+
---- --------------------
3+
1006 GigabitEthernet0/0
4+
1007 GigabitEthernet0/1
5+
1008 GigabitEthernet0/2

0 commit comments

Comments
 (0)