xentaur

annotate xendomain.py @ 64:baf0c3300c19

update tags
author convert-repo
date Sun Jun 29 09:03:52 2008 +0000 (2008-06-29)
parents e838c1223b89
children cf823d27b029
rev   line source
igor@34 1 ####
igor@34 2 #
igor@34 3 # External variables:
igor@34 4 # * network
igor@34 5 # * domain
igor@34 6
igor@35 7 try:
igor@35 8 domain
igor@35 9 except NameError:
igor@35 10 import sys
igor@35 11 network=sys.modules['__main__'].network
igor@35 12 domain=sys.modules['__main__'].domain
igor@34 13
igor@61 14 import os
igor@61 15
nata@36 16 sys.path.append(os.environ['HOME']+"/xentaur")
igor@63 17 sys.path.append('.')
nata@36 18 os.environ['xendomain']=domain
nata@36 19
igor@58 20
igor@58 21
igor@47 22
igor@47 23 ############################
igor@47 24 # default values:
igor@58 25 platform=''
igor@47 26 npe_type='npe-400'
igor@47 27 bridge_bridge_table = {
igor@47 28 }
igor@47 29
igor@61 30 #try:
igor@61 31 # domains
igor@61 32 #except:
igor@61 33 # domains=[]
igor@61 34
igor@61 35
igor@58 36 domains_brief=[]
igor@58 37 domain_types=[]
igor@58 38 domain_notes=[]
igor@58 39 domain_subtypes=[]
igor@47 40 hidden_bridges = []
igor@47 41 broken_links = []
igor@47 42 temporary_links = []
igor@60 43 cross_bridges=[]
igor@47 44 real_bridges=[]
igor@47 45 real_nodes=[]
igor@61 46 connection_table={}
igor@61 47
igor@61 48 exec 'from %s import *' % (network)
igor@61 49
igor@58 50 # overriden by network config
igor@47 51 ############################
igor@47 52
igor@58 53 def process_domains_brief():
igor@61 54 # import sre
igor@61 55 #global domains_brief, domains, domain_types, real_nodes, domain_notes, domain_subtypes
igor@61 56 if len(domains_brief) >0 :
igor@61 57 node_brief_re=sre.compile('([a-zA-Z_0-9-]*)(?::([a-zA-Z_0-9-]*))?(?::([a-zA-Z_0-9-]*))?(\*?)(?:#(.*))?')
igor@61 58 if len(domains)==0:
igor@61 59 domains=map(lambda x:node_brief_re.search(x).groups()[0] or '', domains_brief)
igor@61 60 if len(domain_types)==0:
igor@61 61 domain_types=map(lambda x:node_brief_re.search(x).groups()[1] or '', domains_brief)
igor@61 62 if len(domain_subtypes)==0:
igor@61 63 domain_subtypes=map(lambda x:node_brief_re.search(x).groups()[2] or '', domains_brief)
igor@61 64 if len(real_nodes)==0:
igor@61 65 i=0
igor@61 66 for brief in domains_brief:
igor@61 67 if node_brief_re.search(brief).groups()[3] == '*':
igor@61 68 real_nodes.append(domains[i])
igor@61 69 i+=1
igor@61 70 if len(domain_notes)==0:
igor@61 71 domain_notes=map(lambda x:node_brief_re.search(x).groups()[4] or '', domains_brief)
igor@58 72
igor@58 73 ############################
igor@35 74 #try:
igor@35 75 #except:
igor@35 76 # print "Can't find or interpret module %s with topology description" %(network)
igor@35 77 # sys.exit(1)
igor@34 78
igor@61 79 #process_domains_brief()
igor@34 80
igor@59 81 N = domains.index(domain)
igor@35 82 name=domain
igor@34 83
igor@34 84 pae=1
igor@34 85 if pae:
igor@40 86 kernel = "/boot/vmlinuz-2.6.18-4-xen-686"
igor@40 87 ramdisk = "/boot/initrd.img-2.6.18-4-xen-686"
igor@34 88 else:
igor@34 89 kernel = "/boot/vmlinuz-2.6.18-without-PAE-4-xen-686"
igor@34 90 ramdisk = "/boot/initrd.img-2.6.18-without-PAE-4-xen-686-domU"
igor@34 91
igor@34 92 #builder='linux'
igor@34 93 cpu_cap = 10
igor@34 94
igor@62 95 hvm = 0
igor@62 96 if domain_types[N] in ['freebsd','windows']:
igor@62 97 hvm = 1
igor@59 98
igor@62 99 if hvm:
igor@62 100 kernel = "hvmloader"
igor@62 101 builder='hvm'
igor@62 102 shadow_memory = 8
igor@62 103 device_model = 'qemu-dm'
igor@62 104 boot="c"
igor@62 105 sdl=0
igor@62 106 vnc=1
igor@62 107 vncpasswd=''
igor@62 108 stdvga=0
igor@62 109 serial='pty'
igor@62 110 usb=1
igor@59 111
igor@59 112
igor@56 113 for br in bridges:
igor@56 114 if not br in vbridges_table.keys():
igor@56 115 vbridges_table[br]=[]
igor@56 116
igor@56 117 for domain in domains:
igor@56 118 if not domain in connection_table.keys():
igor@56 119 connection_table[domain]='true'
igor@34 120
igor@34 121 vbridges = vbridges_table[name]
igor@34 122
igor@34 123 vif=[]
igor@34 124 x=1
igor@34 125 for i in vbridges:
igor@62 126 if hvm:
igor@62 127 vif.append('bridge='+i+',type=ioemu,mac=00:16:3e:01:'+hex(N)[2:]+':'+hex(int('c0',16)+x)[2:])
igor@62 128 else:
igor@62 129 vif.append('bridge='+i+',mac=00:16:3e:01:'+hex(N)[2:]+':'+hex(int('c0',16)+x)[2:])
igor@34 130 x+=1
igor@34 131
igor@62 132 if domain_types[N] in ['xenomips','quagga','dynamips','pixemu']:
igor@62 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' ]
igor@62 134 else:
igor@62 135 if hvm:
igor@62 136 if domain_types[N] == 'linux':
igor@62 137 disk = [ 'file:/xen/xentaur-images/'+network+'/'+name+'.img,hda,w' ]
igor@62 138 else:
igor@62 139 disk = [ 'file:/xen/xentaur-images/'+network+'/'+name+'.img,hda,w', 'file:/xen/xentaur-images/'+network+'/'+name+'-disk2.img,hdb,w' ]
igor@62 140
igor@62 141 else:
igor@62 142 disk = [ 'file:/xen/xentaur-images/'+network+'/'+name+'.img,hda1,w' ]
igor@62 143
igor@34 144 root = "/dev/hda1 ro"
igor@34 145
igor@59 146 if domain_types[N] == 'quagga':
igor@59 147 memory = 64
igor@62 148 elif domain_types[N] == 'linux':
igor@63 149 memory = 128
igor@59 150 else:
igor@62 151 memory = 300
igor@59 152
igor@61 153 if len(domain_subtypes) >0 and domain_subtypes[N] != '' and platform == '':
igor@58 154 platform=domain_subtypes[N]
igor@58 155
igor@59 156 if platform == '':
igor@58 157 platform='7200'
igor@42 158
igor@34 159
igor@59 160 if domain_types[N] == 'quagga':
igor@34 161 extra = "quagga"
igor@61 162 elif domain_types[N] == 'dynamips':
igor@61 163 default_network_module={
igor@61 164 '7200' : 'PA-FE-TX',
igor@61 165 '3600' : 'NM-1FE-TX',
igor@61 166 '3725' : 'NM-1FE-TX',
igor@61 167 '3745' : 'NM-1FE-TX',
igor@61 168 '2691' : 'NM-1FE-TX',
igor@61 169 }
igor@61 170
igor@61 171 platform_option=""
igor@61 172 if platform != '7200':
igor@61 173 platform_option=' -P '+platform
igor@61 174 npe_option=""
igor@61 175 if platform == '7200':
igor@61 176 npe_option=" -t "+npe_type
igor@61 177 mac_option=' -m 00:16:3e:01:'+hex(N)[2:]+':01'
igor@61 178 if platform != '7200':
igor@61 179 mac_option =''
igor@61 180
igor@61 181 network_module=default_network_module[platform]
igor@61 182
igor@61 183 xenomips='dynamips /xenomips/ios/'+ios_name+platform_option+npe_option+mac_option
igor@61 184 if platform== '7200':
igor@61 185 for i in range(len(vbridges)-1):
igor@61 186 xenomips += ' -p '+str(i+1)+':'+network_module
igor@61 187 else:
igor@61 188 for i in range(len(vbridges)-1):
igor@61 189 xenomips += ' -p '+str(i+1)+':'+network_module
igor@61 190 for i in range(len(vbridges)):
igor@61 191 xenomips += ' -s '+str(i)+':0:gen_eth:eth'+str(i)
igor@61 192 extra = "xenomips=\""+xenomips+"\""
igor@61 193 elif domain_types[N] == 'pixemu':
igor@61 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
igor@61 195 extra = "xenomips=\""+xenomips+"\""
igor@34 196 else:
igor@62 197 if not domain_types[N] in ['freebsd','windows','linux'] :
igor@62 198 raise "Unknown domain type %s of domain %s " % (domain_types[N], domains[N])
igor@34 199
igor@34 200 on_poweroff = 'destroy'
igor@34 201 on_reboot = 'restart'
igor@34 202 on_crash = 'restart'
igor@34 203