-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconsole.tcl
76 lines (67 loc) · 2.44 KB
/
console.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
# Support for conserver i.e. "console - console server client program"
package provide 9pm::console 1.0
package require Expect
namespace eval ::9pm::console {
proc connect {node args} {
set PROMPT [::9pm::misc::dict::require $node prompt]
set CONSOLE [::9pm::misc::dict::require $node console]
set flags "-v"
if {[dict exist $::9pm::core::rc "console_opts"]} {
set flags [concat $flags [dict get $::9pm::core::rc "console_opts"]]
}
if {$args != ""} {
set flags [concat $flags $args]
}
set console_cmd "console $flags $CONSOLE"
::9pm::output::debug "Connecting console \"$CONSOLE\" (\"$console_cmd\")"
expect *
send "$console_cmd\n"
expect {
{Enter * for help} {
::9pm::output::debug "Started console \"$CONSOLE\""
}
timeout {
::9pm::fatal ::9pm::output::fail "Starting console \"$CONSOLE\" failed (timeout)"
}
eof {
::9pm::fatal ::9pm::output::fail "Starting console \"$CONSOLE\" failed (eof)"
}
}
expect {
-re {\[no, (.*) is attached\]} {
::9pm::output::warning "Read only console ($expect_out(1,string) attached)"
exp_continue
}
-re {\[bumped (.*)\]} {
::9pm::output::warning "Bumped $expect_out(1,string) from console $CONSOLE"
exp_continue
}
{\[\^R\]} {
::9pm::output::info "Connected to console \"$CONSOLE\""
}
timeout {
::9pm::fatal ::9pm::output::fail "Console connection \"$CONSOLE\" failed (timeout)"
}
eof {
::9pm::fatal ::9pm::output::fail "Console connection \"$CONSOLE\" failed (eof)"
}
}
}
proc disconnect {node} {
set CONSOLE [::9pm::misc::dict::require $node console]
send "\005"
send "c"
send "."
expect {
"Console $CONSOLE closed." {
::9pm::output::info "Disconnected from console \"$CONSOLE\""
}
timeout {
::9pm::fatal ::9pm::output::fail "Unable to disconnect console \"$CONSOLE\" (timeout)"
}
eof {
::9pm::fatal ::9pm::output::fail "Unable to disconnect console \"$CONSOLE\" (eof)"
}
}
}
}