xentaur

view xendomain.py @ 65:cf823d27b029

Nattaur changes
author nata@nattaur
date Mon Oct 12 00:12:11 2009 +0300 (2009-10-12)
parents 07c6777758dc
children aaf034af3a35
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("/xentaur/xentaur")
17 sys.path.append('.')
18 os.environ['xendomain']=domain
23 ############################
24 # default values:
25 platform=''
26 npe_type='npe-400'
27 bridge_bridge_table = {
28 }
30 #try:
31 # domains
32 #except:
33 # domains=[]
36 domains_brief=[]
37 domain_types=[]
38 domain_notes=[]
39 domain_subtypes=[]
40 hidden_bridges = []
41 broken_links = []
42 temporary_links = []
43 cross_bridges=[]
44 real_bridges=[]
45 real_nodes=[]
46 connection_table={}
48 exec 'from %s import *' % (network)
50 # overriden by network config
51 ############################
53 def process_domains_brief():
54 # import sre
55 #global domains_brief, domains, domain_types, real_nodes, domain_notes, domain_subtypes
56 if len(domains_brief) >0 :
57 node_brief_re=sre.compile('([a-zA-Z_0-9-]*)(?::([a-zA-Z_0-9-]*))?(?::([a-zA-Z_0-9-]*))?(\*?)(?:#(.*))?')
58 if len(domains)==0:
59 domains=map(lambda x:node_brief_re.search(x).groups()[0] or '', domains_brief)
60 if len(domain_types)==0:
61 domain_types=map(lambda x:node_brief_re.search(x).groups()[1] or '', domains_brief)
62 if len(domain_subtypes)==0:
63 domain_subtypes=map(lambda x:node_brief_re.search(x).groups()[2] or '', domains_brief)
64 if len(real_nodes)==0:
65 i=0
66 for brief in domains_brief:
67 if node_brief_re.search(brief).groups()[3] == '*':
68 real_nodes.append(domains[i])
69 i+=1
70 if len(domain_notes)==0:
71 domain_notes=map(lambda x:node_brief_re.search(x).groups()[4] or '', domains_brief)
73 ############################
74 #try:
75 #except:
76 # print "Can't find or interpret module %s with topology description" %(network)
77 # sys.exit(1)
79 #process_domains_brief()
81 N = domains.index(domain)
82 name=domain
84 try:
85 kernel
86 except:
87 pae=1
88 if pae:
89 kernel="/boot/vmlinuz-2.6.18-6-xen-686"
90 ramdisk = "/boot/initrd.img-2.6.18-6-xen-686"
91 else:
92 kernel = "/boot/vmlinuz-2.6.18-without-PAE-4-xen-686"
93 ramdisk = "/boot/initrd.img-2.6.18-without-PAE-4-xen-686-domU"
95 #builder='linux'
96 cpu_cap = 10
98 hvm = 0
99 if domain_types[N] in ['freebsd','windows']:
100 hvm = 1
102 if hvm:
103 kernel = "hvmloader"
104 builder='hvm'
105 shadow_memory = 8
106 device_model = 'qemu-dm'
107 boot="c"
108 sdl=0
109 vnc=1
110 vncpasswd=''
111 stdvga=0
112 serial='pty'
113 usb=1
116 for br in bridges:
117 if not br in vbridges_table.keys():
118 vbridges_table[br]=[]
120 for domain in domains:
121 if not domain in connection_table.keys():
122 connection_table[domain]='true'
124 vbridges = vbridges_table[name]
126 vif=[]
127 x=1
128 for i in vbridges:
129 if hvm:
130 vif.append('bridge='+i+',type=ioemu,mac=00:16:3e:01:'+hex(N)[2:]+':'+hex(int('c0',16)+x)[2:])
131 else:
132 vif.append('bridge='+i+',mac=00:16:3e:01:'+hex(N)[2:]+':'+hex(int('c0',16)+x)[2:])
133 x+=1
135 if domain_types[N] in ['xenomips','quagga','dynamips','pixemu']:
136 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' ]
137 else:
138 if hvm:
139 if domain_types[N] == 'linux':
140 disk = [ 'file:/xentaur/images/'+network+'/'+name+'.img,hda,w' ]
141 else:
142 disk = [ 'file:/xentaur/images/'+network+'/'+name+'.img,hda,w', 'file:/xen/xentaur-images/'+network+'/'+name+'-disk2.img,hdb,w' ]
144 else:
145 disk = [ 'file:/xentaur/images/'+network+'/'+name+'.img,hda1,w' ]
147 root = "/dev/hda1 ro"
149 if domain_types[N] == 'quagga':
150 memory = 64
151 elif domain_types[N] == 'linux':
152 memory = 128
153 else:
154 memory = 300
156 if len(domain_subtypes) >0 and domain_subtypes[N] != '' and platform == '':
157 platform=domain_subtypes[N]
159 if platform == '':
160 platform='7200'
163 if domain_types[N] == 'quagga':
164 extra = "quagga"
165 elif domain_types[N] == 'dynamips':
166 default_network_module={
167 '7200' : 'PA-FE-TX',
168 '3600' : 'NM-1FE-TX',
169 '3725' : 'NM-1FE-TX',
170 '3745' : 'NM-1FE-TX',
171 '2691' : 'NM-1FE-TX',
172 }
174 platform_option=""
175 if platform != '7200':
176 platform_option=' -P '+platform
177 npe_option=""
178 if platform == '7200':
179 npe_option=" -t "+npe_type
180 mac_option=' -m 00:16:3e:01:'+hex(N)[2:]+':01'
181 if platform != '7200':
182 mac_option =''
184 network_module=default_network_module[platform]
186 xenomips='dynamips /xenomips/ios/'+ios_name+platform_option+npe_option+mac_option
187 if platform== '7200':
188 for i in range(len(vbridges)-1):
189 xenomips += ' -p '+str(i+1)+':'+network_module
190 else:
191 for i in range(len(vbridges)-1):
192 xenomips += ' -p '+str(i+1)+':'+network_module
193 for i in range(len(vbridges)):
194 xenomips += ' -s '+str(i)+':0:linux_eth:eth'+str(i)
195 extra = "xenomips=\""+xenomips+"\""
196 elif domain_types[N] == 'pixemu':
197 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
198 extra = "xenomips=\""+xenomips+"\""
199 else:
200 if not domain_types[N] in ['freebsd','windows','linux'] :
201 raise "Unknown domain type %s of domain %s " % (domain_types[N], domains[N])
203 on_poweroff = 'destroy'
204 on_reboot = 'restart'
205 on_crash = 'restart'