xentaur

annotate xendomain.py @ 66:aaf034af3a35

Merge of Xgurulla into Xentaur code. Not completed yet!!!

Now Xentaur can work with Amazon EC2,
but only with. Local domains management
is switched off temporarily.
author Igor Chubin <igor@chub.in>
date Sat Jan 09 20:20:08 2010 +0200 (2010-01-09)
parents cf823d27b029
children
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@66 48 #exec 'from %s import *' % (network)
igor@66 49 from network import *
igor@61 50
igor@58 51 # overriden by network config
igor@47 52 ############################
igor@47 53
igor@58 54 def process_domains_brief():
igor@61 55 # import sre
igor@61 56 #global domains_brief, domains, domain_types, real_nodes, domain_notes, domain_subtypes
igor@61 57 if len(domains_brief) >0 :
igor@61 58 node_brief_re=sre.compile('([a-zA-Z_0-9-]*)(?::([a-zA-Z_0-9-]*))?(?::([a-zA-Z_0-9-]*))?(\*?)(?:#(.*))?')
igor@61 59 if len(domains)==0:
igor@61 60 domains=map(lambda x:node_brief_re.search(x).groups()[0] or '', domains_brief)
igor@61 61 if len(domain_types)==0:
igor@61 62 domain_types=map(lambda x:node_brief_re.search(x).groups()[1] or '', domains_brief)
igor@61 63 if len(domain_subtypes)==0:
igor@61 64 domain_subtypes=map(lambda x:node_brief_re.search(x).groups()[2] or '', domains_brief)
igor@61 65 if len(real_nodes)==0:
igor@61 66 i=0
igor@61 67 for brief in domains_brief:
igor@61 68 if node_brief_re.search(brief).groups()[3] == '*':
igor@61 69 real_nodes.append(domains[i])
igor@61 70 i+=1
igor@61 71 if len(domain_notes)==0:
igor@61 72 domain_notes=map(lambda x:node_brief_re.search(x).groups()[4] or '', domains_brief)
igor@58 73
igor@58 74 ############################
igor@35 75 #try:
igor@35 76 #except:
igor@35 77 # print "Can't find or interpret module %s with topology description" %(network)
igor@35 78 # sys.exit(1)
igor@34 79
igor@61 80 #process_domains_brief()
igor@34 81
igor@59 82 N = domains.index(domain)
igor@35 83 name=domain
igor@34 84
nata@65 85 try:
nata@65 86 kernel
nata@65 87 except:
nata@65 88 pae=1
nata@65 89 if pae:
nata@65 90 kernel="/boot/vmlinuz-2.6.18-6-xen-686"
nata@65 91 ramdisk = "/boot/initrd.img-2.6.18-6-xen-686"
nata@65 92 else:
nata@65 93 kernel = "/boot/vmlinuz-2.6.18-without-PAE-4-xen-686"
nata@65 94 ramdisk = "/boot/initrd.img-2.6.18-without-PAE-4-xen-686-domU"
igor@34 95
igor@34 96 #builder='linux'
igor@34 97 cpu_cap = 10
igor@34 98
igor@62 99 hvm = 0
igor@62 100 if domain_types[N] in ['freebsd','windows']:
igor@62 101 hvm = 1
igor@59 102
igor@62 103 if hvm:
igor@62 104 kernel = "hvmloader"
igor@62 105 builder='hvm'
igor@62 106 shadow_memory = 8
igor@62 107 device_model = 'qemu-dm'
igor@62 108 boot="c"
igor@62 109 sdl=0
igor@62 110 vnc=1
igor@62 111 vncpasswd=''
igor@62 112 stdvga=0
igor@62 113 serial='pty'
igor@62 114 usb=1
igor@59 115
igor@59 116
igor@56 117 for br in bridges:
igor@56 118 if not br in vbridges_table.keys():
igor@56 119 vbridges_table[br]=[]
igor@56 120
igor@56 121 for domain in domains:
igor@56 122 if not domain in connection_table.keys():
igor@56 123 connection_table[domain]='true'
igor@34 124
igor@34 125 vbridges = vbridges_table[name]
igor@34 126
igor@34 127 vif=[]
igor@34 128 x=1
igor@34 129 for i in vbridges:
igor@62 130 if hvm:
igor@62 131 vif.append('bridge='+i+',type=ioemu,mac=00:16:3e:01:'+hex(N)[2:]+':'+hex(int('c0',16)+x)[2:])
igor@62 132 else:
igor@62 133 vif.append('bridge='+i+',mac=00:16:3e:01:'+hex(N)[2:]+':'+hex(int('c0',16)+x)[2:])
igor@34 134 x+=1
igor@34 135
igor@62 136 if domain_types[N] in ['xenomips','quagga','dynamips','pixemu']:
igor@62 137 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 138 else:
igor@62 139 if hvm:
igor@62 140 if domain_types[N] == 'linux':
nata@65 141 disk = [ 'file:/xentaur/images/'+network+'/'+name+'.img,hda,w' ]
igor@62 142 else:
nata@65 143 disk = [ 'file:/xentaur/images/'+network+'/'+name+'.img,hda,w', 'file:/xen/xentaur-images/'+network+'/'+name+'-disk2.img,hdb,w' ]
igor@62 144
igor@62 145 else:
nata@65 146 disk = [ 'file:/xentaur/images/'+network+'/'+name+'.img,hda1,w' ]
igor@62 147
igor@34 148 root = "/dev/hda1 ro"
igor@34 149
igor@59 150 if domain_types[N] == 'quagga':
igor@59 151 memory = 64
igor@62 152 elif domain_types[N] == 'linux':
igor@63 153 memory = 128
igor@59 154 else:
igor@62 155 memory = 300
igor@59 156
igor@61 157 if len(domain_subtypes) >0 and domain_subtypes[N] != '' and platform == '':
igor@58 158 platform=domain_subtypes[N]
igor@58 159
igor@59 160 if platform == '':
igor@58 161 platform='7200'
igor@42 162
igor@34 163
igor@59 164 if domain_types[N] == 'quagga':
igor@34 165 extra = "quagga"
igor@61 166 elif domain_types[N] == 'dynamips':
igor@61 167 default_network_module={
igor@61 168 '7200' : 'PA-FE-TX',
igor@61 169 '3600' : 'NM-1FE-TX',
igor@61 170 '3725' : 'NM-1FE-TX',
igor@61 171 '3745' : 'NM-1FE-TX',
igor@61 172 '2691' : 'NM-1FE-TX',
igor@61 173 }
igor@61 174
igor@61 175 platform_option=""
igor@61 176 if platform != '7200':
igor@61 177 platform_option=' -P '+platform
igor@61 178 npe_option=""
igor@61 179 if platform == '7200':
igor@61 180 npe_option=" -t "+npe_type
igor@61 181 mac_option=' -m 00:16:3e:01:'+hex(N)[2:]+':01'
igor@61 182 if platform != '7200':
igor@61 183 mac_option =''
igor@61 184
igor@61 185 network_module=default_network_module[platform]
igor@61 186
igor@61 187 xenomips='dynamips /xenomips/ios/'+ios_name+platform_option+npe_option+mac_option
igor@61 188 if platform== '7200':
igor@61 189 for i in range(len(vbridges)-1):
igor@61 190 xenomips += ' -p '+str(i+1)+':'+network_module
igor@61 191 else:
igor@61 192 for i in range(len(vbridges)-1):
igor@61 193 xenomips += ' -p '+str(i+1)+':'+network_module
igor@61 194 for i in range(len(vbridges)):
nata@65 195 xenomips += ' -s '+str(i)+':0:linux_eth:eth'+str(i)
igor@61 196 extra = "xenomips=\""+xenomips+"\""
igor@61 197 elif domain_types[N] == 'pixemu':
igor@61 198 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 199 extra = "xenomips=\""+xenomips+"\""
igor@34 200 else:
igor@62 201 if not domain_types[N] in ['freebsd','windows','linux'] :
igor@62 202 raise "Unknown domain type %s of domain %s " % (domain_types[N], domains[N])
igor@34 203
igor@34 204 on_poweroff = 'destroy'
igor@34 205 on_reboot = 'restart'
igor@34 206 on_crash = 'restart'
igor@34 207