xentaur

view xendomain.py @ 62:e838c1223b89

Делаются какие-то попытки интегрировать в Xentaur
управление разнообразными доменами.
author igor
date Thu Feb 21 21:41:20 2008 +0200 (2008-02-21)
parents 6471afbee150
children 07c6777758dc
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
94 hvm = 0
95 if domain_types[N] in ['freebsd','windows']:
96 hvm = 1
98 if hvm:
99 kernel = "hvmloader"
100 builder='hvm'
101 shadow_memory = 8
102 device_model = 'qemu-dm'
103 boot="c"
104 sdl=0
105 vnc=1
106 vncpasswd=''
107 stdvga=0
108 serial='pty'
109 usb=1
112 for br in bridges:
113 if not br in vbridges_table.keys():
114 vbridges_table[br]=[]
116 for domain in domains:
117 if not domain in connection_table.keys():
118 connection_table[domain]='true'
120 vbridges = vbridges_table[name]
122 vif=[]
123 x=1
124 for i in vbridges:
125 if hvm:
126 vif.append('bridge='+i+',type=ioemu,mac=00:16:3e:01:'+hex(N)[2:]+':'+hex(int('c0',16)+x)[2:])
127 else:
128 vif.append('bridge='+i+',mac=00:16:3e:01:'+hex(N)[2:]+':'+hex(int('c0',16)+x)[2:])
129 x+=1
131 if domain_types[N] in ['xenomips','quagga','dynamips','pixemu']:
132 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' ]
133 else:
134 if hvm:
135 if domain_types[N] == 'linux':
136 disk = [ 'file:/xen/xentaur-images/'+network+'/'+name+'.img,hda,w' ]
137 else:
138 disk = [ 'file:/xen/xentaur-images/'+network+'/'+name+'.img,hda,w', 'file:/xen/xentaur-images/'+network+'/'+name+'-disk2.img,hdb,w' ]
140 else:
141 disk = [ 'file:/xen/xentaur-images/'+network+'/'+name+'.img,hda1,w' ]
143 root = "/dev/hda1 ro"
145 if domain_types[N] == 'quagga':
146 memory = 64
147 elif domain_types[N] == 'linux':
148 memory = 550
149 else:
150 memory = 300
152 if len(domain_subtypes) >0 and domain_subtypes[N] != '' and platform == '':
153 platform=domain_subtypes[N]
155 if platform == '':
156 platform='7200'
159 if domain_types[N] == 'quagga':
160 extra = "quagga"
161 elif domain_types[N] == 'dynamips':
162 default_network_module={
163 '7200' : 'PA-FE-TX',
164 '3600' : 'NM-1FE-TX',
165 '3725' : 'NM-1FE-TX',
166 '3745' : 'NM-1FE-TX',
167 '2691' : 'NM-1FE-TX',
168 }
170 platform_option=""
171 if platform != '7200':
172 platform_option=' -P '+platform
173 npe_option=""
174 if platform == '7200':
175 npe_option=" -t "+npe_type
176 mac_option=' -m 00:16:3e:01:'+hex(N)[2:]+':01'
177 if platform != '7200':
178 mac_option =''
180 network_module=default_network_module[platform]
182 xenomips='dynamips /xenomips/ios/'+ios_name+platform_option+npe_option+mac_option
183 if platform== '7200':
184 for i in range(len(vbridges)-1):
185 xenomips += ' -p '+str(i+1)+':'+network_module
186 else:
187 for i in range(len(vbridges)-1):
188 xenomips += ' -p '+str(i+1)+':'+network_module
189 for i in range(len(vbridges)):
190 xenomips += ' -s '+str(i)+':0:gen_eth:eth'+str(i)
191 extra = "xenomips=\""+xenomips+"\""
192 elif domain_types[N] == 'pixemu':
193 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
194 extra = "xenomips=\""+xenomips+"\""
195 else:
196 if not domain_types[N] in ['freebsd','windows','linux'] :
197 raise "Unknown domain type %s of domain %s " % (domain_types[N], domains[N])
199 on_poweroff = 'destroy'
200 on_reboot = 'restart'
201 on_crash = 'restart'