xentaur

annotate xendomain.py @ 62:e838c1223b89

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