xentaur

changeset 49:65e80fabc89c

many fixes
author igor
date Thu Oct 25 17:59:28 2007 +0300 (2007-10-25)
parents 7a1b67a60fce
children ca80f73e403b
files build-xenomips-image files/xenomips.sh xentaur.py
line diff
     1.1 --- a/build-xenomips-image	Wed Oct 24 19:28:37 2007 +0300
     1.2 +++ b/build-xenomips-image	Thu Oct 25 17:59:28 2007 +0300
     1.3 @@ -1,10 +1,15 @@
     1.4  #!/bin/sh
     1.5  
     1.6  DYNAMIPS_BUILD=no
     1.7 -XENOMIPS_FS_BUILD=no
     1.8 -CONFIG_FS_BUILD=no
     1.9 +XENOMIPS_FS_BUILD=yes
    1.10 +CONFIG_FS_BUILD=yes
    1.11  IOS_FS_BUILD=yes
    1.12  
    1.13 +process_args()
    1.14 +{
    1.15 +    true
    1.16 +}
    1.17 +
    1.18  XENOMIPS_DIR="files/"
    1.19  XENOMIPS_IMAGES_DIR="/xen/images/"
    1.20  IOS_DIR="ios/"
    1.21 @@ -106,9 +111,16 @@
    1.22  #iface eth0 inet dhcp
    1.23  INTERFACES
    1.24  
    1.25 -echo /usr/local/bin/xenomips.sh > /etc/rc.local
    1.26 +#echo /usr/local/bin/xenomips.sh > /etc/rc.local
    1.27  cd /etc/rcS.d; ln -s ../init.d/xenomips-init S35xenomips-init
    1.28  rm /etc/rc2.d/S*quagga
    1.29 +cd /etc/rc2.d; ln -s ../init.d/xenomips S99xenomips
    1.30 +cd /etc/rc3.d; ln -s ../init.d/xenomips S99xenomips
    1.31 +cd /etc/rc4.d; ln -s ../init.d/xenomips S99xenomips
    1.32 +cd /etc/rc5.d; ln -s ../init.d/xenomips S99xenomips
    1.33 +cd /etc/rc0.d; ln -s ../init.d/xenomips K01xenomips
    1.34 +cd /etc/rc1.d; ln -s ../init.d/xenomips K01xenomips
    1.35 +cd /etc/rc6.d; ln -s ../init.d/xenomips K01xenomips
    1.36  
    1.37  #perl -i -p -e s@C_PATH=/etc/quagga@C_PATH=/xenomips/etc/quagga@ /etc/init.d/quagga
    1.38  mv /etc/quagga /etc/quagga.ORIG
    1.39 @@ -128,8 +140,8 @@
    1.40      done
    1.41  
    1.42      cp ${XENOMIPS_DIR}/xenomips-init ${WORK_DIR}/etc/init.d/
    1.43 -    cp ${XENOMIPS_DIR}/xenomips.sh ${WORK_DIR}/usr/local/bin
    1.44 -    sudo chmod +x  ${WORK_DIR}/usr/local/bin/xenomips.sh ${WORK_DIR}/etc/init.d/xenomips-init
    1.45 +    cp ${XENOMIPS_DIR}/xenomips.sh ${WORK_DIR}/etc/init.d/xenomips
    1.46 +    sudo chmod +x  ${WORK_DIR}/etc/init.d/xenomips ${WORK_DIR}/etc/init.d/xenomips-init
    1.47  
    1.48      cat ${SSH_OPEN_KEY} > ${WORK_DIR}/root/.ssh/authorized_keys
    1.49      chmod 600  ${WORK_DIR}/root/.ssh/authorized_keys
     2.1 --- a/files/xenomips.sh	Wed Oct 24 19:28:37 2007 +0300
     2.2 +++ b/files/xenomips.sh	Thu Oct 25 17:59:28 2007 +0300
     2.3 @@ -1,13 +1,25 @@
     2.4  #!/bin/sh
     2.5  
     2.6 -if grep -qi xenomips /proc/cmdline
     2.7 -then 
     2.8 -    DYNAMIPS_WORKDIR="/xenomips/config"
     2.9 -    DYNAMIPS_ARGS=`cat /proc/cmdline | sed 's/.*xenomips="//; s/".*//'`
    2.10 -    cd "$DYNAMIPS_WORKDIR"
    2.11 -    screen -e '^xx' -d -m sh -c "while true; do dynamips $DYNAMIPS_ARGS ; done"
    2.12 -else
    2.13 -    /etc/init.d/quagga start
    2.14 -    screen -e '^xx' -d -m sh -c 'while true; do vtysh; done'
    2.15 -fi
    2.16 +case $1 in
    2.17 +    start)
    2.18 +        if grep -qi xenomips /proc/cmdline
    2.19 +        then 
    2.20 +            DYNAMIPS_WORKDIR="/xenomips/config"
    2.21 +            DYNAMIPS_ARGS=`cat /proc/cmdline | sed 's/.*xenomips="//; s/".*//'`
    2.22 +            cd "$DYNAMIPS_WORKDIR"
    2.23 +            screen -e '^xx' -d -m sh -c "while true; do dynamips $DYNAMIPS_ARGS ; done"
    2.24 +        else
    2.25 +            /etc/init.d/quagga start
    2.26 +            screen -e '^xx' -d -m sh -c 'while true; do vtysh; done'
    2.27 +        fi
    2.28 +    ;;
    2.29 +    stop)
    2.30 +        if grep -qi xenomips /proc/cmdline
    2.31 +        then 
    2.32 +            kill $(ps aux | grep  dynamips | awk '{print $2}')
    2.33 +        else
    2.34 +            /etc/init.d/quagga stop
    2.35 +        fi
    2.36 +    ;;
    2.37 +esac
    2.38  
     3.1 --- a/xentaur.py	Wed Oct 24 19:28:37 2007 +0300
     3.2 +++ b/xentaur.py	Thu Oct 25 17:59:28 2007 +0300
     3.3 @@ -36,7 +36,12 @@
     3.4      p.close()
     3.5      return output
     3.6  
     3.7 -def create_bridges_script():
     3.8 +################################################################################
     3.9 +#Xentaur command-line commands
    3.10 +
    3.11 +## Start
    3.12 +
    3.13 +def start_bridges():
    3.14      unbound_bridges=set(bridges)-set(real_bridges)
    3.15      create_unbound_bridges="\n".join(map(lambda x: "sudo brctl show | awk '{print $1}' | grep -qx "+x+" || sudo brctl addbr "+x, unbound_bridges))
    3.16      create_unbound_bridges+="\n"+"\n".join(map(lambda x: "sudo brctl stp "+x+" off", unbound_bridges))
    3.17 @@ -47,18 +52,46 @@
    3.18  %(create_unbound_bridges)s
    3.19  """ % {'create_unbound_bridges' : create_unbound_bridges}
    3.20  
    3.21 +def start_domain(domain):
    3.22 +    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"
    3.23  
    3.24 -def create_domains_script():
    3.25 -    for domain in domains:
    3.26 +def start_domains(doms=domains):
    3.27 +    for domain in doms:
    3.28          if not domain in real_nodes:
    3.29 -            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"
    3.30 +            start_domain(domain)
    3.31  
    3.32 -def destroy_domains_script():
    3.33 -    for domain in domains:
    3.34 +def start_all():
    3.35 +    graph()
    3.36 +    screen()
    3.37 +    start_bridges()
    3.38 +    start_domains()
    3.39 +
    3.40 +## Stop
    3.41 +
    3.42 +def stop_domain(domain,wait=0):
    3.43 +    if wait:
    3.44 +        print "sudo xm shutdown -w "+domain
    3.45 +    else:
    3.46 +        print "sudo xm shutdown "+domain
    3.47 +
    3.48 +def stop_domains(doms=domains, wait=0):
    3.49 +    for domain in doms:
    3.50          if not domain in real_nodes:
    3.51 -            print "sudo xm shutdown "+domain
    3.52 +            stop_domain(domain,wait)
    3.53  
    3.54 -def create_screens_script():
    3.55 +def stop_bridges():
    3.56 +    ###FIXME###
    3.57 +    return 0
    3.58 +
    3.59 +def stop_all(wait=0):
    3.60 +    stop_domains(domains, wait)
    3.61 +    stop_bridges()
    3.62 +
    3.63 +def restart_all():
    3.64 +    stop_all(1)
    3.65 +    start_all()
    3.66 +
    3.67 +def screen():
    3.68      N=1
    3.69      screens=[]
    3.70      for domain in domains:
    3.71 @@ -72,17 +105,19 @@
    3.72  #        screens.append("screen -t "+domain+"   "+str(N)+" sh -c 'while true; do ssh root@"+ip+" ; done'")
    3.73  #
    3.74  
    3.75 -#hardstatus string "\%{gk}\%c \%{yk}\%M\%d \%{wk}\%?\%-Lw\%?\%{bw}\%n*\%f\%t\%?(\%u)\%?\%{wk}\%?\%+Lw\%?"
    3.76 +    hardstatus='hardstatus string "%{rk}Xentaur%{bk}@%H %{gk}%c %{yk}%d.%m %{wk}%?%-Lw%?%{bw}%n*%f%t%?(%u)%?%{wk}%?%+Lw%?"'
    3.77     
    3.78      f=open(screenrc, "w");
    3.79      f.write("""
    3.80  hardstatus on
    3.81  hardstatus alwayslastline
    3.82 +%s
    3.83  
    3.84  screen -t console 0 bash
    3.85  %s
    3.86 -""" % (screenlist))
    3.87 +""" % (hardstatus,screenlist))
    3.88      f.close()
    3.89 +    print "# GNU Screen config file is written to: %s" % screenrc
    3.90  
    3.91  def graph_node(node):
    3.92      i=0
    3.93 @@ -188,35 +223,37 @@
    3.94      run_command("neato -Tpng -o %s.png %s.dot "%(network,network))
    3.95      run_command("neato -Tjpg -o %s.jpg %s.dot "%(network,network))
    3.96      run_command("neato -Tsvg -o %s.svg %s.dot "%(network,network))
    3.97 +    print "# Network map is written to files: %s.{png,svg,jpg,dot}" % network
    3.98  
    3.99  def autoredraw():
   3.100      graph()
   3.101  
   3.102 -def start_all():
   3.103 -        create_bridges_script()
   3.104 -        create_screens_script()
   3.105 -        create_domains_script()
   3.106 -        graph()
   3.107 -        print """
   3.108 -        cat <<NOTE_FOR_USER
   3.109 -# To view virtual network map, run:
   3.110 -    gqview xenomips.png
   3.111 -# To attach to VM consoles, run:
   3.112 -    screen -c screenrc
   3.113 -NOTE_FOR_USER
   3.114 -"""
   3.115 -
   3.116  def shell():
   3.117      autoredraw()
   3.118      ipshell = IPShellEmbed()
   3.119      ipshell()
   3.120  
   3.121 -def stop_all():
   3.122 -        destroy_domains_script()
   3.123  
   3.124  def show_usage():
   3.125      print """Usage:
   3.126 -    xentaur {start|stop|start-bridges|start-domains|stop-domains|screen|graph}
   3.127 +    xentaur <command> [<argument>]
   3.128 +
   3.129 +Commands:
   3.130 +    start-all       --  start bridges and domains
   3.131 +    start-domains   --  start domains only
   3.132 +    start-bridges   --  start bridges only
   3.133 +    stop-all        --  stop bridges and domains
   3.134 +    stop-domains    --  stop domains only
   3.135 +    stop-bridges    --  stop bridges only (domains have to be stopped already)
   3.136 +    restart-all     --  restart bridges and domains
   3.137 +
   3.138 +    start <domain>  --  start the <domain>
   3.139 +    stop <domain>   --  stop the <domain>
   3.140 +
   3.141 +    graph           --  generate network scheme (result is in <network>.{png,jpg,svg})
   3.142 +    screen          --  generate GNU Screen config file (~/.screenrc_xentaur)
   3.143 +    shell           --  run Xentaur shell
   3.144 +
   3.145  """
   3.146  
   3.147  def save():
   3.148 @@ -470,9 +507,28 @@
   3.149              write_to(dom,"\n\nena\nconf t\nrouter ospf 1\nnetwork 192.168.0.0 0.0.255.255 area 0\nend\n")
   3.150      return 0
   3.151  
   3.152 +def configure_hostname(doms=domains):
   3.153 +    for dom in doms:
   3.154 +        if domain_types[domains.index(dom)] == 'quagga':
   3.155 +            write_to(dom,"\n\nconf t\nhostname %s\nend\n" % dom)
   3.156 +        else:
   3.157 +            write_to(dom,"\n\nena\nconf t\nhostname %s\nend\n" % dom)
   3.158 +    return 0
   3.159 +
   3.160 +def configure_logging_synchronous(doms=domains):
   3.161 +    for dom in domains:
   3.162 +        if domain_types[domains.index(dom)] == 'quagga':
   3.163 +            0
   3.164 +        else:
   3.165 +            write_to(dom,"\n\nena\nconf t\nline console 0\nlogging synchronous\nend\n")
   3.166 +    return 0
   3.167 +
   3.168  def configure_save(doms=domains):
   3.169      write_to(doms,"\nwr\n")
   3.170  
   3.171 +def configure_root(doms=domains):
   3.172 +    write_to(doms,"root\n")
   3.173 +
   3.174  #-----------------------------------------------------------------------
   3.175  
   3.176  
   3.177 @@ -518,15 +574,25 @@
   3.178              run_command("screen -X select %s" % (return_to_screen))
   3.179              time.sleep(wt_timeout)
   3.180  
   3.181 +def filter_by_type(doms,type):
   3.182 +    """
   3.183 +    filter_by_type(doms,type)
   3.184 +
   3.185 +        Return only domains of *doms* that have specified *type*
   3.186 +    """
   3.187 +    return filter(lambda x: domain_types[domains.index(x)]==type,domains)
   3.188 +
   3.189  #-----------------------------------------------------------------------
   3.190  
   3.191  cisco_fa01_up="""
   3.192  ena
   3.193  conf t
   3.194  int fa0/0
   3.195 +duplex half
   3.196  no shutdown
   3.197  exit
   3.198  int fa1/0
   3.199 +duplex half
   3.200  no shutdown
   3.201  exit
   3.202  exit
   3.203 @@ -540,28 +606,43 @@
   3.204  exit
   3.205  """
   3.206  
   3.207 -
   3.208 -
   3.209  nodes=domains
   3.210  
   3.211 -if len(sys.argv) > 1:
   3.212 -    if sys.argv[1] == 'start':
   3.213 +if len(sys.argv) == 2:
   3.214 +    if sys.argv[1] == 'start-all':
   3.215          start_all()
   3.216 -    if sys.argv[1] == 'stop':
   3.217 +    elif sys.argv[1] == 'start-domains':
   3.218 +        start_domains()
   3.219 +    elif sys.argv[1] == 'start-bridges':
   3.220 +        start_bridges()
   3.221 +    elif sys.argv[1] == 'stop-all':
   3.222          stop_all()
   3.223 -    if sys.argv[1] == 'start-bridges':
   3.224 -        create_bridges_script()
   3.225 -    if sys.argv[1] == 'start-domains':
   3.226 -        create_domains_script()
   3.227 -    if sys.argv[1] == 'stop-domains':
   3.228 -        destroy_domains_script()
   3.229 +    elif sys.argv[1] == 'stop-domains':
   3.230 +        stop_domains()
   3.231 +    elif sys.argv[1] == 'stop-bridges':
   3.232 +        stop_bridges()
   3.233 +    elif sys.argv[1] == 'restart-all':
   3.234 +        restart_all()
   3.235      elif sys.argv[1] == 'screen':
   3.236          create_screens_script()
   3.237      elif sys.argv[1] == 'graph':
   3.238          graph()
   3.239      elif sys.argv[1] == 'shell':
   3.240          shell()
   3.241 -
   3.242 +    else:
   3.243 +        show_usage()
   3.244 +        sys.exit(1)
   3.245 +elif len(sys.argv) == 3:
   3.246 +    if sys.argv[1] == 'start':
   3.247 +        start_domain(sys.argv[2])
   3.248 +    elif sys.argv[1] == 'stop':
   3.249 +        stop_domain(sys.argv[2])
   3.250 +    elif sys.argv[1] == 'restart':
   3.251 +        stop_domain(sys.argv[2])
   3.252 +        start_domain(sys.argv[2])
   3.253 +    else:
   3.254 +        show_usage()
   3.255 +        sys.exit(1)
   3.256  else:
   3.257      show_usage()
   3.258      sys.exit(1)