xentaur
view xendomain.py @ 58:58381d1fe31b
domains_brief support
author | igor |
---|---|
date | Sun Nov 11 19:22:52 2007 +0200 (2007-11-11) |
parents | 308b524d9a70 |
children | 9d54d94a7dff |
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 = []
39 real_bridges=[]
40 real_nodes=[]
41 # overriden by network config
42 ############################
44 def process_domains_brief():
45 global domains, domain_types, real_nodes, domain_notes
46 node_brief_re=re.compile('([a-zA-Z_0-9-]*)(?::([a-zA-Z_0-9-]*))?(?::([a-zA-Z_0-9-]*))?(\*?)(?:#(.*))?')
47 if len(domains)==0:
48 domains=map(lambda x:node_brief_re.search(x).groups()[0] or '', domains_brief)
49 if len(domain_types)==0:
50 domain_types=map(lambda x:node_brief_re.search(x).groups()[1] or '', domains_brief)
51 if len(domain_subtypes)==0:
52 domain_subtypes=map(lambda x:node_brief_re.search(x).groups()[2] or '', domains_brief)
53 if len(real_nodes)==0:
54 i=0
55 for brief in domains_brief:
56 if node_brief_re.search(brief).groups()[3] == '*':
57 real_nodes.append(domains[i])
58 i+=1
59 if len(domain_notes)==0:
60 domain_notes=map(lambda x:node_brief_re.search(x).groups()[4] or '', domains_brief)
62 ############################
63 #try:
64 exec 'from %s import *' % (network)
65 #except:
66 # print "Can't find or interpret module %s with topology description" %(network)
67 # sys.exit(1)
69 process_domains_brief()
71 N = str(domains.index(domain))
72 name=domain
74 pae=1
75 if pae:
76 kernel = "/boot/vmlinuz-2.6.18-4-xen-686"
77 ramdisk = "/boot/initrd.img-2.6.18-4-xen-686"
78 else:
79 kernel = "/boot/vmlinuz-2.6.18-without-PAE-4-xen-686"
80 ramdisk = "/boot/initrd.img-2.6.18-without-PAE-4-xen-686-domU"
82 #builder='linux'
83 cpu_cap = 10
85 for br in bridges:
86 if not br in vbridges_table.keys():
87 vbridges_table[br]=[]
89 for domain in domains:
90 if not domain in connection_table.keys():
91 connection_table[domain]='true'
93 vbridges = vbridges_table[name]
95 vif=[]
96 x=1
97 for i in vbridges:
98 vif.append('bridge='+i+',mac=00:16:3e:01:'+hex(int(N))[2:]+':'+hex(int('c0',16)+x)[2:])
99 x+=1
101 disk = [ 'file:'+xenomips_dir+'xenomips1.img,hda1,r', 'file:'+xenomips_dir+'xenomips-ios1.img,hda2,r', 'file:'+xenomips_dir+'xenomips-config'+N+'.img,hda3,w' ]
102 root = "/dev/hda1 ro"
104 if domain_subtypes[N] != '' and platform == '':
105 platform=domain_subtypes[N]
107 if platform = '':
108 platform='7200'
109 platform_option=""
110 if platform != '7200':
111 platform_option=' -P '+platform
113 npe_option=""
114 if platform == '7200':
115 npe_option=" -t "+npe_type
117 mac_option=' -m 00:16:3e:01:'+hex(int(N))[2:]+':01'
118 if platform != '7200':
119 mac_option =''
121 xenomips='/xenomips/ios/'+ios_name+platform_option+npe_option+mac_option
123 default_network_module={
124 '7200' : 'PA-FE-TX',
125 '3600' : 'NM-1FE-TX',
126 '3725' : 'NM-1FE-TX',
127 '3745' : 'NM-1FE-TX',
128 '2691' : 'NM-1FE-TX',
129 }
130 network_module=default_network_module[platform]
132 if platform== '7200':
133 for i in range(len(vbridges)-1):
134 xenomips += ' -p '+str(i+1)+':'+network_module
135 else:
136 for i in range(len(vbridges)-1):
137 xenomips += ' -p '+str(i+1)+':'+network_module
140 for i in range(len(vbridges)):
141 xenomips += ' -s '+str(i)+':0:gen_eth:eth'+str(i)
143 if domain_types[int(N)] == 'quagga':
144 extra = "quagga"
145 else:
146 extra = "xenomips=\""+xenomips+"\""
148 on_poweroff = 'destroy'
149 on_reboot = 'restart'
150 on_crash = 'restart'