xentaur

view 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 source
1 ####
2 #
3 # External variables:
4 # * network
5 # * domain
7 try:
8 domain
9 except NameError:
10 import sys
11 network=sys.modules['__main__'].network
12 domain=sys.modules['__main__'].domain
14 import os
16 sys.path.append(os.environ['HOME']+"/xentaur")
17 os.environ['xendomain']=domain
22 ############################
23 # default values:
24 platform=''
25 npe_type='npe-400'
26 bridge_bridge_table = {
27 }
29 #try:
30 # domains
31 #except:
32 # domains=[]
35 domains_brief=[]
36 domain_types=[]
37 domain_notes=[]
38 domain_subtypes=[]
39 hidden_bridges = []
40 broken_links = []
41 temporary_links = []
42 cross_bridges=[]
43 real_bridges=[]
44 real_nodes=[]
45 connection_table={}
47 exec 'from %s import *' % (network)
49 # overriden by network config
50 ############################
52 def process_domains_brief():
53 # import sre
54 #global domains_brief, domains, domain_types, real_nodes, domain_notes, domain_subtypes
55 if len(domains_brief) >0 :
56 node_brief_re=sre.compile('([a-zA-Z_0-9-]*)(?::([a-zA-Z_0-9-]*))?(?::([a-zA-Z_0-9-]*))?(\*?)(?:#(.*))?')
57 if len(domains)==0:
58 domains=map(lambda x:node_brief_re.search(x).groups()[0] or '', domains_brief)
59 if len(domain_types)==0:
60 domain_types=map(lambda x:node_brief_re.search(x).groups()[1] or '', domains_brief)
61 if len(domain_subtypes)==0:
62 domain_subtypes=map(lambda x:node_brief_re.search(x).groups()[2] or '', domains_brief)
63 if len(real_nodes)==0:
64 i=0
65 for brief in domains_brief:
66 if node_brief_re.search(brief).groups()[3] == '*':
67 real_nodes.append(domains[i])
68 i+=1
69 if len(domain_notes)==0:
70 domain_notes=map(lambda x:node_brief_re.search(x).groups()[4] or '', domains_brief)
72 ############################
73 #try:
74 #except:
75 # print "Can't find or interpret module %s with topology description" %(network)
76 # sys.exit(1)
78 #process_domains_brief()
80 N = domains.index(domain)
81 name=domain
83 pae=1
84 if pae:
85 kernel = "/boot/vmlinuz-2.6.18-4-xen-686"
86 ramdisk = "/boot/initrd.img-2.6.18-4-xen-686"
87 else:
88 kernel = "/boot/vmlinuz-2.6.18-without-PAE-4-xen-686"
89 ramdisk = "/boot/initrd.img-2.6.18-without-PAE-4-xen-686-domU"
91 #builder='linux'
92 cpu_cap = 10
97 for br in bridges:
98 if not br in vbridges_table.keys():
99 vbridges_table[br]=[]
101 for domain in domains:
102 if not domain in connection_table.keys():
103 connection_table[domain]='true'
105 vbridges = vbridges_table[name]
107 vif=[]
108 x=1
109 for i in vbridges:
110 vif.append('bridge='+i+',mac=00:16:3e:01:'+hex(N)[2:]+':'+hex(int('c0',16)+x)[2:])
111 x+=1
113 disk = [ 'file:'+xenomips_dir+'xenomips1.img,hda1,r', 'file:'+xenomips_dir+'xenomips-ios1.img,hda2,r', 'file:'+xenomips_dir+'xenomips-config'+str(N)+'.img,hda3,w' ]
114 root = "/dev/hda1 ro"
116 if domain_types[N] == 'quagga':
117 memory = 64
118 else:
119 memory = 400
121 if len(domain_subtypes) >0 and domain_subtypes[N] != '' and platform == '':
122 platform=domain_subtypes[N]
124 if platform == '':
125 platform='7200'
128 if domain_types[N] == 'quagga':
129 extra = "quagga"
130 elif domain_types[N] == 'dynamips':
131 default_network_module={
132 '7200' : 'PA-FE-TX',
133 '3600' : 'NM-1FE-TX',
134 '3725' : 'NM-1FE-TX',
135 '3745' : 'NM-1FE-TX',
136 '2691' : 'NM-1FE-TX',
137 }
139 platform_option=""
140 if platform != '7200':
141 platform_option=' -P '+platform
142 npe_option=""
143 if platform == '7200':
144 npe_option=" -t "+npe_type
145 mac_option=' -m 00:16:3e:01:'+hex(N)[2:]+':01'
146 if platform != '7200':
147 mac_option =''
149 network_module=default_network_module[platform]
151 xenomips='dynamips /xenomips/ios/'+ios_name+platform_option+npe_option+mac_option
152 if platform== '7200':
153 for i in range(len(vbridges)-1):
154 xenomips += ' -p '+str(i+1)+':'+network_module
155 else:
156 for i in range(len(vbridges)-1):
157 xenomips += ' -p '+str(i+1)+':'+network_module
158 for i in range(len(vbridges)):
159 xenomips += ' -s '+str(i)+':0:gen_eth:eth'+str(i)
160 extra = "xenomips=\""+xenomips+"\""
161 elif domain_types[N] == 'pixemu':
162 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
163 extra = "xenomips=\""+xenomips+"\""
164 else:
165 raise "Unknown domain type %s of domain %s " % (domain_types[N], domains[N])
167 on_poweroff = 'destroy'
168 on_reboot = 'restart'
169 on_crash = 'restart'