xentaur
changeset 0:ab37f0ad70e5
Initial revision
author | igor |
---|---|
date | Fri Jul 13 16:57:33 2007 +0300 (2007-07-13) |
parents | |
children | 50d24d4b810d e34dd9ee49e5 |
files | build-xenomips-image files/id_dsa files/id_dsa.pub files/xenomips-init files/xenomips.sh shapes/all/bridge.png shapes/all/quagga.png shapes/all/router.png shapes/all/switch.png shapes/all/xenomips.png shapes/all/zebralogo.jpg xenomips_vars.py xentaur.py |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/build-xenomips-image Fri Jul 13 16:57:33 2007 +0300 1.3 @@ -0,0 +1,123 @@ 1.4 +#!/bin/sh 1.5 + 1.6 +DYNAMIPS_BUILD=yes 1.7 +XENOMIPS_FS_BUILD=yes 1.8 +CONFIG_FS_BUILD=no 1.9 +IOS_FS_BUILD=yes 1.10 + 1.11 +#Xenomips FS 1.12 +XENOMIPS_FS_SIZE=2048k # size in 1k blocks 1.13 +XENOMIPS_FS_NAME=xenomips1.img 1.14 + 1.15 +# Config FS 1.16 +CONFIG_FS_SIZE=100k 1.17 +CONFIG_FS_NAME=xenomips-config1.img 1.18 + 1.19 +# IOS FS 1.20 +IOS_FS_SIZE=2048k 1.21 +IOS_FS_NAME=xenomips-ios1.img 1.22 + 1.23 + 1.24 +XENOMIPS_DIR="files/" 1.25 + 1.26 + 1.27 +DEBIAN_MIRROR=http://debian.org.ua/debian 1.28 +DISTRO=sid 1.29 +PACKAGES="openssh-server libc6-xen libelf1 libpcap0.8 screen nfs-common quagga" 1.30 +DYNAMIPS_SOURCES=http://www.ipflow.utc.fr/dynamips/dynamips-0.2.7.tar.gz 1.31 +DYNAMIPS_BUILD_DIR=dynamips/ 1.32 +KERNEL_VERSION=`uname -r` 1.33 +SSH_OPEN_KEY=files/id_dsa.pub 1.34 + 1.35 +IOS_DIR="ios/" 1.36 + 1.37 +WORK_DIR=${XENOMIPS_FS_NAME%%.img} 1.38 + 1.39 +build_and_install_dynamips() 1.40 +{ 1.41 + OLD_PWD="`pwd`" 1.42 + DESTDIR=`pwd`/${WORK_DIR} 1.43 + 1.44 + if echo $DYNAMIPS_BUILD | grep -qi ^y 1.45 + then 1.46 + rm -rf ${DYNAMIPS_BUILD_DIR}/ 1.47 + mkdir -p ${DYNAMIPS_BUILD_DIR}/ 1.48 + cd ${DYNAMIPS_BUILD_DIR}/ 1.49 + wget $DYNAMIPS_SOURCES 1.50 + tar xfz dynamips*tar* 1.51 + cd dynamips*/ 1.52 + perl -p -i -e s@^PCAP_LIB=.*@PCAP_LIB=-lpcap@ Makefile 1.53 + make 1.54 + else 1.55 + cd ${DYNAMIPS_BUILD_DIR}/dynamips*/ 1.56 + fi 1.57 + make install DESTDIR=${DESTDIR} 1.58 + cd ${OLD_PWD} 1.59 +} 1.60 + 1.61 + 1.62 +dd if=/dev/zero of=${XENOMIPS_FS_NAME} count=${XENOMIPS_FS_SIZE} bs=1024 1.63 +mkfs.ext3 -F ${XENOMIPS_FS_NAME} 1.64 +mkdir -p ${WORK_DIR} 1.65 +mount -o loop ${XENOMIPS_FS_NAME} ${WORK_DIR} 1.66 +debootstrap ${DISTRO} ${WORK_DIR} ${DEBIAN_MIRROR} 1.67 +cat <<SCRIPT | chroot ${WORK_DIR} sh -s 1.68 +unset LANG 1.69 +apt-get -y --force-yes install ${PACKAGES} 1.70 +/etc/init.d/ssh stop 1.71 +cat <<FSTAB > /etc/fstab 1.72 +/dev/hda1 / ext3 ro 0 0 1.73 +/dev/hda2 /xenomips/ios ext3 ro 0 0 1.74 +/dev/hda3 /xenomips/config ext3 rw 0 0 1.75 +FSTAB 1.76 +mkdir -p /data/Cisco_IOS /xenomips 1.77 + 1.78 +cat <<'INTERFACES' > /etc/network/interfaces 1.79 +auto lo eth0 1.80 + 1.81 +iface lo inet loopback 1.82 + up for i in \`ifconfig -a | grep 'eth.*Link encap' | awk '{print \$1}'\`; do ifconfig \$i up ; done || true 1.83 + 1.84 +iface eth0 inet dhcp 1.85 +INTERFACES 1.86 + 1.87 +echo /usr/local/bin/xenomips.sh > /etc/rc.local 1.88 +cd /etc/rcS.d; ln -s ../init.d/xenomips-init S35xenomips-init 1.89 +rm /etc/rc2.d/S*quagga 1.90 + 1.91 +perl -i -p -e s@C_PATH=/etc/quagga@C_PATH=/xenomips/etc/quagga@ /etc/init.d/quagga 1.92 + 1.93 +mkdir -p /xenomips/{ios,config,dynamips,etc/quagga} /var/lib/xenomips /root/.ssh 1.94 + 1.95 +screen -ls | grep -q Attached && screen -x || screen -ls | grep -q Detached && screen -r 1.96 +SCRIPT 1.97 + 1.98 +cp -R /lib/modules/${KERNEL_VERSION} ${WORK_DIR}/lib/modules 1.99 + 1.100 +cp ${XENOMIPS_DIR}/xenomips-init ${WORK_DIR}/etc/init.d/ 1.101 +cp ${XENOMIPS_DIR}/xenomips.sh ${WORK_DIR}/usr/local/bin 1.102 +sudo chmod +x ${WORK_DIR}/usr/local/bin/xenomips.sh ${WORK_DIR}/etc/init.d/xenomips-init 1.103 + 1.104 +cat ${SSH_OPEN_KEY} > ${WORK_DIR}/root/.ssh/authorized_keys 1.105 +chmod 600 ${WORK_DIR}/root/.ssh/authorized_keys 1.106 + 1.107 +build_and_install_dynamips 1.108 + 1.109 +umount ${WORK_DIR} 1.110 + 1.111 +if echo $CONFIG_FS_BUILD | grep -qi ^y 1.112 +then 1.113 + dd if=/dev/zero of=${CONFIG_FS_NAME} bs=1k count=${CONFIG_FS_SIZE} 1.114 + mkfs.ext3 -F ${CONFIG_FS_NAME} 1.115 +fi 1.116 + 1.117 + 1.118 +if echo $IOS_FS_BUILD | grep -qi ^y 1.119 +then 1.120 + dd if=/dev/zero of=${IOS_FS_NAME} bs=1k count=${CONFIG_FS_SIZE} 1.121 + mkfs.ext3 -F ${IOS_FS_NAME} 1.122 + mount -o loop ${IOS_FS_NAME} ${WORK_DIR} 1.123 + cp ${IOS_DIR}/* ${WORK_DIR} 1.124 + umount ${WORK_DIR} 1.125 +fi 1.126 +
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/files/id_dsa Fri Jul 13 16:57:33 2007 +0300 2.3 @@ -0,0 +1,12 @@ 2.4 +-----BEGIN DSA PRIVATE KEY----- 2.5 +MIIBvAIBAAKBgQC1BnqCB3rBr6sGdTbd7sgab+mfLxULlyS7G/lKkQcc6B3WnpdT 2.6 +j/puo/p3DVsXYQJYgPJlpxtZ462xpPuzfVc3zYlwdu6iC1kqhHq8i4EkKv3+5OAq 2.7 +A/5m+haOH4JOcLu8751JsWXn3QqnLpwxuPyJrA9g9MQzVkvwAlUxjplVPwIVAKLf 2.8 +ClG5F1P7VSbZz9r7emQx1MurAoGAX65WRoG4lG/4RC/RbbqHV8Cgjw7iJeX6alLK 2.9 +VL7sTpPUZj0GsAjqvO9VEK5o7No/OA40uFuCFJg7v5ZkeEzT4RP9RpoVsX7OUm9k 2.10 +Y/frldeDVmmFqQeWQ3s7JjjQzFuemojpOWfIcUvWeXPoaksY+c8D8Mjr6pKQPzhQ 2.11 +JzgzqPACgYEApwMEoYQac3kj1XUvCreyXZYhBAS3JbS+K6U7zg+jWd2Bt5mKkTbf 2.12 +ALkdMAm9i7lheRg4LBgxsezDJkF9qrTybOJIFwYJ3v1H+UOGjQo9XVCcHbuYuQAB 2.13 +mzMg25o3nK0AqAl9jZepx0FLiqkY/zOAMOV+u9mBFFent0XKUqfLKCoCFQCG/KmB 2.14 +2CCWLMk9OzbSHlpN5QpFqw== 2.15 +-----END DSA PRIVATE KEY-----
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/files/id_dsa.pub Fri Jul 13 16:57:33 2007 +0300 3.3 @@ -0,0 +1,1 @@ 3.4 +ssh-dss AAAAB3NzaC1kc3MAAACBALUGeoIHesGvqwZ1Nt3uyBpv6Z8vFQuXJLsb+UqRBxzoHdael1OP+m6j+ncNWxdhAliA8mWnG1njrbGk+7N9VzfNiXB27qILWSqEeryLgSQq/f7k4CoD/mb6Fo4fgk5wu7zvnUmxZefdCqcunDG4/ImsD2D0xDNWS/ACVTGOmVU/AAAAFQCi3wpRuRdT+1Um2c/a+3pkMdTLqwAAAIBfrlZGgbiUb/hEL9FtuodXwKCPDuIl5fpqUspUvuxOk9RmPQawCOq871UQrmjs2j84DjS4W4IUmDu/lmR4TNPhE/1GmhWxfs5Sb2Rj9+uV14NWaYWpB5ZDezsmONDMW56aiOk5Z8hxS9Z5c+hqSxj5zwPwyOvqkpA/OFAnODOo8AAAAIEApwMEoYQac3kj1XUvCreyXZYhBAS3JbS+K6U7zg+jWd2Bt5mKkTbfALkdMAm9i7lheRg4LBgxsezDJkF9qrTybOJIFwYJ3v1H+UOGjQo9XVCcHbuYuQABmzMg25o3nK0AqAl9jZepx0FLiqkY/zOAMOV+u9mBFFent0XKUqfLKCo= igor@cholpon
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 4.2 +++ b/files/xenomips-init Fri Jul 13 16:57:33 2007 +0300 4.3 @@ -0,0 +1,47 @@ 4.4 +#!/bin/sh 4.5 + 4.6 +bind_mounts () { 4.7 + # set defaults 4.8 + test -z "$tmpfs_dir" && tmpfs_dir=/var/lib/xenomips 4.9 + test -z "$rw_dirs" \ 4.10 + && rw_dirs="/var/cache/man /var/lock /var/run /var/log /var/spool /var/tmp /tmp /var/lib/urandom /var/lib/dhcp3 /tmp" 4.11 + test -z "$copy_dirs" && copy_dirs="" 4.12 + test -z "$temp_copy_dirs" && temp_copy_dirs="/var/cache/debconf" 4.13 + test -z "$bindfiles" && bindfiles="" 4.14 + mount -t tmpfs -o mode=0755 tmpfs $tmpfs_dir 4.15 + # preserve directory structure 4.16 + for d in $rw_dirs ; do 4.17 + if [ -d "$d" ]; then 4.18 + cd $tmpfs_dir 4.19 + tar --no-recursion -cpf - $(find $d -type d 2> /dev/null) 2> /dev/null | tar xpf - 4.20 + mount --bind $tmpfs_dir/$d $d 4.21 + else 4.22 + echo "WARNING: $d does not exist" 4.23 + fi 4.24 + done 4.25 + # copy contents into tmpfs 4.26 + for d in $copy_dirs $temp_copy_dirs; do 4.27 + if [ -d "$d" ]; then 4.28 + cd $tmpfs_dir 4.29 + tar -cpf - $d 2> /dev/null | tar xpf - 4.30 + mount --bind $tmpfs_dir/$d $d 4.31 + else 4.32 + echo "WARNING: $d does not exist" 4.33 + fi 4.34 + done 4.35 + # mount one file on top of another 4.36 + for f in $bindfiles ; do 4.37 + if [ -e "$f" ]; then 4.38 + mkdir -p "$(dirname $tmpfs_dir/$f)" 4.39 + cp $f $tmpfs_dir/$f 4.40 + mount --bind $tmpfs_dir/$f $f 4.41 + else 4.42 + echo "WARNING: $f does not exist" 4.43 + fi 4.44 + done 4.45 + touch /var/log/dmesg 4.46 +} 4.47 + 4.48 + 4.49 +bind_mounts 4.50 +
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 5.2 +++ b/files/xenomips.sh Fri Jul 13 16:57:33 2007 +0300 5.3 @@ -0,0 +1,9 @@ 5.4 +#!/bin/sh 5.5 + 5.6 +DYNAMIPS_WORKDIR="/xenomips/config" 5.7 +DYNAMIPS_ARGS=`cat /proc/cmdline | sed 's/.*xenomips="//; s/".*//'` 5.8 + 5.9 + 5.10 +cd "$DYNAMIPS_WORKDIR" 5.11 +screen -e '^``' -d -m dynamips $DYNAMIPS_ARGS 5.12 +
6.1 Binary file shapes/all/bridge.png has changed
7.1 Binary file shapes/all/quagga.png has changed
8.1 Binary file shapes/all/router.png has changed
9.1 Binary file shapes/all/switch.png has changed
10.1 Binary file shapes/all/xenomips.png has changed
11.1 Binary file shapes/all/zebralogo.jpg has changed
12.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 12.2 +++ b/xenomips_vars.py Fri Jul 13 16:57:33 2007 +0300 12.3 @@ -0,0 +1,4 @@ 12.4 + 12.5 +N=1 12.6 + 12.7 +
13.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 13.2 +++ b/xentaur.py Fri Jul 13 16:57:33 2007 +0300 13.3 @@ -0,0 +1,211 @@ 13.4 +#!/usr/bin/python 13.5 + 13.6 + 13.7 +import sys 13.8 +import xenomips_vars 13.9 +xenomips_vars.N='1' 13.10 +sys.path.append('/etc/xen') 13.11 +from xenomipsN import vbridges_table, hidden_bridges, domains, broken_links, temporary_links, domain_types 13.12 +from IPython.Shell import IPShellEmbed 13.13 + 13.14 +def create_bridges_script(): 13.15 + unbound_bridges=bridges 13.16 + create_unbound_bridges="\n".join(map(lambda x: "brctl show | awk '{print $1}' | grep -q "+x+" || brctl addbr "+x, unbound_bridges)) 13.17 + create_unbound_bridges+="\n"+"\n".join(map(lambda x: "ip link set "+x+" up", unbound_bridges)) 13.18 + 13.19 + print """#!/bin/sh 13.20 +# create unbound bridges 13.21 +%(create_unbound_bridges)s 13.22 +""" % {'create_unbound_bridges' : create_unbound_bridges} 13.23 + 13.24 + 13.25 +def create_domains_script(): 13.26 + for N in range(len(domains)): 13.27 + print "xm create xenomipsN N="+str(N)+" && sleep 1 && xm sched-credit -d $(xm list | grep "+domains[N]+" | awk '{print $2}') -c 10 && sleep 1" 13.28 + 13.29 +def destroy_domains_script(): 13.30 + for N in range(len(domains)): 13.31 + print "xm shutdown "+domains[N] 13.32 + 13.33 +def create_screens_script(): 13.34 + 13.35 + N=0 13.36 + screens=[] 13.37 + for domain in domains: 13.38 + ip="192.168.80."+str(200+N) 13.39 + screens.append("screen -t "+domain+" "+str(N)+" sh -c 'while true; do ssh root@"+ip+" ; done'") 13.40 + N+=1 13.41 + screenlist="\n".join(screens) 13.42 + 13.43 + print """ 13.44 +cat <<SCREENRC > screenrc 13.45 +screen -t console 0 bash 13.46 +%(screenlist)s 13.47 +SCREENRC 13.48 +""" % { 'screenlist' : screenlist } 13.49 + 13.50 +def graph_node(node): 13.51 + i=0 13.52 + domain_type={} 13.53 + for domain in domains: 13.54 + domain_type[domain]=domain_types[i] 13.55 + i+=1 13.56 + return node+" [label=\" "+node+"\",shapefile=\"shapes/all/"+domain_type[node]+".png\",fontcolor=navy,fontsize=14]" 13.57 + 13.58 +def graph(): 13.59 + 13.60 + nodelist="" 13.61 + bridgelist="" 13.62 + linklist="" 13.63 + physicallist="" 13.64 + networklist="" 13.65 + 13.66 + nodelist=";\n ".join(map(graph_node,nodes)) 13.67 + if nodelist: nodelist += ";" 13.68 + 13.69 + bridgelist=";\n ".join(bridges-set(hidden_bridges)) 13.70 + if bridgelist: bridgelist += ";" 13.71 + 13.72 + links=[] 13.73 + for host, bridges_raw in vbridges_table.iteritems(): 13.74 + i=0 13.75 + for this_bridge in bridges_raw: 13.76 + if this_bridge in hidden_bridges: 13.77 + continue 13.78 + if [ host, this_bridge ] in broken_links: 13.79 + links.append(host+" -- "+this_bridge+" [taillabel=\"fa"+str(i)+"/0\",style=dashed]") 13.80 + else: 13.81 + links.append(host+" -- "+this_bridge+" [taillabel=\"fa"+str(i)+"/0\"]") 13.82 + i+=1 13.83 + 13.84 + for link in temporary_links: 13.85 + links.append(link[0]+" -- "+link[1]+" [color=blue,len=10,w=5,weight=5]") 13.86 + 13.87 + linklist=";\n ".join(links) 13.88 + 13.89 + graph_dot = { 13.90 + 'nodelist' : nodelist, 13.91 + 'bridgelist' : bridgelist, 13.92 + 'linklist' : linklist, 13.93 + 'physicallist' : physicallist, 13.94 + 'networklist' : networklist, 13.95 + } 13.96 + 13.97 + print """ 13.98 + cat <<'GRAPH' > xenomips.dot 13.99 +graph G { 13.100 + edge [len=1.25]; 13.101 + splines=true; 13.102 +// nodes 13.103 + 13.104 + node [shape=plaintext,color=white,shapefile="shapes/cisco.bmp/router.png"]; 13.105 + %(nodelist)s 13.106 + 13.107 +// bridges 13.108 + 13.109 + node [shape=none,shapefile="shapes/cisco.bmp/switch.png"]; 13.110 + %(bridgelist)s 13.111 + 13.112 +// physical 13.113 + 13.114 + node [shape=rectangle,color=blue]; 13.115 + %(physicallist)s 13.116 + 13.117 +// networks (not bridges, not physical) 13.118 + node [shape=rectangle,color=green]; 13.119 + %(networklist)s 13.120 + 13.121 +// links (between nodes and bridges) 13.122 + %(linklist)s 13.123 + 13.124 +}; 13.125 +GRAPH 13.126 + neato -Tpng -o xenomips.png xenomips.dot 13.127 +""" % graph_dot 13.128 + 13.129 +def start_all(): 13.130 + create_bridges_script() 13.131 + create_screens_script() 13.132 + create_domains_script() 13.133 + graph() 13.134 + print """ 13.135 + cat <<NOTE_FOR_USER 13.136 +# To view virtual network map, run: 13.137 + gqview xenomips.png 13.138 +# To attach to VM consoles, run: 13.139 + screen -c screenrc 13.140 +NOTE_FOR_USER 13.141 +""" 13.142 + 13.143 +def shell(): 13.144 + ipshell = IPShellEmbed() 13.145 + ipshell() 13.146 + 13.147 +def stop_all(): 13.148 + destroy_domains_script(domains) 13.149 + 13.150 +def show_usage(): 13.151 + print """Usage: 13.152 + xentaur {start|stop|start-bridges|start-domains|stop-domains|screen|graph} 13.153 +""" 13.154 + 13.155 +#----------------------------------------------------------------------- 13.156 + 13.157 +def run(program, *args): 13.158 + pid = os.fork() 13.159 + if not pid: 13.160 + os.execvp(program, (program,) + args) 13.161 + return os.wait()[0] 13.162 + 13.163 +def run_command(line) 13.164 + cmds=line.split() 13.165 + run(cmds[0],cmds[1:]) 13.166 + 13.167 +def add_domain(name,type): 13.168 + domains.append(name) 13.169 + domain_types.append(type) 13.170 + 13.171 +def brake_link(domain,bridge): 13.172 + broken_links.append([domain,bridge]) 13.173 + 13.174 +def type_to(screen,string) 13.175 + run_command("screen -X readreg p /tmp/xentaurbuf") 13.176 + run_command("screen -X select 1 ") 13.177 + run_command("screen -X paste p ") 13.178 + run_command("sleep 1") 13.179 + run_command("screen -X select 0") 13.180 + 13.181 +#----------------------------------------------------------------------- 13.182 + 13.183 +bridges=[] 13.184 +for domain in vbridges_table.keys(): 13.185 + bridges += set(vbridges_table[domain]) 13.186 +bridges=set(bridges) 13.187 + 13.188 +nodes=domains 13.189 + 13.190 +if len(sys.argv) > 1: 13.191 + if sys.argv[1] == 'start': 13.192 + start_all() 13.193 + if sys.argv[1] == 'stop': 13.194 + stop_all() 13.195 + if sys.argv[1] == 'start-bridges': 13.196 + create_bridges_script(bridges) 13.197 + if sys.argv[1] == 'start-domains': 13.198 + create_domains_script(domains) 13.199 + if sys.argv[1] == 'stop-domains': 13.200 + destroy_domains_script(domains) 13.201 + elif sys.argv[1] == 'screen': 13.202 + create_screens_script(domains) 13.203 + elif sys.argv[1] == 'graph': 13.204 + graph() 13.205 + elif sys.argv[1] == 'shell': 13.206 + shell() 13.207 + 13.208 +else: 13.209 + show_usage() 13.210 + sys.exit(1) 13.211 + 13.212 +sys.exit(0) 13.213 + 13.214 +