xentaur

annotate xendomain.py @ 58:58381d1fe31b

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