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