rev |
line source |
igor@0
|
1 #!/usr/bin/python
|
igor@0
|
2
|
igor@9
|
3 import sys,re
|
igor@20
|
4 sys.path.append('/etc/xen')
|
igor@0
|
5
|
igor@10
|
6 def show_usage():
|
igor@10
|
7 print """
|
igor@10
|
8 Usage:
|
igor@10
|
9 xen-drbd-install <network> <command> (to view)
|
igor@10
|
10 xen-drbd-install <network> <command> | sh -s (to run)
|
igor@10
|
11
|
igor@30
|
12 <network> is the name of the file, which contains network description
|
igor@10
|
13
|
igor@10
|
14 Commands:
|
igor@10
|
15 make-drbd
|
igor@10
|
16 make-domains
|
igor@10
|
17 make-bridges
|
igor@10
|
18 make-links
|
igor@10
|
19 """
|
igor@10
|
20
|
igor@11
|
21 if len(sys.argv) != 3:
|
igor@10
|
22 show_usage()
|
igor@10
|
23 sys.exit(1)
|
igor@10
|
24
|
igor@10
|
25
|
igor@0
|
26 network=sys.argv[1]
|
igor@0
|
27 try:
|
igor@9
|
28 exec 'from %s import * ' % (network)
|
igor@23
|
29 except ImportError:
|
igor@2
|
30 print "Can't find or interpret module %s with topology description" %(network)
|
igor@2
|
31 sys.exit(1)
|
igor@0
|
32
|
igor@0
|
33 drbd_base_port=7790
|
igor@0
|
34 meta_disk='/dev/%s/meta'%lvm_vg_name
|
igor@2
|
35 drbd_device={}
|
igor@0
|
36
|
igor@33
|
37 linux_domains=[]
|
igor@33
|
38 for dom in domains:
|
igor@33
|
39 if domain_types[domains.index(dom)] == 'linux':
|
igor@33
|
40 linux_domains.append(dom)
|
igor@33
|
41
|
igor@2
|
42 def make_drbd_hash():
|
igor@2
|
43 for dom in domains:
|
igor@2
|
44 for disk in disk_table[dom]:
|
igor@2
|
45 if disk.find(":") == -1:
|
igor@36
|
46 if disk.find("=") == -1:
|
igor@36
|
47 drbd_device[disk]=dom
|
igor@36
|
48 else:
|
igor@36
|
49 drbd_device[disk.split('=')[0]]=dom
|
igor@2
|
50 else:
|
igor@36
|
51 disk0=disk.split(':')[0]
|
igor@36
|
52 drbd_device[disk0.split('=')[0]]=disk.split(':')[1]
|
igor@2
|
53
|
igor@2
|
54 def make_lvm():
|
igor@9
|
55 print "###################################################"
|
igor@9
|
56 print "# MAKE LVM FOR DOMAINS DRBD DEVICES"
|
igor@9
|
57 print "#"
|
igor@9
|
58 for lvm_pv_name in re.compile('\s+').split(lvm_pv_names):
|
igor@9
|
59 print "pvcreate %s" % (lvm_pv_name)
|
igor@9
|
60 print "vgcreate /dev/%s %s" % (lvm_vg_name, lvm_pv_names)
|
igor@9
|
61 print "lvcreate -L %s -n %s /dev/%s" % (lvm_lv_drbd_meta_size, lvm_lv_drbd_meta_name, lvm_vg_name)
|
igor@33
|
62 for dom in linux_domains:
|
igor@2
|
63 for disk in disk_table[dom]:
|
igor@2
|
64 if disk.find(":") == -1:
|
igor@2
|
65 #if do_print:
|
igor@2
|
66 # print "lvcreate -L %s -n %s /dev/%s" % (disk, dom, lvm_vg_name)
|
igor@2
|
67 #drbd_devices.append([dom, "/dev/%s/%s" % (lvm_vg_name, dom)])
|
igor@2
|
68 drbd_device[disk]=dom
|
igor@2
|
69 else:
|
igor@2
|
70 drbd_device[disk.split(':')[0]]=disk.split(':')[0]
|
igor@12
|
71 print "lvcreate -L %s -n %s /dev/%s" % (disk.split(':')[2], disk.split(':')[1], lvm_vg_name)
|
igor@9
|
72 #drbd_devices.append([disk.split(':')[0], "/dev/%s/%s" % (lvm_vg_name, disk.split(':')[0])])
|
igor@9
|
73 print ""
|
igor@0
|
74
|
igor@0
|
75
|
igor@0
|
76 def make_drbdconf():
|
igor@9
|
77 print "###################################################"
|
igor@9
|
78 print "# MAKE DRBD CONFIG FILE /etc/drbd.conf"
|
igor@9
|
79 print "#"
|
igor@9
|
80
|
igor@2
|
81 print "cat <<DRBD > /etc/drbd.conf"
|
igor@9
|
82
|
igor@9
|
83
|
igor@9
|
84 for dom in domains:
|
igor@9
|
85 for disk in disk_table[dom]:
|
igor@9
|
86 drbd_number=int(re.compile('drbd').sub('',disk.split(':')[0]))
|
igor@9
|
87 resource=disk.split(':')[1]
|
igor@9
|
88 disk="/dev/%s/%s" % (lvm_vg_name,resource)
|
igor@9
|
89
|
igor@9
|
90 print """
|
igor@0
|
91 resource %s {
|
igor@2
|
92 protocol C;
|
igor@2
|
93 net {
|
igor@2
|
94 allow-two-primaries;
|
igor@2
|
95 after-sb-0pri discard-least-changes;
|
igor@2
|
96 after-sb-1pri call-pri-lost-after-sb;
|
igor@2
|
97 after-sb-2pri call-pri-lost-after-sb;
|
igor@2
|
98 }
|
igor@2
|
99 syncer {
|
igor@2
|
100 rate 5M;
|
igor@2
|
101 }
|
igor@2
|
102 on %s
|
igor@2
|
103 {
|
igor@2
|
104 device /dev/drbd%s;
|
igor@2
|
105 disk %s;
|
igor@2
|
106 address %s:%s;
|
igor@2
|
107 meta-disk %s[%s];
|
igor@2
|
108 }
|
igor@2
|
109 on %s
|
igor@2
|
110 {
|
igor@2
|
111 device /dev/drbd%s;
|
igor@2
|
112 disk %s;
|
igor@2
|
113 address %s:%s;
|
igor@2
|
114 meta-disk %s[%s];
|
igor@2
|
115 }
|
igor@0
|
116 }
|
igor@0
|
117
|
igor@9
|
118 """ % (resource, node1, drbd_number, disk, node1_ip, drbd_number+drbd_base_port, meta_disk, drbd_number, node2, drbd_number, disk, node2_ip, drbd_number+drbd_base_port, meta_disk, drbd_number )
|
igor@9
|
119 print "DRBD"
|
igor@9
|
120 print ""
|
igor@9
|
121
|
igor@9
|
122
|
igor@9
|
123 def make_drbdmeta():
|
igor@9
|
124 print "###################################################"
|
igor@9
|
125 print "# MAKE DRBD DEVICES "
|
igor@9
|
126 print "#"
|
igor@13
|
127 print "yes yes | drbdadm create-md all"
|
igor@9
|
128
|
igor@9
|
129 def make_drbdprimary():
|
igor@9
|
130 print "###################################################"
|
igor@9
|
131 print "# SET DRBD DEVICES PRIMARY "
|
igor@9
|
132 print "#"
|
igor@9
|
133
|
igor@9
|
134 print "drbdadm up all"
|
igor@9
|
135 for dom in domains:
|
igor@9
|
136 for disk in disk_table[dom]:
|
igor@9
|
137 print "drbdsetup %s primary -o" % disk.split(':')[0]
|
igor@0
|
138
|
igor@0
|
139
|
igor@2
|
140 def make_links():
|
igor@2
|
141
|
igor@9
|
142 print "###################################################"
|
igor@9
|
143 print "# MAKE SYMBOLIC LINKS TO /dev/drbd* FILES"
|
igor@9
|
144 print "#"
|
igor@2
|
145
|
igor@2
|
146 # drbd_devices={
|
igor@2
|
147 # 'dev' : 'resource',
|
igor@2
|
148 # }
|
igor@2
|
149
|
igor@2
|
150 make_drbd_hash()
|
igor@2
|
151 print "mkdir -p /dev/drbd"
|
igor@2
|
152 for dev in drbd_device.keys():
|
igor@2
|
153 resource=drbd_device[dev]
|
igor@2
|
154 print "ln -sf /dev/%s /dev/drbd/%s" %(dev, resource)
|
igor@0
|
155
|
igor@0
|
156 def make_fs():
|
igor@9
|
157
|
igor@9
|
158 print "###################################################"
|
igor@9
|
159 print "# MAKE FILESYSTEMS ON THE DRBDs"
|
igor@9
|
160 print "#"
|
igor@9
|
161
|
igor@9
|
162 for dev in drbd_device.keys():
|
igor@9
|
163 print "mkfs.ext3 %s /dev/%s" %(mkfs_options,dev)
|
igor@0
|
164
|
igor@0
|
165
|
igor@0
|
166 def make_mount():
|
igor@9
|
167 print "###################################################"
|
igor@9
|
168 print "# MOUNT U-DOMAINS FILESYSTEMS"
|
igor@9
|
169 print "#"
|
igor@9
|
170
|
igor@2
|
171 print "mkdir -p /domU"
|
igor@33
|
172 for dom in linux_domains:
|
igor@2
|
173 print "mkdir -p /domU/%s" % (dom)
|
igor@2
|
174 print "mount /dev/drbd/%s /domU/%s" % (dom,dom)
|
igor@0
|
175
|
igor@0
|
176 def make_umount():
|
igor@33
|
177 for dom in linux_domains:
|
igor@2
|
178 print "umount /domU/%s" % (dom)
|
igor@0
|
179
|
igor@0
|
180 def make_dns():
|
igor@2
|
181 i=1
|
igor@33
|
182 for dom in linux_domains:
|
igor@2
|
183 print "%s A %s.%s" % (dom, ip_network, i)
|
igor@2
|
184 i+=1
|
igor@0
|
185
|
igor@0
|
186 def make_dns_reverse():
|
igor@2
|
187 i=1
|
igor@33
|
188 for dom in linux_domains:
|
igor@2
|
189 print "%s A %s.%s." % (i, dom, domain_name)
|
igor@2
|
190 i+=1
|
igor@0
|
191
|
igor@0
|
192 def make_install_debian():
|
igor@2
|
193 print """
|
igor@17
|
194 apt-get install debootstrap
|
igor@0
|
195 debootstrap %s /domU/%s %s
|
igor@0
|
196 chroot /domU/%s apt-get install -y --force-yes %s
|
igor@2
|
197 """ % (debian_release,domains[0],debian_mirror,domains[0],apt_get_install)
|
igor@0
|
198
|
igor@0
|
199 def make_rsync():
|
igor@2
|
200 for dom in domains[1:]:
|
igor@2
|
201 print """
|
igor@0
|
202 rsync -a /domU/%s/ /domU/%s/
|
igor@2
|
203 """ % (domains[0], dom)
|
igor@0
|
204
|
igor@0
|
205 def make_etcfstab():
|
igor@2
|
206 i=0
|
igor@33
|
207 for dom in linux_domains:
|
igor@2
|
208 i+=1
|
igor@2
|
209 print """
|
igor@0
|
210 cat <<FSTAB > /domU/%s/etc/fstab
|
igor@0
|
211 proc /proc proc defaults 0 0
|
igor@0
|
212 /dev/hda1 / ext3 defaults,errors=remount-ro 0 1
|
igor@0
|
213 FSTAB
|
igor@2
|
214 """ % (dom)
|
igor@0
|
215
|
igor@0
|
216 def make_etcnetworkinterfaces():
|
igor@2
|
217 i=0
|
igor@33
|
218 for dom in linux_domains:
|
igor@2
|
219 i+=1
|
igor@2
|
220 print """
|
igor@0
|
221 cat <<INTERFACES > /domU/%s/etc/network/interfaces
|
igor@0
|
222 auto lo eth0
|
igor@0
|
223 iface lo inet loopback
|
igor@0
|
224
|
igor@0
|
225 iface eth0 inet static
|
igor@9
|
226 address %s
|
igor@0
|
227 netmask 255.255.255.0
|
igor@0
|
228 network %s.0
|
igor@0
|
229 broadcast %s.255
|
igor@0
|
230 gateway %s
|
igor@0
|
231 dns-nameservers %s
|
igor@0
|
232 dns-search %s
|
igor@0
|
233 INTERFACES
|
igor@9
|
234 """ % (dom,ip_address_table[dom],ip_network, ip_network, ip_gateway, domain_name, ip_nameserver)
|
igor@0
|
235
|
igor@0
|
236 def make_etcresolvconf():
|
igor@33
|
237 for dom in linux_domains:
|
igor@2
|
238 print """
|
igor@0
|
239 cat <<RESOLVCONF > /domU/%s/etc/resolv.conf
|
igor@0
|
240 search %s
|
igor@0
|
241 nameserver %s
|
igor@0
|
242 RESOLVCONF
|
igor@2
|
243 """ % (dom,domain_name,ip_nameserver)
|
igor@0
|
244
|
igor@0
|
245 def make_etchostname():
|
igor@33
|
246 for dom in linux_domains:
|
igor@2
|
247 print """
|
igor@0
|
248 cat <<HOSTNAME > /domU/%s/etc/hostname
|
igor@0
|
249 %s
|
igor@0
|
250 HOSTNAME
|
igor@2
|
251 """ % (dom,dom)
|
igor@0
|
252
|
igor@0
|
253
|
igor@0
|
254 def make_etchosts():
|
igor@2
|
255 i=0
|
igor@33
|
256 for dom in linux_domains:
|
igor@2
|
257 i+=1
|
igor@2
|
258 print """
|
igor@0
|
259 cat <<HOSTS > /domU/%s/etc/hosts
|
igor@0
|
260 127.0.0.1 localhost
|
igor@9
|
261 %s %s.%s %s
|
igor@0
|
262
|
igor@0
|
263 ::1 ip6-localhost ip6-loopback
|
igor@0
|
264 fe00::0 ip6-localnet
|
igor@0
|
265 ff00::0 ip6-mcastprefix
|
igor@0
|
266 ff02::1 ip6-allnodes
|
igor@0
|
267 ff02::2 ip6-allrouters
|
igor@0
|
268 ff02::3 ip6-allhosts
|
igor@0
|
269 HOSTS
|
igor@9
|
270 """ % (dom,ip_address_table[dom],dom,domain_name,dom)
|
igor@0
|
271
|
igor@0
|
272 def make_rootssh():
|
igor@33
|
273 for dom in linux_domains:
|
igor@2
|
274 print """
|
igor@14
|
275 mkdir -p /domU/%s/home/eb/.ssh/
|
igor@14
|
276 chown -R 1000:1000 /domU/%s/home/eb
|
igor@0
|
277 cp ~/.ssh/id_dsa.pub /domU/%s/root/.ssh/authorized_keys
|
igor@14
|
278 chmod 600 /domU/%s/home/eb/.ssh/authorized_keys
|
igor@16
|
279 """ % (dom,dom,dom,dom)
|
igor@0
|
280
|
igor@0
|
281 def make_l3rc():
|
igor@33
|
282 for dom in linux_domains:
|
igor@2
|
283 print """
|
igor@2
|
284 cat <<EOF > /domU/%s/root/.l3rc
|
igor@0
|
285 l3cd=/users/igor/xen-drbd-dom0-setup/%s.%s/root
|
igor@0
|
286 EOF
|
igor@2
|
287 """ % (dom,dom,domain_name)
|
igor@0
|
288
|
igor@0
|
289
|
igor@0
|
290 def make_etc():
|
igor@2
|
291 make_etcfstab()
|
igor@2
|
292 make_etcnetworkinterfaces()
|
igor@2
|
293 make_etcresolvconf()
|
igor@2
|
294 make_etchosts()
|
igor@2
|
295 make_etchostname()
|
igor@2
|
296 make_rootssh()
|
igor@15
|
297 #make_l3rc()
|
igor@0
|
298
|
igor@9
|
299 def make_drbd():
|
igor@9
|
300 make_lvm()
|
igor@9
|
301 make_drbdconf()
|
igor@9
|
302 make_drbdmeta()
|
igor@9
|
303
|
igor@9
|
304 def make_domains():
|
igor@9
|
305 make_drbdprimary()
|
igor@9
|
306 make_links()
|
igor@2
|
307 make_fs()
|
igor@2
|
308 make_mount()
|
igor@2
|
309 make_install_debian()
|
igor@2
|
310 make_rsync()
|
igor@2
|
311 make_etc()
|
igor@2
|
312 make_umount()
|
igor@0
|
313
|
igor@0
|
314 def get_management_ip():
|
igor@2
|
315 return management_ip
|
igor@0
|
316
|
igor@0
|
317 def get_default_gateway():
|
igor@2
|
318 return management_gw
|
igor@0
|
319
|
igor@0
|
320 def make_bridges():
|
igor@2
|
321 ip=get_management_ip()
|
igor@2
|
322 gw=get_default_gateway()
|
igor@21
|
323 print "ifconfig %s 0.0.0.0 down" % (trunk)
|
igor@2
|
324
|
igor@2
|
325 # tagged interfaces
|
igor@2
|
326 for bridge in bridges:
|
igor@2
|
327 vlan=vlans[bridges.index(bridge)]
|
igor@2
|
328 if vlan == 'tagged':
|
igor@2
|
329 print "/etc/xen/scripts/network-bridge start vifnum=%s bridge=%s netdev=%s" % (bridges.index(bridge)+2,bridge,trunk)
|
igor@2
|
330 print "ip link set %s up" % (trunk)
|
igor@2
|
331
|
igor@2
|
332 # untagged interfaces
|
igor@2
|
333 for bridge in bridges:
|
igor@2
|
334 vlan=vlans[bridges.index(bridge)]
|
igor@2
|
335 if vlan != 'tagged':
|
igor@2
|
336 print "vconfig add %s %s" % (trunk,vlan)
|
igor@2
|
337 print "/etc/xen/scripts/network-bridge start vifnum=%s bridge=%s netdev=%s.%s" % (bridges.index(bridge)+2,bridge,trunk,vlan)
|
igor@2
|
338 print "ip link set %s.%s up" % (trunk,vlan)
|
igor@2
|
339
|
igor@22
|
340 print "ifconfig %s.%s %s netmask %s" % (trunk,management_vlan,management_ip,management_netmask)
|
igor@2
|
341 if management_gw:
|
igor@2
|
342 print "route add default gw %s" % (management_gw)
|
igor@0
|
343
|
igor@0
|
344
|
igor@0
|
345
|
igor@0
|
346 #make_all_system()
|
igor@0
|
347
|
igor@0
|
348 if len(sys.argv) > 1:
|
igor@2
|
349 command = sys.argv[2]
|
igor@9
|
350 if command == 'make-drbd':
|
igor@9
|
351 make_drbd()
|
igor@9
|
352 elif command == 'make-domains':
|
igor@9
|
353 make_domains()
|
igor@9
|
354 elif command == 'make-bridges':
|
igor@2
|
355 make_bridges()
|
igor@2
|
356 elif command == 'make-links':
|
igor@2
|
357 make_links()
|
igor@2
|
358 else:
|
igor@2
|
359 show_usage()
|
igor@0
|
360 else:
|
igor@2
|
361 show_usage()
|
igor@0
|
362
|