xentaur

annotate xendomain.py @ 61:6471afbee150

*** empty log message ***
author igor
date Mon Dec 03 08:36:13 2007 +0200 (2007-12-03)
parents e7b9761c03e8
children e838c1223b89
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@59 94
igor@59 95
igor@59 96
igor@56 97 for br in bridges:
igor@56 98 if not br in vbridges_table.keys():
igor@56 99 vbridges_table[br]=[]
igor@56 100
igor@56 101 for domain in domains:
igor@56 102 if not domain in connection_table.keys():
igor@56 103 connection_table[domain]='true'
igor@34 104
igor@34 105 vbridges = vbridges_table[name]
igor@34 106
igor@34 107 vif=[]
igor@34 108 x=1
igor@34 109 for i in vbridges:
igor@59 110 vif.append('bridge='+i+',mac=00:16:3e:01:'+hex(N)[2:]+':'+hex(int('c0',16)+x)[2:])
igor@34 111 x+=1
igor@34 112
igor@59 113 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@34 114 root = "/dev/hda1 ro"
igor@34 115
igor@59 116 if domain_types[N] == 'quagga':
igor@59 117 memory = 64
igor@59 118 else:
igor@59 119 memory = 400
igor@59 120
igor@61 121 if len(domain_subtypes) >0 and domain_subtypes[N] != '' and platform == '':
igor@58 122 platform=domain_subtypes[N]
igor@58 123
igor@59 124 if platform == '':
igor@58 125 platform='7200'
igor@42 126
igor@34 127
igor@59 128 if domain_types[N] == 'quagga':
igor@34 129 extra = "quagga"
igor@61 130 elif domain_types[N] == 'dynamips':
igor@61 131 default_network_module={
igor@61 132 '7200' : 'PA-FE-TX',
igor@61 133 '3600' : 'NM-1FE-TX',
igor@61 134 '3725' : 'NM-1FE-TX',
igor@61 135 '3745' : 'NM-1FE-TX',
igor@61 136 '2691' : 'NM-1FE-TX',
igor@61 137 }
igor@61 138
igor@61 139 platform_option=""
igor@61 140 if platform != '7200':
igor@61 141 platform_option=' -P '+platform
igor@61 142 npe_option=""
igor@61 143 if platform == '7200':
igor@61 144 npe_option=" -t "+npe_type
igor@61 145 mac_option=' -m 00:16:3e:01:'+hex(N)[2:]+':01'
igor@61 146 if platform != '7200':
igor@61 147 mac_option =''
igor@61 148
igor@61 149 network_module=default_network_module[platform]
igor@61 150
igor@61 151 xenomips='dynamips /xenomips/ios/'+ios_name+platform_option+npe_option+mac_option
igor@61 152 if platform== '7200':
igor@61 153 for i in range(len(vbridges)-1):
igor@61 154 xenomips += ' -p '+str(i+1)+':'+network_module
igor@61 155 else:
igor@61 156 for i in range(len(vbridges)-1):
igor@61 157 xenomips += ' -p '+str(i+1)+':'+network_module
igor@61 158 for i in range(len(vbridges)):
igor@61 159 xenomips += ' -s '+str(i)+':0:gen_eth:eth'+str(i)
igor@61 160 extra = "xenomips=\""+xenomips+"\""
igor@61 161 elif domain_types[N] == 'pixemu':
igor@61 162 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 163 extra = "xenomips=\""+xenomips+"\""
igor@34 164 else:
igor@61 165 raise "Unknown domain type %s of domain %s " % (domain_types[N], domains[N])
igor@34 166
igor@34 167 on_poweroff = 'destroy'
igor@34 168 on_reboot = 'restart'
igor@34 169 on_crash = 'restart'
igor@34 170