xen-drbd
diff xen-drbd-install.py @ 9:e2eafd7e1b85
Доработана инсталляции системы виртуализации
author | igor |
---|---|
date | Tue Feb 12 13:34:12 2008 +0200 (2008-02-12) |
parents | afe3c0992ec3 |
children | c14b6387ada5 |
line diff
1.1 --- a/xen-drbd-install.py Fri Sep 28 15:39:51 2007 +0300 1.2 +++ b/xen-drbd-install.py Tue Feb 12 13:34:12 2008 +0200 1.3 @@ -1,13 +1,14 @@ 1.4 #!/usr/bin/python 1.5 1.6 -import sys 1.7 +import sys,re 1.8 1.9 network=sys.argv[1] 1.10 try: 1.11 - exec 'from %s import domains,disk_table,lvm_vg_name,node1,node1_ip,node2,node2_ip, \ 1.12 - ip_network, domain_name, ip_nameserver, ip_gateway, apt_get_install, \ 1.13 - debian_release, debian_mirror, \ 1.14 - bridges, vlans, management_vlan, trunk, management_ip, management_gw ' % (network) 1.15 + exec 'from %s import * ' % (network) 1.16 +# exec 'from %s import domains,disk_table,lvm_vg_name,node1,node1_ip,node2,node2_ip, \ 1.17 +# ip_network, domain_name, ip_nameserver, ip_gateway, apt_get_install, \ 1.18 +# debian_release, debian_mirror, \ 1.19 +# bridges, vlans, management_vlan, trunk, management_ip, management_gw ' % (network) 1.20 except: 1.21 print "Can't find or interpret module %s with topology description" %(network) 1.22 sys.exit(1) 1.23 @@ -25,8 +26,13 @@ 1.24 drbd_device[disk.split(':')[0]]=disk.split(':')[1] 1.25 1.26 def make_lvm(): 1.27 - if do_print: 1.28 - print "lvcreate -L %s -n %s /dev/%s" % ("10G", "meta", lvm_vg_name) 1.29 + print "###################################################" 1.30 + print "# MAKE LVM FOR DOMAINS DRBD DEVICES" 1.31 + print "#" 1.32 + for lvm_pv_name in re.compile('\s+').split(lvm_pv_names): 1.33 + print "pvcreate %s" % (lvm_pv_name) 1.34 + print "vgcreate /dev/%s %s" % (lvm_vg_name, lvm_pv_names) 1.35 + print "lvcreate -L %s -n %s /dev/%s" % (lvm_lv_drbd_meta_size, lvm_lv_drbd_meta_name, lvm_vg_name) 1.36 for dom in domains: 1.37 for disk in disk_table[dom]: 1.38 if disk.find(":") == -1: 1.39 @@ -36,20 +42,26 @@ 1.40 drbd_device[disk]=dom 1.41 else: 1.42 drbd_device[disk.split(':')[0]]=disk.split(':')[0] 1.43 - if do_print: 1.44 - print "lvcreate -L %s -n %s /dev/%s" % (disk.split(':')[1], disk.split(':')[0], lvm_vg_name) 1.45 - drbd_devices.append([disk.split(':')[0], "/dev/%s/%s" % (lvm_vg_name, disk.split(':')[0])]) 1.46 + print "lvcreate -L %s -n %s /dev/%s" % (disk.split(':')[1], disk.split(':')[0], lvm_vg_name) 1.47 + #drbd_devices.append([disk.split(':')[0], "/dev/%s/%s" % (lvm_vg_name, disk.split(':')[0])]) 1.48 + print "" 1.49 1.50 1.51 def make_drbdconf(): 1.52 + print "###################################################" 1.53 + print "# MAKE DRBD CONFIG FILE /etc/drbd.conf" 1.54 + print "#" 1.55 + 1.56 print "cat <<DRBD > /etc/drbd.conf" 1.57 - i=0 1.58 - for drbd in drbd_devices: 1.59 - resource=drbd[0] 1.60 - disk=drbd[1] 1.61 - drbd_number=i 1.62 - i+=1 1.63 - print """ 1.64 + 1.65 + 1.66 + for dom in domains: 1.67 + for disk in disk_table[dom]: 1.68 + drbd_number=int(re.compile('drbd').sub('',disk.split(':')[0])) 1.69 + resource=disk.split(':')[1] 1.70 + disk="/dev/%s/%s" % (lvm_vg_name,resource) 1.71 + 1.72 + print """ 1.73 resource %s { 1.74 protocol C; 1.75 net { 1.76 @@ -77,12 +89,33 @@ 1.77 } 1.78 } 1.79 1.80 -""" % (resource, node1, drbd_number, disk, node1_ip, i+drbd_base_port, meta_disk, drbd_number, node2, drbd_number, disk, node2_ip, i+drbd_base_port, meta_disk, drbd_number ) 1.81 - print "DRBD" 1.82 +""" % (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 ) 1.83 + print "DRBD" 1.84 + print "" 1.85 + 1.86 + 1.87 +def make_drbdmeta(): 1.88 + print "###################################################" 1.89 + print "# MAKE DRBD DEVICES " 1.90 + print "#" 1.91 + print "drbdadm create-md all" 1.92 + 1.93 +def make_drbdprimary(): 1.94 + print "###################################################" 1.95 + print "# SET DRBD DEVICES PRIMARY " 1.96 + print "#" 1.97 + 1.98 + print "drbdadm up all" 1.99 + for dom in domains: 1.100 + for disk in disk_table[dom]: 1.101 + print "drbdsetup %s primary -o" % disk.split(':')[0] 1.102 1.103 1.104 def make_links(): 1.105 1.106 + print "###################################################" 1.107 + print "# MAKE SYMBOLIC LINKS TO /dev/drbd* FILES" 1.108 + print "#" 1.109 1.110 # drbd_devices={ 1.111 # 'dev' : 'resource', 1.112 @@ -95,11 +128,20 @@ 1.113 print "ln -sf /dev/%s /dev/drbd/%s" %(dev, resource) 1.114 1.115 def make_fs(): 1.116 - for dom in domains: 1.117 - print "mkfs.ext3 /dev/drbd/"+dom 1.118 + 1.119 + print "###################################################" 1.120 + print "# MAKE FILESYSTEMS ON THE DRBDs" 1.121 + print "#" 1.122 + 1.123 + for dev in drbd_device.keys(): 1.124 + print "mkfs.ext3 %s /dev/%s" %(mkfs_options,dev) 1.125 1.126 1.127 def make_mount(): 1.128 + print "###################################################" 1.129 + print "# MOUNT U-DOMAINS FILESYSTEMS" 1.130 + print "#" 1.131 + 1.132 print "mkdir -p /domU" 1.133 for dom in domains: 1.134 print "mkdir -p /domU/%s" % (dom) 1.135 @@ -154,7 +196,7 @@ 1.136 iface lo inet loopback 1.137 1.138 iface eth0 inet static 1.139 - address %s.%s 1.140 + address %s 1.141 netmask 255.255.255.0 1.142 network %s.0 1.143 broadcast %s.255 1.144 @@ -162,7 +204,7 @@ 1.145 dns-nameservers %s 1.146 dns-search %s 1.147 INTERFACES 1.148 - """ % (dom,ip_network,i,ip_network, ip_network, ip_gateway, domain_name, ip_nameserver) 1.149 + """ % (dom,ip_address_table[dom],ip_network, ip_network, ip_gateway, domain_name, ip_nameserver) 1.150 1.151 def make_etcresolvconf(): 1.152 for dom in domains: 1.153 @@ -189,7 +231,7 @@ 1.154 print """ 1.155 cat <<HOSTS > /domU/%s/etc/hosts 1.156 127.0.0.1 localhost 1.157 -192.168.1.%s %s.%s %s 1.158 +%s %s.%s %s 1.159 1.160 ::1 ip6-localhost ip6-loopback 1.161 fe00::0 ip6-localnet 1.162 @@ -198,7 +240,7 @@ 1.163 ff02::2 ip6-allrouters 1.164 ff02::3 ip6-allhosts 1.165 HOSTS 1.166 - """ % (dom,i,dom,domain_name,dom) 1.167 + """ % (dom,ip_address_table[dom],dom,domain_name,dom) 1.168 1.169 def make_rootssh(): 1.170 for dom in domains: 1.171 @@ -226,8 +268,14 @@ 1.172 make_rootssh() 1.173 make_l3rc() 1.174 1.175 -def make_all_system(): 1.176 - make_drbd_links() 1.177 +def make_drbd(): 1.178 + make_lvm() 1.179 + make_drbdconf() 1.180 + make_drbdmeta() 1.181 + 1.182 +def make_domains(): 1.183 + make_drbdprimary() 1.184 + make_links() 1.185 make_fs() 1.186 make_mount() 1.187 make_install_debian() 1.188 @@ -275,7 +323,8 @@ 1.189 <network> is a name of the file, which contains network description 1.190 1.191 Commands: 1.192 - make-all 1.193 + make-drbd 1.194 + make-domains 1.195 make-bridges 1.196 make-links 1.197 """ 1.198 @@ -284,9 +333,11 @@ 1.199 1.200 if len(sys.argv) > 1: 1.201 command = sys.argv[2] 1.202 - if command == 'make-all': 1.203 - make_all_system() 1.204 - if command == 'make-bridges': 1.205 + if command == 'make-drbd': 1.206 + make_drbd() 1.207 + elif command == 'make-domains': 1.208 + make_domains() 1.209 + elif command == 'make-bridges': 1.210 make_bridges() 1.211 elif command == 'make-links': 1.212 make_links()