Added scripts from lgcore
[debian6500.git] / simple-cdd / additional_scripts / configure_switch_bootstrap.tcl
diff --git a/simple-cdd/additional_scripts/configure_switch_bootstrap.tcl b/simple-cdd/additional_scripts/configure_switch_bootstrap.tcl
new file mode 100755 (executable)
index 0000000..873b674
--- /dev/null
@@ -0,0 +1,47 @@
+#!/usr/bin/expect
+
+set host [lrange $argv 0 0]
+if { $host == "" } {
+    puts "usage: configure_switch_bootstrap.tcl \[swg1|swg2|swm\]"
+    exit 1
+}
+
+set ipaddress ""
+if { $host == "swg1" } { set ipaddress "10.133.26.231" }
+if { $host == "swg2" } { set ipaddress "10.133.26.232" }
+if { $host == "swm" } { set ipaddress "10.133.28.231" }
+if { $ipaddress == "" } { puts "unknown switch '$host'""; exit 1 }
+
+spawn screen -c . /dev/ttyUSB0
+
+set timeout 5
+
+set state 0
+while { $state != 1 } {
+    expect {
+        timeout { send "\r" }
+        -exact ">" { send "enable\r" }
+        "#" { set state 1 }
+        "Password:" { send "thales\r" }
+        eof { send_user "connection to host failed\n"; exit 1 }
+    }
+}
+
+send "configure terminal\r"
+expect "#" { send "interface vlan 1\r" }
+expect "#" { send "ip address $ipaddress 255.255.255.0\r" }
+expect "#" { send "exit\r" }
+expect "#" { send "line vty 0 4\r" }
+expect "#" { send "password thales\r" }
+expect "#" { send "enable password thales\r" }
+expect "#" { send "end\r" }
+
+# quit switch connection
+expect "#" { send "exit\r" }
+
+# to quit screen we need to send C-a \.
+send "\001\\"
+expect "kill all your windows" { send "y\r" }
+
+exit 0
+# vim:set tabstop=4 expandtab shiftwidth=4: