Commit abc4cfbd authored by 135's avatar 135 Committed by Andrey Vertiprahov
Browse files

ConfDB Eltex.MES

+ dns resolver syntax
+ confdb tests
+ normalizer fixes (interface vlan, http server, igmp-snooping vlan, spannig tree and storm-control)
parent b931ee59
# ----------------------------------------------------------------------
# Eltex.MES config normalizer
# ----------------------------------------------------------------------
# Copyright (C) 2007-2019 The NOC Project
# Copyright (C) 2007-2020 The NOC Project
# See LICENSE for details
# ----------------------------------------------------------------------
# NOC modules
from noc.core.confdb.normalizer.base import BaseNormalizer, match, ANY, REST
from noc.core.text import ranges_to_list
from noc.core.confdb.syntax.patterns import IP_ADDRESS, INTEGER
class MESNormalizer(BaseNormalizer):
def normalize_interface_name(self, tokens):
if tokens[1] == "vlan":
return self.interface_name(tokens[1], tokens[2])
else:
return self.interface_name(tokens[1])
@match("hostname", ANY)
def normalize_hostname(self, tokens):
yield self.make_hostname(tokens[1])
@match("no", "ip", "http", "server")
@match("ip", "http", "server")
def normalize_http_server(self, tokens):
yield self.make_protocols_http()
......@@ -38,21 +45,27 @@ class MESNormalizer(BaseNormalizer):
self.set_context("spanning_tree_disabled", True)
yield self.make_global_spanning_tree_status(status=False)
@match("spanning-tree", "priority", INTEGER)
def normalize_spanning_tree_priority(self, tokens):
yield self.make_spanning_tree_priority(priority=tokens[-1])
@match("interface", ANY)
@match("interface", "vlan", ANY)
def normalize_interface(self, tokens):
if_name = self.interface_name(tokens[1])
yield self.make_interface(interface=if_name)
yield self.make_interface(interface=self.normalize_interface_name(tokens))
@match("interface", ANY, "shutdown")
@match("interface", "vlan", ANY, "shutdown")
def normalize_interface_shutdown(self, tokens):
yield self.make_interface_admin_status(
interface=self.interface_name(tokens[1], tokens[2]), admin_status="off"
interface=self.normalize_interface_name(tokens), admin_status="off"
)
@match("interface", ANY, "description", REST)
@match("interface", "vlan", ANY, "name", REST)
def normalize_interface_description(self, tokens):
yield self.make_interface_description(
interface=self.interface_name(tokens[1]), description=" ".join(tokens[2:])
interface=self.normalize_interface_name(tokens), description=" ".join(tokens[-2:])
)
@match("interface", ANY, "port", "security", "max", ANY)
......@@ -62,18 +75,24 @@ class MESNormalizer(BaseNormalizer):
)
@match("interface", ANY, "broadcast", "level", "kpbs", ANY)
@match("interface", ANY, "storm-control", "broadcast", "kbps", INTEGER)
@match("interface", ANY, "storm-control", "broadcast", "kbps", INTEGER, "shutdown")
def normalize_port_storm_control_broadcast(self, tokens):
yield self.make_interface_storm_control_broadcast_level(
interface=self.interface_name(tokens[1]), level=tokens[5]
)
@match("interface", ANY, "multicast", "level", "kpbs", ANY)
@match("interface", ANY, "storm-control", "multicast", "kbps", INTEGER)
@match("interface", ANY, "storm-control", "multicast", "kbps", INTEGER, "shutdown")
def normalize_port_storm_control_multicast(self, tokens):
yield self.make_interface_storm_control_multicast_level(
interface=self.interface_name(tokens[1]), level=tokens[5]
)
@match("interface", ANY, "unknown-unicast", "level", "kpbs", ANY)
@match("interface", ANY, "storm-control", "unknown-unicast", "kbps", INTEGER)
@match("interface", ANY, "storm-control", "unknown-unicast", "kbps", INTEGER, "shutdown")
def normalize_port_storm_control_unicast(self, tokens):
yield self.make_interface_storm_control_unicast_level(
interface=self.interface_name(tokens[1]), level=tokens[5]
......@@ -97,6 +116,12 @@ class MESNormalizer(BaseNormalizer):
interface=self.interface_name(tokens[1]), enabled=True
)
@match("interface", ANY, "spanning-tree", "portfast")
def normalize_interface_stp_mode(self, tokens):
yield self.make_spanning_tree_interface_mode(
interface=self.interface_name(tokens[1]), mode="portfast"
)
@match("interface", ANY, "no", "lldp", ANY)
def normalize_interface_lldp_admin_status(self, tokens):
if not self.get_context("lldp_disabled"):
......@@ -138,15 +163,15 @@ class MESNormalizer(BaseNormalizer):
interface=if_name, unit=if_name, vlan_filter=tokens[5]
)
# @match("ip", "igmp", "vlan", ANY)
# def normalize_igmp_snoopiing_vlan(self, tokens):
# yield self.
@match("ip", "igmp", "snooping", "vlan", ANY)
def normalize_igmp_snoopiing_vlan(self, tokens):
yield self.make_igmp_snooping_multicast_router(vlan=tokens[-1])
@match("interface", ANY, "ip", "address", ANY, ANY)
@match("interface", "vlan", ANY, "ip", "address", ANY, ANY)
def normalize_vlan_ip(self, tokens):
if_name = self.interface_name(tokens[1])
if_name = self.interface_name(tokens[1], tokens[2])
yield self.make_unit_inet_address(
interface=if_name, unit=if_name, address=self.to_prefix(tokens[4], tokens[5])
interface=if_name, unit=if_name, address=self.to_prefix(tokens[-2], tokens[-1])
)
@match("ip", "default-gateway", ANY)
......@@ -255,3 +280,11 @@ class MESNormalizer(BaseNormalizer):
@match("sntp", "server", ANY, ANY, ANY, ANY)
def normalize_ntp_server(self, tokens):
yield self.make_ntp_server_address(name=tokens[2], address=tokens[2])
@match("ip", "name-server", IP_ADDRESS)
def normalize_dns_name_server(self, tokens):
yield self.make_protocols_dns_name_server(ip=tokens[-1])
@match("ip", "domain", "name", ANY)
def normalize_dns_name_server_search_suffix(self, tokens):
yield self.make_protocols_dns_search_suffix(suffix=tokens[-1])
config: |
!
ip default-gateway 192.168.0.1
!
result:
- ['virtual-router', 'default', 'forwarding-instance', 'default', 'route', 'inet', 'static', '0.0.0.0/0', 'next-hop', '192.168.0.1']
config: |
!
ip domain name company.ru
ip name-server 192.168.0.1
!
result:
- ['protocols', 'dns', 'search', 'company.ru']
- ['protocols', 'dns', 'name-server', '192.168.0.1']
config: |
!
hostname host-name
!
result:
- ['system', 'hostname', 'host-name', {'replace': True}]
config: |
spanning-tree priority 8192
!
result:
- ['protocols', 'spanning-tree', 'priority', 8192, {'replace': True}]
config: |
no spanning-tree
!
result:
- ['hints', 'protocols', 'spanning-tree', 'status', False, {'replace': True}]
config: |
!
ip ssh server
!
result:
- ['virtual-router', 'default', 'forwarding-instance', 'default', 'protocols', 'ssh']
config: |
!
username admin password encrypted DESishelmebegelme= privilege 15
!
result:
- ['system', 'user', 'admin', 'authentication', 'encrypted-password', 'D E S i s h e l m e b e g e l m e =', {'replace': True}]
- ['system', 'user', 'admin', 'class', 'level-15']
config: |
!
vlan database
vlan 2,5,101-106
vlan 2250-2255,2586-2588
exit
!
result:
- ['virtual-router', 'default', 'forwarding-instance', 'default', 'vlans', 2]
- ['virtual-router', 'default', 'forwarding-instance', 'default', 'vlans', 5]
- ['virtual-router', 'default', 'forwarding-instance', 'default', 'vlans', 101]
- ['virtual-router', 'default', 'forwarding-instance', 'default', 'vlans', 102]
- ['virtual-router', 'default', 'forwarding-instance', 'default', 'vlans', 103]
- ['virtual-router', 'default', 'forwarding-instance', 'default', 'vlans', 104]
- ['virtual-router', 'default', 'forwarding-instance', 'default', 'vlans', 105]
- ['virtual-router', 'default', 'forwarding-instance', 'default', 'vlans', 106]
- ['virtual-router', 'default', 'forwarding-instance', 'default', 'vlans', 2250]
- ['virtual-router', 'default', 'forwarding-instance', 'default', 'vlans', 2251]
- ['virtual-router', 'default', 'forwarding-instance', 'default', 'vlans', 2252]
- ['virtual-router', 'default', 'forwarding-instance', 'default', 'vlans', 2253]
- ['virtual-router', 'default', 'forwarding-instance', 'default', 'vlans', 2254]
- ['virtual-router', 'default', 'forwarding-instance', 'default', 'vlans', 2255]
- ['virtual-router', 'default', 'forwarding-instance', 'default', 'vlans', 2586]
- ['virtual-router', 'default', 'forwarding-instance', 'default', 'vlans', 2587]
- ['virtual-router', 'default', 'forwarding-instance', 'default', 'vlans', 2588]
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment