# HG changeset patch # User igor # Date 1202816052 -7200 # Node ID e2eafd7e1b856cd2399a9c3923b706e6076b49c7 # Parent 3e4a29f88d50d468a680a1787fe813dbb8b3c7c1 Доработана инсталляции системы виртуализации diff -r 3e4a29f88d50 -r e2eafd7e1b85 od.py --- a/od.py Mon Feb 11 19:56:57 2008 +0200 +++ b/od.py Tue Feb 12 13:34:12 2008 +0200 @@ -48,6 +48,11 @@ } lvm_vg_name="TURBO" +lvm_pv_names="/dev/md2" +lvm_lv_drbd_meta_name="meta" +lvm_lv_drbd_meta_size="5G" +mkfs_options="-m1" + disk_table={ 'gw' : ['drbd1:gw:2G'], 'igw' : ['drbd2:igw:2G'], @@ -92,7 +97,7 @@ ip_netmask="255.255.255.224" domain_name="od.eb.co.ua" ip_nameserver="10.4.3.4" -ip_gateway="10.0.3.3" +ip_gateway="10.4.3.6" ip_address_table={ "dns" :"10.4.3.4", diff -r 3e4a29f88d50 -r e2eafd7e1b85 xen-drbd-install.py --- a/xen-drbd-install.py Mon Feb 11 19:56:57 2008 +0200 +++ b/xen-drbd-install.py Tue Feb 12 13:34:12 2008 +0200 @@ -1,13 +1,14 @@ #!/usr/bin/python -import sys +import sys,re network=sys.argv[1] try: - exec 'from %s import domains,disk_table,lvm_vg_name,node1,node1_ip,node2,node2_ip, \ - ip_network, domain_name, ip_nameserver, ip_gateway, apt_get_install, \ - debian_release, debian_mirror, \ - bridges, vlans, management_vlan, trunk, management_ip, management_gw ' % (network) + exec 'from %s import * ' % (network) +# exec 'from %s import domains,disk_table,lvm_vg_name,node1,node1_ip,node2,node2_ip, \ +# ip_network, domain_name, ip_nameserver, ip_gateway, apt_get_install, \ +# debian_release, debian_mirror, \ +# bridges, vlans, management_vlan, trunk, management_ip, management_gw ' % (network) except: print "Can't find or interpret module %s with topology description" %(network) sys.exit(1) @@ -25,8 +26,13 @@ drbd_device[disk.split(':')[0]]=disk.split(':')[1] def make_lvm(): - if do_print: - print "lvcreate -L %s -n %s /dev/%s" % ("10G", "meta", lvm_vg_name) + print "###################################################" + print "# MAKE LVM FOR DOMAINS DRBD DEVICES" + print "#" + for lvm_pv_name in re.compile('\s+').split(lvm_pv_names): + print "pvcreate %s" % (lvm_pv_name) + print "vgcreate /dev/%s %s" % (lvm_vg_name, lvm_pv_names) + print "lvcreate -L %s -n %s /dev/%s" % (lvm_lv_drbd_meta_size, lvm_lv_drbd_meta_name, lvm_vg_name) for dom in domains: for disk in disk_table[dom]: if disk.find(":") == -1: @@ -36,20 +42,26 @@ drbd_device[disk]=dom else: drbd_device[disk.split(':')[0]]=disk.split(':')[0] - if do_print: - print "lvcreate -L %s -n %s /dev/%s" % (disk.split(':')[1], disk.split(':')[0], lvm_vg_name) - drbd_devices.append([disk.split(':')[0], "/dev/%s/%s" % (lvm_vg_name, disk.split(':')[0])]) + print "lvcreate -L %s -n %s /dev/%s" % (disk.split(':')[1], disk.split(':')[0], lvm_vg_name) + #drbd_devices.append([disk.split(':')[0], "/dev/%s/%s" % (lvm_vg_name, disk.split(':')[0])]) + print "" def make_drbdconf(): + print "###################################################" + print "# MAKE DRBD CONFIG FILE /etc/drbd.conf" + print "#" + print "cat < /etc/drbd.conf" - i=0 - for drbd in drbd_devices: - resource=drbd[0] - disk=drbd[1] - drbd_number=i - i+=1 - print """ + + + for dom in domains: + for disk in disk_table[dom]: + drbd_number=int(re.compile('drbd').sub('',disk.split(':')[0])) + resource=disk.split(':')[1] + disk="/dev/%s/%s" % (lvm_vg_name,resource) + + print """ resource %s { protocol C; net { @@ -77,12 +89,33 @@ } } -""" % (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 ) - print "DRBD" +""" % (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 ) + print "DRBD" + print "" + + +def make_drbdmeta(): + print "###################################################" + print "# MAKE DRBD DEVICES " + print "#" + print "drbdadm create-md all" + +def make_drbdprimary(): + print "###################################################" + print "# SET DRBD DEVICES PRIMARY " + print "#" + + print "drbdadm up all" + for dom in domains: + for disk in disk_table[dom]: + print "drbdsetup %s primary -o" % disk.split(':')[0] def make_links(): + print "###################################################" + print "# MAKE SYMBOLIC LINKS TO /dev/drbd* FILES" + print "#" # drbd_devices={ # 'dev' : 'resource', @@ -95,11 +128,20 @@ print "ln -sf /dev/%s /dev/drbd/%s" %(dev, resource) def make_fs(): - for dom in domains: - print "mkfs.ext3 /dev/drbd/"+dom + + print "###################################################" + print "# MAKE FILESYSTEMS ON THE DRBDs" + print "#" + + for dev in drbd_device.keys(): + print "mkfs.ext3 %s /dev/%s" %(mkfs_options,dev) def make_mount(): + print "###################################################" + print "# MOUNT U-DOMAINS FILESYSTEMS" + print "#" + print "mkdir -p /domU" for dom in domains: print "mkdir -p /domU/%s" % (dom) @@ -154,7 +196,7 @@ iface lo inet loopback iface eth0 inet static - address %s.%s + address %s netmask 255.255.255.0 network %s.0 broadcast %s.255 @@ -162,7 +204,7 @@ dns-nameservers %s dns-search %s INTERFACES - """ % (dom,ip_network,i,ip_network, ip_network, ip_gateway, domain_name, ip_nameserver) + """ % (dom,ip_address_table[dom],ip_network, ip_network, ip_gateway, domain_name, ip_nameserver) def make_etcresolvconf(): for dom in domains: @@ -189,7 +231,7 @@ print """ cat < /domU/%s/etc/hosts 127.0.0.1 localhost -192.168.1.%s %s.%s %s +%s %s.%s %s ::1 ip6-localhost ip6-loopback fe00::0 ip6-localnet @@ -198,7 +240,7 @@ ff02::2 ip6-allrouters ff02::3 ip6-allhosts HOSTS - """ % (dom,i,dom,domain_name,dom) + """ % (dom,ip_address_table[dom],dom,domain_name,dom) def make_rootssh(): for dom in domains: @@ -226,8 +268,14 @@ make_rootssh() make_l3rc() -def make_all_system(): - make_drbd_links() +def make_drbd(): + make_lvm() + make_drbdconf() + make_drbdmeta() + +def make_domains(): + make_drbdprimary() + make_links() make_fs() make_mount() make_install_debian() @@ -275,7 +323,8 @@ is a name of the file, which contains network description Commands: - make-all + make-drbd + make-domains make-bridges make-links """ @@ -284,9 +333,11 @@ if len(sys.argv) > 1: command = sys.argv[2] - if command == 'make-all': - make_all_system() - if command == 'make-bridges': + if command == 'make-drbd': + make_drbd() + elif command == 'make-domains': + make_domains() + elif command == 'make-bridges': make_bridges() elif command == 'make-links': make_links()