-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.tcl
executable file
·85 lines (74 loc) · 1.51 KB
/
cli.tcl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# ------------------------------------------------------------------------------
#
# EEM LIBRARY
#
# Author: Vladimir Akhmarov
# Date: April 2012
# Version: 1.0
#
# Requires: EEM 3.2
# License: Cisco-Style BSD
#
# Description:
# 1
#
# ------------------------------------------------------------------------------
namespace import ::cisco::eem::*
namespace import ::cisco::lib::*
#
# Open CLI session
#
proc ios_cli_open { } {
uplevel #0 {
if { [array exists cli] } {
return
}
if [catch {cli_open} result] {
error $result $errorInfo
} else {
array set cli $result
}
}
}
#
# Close CLI session
#
proc ios_cli_close {} {
if [catch {cli_close $cli(fd) $cli(tty_id)} result] {
error $result $errorInfo
}
}
#
# Exec CLI commands
#
proc ios_cli_exec { arr_cmd } {
if [catch {cli_open} result] {
error $result $errorInfo
} else {
array set cli $result
}
if [catch {cli_exec $cli(fd) "enable"} result] {
error $result $errorInfo
}
if [catch {cli_exec $cli(fd) "terminal length 0"} result] {
error $result $errorInfo
}
foreach cmd $arr_cmd {
if [catch {cli_exec $cli(fd) $cmd} result] {
error $result $errorInfo
} else {
set str [string length $cmd]
while { $str > 0 } {
incr str -1
append line =
}
lappend cmd_output $line $cmd $line
lappend cmd_output $result
}
}
if [catch {cli_close $cli(fd) $cli(tty_id)} result] {
error $result $errorInfo
}
return $cmd_output
}