Commit 449b1291 authored by Andrey Vertiprahov's avatar Andrey Vertiprahov
Browse files

Add ConfDB normalizer to Cisco.IOS profile.

parent 44b6f467
# -*- coding: utf-8 -*-
# ----------------------------------------------------------------------
# DefaultCDPStatusApplicator
# ----------------------------------------------------------------------
# Copyright (C) 2007-2019 The NOC Project
# See LICENSE for details
# ----------------------------------------------------------------------
# Python modules
from __future__ import absolute_import
# NOC modules
from .query import QueryApplicator
class DefaultCDPStatusApplicator(QueryApplicator):
"""
Apply non-disabled CDP interfaces
"""
CHECK_QUERY = "Match('hints', 'protocols', 'cdp', 'status')"
QUERY = [
# CDP is globally enabled
"Match('hints', 'protocols', 'cdp', 'status', 'on') and "
# Get all physical interfaces and bind to variable X
"Match('interfaces', X, 'type', 'physical') and "
# Only admin-status up interfaces
"Match('interfaces', X, 'admin-status', 'on') and "
# Filter out explicitly disabled interfaces
"NotMatch('hints', 'protocols', 'cdp', 'interface', X, 'off') and "
# For each interface with cdp admin status is not set
"NotMatch('protocols', 'cdp', 'interface', X) and "
# Set stp admin-status to rx and tx
"Fact('protocols', 'cdp', 'interface', X)"
]
# -*- coding: utf-8 -*-
# ----------------------------------------------------------------------
# ConfDB hints protocols cdp syntax
# ----------------------------------------------------------------------
# Copyright (C) 2007-2019 The NOC Project
# See LICENSE for details
# ----------------------------------------------------------------------
# Python modules
from __future__ import absolute_import
# NOC modules
from ...defs import DEF
from ...patterns import BOOL, IF_NAME
HINTS_PROTOCOLS_CDP = DEF(
"cdp",
[
DEF("status", [DEF(BOOL, name="status", required=True, gen="make_global_cdp_status")]),
DEF(
"interface",
[
DEF(
IF_NAME,
[DEF("off", gen="make_cdp_interface_disable")],
multi=True,
name="interface",
)
],
),
],
)
......@@ -12,9 +12,10 @@ from __future__ import absolute_import
# NOC modules
from ..defs import DEF
from .lldp.hints import HINTS_PROTOCOLS_LLDP
from .cdp.hints import HINTS_PROTOCOLS_CDP
from .spanningtree.hints import HINTS_PROTOCOLS_SPANNING_TREE
from .loopdetect.hints import HINTS_PROTOCOLS_LOOP_DETECT
PROTOCOLS_HINTS_SYNTAX = DEF(
"protocols", [HINTS_PROTOCOLS_LLDP, HINTS_PROTOCOLS_SPANNING_TREE, HINTS_PROTOCOLS_LOOP_DETECT]
"protocols", [HINTS_PROTOCOLS_LLDP, HINTS_PROTOCOLS_CDP, HINTS_PROTOCOLS_SPANNING_TREE, HINTS_PROTOCOLS_LOOP_DETECT]
)
......@@ -243,6 +243,7 @@ class BaseProfile(six.with_metaclass(BaseProfileMetaclass, object)):
"noc.core.confdb.applicator.loopdetectstatus.DefaultLoopDetectStatusApplicator",
"noc.core.confdb.applicator.stpstatus.DefaultSTPStatusApplicator",
"noc.core.confdb.applicator.stppriority.DefaultSTPPriorityApplicator",
"noc.core.confdb.applicator.cdpstatus.DefaultCDPStatusApplicator",
"noc.core.confdb.applicator.ntp.DefaultNTPModeApplicator",
"noc.core.confdb.applicator.ntp.DefaultNTPVersionApplicator",
# Finally apply meta
......
# -*- coding: utf-8 -*-
# ----------------------------------------------------------------------
# Cisco.IOS config normalizer
# ----------------------------------------------------------------------
# Copyright (C) 2007-2019 The NOC Project
# See LICENSE for details
# ----------------------------------------------------------------------
# NOC modules
from noc.core.confdb.normalizer.base import BaseNormalizer, match, ANY, REST
class CiscoIOSNormalizer(BaseNormalizer):
@match("hostname", REST)
def normalize_hostname(self, tokens):
yield self.make_hostname(" ".join(tokens[1:]))
@match("no", "ip", "http", "server")
def normalize_http_server(self, tokens):
yield self.make_protocols_http()
@match("no", "ip", "http", "secure-server")
def normalize_https_server(self, tokens):
yield self.make_protocols_https()
@match("clock", "timezone", ANY, ANY)
def normalize_timezone(self, tokens):
yield self.make_tz_offset(tz_name=tokens[2], tz_offset=tokens[3])
@match("snmp-server", "community", ANY, ANY, ANY)
def normalize_snmp_protocol(self, tokens):
yield self.make_snmp_community_level(
community=tokens[2], level={"RO": "read-only", "RW": "read-write"}[tokens[3]])
@match("vlan", ANY)
def normalize_vlan(self, tokens):
yield self.make_vlan_id(vlan_id=tokens[1])
@match("vlan", ANY, "name", REST)
def normalize_vlan_name(self, tokens):
yield self.make_vlan_name(vlan_id=tokens[1], name=" ".join(tokens[3:]))
@match("interface", ANY)
def normalize_interface_name(self, tokens):
if "." in tokens[1]:
ifname, unit = tokens[1].split(".")
yield self.make_unit_description(
interface=self.interface_name(ifname),
unit=self.interface_name(tokens[1]),
description="")
else:
yield self.make_interface(interface=self.interface_name(tokens[1]))
@match("interface", ANY, "shutdown")
def normalize_interface_status(self, tokens):
yield self.make_interface_admin_status(interface=self.interface_name(tokens[1]), admin_status=False)
@match("interface", ANY, "mtu", ANY)
def normalize_interface_mtu(self, tokens):
yield self.make_interface_mtu(interface=self.interface_name(tokens[1]), mtu=tokens[3])
@match("interface", ANY, "description", REST)
def normalize_interface_description(self, tokens):
if "." in tokens[1]:
ifname, unit = tokens[1].split(".")
yield self.make_unit_description(
interface=self.interface_name(ifname),
unit=self.interface_name(tokens[1]),
description=" ".join(tokens[3:]))
else:
yield self.make_interface_description(
interface=self.interface_name(tokens[1]),
description=" ".join(tokens[3:]))
@match("interface", ANY, "speed", ANY)
def normalize_interface_speed(self, tokens):
yield self.make_interface_speed(interface=self.interface_name(tokens[1]), speed=tokens[3])
@match("interface", ANY, "duplex", ANY)
def normalize_interface_duplex(self, tokens):
yield self.make_interface_duplex(interface=self.interface_name(tokens[1]), duplex=tokens[3])
@match("interface", ANY, "storm-control", "broadcast", "level", ANY)
@match("interface", ANY, "storm-control", "broadcast", "level", ANY, ANY)
@match("interface", ANY, "storm-control", "broadcast", "level", "bps", ANY, ANY)
@match("interface", ANY, "storm-control", "broadcast", "level", "pps", ANY, ANY)
def normalize_interface_storm_control_broadcast_pps(self, tokens):
level = tokens[5]
if tokens[5] in {"bps", "pps"}:
level = tokens[6]
yield self.make_interface_storm_control_broadcast_level(
interface=self.interface_name(tokens[1]), level=level
)
@match("interface", ANY, "storm-control", "multicast", "level", ANY)
@match("interface", ANY, "storm-control", "multicast", "level", ANY, ANY)
@match("interface", ANY, "storm-control", "multicast", "level", "bps", ANY, ANY)
@match("interface", ANY, "storm-control", "multicast", "level", "pps", ANY, ANY)
def normalize_interface_storm_control_multicast_pps(self, tokens):
level = tokens[5]
if tokens[5] in {"bps", "pps"}:
level = tokens[6]
yield self.make_interface_storm_control_multicast_level(
interface=self.interface_name(tokens[1]), level=level
)
@match("interface", ANY, "storm-control", "unicast", "level", ANY)
@match("interface", ANY, "storm-control", "unicast", "level", ANY, ANY)
@match("interface", ANY, "storm-control", "unicast", "level", "bps", ANY, ANY)
@match("interface", ANY, "storm-control", "unicast", "level", "pps", ANY, ANY)
def normalize_interface_storm_control_unicast_pps(self, tokens):
level = tokens[5]
if tokens[5] in {"bps", "pps"}:
level = tokens[6]
yield self.make_interface_storm_control_unicast_level(
interface=self.interface_name(tokens[1]), level=level
)
@match("interface", ANY, "switchport", "access", "vlan", ANY)
def normalize_switchport_untagged(self, tokens):
if_name = self.interface_name(tokens[1])
yield self.make_switchport_untagged(interface=if_name, unit=if_name, vlan_filter=tokens[5])
@match("interface", ANY, "switchport", "trunk", "allowed", "vlan", REST)
def normalize_switchport_tagged(self, tokens):
if_name = self.interface_name(tokens[1])
yield self.make_switchport_tagged(
interface=if_name,
unit=if_name,
vlan_filter=tokens[6],
)
@match("interface", ANY, "ip", "address", ANY, ANY)
def normalize_interface_ip(self, tokens):
ifname = tokens[1]
if "." in ifname:
ifname, unit = tokens[1].split(".")
yield self.make_unit_inet_address(
interface=self.interface_name(ifname),
unit=self.interface_name(tokens[1]),
address=self.to_prefix(tokens[4], tokens[5]))
@match("ip", "vrf", ANY, "rd", ANY)
def normalize_routing_instances_rd(self, tokens):
yield self.make_forwarding_instance_rd(instance=tokens[2], rd=tokens[4])
@match("ip", "vrf", ANY, "route-target", "export", ANY)
def normalize_routing_instances_rt_export(self, tokens):
yield self.make_forwarding_instance_export_target(instance=tokens[2], target=tokens[5])
@match("ip", "vrf", ANY, "route-target", "import", ANY)
def normalize_routing_instances_rt_import(self, tokens):
yield self.make_forwarding_instance_import_target(instance=tokens[2], target=tokens[5])
@match("ip", "vrf", ANY, "description", REST)
def normalize_routing_instances_description(self, tokens):
yield self.make_forwarding_instance_description(
instance=tokens[2], description=" ".join(tokens[3:])
)
@match("spanning-tree", "mode", ANY)
def normalize_spanning_tree_mode(self, tokens):
yield self.make_spanning_tree_mode(mode=tokens[2])
@match("interface", ANY, "spanning-tree", "portfast", ANY)
def normalize_spanning_tree_interface_mode(self, tokens):
yield self.make_spanning_tree_interface_mode(
interface=self.interface_name(tokens[1]), mode="portfast")
@match("interface", ANY, "spanning-tree", "bpdufilter", "enable")
def normalize_spanning_tree_bpdufilter(self, tokens):
yield self.make_spanning_tree_interface_bpdu_filter(
interface=self.interface_name(tokens[1]), enabled=True)
@match("interface", ANY, "spanning-tree", "bpduguard", "enable")
def normalize_spanning_tree_bpduguard(self, tokens):
yield self.make_spanning_tree_interface_bpdu_guard(
interface=self.interface_name(tokens[1]), enabled=True)
@match("interface", ANY, "no", "cdp", "enable")
def normalize_cdp_interface_disable(self, tokens):
yield self.make_cdp_interface_disable(
interface=self.interface_name(tokens[1]))
......@@ -43,6 +43,15 @@ class Profile(BaseProfile):
)
config_tokenizer = "indent"
config_tokenizer_settings = {"line_comment": "!"}
config_normalizer = "CiscoIOSNormalizer"
confdb_defaults = [
("hints", "interfaces", "defaults", "admin-status", True),
("hints", "protocols", "lldp", "status", False),
("hints", "protocols", "cdp", "status", True),
("hints", "protocols", "ntp", "mode", "server"),
("hints", "protocols", "ntp", "version", "3"),
# ("hints", "protocols", "loop-detect", "status", False),
]
default_parser = "noc.cm.parsers.Cisco.IOS.base.BaseIOSParser"
rx_ver = re.compile(r"(\d+)\.(\d+)[\(.](\d+)[\).]\S*")
......
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