xentaur

annotate xendomain.py @ 60:e7b9761c03e8

info() + logo()
author igor
date Sun Nov 11 20:57:50 2007 +0200 (2007-11-11)
parents 9d54d94a7dff
children 6471afbee150
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@34 7
igor@35 8 try:
igor@35 9 domain
igor@35 10 except NameError:
igor@35 11 import sys
igor@35 12 network=sys.modules['__main__'].network
igor@35 13 domain=sys.modules['__main__'].domain
igor@34 14
igor@58 15 import os,re
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@58 29 domains_brief=[]
igor@58 30 domains=[]
igor@58 31 domain_types=[]
igor@58 32 domain_notes=[]
igor@58 33 domain_subtypes=[]
igor@58 34
igor@47 35 hidden_bridges = []
igor@47 36 broken_links = []
igor@47 37 temporary_links = []
igor@60 38 cross_bridges=[]
igor@47 39
igor@47 40 real_bridges=[]
igor@47 41 real_nodes=[]
igor@58 42 # overriden by network config
igor@47 43 ############################
igor@47 44
igor@58 45 def process_domains_brief():
igor@59 46 global domains, domain_types, real_nodes, domain_notes, domain_subtypes
igor@58 47 node_brief_re=re.compile('([a-zA-Z_0-9-]*)(?::([a-zA-Z_0-9-]*))?(?::([a-zA-Z_0-9-]*))?(\*?)(?:#(.*))?')
igor@58 48 if len(domains)==0:
igor@58 49 domains=map(lambda x:node_brief_re.search(x).groups()[0] or '', domains_brief)
igor@58 50 if len(domain_types)==0:
igor@58 51 domain_types=map(lambda x:node_brief_re.search(x).groups()[1] or '', domains_brief)
igor@58 52 if len(domain_subtypes)==0:
igor@58 53 domain_subtypes=map(lambda x:node_brief_re.search(x).groups()[2] or '', domains_brief)
igor@58 54 if len(real_nodes)==0:
igor@58 55 i=0
igor@58 56 for brief in domains_brief:
igor@58 57 if node_brief_re.search(brief).groups()[3] == '*':
igor@58 58 real_nodes.append(domains[i])
igor@58 59 i+=1
igor@58 60 if len(domain_notes)==0:
igor@58 61 domain_notes=map(lambda x:node_brief_re.search(x).groups()[4] or '', domains_brief)
igor@58 62
igor@58 63 ############################
igor@35 64 #try:
igor@35 65 exec 'from %s import *' % (network)
igor@35 66 #except:
igor@35 67 # print "Can't find or interpret module %s with topology description" %(network)
igor@35 68 # sys.exit(1)
igor@34 69
igor@58 70 process_domains_brief()
igor@34 71
igor@59 72 N = domains.index(domain)
igor@35 73 name=domain
igor@34 74
igor@34 75 pae=1
igor@34 76 if pae:
igor@40 77 kernel = "/boot/vmlinuz-2.6.18-4-xen-686"
igor@40 78 ramdisk = "/boot/initrd.img-2.6.18-4-xen-686"
igor@34 79 else:
igor@34 80 kernel = "/boot/vmlinuz-2.6.18-without-PAE-4-xen-686"
igor@34 81 ramdisk = "/boot/initrd.img-2.6.18-without-PAE-4-xen-686-domU"
igor@34 82
igor@34 83 #builder='linux'
igor@34 84 cpu_cap = 10
igor@34 85
igor@59 86
igor@59 87
igor@59 88
igor@56 89 for br in bridges:
igor@56 90 if not br in vbridges_table.keys():
igor@56 91 vbridges_table[br]=[]
igor@56 92
igor@56 93 for domain in domains:
igor@56 94 if not domain in connection_table.keys():
igor@56 95 connection_table[domain]='true'
igor@34 96
igor@34 97 vbridges = vbridges_table[name]
igor@34 98
igor@34 99 vif=[]
igor@34 100 x=1
igor@34 101 for i in vbridges:
igor@59 102 vif.append('bridge='+i+',mac=00:16:3e:01:'+hex(N)[2:]+':'+hex(int('c0',16)+x)[2:])
igor@34 103 x+=1
igor@34 104
igor@59 105 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 106 root = "/dev/hda1 ro"
igor@34 107
igor@59 108 if domain_types[N] == 'quagga':
igor@59 109 memory = 64
igor@59 110 else:
igor@59 111 memory = 400
igor@59 112
igor@58 113 if domain_subtypes[N] != '' and platform == '':
igor@58 114 platform=domain_subtypes[N]
igor@58 115
igor@59 116 if platform == '':
igor@58 117 platform='7200'
igor@42 118 platform_option=""
igor@42 119 if platform != '7200':
igor@42 120 platform_option=' -P '+platform
igor@42 121
igor@42 122 npe_option=""
igor@42 123 if platform == '7200':
igor@42 124 npe_option=" -t "+npe_type
igor@42 125
igor@59 126 mac_option=' -m 00:16:3e:01:'+hex(N)[2:]+':01'
igor@45 127 if platform != '7200':
igor@45 128 mac_option =''
igor@34 129
igor@45 130 xenomips='/xenomips/ios/'+ios_name+platform_option+npe_option+mac_option
igor@45 131
igor@45 132 default_network_module={
igor@44 133 '7200' : 'PA-FE-TX',
igor@44 134 '3600' : 'NM-1FE-TX',
igor@44 135 '3725' : 'NM-1FE-TX',
igor@44 136 '3745' : 'NM-1FE-TX',
igor@44 137 '2691' : 'NM-1FE-TX',
igor@44 138 }
igor@44 139 network_module=default_network_module[platform]
igor@44 140
igor@48 141 if platform== '7200':
igor@48 142 for i in range(len(vbridges)-1):
igor@48 143 xenomips += ' -p '+str(i+1)+':'+network_module
igor@48 144 else:
igor@48 145 for i in range(len(vbridges)-1):
igor@48 146 xenomips += ' -p '+str(i+1)+':'+network_module
igor@48 147
igor@34 148
igor@34 149 for i in range(len(vbridges)):
igor@34 150 xenomips += ' -s '+str(i)+':0:gen_eth:eth'+str(i)
igor@34 151
igor@59 152 if domain_types[N] == 'quagga':
igor@34 153 extra = "quagga"
igor@34 154 else:
igor@34 155 extra = "xenomips=\""+xenomips+"\""
igor@34 156
igor@34 157 on_poweroff = 'destroy'
igor@34 158 on_reboot = 'restart'
igor@34 159 on_crash = 'restart'
igor@34 160