xentaur

annotate xendomain.py @ 65:cf823d27b029

Nattaur changes
author nata@nattaur
date Mon Oct 12 00:12:11 2009 +0300 (2009-10-12)
parents 07c6777758dc
children aaf034af3a35
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@65 16 sys.path.append("/xentaur/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
nata@65 84 try:
nata@65 85 kernel
nata@65 86 except:
nata@65 87 pae=1
nata@65 88 if pae:
nata@65 89 kernel="/boot/vmlinuz-2.6.18-6-xen-686"
nata@65 90 ramdisk = "/boot/initrd.img-2.6.18-6-xen-686"
nata@65 91 else:
nata@65 92 kernel = "/boot/vmlinuz-2.6.18-without-PAE-4-xen-686"
nata@65 93 ramdisk = "/boot/initrd.img-2.6.18-without-PAE-4-xen-686-domU"
igor@34 94
igor@34 95 #builder='linux'
igor@34 96 cpu_cap = 10
igor@34 97
igor@62 98 hvm = 0
igor@62 99 if domain_types[N] in ['freebsd','windows']:
igor@62 100 hvm = 1
igor@59 101
igor@62 102 if hvm:
igor@62 103 kernel = "hvmloader"
igor@62 104 builder='hvm'
igor@62 105 shadow_memory = 8
igor@62 106 device_model = 'qemu-dm'
igor@62 107 boot="c"
igor@62 108 sdl=0
igor@62 109 vnc=1
igor@62 110 vncpasswd=''
igor@62 111 stdvga=0
igor@62 112 serial='pty'
igor@62 113 usb=1
igor@59 114
igor@59 115
igor@56 116 for br in bridges:
igor@56 117 if not br in vbridges_table.keys():
igor@56 118 vbridges_table[br]=[]
igor@56 119
igor@56 120 for domain in domains:
igor@56 121 if not domain in connection_table.keys():
igor@56 122 connection_table[domain]='true'
igor@34 123
igor@34 124 vbridges = vbridges_table[name]
igor@34 125
igor@34 126 vif=[]
igor@34 127 x=1
igor@34 128 for i in vbridges:
igor@62 129 if hvm:
igor@62 130 vif.append('bridge='+i+',type=ioemu,mac=00:16:3e:01:'+hex(N)[2:]+':'+hex(int('c0',16)+x)[2:])
igor@62 131 else:
igor@62 132 vif.append('bridge='+i+',mac=00:16:3e:01:'+hex(N)[2:]+':'+hex(int('c0',16)+x)[2:])
igor@34 133 x+=1
igor@34 134
igor@62 135 if domain_types[N] in ['xenomips','quagga','dynamips','pixemu']:
igor@62 136 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 137 else:
igor@62 138 if hvm:
igor@62 139 if domain_types[N] == 'linux':
nata@65 140 disk = [ 'file:/xentaur/images/'+network+'/'+name+'.img,hda,w' ]
igor@62 141 else:
nata@65 142 disk = [ 'file:/xentaur/images/'+network+'/'+name+'.img,hda,w', 'file:/xen/xentaur-images/'+network+'/'+name+'-disk2.img,hdb,w' ]
igor@62 143
igor@62 144 else:
nata@65 145 disk = [ 'file:/xentaur/images/'+network+'/'+name+'.img,hda1,w' ]
igor@62 146
igor@34 147 root = "/dev/hda1 ro"
igor@34 148
igor@59 149 if domain_types[N] == 'quagga':
igor@59 150 memory = 64
igor@62 151 elif domain_types[N] == 'linux':
igor@63 152 memory = 128
igor@59 153 else:
igor@62 154 memory = 300
igor@59 155
igor@61 156 if len(domain_subtypes) >0 and domain_subtypes[N] != '' and platform == '':
igor@58 157 platform=domain_subtypes[N]
igor@58 158
igor@59 159 if platform == '':
igor@58 160 platform='7200'
igor@42 161
igor@34 162
igor@59 163 if domain_types[N] == 'quagga':
igor@34 164 extra = "quagga"
igor@61 165 elif domain_types[N] == 'dynamips':
igor@61 166 default_network_module={
igor@61 167 '7200' : 'PA-FE-TX',
igor@61 168 '3600' : 'NM-1FE-TX',
igor@61 169 '3725' : 'NM-1FE-TX',
igor@61 170 '3745' : 'NM-1FE-TX',
igor@61 171 '2691' : 'NM-1FE-TX',
igor@61 172 }
igor@61 173
igor@61 174 platform_option=""
igor@61 175 if platform != '7200':
igor@61 176 platform_option=' -P '+platform
igor@61 177 npe_option=""
igor@61 178 if platform == '7200':
igor@61 179 npe_option=" -t "+npe_type
igor@61 180 mac_option=' -m 00:16:3e:01:'+hex(N)[2:]+':01'
igor@61 181 if platform != '7200':
igor@61 182 mac_option =''
igor@61 183
igor@61 184 network_module=default_network_module[platform]
igor@61 185
igor@61 186 xenomips='dynamips /xenomips/ios/'+ios_name+platform_option+npe_option+mac_option
igor@61 187 if platform== '7200':
igor@61 188 for i in range(len(vbridges)-1):
igor@61 189 xenomips += ' -p '+str(i+1)+':'+network_module
igor@61 190 else:
igor@61 191 for i in range(len(vbridges)-1):
igor@61 192 xenomips += ' -p '+str(i+1)+':'+network_module
igor@61 193 for i in range(len(vbridges)):
nata@65 194 xenomips += ' -s '+str(i)+':0:linux_eth:eth'+str(i)
igor@61 195 extra = "xenomips=\""+xenomips+"\""
igor@61 196 elif domain_types[N] == 'pixemu':
igor@61 197 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 198 extra = "xenomips=\""+xenomips+"\""
igor@34 199 else:
igor@62 200 if not domain_types[N] in ['freebsd','windows','linux'] :
igor@62 201 raise "Unknown domain type %s of domain %s " % (domain_types[N], domains[N])
igor@34 202
igor@34 203 on_poweroff = 'destroy'
igor@34 204 on_reboot = 'restart'
igor@34 205 on_crash = 'restart'
igor@34 206