Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
U
ulg
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
2
Issues
2
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
labs
ulg
Commits
4883ca7f
Commit
4883ca7f
authored
Apr 17, 2014
by
Tomas Hlavacek
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
https://github.com/tmshlvck/ulg
parents
0138cf10
f9c4bcd2
Changes
7
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
374 additions
and
210 deletions
+374
-210
index.html
templates/index.html
+48
-32
tests.py
tests.py
+3
-3
ulg.py
ulg.py
+16
-2
ulgbird.py
ulgbird.py
+113
-106
ulgcisco.py
ulgcisco.py
+129
-50
ulgjuniper.py
ulgjuniper.py
+23
-15
ulgmodel.py
ulgmodel.py
+42
-2
No files found.
templates/index.html
View file @
4883ca7f
...
...
@@ -20,53 +20,69 @@
var
rs
=
document
.
getElementById
(
"routerselect"
);
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
=
"cidx,cmd in enumerate(routers[ridx].listCommands())"
>
<!
[
CDATA
[
if
((
rs
.
options
[
rs
.
selectedIndex
].
value
==
$ridx
)
&&
(
cs
.
options
[
cs
.
selectedIndex
].
value
==
$cidx
))
{
]]
>
document
.
getElementById
(
"paramsect"
).
innerHTML
=
'
\
document
.
getElementById
(
"paramsect"
).
innerHTML
=
'
\
<py:for each="pidx,param in enumerate(routers[ridx].listCommands()[cidx].getParamSpecs())">
<fieldset>
\
<label for="param${pidx}">
\
${pidx+3}. ${param.getName()}:
\
</label>
\
<fieldset>
\
<label for="param${pidx}">
\
${pidx+3}. ${param.getName()}:
\
</label>
\
<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
'">
<select name="param${pidx}" id="param${pidx}">
\
<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]}">
\
${partuple[1]}
\
</option>
\
</py:otherwise>
</py:choose>
</py:for>
</select>
\
<select name="param${pidx}" id="param${pidx}">
\
<py:for each="paridx,partuple in enumerate(param.getOptions())">
<option value="${partuple[0]}">
\
${partuple[1]}
\
</option>
\
</py:for>
</select>
\
</py:when>
<py:otherwise>
<py:choose>
<py:when test="default_routerid == ridx and default_commandid == cidx and defined('
default_params
') and pidx < len(default_params)">
<input type="text" name="param${pidx}" id="param${pidx}" value="${default_params[pidx]}" onfocus="this.className=
\'
hover
\'
" onblur="this.className=
\'
out
\'
" />
\
<input type="text" name="param${pidx}" id="param${pidx}" value="${default_params[pidx]}" onfocus="this.className=
\'
hover
\'
" onblur="this.className=
\'
out
\'
" />
\
</py:when>
<py:otherwise>
<input type="text" name="param${pidx}" id="param${pidx}" value="${param.getDefault()}" onfocus="this.className=
\'
hover
\'
" onblur="this.className=
\'
out
\'
" />
\
<input type="text" name="param${pidx}" id="param${pidx}" value="${param.getDefault()}" onfocus="this.className=
\'
hover
\'
" onblur="this.className=
\'
out
\'
" />
\
</py:otherwise>
</py:choose>
</py:otherwise>
</py:choose>
</fieldset>
\
</fieldset>
\
</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
>
...
...
@@ -77,14 +93,14 @@
var
rs
=
document
.
getElementById
(
"routerselect"
);
<
py
:
for
each
=
"ridx,router in enumerate(routers)"
>
if
(
rs
.
options
[
rs
.
selectedIndex
].
value
==
$ridx
)
{
document
.
getElementById
(
"commandselect"
).
innerHTML
=
'
\
document
.
getElementById
(
"commandselect"
).
innerHTML
=
'
\
<py:for each="cidx,cmd in enumerate(routers[ridx].listCommands())">
<py:choose>
<py:when test="default_routerid == ridx and default_commandid == cidx">
<option value="$cidx" selected="selected">${cmd.getName()}</option>
\
<option value="$cidx" selected="selected">${cmd.getName()}</option>
\
</py:when>
<py:otherwise>
<option value="$cidx">${cmd.getName()}</option>
\
<option value="$cidx">${cmd.getName()}</option>
\
</py:otherwise>
</py:choose>
</py:for>'
;
...
...
tests.py
View file @
4883ca7f
...
...
@@ -38,8 +38,8 @@ config = ulgmodel.import_config()
def
testRouterCommand
(
router
=
0
,
command
=
0
,
params
=
[]):
r
=
config
.
routers
[
router
]
try
:
if
(
not
r
.
run
Command
(
r
.
listCommands
()[
command
],
params
,
ulg
.
DecoratorHelper
()
)):
print
"WARN: Outp
i
t of test running command "
+
str
(
command
)
+
" on router "
+
str
(
router
)
+
" with parameters:"
+
str
(
params
)
+
" is empty."
if
(
not
r
.
run
SyncCommand
(
r
.
listCommands
()[
command
],
params
)):
print
"WARN: Outp
u
t of test running command "
+
str
(
command
)
+
" on router "
+
str
(
router
)
+
" with parameters:"
+
str
(
params
)
+
" is empty."
return
False
except
Exception
as
e
:
...
...
@@ -143,7 +143,7 @@ def testULGLock():
def
testULGRunParameter
(
router
=
0
,
command
=
4
,
params
=
[
'91.210.16.1'
]):
r
=
config
.
routers
[
router
]
try
:
if
(
not
r
.
run
Command
(
r
.
listCommands
()[
command
],
params
,
ulg
.
DecoratorHelper
()
)):
if
(
not
r
.
run
SyncCommand
(
r
.
listCommands
()[
command
],
params
)):
print
"WARN: Output of test running command "
+
str
(
command
)
+
" on router "
+
str
(
router
)
+
" with parameters:"
+
str
(
params
)
+
" is empty."
return
False
...
...
ulg.py
View file @
4883ca7f
...
...
@@ -28,7 +28,7 @@ import re
import
fcntl
import
traceback
import
urllib
import
md5
import
hashlib
import
time
import
random
...
...
@@ -90,7 +90,7 @@ class Session(object):
self
.
save
()
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
):
try
:
...
...
@@ -462,6 +462,16 @@ class ULGCgi:
else
:
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
):
return
"""<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
...
...
@@ -531,6 +541,7 @@ class ULGCgi:
return
template
.
generate
(
defaults
=
defaults
,
routers
=
config
.
routers
,
commonparams
=
self
.
getCommonParams
(),
default_routerid
=
routerid
,
default_commandid
=
commandid
,
default_sessionid
=
sessionid
,
...
...
@@ -617,6 +628,7 @@ class ULGCgi:
template
=
self
.
loader
.
load
(
defaults
.
index_template_file
)
return
template
.
generate
(
defaults
=
defaults
,
routers
=
config
.
routers
,
commonparams
=
self
.
getCommonParams
(),
default_routerid
=
session
.
getRouterId
(),
default_commandid
=
session
.
getCommandId
(),
default_params
=
session
.
getParameters
(),
...
...
@@ -639,6 +651,7 @@ class ULGCgi:
return
template
.
generate
(
defaults
=
defaults
,
routers
=
config
.
routers
,
commonparams
=
self
.
getCommonParams
(),
default_routerid
=
0
,
default_commandid
=
0
,
default_sessionid
=
None
,
...
...
@@ -657,6 +670,7 @@ class ULGCgi:
return
template
.
generate
(
defaults
=
defaults
,
routers
=
config
.
routers
,
commonparams
=
self
.
getCommonParams
(),
default_routerid
=
0
,
default_commandid
=
0
,
default_sessionid
=
None
,
...
...
ulgbird.py
View file @
4883ca7f
This diff is collapsed.
Click to expand it.
ulgcisco.py
View file @
4883ca7f
This diff is collapsed.
Click to expand it.
ulgjuniper.py
View file @
4883ca7f
...
...
@@ -22,6 +22,7 @@ import os
import
socket
import
re
import
pexpect
import
hashlib
import
defaults
...
...
@@ -120,26 +121,20 @@ def juniper_reduce_paths(paths):
class
JuniperShowBgpNeigh
(
ulgmodel
.
TextCommand
):
COMMAND_TEXT
=
'show bgp neighbor
%
s'
def
__init__
(
self
,
peers
,
name
=
None
):
peer_param
=
ulgmodel
.
SelectionParameter
([
tuple
((
p
,
p
,))
for
p
in
peers
],
name
=
defaults
.
STRING_IPADDRESS
)
ulgmodel
.
TextCommand
.
__init__
(
self
,
self
.
COMMAND_TEXT
,
param_specs
=
[
peer_param
],
name
=
name
)
def
__init__
(
self
,
router
,
name
=
None
):
ulgmodel
.
TextCommand
.
__init__
(
self
,
self
.
COMMAND_TEXT
,
param_specs
=
[
router
.
getBGPPeerSelect
()],
name
=
name
)
class
JuniperShowRouteBgpAdv
(
ulgmodel
.
TextCommand
):
COMMAND_TEXT
=
'show route advertising-protocol bgp
%
s'
def
__init__
(
self
,
peers
,
name
=
None
):
peer_param
=
ulgmodel
.
SelectionParameter
([
tuple
((
p
,
p
,))
for
p
in
peers
],
name
=
defaults
.
STRING_IPADDRESS
)
ulgmodel
.
TextCommand
.
__init__
(
self
,
self
.
COMMAND_TEXT
,
param_specs
=
[
peer_param
],
name
=
name
)
def
__init__
(
self
,
router
,
name
=
None
):
ulgmodel
.
TextCommand
.
__init__
(
self
,
self
.
COMMAND_TEXT
,
param_specs
=
[
router
.
getBGPPeerSelect
()],
name
=
name
)
class
JuniperShowRouteBgpRecv
(
ulgmodel
.
TextCommand
):
COMMAND_TEXT
=
'show route receive-protocol bgp
%
s'
def
__init__
(
self
,
peers
,
name
=
None
):
peer_param
=
ulgmodel
.
SelectionParameter
([
tuple
((
p
,
p
,))
for
p
in
peers
],
name
=
defaults
.
STRING_IPADDRESS
)
ulgmodel
.
TextCommand
.
__init__
(
self
,
self
.
COMMAND_TEXT
,
param_specs
=
[
peer_param
],
name
=
name
)
def
__init__
(
self
,
router
,
name
=
None
):
ulgmodel
.
TextCommand
.
__init__
(
self
,
self
.
COMMAND_TEXT
,
param_specs
=
[
router
.
getBGPPeerSelect
()],
name
=
name
)
class
JuniperShowRoute
(
ulgmodel
.
TextCommand
):
COMMAND_TEXT
=
'show route
%
s'
...
...
@@ -193,6 +188,7 @@ class JuniperRouter(ulgmodel.RemoteRouter):
def
__init__
(
self
,
host
,
user
,
password
=
''
,
port
=
22
,
commands
=
None
,
asn
=
'My ASN'
,
name
=
None
):
ulgmodel
.
RemoteRouter
.
__init__
(
self
)
self
.
bgp_peer_select
=
None
self
.
setHost
(
host
)
self
.
setUser
(
user
)
self
.
setPassword
(
password
)
...
...
@@ -222,9 +218,9 @@ class JuniperRouter(ulgmodel.RemoteRouter):
return
[
ulgmodel
.
TextCommand
(
'show version'
),
ulgmodel
.
TextCommand
(
'show bgp summary'
),
JuniperShowRoute
(),
JuniperShowBgpNeigh
(
self
.
getBGPPeers
()
),
JuniperShowRouteBgpRecv
(
self
.
getBGPPeers
()
),
JuniperShowRouteBgpAdv
(
self
.
getBGPPeers
()
),
JuniperShowBgpNeigh
(
self
),
JuniperShowRouteBgpRecv
(
self
),
JuniperShowRouteBgpAdv
(
self
),
JuniperGraphShowRoute
(),
]
...
...
@@ -238,6 +234,18 @@ class JuniperRouter(ulgmodel.RemoteRouter):
def
getBGPPeers
(
self
):
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
):
key_bgp
=
self
.
getHost
()
+
self
.
getName
()
+
self
.
PS_KEY_BGP
...
...
ulgmodel.py
View file @
4883ca7f
...
...
@@ -169,6 +169,7 @@ class TextParameter(object):
raise
Exception
(
"Invalid input encountered: Check did not passed."
)
class
AddressParameter
(
TextParameter
):
""" Abstract base class """
def
__init__
(
self
,
pattern
=
None
,
name
=
defaults
.
STRING_IPADDRESS
,
default
=
''
):
TextParameter
.
__init__
(
self
,
pattern
,
name
,
default
)
...
...
@@ -231,6 +232,31 @@ class IPv6AddressParameter(AddressParameter):
AddressParameter
.
__init__
(
self
,
IPV6_ADDRESS_REGEXP
,
name
,
default
)
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
):
def
__init__
(
self
,
option_tuples
=
[],
name
=
defaults
.
STRING_PARAMETER
,
default
=
None
):
...
...
@@ -275,6 +301,20 @@ class SelectionParameter(TextParameter):
else
:
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
):
def
__init__
(
self
,
command
,
param_specs
=
[],
name
=
None
):
...
...
@@ -396,8 +436,8 @@ class Router(object):
c
.
rescanHook
(
self
)
def
returnError
(
self
,
error
=
None
):
r
=
'<em>'
+
defaults
.
STRING_ERROR_COMMANDRUN
r
=
r
+
': '
+
error
+
'</em>'
if
error
else
r
+
'.</em>'
r
=
defaults
.
STRING_ERROR_COMMANDRUN
r
=
r
+
': '
+
error
if
error
else
r
return
r
def
__prepareCommand
(
self
,
command
,
parameters
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment