This commit is contained in:
ilya
2025-06-17 15:47:44 +03:00
commit d5428044d1
7 changed files with 210 additions and 0 deletions

39
oxi/models/vrp.py Normal file
View File

@@ -0,0 +1,39 @@
import re
from oxi.models.base import BaseDevice, Vlan
class Vrp(BaseDevice):
anchor_pattern: str = '#'
hostname_pattern = 'sysname'
unamed_vlan_splitter = ' '
unamed_vlan_counter = 'to'
def _parse_unamed_vlans(self) -> list[Vlan]:
vlans = []
pattern = self.unamed_vlans_parse_pattern
for match in re.finditer(pattern, self.config, re.MULTILINE):
tokens = match.group(1).split(self.unamed_vlan_splitter)
i = 0
while i < len(tokens):
if i + 2 < len(tokens) and tokens[i + 1].lower() == 'to':
start = int(tokens[i])
end = int(tokens[i + 2])
for vlan_id in range(start, end + 1):
vlans.append(Vlan(vlan=str(vlan_id), name=None, description=None))
i += 3 # пропустить X, 'to', Y
else:
vlans.append(Vlan(vlan=str(tokens[i]), name=None, description=None))
i += 1
return vlans
with open('../../vrp_switch.txt', 'r') as file:
data = file.read()
result = Vrp(data).parse_config()
print(result.vlans)
print(result.l3interfaces)
print(result.vlaninterfaces)