fix base vlan pattern
This commit is contained in:
@@ -36,7 +36,7 @@ class BaseDevice(Protocol):
|
||||
|
||||
@property
|
||||
def vlan_parse_pattern(self):
|
||||
return rf"^vlan\s+(\d{{1,4}})\n(.*?)(?=^{self.anchor_pattern}|\Z)"
|
||||
return rf"^vlan\s+(\d{{1,4}})\r?\n(.*?)(?=^{self.anchor_pattern}|\Z)"
|
||||
|
||||
unamed_vlan_splitter: str = ','
|
||||
unamed_vlan_counter = '-'
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
from oxi.interface import Qtech
|
||||
|
||||
|
||||
class BDcom(Qtech):
|
||||
pass
|
||||
@@ -1,5 +0,0 @@
|
||||
from oxi.interface.base import BaseDevice
|
||||
|
||||
|
||||
class Mikrotik(BaseDevice):
|
||||
...
|
||||
@@ -1,23 +0,0 @@
|
||||
import re
|
||||
|
||||
from oxi.interface.base import BaseDevice
|
||||
|
||||
|
||||
class Qtech(BaseDevice):
|
||||
|
||||
def __init__(self, config):
|
||||
self.config: str = self._fix_config(config)
|
||||
|
||||
def _fix_config(self, config):
|
||||
pattern = r"Pending configurations.*"
|
||||
cleaned_text = re.sub(pattern, "", config, flags=re.DOTALL)
|
||||
return cleaned_text
|
||||
|
||||
|
||||
with open('../../core_switch.txt', 'r') as file:
|
||||
data = file.read()
|
||||
|
||||
result = Qtech(data).parse_config()
|
||||
print(result.vlans)
|
||||
print(result.l3interfaces)
|
||||
print(result.vlaninterfaces)
|
||||
@@ -1,39 +0,0 @@
|
||||
import re
|
||||
|
||||
from oxi.interface.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)
|
||||
Reference in New Issue
Block a user