xentaur

view xendomain.py @ 60:e7b9761c03e8

info() + logo()
author igor
date Sun Nov 11 20:57:50 2007 +0200 (2007-11-11)
parents 9d54d94a7dff
children 6471afbee150
line source
1 ####
2 #
3 # External variables:
4 # * network
5 # * domain
8 try:
9 domain
10 except NameError:
11 import sys
12 network=sys.modules['__main__'].network
13 domain=sys.modules['__main__'].domain
15 import os,re
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 domains_brief=[]
30 domains=[]
31 domain_types=[]
32 domain_notes=[]
33 domain_subtypes=[]
35 hidden_bridges = []
36 broken_links = []
37 temporary_links = []
38 cross_bridges=[]
40 real_bridges=[]
41 real_nodes=[]
42 # overriden by network config
43 ############################
45 def process_domains_brief():
46 global domains, domain_types, real_nodes, domain_notes, domain_subtypes
47 node_brief_re=re.compile('([a-zA-Z_0-9-]*)(?::([a-zA-Z_0-9-]*))?(?::([a-zA-Z_0-9-]*))?(\*?)(?:#(.*))?')
48 if len(domains)==0:
49 domains=map(lambda x:node_brief_re.search(x).groups()[0] or '', domains_brief)
50 if len(domain_types)==0:
51 domain_types=map(lambda x:node_brief_re.search(x).groups()[1] or '', domains_brief)
52 if len(domain_subtypes)==0:
53 domain_subtypes=map(lambda x:node_brief_re.search(x).groups()[2] or '', domains_brief)
54 if len(real_nodes)==0:
55 i=0
56 for brief in domains_brief:
57 if node_brief_re.search(brief).groups()[3] == '*':
58 real_nodes.append(domains[i])
59 i+=1
60 if len(domain_notes)==0:
61 domain_notes=map(lambda x:node_brief_re.search(x).groups()[4] or '', domains_brief)
63 ############################
64 #try:
65 exec 'from %s import *' % (network)
66 #except:
67 # print "Can't find or interpret module %s with topology description" %(network)
68 # sys.exit(1)
70 process_domains_brief()
72 N = domains.index(domain)
73 name=domain
75 pae=1
76 if pae:
77 kernel = "/boot/vmlinuz-2.6.18-4-xen-686"
78 ramdisk = "/boot/initrd.img-2.6.18-4-xen-686"
79 else:
80 kernel = "/boot/vmlinuz-2.6.18-without-PAE-4-xen-686"
81 ramdisk = "/boot/initrd.img-2.6.18-without-PAE-4-xen-686-domU"
83 #builder='linux'
84 cpu_cap = 10
89 for br in bridges:
90 if not br in vbridges_table.keys():
91 vbridges_table[br]=[]
93 for domain in domains:
94 if not domain in connection_table.keys():
95 connection_table[domain]='true'
97 vbridges = vbridges_table[name]
99 vif=[]
100 x=1
101 for i in vbridges:
102 vif.append('bridge='+i+',mac=00:16:3e:01:'+hex(N)[2:]+':'+hex(int('c0',16)+x)[2:])
103 x+=1
105 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' ]
106 root = "/dev/hda1 ro"
108 if domain_types[N] == 'quagga':
109 memory = 64
110 else:
111 memory = 400
113 if domain_subtypes[N] != '' and platform == '':
114 platform=domain_subtypes[N]
116 if platform == '':
117 platform='7200'
118 platform_option=""
119 if platform != '7200':
120 platform_option=' -P '+platform
122 npe_option=""
123 if platform == '7200':
124 npe_option=" -t "+npe_type
126 mac_option=' -m 00:16:3e:01:'+hex(N)[2:]+':01'
127 if platform != '7200':
128 mac_option =''
130 xenomips='/xenomips/ios/'+ios_name+platform_option+npe_option+mac_option
132 default_network_module={
133 '7200' : 'PA-FE-TX',
134 '3600' : 'NM-1FE-TX',
135 '3725' : 'NM-1FE-TX',
136 '3745' : 'NM-1FE-TX',
137 '2691' : 'NM-1FE-TX',
138 }
139 network_module=default_network_module[platform]
141 if platform== '7200':
142 for i in range(len(vbridges)-1):
143 xenomips += ' -p '+str(i+1)+':'+network_module
144 else:
145 for i in range(len(vbridges)-1):
146 xenomips += ' -p '+str(i+1)+':'+network_module
149 for i in range(len(vbridges)):
150 xenomips += ' -s '+str(i)+':0:gen_eth:eth'+str(i)
152 if domain_types[N] == 'quagga':
153 extra = "quagga"
154 else:
155 extra = "xenomips=\""+xenomips+"\""
157 on_poweroff = 'destroy'
158 on_reboot = 'restart'
159 on_crash = 'restart'