Commit 5cdd91c8 authored by Tomas Hlavacek's avatar Tomas Hlavacek

Refactor BIRD router to reuse code.

Prepare for BIRD remote router via SSH by refactoring current class
BirdLocalRouter class and pull out common stuff to a new BirdRouter
abstract class.

Add (now empty) BirdRemoteRouter class.
parent 726d99d1
......@@ -356,14 +356,29 @@ class BirdGraphShowRouteAll(ulgmodel.TextCommand):
def showRange(self):
return False
class BirdRouterLocal(ulgmodel.LocalRouter):
class BirdRouter(ulgmodel.Router):
RESCAN_PEERS_COMMAND = 'show protocols'
RESCAN_TABLES_COMMAND = 'show symbols'
DEFAULT_PROTOCOL_FLTR = '^(Kernel|Device|Static|BGP).*$'
def _getDefaultCommands(self):
sh_proto_all = BirdShowProtocolsAllCommand(self.getBGPPeers())
sh_proto_route = BirdShowRouteProtocolCommand(self.getBGPPeers(),self.getRoutingTables())
sh_proto_export = BirdShowRouteExportCommand(self.getBGPPeers())
return [BirdShowProtocolsCommand(show_proto_all_command=sh_proto_all, proto_filter = self.proto_fltr),
BirdShowRouteCommand(self.getRoutingTables()),
sh_proto_all,
sh_proto_route,
sh_proto_export,
BirdShowRouteAllCommand(self.getRoutingTables()),
BirdGraphShowRouteAll(self.getRoutingTables()),
ulgmodel.TextCommand('show status'),
ulgmodel.TextCommand('show memory')
]
class BirdRouterLocal(ulgmodel.LocalRouter,BirdRouter):
def __init__(self,sock=defaults.default_bird_sock,commands=None,proto_fltr=None,asn='My ASN'):
super(self.__class__,self).__init__()
ulgmodel.LocalRouter.__init__(self)
self.sock = sock
self.setName('localhost')
self.setASN(asn)
......@@ -378,20 +393,6 @@ class BirdRouterLocal(ulgmodel.LocalRouter):
else:
self.setCommands(self._getDefaultCommands())
def _getDefaultCommands(self):
sh_proto_all = BirdShowProtocolsAllCommand(self.getBGPPeers())
sh_proto_route = BirdShowRouteProtocolCommand(self.getBGPPeers(),self.getRoutingTables())
sh_proto_export = BirdShowRouteExportCommand(self.getBGPPeers())
return [BirdShowProtocolsCommand(show_proto_all_command=sh_proto_all, proto_filter = self.proto_fltr),
BirdShowRouteCommand(self.getRoutingTables()),
sh_proto_all,
sh_proto_route,
sh_proto_export,
BirdShowRouteAllCommand(self.getRoutingTables()),
BirdGraphShowRouteAll(self.getRoutingTables()),
ulgmodel.TextCommand('show status'),
ulgmodel.TextCommand('show memory')
]
def runRawCommand(self,command,outfile):
def parseBirdSockLine(line):
......@@ -508,3 +509,8 @@ class BirdRouterLocal(ulgmodel.LocalRouter):
def getRoutingTables(self):
return self.rescanRoutingTables()
class BirdRouterRemote(ulgmodel.RemoteRouter,BirdRouter):
pass
Markdown is supported
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