xen-drbd

annotate xen-drbd-start.py @ 61:e005bb283f54

minor fixes for usage with xen 3.4 (HVM)
author igor@book.xt.vpn
date Thu Jun 25 15:22:25 2009 +0300 (2009-06-25)
parents dd23766a87c6
children d9780d8380b9
rev   line source
igor@0 1 #!/usr/bin/python
igor@0 2
igor@0 3
igor@0 4 # External variables:
igor@0 5 # * network
igor@0 6 # * domain
igor@0 7
igor@0 8 import sys
igor@0 9
igor@38 10 #sys.path.append('/etc/xen')
igor@38 11
igor@0 12 try:
igor@40 13 execfile('/etc/xen/'+network)
igor@0 14 except:
igor@0 15 print "Can't find or interpret module %s with topology description" %(network)
igor@0 16 sys.exit(1)
igor@0 17
igor@0 18 name=domain
igor@0 19 N = domains.index(domain)
igor@0 20
igor@31 21 if domain_types[N] == 'hvm':
igor@31 22 kernel='hvmloader'
igor@31 23 builder='hvm'
igor@31 24 device_model='qemu-dm'
igor@31 25 boot='c'
igor@31 26 sdl=0
igor@31 27 vnc=1
igor@31 28 stdvga=0
igor@31 29 serial='pty'
igor@47 30 localtime=0
igor@45 31 else:
igor@45 32 root="/dev/hda1 ro"
igor@45 33 extra=""
igor@45 34
igor@45 35 try:
igor@45 36 execfile('/etc/xen/'+network)
igor@45 37 except:
igor@45 38 print "Can't find or interpret module %s with topology description" %(network)
igor@45 39 sys.exit(1)
igor@0 40
igor@60 41 try:
igor@60 42 hvmloader
igor@60 43 except:
igor@60 44 hvmloader='hvmloader'
igor@60 45
igor@46 46 if domain_types[N] == 'hvm':
igor@60 47 kernel=hvmloader
igor@46 48 builder='hvm'
igor@61 49 try:
igor@61 50 del extra
igor@61 51 except:
igor@61 52 pass
igor@61 53 try:
igor@61 54 del root
igor@61 55 except:
igor@61 56 pass
igor@61 57 try:
igor@61 58 del ramdisk
igor@61 59 except:
igor@61 60 pass
igor@46 61
igor@38 62 try:
igor@38 63 memory=mem_table[domain]
igor@38 64 except:
igor@38 65 pass
igor@38 66
igor@38 67 try:
igor@38 68 vcpus=vcpus_table[domain]
igor@38 69 except:
igor@38 70 pass
igor@0 71
igor@0 72 disk=[]
igor@32 73 if domain_types[N] == 'hvm':
igor@32 74 letters='abcdefghijklmnopqrstuvwxyz'
igor@32 75 i=0
igor@32 76 for disk_description in disk_table[domain]:
igor@32 77 i+=1
igor@32 78 if disk_description.find(":") == -1:
igor@36 79 disk_name=disk_description
igor@36 80 if disk_name.find("=") == -1:
igor@36 81 disk.append('phy:/dev/drbd/%s,hd%s,w' % (domain,letters[i-1]) )
igor@36 82 else:
igor@36 83 disk.append('phy:/dev/drbd/%s,%s,w' % (domain,(disk_name.split("="))[1]) )
igor@32 84 else:
igor@36 85 disk_name=(disk_description.split(':'))[0]
igor@36 86 if disk_name.find("=") == -1:
igor@36 87 disk.append('phy:/dev/drbd/%s,hd%s,w' % ((disk_description.split(':'))[1],letters[i-1]) )
igor@36 88 else:
igor@36 89 disk.append('phy:/dev/drbd/%s,%s,w' % ((disk_description.split(':'))[1],(disk_name.split("="))[1]) )
igor@36 90
igor@32 91 else:
igor@32 92 i=0
igor@32 93 for disk_description in disk_table[domain]:
igor@32 94 i+=1
igor@32 95 if disk_description.find(":") == -1:
igor@36 96 disk_name=disk_description
igor@36 97 if disk_name.find("=") == -1:
igor@36 98 disk.append('phy:/dev/drbd/%s,hda%s,w' % (domain,i) )
igor@36 99 else:
igor@36 100 disk.append('phy:/dev/drbd/%s,%s,w' % (domain,(disk_name.split("="))[1]) )
igor@32 101 else:
igor@36 102 disk_name=(disk_description.split(':'))[0]
igor@36 103 if disk_name.find("=") == -1:
igor@36 104 disk.append('phy:/dev/drbd/%s,hda%s,w' % ((disk_description.split(':'))[1],i) )
igor@36 105 else:
igor@36 106 disk.append('phy:/dev/drbd/%s,%s,w' % ((disk_description.split(':'))[1],(disk_name.split("="))[1]) )
igor@0 107
igor@0 108 vif=[]
igor@0 109 vbridges = vbridges_table[domain]
igor@0 110 x=1
igor@0 111 for i in vbridges:
igor@31 112 if domain_types[N] == 'hvm':
igor@31 113 vif.append('type=ioemu, bridge='+i+',mac=00:16:3e:01:'+hex(int(N))[2:]+':'+hex(int('c0',16)+x)[2:])
igor@31 114 else:
igor@31 115 vif.append('bridge='+i+',mac=00:16:3e:01:'+hex(int(N))[2:]+':'+hex(int('c0',16)+x)[2:])
igor@31 116 x+=1
igor@31 117
igor@0 118
igor@0 119
igor@0 120 def print_config():
igor@31 121 if domain_types[N] == 'hvm':
igor@31 122 print "name = \"%s\""% name
igor@31 123 print "kernel = \"%s\""% kernel
igor@31 124 print "builder = \"%s\""% builder
igor@31 125 print "memory = %s"% memory
igor@31 126 print "device_model=\"%s\"" % device_model
igor@31 127 print "vcpus = %s"% vcpus
igor@31 128 print "disk =", disk
igor@31 129 print "vif =", vif
igor@31 130 print "boot=\"%s\""%boot
igor@31 131 print "sdl=%s"%sdl
igor@31 132 print "vnc=%s"%vnc
igor@47 133 print "localtime=%s"%localtime
igor@31 134 print "stdvga=%s"%stdvga
igor@31 135 print "serial=\"%s\""%serial
igor@31 136 else:
igor@31 137 print "name = \"%s\""% name
igor@41 138 try:
igor@41 139 print "kernel = \"%s\""% kernel
igor@41 140 except:
igor@41 141 pass
igor@41 142 try:
igor@41 143 print "ramdisk = \"%s\""% ramdisk
igor@41 144 except:
igor@41 145 pass
igor@31 146 print "memory = %s"% memory
igor@31 147 print "vcpus = %s"% vcpus
igor@31 148 print "disk =", disk
igor@31 149 print "vif =", vif
igor@31 150 print "root = \"%s\""% root
igor@31 151 print "extra = \"%s\""% extra
igor@41 152 try:
igor@41 153 print "bootloader = \"%s\""% bootloader
igor@41 154 except:
igor@41 155 pass
igor@41 156
igor@31 157 # else:
igor@0 158
igor@61 159 try:
igor@61 160 del domain, N, x, i, node1, node2, ip_address, node1_ip, node2_ip, domains, domain_types, domain_home, mem_table, vcpus_table, disk_table, lvm_pv, lvm_vg_name, bridges, vlans, management_interface, trunk, vbridges_table, domain_name
igor@61 161 except:
igor@61 162 pass