Mesh and BGP
annet.meshBGP sessions and interfaces are defined by rules for pairs of devices. Annet applies a rule to neighbors whose names match its pattern.
registry = MeshRulesRegistry()
@registry.direct("spine{s}.example.com", "leaf{l}.example.com")
def spine_leaf(spine: DirectPeer, leaf: DirectPeer, session: MeshSession):
spine.asnum = 65000
leaf.asnum = 65100 + leaf.match.l
spine.addr = f"10.{spine.match.s}.{leaf.match.l}.0/31"
leaf.addr = f"10.{spine.match.s}.{leaf.match.l}.1/31"
session.families = {"ipv4_unicast"}
session.bfd = True
session.import_policy = "fabric_in"
Routing policies
annet.rplDefine a routing policy once in RPL. Annet generates CLI configuration for Huawei, Arista, Cisco IOS XR, and Juniper; FRR on Cumulus uses a separate file generator.
routemap = RouteMap[NetboxDevice]()
@routemap
def fabric_in(device, route: Route):
with route(R.community.has("BLACKHOLE"), number=10, name="blackhole") as rule:
rule.deny()
with route(R.match_v4("LEAF_LOOPBACKS"), number=20, name="loopbacks") as rule:
rule.set_local_pref(200)
rule.community.add("FROM_LEAF")
rule.allow()
with route(R.as_path_length <= 3, number=30, name="short_path") as rule:
rule.set_metric(100)
rule.allow()
with route(number=100, name="deny_rest") as rule:
rule.deny()
Rulebooks
.rul · .order · .deployA rulebook defines how differences become commands, the order to send them in, and answers to device prompts such as Are you sure? [Y/N].
.rulHow to compare commands and undo them.
sysname
ntp unicast-server * # * — one argument in undo
ntp ~ # ~ — one or more
interface * %logic=annet.rulebook.huawei.iface.permanent
.orderWhich order to send commands in.
port split mode
interface */Vlanif\d+/
undo interface */Vlanif\d+/ %order_reverse
.deployHow to answer device prompts.
undo bgp
dialog: Warning: The BGP process will be deleted. Continue? [Y/N]: ::: Y
commit %timeout=180
Generators
Partial · Entire · JSONFragmentGenerators split configuration into manageable parts. An ACL defines the lines owned by PartialGenerator and the keys owned by JSONFragment. Entire generates a whole file without an ACL.
class Hostname(PartialGenerator):
TAGS = ["hostname"]
def acl_huawei(self, device):
return """
sysname
header
"""
def run_huawei(self, device):
yield "sysname", device.hostname
yield 'header login information "%s"' % device.hostname
The device type determines which generator describes its configuration.
PartialGenerator
BlackboxFor CLI devices that return their complete current configuration. A generator describes its part; Annet compares it with the current state and prepares commands.
Each vendor has its own method: run_huawei, run_arista, and so on.
CLI vendors and operating systems:
CiscoIOS / IOS-XECiscoNX-OSCiscoIOS XRJuniperJunOSHuaweiVRP 5 / VRP 8AristaEOSNokiaTiMOSMikroTikRouterOS
class Lldp(PartialGenerator):
def run_huawei(self, device):
yield "lldp enable"
def run_nexus(self, device):
yield "feature lldp"
yield "lldp timer 10"
Entire
WhiteboxThe generator builds the complete file contents, for example /etc/ntp.conf. Annet compares them with the file on the device. If they differ, Annet replaces the file and runs the reload command specified by the generator.
Examples of systems with file-based configuration:
FRRLinuxFreeBSDCumulus
class Ntp(Entire):
def path(self, device):
return "/etc/ntp.conf"
def reload(self, device):
return "systemctl restart ntp"
def run(self, device):
yield "server 0.ru.pool.ntp.org iburst"
JSONFragment
WhiteboxPart of a JSON or YAML file on disk. The generator owns specific keys; Annet patches only those keys and leaves the rest of the file intact.
Examples of systems with file-based configuration:
SONiC
class SonicNtp(JSONFragment):
def path(self, device):
return "/etc/sonic/config_db.json"
def acl(self, device):
return ["/NTP_SERVER"]
def reload(self, device):
return "sudo config load -y"
def run(self, device):
with self.block("NTP_SERVER"):
yield {"0.ru.pool.ntp.org": {}}