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@0
|
184 debootstrap %s /domU/%s %s
|
igor@0
|
185 chroot /domU/%s apt-get install -y --force-yes %s
|
igor@2
|
186 """ % (debian_release,domains[0],debian_mirror,domains[0],apt_get_install)
|
igor@0
|
187
|
igor@0
|
188 def make_rsync():
|
igor@2
|
189 for dom in domains[1:]:
|
igor@2
|
190 print """
|
igor@0
|
191 rsync -a /domU/%s/ /domU/%s/
|
igor@2
|
192 """ % (domains[0], dom)
|
igor@0
|
193
|
igor@0
|
194 def make_etcfstab():
|
igor@2
|
195 i=0
|
igor@2
|
196 for dom in domains:
|
igor@2
|
197 i+=1
|
igor@2
|
198 print """
|
igor@0
|
199 cat <<FSTAB > /domU/%s/etc/fstab
|
igor@0
|
200 proc /proc proc defaults 0 0
|
igor@0
|
201 /dev/hda1 / ext3 defaults,errors=remount-ro 0 1
|
igor@0
|
202 FSTAB
|
igor@2
|
203 """ % (dom)
|
igor@0
|
204
|
igor@0
|
205 def make_etcnetworkinterfaces():
|
igor@2
|
206 i=0
|
igor@2
|
207 for dom in domains:
|
igor@2
|
208 i+=1
|
igor@2
|
209 print """
|
igor@0
|
210 cat <<INTERFACES > /domU/%s/etc/network/interfaces
|
igor@0
|
211 auto lo eth0
|
igor@0
|
212 iface lo inet loopback
|
igor@0
|
213
|
igor@0
|
214 iface eth0 inet static
|
igor@9
|
215 address %s
|
igor@0
|
216 netmask 255.255.255.0
|
igor@0
|
217 network %s.0
|
igor@0
|
218 broadcast %s.255
|
igor@0
|
219 gateway %s
|
igor@0
|
220 dns-nameservers %s
|
igor@0
|
221 dns-search %s
|
igor@0
|
222 INTERFACES
|
igor@9
|
223 """ % (dom,ip_address_table[dom],ip_network, ip_network, ip_gateway, domain_name, ip_nameserver)
|
igor@0
|
224
|
igor@0
|
225 def make_etcresolvconf():
|
igor@2
|
226 for dom in domains:
|
igor@2
|
227 print """
|
igor@0
|
228 cat <<RESOLVCONF > /domU/%s/etc/resolv.conf
|
igor@0
|
229 search %s
|
igor@0
|
230 nameserver %s
|
igor@0
|
231 RESOLVCONF
|
igor@2
|
232 """ % (dom,domain_name,ip_nameserver)
|
igor@0
|
233
|
igor@0
|
234 def make_etchostname():
|
igor@2
|
235 for dom in domains:
|
igor@2
|
236 print """
|
igor@0
|
237 cat <<HOSTNAME > /domU/%s/etc/hostname
|
igor@0
|
238 %s
|
igor@0
|
239 HOSTNAME
|
igor@2
|
240 """ % (dom,dom)
|
igor@0
|
241
|
igor@0
|
242
|
igor@0
|
243 def make_etchosts():
|
igor@2
|
244 i=0
|
igor@2
|
245 for dom in domains:
|
igor@2
|
246 i+=1
|
igor@2
|
247 print """
|
igor@0
|
248 cat <<HOSTS > /domU/%s/etc/hosts
|
igor@0
|
249 127.0.0.1 localhost
|
igor@9
|
250 %s %s.%s %s
|
igor@0
|
251
|
igor@0
|
252 ::1 ip6-localhost ip6-loopback
|
igor@0
|
253 fe00::0 ip6-localnet
|
igor@0
|
254 ff00::0 ip6-mcastprefix
|
igor@0
|
255 ff02::1 ip6-allnodes
|
igor@0
|
256 ff02::2 ip6-allrouters
|
igor@0
|
257 ff02::3 ip6-allhosts
|
igor@0
|
258 HOSTS
|
igor@9
|
259 """ % (dom,ip_address_table[dom],dom,domain_name,dom)
|
igor@0
|
260
|
igor@0
|
261 def make_rootssh():
|
igor@2
|
262 for dom in domains:
|
igor@2
|
263 print """
|
igor@14
|
264 mkdir -p /domU/%s/home/eb/.ssh/
|
igor@14
|
265 chown -R 1000:1000 /domU/%s/home/eb
|
igor@0
|
266 cp ~/.ssh/id_dsa.pub /domU/%s/root/.ssh/authorized_keys
|
igor@14
|
267 chmod 600 /domU/%s/home/eb/.ssh/authorized_keys
|
igor@16
|
268 """ % (dom,dom,dom,dom)
|
igor@0
|
269
|
igor@0
|
270 def make_l3rc():
|
igor@2
|
271 for dom in domains:
|
igor@2
|
272 print """
|
igor@2
|
273 cat <<EOF > /domU/%s/root/.l3rc
|
igor@0
|
274 l3cd=/users/igor/xen-drbd-dom0-setup/%s.%s/root
|
igor@0
|
275 EOF
|
igor@2
|
276 """ % (dom,dom,domain_name)
|
igor@0
|
277
|
igor@0
|
278
|
igor@0
|
279 def make_etc():
|
igor@2
|
280 make_etcfstab()
|
igor@2
|
281 make_etcnetworkinterfaces()
|
igor@2
|
282 make_etcresolvconf()
|
igor@2
|
283 make_etchosts()
|
igor@2
|
284 make_etchostname()
|
igor@2
|
285 make_rootssh()
|
igor@15
|
286 #make_l3rc()
|
igor@0
|
287
|
igor@9
|
288 def make_drbd():
|
igor@9
|
289 make_lvm()
|
igor@9
|
290 make_drbdconf()
|
igor@9
|
291 make_drbdmeta()
|
igor@9
|
292
|
igor@9
|
293 def make_domains():
|
igor@9
|
294 make_drbdprimary()
|
igor@9
|
295 make_links()
|
igor@2
|
296 make_fs()
|
igor@2
|
297 make_mount()
|
igor@2
|
298 make_install_debian()
|
igor@2
|
299 make_rsync()
|
igor@2
|
300 make_etc()
|
igor@2
|
301 make_umount()
|
igor@0
|
302
|
igor@0
|
303 def get_management_ip():
|
igor@2
|
304 return management_ip
|
igor@0
|
305
|
igor@0
|
306 def get_default_gateway():
|
igor@2
|
307 return management_gw
|
igor@0
|
308
|
igor@0
|
309 def make_bridges():
|
igor@2
|
310 ip=get_management_ip()
|
igor@2
|
311 gw=get_default_gateway()
|
igor@2
|
312 print "ifconfig %s 0.0.0.0" % (trunk)
|
igor@2
|
313
|
igor@2
|
314 # tagged interfaces
|
igor@2
|
315 for bridge in bridges:
|
igor@2
|
316 vlan=vlans[bridges.index(bridge)]
|
igor@2
|
317 if vlan == 'tagged':
|
igor@2
|
318 print "/etc/xen/scripts/network-bridge start vifnum=%s bridge=%s netdev=%s" % (bridges.index(bridge)+2,bridge,trunk)
|
igor@2
|
319 print "ip link set %s up" % (trunk)
|
igor@2
|
320
|
igor@2
|
321 # untagged interfaces
|
igor@2
|
322 for bridge in bridges:
|
igor@2
|
323 vlan=vlans[bridges.index(bridge)]
|
igor@2
|
324 if vlan != 'tagged':
|
igor@2
|
325 print "vconfig add %s %s" % (trunk,vlan)
|
igor@2
|
326 print "/etc/xen/scripts/network-bridge start vifnum=%s bridge=%s netdev=%s.%s" % (bridges.index(bridge)+2,bridge,trunk,vlan)
|
igor@2
|
327 print "ip link set %s.%s up" % (trunk,vlan)
|
igor@2
|
328
|
igor@2
|
329 print "ifconfig %s.%s %s" % (trunk,management_vlan,management_ip)
|
igor@2
|
330 if management_gw:
|
igor@2
|
331 print "route add default gw %s" % (management_gw)
|
igor@0
|
332
|
igor@0
|
333
|
igor@0
|
334
|
igor@0
|
335 #make_all_system()
|
igor@0
|
336
|
igor@0
|
337 if len(sys.argv) > 1:
|
igor@2
|
338 command = sys.argv[2]
|
igor@9
|
339 if command == 'make-drbd':
|
igor@9
|
340 make_drbd()
|
igor@9
|
341 elif command == 'make-domains':
|
igor@9
|
342 make_domains()
|
igor@9
|
343 elif command == 'make-bridges':
|
igor@2
|
344 make_bridges()
|
igor@2
|
345 elif command == 'make-links':
|
igor@2
|
346 make_links()
|
igor@2
|
347 else:
|
igor@2
|
348 show_usage()
|
igor@0
|
349 else:
|
igor@2
|
350 show_usage()
|
igor@0
|
351
|