xen-drbd

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