Commit e1c16caa authored by Tomas Hlavacek's avatar Tomas Hlavacek

Convert Juniper to use CommonSelectionParameter

Convert Juniper router handlers and commands to use CommonSelectionParameter
instead of SelectionParameter.
parent 05de1e14
...@@ -22,6 +22,7 @@ import os ...@@ -22,6 +22,7 @@ import os
import socket import socket
import re import re
import pexpect import pexpect
import hashlib
import defaults import defaults
...@@ -120,26 +121,20 @@ def juniper_reduce_paths(paths): ...@@ -120,26 +121,20 @@ def juniper_reduce_paths(paths):
class JuniperShowBgpNeigh(ulgmodel.TextCommand): class JuniperShowBgpNeigh(ulgmodel.TextCommand):
COMMAND_TEXT='show bgp neighbor %s' COMMAND_TEXT='show bgp neighbor %s'
def __init__(self,peers,name=None): def __init__(self,router,name=None):
peer_param = ulgmodel.SelectionParameter([tuple((p,p,)) for p in peers], ulgmodel.TextCommand.__init__(self,self.COMMAND_TEXT,param_specs=[router.getBGPPeerSelect()],name=name)
name=defaults.STRING_IPADDRESS)
ulgmodel.TextCommand.__init__(self,self.COMMAND_TEXT,param_specs=[peer_param],name=name)
class JuniperShowRouteBgpAdv(ulgmodel.TextCommand): class JuniperShowRouteBgpAdv(ulgmodel.TextCommand):
COMMAND_TEXT='show route advertising-protocol bgp %s' COMMAND_TEXT='show route advertising-protocol bgp %s'
def __init__(self,peers,name=None): def __init__(self,router,name=None):
peer_param = ulgmodel.SelectionParameter([tuple((p,p,)) for p in peers], ulgmodel.TextCommand.__init__(self,self.COMMAND_TEXT,param_specs=[router.getBGPPeerSelect()],name=name)
name=defaults.STRING_IPADDRESS)
ulgmodel.TextCommand.__init__(self,self.COMMAND_TEXT,param_specs=[peer_param],name=name)
class JuniperShowRouteBgpRecv(ulgmodel.TextCommand): class JuniperShowRouteBgpRecv(ulgmodel.TextCommand):
COMMAND_TEXT='show route receive-protocol bgp %s' COMMAND_TEXT='show route receive-protocol bgp %s'
def __init__(self,peers,name=None): def __init__(self,router,name=None):
peer_param = ulgmodel.SelectionParameter([tuple((p,p,)) for p in peers], ulgmodel.TextCommand.__init__(self,self.COMMAND_TEXT,param_specs=[router.getBGPPeerSelect()],name=name)
name=defaults.STRING_IPADDRESS)
ulgmodel.TextCommand.__init__(self,self.COMMAND_TEXT,param_specs=[peer_param],name=name)
class JuniperShowRoute(ulgmodel.TextCommand): class JuniperShowRoute(ulgmodel.TextCommand):
COMMAND_TEXT = 'show route %s' COMMAND_TEXT = 'show route %s'
...@@ -193,6 +188,7 @@ class JuniperRouter(ulgmodel.RemoteRouter): ...@@ -193,6 +188,7 @@ class JuniperRouter(ulgmodel.RemoteRouter):
def __init__(self,host,user,password='',port=22,commands=None,asn='My ASN',name=None): def __init__(self,host,user,password='',port=22,commands=None,asn='My ASN',name=None):
ulgmodel.RemoteRouter.__init__(self) ulgmodel.RemoteRouter.__init__(self)
self.bgp_peer_select = None
self.setHost(host) self.setHost(host)
self.setUser(user) self.setUser(user)
self.setPassword(password) self.setPassword(password)
...@@ -222,9 +218,9 @@ class JuniperRouter(ulgmodel.RemoteRouter): ...@@ -222,9 +218,9 @@ class JuniperRouter(ulgmodel.RemoteRouter):
return [ulgmodel.TextCommand('show version'), return [ulgmodel.TextCommand('show version'),
ulgmodel.TextCommand('show bgp summary'), ulgmodel.TextCommand('show bgp summary'),
JuniperShowRoute(), JuniperShowRoute(),
JuniperShowBgpNeigh(self.getBGPPeers()), JuniperShowBgpNeigh(self),
JuniperShowRouteBgpRecv(self.getBGPPeers()), JuniperShowRouteBgpRecv(self),
JuniperShowRouteBgpAdv(self.getBGPPeers()), JuniperShowRouteBgpAdv(self),
JuniperGraphShowRoute(), JuniperGraphShowRoute(),
] ]
...@@ -238,6 +234,18 @@ class JuniperRouter(ulgmodel.RemoteRouter): ...@@ -238,6 +234,18 @@ class JuniperRouter(ulgmodel.RemoteRouter):
def getBGPPeers(self): def getBGPPeers(self):
return self.bgp_peers return self.bgp_peers
def initBGPPeerSelect(self,peers):
rid = hashlib.md5(self.getName()).hexdigest()
self.bgp_peer_select = ulgmodel.CommonSelectionParameter(rid+"bgp",[tuple((p,p,)) for p in peers],
name=defaults.STRING_PEERID)
def getBGPPeerSelect(self):
if(not self.bgp_peer_select):
self.initBGPPeerSelect(self.getBGPPeers())
return self.bgp_peer_select
def savePersistentInfo(self): def savePersistentInfo(self):
key_bgp = self.getHost() + self.getName() + self.PS_KEY_BGP key_bgp = self.getHost() + self.getName() + self.PS_KEY_BGP
......
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