xen-drbd

changeset 9:e2eafd7e1b85

Доработана инсталляции системы виртуализации
author igor
date Tue Feb 12 13:34:12 2008 +0200 (2008-02-12)
parents 3e4a29f88d50
children c14b6387ada5
files od.py xen-drbd-install.py
line diff
     1.1 --- a/od.py	Mon Feb 11 19:56:57 2008 +0200
     1.2 +++ b/od.py	Tue Feb 12 13:34:12 2008 +0200
     1.3 @@ -48,6 +48,11 @@
     1.4  }
     1.5  
     1.6  lvm_vg_name="TURBO"
     1.7 +lvm_pv_names="/dev/md2"
     1.8 +lvm_lv_drbd_meta_name="meta"
     1.9 +lvm_lv_drbd_meta_size="5G"
    1.10 +mkfs_options="-m1"
    1.11 +
    1.12  disk_table={
    1.13      'gw'        : ['drbd1:gw:2G'], 
    1.14      'igw'       : ['drbd2:igw:2G'], 
    1.15 @@ -92,7 +97,7 @@
    1.16  ip_netmask="255.255.255.224"
    1.17  domain_name="od.eb.co.ua"
    1.18  ip_nameserver="10.4.3.4"
    1.19 -ip_gateway="10.0.3.3"
    1.20 +ip_gateway="10.4.3.6"
    1.21  
    1.22  ip_address_table={
    1.23      "dns"   :"10.4.3.4",
     2.1 --- a/xen-drbd-install.py	Mon Feb 11 19:56:57 2008 +0200
     2.2 +++ b/xen-drbd-install.py	Tue Feb 12 13:34:12 2008 +0200
     2.3 @@ -1,13 +1,14 @@
     2.4  #!/usr/bin/python
     2.5  
     2.6 -import sys
     2.7 +import sys,re
     2.8  
     2.9  network=sys.argv[1]
    2.10  try:
    2.11 -    exec 'from %s import domains,disk_table,lvm_vg_name,node1,node1_ip,node2,node2_ip, \
    2.12 -        ip_network, domain_name, ip_nameserver, ip_gateway, apt_get_install, \
    2.13 -        debian_release, debian_mirror, \
    2.14 -        bridges, vlans, management_vlan, trunk, management_ip, management_gw ' % (network)
    2.15 +    exec 'from %s import * ' % (network)
    2.16 +#    exec 'from %s import domains,disk_table,lvm_vg_name,node1,node1_ip,node2,node2_ip, \
    2.17 +#        ip_network, domain_name, ip_nameserver, ip_gateway, apt_get_install, \
    2.18 +#        debian_release, debian_mirror, \
    2.19 +#        bridges, vlans, management_vlan, trunk, management_ip, management_gw ' % (network)
    2.20  except:
    2.21      print "Can't find or interpret module %s with topology description" %(network)
    2.22      sys.exit(1)
    2.23 @@ -25,8 +26,13 @@
    2.24                  drbd_device[disk.split(':')[0]]=disk.split(':')[1]
    2.25  
    2.26  def make_lvm():
    2.27 -    if do_print:
    2.28 -        print "lvcreate -L %s -n %s /dev/%s" % ("10G", "meta", lvm_vg_name)
    2.29 +    print "###################################################"
    2.30 +    print "# MAKE LVM FOR DOMAINS DRBD DEVICES"
    2.31 +    print "#"
    2.32 +    for lvm_pv_name in re.compile('\s+').split(lvm_pv_names):
    2.33 +        print "pvcreate %s" % (lvm_pv_name)
    2.34 +    print "vgcreate /dev/%s %s" % (lvm_vg_name, lvm_pv_names)
    2.35 +    print "lvcreate -L %s -n %s /dev/%s" % (lvm_lv_drbd_meta_size, lvm_lv_drbd_meta_name, lvm_vg_name)
    2.36      for dom in domains:
    2.37          for disk in disk_table[dom]:
    2.38              if disk.find(":") == -1:
    2.39 @@ -36,20 +42,26 @@
    2.40                  drbd_device[disk]=dom
    2.41              else:
    2.42                  drbd_device[disk.split(':')[0]]=disk.split(':')[0]
    2.43 -                if do_print:
    2.44 -                    print "lvcreate -L %s -n %s /dev/%s" % (disk.split(':')[1], disk.split(':')[0], lvm_vg_name)
    2.45 -                drbd_devices.append([disk.split(':')[0], "/dev/%s/%s" % (lvm_vg_name, disk.split(':')[0])])
    2.46 +                print "lvcreate -L %s -n %s /dev/%s" % (disk.split(':')[1], disk.split(':')[0], lvm_vg_name)
    2.47 +                #drbd_devices.append([disk.split(':')[0], "/dev/%s/%s" % (lvm_vg_name, disk.split(':')[0])])
    2.48 +    print ""
    2.49  
    2.50  
    2.51  def make_drbdconf():
    2.52 +    print "###################################################"
    2.53 +    print "# MAKE DRBD CONFIG FILE /etc/drbd.conf"
    2.54 +    print "#"
    2.55 +
    2.56      print "cat <<DRBD > /etc/drbd.conf"
    2.57 -    i=0
    2.58 -    for drbd in drbd_devices:
    2.59 -        resource=drbd[0]
    2.60 -        disk=drbd[1]
    2.61 -        drbd_number=i
    2.62 -        i+=1
    2.63 -        print """
    2.64 +
    2.65 +
    2.66 +    for dom in domains:
    2.67 +        for disk in disk_table[dom]:
    2.68 +            drbd_number=int(re.compile('drbd').sub('',disk.split(':')[0]))
    2.69 +            resource=disk.split(':')[1]
    2.70 +            disk="/dev/%s/%s" % (lvm_vg_name,resource)
    2.71 +
    2.72 +            print """
    2.73  resource %s {
    2.74      protocol C;
    2.75      net { 
    2.76 @@ -77,12 +89,33 @@
    2.77      }
    2.78  }
    2.79  
    2.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 )
    2.81 -        print "DRBD"
    2.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 )
    2.83 +    print "DRBD"
    2.84 +    print ""
    2.85 +
    2.86 +
    2.87 +def make_drbdmeta():
    2.88 +    print "###################################################"
    2.89 +    print "# MAKE DRBD DEVICES "
    2.90 +    print "#"
    2.91 +    print "drbdadm create-md all"
    2.92 +
    2.93 +def make_drbdprimary():
    2.94 +    print "###################################################"
    2.95 +    print "# SET DRBD DEVICES PRIMARY "
    2.96 +    print "#"
    2.97 +
    2.98 +    print "drbdadm up all"
    2.99 +    for dom in domains:
   2.100 +        for disk in disk_table[dom]:
   2.101 +            print "drbdsetup %s primary -o" % disk.split(':')[0]
   2.102  
   2.103  
   2.104  def make_links():
   2.105  
   2.106 +    print "###################################################"
   2.107 +    print "# MAKE SYMBOLIC LINKS TO /dev/drbd* FILES"
   2.108 +    print "#"
   2.109  
   2.110      # drbd_devices={
   2.111      #   'dev' : 'resource',
   2.112 @@ -95,11 +128,20 @@
   2.113          print "ln -sf /dev/%s /dev/drbd/%s" %(dev, resource)
   2.114  
   2.115  def make_fs():
   2.116 -    for dom in domains:
   2.117 -        print "mkfs.ext3 /dev/drbd/"+dom
   2.118 +
   2.119 +    print "###################################################"
   2.120 +    print "# MAKE FILESYSTEMS ON THE DRBDs"
   2.121 +    print "#"
   2.122 +
   2.123 +    for dev in drbd_device.keys():
   2.124 +        print "mkfs.ext3 %s /dev/%s" %(mkfs_options,dev)
   2.125  
   2.126  
   2.127  def make_mount():
   2.128 +    print "###################################################"
   2.129 +    print "# MOUNT U-DOMAINS FILESYSTEMS"
   2.130 +    print "#"
   2.131 +
   2.132      print "mkdir -p /domU"
   2.133      for dom in domains:
   2.134          print "mkdir -p /domU/%s" % (dom)
   2.135 @@ -154,7 +196,7 @@
   2.136  iface lo inet loopback
   2.137  
   2.138  iface eth0 inet static
   2.139 -    address %s.%s
   2.140 +    address %s
   2.141      netmask 255.255.255.0
   2.142      network %s.0
   2.143      broadcast %s.255
   2.144 @@ -162,7 +204,7 @@
   2.145      dns-nameservers %s
   2.146      dns-search %s
   2.147  INTERFACES
   2.148 -        """ % (dom,ip_network,i,ip_network, ip_network, ip_gateway, domain_name, ip_nameserver)
   2.149 +        """ % (dom,ip_address_table[dom],ip_network, ip_network, ip_gateway, domain_name, ip_nameserver)
   2.150  
   2.151  def make_etcresolvconf():
   2.152      for dom in domains:
   2.153 @@ -189,7 +231,7 @@
   2.154          print """
   2.155  cat <<HOSTS > /domU/%s/etc/hosts
   2.156  127.0.0.1       localhost
   2.157 -192.168.1.%s   %s.%s  %s
   2.158 +%s   %s.%s  %s
   2.159  
   2.160  ::1     ip6-localhost ip6-loopback
   2.161  fe00::0 ip6-localnet
   2.162 @@ -198,7 +240,7 @@
   2.163  ff02::2 ip6-allrouters
   2.164  ff02::3 ip6-allhosts
   2.165  HOSTS
   2.166 -        """ % (dom,i,dom,domain_name,dom)
   2.167 +        """ % (dom,ip_address_table[dom],dom,domain_name,dom)
   2.168  
   2.169  def make_rootssh():
   2.170      for dom in domains:
   2.171 @@ -226,8 +268,14 @@
   2.172      make_rootssh()
   2.173      make_l3rc()
   2.174  
   2.175 -def make_all_system():
   2.176 -    make_drbd_links()
   2.177 +def make_drbd():
   2.178 +    make_lvm()
   2.179 +    make_drbdconf()
   2.180 +    make_drbdmeta()
   2.181 +
   2.182 +def make_domains():
   2.183 +    make_drbdprimary()
   2.184 +    make_links()
   2.185      make_fs()
   2.186      make_mount()
   2.187      make_install_debian()
   2.188 @@ -275,7 +323,8 @@
   2.189      <network> is a name of the file, which contains network description
   2.190  
   2.191  Commands:
   2.192 -    make-all
   2.193 +    make-drbd
   2.194 +    make-domains
   2.195      make-bridges
   2.196      make-links
   2.197  """
   2.198 @@ -284,9 +333,11 @@
   2.199  
   2.200  if len(sys.argv) > 1:
   2.201      command = sys.argv[2]
   2.202 -    if command == 'make-all':
   2.203 -        make_all_system()
   2.204 -    if command == 'make-bridges':   
   2.205 +    if command == 'make-drbd':
   2.206 +        make_drbd()
   2.207 +    elif command == 'make-domains':
   2.208 +        make_domains()
   2.209 +    elif command == 'make-bridges':   
   2.210          make_bridges()
   2.211      elif command == 'make-links':   
   2.212          make_links()