xentaur
view xendomain.py @ 66:aaf034af3a35
Merge of Xgurulla into Xentaur code. Not completed yet!!!
Now Xentaur can work with Amazon EC2,
but only with. Local domains management
is switched off temporarily.
Now Xentaur can work with Amazon EC2,
but only with. Local domains management
is switched off temporarily.
author | Igor Chubin <igor@chub.in> |
---|---|
date | Sat Jan 09 20:20:08 2010 +0200 (2010-01-09) |
parents | cf823d27b029 |
children |
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)
49 from network import *
51 # overriden by network config
52 ############################
54 def process_domains_brief():
55 # import sre
56 #global domains_brief, domains, domain_types, real_nodes, domain_notes, domain_subtypes
57 if len(domains_brief) >0 :
58 node_brief_re=sre.compile('([a-zA-Z_0-9-]*)(?::([a-zA-Z_0-9-]*))?(?::([a-zA-Z_0-9-]*))?(\*?)(?:#(.*))?')
59 if len(domains)==0:
60 domains=map(lambda x:node_brief_re.search(x).groups()[0] or '', domains_brief)
61 if len(domain_types)==0:
62 domain_types=map(lambda x:node_brief_re.search(x).groups()[1] or '', domains_brief)
63 if len(domain_subtypes)==0:
64 domain_subtypes=map(lambda x:node_brief_re.search(x).groups()[2] or '', domains_brief)
65 if len(real_nodes)==0:
66 i=0
67 for brief in domains_brief:
68 if node_brief_re.search(brief).groups()[3] == '*':
69 real_nodes.append(domains[i])
70 i+=1
71 if len(domain_notes)==0:
72 domain_notes=map(lambda x:node_brief_re.search(x).groups()[4] or '', domains_brief)
74 ############################
75 #try:
76 #except:
77 # print "Can't find or interpret module %s with topology description" %(network)
78 # sys.exit(1)
80 #process_domains_brief()
82 N = domains.index(domain)
83 name=domain
85 try:
86 kernel
87 except:
88 pae=1
89 if pae:
90 kernel="/boot/vmlinuz-2.6.18-6-xen-686"
91 ramdisk = "/boot/initrd.img-2.6.18-6-xen-686"
92 else:
93 kernel = "/boot/vmlinuz-2.6.18-without-PAE-4-xen-686"
94 ramdisk = "/boot/initrd.img-2.6.18-without-PAE-4-xen-686-domU"
96 #builder='linux'
97 cpu_cap = 10
99 hvm = 0
100 if domain_types[N] in ['freebsd','windows']:
101 hvm = 1
103 if hvm:
104 kernel = "hvmloader"
105 builder='hvm'
106 shadow_memory = 8
107 device_model = 'qemu-dm'
108 boot="c"
109 sdl=0
110 vnc=1
111 vncpasswd=''
112 stdvga=0
113 serial='pty'
114 usb=1
117 for br in bridges:
118 if not br in vbridges_table.keys():
119 vbridges_table[br]=[]
121 for domain in domains:
122 if not domain in connection_table.keys():
123 connection_table[domain]='true'
125 vbridges = vbridges_table[name]
127 vif=[]
128 x=1
129 for i in vbridges:
130 if hvm:
131 vif.append('bridge='+i+',type=ioemu,mac=00:16:3e:01:'+hex(N)[2:]+':'+hex(int('c0',16)+x)[2:])
132 else:
133 vif.append('bridge='+i+',mac=00:16:3e:01:'+hex(N)[2:]+':'+hex(int('c0',16)+x)[2:])
134 x+=1
136 if domain_types[N] in ['xenomips','quagga','dynamips','pixemu']:
137 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' ]
138 else:
139 if hvm:
140 if domain_types[N] == 'linux':
141 disk = [ 'file:/xentaur/images/'+network+'/'+name+'.img,hda,w' ]
142 else:
143 disk = [ 'file:/xentaur/images/'+network+'/'+name+'.img,hda,w', 'file:/xen/xentaur-images/'+network+'/'+name+'-disk2.img,hdb,w' ]
145 else:
146 disk = [ 'file:/xentaur/images/'+network+'/'+name+'.img,hda1,w' ]
148 root = "/dev/hda1 ro"
150 if domain_types[N] == 'quagga':
151 memory = 64
152 elif domain_types[N] == 'linux':
153 memory = 128
154 else:
155 memory = 300
157 if len(domain_subtypes) >0 and domain_subtypes[N] != '' and platform == '':
158 platform=domain_subtypes[N]
160 if platform == '':
161 platform='7200'
164 if domain_types[N] == 'quagga':
165 extra = "quagga"
166 elif domain_types[N] == 'dynamips':
167 default_network_module={
168 '7200' : 'PA-FE-TX',
169 '3600' : 'NM-1FE-TX',
170 '3725' : 'NM-1FE-TX',
171 '3745' : 'NM-1FE-TX',
172 '2691' : 'NM-1FE-TX',
173 }
175 platform_option=""
176 if platform != '7200':
177 platform_option=' -P '+platform
178 npe_option=""
179 if platform == '7200':
180 npe_option=" -t "+npe_type
181 mac_option=' -m 00:16:3e:01:'+hex(N)[2:]+':01'
182 if platform != '7200':
183 mac_option =''
185 network_module=default_network_module[platform]
187 xenomips='dynamips /xenomips/ios/'+ios_name+platform_option+npe_option+mac_option
188 if platform== '7200':
189 for i in range(len(vbridges)-1):
190 xenomips += ' -p '+str(i+1)+':'+network_module
191 else:
192 for i in range(len(vbridges)-1):
193 xenomips += ' -p '+str(i+1)+':'+network_module
194 for i in range(len(vbridges)):
195 xenomips += ' -s '+str(i)+':0:linux_eth:eth'+str(i)
196 extra = "xenomips=\""+xenomips+"\""
197 elif domain_types[N] == 'pixemu':
198 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
199 extra = "xenomips=\""+xenomips+"\""
200 else:
201 if not domain_types[N] in ['freebsd','windows','linux'] :
202 raise "Unknown domain type %s of domain %s " % (domain_types[N], domains[N])
204 on_poweroff = 'destroy'
205 on_reboot = 'restart'
206 on_crash = 'restart'