Commit 4883ca7f authored by Tomas Hlavacek's avatar Tomas Hlavacek

Merge branch 'master' of https://github.com/tmshlvck/ulg

parents 0138cf10 f9c4bcd2
...@@ -20,6 +20,14 @@ ...@@ -20,6 +20,14 @@
var rs=document.getElementById("routerselect"); var rs=document.getElementById("routerselect");
var cs=document.getElementById("commandselect"); var cs=document.getElementById("commandselect");
<py:for each="cp in commonparams.keys()">
var commondict_${cp} = ' \
<py:for each="paridx,partuple in enumerate(commonparams[cp].getOptions())">
<option value="${partuple[0]}"> ${partuple[1]} </option> \
</py:for>
';
</py:for>
<py:for each="ridx,router in enumerate(routers)"> <py:for each="ridx,router in enumerate(routers)">
<py:for each="cidx,cmd in enumerate(routers[ridx].listCommands())"> <py:for each="cidx,cmd in enumerate(routers[ridx].listCommands())">
<![CDATA[ if((rs.options[rs.selectedIndex].value==$ridx) && (cs.options[cs.selectedIndex].value==$cidx)) { ]]> <![CDATA[ if((rs.options[rs.selectedIndex].value==$ridx) && (cs.options[cs.selectedIndex].value==$cidx)) { ]]>
...@@ -31,26 +39,17 @@ ...@@ -31,26 +39,17 @@
${pidx+3}. ${param.getName()}: \ ${pidx+3}. ${param.getName()}: \
</label> \ </label> \
<py:choose> <py:choose>
<py:when test="param.getType() == 'commonselect'">
<select name="param${pidx}" id="param${pidx}"> \
' + commondict_${param.getID()} + ' \
</select> \
</py:when>
<py:when test="param.getType() == 'select'"> <py:when test="param.getType() == 'select'">
<select name="param${pidx}" id="param${pidx}"> \ <select name="param${pidx}" id="param${pidx}"> \
<py:for each="paridx,partuple in enumerate(param.getOptions())"> <py:for each="paridx,partuple in enumerate(param.getOptions())">
<py:choose>
<py:when test="default_routerid == ridx and default_commandid == cidx and defined('default_params') and partuple[0] == default_params[pidx]">
<option value="${partuple[0]}" selected="selected"> \
${partuple[1]} \
</option> \
</py:when>
<py:when test="partuple[0] == param.getDefault()">
<option value="${partuple[0]}" selected="selected"> \
${partuple[1]} \
</option> \
</py:when>
<py:otherwise>
<option value="${partuple[0]}"> \ <option value="${partuple[0]}"> \
${partuple[1]} \ ${partuple[1]} \
</option> \ </option> \
</py:otherwise>
</py:choose>
</py:for> </py:for>
</select> \ </select> \
</py:when> </py:when>
...@@ -67,6 +66,23 @@ ...@@ -67,6 +66,23 @@
</py:choose> </py:choose>
</fieldset> \ </fieldset> \
</py:for>'; </py:for>';
<py:for each="pidx,param in enumerate(routers[ridx].listCommands()[cidx].getParamSpecs())">
<py:choose>
<py:when test="(param.getType() == 'select') or (param.getType() == 'commonselect')">
<py:for each="paridx,partuple in enumerate(param.getOptions())">
<py:choose>
<py:when test="default_routerid == ridx and default_commandid == cidx and defined('default_params') and partuple[0] == default_params[pidx]">
document.getElementById("param${pidx}").selectedIndex=${paridx};
</py:when>
<py:when test="partuple[0] == param.getDefault()">
document.getElementById("param${pidx}").selectedIndex=${paridx};
</py:when>
</py:choose>
</py:for>
</py:when>
</py:choose>
</py:for>
} }
</py:for> </py:for>
</py:for> </py:for>
......
...@@ -38,8 +38,8 @@ config = ulgmodel.import_config() ...@@ -38,8 +38,8 @@ config = ulgmodel.import_config()
def testRouterCommand(router=0,command=0,params=[]): def testRouterCommand(router=0,command=0,params=[]):
r = config.routers[router] r = config.routers[router]
try: try:
if(not r.runCommand(r.listCommands()[command],params,ulg.DecoratorHelper())): if(not r.runSyncCommand(r.listCommands()[command],params)):
print "WARN: Outpit of test running command "+str(command)+" on router "+str(router)+" with parameters:"+str(params)+" is empty." print "WARN: Output of test running command "+str(command)+" on router "+str(router)+" with parameters:"+str(params)+" is empty."
return False return False
except Exception as e: except Exception as e:
...@@ -143,7 +143,7 @@ def testULGLock(): ...@@ -143,7 +143,7 @@ def testULGLock():
def testULGRunParameter(router=0,command=4,params=['91.210.16.1']): def testULGRunParameter(router=0,command=4,params=['91.210.16.1']):
r = config.routers[router] r = config.routers[router]
try: try:
if(not r.runCommand(r.listCommands()[command],params,ulg.DecoratorHelper())): if(not r.runSyncCommand(r.listCommands()[command],params)):
print "WARN: Output of test running command "+str(command)+" on router "+str(router)+" with parameters:"+str(params)+" is empty." print "WARN: Output of test running command "+str(command)+" on router "+str(router)+" with parameters:"+str(params)+" is empty."
return False return False
......
...@@ -28,7 +28,7 @@ import re ...@@ -28,7 +28,7 @@ import re
import fcntl import fcntl
import traceback import traceback
import urllib import urllib
import md5 import hashlib
import time import time
import random import random
...@@ -90,7 +90,7 @@ class Session(object): ...@@ -90,7 +90,7 @@ class Session(object):
self.save() self.save()
def __genSessionId__(self): def __genSessionId__(self):
return md5.new(str(time.time())+str(random.randint(1,1000000))).hexdigest() return hashlib.md5(str(time.time())+str(random.randint(1,1000000))).hexdigest()
def save(self): def save(self):
try: try:
...@@ -462,6 +462,16 @@ class ULGCgi: ...@@ -462,6 +462,16 @@ class ULGCgi:
else: else:
return defaults.refresh_interval return defaults.refresh_interval
def getCommonParams(self):
res = {}
for r in config.routers:
for c in r.listCommands():
for ps in c.getParamSpecs():
if(ps.getType() == 'commonselect'):
res[ps.getID()] = ps
return res
def HTTPRedirect(self,url): def HTTPRedirect(self,url):
return """<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> return """<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html> <html>
...@@ -531,6 +541,7 @@ class ULGCgi: ...@@ -531,6 +541,7 @@ class ULGCgi:
return template.generate(defaults=defaults, return template.generate(defaults=defaults,
routers=config.routers, routers=config.routers,
commonparams=self.getCommonParams(),
default_routerid=routerid, default_routerid=routerid,
default_commandid=commandid, default_commandid=commandid,
default_sessionid=sessionid, default_sessionid=sessionid,
...@@ -617,6 +628,7 @@ class ULGCgi: ...@@ -617,6 +628,7 @@ class ULGCgi:
template = self.loader.load(defaults.index_template_file) template = self.loader.load(defaults.index_template_file)
return template.generate(defaults=defaults, return template.generate(defaults=defaults,
routers=config.routers, routers=config.routers,
commonparams=self.getCommonParams(),
default_routerid=session.getRouterId(), default_routerid=session.getRouterId(),
default_commandid=session.getCommandId(), default_commandid=session.getCommandId(),
default_params=session.getParameters(), default_params=session.getParameters(),
...@@ -639,6 +651,7 @@ class ULGCgi: ...@@ -639,6 +651,7 @@ class ULGCgi:
return template.generate(defaults=defaults, return template.generate(defaults=defaults,
routers=config.routers, routers=config.routers,
commonparams=self.getCommonParams(),
default_routerid=0, default_routerid=0,
default_commandid=0, default_commandid=0,
default_sessionid=None, default_sessionid=None,
...@@ -657,6 +670,7 @@ class ULGCgi: ...@@ -657,6 +670,7 @@ class ULGCgi:
return template.generate(defaults=defaults, return template.generate(defaults=defaults,
routers=config.routers, routers=config.routers,
commonparams=self.getCommonParams(),
default_routerid=0, default_routerid=0,
default_commandid=0, default_commandid=0,
default_sessionid=None, default_sessionid=None,
......
This diff is collapsed.
This diff is collapsed.
...@@ -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
......
...@@ -169,6 +169,7 @@ class TextParameter(object): ...@@ -169,6 +169,7 @@ class TextParameter(object):
raise Exception("Invalid input encountered: Check did not passed.") raise Exception("Invalid input encountered: Check did not passed.")
class AddressParameter(TextParameter): class AddressParameter(TextParameter):
""" Abstract base class """
def __init__(self,pattern=None,name=defaults.STRING_IPADDRESS,default=''): def __init__(self,pattern=None,name=defaults.STRING_IPADDRESS,default=''):
TextParameter.__init__(self,pattern,name,default) TextParameter.__init__(self,pattern,name,default)
...@@ -231,6 +232,31 @@ class IPv6AddressParameter(AddressParameter): ...@@ -231,6 +232,31 @@ class IPv6AddressParameter(AddressParameter):
AddressParameter.__init__(self,IPV6_ADDRESS_REGEXP,name,default) AddressParameter.__init__(self,IPV6_ADDRESS_REGEXP,name,default)
self.addrfam=socket.AF_INET6 self.addrfam=socket.AF_INET6
class IPv64AddressParameter(IPv6AddressParameter):
def __init__(self,name=defaults.STRING_IPADDRESS,default=''):
IPv6AddressParameter.__init__(self,name,default)
self.ip6 = IPv6AddressParameter(name,default)
self.ip4 = IPv4AddressParameter(name,default)
def checkInput(self,input):
if(self.ip6.checkInput(input)):
return True
elif(self.ip4.checkInput(input)):
return True
else:
return False
def normalizeInput(self,input):
res1 = self.ip6.normalizeInput(input)
if(res1 != input):
return res1
res2 = self.ip4.normalizeInput(input)
if(res2 != input):
return res2
return input
class SelectionParameter(TextParameter): class SelectionParameter(TextParameter):
def __init__(self,option_tuples=[],name=defaults.STRING_PARAMETER,default=None): def __init__(self,option_tuples=[],name=defaults.STRING_PARAMETER,default=None):
...@@ -275,6 +301,20 @@ class SelectionParameter(TextParameter): ...@@ -275,6 +301,20 @@ class SelectionParameter(TextParameter):
else: else:
raise Exception("Invalid input encountered: Check did not passed.") raise Exception("Invalid input encountered: Check did not passed.")
class CommonSelectionParameter(SelectionParameter):
def __init__(self,oid,option_tuples=[],name=defaults.STRING_PARAMETER,default=None):
SelectionParameter.__init__(self,option_tuples,name,default)
self.setID(oid)
def getType(self):
return 'commonselect'
def setID(self,oid):
self.oid = oid
def getID(self):
return self.oid
class TextCommand(object): class TextCommand(object):
def __init__(self,command,param_specs=[],name=None): def __init__(self,command,param_specs=[],name=None):
...@@ -396,8 +436,8 @@ class Router(object): ...@@ -396,8 +436,8 @@ class Router(object):
c.rescanHook(self) c.rescanHook(self)
def returnError(self,error=None): def returnError(self,error=None):
r = '<em>'+defaults.STRING_ERROR_COMMANDRUN r = defaults.STRING_ERROR_COMMANDRUN
r = r + ': '+error+'</em>' if error else r+'.</em>' r = r + ': '+error if error else r
return r return r
def __prepareCommand(self,command,parameters): def __prepareCommand(self,command,parameters):
......
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