Display configuration sections while configuring the router
From CT3
These EEM Tcl policies help you display the configuration of currently selected interface or routing protocol. After installing them and configuring the appropriate aliases, you’ll be able to use the config command to display parts of the router configuration while configuring an interface or a routing protocol.
Contents |
Installation
- Store the source files into the router’s flash or disk0.It’s recommended you create a subdirectory in which you store EEM Tcl policies.
- Configure the EEM Tcl policies (assuming the source files have been stored in flash:/tcl):
event manager directory user policy "flash:/tcl" event manager policy cliconfig.tcl type user event manager policy cliparser.tcl type user
- Configure the configuration mode aliases:
alias router config do event manager run cliconfig.tcl alias interface config do event manager run cliconfig.tcl
Usage guidelines
Use the config command in interface or router configuration mode.
Sample usage scenario
c7200(config)#interface fa 0/1 c7200(config-if)#config Building configuration... Current configuration : 94 bytes ! interface FastEthernet0/1 ip address 10.17.0.1 255.255.255.0 duplex auto speed auto end c7200(config-if)#router bgp 65000 c7200(config-router)#config router bgp 65000 no synchronization bgp log-neighbor-changes network 1.0.0.1 mask 255.255.255.255 no auto-summary
Author
Boštjan Šuštar, © 2008 NIL Data Communications
Source code
cliparser.tcl
::cisco::eem::event_register_cli sync yes occurs 1 pattern "^interface (.*)$|^router (.*)$"
namespace import ::cisco::eem::*
namespace import ::cisco::lib::*
array set evtData [event_reqinfo]
set _cli_msg $evtData(msg)
#
# INTERFACE CONFIGURATION COMMAND
# remember interface which is being configured
#
if { [ regexp -nocase {^interface (\S+)} $_cli_msg ignore intf] } {
appl_reqinfo key "cmd"
appl_setinfo key "cmd" data "show running interface $intf"
exit 1
}
#
# ROUTER CONFIGURATION COMMAND
# remember routing protocol being configured
#
if { [ regexp -nocase {^router (.*)$} $_cli_msg ignore rtr] } {
appl_reqinfo key "cmd"
set rtr [string trim $rtr]
appl_setinfo key "cmd" data "show running | section router $rtr"
exit 1
}
cliconfig.tcl
::cisco::eem::event_register_none
namespace import ::cisco::eem::*
namespace import ::cisco::lib::*
set cmda [appl_reqinfo key "cmd"]
if { [ lindex $cmda 0 ] == "data" } {
set cmd [ lindex $cmda 1 ]
appl_setinfo key "cmd" data $cmd
}
if {[catch {cli_open} result]} {
puts stderr "%CLICONFIG-3-EXEC: CLI OPEN failed ($result)"
exit 0
}
array set cfd $result
if {[catch {cli_exec $cfd(fd) "enable"} result]} {
puts stderr "%CLICONFIG-3-EXEC: Cannot execute 'enable' command ($result)"
exit 0
}
if {[catch {cli_exec $cfd(fd) $cmd} result]} {
puts stderr "%CLICONFIG-3-EXEC: Cannot execute $cmd ($result)"
exit 0
}
puts $result
catch {cli_close $cfd(fd) $cfd(tty_id)}
exit 0
BlogMarks
del.icio.us
digg
Facebook
LinkedIn
Newsvine
reddit
Slashdot