xentaur

diff xentaur.py @ 38:f71b298798c2

real topologies
author igor
date Fri Sep 28 13:03:15 2007 +0300 (2007-09-28)
parents 7bf7abe92123
children 54b7c7ae50ec
line diff
     1.1 --- a/xentaur.py	Tue Sep 25 22:47:27 2007 +0300
     1.2 +++ b/xentaur.py	Fri Sep 28 13:03:15 2007 +0300
     1.3 @@ -2,8 +2,6 @@
     1.4  
     1.5  
     1.6  import sys,os,time
     1.7 -import xenomips_vars
     1.8 -xenomips_vars.N='1'
     1.9  
    1.10  xentaur_path=os.environ['HOME']+"/xentaur"
    1.11  
    1.12 @@ -39,7 +37,7 @@
    1.13      return output
    1.14  
    1.15  def create_bridges_script():
    1.16 -    unbound_bridges=bridges
    1.17 +    unbound_bridges=set(bridges)-set(real_bridges)
    1.18      create_unbound_bridges="\n".join(map(lambda x: "sudo /usr/sbin/brctl show | awk '{print $1}' | grep -q "+x+" || sudo /usr/sbin/brctl addbr "+x, unbound_bridges))
    1.19      create_unbound_bridges+="\n"+"\n".join(map(lambda x: "sudo /bin/ip link set "+x+" up", unbound_bridges))
    1.20  
    1.21 @@ -51,11 +49,13 @@
    1.22  
    1.23  def create_domains_script():
    1.24      for domain in domains:
    1.25 -        print "sudo /usr/sbin/xm create "+xentaur_path+"/xendomain.py "+" domain="+domain+" network="+network+" && sleep 1 && sudo /usr/sbin/xm sched-credit -d $(sudo /usr/sbin/xm list | grep "+domain+" | awk '{print $2}') -c 10 && sleep 1"
    1.26 +        if not domain in real_nodes:
    1.27 +            print "sudo /usr/sbin/xm create "+xentaur_path+"/xendomain.py "+" domain="+domain+" network="+network+" && sleep 1 && sudo /usr/sbin/xm sched-credit -d $(sudo /usr/sbin/xm list | grep "+domain+" | awk '{print $2}') -c 10 && sleep 1"
    1.28  
    1.29  def destroy_domains_script():
    1.30      for domain in domains:
    1.31 -        print "sudo /usr/sbin/xm shutdown "+domain
    1.32 +        if not domain in real_nodes:
    1.33 +            print "sudo /usr/sbin/xm shutdown "+domain
    1.34  
    1.35  def create_screens_script():
    1.36      N=1
    1.37 @@ -94,7 +94,9 @@
    1.38  def graph_bridge(bridge):
    1.39      if bridge in hidden_bridges:
    1.40          return ""
    1.41 -    if bridge in bridges_turned_down:
    1.42 +    if bridge in real_bridges:
    1.43 +        return "%s [shape=none,shapefile=\"shapes/all/real_switch.png\"]" % (bridge)
    1.44 +    elif bridge in bridges_turned_down:
    1.45          return "%s [shape=none,shapefile=\"shapes/all/switch_turned_down.png\"]" % (bridge)
    1.46      else:
    1.47          return "%s [shape=none,shapefile=\"shapes/all/switch.png\"]" % (bridge)
    1.48 @@ -232,6 +234,20 @@
    1.49          dump_start(self.name,filter)
    1.50  
    1.51  
    1.52 +class Domain:
    1.53 +    def __init__ (self,name):
    1.54 +        self.name=name
    1.55 +    def start(self):
    1.56 +        return ""
    1.57 +    def stop(self):
    1.58 +        return ""
    1.59 +    def start_commandline(self):
    1.60 +        return ""
    1.61 +    def graphviz(self):
    1.62 +        return ""
    1.63 +    def get_domain_id(self):
    1.64 +        return get_domain_id(self.name)
    1.65 +
    1.66  #-----------------------------------------------------------------------
    1.67  # DOMAINS
    1.68  
    1.69 @@ -246,6 +262,9 @@
    1.70      """
    1.71      Turn the bridge <bridge> down
    1.72      """
    1.73 +    if bridge in real_bridges:
    1.74 +        print "Bridge %s is a real bridge" % (bridge)
    1.75 +        return -1
    1.76      if bridge in bridges_turned_down:
    1.77          print "Bridge %s is turned down already" % (bridge)
    1.78      else:
    1.79 @@ -257,6 +276,9 @@
    1.80      """
    1.81      Turn the bridge <bridge> up
    1.82      """
    1.83 +    if bridge in real_bridges:
    1.84 +        print "Bridge %s is a real bridge" % (bridge)
    1.85 +        return -1
    1.86      if not (bridge in bridges_turned_down):
    1.87          print "Bridge %s is turned up already" % (bridge)
    1.88      else:
    1.89 @@ -268,6 +290,9 @@
    1.90      """
    1.91      Show the state of the bridge <bridge>
    1.92      """
    1.93 +    if bridge in real_bridges:
    1.94 +        print "Bridge %s is a real bridge" % (bridge)
    1.95 +        return -1
    1.96      run_command("sudo ip link show %s" % bridge)
    1.97  
    1.98  
    1.99 @@ -295,8 +320,11 @@
   1.100      Connect the interface with the number <int_number>
   1.101      of the domain <domain> to the bridge <bridge>
   1.102      """
   1.103 +    if bridge in real_bridges:
   1.104 +        print "Bridge %s is a real bridge" % (bridge)
   1.105 +        return -1
   1.106 +
   1.107      dom_id=get_domain_id(domain)
   1.108 -    
   1.109      if vbridges_table[domain][int_number]:
   1.110          print "Interface %s of the %s domain is connected already to the %s bridge" % (int_number, domain, vbridges_table[domain][int_number])
   1.111          return 1
   1.112 @@ -314,6 +342,10 @@
   1.113      of the domain <domain> from the bridge to which
   1.114      it is connected to the bridge <bridge>
   1.115      """
   1.116 +    if bridge in real_bridges:
   1.117 +        print "Bridge %s is a real bridge" % (bridge)
   1.118 +        return -1
   1.119 +    
   1.120      int_disconnect(domain, int_number)
   1.121      int_connect(domain, int_number, bridge)
   1.122  
   1.123 @@ -326,6 +358,9 @@
   1.124  
   1.125  
   1.126  def dump_start(bridge, filter=""):
   1.127 +    if bridge in real_bridges:
   1.128 +        print "Bridge %s is a real bridge" % (bridge)
   1.129 +        return -1
   1.130      try:
   1.131          print "Writing dump... (press Ctrl-C to stop)"
   1.132          run_command("sudo tcpdump -w xentaur.dump -i %s %s > /dev/null 2>&1 " % (bridge,filter))