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