xentaur

diff xendomain.py @ 61:6471afbee150

*** empty log message ***
author igor
date Mon Dec 03 08:36:13 2007 +0200 (2007-12-03)
parents e7b9761c03e8
children e838c1223b89
line diff
     1.1 --- a/xendomain.py	Sun Nov 11 20:57:50 2007 +0200
     1.2 +++ b/xendomain.py	Mon Dec 03 08:36:13 2007 +0200
     1.3 @@ -4,7 +4,6 @@
     1.4  # * network 
     1.5  # * domain
     1.6  
     1.7 -
     1.8  try: 
     1.9      domain
    1.10  except NameError:
    1.11 @@ -12,7 +11,8 @@
    1.12      network=sys.modules['__main__'].network
    1.13      domain=sys.modules['__main__'].domain
    1.14  
    1.15 -import os,re
    1.16 +import os
    1.17 +
    1.18  sys.path.append(os.environ['HOME']+"/xentaur")
    1.19  os.environ['xendomain']=domain
    1.20  
    1.21 @@ -26,48 +26,56 @@
    1.22  bridge_bridge_table = {
    1.23  }
    1.24  
    1.25 +#try:
    1.26 +#    domains
    1.27 +#except:
    1.28 +#    domains=[]
    1.29 +
    1.30 +
    1.31  domains_brief=[]
    1.32 -domains=[]
    1.33  domain_types=[]
    1.34  domain_notes=[]
    1.35  domain_subtypes=[]
    1.36 -
    1.37  hidden_bridges = []
    1.38  broken_links = []
    1.39  temporary_links = []
    1.40  cross_bridges=[]
    1.41 -
    1.42  real_bridges=[]
    1.43  real_nodes=[]
    1.44 +connection_table={}
    1.45 +
    1.46 +exec 'from %s import *' % (network)
    1.47 +
    1.48  # overriden by network config
    1.49  ############################
    1.50  
    1.51  def process_domains_brief():
    1.52 -    global domains, domain_types, real_nodes, domain_notes, domain_subtypes
    1.53 -    node_brief_re=re.compile('([a-zA-Z_0-9-]*)(?::([a-zA-Z_0-9-]*))?(?::([a-zA-Z_0-9-]*))?(\*?)(?:#(.*))?')
    1.54 -    if len(domains)==0:
    1.55 -        domains=map(lambda x:node_brief_re.search(x).groups()[0] or '', domains_brief)
    1.56 -    if len(domain_types)==0:
    1.57 -        domain_types=map(lambda x:node_brief_re.search(x).groups()[1] or '', domains_brief)
    1.58 -    if len(domain_subtypes)==0:
    1.59 -        domain_subtypes=map(lambda x:node_brief_re.search(x).groups()[2] or '', domains_brief)
    1.60 -    if len(real_nodes)==0:
    1.61 -        i=0
    1.62 -        for brief in domains_brief:
    1.63 -            if node_brief_re.search(brief).groups()[3] == '*':
    1.64 -                real_nodes.append(domains[i])
    1.65 -            i+=1
    1.66 -    if len(domain_notes)==0:
    1.67 -        domain_notes=map(lambda x:node_brief_re.search(x).groups()[4] or '', domains_brief)
    1.68 +#    import sre
    1.69 +    #global domains_brief, domains, domain_types, real_nodes, domain_notes, domain_subtypes
    1.70 +    if len(domains_brief) >0 :
    1.71 +        node_brief_re=sre.compile('([a-zA-Z_0-9-]*)(?::([a-zA-Z_0-9-]*))?(?::([a-zA-Z_0-9-]*))?(\*?)(?:#(.*))?')
    1.72 +        if len(domains)==0:
    1.73 +            domains=map(lambda x:node_brief_re.search(x).groups()[0] or '', domains_brief)
    1.74 +        if len(domain_types)==0:
    1.75 +            domain_types=map(lambda x:node_brief_re.search(x).groups()[1] or '', domains_brief)
    1.76 +        if len(domain_subtypes)==0:
    1.77 +            domain_subtypes=map(lambda x:node_brief_re.search(x).groups()[2] or '', domains_brief)
    1.78 +        if len(real_nodes)==0:
    1.79 +            i=0
    1.80 +            for brief in domains_brief:
    1.81 +                if node_brief_re.search(brief).groups()[3] == '*':
    1.82 +                    real_nodes.append(domains[i])
    1.83 +                i+=1
    1.84 +        if len(domain_notes)==0:
    1.85 +            domain_notes=map(lambda x:node_brief_re.search(x).groups()[4] or '', domains_brief)
    1.86  
    1.87  ############################
    1.88  #try:
    1.89 -exec 'from %s import *' % (network)
    1.90  #except:
    1.91  #    print "Can't find or interpret module %s with topology description" %(network)
    1.92  #    sys.exit(1)
    1.93  
    1.94 -process_domains_brief()
    1.95 +#process_domains_brief()
    1.96  
    1.97  N = domains.index(domain)
    1.98  name=domain
    1.99 @@ -110,49 +118,51 @@
   1.100  else:
   1.101      memory = 400
   1.102  
   1.103 -if domain_subtypes[N] != '' and platform == '':
   1.104 +if len(domain_subtypes) >0 and domain_subtypes[N] != '' and platform == '':
   1.105      platform=domain_subtypes[N]
   1.106  
   1.107  if platform == '': 
   1.108      platform='7200'
   1.109 -platform_option=""
   1.110 -if platform != '7200':
   1.111 -    platform_option=' -P '+platform
   1.112  
   1.113 -npe_option=""
   1.114 -if platform == '7200':
   1.115 -    npe_option=" -t "+npe_type
   1.116 -
   1.117 -mac_option=' -m 00:16:3e:01:'+hex(N)[2:]+':01'
   1.118 -if platform != '7200':
   1.119 -    mac_option =''
   1.120 -
   1.121 -xenomips='/xenomips/ios/'+ios_name+platform_option+npe_option+mac_option
   1.122 -
   1.123 -default_network_module={
   1.124 -    '7200' : 'PA-FE-TX',
   1.125 -    '3600' : 'NM-1FE-TX',
   1.126 -    '3725' : 'NM-1FE-TX',
   1.127 -    '3745' : 'NM-1FE-TX',
   1.128 -    '2691' : 'NM-1FE-TX',
   1.129 -}
   1.130 -network_module=default_network_module[platform]
   1.131 -
   1.132 -if platform== '7200':
   1.133 -    for i in range(len(vbridges)-1):
   1.134 -        xenomips += ' -p '+str(i+1)+':'+network_module
   1.135 -else:
   1.136 -    for i in range(len(vbridges)-1):
   1.137 -        xenomips += ' -p '+str(i+1)+':'+network_module
   1.138 -
   1.139 -
   1.140 -for i in range(len(vbridges)):
   1.141 - xenomips += ' -s '+str(i)+':0:gen_eth:eth'+str(i)
   1.142  
   1.143  if domain_types[N] == 'quagga':
   1.144      extra = "quagga"
   1.145 +elif domain_types[N] == 'dynamips':
   1.146 +    default_network_module={
   1.147 +        '7200' : 'PA-FE-TX',
   1.148 +        '3600' : 'NM-1FE-TX',
   1.149 +        '3725' : 'NM-1FE-TX',
   1.150 +        '3745' : 'NM-1FE-TX',
   1.151 +        '2691' : 'NM-1FE-TX',
   1.152 +    }
   1.153 +
   1.154 +    platform_option=""
   1.155 +    if platform != '7200':
   1.156 +        platform_option=' -P '+platform
   1.157 +    npe_option=""
   1.158 +    if platform == '7200':
   1.159 +        npe_option=" -t "+npe_type
   1.160 +    mac_option=' -m 00:16:3e:01:'+hex(N)[2:]+':01'
   1.161 +    if platform != '7200':
   1.162 +        mac_option =''
   1.163 +
   1.164 +    network_module=default_network_module[platform]
   1.165 +
   1.166 +    xenomips='dynamips /xenomips/ios/'+ios_name+platform_option+npe_option+mac_option
   1.167 +    if platform== '7200':
   1.168 +        for i in range(len(vbridges)-1):
   1.169 +            xenomips += ' -p '+str(i+1)+':'+network_module
   1.170 +    else:
   1.171 +        for i in range(len(vbridges)-1):
   1.172 +            xenomips += ' -p '+str(i+1)+':'+network_module
   1.173 +    for i in range(len(vbridges)):
   1.174 +        xenomips += ' -s '+str(i)+':0:gen_eth:eth'+str(i)
   1.175 +    extra = "xenomips=\""+xenomips+"\""
   1.176 +elif domain_types[N] == 'pixemu':
   1.177 +    xenomips="./pemu -net nic,vlan=1,macaddr=00:aa:00:00:02:01 -net pcap,vlan=1,ifname=eth0 -net nic,vlan=2,macaddr=00:aa:00:00:02:02 -net pcap,vlan=2,ifname=eth1 -serial stdio -m 128 FLASH"+' /xenomips/ios/'+ios_name
   1.178 +    extra = "xenomips=\""+xenomips+"\""
   1.179  else:
   1.180 -    extra = "xenomips=\""+xenomips+"\""
   1.181 +    raise "Unknown domain type %s of domain %s " % (domain_types[N], domains[N])
   1.182  
   1.183  on_poweroff = 'destroy'
   1.184  on_reboot   = 'restart'