42fb513f6d384edc7161eab9c142a02c3e76d0a7
[debian6500.git] / simple-cdd / additional_scripts / configure_switch_bootstrap.tcl
1 #!/usr/bin/expect
2
3 set host [lrange $argv 0 0]
4 if { $host == "" } {
5 puts "usage: configure_switch_bootstrap.tcl \[swg1|swg2|swm\]"
6 exit 1
7 }
8
9 set ipaddress ""
10 if { $host == "swg1" } { set ipaddress "10.133.26.231" }
11 if { $host == "swg2" } { set ipaddress "10.133.26.232" }
12 if { $host == "swm" } { set ipaddress "10.133.28.231" }
13 if { $host == "sw1" } { set ipaddress "10.133.26.231" }
14 if { $host == "sw2" } { set ipaddress "10.133.26.232" }
15 if { $ipaddress == "" } { puts "unknown switch '$host'""; exit 1 }
16
17 spawn screen -c . /dev/ttyUSB0
18
19 set timeout 5
20
21 set state 0
22 while { $state != 1 } {
23 expect {
24 timeout { send "\r" }
25 -exact ">" { send "enable\r" }
26 "#" { set state 1 }
27 "Password:" { send "thales\r" }
28 eof { send_user "connection to host failed\n"; exit 1 }
29 }
30 }
31
32 send "configure terminal\r"
33 expect "#" { send "interface vlan 1\r" }
34 expect "#" { send "ip address $ipaddress 255.255.255.0\r" }
35 expect "#" { send "exit\r" }
36 expect "#" { send "line vty 0 4\r" }
37 expect "#" { send "password thales\r" }
38 expect "#" { send "enable password thales\r" }
39 expect "#" { send "end\r" }
40
41 # quit switch connection
42 expect "#" { send "exit\r" }
43
44 # to quit screen we need to send C-a \.
45 send "\001\\"
46 expect "kill all your windows" { send "y\r" }
47
48 exit 0
49 # vim:set tabstop=4 expandtab shiftwidth=4: