xentaur

view xendomain.py @ 63:07c6777758dc

* path to shapes
* dynamips icon
author igor
date Fri Feb 29 07:22:46 2008 +0200 (2008-02-29)
parents e838c1223b89
children cf823d27b029
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 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 pae=1
85 if pae:
86 kernel = "/boot/vmlinuz-2.6.18-4-xen-686"
87 ramdisk = "/boot/initrd.img-2.6.18-4-xen-686"
88 else:
89 kernel = "/boot/vmlinuz-2.6.18-without-PAE-4-xen-686"
90 ramdisk = "/boot/initrd.img-2.6.18-without-PAE-4-xen-686-domU"
92 #builder='linux'
93 cpu_cap = 10
95 hvm = 0
96 if domain_types[N] in ['freebsd','windows']:
97 hvm = 1
99 if hvm:
100 kernel = "hvmloader"
101 builder='hvm'
102 shadow_memory = 8
103 device_model = 'qemu-dm'
104 boot="c"
105 sdl=0
106 vnc=1
107 vncpasswd=''
108 stdvga=0
109 serial='pty'
110 usb=1
113 for br in bridges:
114 if not br in vbridges_table.keys():
115 vbridges_table[br]=[]
117 for domain in domains:
118 if not domain in connection_table.keys():
119 connection_table[domain]='true'
121 vbridges = vbridges_table[name]
123 vif=[]
124 x=1
125 for i in vbridges:
126 if hvm:
127 vif.append('bridge='+i+',type=ioemu,mac=00:16:3e:01:'+hex(N)[2:]+':'+hex(int('c0',16)+x)[2:])
128 else:
129 vif.append('bridge='+i+',mac=00:16:3e:01:'+hex(N)[2:]+':'+hex(int('c0',16)+x)[2:])
130 x+=1
132 if domain_types[N] in ['xenomips','quagga','dynamips','pixemu']:
133 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' ]
134 else:
135 if hvm:
136 if domain_types[N] == 'linux':
137 disk = [ 'file:/xen/xentaur-images/'+network+'/'+name+'.img,hda,w' ]
138 else:
139 disk = [ 'file:/xen/xentaur-images/'+network+'/'+name+'.img,hda,w', 'file:/xen/xentaur-images/'+network+'/'+name+'-disk2.img,hdb,w' ]
141 else:
142 disk = [ 'file:/xen/xentaur-images/'+network+'/'+name+'.img,hda1,w' ]
144 root = "/dev/hda1 ro"
146 if domain_types[N] == 'quagga':
147 memory = 64
148 elif domain_types[N] == 'linux':
149 memory = 128
150 else:
151 memory = 300
153 if len(domain_subtypes) >0 and domain_subtypes[N] != '' and platform == '':
154 platform=domain_subtypes[N]
156 if platform == '':
157 platform='7200'
160 if domain_types[N] == 'quagga':
161 extra = "quagga"
162 elif domain_types[N] == 'dynamips':
163 default_network_module={
164 '7200' : 'PA-FE-TX',
165 '3600' : 'NM-1FE-TX',
166 '3725' : 'NM-1FE-TX',
167 '3745' : 'NM-1FE-TX',
168 '2691' : 'NM-1FE-TX',
169 }
171 platform_option=""
172 if platform != '7200':
173 platform_option=' -P '+platform
174 npe_option=""
175 if platform == '7200':
176 npe_option=" -t "+npe_type
177 mac_option=' -m 00:16:3e:01:'+hex(N)[2:]+':01'
178 if platform != '7200':
179 mac_option =''
181 network_module=default_network_module[platform]
183 xenomips='dynamips /xenomips/ios/'+ios_name+platform_option+npe_option+mac_option
184 if platform== '7200':
185 for i in range(len(vbridges)-1):
186 xenomips += ' -p '+str(i+1)+':'+network_module
187 else:
188 for i in range(len(vbridges)-1):
189 xenomips += ' -p '+str(i+1)+':'+network_module
190 for i in range(len(vbridges)):
191 xenomips += ' -s '+str(i)+':0:gen_eth:eth'+str(i)
192 extra = "xenomips=\""+xenomips+"\""
193 elif domain_types[N] == 'pixemu':
194 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
195 extra = "xenomips=\""+xenomips+"\""
196 else:
197 if not domain_types[N] in ['freebsd','windows','linux'] :
198 raise "Unknown domain type %s of domain %s " % (domain_types[N], domains[N])
200 on_poweroff = 'destroy'
201 on_reboot = 'restart'
202 on_crash = 'restart'