# HG changeset patch # User igor # Date 1193324368 -10800 # Node ID 65e80fabc89cbea9f6c71d3ce631dfd0f2c5df97 # Parent 7a1b67a60fce73813e509390ba17200664b784fd many fixes diff -r 7a1b67a60fce -r 65e80fabc89c build-xenomips-image --- a/build-xenomips-image Wed Oct 24 19:28:37 2007 +0300 +++ b/build-xenomips-image Thu Oct 25 17:59:28 2007 +0300 @@ -1,10 +1,15 @@ #!/bin/sh DYNAMIPS_BUILD=no -XENOMIPS_FS_BUILD=no -CONFIG_FS_BUILD=no +XENOMIPS_FS_BUILD=yes +CONFIG_FS_BUILD=yes IOS_FS_BUILD=yes +process_args() +{ + true +} + XENOMIPS_DIR="files/" XENOMIPS_IMAGES_DIR="/xen/images/" IOS_DIR="ios/" @@ -106,9 +111,16 @@ #iface eth0 inet dhcp INTERFACES -echo /usr/local/bin/xenomips.sh > /etc/rc.local +#echo /usr/local/bin/xenomips.sh > /etc/rc.local cd /etc/rcS.d; ln -s ../init.d/xenomips-init S35xenomips-init rm /etc/rc2.d/S*quagga +cd /etc/rc2.d; ln -s ../init.d/xenomips S99xenomips +cd /etc/rc3.d; ln -s ../init.d/xenomips S99xenomips +cd /etc/rc4.d; ln -s ../init.d/xenomips S99xenomips +cd /etc/rc5.d; ln -s ../init.d/xenomips S99xenomips +cd /etc/rc0.d; ln -s ../init.d/xenomips K01xenomips +cd /etc/rc1.d; ln -s ../init.d/xenomips K01xenomips +cd /etc/rc6.d; ln -s ../init.d/xenomips K01xenomips #perl -i -p -e s@C_PATH=/etc/quagga@C_PATH=/xenomips/etc/quagga@ /etc/init.d/quagga mv /etc/quagga /etc/quagga.ORIG @@ -128,8 +140,8 @@ done cp ${XENOMIPS_DIR}/xenomips-init ${WORK_DIR}/etc/init.d/ - cp ${XENOMIPS_DIR}/xenomips.sh ${WORK_DIR}/usr/local/bin - sudo chmod +x ${WORK_DIR}/usr/local/bin/xenomips.sh ${WORK_DIR}/etc/init.d/xenomips-init + cp ${XENOMIPS_DIR}/xenomips.sh ${WORK_DIR}/etc/init.d/xenomips + sudo chmod +x ${WORK_DIR}/etc/init.d/xenomips ${WORK_DIR}/etc/init.d/xenomips-init cat ${SSH_OPEN_KEY} > ${WORK_DIR}/root/.ssh/authorized_keys chmod 600 ${WORK_DIR}/root/.ssh/authorized_keys diff -r 7a1b67a60fce -r 65e80fabc89c files/xenomips.sh --- a/files/xenomips.sh Wed Oct 24 19:28:37 2007 +0300 +++ b/files/xenomips.sh Thu Oct 25 17:59:28 2007 +0300 @@ -1,13 +1,25 @@ #!/bin/sh -if grep -qi xenomips /proc/cmdline -then - DYNAMIPS_WORKDIR="/xenomips/config" - DYNAMIPS_ARGS=`cat /proc/cmdline | sed 's/.*xenomips="//; s/".*//'` - cd "$DYNAMIPS_WORKDIR" - screen -e '^xx' -d -m sh -c "while true; do dynamips $DYNAMIPS_ARGS ; done" -else - /etc/init.d/quagga start - screen -e '^xx' -d -m sh -c 'while true; do vtysh; done' -fi +case $1 in + start) + if grep -qi xenomips /proc/cmdline + then + DYNAMIPS_WORKDIR="/xenomips/config" + DYNAMIPS_ARGS=`cat /proc/cmdline | sed 's/.*xenomips="//; s/".*//'` + cd "$DYNAMIPS_WORKDIR" + screen -e '^xx' -d -m sh -c "while true; do dynamips $DYNAMIPS_ARGS ; done" + else + /etc/init.d/quagga start + screen -e '^xx' -d -m sh -c 'while true; do vtysh; done' + fi + ;; + stop) + if grep -qi xenomips /proc/cmdline + then + kill $(ps aux | grep dynamips | awk '{print $2}') + else + /etc/init.d/quagga stop + fi + ;; +esac diff -r 7a1b67a60fce -r 65e80fabc89c xentaur.py --- a/xentaur.py Wed Oct 24 19:28:37 2007 +0300 +++ b/xentaur.py Thu Oct 25 17:59:28 2007 +0300 @@ -36,7 +36,12 @@ p.close() return output -def create_bridges_script(): +################################################################################ +#Xentaur command-line commands + +## Start + +def start_bridges(): unbound_bridges=set(bridges)-set(real_bridges) create_unbound_bridges="\n".join(map(lambda x: "sudo brctl show | awk '{print $1}' | grep -qx "+x+" || sudo brctl addbr "+x, unbound_bridges)) create_unbound_bridges+="\n"+"\n".join(map(lambda x: "sudo brctl stp "+x+" off", unbound_bridges)) @@ -47,18 +52,46 @@ %(create_unbound_bridges)s """ % {'create_unbound_bridges' : create_unbound_bridges} +def start_domain(domain): + print "sudo xm create "+xentaur_path+"/xendomain.py "+" domain="+domain+" network="+network+" && sleep 1 && sudo xm sched-credit -d $(sudo xm list | grep "+domain+" | awk '{print $2}') -c 10 && sleep 1" -def create_domains_script(): - for domain in domains: +def start_domains(doms=domains): + for domain in doms: if not domain in real_nodes: - print "sudo xm create "+xentaur_path+"/xendomain.py "+" domain="+domain+" network="+network+" && sleep 1 && sudo xm sched-credit -d $(sudo xm list | grep "+domain+" | awk '{print $2}') -c 10 && sleep 1" + start_domain(domain) -def destroy_domains_script(): - for domain in domains: +def start_all(): + graph() + screen() + start_bridges() + start_domains() + +## Stop + +def stop_domain(domain,wait=0): + if wait: + print "sudo xm shutdown -w "+domain + else: + print "sudo xm shutdown "+domain + +def stop_domains(doms=domains, wait=0): + for domain in doms: if not domain in real_nodes: - print "sudo xm shutdown "+domain + stop_domain(domain,wait) -def create_screens_script(): +def stop_bridges(): + ###FIXME### + return 0 + +def stop_all(wait=0): + stop_domains(domains, wait) + stop_bridges() + +def restart_all(): + stop_all(1) + start_all() + +def screen(): N=1 screens=[] for domain in domains: @@ -72,17 +105,19 @@ # screens.append("screen -t "+domain+" "+str(N)+" sh -c 'while true; do ssh root@"+ip+" ; done'") # -#hardstatus string "\%{gk}\%c \%{yk}\%M\%d \%{wk}\%?\%-Lw\%?\%{bw}\%n*\%f\%t\%?(\%u)\%?\%{wk}\%?\%+Lw\%?" + hardstatus='hardstatus string "%{rk}Xentaur%{bk}@%H %{gk}%c %{yk}%d.%m %{wk}%?%-Lw%?%{bw}%n*%f%t%?(%u)%?%{wk}%?%+Lw%?"' f=open(screenrc, "w"); f.write(""" hardstatus on hardstatus alwayslastline +%s screen -t console 0 bash %s -""" % (screenlist)) +""" % (hardstatus,screenlist)) f.close() + print "# GNU Screen config file is written to: %s" % screenrc def graph_node(node): i=0 @@ -188,35 +223,37 @@ run_command("neato -Tpng -o %s.png %s.dot "%(network,network)) run_command("neato -Tjpg -o %s.jpg %s.dot "%(network,network)) run_command("neato -Tsvg -o %s.svg %s.dot "%(network,network)) + print "# Network map is written to files: %s.{png,svg,jpg,dot}" % network def autoredraw(): graph() -def start_all(): - create_bridges_script() - create_screens_script() - create_domains_script() - graph() - print """ - cat < [] + +Commands: + start-all -- start bridges and domains + start-domains -- start domains only + start-bridges -- start bridges only + stop-all -- stop bridges and domains + stop-domains -- stop domains only + stop-bridges -- stop bridges only (domains have to be stopped already) + restart-all -- restart bridges and domains + + start -- start the + stop -- stop the + + graph -- generate network scheme (result is in .{png,jpg,svg}) + screen -- generate GNU Screen config file (~/.screenrc_xentaur) + shell -- run Xentaur shell + """ def save(): @@ -470,9 +507,28 @@ write_to(dom,"\n\nena\nconf t\nrouter ospf 1\nnetwork 192.168.0.0 0.0.255.255 area 0\nend\n") return 0 +def configure_hostname(doms=domains): + for dom in doms: + if domain_types[domains.index(dom)] == 'quagga': + write_to(dom,"\n\nconf t\nhostname %s\nend\n" % dom) + else: + write_to(dom,"\n\nena\nconf t\nhostname %s\nend\n" % dom) + return 0 + +def configure_logging_synchronous(doms=domains): + for dom in domains: + if domain_types[domains.index(dom)] == 'quagga': + 0 + else: + write_to(dom,"\n\nena\nconf t\nline console 0\nlogging synchronous\nend\n") + return 0 + def configure_save(doms=domains): write_to(doms,"\nwr\n") +def configure_root(doms=domains): + write_to(doms,"root\n") + #----------------------------------------------------------------------- @@ -518,15 +574,25 @@ run_command("screen -X select %s" % (return_to_screen)) time.sleep(wt_timeout) +def filter_by_type(doms,type): + """ + filter_by_type(doms,type) + + Return only domains of *doms* that have specified *type* + """ + return filter(lambda x: domain_types[domains.index(x)]==type,domains) + #----------------------------------------------------------------------- cisco_fa01_up=""" ena conf t int fa0/0 +duplex half no shutdown exit int fa1/0 +duplex half no shutdown exit exit @@ -540,28 +606,43 @@ exit """ - - nodes=domains -if len(sys.argv) > 1: - if sys.argv[1] == 'start': +if len(sys.argv) == 2: + if sys.argv[1] == 'start-all': start_all() - if sys.argv[1] == 'stop': + elif sys.argv[1] == 'start-domains': + start_domains() + elif sys.argv[1] == 'start-bridges': + start_bridges() + elif sys.argv[1] == 'stop-all': stop_all() - if sys.argv[1] == 'start-bridges': - create_bridges_script() - if sys.argv[1] == 'start-domains': - create_domains_script() - if sys.argv[1] == 'stop-domains': - destroy_domains_script() + elif sys.argv[1] == 'stop-domains': + stop_domains() + elif sys.argv[1] == 'stop-bridges': + stop_bridges() + elif sys.argv[1] == 'restart-all': + restart_all() elif sys.argv[1] == 'screen': create_screens_script() elif sys.argv[1] == 'graph': graph() elif sys.argv[1] == 'shell': shell() - + else: + show_usage() + sys.exit(1) +elif len(sys.argv) == 3: + if sys.argv[1] == 'start': + start_domain(sys.argv[2]) + elif sys.argv[1] == 'stop': + stop_domain(sys.argv[2]) + elif sys.argv[1] == 'restart': + stop_domain(sys.argv[2]) + start_domain(sys.argv[2]) + else: + show_usage() + sys.exit(1) else: show_usage() sys.exit(1)